From d0b49780ab5d6a0aae879b380b100fc24c4e86fc Mon Sep 17 00:00:00 2001 From: Jonathan Green Date: Thu, 6 Sep 2018 16:31:22 -0300 Subject: [PATCH] Add hook for child relationships --- includes/orphaned_objects.inc | 13 +++++-------- islandora.api.php | 18 ++++++++++++++++++ islandora.module | 7 +++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/includes/orphaned_objects.inc b/includes/orphaned_objects.inc index 54a156ce..60ddf34d 100644 --- a/includes/orphaned_objects.inc +++ b/includes/orphaned_objects.inc @@ -145,7 +145,7 @@ function islandora_get_orphaned_objects() { $connection = islandora_get_tuque_connection(); // SPARQL: get orphaned objects, exclude any with a living parent. $object_query = << +!prefix SELECT DISTINCT ?object ?title WHERE { ?object ; @@ -169,11 +169,7 @@ WHERE { FILTER (!bound(?liveparent)) } ORDER BY ?object EOQ; - $parent_relationships = array('', '', ''); - if (module_exists('islandora_compound_object')) { - $predicate = variable_get('islandora_compound_object_relationship', 'isConstituentOf'); - $parent_relationships[] = ""; - } + $parent_relationships = module_invoke_all('islandora_solution_pack_child_relationships'); $optionals = (array) module_invoke('islandora_xacml_api', 'islandora_basic_collection_get_query_optionals', 'view'); $filter_modules = array( @@ -194,8 +190,9 @@ EOQ; $sparql_query_objects = format_string($object_query, array( '!optionals' => !empty($optionals) ? ('OPTIONAL {{' . implode('} UNION {', $optionals) . '}}') : '', '!filters' => !empty($filters) ? implode(' ', array_map($filter_map, $filters)) : '', - '!dead_parent_relationships' => '?p = ' . implode(' || ?p = ', $parent_relationships), - '!live_parent_relationships' => '{' . implode(' } UNION { ', array_map($parent_map,$parent_relationships)) . '}', + '!dead_parent_relationships' => '?p = ' . implode(' || ?p = ', $parent_relationships['predicate']), + '!live_parent_relationships' => '{' . implode(' } UNION { ', array_map($parent_map, $parent_relationships['predicate'])) . '}', + '!prefix' => implode("\n", $parent_relationships['prefix']), )); $results = $connection->repository->ri->sparqlQuery($sparql_query_objects); return $results; diff --git a/islandora.api.php b/islandora.api.php index c5de95e1..166998ac 100644 --- a/islandora.api.php +++ b/islandora.api.php @@ -966,3 +966,21 @@ function hook_islandora_datastream_filename_alter(&$filename, AbstractDatastream ); } } + +/** + * Allow solution packs to register relationships used for children. + * + * @return array + * - prefix (array): This is is a valid snip-it of SPARQL to register prefixes used in the predicates array. + * - predicate (array): This array contains predicates used by the solution pack for child objects. + */ +function hook_islandora_solution_pack_child_relationships() { + return array( + 'prefix' => array('PREFIX islandora: '), + 'predicate' => array( + '', + '', + '', + ), + ); +} \ No newline at end of file diff --git a/islandora.module b/islandora.module index f9276404..effa4a79 100644 --- a/islandora.module +++ b/islandora.module @@ -2215,3 +2215,10 @@ function islandora_islandora_breadcrumbs_backends() { ), ); } + +/** + * Implements hook_islandora_solution_pack_child_relationships + */ +function islandora_islandora_solution_pack_child_relationships() { + return array('predicate' => array(), 'prefix' => array()); +} \ No newline at end of file