Item Relations plugin

I’m trying to use the Item Relations plugin but cannot figure out the php syntax to display metadata elements of related items. For example, I am able to display the titles, ids, etc. of the related items as specified in ItemRelationsPlugin.php file in this snippet.

        foreach ($objects as $object) {
            $objectRelations[] = array(
                'item_relation_id' => $object->id,
                'subject_item_id' => $object->subject_item_id,
                'subject_item_title' => self::getItemTitle($object->subject_item_id),
                'relation_text' => $object->getPropertyText(),
                'relation_description' => $object->property_description
            );
        }
        return $objectRelations;

This is a very limited selection of elements for related items. How can I display any Dublin Core elements like title of creator or the image file? I tried to copy these php snippets from my ordinary show page but that didn’t work.

<?php echo metadata('item', array('Dublin Core', 'Title')); ?>

I’ve been trying countless variations and searched forums and the wider web. There is very little documentation on plugin use. Perhaps I’m not searching the right places.

Replace the 'item' in metadata by the true $item:

foreach ($relatedItems as $relatedItem) {
    echo metadata($relatedItem, array('Dublin Core', 'Title')); 
}

'item' means the main item of the page, if any.

Thanks for the input. I changed the code to match and still ended up getting this message:
Warning: Invalid argument supplied for foreach() in /home/brryan/provath.dreamhosters.com/themes/pvdAth/items/show.php on line 134
Line 134 being the foreach line.

My answer was a little short. In fact, you have to get the whole item subject for each relation:

$objectRelations[] = array();
foreach ($objects as $object) {
    $objectRelations[] = array(
        'subject' => get_record('Item', $object->subject_item_id),
        'item_relation_id' => $object->id,
        'subject_item_id' => $object->subject_item_id,
        'subject_item_title' => self::getItemTitle($object->subject_item_id),
        'relation_text' => $object->getPropertyText(),
        'relation_description' => $object->property_description
    );
}

Then for each relation, you can do:

foreach ($objectRelations as $objectRelation) {
    echo metadata($objectRelation['subject'], array('Dublin Core', 'Title')); 
    echo metadata($objectRelation['subject'], array('Dublin Core', 'Creator')); 
}

My first guess is that for the particular item, there might not be any related items. So, does this happen for all items, and can you manually check whether there really are related items for it?

If it works when you are sure that there are related items, but not when there aren’t, a quick check for whether the $relatedItems array has data might do the trick:

if (! empty($relatedItems)) {
    foreach ($relatedItems as $relatedItem) {
        echo metadata($relatedItem, array('Dublin Core', 'Title')); 
    }
}

Ok, so now I am really confused. Should the php code go in the item-relations-show.php or the show.php used for all items? Does it go on the page inside the Item Relations plugin and then get called through php on the show.php in some manner like the footer gets called:

<?php echo foot(); ?>

different syntax of course

1 Like

I’m in a similar problem. I want to display the related item’s image in the item’s show page, but i can’t access the related item. When I use the built-in hook there is no problem, it displays de relation with a link pointing to the item:

echo get_specific_plugin_hook_output('ItemRelations', 'public_items_show', array('view' => $this, 'item' => $item));
But I haven’t figured out how to access the related items image, to display it in the item/show,php view of my theme.

I hope someone can point me in the right direction

thanks

This topic was automatically closed after 250 days. New replies are no longer allowed.