get active item id

profix898

Joined: 2005-11-08
Posts: 135
Posted: Thu, 2007-03-01 15:12

The title says it all:
Is there any API method (GalleryCoreApi) to receive the itemID of the active (currently viewed) album/photo?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2007-03-01 16:25

in the .tpl files, you can use {$theme.item.id} to print the id.

you might also be interested in the formatted urls (geturls) module which shows bbcode, the item id and other stuff.

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

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Thu, 2007-03-01 16:52

Thanks for your fast reply. But I was actually not talking about the theme layer, {$theme.item.id} doesnt help. I'm trying to get the active itemID in embedded mode (but also tried from a module) to trigger a custom operation based on the current item id. I already tried the 'fetchItemIdByPath()' method, but I'm always getting an error from it (what is 'a complete logical path' (from api docs) in this context?) ... Is the item id stored in a variable? Can I use the getPluginParameter method?

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Mon, 2007-08-20 18:08

Function fetchItemIdByPath() sounds exactly what I'm looking for. However I cant figure out how to use it. Does anyone know how the parameters should be like? The API docs on codex are not very helpful on this function.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2007-08-23 10:58

- GalleryEmbed::handleRequest() returns 'themeData' which includes the itemId
- @GalleryCoreApi::fetchItemIdByPath():
you can use it like: list ($ret, $id) = GalleryCoreApi::fetchItemIdByPath('albumA/subAlbumB/fileC.jpg');

not sure if it needs a leading slash or not, you'll find out. :)
it will return a ERROR_MISSING_OBJECT error if the path doesn't resolve to any item. else it returns the id of the item at that path.

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

 
profix898

Joined: 2005-11-08
Posts: 135
Posted: Thu, 2007-08-23 13:44

Great news. Thanks a lot! I will be joining the #gallery channel later to ask some more questions about G2 internals.

 
Miss Universum
Miss Universum's picture

Joined: 2008-06-16
Posts: 40
Posted: Wed, 2008-07-23 17:29

I just wanted to share my 2cent code for that one and follow up with a question... In an embedded environment, to set the title, I use the following code which displays the name of the album in the title (if it's an album, it just takes it, if it's an image it looks for its parent).

[code]
$g2moddata = GalleryEmbed::handleRequest();
if ($g2moddata['themeData']['item']['canContainChildren']) {
$pageTitle = $title;
} else {
$curPar = end($g2moddata['themeData']['parents']);
$pageTitle = $curPar['title'];
}
[code]

concerning fetchItemIdByPath, is there also a function doing the opposite? I would like to link to my images from outside and I can look up the ID from the database but then I would like to do a redirect to the "speaking" url, not to the id driven one...

cheers
MU

 
patman362

Joined: 2009-04-08
Posts: 1
Posted: Wed, 2009-04-08 02:11

It was driving me nuts not being able to figure out what a logical path for gallery was. Finally I have figured it out. Here is an example including one important detail:

list ($ret, $id) = GalleryCoreApi::fetchItemIdByPath('/albumA/subAlbumB/fileC.jpg');

Remember the slash at the beginning of the path. The method will recognize the first slash as the root album and you can then start putting in albums/filenames from there. Hope this helps someone.