. */ /** * Implementation of hook_menu. * we need some standard entry points so we can have consistent urls for different Object actions */ function islandora_basic_collection_menu() { $items = array(); $items['islandora/object/%/edit/collection'] = array( 'title' => 'Manage Collection', 'page callback' => 'islandora_basic_collection_edit_object', 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access callback' => 'islandora_basic_collection_access', 'access arguments' => array(2), ); $items['islandora/object/%/view/collection'] = array( 'title' => 'Collection View', 'page callback' => 'islandora_basic_collection_view1', 'page arguments' => array(2), 'type' => MENU_LOCAL_TASK, 'access callback' => 'islandora_basic_collection_access', 'access arguments' => array(2), ); return $items; } function islandora_basic_collection_edit_object($object_id){ return 'Collection CModel edit function '.$object_id; } function islandora_basic_collection_view1($object_id){ return 'A view returned by the Collection cmodel '.$object_id; } /** * determines whether or not to show this modules manage tab * @global object $user * @param string $object_id * @return boolean */ function islandora_basic_collection_access($object_id){ module_load_include('inc', 'islandora', 'RestConnection'); global $user; try { $restConnection = new RestConnection($user); $fedora_object = new FedoraObject($object_id, $restConnection->repository); } catch (Exception $e) { drupal_set_message(t('Error getting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); return FALSE; } if (!isset($fedora_object)) { return FALSE; } $models = $fedora_object->models; $cmodel_list = islandora_basic_collection_islandora_get_types(); foreach ($fedora_object->models as $model) { if (isset($cmodel_list[$model])){ return user_access(FEDORA_MODIFY_STATE); } } return FALSE; } /** * Theme registry function * We supply a pattern so we can overide templates at the theme level if needed. * we can append a pid to a template and the new template file will be called (the pids * colon should be replaced with a dash) * @return array */ function islandora_basic_collection_theme($existing, $type, $theme, $path) { return array( 'islandora_basic_collection' => array( 'template' => 'islandora-basic-collection', 'pattern' => 'islandora_basic_collection__', //we can add pids to the end of this pattern in our preprocess function // and templates will be able to have have a pid appended to the template name to overide a template on a per object basis //an example template would be named islandora-basic-image--islandora-27.tpl.phps 'variables' => array('islandora_object' => NULL), ) ); } /** * tells the main module what types of objects we support. This is used to determine whether or not * this module should attempt to respond. * @return array * array of content model pids that this module supports */ function islandora_basic_collection_islandora_get_types() { $types = array(); $types['islandora:collectionCModel'][ISLANDORA_VIEW_HOOK] = TRUE; $types['islandora:collectionCModel'][ISLANDORA_EDIT_HOOK] = FALSE; return $types; } /** * this modules implentation of view_object hook will handle objects of type islandora:basicImageCModel and info:fedora/islandora:sp_basic_image * as registered in its return types * Other modules would handle objects of other types. * @param Object $object * a tuque fedora object * @param object $user * @param string $page_number * @param string $page_size * @return string * themed html */ function islandora_basic_collection_islandora_view_object($object, $user, $page_number, $page_size) { //global $user; $cmodel_list = islandora_basic_collection_islandora_get_types(); $models = $object->models; foreach ($object->models as $model) { if (isset($cmodel_list[$model][ISLANDORA_VIEW_HOOK]) && $cmodel_list[$model][ISLANDORA_VIEW_HOOK] == TRUE) { $output = theme('islandora_basic_collection', array('islandora_object' => $object)); return array('Basic Collection Output' => $output); } } return NULL; } /** * * @global type $base_url * @param array $variables * an array of variables that will be passed to the theme function */ function islandora_basic_collection_preprocess_islandora_basic_collection(&$variables) { $islandora_object = $variables['islandora_object']; module_load_include('inc', 'islandora', 'includes/islandora_dublin_core'); try { $dc = $islandora_object['DC']->content; $dc_object = Dublin_Core::import_from_xml_string($dc); } catch (Exception $e) { drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error'); } $variables['islandora_associated_objects'] = islandora_basic_collection_get_objects($islandora_object); $variables['islandora_dublin_core'] = $dc_object; $variables['islandora_object_label'] = $islandora_object->label; $variables['theme_hook_suggestions'][] = 'islandora_basic_collection__' . str_replace(':', '_', $islandora_object->id); global $base_url; if (isset($islandora_object['OBJ'])) { $variables['islandora_image_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/OBJ/view'; } if (isset($islandora_object['TN'])) { $variables['islandora_thumbnail_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/TN/view'; } if (isset($islandora_object['MEDIUM_SIZE'])) { $variables['islandora_medium_size_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/MEDIUM_SIZE/view'; } } function islandora_basic_collection_get_objects($object) { $query = 'select $object $title $content from <#ri> where ($object $title and $object $content and ($object id . '> or $object id . '>) and $object ) minus $content order by $title'; $page_number = (empty($_GET['page'])) ? '1' : $_GET['page']; $page_size = (empty($_GET['pagesize'])) ? '10' : $_GET['pagesize']; module_load_include('inc', 'islandora', 'RestConnection'); $query_array = array('query' => $query, 'type' => 'itql', 'pid' => $object->id, 'page_size' => $page_size, 'page_number' => $page_number); drupal_alter('islandora_basic_collection_query', $query_array); global $user; try { $restConnection = new RestConnection($user); $queryObject = new RepositoryQuery($restConnection->connection); $results = $queryObject->query($query_array['query'], $query_array['type']); } catch (Exception $e) { drupal_set_message(t('Islandora Error getting related objects for %s', array('%s' => $object->id)), 'error'); return""; } return $results; } function islandora_basic_collection_islandora_ingest_get_information($models, $object) { if (in_array('islandora:collectionCModel', $models) && isset($object['COLLECTION_POLICY'])) { try { module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy'); $return = array(); $policy = new CollectionPolicy($object['COLLECTION_POLICY']->content); $return['models'] = $policy->getContentModels(); $return['relationship'] = $policy->getRelationship(); return $return; } catch (Exception $e) { drupal_set_message(t('Islandora Error getting collection info for %s', array('%s' => $object->id)), 'error'); } } }