You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
338 lines
13 KiB
338 lines
13 KiB
<?php |
|
|
|
/* |
|
* @file |
|
* islandora_basic_collection.module |
|
* |
|
* an Islandora module to handle basic image cmodels |
|
* |
|
* |
|
* This file is part of Islandora. |
|
* |
|
* This program is free software: you can redistribute it and/or modify |
|
* it under the terms of the GNU General Public License as published by |
|
* the Free Software Foundation, either version 3 of the License, or |
|
* (at your option) any later version. |
|
* |
|
* This program is distributed in the hope that it will be useful, |
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
* GNU General Public License for more details. |
|
* |
|
* You should have received a copy of the GNU General Public License |
|
* along with the program. If not, see <http ://www.gnu.org/licenses/>. |
|
*/ |
|
|
|
/** |
|
* Implements 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/%/manage/collection'] = array( |
|
'title' => 'Collection related', |
|
'page callback' => 'islandora_basic_collection_manage_object', |
|
'page arguments' => array(2), |
|
'type' => MENU_LOCAL_TASK, |
|
'access callback' => 'islandora_basic_collection_access', |
|
'access arguments' => array(2), |
|
); |
|
|
|
$items['admin/islandora/basic_collection'] = array( |
|
'title' => 'Islandora basic collection', |
|
'description' => 'Configure the basic Collection solution pack.', |
|
'page callback' => 'drupal_get_form', |
|
'access arguments' => array('administer site configuration'), |
|
'page arguments' => array('islandora_basic_collection_admin'), |
|
'file' => 'admin/islandora_basic_collection.admin.inc', |
|
'type' => MENU_NORMAL_ITEM, |
|
); |
|
|
|
/* an example of adding a tab for view |
|
$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_init() { |
|
if (path_is_admin(current_path())) { |
|
drupal_add_css(drupal_get_path('module', 'islandora_basic_collection') . '/css/islandora_basic_collection.admin.css'); |
|
} |
|
} |
|
|
|
/** |
|
* Implements hook_menu_local_tasks_alter(). |
|
*/ |
|
function islandora_basic_collection_menu_local_tasks_alter(&$data, $router_item, $root_path) { |
|
// Add action link |
|
if ($root_path == 'islandora/object/%/manage/collection') { |
|
$object_id = $router_item['page_arguments'][0]; |
|
$item = menu_get_item("islandora/ingest/$object_id"); |
|
$item['title'] = 'Add a repository item'; |
|
if ($item['access']) { |
|
$data['actions']['output'][] = array( |
|
'#theme' => 'menu_local_action', |
|
'#link' => $item, |
|
); |
|
} |
|
} |
|
} |
|
|
|
/** |
|
* This function is where we create the view for the related menu item |
|
* @param type $object_id |
|
* @return type |
|
*/ |
|
function islandora_basic_collection_manage_object($object_id) { |
|
|
|
module_load_include('inc', 'islandora_basic_collection', 'includes/collection_management'); |
|
module_load_include('inc', 'islandora_basic_collection', 'includes/collection_manager_table'); |
|
module_load_include('inc', 'islandora_basic_collection', 'includes/delete_collection'); |
|
module_load_include('inc', 'islandora_basic_collection', 'includes/move_collection'); |
|
module_load_include('inc', 'islandora_basic_collection', 'includes/child_collection'); |
|
module_load_include('inc', 'islandora_basic_collection', 'includes/manage_policies'); |
|
module_load_include('inc', 'islandora_basic_collection', 'includes/change_content_models'); |
|
|
|
$form = array(); |
|
|
|
$form['collection_manager'] = array( |
|
'#type' => 'vertical_tabs', |
|
'#weight' => 0, |
|
'#prefix' => '', |
|
); |
|
|
|
$form['collection_manager']['create_child_collection'] = array( |
|
'#title' => t('Create child collection'), |
|
'#type' => 'fieldset', |
|
); |
|
|
|
$form['collection_manager']['create_child_collection']['form'] = drupal_get_form('islandora_create_child_collection_form', $object_id); |
|
|
|
$form['collection_manager']['manage_policies'] = array( |
|
'#type' => 'fieldset', |
|
'#title' => t('Manage collection policies'), |
|
'#collapsible' => TRUE, |
|
'#collapsed' => TRUE, |
|
); |
|
|
|
$form['collection_manager']['manage_policies']['form'] = drupal_get_form('islandora_manage_policies_form', $object_id); |
|
|
|
$form['collection_manager']['change_content_models'] = array( |
|
'#type' => 'fieldset', |
|
'#title' => t('Change content models'), |
|
'#collapsible' => TRUE, |
|
'#collapsed' => TRUE, |
|
); |
|
|
|
$form['collection_manager']['change_content_models']['form'] = drupal_get_form('islandora_change_content_models_form', $object_id); |
|
|
|
$form['collection_manager']['migrate_members'] = array( |
|
'#type' => 'fieldset', |
|
'#title' => t('Migrate members'), |
|
'#collapsible' => TRUE, |
|
'#collapsed' => TRUE, |
|
); |
|
|
|
$form['collection_manager']['migrate_members']['form'] = drupal_get_form('islandora_collection_migrate_form', $object_id); |
|
|
|
$form['collection_manager']['delete_members'] = array( |
|
'#type' => 'fieldset', |
|
'#title' => t('Delete members of this collection'), |
|
'#collapsible' => TRUE, |
|
'#collapsed' => TRUE, |
|
); |
|
|
|
$form['collection_manager']['delete_members']['form'] = drupal_get_form('islandora_collection_deletion_form', $object_id); |
|
|
|
// Pass the form around any modules that are interested so that they can add their own collection management functions. |
|
module_invoke_all('islandora_collection_manager', $form); |
|
|
|
return $form; |
|
} |
|
|
|
/** |
|
* 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) { |
|
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_MANAGE); |
|
} |
|
} |
|
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( |
|
'file' => 'theme/islandora_basic_collection.theme.inc', |
|
'template' => 'theme/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), |
|
), |
|
'islandora_basic_collection_grid' => array( |
|
'file' => 'theme/islandora_basic_collection.theme.inc', |
|
'template' => 'theme/islandora-basic-collection-grid', |
|
'pattern' => 'islandora_basic_collection_grid__', |
|
'variables' => array('islandora_object' => NULL, 'collection_results' => NULL), |
|
), |
|
'islandora_basic_collection_wrapper' => array( |
|
'file' => 'theme/islandora_basic_collection.theme.inc', |
|
'template' => 'theme/islandora-basic-collection-wrapper', |
|
'variables' => array('islandora_object' => NULL), |
|
), |
|
'islandora_basic_collection_management_form_table' => array( |
|
'file' => 'theme/islandora_basic_collection.theme.inc', |
|
'arguments' => array('element' => NULL), |
|
'file' => 'includes/collection_manager_table.inc', |
|
), |
|
); |
|
} |
|
|
|
/** |
|
* tells the main module what types of objects we support. This is used to determine whether or not |
|
* this module should attempt to respond. |
|
* If ISLANDORA_VIEW_HOOK = TRUE this function will populate the default tab. This should be configurable |
|
* in the modules admin section, otherwise two modules can populate one tab. |
|
* @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] = variable_get('islandora_basic_collection_use_for_default_tab', 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) { |
|
//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_wrapper', array('islandora_object' => $object,)); |
|
return array('Collection View' => $output); |
|
} |
|
} |
|
return NULL; |
|
} |
|
|
|
/** |
|
* a wrappert to retrieve an object from Fedora |
|
* @global object $user |
|
* @param string $object_id |
|
* @return null|\FedoraObject |
|
*/ |
|
function islandora_basic_collection_get_object($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', array('%s' => $object_id)), 'error'); |
|
return NULL; |
|
} |
|
return $fedora_object; |
|
} |
|
|
|
/** |
|
* gets objects associated with this object with teh isMemberOf or isMemberOfCollection |
|
* |
|
* @global object $user |
|
* @param object $object |
|
* @param string $page_number |
|
* @param string $page_size |
|
* @return array |
|
*/ |
|
function islandora_basic_collection_get_objects($object, $page_number = 1, $page_size = 5) { |
|
$query = 'select $object $title $content from <#ri> |
|
where ($object <fedora-model:label> $title |
|
and $object <fedora-model:hasModel> $content |
|
and ($object <fedora-rels-ext:isMemberOfCollection> <info:fedora/' . $object->id . '> |
|
or $object <fedora-rels-ext:isMemberOf> <info:fedora/' . $object->id . '>) |
|
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>) |
|
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0> |
|
order by $title'; |
|
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'); |
|
} |
|
} |
|
} |
|
|
|
function islandora_basic_collection_islandora_undeletable_datastreams($models) { |
|
if(in_array('islandora:collectionCModel', $models)) { |
|
if(variable_get('islandora_basic_collection_disable_collection_policy_delete', TRUE)) { |
|
return array('COLLECTION_POLICY'); |
|
} |
|
} |
|
} |