Browse Source

Breadcrumbs

pull/120/head
jonathangreen 12 years ago
parent
commit
ddc5ad96db
  1. 78
      includes/Breadcrumbs.inc
  2. 2
      islandora.module

78
includes/Breadcrumbs.inc

@ -0,0 +1,78 @@
<?php
function islandora_get_breadcrumbs($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$breadcrumbs = array();
$connection = new RestConnection();
islandora_get_breadcrumbs_recursive($pid, $breadcrumbs, $connection->repository);
if(isset($breadcrumbs[0])) {
unset($breadcrumbs[0]);
}
$breadcrumbs = array_reverse($breadcrumbs);
return $breadcrumbs;
}
/**
* Builds an array of drupal links for use in breadcrumbs.
*
* @todo Make fully recursive...
*
* @global type $base_url
* @param type $pid
* @param type $breadcrumbs
* @param type $level
*/
function islandora_get_breadcrumbs_recursive($pid, &$breadcrumbs, $repository) {
// Before executing the query, we hve a base case of accessing the top-level collection
global $base_url;
static $max_level = 10;
static $level = -1;
if (count($breadcrumbs) === 0) {
$level = $max_level;
}
$root = variable_get('islandora_repository_pid', 'islandora:root');
if ($pid == $root) {
$breadcrumbs[] = l(menu_get_active_title(), 'islandora');
$breadcrumbs[] = l(t('Home'), '<front>');
}
else {
$query_string = 'select $parentObject $title $content from <#ri>
where (
<info:fedora/' . $pid . '> <fedora-model:label> $title
and $parentObject <fedora-model:hasModel> $content
and (
<info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOfCollection> $parentObject
or <info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOf> $parentObject
or <info:fedora/' . $pid . '> <fedora-rels-ext:isPartOf> $parentObject
)
and $parentObject <fedora-model:state> <info:fedora/fedora-system:def/model#Active>
)
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
order by $title desc';
$results = $repository->ri->itqlQuery($query_string);
if (count($results) > 0 && $level > 0) {
$parent = $results[0]['parentObject']['value'];
$this_title = $results[0]['title']['value'];
if (empty($this_title)) {
$this_title = t('-');
}
$breadcrumbs[] = l($this_title, "islandora/object/$pid");
$level--;
islandora_get_breadcrumbs_recursive($parent, $breadcrumbs, $repository);
}
else {
$breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root.
islandora_get_breadcrumbs_recursive($root, $breadcrumbs, $repository); //And render the last two links and break (on the next pass).
}
}
}

2
islandora.module

@ -480,6 +480,8 @@ function islandora_view_default_object() {
* @return string * @return string
*/ */
function islandora_view_object($object_id = NULL) { function islandora_view_object($object_id = NULL) {
module_load_include('inc', 'islandora', 'includes/Breadcrumbs');
drupal_set_breadcrumb(islandora_get_breadcrumbs($object_id));
//return $object_id; //return $object_id;
if (!isset($object_id)) { if (!isset($object_id)) {
$object_id = variable_get('islandora_repository_pid', 'islandora:root'); $object_id = variable_get('islandora_repository_pid', 'islandora:root');

Loading…
Cancel
Save