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
Posts: 8601
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
Posts: 69
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
This isn't correct code but it's meant to be an idea...
Posts: 19
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:
Posts: 8601
don't call loadEntitiesById in the case where $childIds comes up empty.
Posts: 19
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:
Posts: 19
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.
Posts: 13
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
Posts: 19
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.
Posts: 13
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)
Posts: 31
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.
Posts: 9
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).
Posts: 13
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):
Seems there's an error at line 120 in the module.inc file. That would be this line:
list ($ret, $childAlbums) = GalleryCoreApi::loadEntitiesById($childIds);
Posts: 4342
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.
Posts: 19
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.
Posts: 4342
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.
Posts: 19
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:
(I'm not sure why the code block is so narrow, but there is a scroll bar at the very bottom.)
Posts: 13
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.
Posts: 13
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 ;-)
Posts: 19
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.
Posts: 13
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:
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...
Posts: 19
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?
Posts: 13
Well what do you know: it works! :D
Lentil: thank you for your quick support and your patience!
Posts: 13
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!