Gallery2:How to use Thumbnails for the Sub Album List - Gallery Codex
Personal tools

Gallery2:How to use Thumbnails for the Sub Album List

From Gallery Codex

Gallery Version 2.1.1

Changing the classic theme to show thumbs of subalbums

Note2: I added the ability to enable this feture in the options page of the theme. the pachtes are for gallery version 2.1.1. The patch files can be found here.

Note: These instructions will only work with Gallery 2 beta 4 or later as the theme system was changed in that beta release.

Every parent album can display a list of its subalbums and so on down the hierarchy as many levels deep as you want. This display is text only. If you would like these subalbums to show up as thumbnails instead of a list of titles, you need to modify your theme.

Changes to theme.inc

I created an pach against version 2.1.1 of the classic theme to applay the changes mentiond here.g2-theme-classic-theme.inc.diff Mastalee 12:46, 14 July 2006 (PDT)


Theme.inc is found at the root of the theme folder. You need to add some code here in order for the thumbnails to be available in the template.

Under function showAlbumPage, make these two changes:

	    if (!empty($treeIds)) {
		list ($ret, $treeItems) = GalleryCoreApi::loadEntitiesById($treeIds);
		if ($ret->isError()) {
		    return array($ret->wrap(__FILE__, __LINE__), null);
		}

/* BEGIN ADDED CODE */             
            list ($ret, $thumbs) = GalleryCoreApi::fetchThumbnailsByItemIds($treeIds);
            if ($ret->isError()) {
                return array($ret->wrap(__FILE__, __LINE__), null);
            }
/* END ADDED CODE */

	    }
	    $theme['tree'] = $treeList;
	    $theme['treeItems'] = array();
	    foreach ($treeItems as $treeItem) {
		$theme['treeItems'][$treeItem->getId()] = $treeItem->getMemberData();

/* BEGIN ADDED CODE */              
            if (isset($thumbs[$treeItem->getId()])) {
                $theme['treeItems'][$treeItem->getId()]['thumbnail'] =
                    $thumbs[$treeItem->getId()]->getMemberData();
            }
/* END ADDED CODE */

Changes to album.tpl

The changes for the album.tpl version 2.1.1 are in this patch file: g2-theme-classic-album.tpl.diff

--Mastalee 12:48, 14 July 2006 (PDT)



Album.tpl is found under the templates directory for your theme.

The sub album display is done in this section:

{if $theme.params.showSubalbums}
  /*middle part snipped*/
{/if}

The key part of the original code is the list item. If you want to keep the tree building part, just replace:

   <a href="{g->url arg1="view=core.ShowItem" arg2="itemId=`$node.id`"}">
      {$theme.treeItems[$node.id].title|default:$theme.treeItems[$node.id].pathComponent|markup}
  </a>

with:

    {if !empty($theme.treeItems[$node.id].thumbnail)}
       <a href="{g->url arg1="view=core:ShowItem" arg2="itemId=`$node.id`"}">
         {g->image 
            item=$theme.treeItems[$node.id] 
            image=$theme.treeItems[$node.id].thumbnail 
            maxSize=60
            title=$theme.treeItems[$node.id].title}
       </a>
      {/if}

This checks to make sure there is a thumbnail (in case of empty albums) and displays the thumbnail if there is one. If you want empty albums to show up, add an "else" to it that displays the title as in the original code. If you want bigger thumbnails, change the maxSize setting.


If you would rather show all the thumbnails inline, replace the entire section with the following. This looks best if you only list the immediate children (1 level of sub albums).

{if $theme.params.showSubalbums}
  {if !empty($theme.tree[$child.id])}
  <p>
  Subalbums:<br />
  
<ul style="display:inline">
  {foreach from=$theme.tree[$child.id] item=node}
    <li style="display:inline">
      {if !empty($theme.treeItems[$node.id].thumbnail)}
         <a href="{g->url arg1="view=core:ShowItem" arg2="itemId=`$node.id`"}">
           {g->image 
             item=$theme.treeItems[$node.id] 
             image=$theme.treeItems[$node.id].thumbnail 
             maxSize=60 
             title=$theme.treeItems[$node.id].title}
         </a>
      {/if}
    </li>
  {/foreach}
  </ul>
  
</p>
{/if}


Gallery Version 2.2.X

You should probably read the bits above from Mastalee, especially the album.tpl, as his/her changes to that file worked for me. I won't duplicate them here.

This is the entire function from the classic theme's theme.inc as of version 2.2.3, modified to support thumbnails for the sub album list. I included the entire function so that it is obvious where the changes were made in relation to the rest of the code, just in case it all changes again in the next version and someone needs to understand exactly how this was done in the old code in order to add thumbnail ability to the new code.

You should be able to cut and paste this entire block over-top of the original _buildTree function.

theme.inc

    /**
     * Build template data for subalbum tree
     * @return object GalleryStatus a status code
     * @access private
     */
    function _buildTree($childIds, &$treeList, &$treeItems, $maxDepth, $subalbumSort, $userId) {
	list ($ret, $items) = GalleryCoreApi::loadEntitiesById($childIds);
	if ($ret) {
	    return $ret;
	}
	$treeIds = array();
	foreach ($items as $item) {
	    if (!GalleryUtilities::isA($item, 'GalleryAlbumItem')) {
		continue;
	    }
	    if ($subalbumSort) {
		/* Apply sort preference of each album */
		$ret = $this->_doBuildTree($item, $item->getId(), $treeList, $treeItems,
					   $maxDepth, $userId, 1);
		if ($ret) {
		    return $ret;
		}
	    } else {
		$id = $item->getId();
		list ($ret, $tree) = GalleryCoreApi::fetchAlbumTree($id, $maxDepth, $userId);
		if ($ret) {
		    return $ret;
		}
		$treeList[$id] = array();
		$this->_parseTree($tree, $treeList[$id], $treeIds);
	    }
	}
	if (!empty($treeIds)) {
	    list ($ret, $items) = GalleryCoreApi::loadEntitiesById($treeIds);
	    if ($ret) {
		return $ret;
	    }
/* new code */
	    list ($ret, $thumbnail) = GalleryCoreApi::fetchThumbnailsByItemIds($treeIds);
	    if ($ret) {
	    return $ret;
	    }
/* end new code */
	    foreach ($items as $item) {
		$treeItems[$item->getId()] = (array)$item;
/* new code */
		if(isset($treeItems[$item->getId()])) {
		    $treeItems[$item->getId()]['thumbnail'] = (array)$thumbnail[$item->getId()];
		}
/* end new code */
	    }
	}
	
	return null;
}