Get original photo of an album highlight

aymerick

Joined: 2005-11-30
Posts: 3
Posted: Wed, 2005-11-30 14:47

Hi,

I'm searching a simple way, given an album ID, to get the original photo of the album highlight.

As far as i understand, I'm searching a way to:
- Get the thumbnail of the album (which is the 'highlight')
- Find the original photo that produced this thumbnail

Is there already a simple function that does the job ? I haven't found.

Thanks,
Aymerick

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-30 15:25

please don't post multiple topics for the same question. topic locked.

edit: sorry, confused your username with another. the same question was asked twice today.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Wed, 2005-11-30 15:29

GalleryCoreApi::fetchThumbnailsByItemIds
see developers -> G2 API docs, or just take a look at modules/core/classes/GalleryCoreApi.class

to find the original photo:
$sourceEntity = $derivative->getSourceId();

$sourceEntity can be either a GalleryPhotoItem or a GalleryDerivative

$derivative->getParentId() returns the id of the album (the id for which this derivative is used).

 
ruzster

Joined: 2006-05-30
Posts: 11
Posted: Fri, 2006-06-16 15:37

I'm having trouble figuring this one out. I don't suppose someone could provide an example? Please?

 
ruzster

Joined: 2006-05-30
Posts: 11
Posted: Fri, 2006-06-16 16:13

Actually... nevermind. I think I got it.

But now I'm getting this error: "Warning: Cannot use a scalar value as an array in <my directory>/gallery/modules/core/classes/GalleryPhotoItem.class on line 236"

 
cc5henry

Joined: 2006-06-15
Posts: 12
Posted: Sat, 2006-06-17 21:04
ruzster wrote:
Actually... nevermind. I think I got it.

But now I'm getting this error: "Warning: Cannot use a scalar value as an array in <my directory>/gallery/modules/core/classes/GalleryPhotoItem.class on line 236"

Did you adjust the code? Because it says <my directory> or is it just to not reveal ur domain?

 
ruzster

Joined: 2006-05-30
Posts: 11
Posted: Sun, 2006-06-18 04:14

Yes, I hid my domain.

 
Umka

Joined: 2008-06-16
Posts: 12
Posted: Mon, 2008-06-16 18:26

Greetings to all!

Dear forum members, I encounter the same problem and can't solve it myself.

I am making a theme for the Gallery2 (I use "tiny" installation) which supposed to behave this way: I click the root album thumbnail, then go to that album, then i click nested album thumbnail, but if album I clicked is the last one (no more nested albums detected), then I skip clicked "album" page, and go directly to the original image "photo" page, from which album thumbnail is made (highlighted image). Or, as an option, to the first item in that album, and again to the "photo" page, not album view. So I need to simply find item id which i would use in album thumbnail link, to skip album and go directly to the image. (Or as an option id of first item in clicked album)

I decided to solve the "highlighted item link" problem first. I read topic above, and tried to modify my theme.inc, but when it came to this:

Quote:
$sourceEntity = $derivative->getSourceId();

I stuck. I would appreciate any help on this, may be some source code.

Thanks in advance and sorry for my English, it's my second.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2008-06-17 01:04

- to decide whether the link should point to an album page or a photo page, you need to find out whether the album has any sub-albums. you can use GalleryCoreApi::fetchChildAlbumItemIds( ... ) in your theme.inc function showAlbumPage for that. if it returns more than 0 child albums for the id you're testing against, you can generate a link to an album page. else query for the album's highlight item to generate a link to that item's photo page.

- to get the item id of the album's highlight, you need to do the following:
the problem is that a album's highlight image is not necessarily derived from any item / photo within the album. the highlight image might be a custom thumbnail. (see "thumbnail" module).
so you need to handle multiple cases:
a) the highlight's source is an item within the album: generate a link pointing to that item in the album.
b) the highlight's source is a custom thumbnail: generate a link pointing to the first item in the album. (fallback case)

- from the album itemId you get the album's thumbnail id (=highlight id): fetchThumbnailsByItemIds($albumId)
-- if the album has no highlight ($highlightId == null / not set), you need to fall back to loading the album's first item
- from the highlight id you can load the highlight entity object: loadEntitiesById($highlightId)
- from the $highlight entity object you get its source id with $sourceId = $highlight->getDerivativeSourceId();
- with the following code you get to the actual photo item...if there is one.

do {
    list ($ret, $source) = GalleryCoreApi::loadEntitiesById($source->getDerivativeSourceId());
} while (GalleryUtilities::isA($source, 'GalleryDerivative'));

if (GalleryUtilities::isA($source, 'GalleryItem') && $source->getParentId() == $albumId) {
    $itemIdForUrl = $source->getId();
} else {
    // fall back to the first child item of the album
    // e.g. use GalleryCoreApi::fetchChildIds() to get the album's children.
}

--------------
Documentation: Support / Troubleshooting | Installation, Upgrade, Configuration and Usage

 
Umka

Joined: 2008-06-16
Posts: 12
Posted: Tue, 2008-06-17 01:59

Thank you very much for your explanation. I'm starting to understand.

I'm planning to end up with code that adds "thumbnailSourceId" variable to every "$children" array that contains thumbnails, and my major roadblock removed. I'll post my final result.

 
Umka

Joined: 2008-06-16
Posts: 12
Posted: Tue, 2008-06-17 15:13

Might be clumsy, but works for me. (Gallery 2.2.5)

list ($ret, $thumbs) = GalleryCoreApi::fetchThumbnailsByItemIds($childIds);
if ($ret) {
   return array($ret, null);
}
$counter = 0;
foreach ($childIds as $child) {
   if ($theme['children']){
      if ($theme['children'][$counter]['canContainChildren'] == 1) {
         list ($ret, $childEntity) = GalleryCoreApi::loadEntitiesById($child);
         list ($ret, $subChildren) = GalleryCoreApi::fetchChildItemIds($childEntity);
         if (count($subChildren) > 0 && $counter < count($thumbs)){
            list ($ret, $derivativeThumbnailObject) = GalleryCoreApi::loadEntitiesById($thumbs[$child]->getDerivativeSourceId());
            $theme['children'][$counter]['thumbnailSourceId'] = $derivativeThumbnailObject->getParentId();
         }
      }
   }
   $counter++;
}

Thanks for help.

P.S. Updated since my last post.