Looping through the album database object - what's the best way?

SeanW

Joined: 2003-10-29
Posts: 6
Posted: Mon, 2007-06-04 19:35

Hello,

I hope this is the appropriate forum for this... if not, I apologize in advance.

I need to find the best way to loop through all my galleries and sub-galleries. I have a handful of G1 installations that I have to export to a custom imaging system. I have a recursion loop working right now, but I'm not convinced it's the best way to do it.

Any tips would be greatly appreciated... here's what I have so far (with extra junk removed):

list ($numPhotos, $numAccess, $numAlbums) = $albumDB->numAccessibleItems($gallery->user);

for ($i = 1; $i <= $numAlbums; $i++) {

	// setup the current album var
	$gallery->album = $albumDB->getAlbum($gallery->user, $i);

	// Get this album's Var's
	$albumTitle = $gallery->album->fields["title"];
	$albumName = $gallery->album->fields["name"];
	// more vars here... etc, etc

	// do stuff

	// call the sub album loop to handle this album's children
	SubGalleryLoop(createTreeArray($albumName, $depth = 0));
}

function SubGalleryLoop($subAlbums) {
    global $gallery, $albumDB;

    // for each sub album in the parent album
    foreach($subAlbums as $subAlbum) {

        // this creates the album object for the current sub album
        $gallery->album = $albumDB->getAlbumByName($subAlbum['albumName']);

        // Get this album's Var's
        $albumTitle = $gallery->album->fields["title"];
        $albumName = $gallery->album->fields["name"];
        // more vars here... etc, etc

		// do stuff

        // if this sub album contains albums, call back into this function for recursion
        if($subAlbum['subTree']) SubGalleryLoop($subAlbum['subTree']);
    }
}