Using exhibit_builder_exhibit_display_caption() within item.php

Hi,

I'd like to use exhibit_builder_exhibit_display_caption() within the exhibit-builder/exhibits/item.php template. Is this possible?

I've tried and nothing seems to happen, not even an error.

Thanks in advance for any help :)

The problem is, the caption function, along with many other ExhibitBuilder functions, is designed to work on an exhibit page (in a layout, for example).

On the "show item" page, that function doesn't have access to the data it needs to read the caption.

That's disappointing. There's no way to do it, even though that data is in the database?

In _theory_ it can be done, but it would require some complex work to dig it directly out of the database. You would need to dig up two things: the ExhibitPage for the item, and what the index of the item on the page is. If you have those, you can plug them into the exhibit_builder_page_caption function (which is called by exhibit_builder_exhibit_display_caption) to get the caption itself.

This code should get you the ExhibitPage (usually $exhibitPages is an array with 0 or 1 elements)

$db = get_db();
        $itemId = $this->record->id;
        $select = "	SELECT DISTINCT sp.* FROM $db->ExhibitPage sp
                    INNER JOIN $db->ExhibitPageEntry epe ON epe.page_id = sp.id
                    WHERE epe.item_id = $itemId ";
        $exhibitPages = $db->getTable('ExhibitPage')->fetchObjects($select);

To get the index, you'd need to look through the ExhibitPageEntries that are attached to the ExhibitPage, looking for the entry that corresponds to the item on your page. Something like:

//untested code! beware!
$entries = $exhibitPage->getPageEntries();
$index = 0;
foreach($entries as $i=>$entry) {
    if($entry->item_id == $item->id) {
        $index = $i;
        break;
    }
}

Then this should give you the raw caption text:

$caption = exhibit_builder_page_caption($index, $exhibitPage);

That's the theory, at least. Haven't tested it, but that's my guess for how to tackle it.

Thank you. That's a little over my head, but I have a backend developer who I can bother to help me with it.

If you're curious, I think future versions of Omeka and Exhibit should have this functionality. We're attempting to have one install of Omeka and multiple exhibits (via the Exhibit Builder plugin) that share the same items. We're weary to use the the Description field in the items metadata because different exhibits may have different descriptions. Our solution is to use the caption field, ideally. Then we can have an exhibit specific description for the item.

Of course, if there's a more intelligent solution, I'm all ears, err, eyes.

Thanks. We are giving Exhibit Builder an overhaul, and the relationship between different items and exhibit pages is high on our minds.

One tricky thing in the scenario you describe, though. If we were to show captions on an item page, we would have to show all of them, which might make the user interface and navigating between an item page and an exhibit page confusing.

That said, something new that tries to tackle these issues is on its way!

Hey we got this to work.

custom.php:


function exhibit_builder_page_caption_for_item($itemId)
{

$db = get_db();
$select = " SELECT DISTINCT sp.* FROM $db->ExhibitPage sp
INNER JOIN $db->ExhibitPageEntry epe ON epe.page_id = sp.id
WHERE epe.item_id = $itemId ";
$exhibitPage = $db->getTable('ExhibitPage')->fetchObject($select);

$entries = $exhibitPage->getPageEntries();

$index = null;

$caption = '';

foreach($entries as $i=>$entry) {
if($entry->item_id == $itemId) {
$index = $i;
break;
}
}
if($index != null){
$caption = exhibit_builder_page_caption($index, $exhibitPage);
}

return $caption;
}

exhibit-builder/exhibits/item.php:


<?php echo exhibit_builder_page_caption_for_item($item->id); ?>

Thanks again for the help!

Great! Well done!