From ece4b57b29cbfb250b3ce61ebdcd294e54103321 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Thu, 23 Jul 2015 17:07:41 -0300 Subject: [PATCH] Breadcrumb predicates. --- includes/breadcrumb.inc | 13 +++++++++---- islandora.api.php | 14 ++++++++++++++ islandora.module | 12 ++++++++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/includes/breadcrumb.inc b/includes/breadcrumb.inc index 38c0970e..a8dc3169 100644 --- a/includes/breadcrumb.inc +++ b/includes/breadcrumb.inc @@ -54,6 +54,8 @@ function islandora_get_breadcrumbs($object) { * An array of links representing the breadcrumb trail, "root" first. */ function islandora_get_breadcrumbs_recursive($pid, FedoraRepository $repository, array &$context = NULL) { + module_load_include('inc', 'islandora', 'includes/utilities'); + // Before executing the query, we have a base case of accessing the top-level // collection. if ($context === NULL) { @@ -102,9 +104,13 @@ EOQ; $filter_map = function ($filter) { return "FILTER($filter)"; }; - $collection_predicate_filters = "sameTerm(?collection_predicate, )"; - $collection_predicate_filters .= " || sameTerm(?collection_predicate, ) || sameTerm(?collection_predicate, )"; - $query_filters[] = $collection_predicate_filters; + $object = islandora_object_load($pid); + $breadcrumb_predicates = islandora_invoke_hook_list(ISLANDORA_BREADCRUMB_FILTER_PREDICATE_HOOK, $object->models, array($object)); + $same_term_map = function ($predicate) { + return "sameTerm(?collection_predicate, <$predicate>)"; + }; + $collection_predicate_filters = array_map($same_term_map, $breadcrumb_predicates); + $query_filters[] = implode(' || ', $collection_predicate_filters); $query_order = "ORDER BY DESC(?label)"; $query = format_string($query, array( '!optionals' => !empty($query_optionals) ? ('OPTIONAL {{' . implode('} UNION {', $query_optionals) . '}}') : '', @@ -114,7 +120,6 @@ EOQ; $query = format_string($query, array( '!pid' => $pid, )); - $results = $repository->ri->sparqlQuery($query, 'unlimited'); if (count($results) > 0 && $context['level'] > 0) { diff --git a/islandora.api.php b/islandora.api.php index e7026923..6d5ad433 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -794,3 +794,17 @@ function hook_islandora_metadata_display_info() { ), ); } + +/** + * Defines predicates to be searched for when constructing breadcrumbs. + * + * @return array + * An array containing strings of predicates to be ORed together to be + * matched on in SPARQL. + */ +function hook_islandora_get_breadcrumb_query_predicates() { + return array( + 'somepredicate', + 'someotherpredicate,' + ); +} diff --git a/islandora.module b/islandora.module index 10d6060f..f171776e 100644 --- a/islandora.module +++ b/islandora.module @@ -49,6 +49,7 @@ define('ISLANDORA_POST_INGEST_HOOK', 'islandora_ingest_post_ingest'); define('ISLANDORA_PRE_PURGE_OBJECT_HOOK', 'islandora_pre_purge_object'); define('ISLANDORA_POST_PURGE_OBJECT_HOOK', 'islandora_post_purge_object'); define('ISLANDORA_UPDATE_RELATED_OBJECTS_PROPERTIES_HOOK', 'islandora_update_related_objects_properties'); +define('ISLANDORA_BREADCRUMB_FILTER_PREDICATE_HOOK', 'islandora_get_breadcrumb_query_predicates'); // @todo Add Documentation. define('ISLANDORA_OBJECT_INGESTED_HOOK', 'islandora_object_ingested'); @@ -2186,3 +2187,14 @@ function islandora_schedule_cache_clear_for_batch() { // iterations/operations of a single batch. $batch['islandora_cache_clear_scheduled'] = TRUE; } + +/** + * Implements hook_islandora_get_breadcrumb_query_predicates(). + */ +function islandora_islandora_get_breadcrumb_query_predicates(AbstractObject $object) { + return array( + 'fedora-rels-ext:isPartOf', + 'fedora-rels-ext:isMemberOfCollection', + 'fedora-rels-ext:isMemberOf', + ); +}