Getting tags based upon collection tree hierarchy

55 views
Skip to first unread message

Tom

unread,
May 8, 2013, 5:22:22 PM5/8/13
to omek...@googlegroups.com
I am using Omeka 1.5.3, with the "collection tree" plugin and Jeremy's get_tags_for_items_in_collection from https://gist.github.com/clioweb/901923 which is listed below.

I really would like to enhance the functionality of this code, so that not just the tags of the specified collection, but also all tags in any children collections or their children would be returned.

How can I...
Determine if the "collection tree" plugin is active.
Get a list of all children and grandchildren of a collection from the plugin tables.
Incorporate that list of collections to the select->where filter.

Thanks for any help.

-Tom

<?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;
}

Patrick Murray-John

unread,
May 9, 2013, 10:55:19 AM5/9/13
to omek...@googlegroups.com
For testing whether the plugin is active, you could use something like
this that's in Omeka 2.0

function plugin_is_active($name, $version = null, $compOperator = '>=')
{
$plugin = get_db()->getTable('Plugin')->findByDirectoryName($name);
if (!$plugin) {
return false;
}
if (!$plugin->isActive()) {
return false;
}
if ($version) {
return version_compare($plugin->getDbVersion(), $version,
$compOperator);
} else {
return true;
}
}


I _think_ just getting the list of child collections could work like this:

$childCollections =
get_db()->getTable('CollectionTree')->getDescendantTree($collectionId);

I'm not sure if there's a way to condense it all into a single select,
though.

Patrick
> --
> You received this message because you are subscribed to the Google
> Groups "Omeka Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to omeka-dev+...@googlegroups.com.
> To post to this group, send email to omek...@googlegroups.com.
> Visit this group at http://groups.google.com/group/omeka-dev?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

Reply all
Reply to author
Forward
0 new messages