Browse Source

Merge pull request #610 from jordandukart/7.x-breadcrumb-predicate

Breadcrumb predicates.
pull/612/head
Adam 9 years ago
parent
commit
24e930a0e9
  1. 13
      includes/breadcrumb.inc
  2. 14
      islandora.api.php
  3. 12
      islandora.module

13
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, <fedora-rels-ext:isPartOf>)";
$collection_predicate_filters .= " || sameTerm(?collection_predicate, <fedora-rels-ext:isMemberOfCollection>) || sameTerm(?collection_predicate, <fedora-rels-ext:isMemberOf>)";
$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) {

14
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',
);
}

12
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',
);
}

Loading…
Cancel
Save