(Solved) "Last Changed Date" for parent albums

demeli

Joined: 2006-01-25
Posts: 2
Posted: Wed, 2006-01-25 19:36

Hey,

My situation:
I have a toplevel album with subalbums. Each of those subalbums has more subalbums. The toplevel album has its sort order set to "Last Changed Date - Decending." I figured that when someone adds something to a nested subalbum, the last changed date would update itself all the way up to the toplevel album, which aparently isn't the case.

Could someone give me a pointer as to where I would have to add my custom code to do this and what the function for changing the "Last Changed Date" is? I'm using a G2.1 snapshot from 23/Jan/2006.

My guess is that it would work similar to this pseudocode (which was aparently how it was done in G1):

function SomeFunction() {
 $album = GetCurrentAlbum();
 $album->SetLastChangedDate(time());
 while ($album->hasParents()) {
  $album = $album->getParent();
  $album->SetLastChangedDate(time());  
 }
}

Thanks!!

//Demeli

 
dotnature
dotnature's picture

Joined: 2005-10-26
Posts: 224
Posted: Wed, 2006-01-25 20:54

maybe check out your themes album.tpl, its where the date is called and displayed for your albums

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2006-01-26 01:21

search for "addShutdownAction" in modules/core/classes/GalleryItem.class
you'll find a couple places there that update the parent modification timestamp.
check GalleryCoreApi.class for apis to get all the ancestor ids..

 
demeli

Joined: 2006-01-25
Posts: 2
Posted: Thu, 2006-01-26 17:25

I've managed to implement it and it seems to be working perfectly.

For sake of completion, here's the code I used. (It goes into modules/core/classes/GalleryItem.class, line 436)

if ($isNew) {
 list ($ret, $parents) = GalleryCoreApi::fetchParents($this);
 if ($ret) {
  return $ret->wrap(__FILE__, __LINE__);
 }
 foreach ($parents as $item) {
  $gallery->addShutdownAction(array('GalleryCoreApi',
  'updateModificationTimestamp'), array($item->getId()));
 }
}

Thanks again for your help.

EDIT: 27/Jan - Updated code to adapt to G2 coding style. That should make this hack be able to survive more API changes. :)

 
mindless
mindless's picture

Joined: 2004-01-04
Posts: 8601
Posted: Thu, 2006-01-26 20:10

cool, glad you got it to work!

list ($ret, $parents) = GalleryCoreApi::fetchParents($this);
is the proper call.. a $ret value of NULL means success, non-null is an error..
also we generally use $item->getId() rather than direct access to ->id
these are just coding style things....