Skip to content

Instantly share code, notes, and snippets.

@jeremyboggs
Created June 3, 2011 21:58
Show Gist options
  • Save jeremyboggs/1007255 to your computer and use it in GitHub Desktop.
Save jeremyboggs/1007255 to your computer and use it in GitHub Desktop.
Filters the 'item_browse_sql' select in Omeka to return items in a given Exhibit.
<?php
// Hook the 'filter_items_by_exhibit' into the Items SQL.
add_plugin_hook('item_browse_sql', 'filter_items_by_exhibit');
/**
* Filters the 'item_browse_sql' select to return items in a given
* Exhibit. Checks for the existence of a parameter called 'exhibit'
* with a value of either an Exhibit object or Exhibit ID.
*/
function filter_items_by_exhibit($select, $params)
{
$db = get_db();
if ($request = Zend_Controller_Front::getInstance()->getRequest()) {
$exhibit = $request->get('exhibit') ? $request->get('exhibit') : null;
}
$exhibit = isset($params['exhibit']) ? $params['exhibit'] : $exhibit;
if ($exhibit) {
$select->joinInner(
array('isp' => $db->ExhibitPageEntry),
'isp.item_id = i.id',
array()
);
$select->joinInner(
array('sp' => $db->ExhibitPage),
'sp.id = isp.page_id',
array()
);
$select->joinInner(
array('s' => $db->ExhibitSection),
's.id = sp.section_id',
array()
);
$select->joinInner(
array('e' => $db->Exhibit),
'e.id = s.exhibit_id',
array()
);
if ($exhibit instanceof Exhibit) {
$select->where('e.id = ?', $exhibit->id);
} elseif (is_numeric($exhibit)) {
$select->where('e.id = ?', $exhibit);
}
}
return $select;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment