"Updated/New" for parent album when changes in subalbums?

dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Thu, 2006-09-07 01:59

Hi there!
I'd like to extend the functionality of the new/ubdated modul so that it is showing the "updated" status for an album whose subalbums have been changed or added. Maybe it's already done but I can't use the search function at the moment.
E.g. I've got a struktur like

Album 1
- subalbum 1
- subalbum 2
Album 2
- subalbum 3

When there are changes in subalbum 2 for example the updated symbol only occurs for that special subalbum but not for the parent Album 1.

Can anybody give me a hint?

cheers

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2006-09-07 02:49

I'm pretty sure I've seen code for this, but couldn't find it either.. just others asking the same:

http://gallery.menalto.com/node/41940
http://gallery.menalto.com/node/38008

 
dreamingof8a

Joined: 2005-05-22
Posts: 69
Posted: Thu, 2006-09-07 04:48

I think it could pretty easily be done by adding a recursive search through all subalbums (if there are some) in this part of module.inc:

foreach ($items as $item) {
	    if ($param['days.new'] > 0 && $item->getCreationTimestamp() > $newTime) {
		$summaries[$item->getId()] = '<span class="giNew">'
		    . $newString . '</span>';
	    } else if ($param['days.updated'] > 0
			&& $item->getModificationTimestamp() > $updatedTime) {
		$summaries[$item->getId()] = '<span class="giUpdated">'
		    . $updatedString . '</span>';
	    } else RECURSIVE SEARCH THROUGH SUBALBUMS UNTIL FIRST UPDATE CONDITION IS FULFILLED
	}

This might slow down the gallery if there are many subalbums but that would be worth it. I'd like to do this change but I don't know enough about how the gallery works (it seems a bit confusing to me sometimes) and wich terms to use to parse through the subalbums. I imagine something like

  if (item.hassubalbums) {
    foreach (item.subalbums as sub) {
      if (sub.updated) {
       $summaries[]=..giupdated..; break;
    }
  }

This isn't correct code but it's meant to be an idea...

 
Lentil

Joined: 2007-04-06
Posts: 19
Posted: Tue, 2007-04-24 05:55

I know this is an old post, but I didn't find any more recent related articles. I've started to make a hack at modifying newitems:module.inc, but I'm pretty much a class newbie. This is pretty clunky code, so I'll take all suggestions on streamlining, but first I'd like to get it working.

Here's what I have so far:

	$summaries = array();
	foreach ($items as $item) {
	    if ($param['days.new'] > 0 && $item->getCreationTimestamp() > $newTime) {
		$summaries[$item->getId()] = '<span class="giNew">'
		    . $newString . '</span>';
	    } else if ($param['days.updated'] > 0
			&& $item->getModificationTimestamp() > $updatedTime) {
		$summaries[$item->getId()] = '<span class="giUpdated">'
		    . $updatedString . '</span>';
	    } else {/* Recurse lower albums, only need albums, because the above got us that far */
			list ($ret, $childIds) = GalleryCoreApi::fetchDescendentAlbumItemIds($item);
			if ($ret) {
				return array($ret, null);
			}
			$sub_index=0;
			$max_index=count($childIds);
			/* Load the children */
		    list ($ret, $childAlbums) = GalleryCoreApi::loadEntitiesById($childIds);
		    if ($ret) {
			return array($ret, null);
		    }
			while ($sub_index < $max_index && $param['days.update'] > 0) {
				if ($childAlbums[$sub_index]->getModificationTimestamp() > $updatedTime) {
					$summaries[$item->getId()] = '<span class="giUpdated">'
					. $updatedString . '</span>';
					$sub_index=$max_index+1;
				}
				$sub_index++;
			}			
		
	    }
		
	}
	return array(null, $summaries);

Unfortunately, I'm getting a BAD PARAMETER error in GalleryCoreApi::loadEntitiesById. Any ideas?

Vital stats:

Gallery version = 2.2.1 core 1.2.0.1
PHP version = 4.4.4 cgi
Webserver = Apache/1.3.33 (Unix)
Database = mysqlt 4.0.27-standard-log, lock.system=flock
Toolkits = Exif, LinkItemToolkit, SquareThumb, NetPBM
Acceleration = partial/21600, none
Operating system = Linux infong 2.4 #1 SMP Thu Jan 13 08:59:31 CET 2005 i686 unknown
Default theme = matrix
gettext = enabled
Locale = en_US
Browser = Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3
Rows in GalleryAccessMap table = 27
Rows in GalleryAccessSubscriberMap table = 882
Rows in GalleryUser table = 13
Rows in GalleryItem table = 881
Rows in GalleryAlbumItem table = 54
Rows in GalleryCacheMap table = 155 
 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Tue, 2007-04-24 18:00

don't call loadEntitiesById in the case where $childIds comes up empty.

 
Lentil

Joined: 2007-04-06
Posts: 19
Posted: Wed, 2007-04-25 03:59

Thanks mindless. That was the cause of the error, for some reason I though that empty in would return empty out, but that is clearly not the case.

After some additional experimenting, here is the final code. This will add the "Updated" tag to any album which contains an item which is "Updated". It doesn't check for "New" items at the lower level, since the modification dates (what "Update" looks at) for parents are automatically changed when new items are created. I had originally planned to add a function for recursion into sub-sub-items, but the fetchDescendents seems to do this already. Note: this might be slow on very big/nested Galleries, but it didn't add any noticeable delay on my (relatively) small gallery.

I haven't investigated appropriate baselining and versioning in the Gallery codebase, so I just added a sub-version. This module will identify itself as version 1.0.5.1, since I updated the 1.0.5 version (included in Gallery 2.2.1 full). To reproduce for yourself, simply copy the below code into a new module.inc and overwrite the one in version 1.0.5 of "newitems".

Complete code of /newitems/module.inc with my changes in blue:

<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2007 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * Add new/updated image in summary info for new/updated items.
 * New sort option to put new items in front, follwed by another sort.
 * Thanks to Felix Rabinovich (virshu) for the idea.
 *
 * @package NewItems
 * @author Alan Harder <alan.harder@sun.com>
 * @version $Revision: 16034 $
 */
class NewItemsModule extends GalleryModule {

    function NewItemsModule() {
	global $gallery;

	$this->setId('newitems');
	$this->setName($gallery->i18n('New Items'));
	$this->setDescription($gallery->i18n('Highlight new/updated Gallery items'));
	$this->setVersion('1.0.5.1');
	$this->setGroup('display', $gallery->i18n('Display'));
	$this->setCallbacks('getSiteAdminViews|getItemSummaries');
	$this->setRequiredCoreApi(array(7, 10));
	$this->setRequiredModuleApi(array(3, 0));
    }

    /**
     * @see GalleryModule::upgrade
     */
    function upgrade($currentVersion) {
	if (!isset($currentVersion)) {
	    foreach (array('days.new' => '7',
			   'days.updated' => '7' )
		     as $key => $value) {
		$ret = $this->setParameter($key, $value);
		if ($ret) {
		    return $ret;
		}
	    }
	}

	return null;
    }

    /**
     * @see GalleryModule::performFactoryRegistrations
     */
    function performFactoryRegistrations() {
	$ret = GalleryCoreApi::registerFactoryImplementation(
	    'GallerySortInterface_1_2', 'NewItemsSortOrder', 'NewItems',
	    'modules/newitems/classes/NewItemsSortOrder.class', 'newitems', null);
	if ($ret) {
	    return $ret;
	}

	return null;
    }

    /**
     * @see GalleryModule::getSiteAdminViews
     */
    function getSiteAdminViews() {
	return array(null,
		     array(array('name' => $this->translate('New Items'),
				 'view' => 'newitems.NewItemsSiteAdmin')));
    }

    /**
     * @see GalleryModule::getItemSummaries
     */
    function getItemSummaries($items, $permissions, &$template) {
	list ($ret, $param) = GalleryCoreApi::fetchAllPluginParameters('module', 'newitems');
	if ($ret) {
	    return array($ret, null);
	}
	$time = time();
	$newTime = $time - $param['days.new'] * 86400;
	$updatedTime = $time - $param['days.updated'] * 86400;

	$newString = $this->translate('New');
	$updatedString = $this->translate('Updated');

	$summaries = array();
	foreach ($items as $item) {
	    if ($param['days.new'] > 0 && $item->getCreationTimestamp() > $newTime) {
		$summaries[$item->getId()] = '<span class="giNew">'
		    . $newString . '</span>';
	    } else if ($param['days.updated'] > 0
			&& $item->getModificationTimestamp() > $updatedTime) {
		$summaries[$item->getId()] = '<span class="giUpdated">'
		    . $updatedString . '</span>';
	    } else if ($param['days.updated'] > 0) {
			/* C. Schierer 24 April 2007: Look at child (lower) items for update status */
			list ($ret, $childIds) = GalleryCoreApi::fetchDescendentItemIds($item);
			if ($ret) {
				return array($ret, null);
			}
			$sub_index=0;
			$max_index=count($childIds);
			/* If there are any children, Load them */
			if ($max_index>0) {
				list ($ret, $childAlbums) = GalleryCoreApi::loadEntitiesById($childIds);
				if ($ret) {
				return array($ret, null);
				}
				/* Check each child's modification date */
				while ($sub_index<$max_index) {
					if ($childAlbums[$sub_index]->getModificationTimestamp() > $updatedTime) {
						$summaries[$item->getId()] = '<span class="giUpdated">'
							. $updatedString . '</span>';
						$sub_index=$max_index+1;
					} 
					$sub_index++;
				} /* while */
			} /* End C. Schierer mods */
		}			
	} 
		 
	return array(null, $summaries);
    }

	
    /**
     * @see GalleryModule::uninstall
     */
    function uninstall() {
	$ret = GalleryCoreApi::deleteSortOrder('NewItems');
	if ($ret) {
	    return $ret;
	}

	return parent::uninstall();
    }
	
}
?>
 
Lentil

Joined: 2007-04-06
Posts: 19
Posted: Wed, 2007-04-25 04:04

P.S:
Any processing improvement comments would be welcome as I tend to code in brute force.
If I get inspired, I may try to add an option to the admin page to toggle this "recursion" behavior.

 
jacauc

Joined: 2005-06-15
Posts: 13
Posted: Tue, 2007-06-12 16:40

Thanks Lentil.
This works like a charm for me. (don't know much about coding. Just copied and pasted into my module.inc file)
Now my only remaining question :D :
Now that the "updated" part is replicated all the way to all parents, how can I make the "sort by last updated" recognize that this album was updated.

See my attachment. The a sub-album in the fourth album was updated, and it now shows the "updated" tag correctly till the parent, but the "sort by last updated" did not realize this. The third album should be demoted by the sort method, and the fourth promoted.

Any ideas how to make this possible?
Thanks in advance!
Jacauc
http://www.dieinter.net

 
Lentil

Joined: 2007-04-06
Posts: 19
Posted: Tue, 2007-06-12 17:31

jacauc: You're welcome!

The code I changed only affects whether the "Updated" tag/graphic is displayed as the album thumbnails are being rendered in the main area of the Gallery window. It doesn't affect any actual attribute of the object, that is to say: there is no 'updated' attribute of the object (album,image,etc). So, if you want the sort behavior to work the same way (in deciding whether the object is updated or not) my guess is that you would need to find the similar code above in the sort routine, and add the same sort of extra logic as was done above.

That's just an educated guess, since I don't really know how (or where) the sort function is implemented.

 
jacauc

Joined: 2005-06-15
Posts: 13
Posted: Wed, 2007-06-13 05:58

Ah well, thought it might be worth asking.
Thanks anyways!

(I'm not a programmer, so I do not want to go and fool around there myself)

 
Kadina

Joined: 2006-04-26
Posts: 31
Posted: Mon, 2007-06-18 18:35

This works well, thank you! I would like to extend it a bit to work with a tree view. On the main page of my gallery I list all subalbums to the right of the parent album (similiar to a G1 layout) and I would like to "mark" any updated albums right there in that list based on the days parameter of the new/updated module. Does anyone have an idea of how to access that parameter from within a template? Below is the code in my mainPage.tpl where the subalbums are displayed, but I am not sure how to access the parameter to do the date check.

{if !empty($theme.tree[$child.id])}
		  <h4> {g->text text="Subalbums:"} </h4>
		  <ul>
		    {assign var="empty" value=""}
		    {assign var="depth" value=0}
		    {foreach from=$theme.tree[$child.id] item=node}
		      {if $node.depth > $depth}
			<li><ul>
		      {elseif $node.depth < $depth}
			{$empty|indent:$depth-$node.depth:"</ul></li>"}
		      {/if}
		      {assign var="depth" value=$node.depth}
		      <li>
			<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>
		      </li>
		    {/foreach}
		    {$empty|indent:$depth:"</ul></li>"}
		  </ul>
		{/if}
 
bubbanc

Joined: 2008-12-30
Posts: 9
Posted: Tue, 2008-12-30 00:56

Thanks for this. Funny it's 2 years later and this still hasn't made it into the code base. I've changed classic theme to also show you in the subalbums tree if a subalbum has been updated (with an asterisk).

/gallery2/themes/classic
$ diff -u theme.inc.bak theme.inc 
--- theme.inc.bak       2008-12-29 16:24:40.038564000 -0800
+++ theme.inc   2008-12-29 16:36:09.253695000 -0800
 -247,6 +247,13 @@
        if ($ret) {
            return $ret;
        }
+       list ($ret, $param) = GalleryCoreApi::fetchAllPluginParameters('module', 'newitems');
+        if ($ret) {
+            return array($ret, null);
+        }
+        $time = time();
+        $updatedTime = $time - $param['days.updated'] * 86400;
+
        if (!empty($subAlbumIds)) {
            list ($ret, $subAlbums) =
                GalleryCoreApi::loadEntitiesById($subAlbumIds, 'GalleryAlbumItem');
 -257,6 +264,9 @@
                $id = $subAlbum->getId();
                $treeList[$branchId][] = array('id' => $id, 'depth' => $depth - 1);
                $treeItems[$id] = (array)$subAlbum;
+               if ($subAlbum->getModificationTimestamp() > $updatedTime) {
+                       $treeItems[$id]['updated'] = "1";
+               }
                if (!isset($maxDepth) || $depth < $maxDepth) {
                    $ret = $this->_doBuildTree($subAlbum, $branchId, $treeList, $treeItems,
                                               $maxDepth, $userId, $depth + 1);

/gallery2/themes/classic/templates/local
$ diff -u ../album.tpl album.tpl
--- ../album.tpl        2008-10-18 00:15:37.000000000 -0700
+++ album.tpl   2008-12-29 16:21:14.080153000 -0800
 -160,9 +160,15 @@
                      {/if}
                      {assign var="depth" value=$node.depth}
                      <li>
-                       <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>
+                         {if !empty($theme.treeItems[$node.id].updated)}
+                                  <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><font color=#E66C2C>*</font>
+                         {else}
+                                  <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>
+                         {/if}
                      </li>
                    {/foreach}
                    {$empty|indent:$depth:"</ul></li>"}
 
alargule

Joined: 2010-01-09
Posts: 13
Posted: Sat, 2010-01-09 12:58

Thanks for the code, but it doesn't seem to work for me. I get the following error when trying to load my Gallery home page (www.nederlandmetro.nl):

Error

Item not found.

Back to the Gallery
Error Detail -
Error (ERROR_MISSING_OBJECT)

    * in modules/core/classes/GalleryStorage/GalleryStorageExtras.class at line 169 (GalleryCoreApi::error)
    * in modules/core/classes/GalleryStorage.class at line 298 (GalleryStorageExtras::loadEntities)
    * in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 71 (GalleryStorage::loadEntities)
    * in modules/core/classes/GalleryCoreApi.class at line 2259 (GalleryEntityHelper_simple::loadEntitiesById)
    * in modules/newitems/module.inc at line 120 (GalleryCoreApi::loadEntitiesById)
    * in modules/core/classes/GalleryTheme.class at line 1519 (NewItemsModule::getItemSummaries)
    * in themes/siriux/theme.inc at line 61 (GalleryTheme::loadCommonTemplateData)
    * in modules/core/classes/GalleryTheme.class at line 926 (SiriuxTheme::showAlbumPage)
    * in modules/core/classes/GalleryView.class at line 308 (GalleryTheme::loadTemplate)
    * in main.php at line 441 (GalleryView::doLoadTemplate)
    * in main.php at line 94
    * in main.php at line 83

System Information
Gallery version 	2.2.2
PHP version 	5.2.5 cgi
Webserver 	Apache
Database 	mysqlt 5.1.30-log
Toolkits 	Gd
Operating system 	Linux cash.awardspace.com 2.6.24.3 #4 SMP Thu Sep 10 13:08:39 UTC 2009 x86_64
Browser 	Mozilla/5.0 (Windows; U; Windows NT 6.0; nl; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7 (.NET CLR 3.5.30729)

Seems there's an error at line 120 in the module.inc file. That would be this line:

list ($ret, $childAlbums) = GalleryCoreApi::loadEntitiesById($childIds);

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Mon, 2010-01-11 14:54

The patch was written by a contributor more than two years ago for an old version of gallery which almost nobody is using any more so it's unlikely that anyone will be able to assist.

 
Lentil

Joined: 2007-04-06
Posts: 19
Posted: Tue, 2010-01-12 01:30

Despite the tact of the previous response, the author is essentially correct. Although this modification is running as written above in my 2.2.5 Gallery version, I have very little idea how to help you.

It appears that either the function isn't being found (I think that would result in a different error though) or you are getting an invalid result. This is designed to recurse through sub-albums... I'm assuming you do, in fact, have albums in your gallery.

I never got around to upgrading to 2.3, so I'm not sure what the patch would look like for that version. I may look at that soon for my own site, however.

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Tue, 2010-01-12 01:57

I wasn't aiming for tact. I do however know that it's disheartening to post a query and receive no reply whatsoever - not even an "I'm sorry but nobody can help with that." This applies especially for people new to Gallery (this was the first post by that person) who may not be aware that there isn't an army of developers waiting to leap on every problem nor know that the code he or she is trying to use has never been officially supported.

 
Lentil

Joined: 2007-04-06
Posts: 19
Posted: Tue, 2010-01-12 03:18

alargule: Again this may not be terribly helpful, but I just completed upgrading tot he latest stable Gallery release 2.3.1 including the latest "Newitem" module (1.0.8). After making the same modifications as posted above, the Updated tag appears as before on my albums. I can only assume that there is something wrong with your installation (or lucky about mine). Have you validated your installation with the Gallery 2 Upgrader?

Here is the '1.0.8.99' modified code for /modules/newitems/module.inc:

<?php
/*
 * Gallery - a web based photo album viewer and editor
 * Copyright (C) 2000-2008 Bharat Mediratta
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or (at
 * your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * Add new/updated image in summary info for new/updated items.
 * New sort option to put new items in front, follwed by another sort.
 * Thanks to Felix Rabinovich (virshu) for the idea.
 *
 * @package NewItems
 * @author Alan Harder <alan.harder@sun.com>
 * @version $Revision: 18172 $
 */
class NewItemsModule extends GalleryModule {

    function NewItemsModule() {
	global $gallery;

	$this->setId('newitems');
	$this->setName($gallery->i18n('New Items'));
	$this->setDescription($gallery->i18n('Highlight new/updated Gallery items CLS: and albums'));
	$this->setVersion('1.0.8.99');
	$this->_templateVersion = 1;
	$this->setGroup('display', $gallery->i18n('Display'));
	$this->setCallbacks('getSiteAdminViews|getItemSummaries');
	$this->setRequiredCoreApi(array(7, 27));
	$this->setRequiredModuleApi(array(3, 6));
    }

    /**
     * @see GalleryModule::upgrade
     */
    function upgrade($currentVersion) {
	if (!isset($currentVersion)) {
	    foreach (array('days.new' => '7',
			   'days.updated' => '7' )
		     as $key => $value) {
		$ret = $this->setParameter($key, $value);
		if ($ret) {
		    return $ret;
		}
	    }
	}

	return null;
    }

    /**
     * @see GalleryModule::performFactoryRegistrations
     */
    function performFactoryRegistrations() {
	$ret = GalleryCoreApi::registerFactoryImplementation(
	    'GallerySortInterface_1_2', 'NewItemsSortOrder', 'NewItems',
	    'modules/newitems/classes/NewItemsSortOrder.class', 'newitems', null);
	if ($ret) {
	    return $ret;
	}

	return null;
    }

    /**
     * @see GalleryModule::getSiteAdminViews
     */
    function getSiteAdminViews() {
	return array(null,
		     array(array('name' => $this->translate('New Items'),
				 'view' => 'newitems.NewItemsSiteAdmin')));
    }

    /**
     * @see GalleryModule::getItemSummaries
     */
    function getItemSummaries($items, $permissions, &$template) {
	list ($ret, $param) = GalleryCoreApi::fetchAllPluginParameters('module', 'newitems');
	if ($ret) {
	    return array($ret, null);
	}
	$time = time();
	$newTime = $time - $param['days.new'] * 86400;
	$updatedTime = $time - $param['days.updated'] * 86400;

	$newString = $this->translate('New');
	$updatedString = $this->translate('Updated');

	$summaries = array();
	foreach ($items as $item) {
	    if ($param['days.new'] > 0 && $item->getCreationTimestamp() > $newTime) {
		$summaries[$item->getId()] = '<span class="giNew">'
		    . $newString . '</span>';
	    } else if ($param['days.updated'] > 0
			&& $item->getModificationTimestamp() > $updatedTime) {
		$summaries[$item->getId()] = '<span class="giUpdated">'
		    . $updatedString . '</span>';
	    } else if ($param['days.updated'] > 0) {
			/* C. Schierer CLS 11 January 2010: Look at child (lower) items for update status */
			list ($ret, $childIds) = GalleryCoreApi::fetchDescendentItemIds($item);
			if ($ret) {
				return array($ret, null);
			}
			$sub_index=0;
			$max_index=count($childIds);
			/* If there are any children, Load them */
			if ($max_index>0) {
				list ($ret, $childAlbums) = GalleryCoreApi::loadEntitiesById($childIds);
				if ($ret) {
				return array($ret, null);
				}
				/* Check each child's modification date */
				while ($sub_index<$max_index) {
					if ($childAlbums[$sub_index]->getModificationTimestamp() > $updatedTime) {
						$summaries[$item->getId()] = '<span class="giUpdated">'
							. $updatedString . '</span>';
						$sub_index=$max_index+1;
					} 
					$sub_index++;
				} /* while */
			} /* End C. Schierer CLS mods */
		}			
	} 
		 
	return array(null, $summaries);
    }

    /**
     * @see GalleryModule::uninstall
     */
    function uninstall() {
	$ret = GalleryCoreApi::deleteSortOrder('NewItems');
	if ($ret) {
	    return $ret;
	}

	return parent::uninstall();
    }
}
?>

(I'm not sure why the code block is so narrow, but there is a scroll bar at the very bottom.)

 
alargule

Joined: 2010-01-09
Posts: 13
Posted: Wed, 2010-01-13 16:44

Hmm...I never realized I was using an old version of Gallery2. Should have come as no surprise, though, since I installed it over 2 years ago and never bothered to upgrade it.
I'll try upgrading first, and see if that makes any difference.

BTW: I believe the idea behind your mod is great - I've been searching for a recursive way to show which albums have been updated for quite some time.

 
alargule

Joined: 2010-01-09
Posts: 13
Posted: Wed, 2010-01-13 19:07

OK, I performed the upgrade to the most recent version - all went well - and put your most recent code into the module.inc - file.

Still getting the same error on the same line, though. Diving a bit deeper into the code, it seems to me $childIds is the culprit (missing object). I do have sub-albums, as you can see for yourself ;-)

 
Lentil

Joined: 2007-04-06
Posts: 19
Posted: Thu, 2010-01-14 01:23

alargule: What's strange is that $childIds is used as the argument to a function a few lines up. An empty $childIds causing issues is exactly why the $max_index check is there. I wonder what the $max_index value is. I suppose you could hack the code to return the $max_index number as the text for the album (instead of the "Updated" text) to do some troubleshooting.

 
alargule

Joined: 2010-01-09
Posts: 13
Posted: Thu, 2010-01-14 13:57

Odd thing is that it works fine in certain sub-albums, but throws an error in others. As you can see here for example, the page loads without an error. The album in which sub-albums have been updated ("Overige") displays the 'updated' tag with the number of child items in it, as per your suggestion in the post above.

However, if I want to move up one album, I get the error mentioned before.

Now, I may be onto something: I opened up the ChildEntity table in the database and looked up all the children with parentId 99 (the id of the album that loads fine), and I found out that it displays FIVE children, instead of the four you can see and might have expected.

As it turns out, the fifth one is the Id of a derivative image. The documentation for the function loadEntitiesbyId in the GalleryCoreApi class says:

Quote:
If the loaded entities don't extend the requred entity type, you'll get an
ERROR_MISSING_OBJECT.

When trying to load the page which points to that entity, I get the following error:

Error (ERROR_MISSING_OBJECT) : Entity with id [5526] is a [GalleryDerivativeImage] and does not extend the required entity type [GalleryItem].
in modules/core/classes/helpers/GalleryEntityHelper_simple.class at line 129 (GalleryCoreApi::error) 
in modules/core/classes/GalleryCoreApi.class at line 2361 (GalleryEntityHelper_simple::loadEntitiesById) 
in modules/core/classes/GalleryView.class at line 356 (GalleryCoreApi::loadEntitiesById) 
in modules/core/ShowItem.inc at line 106 (GalleryView::getItem) 
in modules/core/ShowItem.inc at line 61 (ShowItemView::getItem) 
in modules/core/classes/GalleryView.class at line 293 (ShowItemView::loadTemplate) 
in main.php at line 465 (GalleryView::doLoadTemplate) 
in main.php at line 104
in main.php at line 88

Unfortunately, my php-knowledge is next to nothing. I seriously wouldn't know how to get around this...

 
Lentil

Joined: 2007-04-06
Posts: 19
Posted: Fri, 2010-01-15 02:42

Yeah, you're pretty much getting beyond me too. I suppose there's two ways to attack this:
A) Remove the derivatives from the $childIDs before the loadEntitiesbyID call
B) Handle the error gracefully and keep going.

I found this post where somebody else was dealing with the same error, although their circumstance might not be appropriate for us: http://gallery.menalto.com/node/77181

Searching for "does not extend the required entity type" results in quite a few hits in the forums, with resolutions that span from database errors to coding problems. I'm not clear on why you would have a "GalleryDerivativeImage" just sitting as a child of an album... isn't this the class for thumbnails?

Looking at the API for loadEntityByID I see that it takes an optional (soon to be mandatory) second argument. 'GalleryEntity' is the option to accept everything... perhaps this will help? I would test it, but then I can't make your problem happen. I suppose if I knew how to create a "GalleryDerivativeImage" in one of my albums...

Regardless, I made the following modifications to incorporate the second argument:
38 becomes: $this->setVersion('1.0.8.100');
121 becomes: list ($ret, $childAlbums) = GalleryCoreApi::loadEntitiesById($childIds,'GalleryEntity');

This produced the same behavior as before (for me). I also thought to replace GalleryCoreApi::fetchDescendentItemIds($item) with GalleryCoreApi::fetchDescendentAlbumItemIds($item) to avoid loading any objects but albums (since that will be sufficient recursion to get the update info). This might 'evade' the Derivatives.

38 becomes: $this->setVersion('1.0.8.101');
Line 113 becomes: list ($ret, $childIds) = GalleryCoreApi::fetchDescendentAlbumItemIds($item);

I'm now running both changes (1.0.8.101) and it behaves the same as before for me. Maybe you'll have some improvement?

 
alargule

Joined: 2010-01-09
Posts: 13
Posted: Fri, 2010-01-15 09:54

Well what do you know: it works! :D

Lentil: thank you for your quick support and your patience!

 
alargule

Joined: 2010-01-09
Posts: 13
Posted: Mon, 2010-11-15 18:50

Okay, it's been a while since I've posted here.
The above modification has been working great so far. :)
However, I've found out that it will display all updates that have been made to photo items or album items. E.g. when I change the the name of a map, or even the template, the map and all its parents will be tagged as 'updated'.
I would like the 'update' tag to only show when new album or photo items have been added to a parent album. Is there any way that I could do that? I've tried:

list ($ret, $childIds) = GalleryCoreApi::fetchDescendentItemIds($item, 'GalleryPhotoItem');

instead of

list ($ret, $childIds) = GalleryCoreApi::fetchDescendentItemIds($item);

...but that doesn't really seem to do the trick.

Edit: never mind, problem solved! :)