Need sum of all subalbums within album (more than one level)

I've actually mentioned this in another post where the extremely helpful acrylian gave me some help as to solving another issue but this remains unsolved and so this is why I'm creating another thread with a useful title.

The function getSubAlbums has got me so far, telling me how many sub albums are in the immediate folder, or album.

However in the real world things are more than 1 level deep and should I have a layout like this:

Parent
>>>>>Child 1
>>>>>Child 2
>>>>>>>>>>>Child Child 1
>>>>>>>>>>>Child Child 2

At present the parent sub-album would show 2, however it should show 4, as the nested sub albums still exist.

I know that there should be some way of parsing through the database with SQL but I can't for the life of me work out the correct query to display the true number of sub albums in an albums description.

I've got far with the functions today and have used them with some fresh PHP knowledge to allow for conditional resizing etc, but this is something else, and a problem I don't think I can fix without a little help from somebody with some SQL knowledge.

Perhaps I've overlooked something, but I would expect GetSubAlbums to function more than 1 level deep, otherwise it really only supports a very limited and flat album structure.

Thanks.

Comments

  • No need to parse the database. Just "walk" the albums tree. If you look at the current development stream you will see that the albums tab does just what you are trying to do.
  • I dont want spoonfeeding but could you possibly expand on that?

    What do you mean by Albums tab in development stream?
  • acrylian Administrator, Developer
    I think sbillard mistook you talking about the admin tabs as standard themes do not have tabs. However the admin backend indeed does what you want. Also look at the print_album_menu plugin.
  • what I meant is look at the function `printNestedAlbumsList()` in admin-functions.php
  • oooh i see, that sounds promising.

    Very good, thanks for your help. I apologise, all this hacking is new to me, however Zen seams to have thought of most things and created a really good functions library, which has allowed me to learn some good stuff at a great rate.

    Im really very impressed with Zen as a product so far and the developers as people. Coppermine gave me nothing but greif and support was rude and rediculous.

    Many thanks for all your efforts
  • err, I don't have a function called that in my admin-functions.php
  • That is because it is in the development (nightly) build. You would have to download that build.
  • Hi all,

    So after many sleepless nights I'm still unable to get an output of the sum of subalbums within an album in the albums description.

    My php is too primative and even after trying various calls with the function from the nightly (and now released) build I'm unable to get what I need.

    I'm on my knees begging that some kind sole will give me just a line of code that will output this for me. The line I need replaced is:

    `<?php if( getNumAlbums()>0 ){ ?>

    <?php echo getNumAlbums();?> sub albums inside

    <?php } ?>`

    This is the only thing stopping me from putting my site live as it looks like my gallery has few albums when in fact there are lots burried in nested folders. I do feel that this simple function is 100% necessary as standard for any gallery and surpised that it's made so difficult by Zenphoto for somebody with limited skills to implement, but hey, the software is free and works well for what it does.

    May I also make clear that I don't expect Acrylian to reply here or give me this code. I know he's busy and feels that we should all learn but I'm hoping that some proficient developer for whom this would not be too much hassle would give me a break.

    Thank you to anybody who helps.

  • acrylian Administrator, Developer
    This snippet gets what you want:
    `
    <?php
    $allsubalbums = getAllAlbums($_zp_current_album);
    $count = '';
    foreach ($allsubalbums as $album) {
    $count++;
    }
    echo "Total number of subalbums: ".$count;
    ?>
    `
  • You my man are truly a legend, Thank you for this, I was a mile off.

    I really appreciate you taking the time to help me out like that.
Sign In or Register to comment.