Calling Repeated Fields

Hello!

I have entered metadata in repeating fields for some elements, but I'm having trouble reaching that metadata with php. I'm hoping someone can help.

I have been customizing my items/show.php file to call related items, using a custom Item Type Metadata field called SourceIdentifier, which is based on the object's accession number (I probably could have used the Dublin Core field Relation in this way, but my SourceIdentifier element attempts to do that without manually entering all the reciprocal relationships). The way I've been using this works very well when it's a one-to-many relationship, mainly one item is a Physical Object that has many related Still Images. I've been doing it that way so that ALL images are available to the Exhibit Builder. I understand that may no longer be necessary with 2.0, but it's also important for me to be able to make some related images public and others not - so, a separate issue is, can you make some of the attached files for an object public, and others private? In some cases I have around a hundred images related to an object, so I need to be able to have more granular control over each image, with metadata for each image, that I can easily import and export.

Now I'm importing some images that represent more than one object (group photos from an exhibition), so I'm getting into many-to-many relationships. I need to be able to relate these group photos to each of the items that is represented in the photo (which each have other related items). Using my SourceIdentifier field, I should be able to do that without manually entering the relationship in the original item (that's the extra labor that I'm trying to avoid). I first had this as comma separated values in one element entry, but that doesn't seem to work at all, as it seems to require an exact match. It seemed more logical to enter this as repeated fields. However, my attempt to call all of these with php seems to only call the first of the repeats. I've been searching all over trying to find if this is a php issue or an Omeka issue - anything I know about php I've learned from reverse engineering, and I can't find a working example of this to reverse engineer.

So, this item - http://vcomeka.com/vccc/items/show/2773 properly shows the first of the 3 related objects, but not the other 2 (and my layout needs some help, but one thing at a time). Here's the script for the call for related items - the script is pretty clunky in general, so if you have any suggestions for improvement, even outside of this specific question, I'd be very grateful - I'm only copying the first part of the code, for the sake of brevity:

<!-- begin related items - this will display all items related to physical objects, using the source identifier field-->
<div id="item-relateditems" class="element" >
<div class="item-entry">
<?php
$currentid = item('ID');
$source = item('Item Type Metadata', 'Source Identifier');?>

<h6>Related Objects:</h6>

<!-- insert an if statement to see if it's empty-->
<?php if (item('Item Type Metadata', 'Source Identifier') !=''): ?>

<?php
$physicalobjects = get_items(array('type' => 'Physical Object'),5000);
set_items_for_loop($physicalobjects);
while(loop_items()):
?>
<?php if (item('Item Type Metadata', 'Source Identifier') == $source): ?>

<?php if (item_has_thumbnail()): ?>
<div class="item-nimg">
<?php echo link_to_item(item_square_thumbnail()); ?>
</div>

<?php endif; ?>

<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>

<p style="clear:both">
</p>

<h6>Related Images:</h6>

<!-- insert an if statement to see if it's empty-->
<?php if (item('Item Type Metadata', 'Source Identifier') !=''): ?>

<?php
$stillimages = get_items(array('type' => 'Still Image'),5000);
set_items_for_loop($stillimages);
while(loop_items()):
?>

<?php if (item('Item Type Metadata', 'Source Identifier') == $source): ?>

<?php if (item_has_thumbnail()): ?>
<div class="item-nimg">
<?php echo link_to_item(item_square_thumbnail()); ?>
</div>

<?php endif; ?>

	<?php endif; ?>

<?php endwhile; ?>
<?php endif; ?>

<p style="clear:both">
</p>

If you have any ideas of how to solve my problem of calling repeated fields, I'd love to hear them! Thank you so much for your help!

-Arden

The item function (now metadata in Omeka 2.0), by default will only display the first piece of metadata if there are multiple ones. It's designed to make it easy for doing things like printing titles in headings or putting together tables of information.

However, you can easily tell item to output all the pieces of metadata of the type you're asking for. The documentation for item will tell you about the "all" and "delimiter" options.

There's even a section of that page specifically for displaying multiple values.

Thank you so much, John! I had seen that, but I didn't quite understand how to make it work with this example. I'm trying it out, but it still doesn't quite work:

<?php
$currentid = item('ID');
$source = item('Item Type Metadata', 'Source Identifier');?>

<h6>Related Objects:</h6>

<!-- insert an if statement to see if it's empty-->
<?php if (item('Item Type Metadata', 'Source Identifier') !=''): ?>

<?php
$physicalobjects = get_items(array('type' => 'Physical Object'),5000);
set_items_for_loop($physicalobjects);
while(loop_items()):
?>
<?php
    $relatedItems = item('Item Type Metadata', 'Source Identifier', array('all' => true));
    foreach ($relatedItems as $relatedItem): ?>
        <?php if ($relatedItem == $source): ?>
        	<?php if (item_has_thumbnail()): ?>
				<div class="item-nimg">
				<?php echo link_to_item(item_square_thumbnail()); ?>
				</div>
			<?php endif; ?>
		<?php endif; ?>
	<?php endforeach; ?>
<?php endwhile; ?>
<?php endif; ?>

What am I missing there? I think I must be getting something wrong about using foreach, but all the examples I can find of how to use foreach don't apply to this kind of problem. Thanks again for any help you can offer!

You're using the "all" option correctly for the $relatedItems for loop, but I believe you said this was a many-to-many relationship, right?

It looks like you're still just using the first Source Identifier when you set the $source variable up at the top. I'm not sure if that's what you're trying to do or not.

Oops! Thank you so much for catching that. Problem solved! In case anyone is interested, here's the beginning part of the code that works:

<?php
$currentid = item('ID');
$sources = item('Item Type Metadata', 'Source Identifier', array('all' => true));?>

<h6>Related Objects:</h6>

<!-- insert an if statement to see if it's empty-->
<?php if (item('Item Type Metadata', 'Source Identifier') !=''): ?>

<!--  check each source identifier -->
<?php foreach ($sources as $source): ?>

<!-- check each matching item -->
<?php
$physicalobjects = get_items(array('type' => 'Physical Object'),5000);
set_items_for_loop($physicalobjects);
while(loop_items()):
?>
<?php
    $relatedItems = item('Item Type Metadata', 'Source Identifier', array('all' => true));
    foreach ($relatedItems as $relatedItem): ?>
        <?php if ($relatedItem == $source): ?>
        	<?php if (item_has_thumbnail()): ?>
				<div class="item-nimg">
				<?php echo link_to_item(item_square_thumbnail()); ?>
				</div>
			<?php endif; ?>
		<?php endif; ?>
	<?php endforeach; ?>
<?php endwhile; ?>
<?php endforeach; ?>
<?php endif; ?>

<p style="clear:both">
</p>

So, the sample page I gave previously: http://vcomeka.com/vccc/items/show/2773
is now working as desired! Thank you again, John - you cured my headache!