Thumbnails on Browse Exhibits page

Hello,

Had a requirement to show thumbnails for exhibits (using the first image in the exhibit), but couldn't find any particular code to do it. Nancy Moussa sent out code on omeka-dev that would grab an image only from the first page. This code will iterate through the pages and grab the first image. Hope it is useful to someone...

$imgurl = "";

foreach ($exhibit->Sections as $exhibitSection)
{
// echo "\n <!-- get next section -->";
if ($exhibitSection->hasPages())
{
foreach ($exhibitSection->Pages as $exhibitPage)
{
// echo "\n <!-- get next page, " . $exhibitPage->title . " -->";
for ($i = 1; $i <= count($exhibitPage['ExhibitPageEntry']); $i++)
{
$item = exhibit_builder_page_item($i, $exhibitPage);
// echo "\n <!-- get next item, has " . count($item->Files) . " files -->";

if (count($item->Files) > 0)
{
foreach ($item->Files as $file)
{
// echo "\n <!-- get next file, mime type: " . $file->getMimeType() . " -->";
if ($file->hasThumbnail())
{
$imgurl = $file->getWebPath('fullsize');
break;
}
}
}
if ($imgurl != "") break;
}
if ($imgurl != "") break;
}
}
if ($imgurl != "") break;
}

Walt Rice
WaltRiceJr@gmail.com

Hey there! So forgive me, I am a .net programmer in training and am still picking up some of the ropes with php, but is this code compatible with omeka 2.0? foreach ($exhibit->Sections as $exhibitSection) would $exhibit require that you first defined $exhibit = get_current_record('exhibit');? I am trying to do something like this where I pull 8 random thumbnails from my exhibit and for some reason omeka is not pulling the array to loop. Thanks for looking! "Warning: Invalid argument supplied for foreach() in......../browse.php on line 46"

I updated this code for 2.0, and will post it as soon as I am able. If I remember correctly, there are no more sections in 2.0 exhibits. Everything is a page, and pages can be nested. So you have to do a recursive iteration through the pages.

However, if you just want random thumbnails, there should be a way to grab all the items in the exhibit, separate from the page hierarchy, and work with that instead.

Hey thanks Walt, I was skeptical if I would get any response at all from a 11 month old post, but that was quick! Ok so in order to find the helper to pull the images would one be studying the exhibit builder plugin or farther up the hierarchy. All of the explicit documentation I am finding is in reference to old code that has been depreciated.

You'd be looking at the exhibit builder plugin. For the latest Exhibit Builder, you'd have to drill all the way down to block attachments to each block on each page.

Or, you could modify this code for getting a single file for an exhibit, which will be part of the next release of Exhibit Builder

$db = $this->getDb();
        $fileTable = $this->getDb()->getTable('File');
        $select =
            $fileTable->getSelect()
            ->joinInner(
                array('eba' => $db->ExhibitBlockAttachment),
                'eba.file_id = files.id',
                array()
            )
            ->joinInner(
                array('epb' => $db->ExhibitPageBlock),
                'epb.id = eba.block_id',
                array()
            )
            ->joinInner(
                array('ep' => $db->ExhibitPage),
                'ep.id = epb.page_id',
                array()
            )
            ->where('ep.exhibit_id = ?', $this->id)
            ->where('files.has_derivative_image = 1')
            ->order(array('ep.order', 'ep.parent_id', 'epb.order', 'eba.order'))
            ->limit(1);

        return $fileTable->fetchObject($select);

Man this is great stuff Patrick, I'll see if I can find a way to merge it into exhibit builder, how far out is the new plugin if I might ask? Being able to set image previews of the exhibit or a set of random images would really go a long way in finishing this site.

Not entirely sure, since we need to do some internal testing, but I'd guess on a scale of a few weeks

Well a few weeks is well within my timeline, if it happens I will be extremely grateful, not that I'm not already :) I do plan on tinkering once I finish my finals this week though. Zend is one hell of a beast to try and take in all at once, I'm considering reading some books to try and get a better hang on the syntax, any recommended reading(preferably with ample example code)?.

Diving all the way into Zend can indeed be disorienting! Most of what Omeka does sits high enough on top of it, though, that it is fairly rare that developers need to directly reach down into Zend stuff (though we do try to follow Zend patterns as best we can).

So, most of my Zend knowledge just comes from their tutorials. To see more Omeka-specific workings, see our docs (always a work in progress)

Thanks man! I do have to say I have been pouring over those docs. They are a pretty big help :)