Can't Get item_file() Function To Work


I'm developing a custom theme for our library's digital collections that I will soon be migrating from Greenstone. I want to be able to link to the full size image of an item on the items/show/* page:

head(array('title' => item('Dublin Core', 'Title'), 'bodyid'=>'items','bodyclass' => 'show'));
<div id="item-show-left">
<h2><?php print item('Dublin Core', 'Title'); ?></h2>
<?php if(item_thumbnail()): ?>
"><?php print item_thumbnail(); ?>
<?php endif; ?>
<?php if (item_belongs_to_collection()): ?>
<div id="collection" class="element">
<h3><?php echo __('Collection'); ?></h3>
<div class="element-text"><p><?php echo link_to_collection_for_item(); ?></p></div>
<?php endif; ?>
<?php if (item_has_tags()): ?>
<div id="item-tags" class="element">
<h3><?php echo __('Tags'); ?></h3>
<div class="element-text"><?php echo item_tags_as_string(); ?></div>
<?php endif;?>
<div id="item-citation" class="element">
<h3><?php echo __('Citation'); ?></h3>
<div class="element-text"><?php echo item_citation(); ?></div>
<?php echo plugin_append_to_items_show(); ?>
<ul class="item-pagination navigation">
<li id="previous-item" class="previous"><?php echo link_to_previous_item(); ?>
<li id="next-item" class="next"><?php echo link_to_next_item(); ?>

<div id="item-show-right">
<?php echo custom_show_item_metadata(); ?>
<?php foot(); ?>

The item_file() call produces errors that I nabbed from my apache log:

[Thu Nov 15 11:41:15 2012] [error] [client] PHP Catchable fatal error: Argument 1 passed to Omeka_View_Helper_FileMetadata::fileMetadata() must be an instance of File, null given in /usr/local/www/omeka-1.5.3/application/helpers/FileMetadata.php on line 31, referer:
[Thu Nov 15 11:41:15 2012] [error] [client] PHP Fatal error: Undefined class constant 'PRIMARY_TYPE_NUM' in /usr/local/www/omeka-1.5.3/application/libraries/Zend/Session/SaveHandler/DbTable.php on line 522, referer:

I read the documentation and found similar posts in this forum, but can't get it to work.
I ended up achieving what I want with:

head(array('title' => item('Dublin Core', 'Title'), 'bodyid'=>'items','bodyclass' => 'show'));
preg_match('/src="(.*)" alt/', item_fullsize(), $matches);
$fullsize_uri = $matches[1];


<?php if(item_thumbnail()): ?>
"><?php print item_thumbnail(); ?>
<?php endif; ?>

That works, but I wonder why item_file() doesn't work?

Thanks! Overall the Omeka API is wonderful and very easy to use. Love it!

- Gavin

Despite the somewhat confusing name, item_file works on files, not items, so there needs to be a "current file" set or you need to pass one to item_file.

Some calls, like loop_files_for_item, will automatically set the current file for you. Otherwise, you can use set_current_file to do so.

Hmm. I see that the code I posted got filtered/mangled quite a bit.

Thanks, makes sense.

However, although I see a get_current_file function, there is no set_current_file function on the functions page.

I tried set_current_file() w/o any args and get:

Catchable fatal error: Argument 1 passed to set_current_file() must be an instance of File, null given, called in /usr/local/www/omeka-1.5.3/themes/brooks/items/show.php on line 8 and defined in /usr/local/www/omeka-1.5.3/application/helpers/FileFunctions.php on line 82

After some experimentation, I found the following works:

<?php while(loop_files_for_item()): ?>
"><?php print item_thumbnail(); ?>
<?php endwhile; ?>

set_current_file requires an argument, the File object. You can get those out of the Item object, or from some other sources like loop_files_for_item or get_files.

This is pretty much the same for every type of record. On a particular record's "show" page, it's automatically set as the current record, but for any other types on a page, you need to manually get and set the current record, or call a function that loops through them.

On a side note, I'm not sure why the forums keep flagging your posts as spam.

When posting larger blocks of code, try to keep the backticks on separate lines, that will show the code as one large block instead of as separate smaller ones, and may affect the spam blocker's view of your post.

Ah, okay. I was using the code tag instead of the backticks.


print item_file('fullsize uri');


Thanks John.

- Gavin