Integration of G2 showing a treeview of albums

aucupor

Joined: 2007-08-29
Posts: 2
Posted: Wed, 2007-08-29 14:28

Hi folks,

a customer has a large Gallery using G2 that isn't embedded in the rest of his web page yet. Now, I have to show a simple page in the page's style that shows a treeview of available albums (and perhaps the number of containing items).

I've already found some examples that show how to integrate G2 into a page but I didn't found
how I can show a treeview.

Can somebody give me a hint?

Thanks in advance,
Johannes

 
capt_kirk

Joined: 2006-01-24
Posts: 492
Posted: Wed, 2007-08-29 14:53

I just did this for G2Image v3.0. Take a look at g2ic_make_html_album_tree in g2image.php. I used the dtree script (like the album select module does).

You'll need to modify the link generated in g2ic_make_html_album_tree_branches to fit your needs.

Hope that helps or points you in the right direction.

Kirk

 
aucupor

Joined: 2007-08-29
Posts: 2
Posted: Thu, 2007-08-30 00:52

Hi Kirk,

many thanks for the tip, your code was very useful for me.
For the ones who are looking for the same solution, here is my heavily changed code from Kirk:

(This is only a quick & dirty pre-solution ;)

Johannes

<html>
<head>
<title>Test</title>
</head>

<body>

<?php

runGallery();

function runGallery() {

require_once('../embed.php'); // change this!

$init = GalleryEmbed::init(array('fullInit' => true));

if (GalleryUtilities::isCompatibleWithApi(array(7,5), GalleryCoreApi::getApiVersion())) {
list($error, $rootAlbum) = GalleryCoreApi::getDefaultAlbumId();
}
// Otherwise use a Gallery2 2.1 method to get the root album
else {
list($error, $rootAlbum) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum');
}

print g2ic_make_html_album_tree($rootAlbum);

}

function g2ic_make_html_album_tree($root_album){

$parent = -1;
$node = 0;
$html .= g2ic_make_html_album_tree_branches($root_album, $parent, $node);
return $html;
}

function g2ic_make_html_album_tree_branches($current_album, $parent, &$node) {

// global $g2ic_options;

list ($error,$items) = GalleryCoreApi::loadEntitiesById(array($current_album));
if(!$error){
foreach ($items as $item) {
$album_title = $item->getTitle();
if(empty($album_title)) {
$album_title = $item->getPathComponent();
}
}

$html .= "<ul>".
"<li>$album_title</li>";

}

list($error, $sub_albums) = GalleryCoreApi::fetchAlbumTree($current_album,1);

$albums = array_keys($sub_albums);

if (count($albums) > 0) {
$parent = $node;
foreach ($albums as $album) {
$node++;
$html .= g2ic_make_html_album_tree_branches($album, $parent, $node);
}
}

$html .= "</ul>";

return $html;
}

?>

</body>
</html>