a query that get all the images from an album

Anonymous Coward (not verified)

Posted: Sun, 2008-01-13 11:12

Hi all!
I'm trying to create a little plugin for the french CMS SPIP.
I'm not using the integration API provided by Gallery2, because I only need to retrieve images from the albums, and I don't need to integrate the others Gallery's functions.

Could someone suggest me the correct syntax of a SQL query than can select all the images belonging to a given album?

Thanks a lot.
Bye

 
alecmyers

Joined: 2006-08-01
Posts: 4342
Posted: Sun, 2008-01-13 14:26

SELECT [GalleryPhotoItem::id] FROM [GalleryPhotoItem] INNER JOIN [GalleryChildEntity]
WHERE [GalleryPhotoItem::id] = [GalleryChildEntity::id]
AND [GalleryChildEntity::parentId] = <put the album id here>

You'll need to convert Gallery's internal SQL-like code to the syntax of whichever database your gallery is using, including changing the Table prefixes from Gallery... to (by default) g2_... and add g_... as the default column prefix as well.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Sun, 2008-01-13 15:21

but the API makes things a lot easier...

see: docs -> maintenance -> how to write scripts.
- init G2 by including embed.php and calling GalleryEmbed::init().
- load the album: list ($ret, $albumItem) = GalleryCoreApi::loadEntitiesById($id=7); // param is the integer id of some album item
- get the ids of the children: list ($ret, $childIds) = GalleryCoreApi::fetchChildItemIds($albumItem);
- now you can load thumbnails, resizes or the original size images: ...
- to get the titles, descriptions of the images, load their objects: list ($ret, $children) = GalleryCoreApi::loadEntitiesById($childIds);
foreach ($children as $child) { print $child->getTitle(); } // etc.
- to get a URL to an image file (thumb, resize or original size):
$urlGenerator =& $gallery->getUrlGenerator();
$url = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $thumbnail->getId(), 'serialNumber' => $thumbnail->getSerialNumber())); // image URL
$url = $urlGenerator->generateUrl(array('view' => 'core.ShowItem', 'itemId' => $child->getId())); // HTML page URL

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

 
ubik15 (not verified)

Posted: Sun, 2008-01-13 16:14

Thanks a lot.
I'll try the API.

 
ubik15 (not verified)

Posted: Sun, 2008-01-13 18:08

I need help in using the API...

Where should I find an easy tutorial about API use?

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Tue, 2008-01-15 23:29

- see: docs -> maintenance -> how to write scripts.
- development (link in the top right)
- existing code. take a look at modules/core/*.inc, modules/core/*/helpers/*

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

 
ubik15 (not verified)

Posted: Wed, 2008-01-16 08:31

Thanks valiant.
I'm in a hurry with this plugin, so Your help is very appreciated.

 
ubik15 (not verified)

Posted: Sun, 2008-01-20 11:01

I've managed to use the API, but I still have problems in getting an image thumbnail.
I'm a little confused about the three Thumbnail classes (Helper, Toolkit and Image).
Well, what should I do to get a thumbnail from a GalleryEntity object?

Thanks.

 
ozgreg
ozgreg's picture

Joined: 2003-10-18
Posts: 1378
Posted: Tue, 2008-02-12 10:44

ubik15,

Grab a copy of one of the embedded applications, ie WPG2 and have a look at how we have done it.. If you are looking at say the WPG2 / G2image then you can see how the code works by looking into the g2image.php - function g2ic_get_item_info($item_id) but as a hint list($error, $thumbnails) = GalleryCoreApi::fetchThumbnailsByItemIds(array($item->getid())); will help ;)

____________________________________
Wordpress / Gallery2 (WPG2) Plugin, , WPG2 Documentation, WPG2 Demo

 
xpla

Joined: 2006-03-06
Posts: 25
Posted: Sun, 2008-03-02 12:53
valiant wrote:
but the API makes things a lot easier...

see: docs -> maintenance -> how to write scripts.
- init G2 by including embed.php and calling GalleryEmbed::init().
- load the album: list ($ret, $albumItem) = GalleryCoreApi::loadEntitiesById($id=7); // param is the integer id of some album item
- get the ids of the children: list ($ret, $childIds) = GalleryCoreApi::fetchChildItemIds($albumItem);
- now you can load thumbnails, resizes or the original size images: ...
- to get the titles, descriptions of the images, load their objects: list ($ret, $children) = GalleryCoreApi::loadEntitiesById($childIds);
foreach ($children as $child) { print $child->getTitle(); } // etc.
- to get a URL to an image file (thumb, resize or original size):
$urlGenerator =& $gallery->getUrlGenerator();
$url = $urlGenerator->generateUrl(array('view' => 'core.DownloadItem', 'itemId' => $thumbnail->getId(), 'serialNumber' => $thumbnail->getSerialNumber())); // image URL
$url = $urlGenerator->generateUrl(array('view' => 'core.ShowItem', 'itemId' => $child->getId())); // HTML page URL

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

YOU MADE MY DAY, THANK YOU SO MUCH!