Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyboggs/901923 to your computer and use it in GitHub Desktop.
Save jeremyboggs/901923 to your computer and use it in GitHub Desktop.
Omeka function to return Tags associated with Items in a given Collection.
<?php
/**
* Return Tags associated with Items in a given Collection.
*
* @param Collection
* @return array Tags.
*/
function get_tags_for_items_in_collection($collection = null) {
// If collection is null, get the current collection.
if (!$collection) {
$collection = get_current_collection();
}
// Get the database.
$db = get_db();
// Get the Tag table.
$table = $db->getTable('Tag');
// Build the select query.
$select = $table->getSelectForFindBy();
// Join to the Item table where the collection_id is equal to the ID of our Collection.
if ($collection) {
$table->filterByTagType($select, 'Item');
$select->where('i.collection_id = ?', $collection->id);
}
// Fetch some tags with our select.
$tags = $table->fetchObjects($select);
return $tags;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment