rwincewicz
13 years ago
7 changed files with 0 additions and 1088 deletions
@ -1,150 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* ChangeContentModels.inc |
|
||||||
*/ |
|
||||||
|
|
||||||
function islandora_change_content_models_form($form, &$form_state, $collection_pid) { |
|
||||||
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy'); |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
|
|
||||||
$content_models = get_content_models_list($collection_pid); |
|
||||||
$cm_options = array(); |
|
||||||
$name_mappings = array(); |
|
||||||
foreach ($content_models as $content_model) { |
|
||||||
if ($content_model != "islandora:collectionCModel") { |
|
||||||
$item = new FedoraObject($content_model, $rest_connection->repository); |
|
||||||
$cm_name = $item->Label; |
|
||||||
$cm_options[$content_model] = $cm_name; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); |
|
||||||
|
|
||||||
$collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'); |
|
||||||
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository); |
|
||||||
$collection_policy_datastream = $collection_object->getDatastream($collection_policy_dsid); |
|
||||||
|
|
||||||
$supported_collection_models = array(); |
|
||||||
if ($collection_policy_datastream && $collection_policy_datastream->content) { |
|
||||||
$collection_policy = new CollectionPolicy($collection_policy_datastream->content); |
|
||||||
$supported_collection_models = $collection_policy->getContentModels(); |
|
||||||
} |
|
||||||
$collection_namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); |
|
||||||
|
|
||||||
$collection_name = $collection_object->label; |
|
||||||
$new_content_models = get_content_models_as_option_array(); |
|
||||||
$current_models_in_policy = array(); |
|
||||||
|
|
||||||
if ($supported_collection_models) { |
|
||||||
foreach ($supported_collection_models as $supported_model) { |
|
||||||
$current_models_in_policy[$supported_model['pid']] = $supported_model['pid']; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$form['change_cmodel']['titlebox'] = array( |
|
||||||
'#type' => 'item', |
|
||||||
'#title' => t("Change content models within @collection_pid", array('@collection_pid' => $collection_pid)), |
|
||||||
); |
|
||||||
|
|
||||||
$form['change_cmodel']['current_content_model'] = array( |
|
||||||
'#title' => "Choose content model to be changed", |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $current_models_in_policy, |
|
||||||
'#description' => t("All objects in this collection with the selected content model will be changed."), |
|
||||||
); |
|
||||||
|
|
||||||
$form['change_cmodel']['new_content_model'] = array( |
|
||||||
'#title' => "Choose new content model", |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $new_content_models, |
|
||||||
'#description' => t("The new content model to be assigned to selected objects."), |
|
||||||
); |
|
||||||
|
|
||||||
$form['change_cmodel']['collection_pid'] = array( |
|
||||||
'#type' => 'hidden', |
|
||||||
'#value' => $collection_pid, |
|
||||||
); |
|
||||||
|
|
||||||
$form['change_cmodel']['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('Change content model associations'), |
|
||||||
'#id' => 'change_model', |
|
||||||
); |
|
||||||
|
|
||||||
return $form; |
|
||||||
} |
|
||||||
|
|
||||||
function islandora_change_content_models_form_validate($form, &$form_state) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
function islandora_change_content_models_form_submit($form, &$form_state) { |
|
||||||
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy'); |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
|
|
||||||
$current_content_model = $form_state['values']['current_content_model']; |
|
||||||
$new_content_model = $form_state['values']['new_content_model']; |
|
||||||
$collection_pid = $form_state['values']['collection_pid']; |
|
||||||
|
|
||||||
$current_content_model_object = new FedoraObject($current_content_model, $rest_connection->repository); |
|
||||||
|
|
||||||
$collection_object = new FedoraObject($form_state['values']['collection_pid'], $rest_connection->repository); |
|
||||||
$collection_policy_datastream = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY')); |
|
||||||
$policy = new CollectionPolicy($collection_policy_datastream->content); |
|
||||||
|
|
||||||
$collection_policy_xml = new DOMDocument(); |
|
||||||
$collection_policy_xml->loadXML($collection_policy_datastream->content); |
|
||||||
|
|
||||||
$add_to_policy = TRUE; |
|
||||||
$policy_content_models = $policy->getContentModels(); |
|
||||||
foreach ($policy_content_models as $policy_content_model) { |
|
||||||
if ($policy_content_model['pid'] == $current_content_model) { |
|
||||||
$namespace = $policy_content_model['namespace']; |
|
||||||
} |
|
||||||
if ($policy_content_model['pid'] == $new_content_model) { |
|
||||||
$add_to_policy = FALSE; |
|
||||||
} |
|
||||||
} |
|
||||||
if ($add_to_policy) { |
|
||||||
$new_content_model_object = new FedoraObject($new_content_model, $rest_connection->repository); |
|
||||||
$new_content_model_datastream = $new_content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); |
|
||||||
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); |
|
||||||
$content_model_element = $content_models_element->item(0)->getElementsByTagName('content_model'); |
|
||||||
|
|
||||||
$content_model_element = $collection_policy_xml->createElement('content_model'); |
|
||||||
$content_model_element->setAttribute('name', $new_content_model_object->label); |
|
||||||
$content_model_element->setAttribute('dsid', variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); |
|
||||||
$content_model_element->setAttribute('namespace', $namespace); |
|
||||||
$content_model_element->setAttribute('pid', $new_content_model_object->id); |
|
||||||
$content_models_element->item(0)->appendChild($content_model_element); |
|
||||||
|
|
||||||
$new_collection_policy_datastream = $collection_object->getDatastream('COLLECTION_POLICY'); |
|
||||||
$new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML()); |
|
||||||
$new_collection_policy_datastream->label = 'COLLECTION_POLICY'; |
|
||||||
$collection_object->ingestDatastream($new_collection_policy_datastream); |
|
||||||
} |
|
||||||
|
|
||||||
$query = "select \$object from <#ri> |
|
||||||
where (\$object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/$current_content_model> |
|
||||||
and (\$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$collection_pid> |
|
||||||
or \$object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/$collection_pid>) |
|
||||||
and \$object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)"; |
|
||||||
|
|
||||||
$objects = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); |
|
||||||
|
|
||||||
$count = 0; |
|
||||||
foreach ($objects as $object) { |
|
||||||
if (!$object['object']['value']) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
$fedora_item = new FedoraObject($object['object']['value'], $rest_connection->repository); |
|
||||||
$fedora_item->relationships->remove(FEDORA_MODEL_URI, 'hasModel', $current_content_model); |
|
||||||
$fedora_item->relationships->add(FEDORA_MODEL_URI, 'hasModel', $new_content_model); |
|
||||||
$count++; |
|
||||||
} |
|
||||||
drupal_set_message(t('@current_content_model changed to @new_content_model on @count objects', array('@current_content_model' => $current_content_model, '@new_content_model' => $new_content_model, '@count' => $count))); |
|
||||||
} |
|
@ -1,159 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* ChildCollection.inc |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Create the child collection creation form |
|
||||||
* |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
* @param string $this_collection_pid |
|
||||||
* @return array |
|
||||||
*/ |
|
||||||
function islandora_create_child_collection_form($form, &$form_state, $this_collection_pid) { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
|
|
||||||
$restricted = FALSE; |
|
||||||
if (variable_get('fedora_namespace_restriction_enforced', TRUE)) { |
|
||||||
$restricted = TRUE; |
|
||||||
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); |
|
||||||
$namespaces = explode(':', $allowed_string); |
|
||||||
foreach ($namespaces as $namespace) { |
|
||||||
if ($namespace) { |
|
||||||
$allowed[trim($namespace)] = trim($namespace); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
$collection_namespace = substr($this_collection_pid, 0, strpos($this_collection_pid, ":")); |
|
||||||
|
|
||||||
$content_models = get_content_models_as_option_array(); |
|
||||||
unset($content_models['islandora:collectionCModel']); |
|
||||||
|
|
||||||
$form['child_creation']['titlebox'] = array( |
|
||||||
'#type' => 'item', |
|
||||||
'#title' => t("Create new child collection within @collection", array('@collection' => $this_collection_pid)), |
|
||||||
); |
|
||||||
|
|
||||||
$form['child_creation']['collection_name'] = array( |
|
||||||
'#title' => "Collection name", |
|
||||||
'#type' => 'textfield', |
|
||||||
'#size' => 25, |
|
||||||
'#description' => t("Human readable name for this collection"), |
|
||||||
); |
|
||||||
|
|
||||||
$form['child_creation']['new_collection_pid'] = array( |
|
||||||
'#title' => "Collection PID", |
|
||||||
'#type' => 'textfield', |
|
||||||
'#size' => 15, |
|
||||||
'#default_value' => $rest_connection->repository->api->m->getNextPid($collection_namespace), |
|
||||||
'#description' => t("Unique PID for this collection. <br />Pids take the general form of namespace:collection (eg. islandora:pamphlets)"), |
|
||||||
); |
|
||||||
|
|
||||||
if (!$restricted) { |
|
||||||
$form['child_creation']['collection_namespace'] = array( |
|
||||||
'#title' => "Collection namespace", |
|
||||||
'#type' => 'textfield', |
|
||||||
'#size' => 15, |
|
||||||
'#default_value' => $collection_namespace, |
|
||||||
'#description' => t("Namespace for objects in this collection."), |
|
||||||
); |
|
||||||
} |
|
||||||
else { |
|
||||||
$form['child_creation']['collection_namespace'] = array( |
|
||||||
'#title' => "Collection namespace", |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $allowed, |
|
||||||
'#default_value' => 'default', |
|
||||||
'#description' => t("Namespace for objects in this collection."), |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
$form['current'] = array( |
|
||||||
'#type' => 'hidden', |
|
||||||
'#value' => $this_collection_pid, |
|
||||||
); |
|
||||||
|
|
||||||
$form['child_creation']['content_models'] = array( |
|
||||||
'#title' => "Choose allowable content models for this collection", |
|
||||||
'#type' => 'checkboxes', |
|
||||||
'#options' => $content_models, |
|
||||||
'#description' => t("Content models describe the behaviours of objects with which they are associated."), |
|
||||||
); |
|
||||||
|
|
||||||
$form['child_creation']['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('Create collection'), |
|
||||||
'#id' => 'create_child' |
|
||||||
); |
|
||||||
return $form; |
|
||||||
} |
|
||||||
|
|
||||||
function islandora_create_child_collection_form_validate($form, &$form_state) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Submit handler for child collection creation form |
|
||||||
* |
|
||||||
* @global type $base_url |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
*/ |
|
||||||
function islandora_create_child_collection_form_submit($form, &$form_state) { |
|
||||||
global $base_url; |
|
||||||
module_load_include('inc', 'islandora', '/includes/islandora.ingest'); |
|
||||||
$thumbnail = $base_url . '/' . drupal_get_path('module', 'islandora_basic_collection') . '/Crystal_Clear_filesystem_folder_grey.png'; |
|
||||||
$new_collection_pid = $form_state['values']['new_collection_pid']; |
|
||||||
$new_collection_label = $form_state['values']['collection_name']; |
|
||||||
$namespace = $form_state['values']['collection_namespace']; |
|
||||||
$all_cModels = get_content_models_as_option_array(); |
|
||||||
$collection_content_models = array(array('pid' => 'islandora:collectionCModel')); |
|
||||||
$relationship = 'isMemberOfCollection'; |
|
||||||
|
|
||||||
$collection_policy = '<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<collection_policy xmlns="http://www.islandora.ca" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="" xsi:schemaLocation="http://www.islandora.ca http://syn.lib.umanitoba.ca/collection_policy.xsd"> |
|
||||||
<content_models> |
|
||||||
<content_model dsid="ISLANDORACM" name="Islandora Collection Model ~ islandora:collectionCModel" namespace="islandora:1" pid="islandora:collectionCModel"/> |
|
||||||
</content_models> |
|
||||||
<search_terms> |
|
||||||
</search_terms> |
|
||||||
<staging_area></staging_area> |
|
||||||
<relationship>isMemberOfCollection</relationship> |
|
||||||
</collection_policy>'; |
|
||||||
|
|
||||||
$content_models = $form_state['values']['content_models']; |
|
||||||
|
|
||||||
$collection_policy_xml = new DOMDocument(); |
|
||||||
$collection_policy_xml->loadXML($collection_policy); |
|
||||||
|
|
||||||
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); |
|
||||||
$content_model_element = $content_models_element->item(0)->getElementsByTagName('content_model'); |
|
||||||
foreach ($content_models as $content_model) { |
|
||||||
if ($content_model) { |
|
||||||
$content_model_element = $collection_policy_xml->createElement('content_model'); |
|
||||||
$content_model_element->setAttribute('name', $all_cModels[$content_model]); |
|
||||||
$content_model_element->setAttribute('dsid', variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); |
|
||||||
$content_model_element->setAttribute('namespace', $namespace . ':1'); |
|
||||||
$content_model_element->setAttribute('pid', $content_model); |
|
||||||
$content_models_element->item(0)->appendChild($content_model_element); |
|
||||||
} |
|
||||||
} |
|
||||||
$fedora_object = islandora_ingest_get_object($collection_content_models, $form_state['values']['current'], $relationship, $new_collection_pid); |
|
||||||
$fedora_object->label = $new_collection_label; |
|
||||||
$thumbnail_datastream = $fedora_object->constructDatastream('TN'); |
|
||||||
$thumbnail_datastream->setContentFromUrl($thumbnail); |
|
||||||
$thumbnail_datastream->label = 'Thumbnail'; |
|
||||||
$thumbnail_datastream->mimetype = 'image/png'; |
|
||||||
$fedora_object->ingestDatastream($thumbnail_datastream); |
|
||||||
$policy_datastream = $fedora_object->constructDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'), 'X'); |
|
||||||
$policy_datastream->setContentFromString($collection_policy_xml->saveXML()); |
|
||||||
$policy_datastream->label = 'Collection policy'; |
|
||||||
$fedora_object->ingestDatastream($policy_datastream); |
|
||||||
$new_fedora_object = islandora_ingest_add_object($fedora_object); |
|
||||||
|
|
||||||
drupal_goto('/islandora/object/' . $new_collection_pid); |
|
||||||
} |
|
@ -1,241 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* CollectionManagement.inc |
|
||||||
* A set of useful functions to help with collection management |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* returns content models associated with all objects in a collection |
|
||||||
* @param string $pid |
|
||||||
* @return array |
|
||||||
*/ |
|
||||||
function get_represented_content_models($pid) { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; |
|
||||||
|
|
||||||
$query = "select \$model \$title from <#ri> |
|
||||||
where (\$object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/$pid> |
|
||||||
or \$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$pid>) |
|
||||||
and \$object <info:fedora/fedora-system:def/model#hasModel> \$model |
|
||||||
and \$object <dc:title> \$title"; |
|
||||||
|
|
||||||
$model_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); |
|
||||||
$represented_models = array(); |
|
||||||
foreach ($model_pids as $model_pid) { |
|
||||||
|
|
||||||
if ($model_pid['model']['value'] && $model_pid['model']['value'] != 'fedora-system:FedoraObject-3.0') { |
|
||||||
$fedora_object = new FedoraObject($model_pid['model']['value'], $rest_connection->repository); |
|
||||||
$content_model_title = $fedora_object->label; |
|
||||||
$represented_models[$model_pid['model']['value']] = $model_pid['model']['value'] . ' ~ ' . $content_model_title; |
|
||||||
} |
|
||||||
} |
|
||||||
return $represented_models; |
|
||||||
} |
|
||||||
|
|
||||||
function get_child_collections($collection_pid) { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; |
|
||||||
|
|
||||||
$query = <<<EOD |
|
||||||
select \$object from <#ri> |
|
||||||
where \$object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel> |
|
||||||
and \$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$collection_pid> |
|
||||||
EOD; |
|
||||||
|
|
||||||
$lines = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); |
|
||||||
$collection_pids = array_values(array_filter($lines)); |
|
||||||
return $collection_pids; |
|
||||||
} |
|
||||||
|
|
||||||
function islandora_collections_get_collection_from_pid($pid) { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; |
|
||||||
|
|
||||||
$query = 'select $parent from <#ri> |
|
||||||
where ($object <fedora-rels-ext:isMemberOf> $parent |
|
||||||
or $object <fedora-rels-ext:isMemberOfCollection> $parent) |
|
||||||
and $object <dc:identifier> \'' . $pid . '\' |
|
||||||
order by $object'; |
|
||||||
|
|
||||||
$object_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); |
|
||||||
$object_pids = array_values(array_filter($object_pids)); |
|
||||||
return $object_pids; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* Returns an array of pids that match the query contained in the collection |
|
||||||
* object's QUERY datastream or in the suppled $query parameter. |
|
||||||
* @param <type> $collection_pid |
|
||||||
* @param <type> $query |
|
||||||
* @param <type> $query_format R |
|
||||||
*/ |
|
||||||
function get_related_items_as_array($collection_pid, $relationship = array('isMemberOfCollection'), $limit = 10000, $offset = 0, $active_objects_only = TRUE, $cmodel = NULL, $orderby = '$title') { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; |
|
||||||
|
|
||||||
global $user; |
|
||||||
|
|
||||||
// Not sure if this is necessary given that we should never be able to delete objects in a namespace that we don't have access to. |
|
||||||
// if (!fedora_repository_access('view fedora repository', $collection_pid['object']['value'])) { |
|
||||||
// drupal_set_message(t("You do not have access to Fedora objects within the attempted namespace or access to Fedora denied."), 'error'); |
|
||||||
// return array(); |
|
||||||
// } |
|
||||||
|
|
||||||
$query_string = 'select $object $title $content from <#ri> |
|
||||||
where ($object <fedora-model:label> $title |
|
||||||
and $object <fedora-model:hasModel> $content |
|
||||||
and ('; |
|
||||||
|
|
||||||
if (is_array($relationship)) { |
|
||||||
foreach ($relationship as $rel) { |
|
||||||
$query_string .= '$object <fedora-rels-ext:' . $rel . '> <info:fedora/' . $collection_pid . '>'; |
|
||||||
if (next($relationship)) { |
|
||||||
$query_string .= ' OR '; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
elseif (is_string($relationship)) { |
|
||||||
$query_string .= '$object <fedora-rels-ext:' . $relationship . '> <info:fedora/' . $collection_pid . '>'; |
|
||||||
} |
|
||||||
else { |
|
||||||
return ''; |
|
||||||
} |
|
||||||
|
|
||||||
$query_string .= ') '; |
|
||||||
$query_string .= $active_objects_only ? 'and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>' : ''; |
|
||||||
|
|
||||||
if ($cmodel) { |
|
||||||
$query_string .= ' and $content <mulgara:is> <info:fedora/' . $cmodel . '>'; |
|
||||||
} |
|
||||||
|
|
||||||
$query_string .= ') |
|
||||||
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0> |
|
||||||
order by ' . $orderby; |
|
||||||
|
|
||||||
$results = $rest_connection->repository->ri->itqlQuery($query_string, $limit, $offset); |
|
||||||
|
|
||||||
return $results; |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
/** |
|
||||||
* determines whether we can see the object or not |
|
||||||
* checks PID namespace permissions, and user permissions |
|
||||||
* @global type $user |
|
||||||
* @param type $op |
|
||||||
* @param type $pid |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function fedora_repository_access($permission, $pid) { |
|
||||||
global $user; |
|
||||||
$name_space_access = FALSE; |
|
||||||
$is_restricted = variable_get('islandora_namespace_restriction_enforced', TRUE); |
|
||||||
if (!$is_restricted) { |
|
||||||
$name_space_access = TRUE; |
|
||||||
} |
|
||||||
if ($pid == NULL) { |
|
||||||
$pid = variable_get('islandora_repository_pid', 'islandora:root'); |
|
||||||
} |
|
||||||
$name_space_allowed = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: ')); |
|
||||||
$pos = NULL; |
|
||||||
foreach ($name_space_allowed as $name_space) { |
|
||||||
$pos = stripos($pid, $name_space); |
|
||||||
if ($pos === 0) { |
|
||||||
$name_space_access = TRUE; |
|
||||||
} |
|
||||||
} |
|
||||||
if ($name_space_access) { |
|
||||||
$user_access = user_access($permission); |
|
||||||
if ($user_access == NULL) { |
|
||||||
return FALSE; |
|
||||||
} |
|
||||||
return $user_access; |
|
||||||
} |
|
||||||
else { |
|
||||||
return FALSE; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* gets the name of the content models for the specified object |
|
||||||
* this now returns an array of pids as in Fedora 3 we can have more then one Cmodel for an object |
|
||||||
* @param type $pid |
|
||||||
* @param type $include_fedora_system_content_models |
|
||||||
* @return array |
|
||||||
*/ |
|
||||||
function get_content_models_list($pid, $include_fedora_system_content_models = FALSE) { |
|
||||||
|
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
$pids = array(); |
|
||||||
$query = 'select $object from <#ri> |
|
||||||
where <info:fedora/' . $pid . '> <fedora-model:hasModel> $object |
|
||||||
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>'; |
|
||||||
$content_models = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); |
|
||||||
|
|
||||||
if (empty($content_models)) { |
|
||||||
return $pids; |
|
||||||
} |
|
||||||
|
|
||||||
$cmodels = array(); |
|
||||||
foreach ($content_models as $content_model) { |
|
||||||
if (strpos($content_model['object']['uri'], 'fedora-system:FedoraObject-3.0') != FALSE && $include_fedora_system_content_models == FALSE) { |
|
||||||
continue; |
|
||||||
} |
|
||||||
$cmodels[] = substr(strstr($content_model['object']['uri'], '/'), 1); |
|
||||||
} |
|
||||||
|
|
||||||
return $cmodels; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Function: get_content_models_as_option_array |
|
||||||
* |
|
||||||
* Description: Returns an associative array of all available content models in Fedora instance |
|
||||||
* |
|
||||||
* @return array |
|
||||||
*/ |
|
||||||
function get_content_models_as_option_array() { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; |
|
||||||
|
|
||||||
$restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); |
|
||||||
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); |
|
||||||
$namespaces = explode(':', $allowed_string); |
|
||||||
foreach ($namespaces as $namespace) { |
|
||||||
if ($namespace) { |
|
||||||
$allowed[] = trim($namespace); |
|
||||||
} |
|
||||||
} |
|
||||||
$query = 'select $object $title from <#ri> |
|
||||||
where ($object <fedora-model:label> $title |
|
||||||
and ($object <fedora-model:hasModel> <info:fedora/fedora-system:ContentModel-3.0> |
|
||||||
or $object <fedora-rels-ext:isMemberOfCollection> <info:fedora/islandora:ContentModelsCollection>) |
|
||||||
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>) |
|
||||||
order by $title'; |
|
||||||
|
|
||||||
$list = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); |
|
||||||
$options = array(); |
|
||||||
foreach ($list as $item) { //removes blanks |
|
||||||
if ($item) { |
|
||||||
$item_namespace = explode(':', $item['object']['value']); |
|
||||||
if (!$restricted || in_array($item_namespace[0], $allowed)) { |
|
||||||
|
|
||||||
if (!preg_match('/fedora-system/', $item['object']['value'])) { |
|
||||||
$options[$item['object']['value']] = $item['title']['value'] . ' ~ ' . $item['object']['value']; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
return $options; |
|
||||||
} |
|
@ -1,117 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* CollectionManagerTable.inc |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Returns a formatted table listing all members of the collection |
|
||||||
* defined by the $collection_pid parameter |
|
||||||
* @param string $collection_pid |
|
||||||
* @return array |
|
||||||
*/ |
|
||||||
function islandora_collection_table($collection_pid) { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
$query = 'select $object $title from <#ri> |
|
||||||
where ($object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/' . $collection_pid . '> |
|
||||||
or $object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/' . $collection_pid . '>) |
|
||||||
and $object <dc:title> $title'; |
|
||||||
$results = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); |
|
||||||
$keys = array(); |
|
||||||
$objects = array(); |
|
||||||
foreach ($results as $result) { |
|
||||||
$objects[$result['object']['value']] = $result['title']['value']; |
|
||||||
$keys[] = $result['object']['value']; |
|
||||||
} |
|
||||||
$rows = array(); |
|
||||||
foreach ($objects as $key => $object) { |
|
||||||
$rows[$key] = array( |
|
||||||
'#pid' => $key, |
|
||||||
'pid' => array('#value' => l($key, 'islandora/object/' . $key)), |
|
||||||
'title' => array( |
|
||||||
'data' => array( |
|
||||||
'#type' => 'link', |
|
||||||
'#title' => $object, |
|
||||||
'#href' => 'islandora/object/' . $key, |
|
||||||
), |
|
||||||
), |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
$header = array( |
|
||||||
'title' => array('data' => t('Title')), |
|
||||||
); |
|
||||||
|
|
||||||
if (!$rows) { |
|
||||||
return; |
|
||||||
} |
|
||||||
|
|
||||||
$table = array( |
|
||||||
'#type' => 'tableselect', |
|
||||||
'#header' => $header, |
|
||||||
'#options' => $rows, |
|
||||||
); |
|
||||||
|
|
||||||
return $table; |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* themes the form table. |
|
||||||
* |
|
||||||
* @param array $element Drupal Form Element. |
|
||||||
* @return string |
|
||||||
*/ |
|
||||||
function theme_islandora_basic_collection_management_form_table(array $element) { |
|
||||||
$rows = array(); |
|
||||||
foreach (element_children($element['rows']) as $child) { |
|
||||||
$setting = $element['rows'][$child]; |
|
||||||
$pid = $setting['#pid']; |
|
||||||
$fields = array( |
|
||||||
drupal_render($element['selections'][$pid]) // First field is a checkbox |
|
||||||
); |
|
||||||
foreach (element_children($setting) as $property) { |
|
||||||
$field = $setting[$property]; |
|
||||||
$fields[] = drupal_render($field); |
|
||||||
} |
|
||||||
$rows[] = array( |
|
||||||
'data' => $fields, |
|
||||||
'class' => isset($setting['#attributes']['class']) ? $setting['#attributes']['class'] : NULL |
|
||||||
); |
|
||||||
} |
|
||||||
$attributes = isset($element['#id']) ? array('id' => $element['#id']) : NULL; |
|
||||||
return theme_table($element['#header'], $rows, $attributes); |
|
||||||
} |
|
||||||
|
|
||||||
function get_collections_as_option_array() { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; |
|
||||||
|
|
||||||
$restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); |
|
||||||
$allowed_string = variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora:'); |
|
||||||
$namespaces = explode(':', $allowed_string); |
|
||||||
|
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
$query = 'select $object $title from <#ri> |
|
||||||
where ($object <fedora-model:label> $title |
|
||||||
and $object <info:fedora/fedora-system:def/model#hasModel> <info:fedora/islandora:collectionCModel> |
|
||||||
and $object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>) |
|
||||||
order by $title'; |
|
||||||
$results = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); |
|
||||||
foreach ($namespaces as $namespace) { |
|
||||||
$trimmed_names[] = trim($namespace); |
|
||||||
} |
|
||||||
$options = array(); |
|
||||||
foreach ($results as $item) { //removes blanks |
|
||||||
$namespace = explode(':', $item['object']['value']); |
|
||||||
$namespace = trim($namespace[0]); |
|
||||||
if (!$restricted || in_array($namespace, $trimmed_names)) { |
|
||||||
$options[$item['object']['value']] = $item['title']['value']; |
|
||||||
} |
|
||||||
} |
|
||||||
unset($options['islandora:ContentModelCollection']); |
|
||||||
return $options; |
|
||||||
} |
|
@ -1,126 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* DeleteCollection.inc |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* |
|
||||||
* @param array $form_state |
|
||||||
* @param string $pid |
|
||||||
* |
|
||||||
* @return string |
|
||||||
*/ |
|
||||||
function islandora_collection_deletion_form($form, &$form_state, $pid) { |
|
||||||
module_load_include('inc', 'islandora_basic_collection', 'CollectionManagerTable'); |
|
||||||
$potential_collections = get_collections_as_option_array(); |
|
||||||
$table = islandora_collection_table($pid); |
|
||||||
$deletion_message = ($table) ? "Delete Members of this Collection" : "Delete Collection"; |
|
||||||
$submit_text_message = ($table) ? "Delete selected objects" : "Delete collection"; |
|
||||||
|
|
||||||
$form = array(); |
|
||||||
|
|
||||||
$form['collection_delete']['titlebox'] = array( |
|
||||||
'#type' => 'item', |
|
||||||
'#title' => t("Delete objects from @collection_pid", array('@collection_pid' => $pid)), |
|
||||||
); |
|
||||||
|
|
||||||
if ($table) { |
|
||||||
$form['collection_delete']['table'] = array( |
|
||||||
'table' => $table, |
|
||||||
); |
|
||||||
} |
|
||||||
else { |
|
||||||
$form['collection_delete']['delete_root'] = array( |
|
||||||
'#type' => 'checkbox', |
|
||||||
'#title' => "Remove this empty collection?", |
|
||||||
'#id' => 'delete_collection', |
|
||||||
); |
|
||||||
} |
|
||||||
$form['current'] = array( |
|
||||||
'#type' => 'hidden', |
|
||||||
'#value' => $pid, |
|
||||||
); |
|
||||||
|
|
||||||
$form['collection_delete']['message'] = array( |
|
||||||
'#type' => 'item', |
|
||||||
'#value' => t("This action is permanant and cannot be undone."), |
|
||||||
); |
|
||||||
$form['collection_delete']['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#description' => t("This action is permanant and cannot be undone."), |
|
||||||
'#value' => t('@message', array('@message' => $submit_text_message)), |
|
||||||
); |
|
||||||
|
|
||||||
return $form; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Submit handler for object deletion form in the collection manager. |
|
||||||
* |
|
||||||
* @global type $user |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
*/ |
|
||||||
function islandora_collection_deletion_form_submit($form, &$form_state) { |
|
||||||
global $user; |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
|
|
||||||
$collection_pid = $form_state['values']['current']; |
|
||||||
$fedora_object = new FedoraObject($collection_pid, $rest_connection->repository); |
|
||||||
$parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection'); |
|
||||||
$parents = Islandora_collections_get_collection_from_pid($collection_pid); |
|
||||||
$collection_pid = $form_state['values']['current']; |
|
||||||
if (isset($form_state['values']['delete_root']) && $form_state['values']['delete_root'] == 1) { |
|
||||||
delete_root_collection($collection_pid); |
|
||||||
drupal_goto("islandora/object/" . $parents[0]['parent']['value']); |
|
||||||
} |
|
||||||
|
|
||||||
$child_collections = get_child_collections($collection_pid); |
|
||||||
|
|
||||||
$populated_child_collections = array(); |
|
||||||
$pids = @array_filter($form_state['values']['table']); |
|
||||||
|
|
||||||
if (!empty($child_collections)) { |
|
||||||
foreach ($child_collections as $child) { |
|
||||||
$child_pids = get_related_items_as_array($child, 'isMemberOfCollection'); |
|
||||||
if (!empty($child_pids)) { |
|
||||||
$populated_child_collections[] = $child; |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
if (!empty($populated_child_collections)) { |
|
||||||
$conflict = FALSE; |
|
||||||
foreach ($populated_child_collections as $collection) { |
|
||||||
if (in_array($collection, $pids)) { |
|
||||||
$conflict = TRUE; |
|
||||||
drupal_set_message(t("Populated child collections were not deleted.")); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
$pids_to_delete = array_diff($pids, $populated_child_collections); |
|
||||||
|
|
||||||
foreach ($pids_to_delete as $pid_to_delete) { |
|
||||||
$rest_connection->repository->purgeObject($pid_to_delete); |
|
||||||
} |
|
||||||
drupal_goto("islandora/object/" . $collection_pid); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Deletes the collection object |
|
||||||
* |
|
||||||
* @param string $pid |
|
||||||
*/ |
|
||||||
function delete_root_collection($pid) { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
try { |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
$rest_connection->repository->purgeObject($pid); |
|
||||||
} catch (Exception $e) { |
|
||||||
drupal_set_message(t("Collection '@pid' could not be deleted!", array('@pid' => $pid)), 'error'); |
|
||||||
return; |
|
||||||
} |
|
||||||
drupal_set_message(t("Collection '@pid' deleted.", array('@pid' => $pid))); |
|
||||||
} |
|
@ -1,217 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* ManagePolicies.inc |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Create form to collection policy management feature |
|
||||||
* |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
* @param string $collection_pid |
|
||||||
* @return type |
|
||||||
*/ |
|
||||||
function islandora_manage_policies_form($form, &$form_state, $collection_pid) { |
|
||||||
module_load_include('inc', 'islandora_basic_collection', 'includes/CollectionPolicy'); |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
|
|
||||||
$content_models = get_content_models_list($collection_pid); |
|
||||||
$cm_options = array(); |
|
||||||
$name_mappings = array(); |
|
||||||
foreach ($content_models as $content_model) { |
|
||||||
if ($content_model != "islandora:collectionCModel") { |
|
||||||
$item = new FedoraObject($content_model, $rest_connection->repository); |
|
||||||
$cm_name = $item->Label; |
|
||||||
$cm_options[$content_model] = $cm_name; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); |
|
||||||
|
|
||||||
$collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'); |
|
||||||
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository); |
|
||||||
$collection_policy_string = $collection_object->getDatastream($collection_policy_dsid); |
|
||||||
|
|
||||||
$supported_collection_models = array(); |
|
||||||
if ($collection_policy_string) { |
|
||||||
$collection_policy = new CollectionPolicy($collection_policy_string->content); |
|
||||||
$supported_collection_models = $collection_policy->getContentModels(); |
|
||||||
} |
|
||||||
$collection_namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); |
|
||||||
|
|
||||||
$represented_content_models = get_represented_content_models($collection_pid); |
|
||||||
$collection_name = $collection_object->label; |
|
||||||
$new_content_models = get_content_models_as_option_array(); |
|
||||||
$current_models_in_policy = array(); |
|
||||||
|
|
||||||
if ($supported_collection_models) { |
|
||||||
foreach ($supported_collection_models as $supported_model) { |
|
||||||
$current_models_in_policy[$supported_model['pid']] = $supported_model['pid']; |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
$new_options = array(); |
|
||||||
if (is_array($new_content_models) && is_array($current_models_in_policy)) { |
|
||||||
$new_options = array_diff_key($new_content_models, $current_models_in_policy); |
|
||||||
} |
|
||||||
|
|
||||||
$form['manage_collection_policy']['titlebox'] = array( |
|
||||||
'#type' => 'item', |
|
||||||
'#title' => t("Manage collection policy for @collection_pid", array('@collection_pid' => $collection_pid)), |
|
||||||
); |
|
||||||
|
|
||||||
$form ['manage_collection_policy']['add']['content_model_to_add'] = array( |
|
||||||
'#title' => "Choose content model", |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $new_options, |
|
||||||
'#description' => t("Choose content model to add to this collection policy."), |
|
||||||
); |
|
||||||
|
|
||||||
$form ['manage_collection_policy']['add']['new_cp_namespace'] = array( |
|
||||||
'#title' => "Choose namespace", |
|
||||||
'#type' => 'textfield', |
|
||||||
'#size' => 15, |
|
||||||
'#default_value' => $namespace, |
|
||||||
'#description' => t("Choose namespace for objects in this collection associated with this content model"), |
|
||||||
); |
|
||||||
|
|
||||||
$form['parent_collection'] = array( |
|
||||||
'#type' => 'hidden', |
|
||||||
'#value' => $collection_pid, |
|
||||||
); |
|
||||||
|
|
||||||
$form['collection_pid'] = array( |
|
||||||
'#type' => 'hidden', |
|
||||||
'#value' => $collection_pid, |
|
||||||
); |
|
||||||
|
|
||||||
$form['manage_collection_policy']['add']['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('Add content model to collection policy'), |
|
||||||
'#id' => 'add_cm' |
|
||||||
); |
|
||||||
|
|
||||||
if (count($current_models_in_policy) > 0) { |
|
||||||
$form['manage_collection_policy']['remove'] = array( |
|
||||||
'#title' => "Delete content model from collection policy", |
|
||||||
'#type' => 'fieldset', |
|
||||||
'#collapsible' => TRUE, |
|
||||||
'#collapsed' => TRUE, |
|
||||||
); |
|
||||||
|
|
||||||
$form ['manage_collection_policy']['remove']['content_models_to_remove'] = array( |
|
||||||
'#title' => "Choose content model to remove", |
|
||||||
'#type' => 'checkboxes', |
|
||||||
'#options' => $current_models_in_policy, |
|
||||||
'#description' => t("Choose content models to remove from this collection policy."), |
|
||||||
); |
|
||||||
|
|
||||||
$form['manage_collection_policy']['remove']['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('Remove content model from collection policy'), |
|
||||||
'#id' => 'remove_cm' |
|
||||||
); |
|
||||||
} |
|
||||||
return $form; |
|
||||||
} |
|
||||||
|
|
||||||
function islandora_manage_policies_form_validate($form, &$form_state) { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Submit handler for collection policy management form |
|
||||||
* |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
*/ |
|
||||||
function islandora_manage_policies_form_submit($form, &$form_state) { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
|
|
||||||
$collection_pid = $form_state['values']['parent_collection']; |
|
||||||
$collection_object = new FedoraObject($collection_pid, $rest_connection->repository); |
|
||||||
$policy = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY')); |
|
||||||
$collection_policy = '<?xml version="1.0" encoding="UTF-8"?> |
|
||||||
<collection_policy xmlns="http://www.islandora.ca" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="" xsi:schemaLocation="http://www.islandora.ca http://syn.lib.umanitoba.ca/collection_policy.xsd"> |
|
||||||
<content_models> |
|
||||||
<content_model dsid="ISLANDORACM" name="Islandora Collection Model ~ islandora:collectionCModel" namespace="islandora:1" pid="islandora:collectionCModel"/> |
|
||||||
</content_models> |
|
||||||
<search_terms> |
|
||||||
</search_terms> |
|
||||||
<staging_area></staging_area> |
|
||||||
<relationship>isMemberOfCollection</relationship> |
|
||||||
</collection_policy>'; |
|
||||||
|
|
||||||
$collection_policy_xml = new DOMDocument(); |
|
||||||
$collection_policy_xml->loadXML($policy->content); |
|
||||||
|
|
||||||
if ($form_state['clicked_button']['#id'] == 'add_cm') { |
|
||||||
if (empty($policy->content)) { |
|
||||||
$collection_policy_datastream = $collection_object->constructDatastream('COLLECTION_POLICY', 'X'); |
|
||||||
$collection_policy_datastream->setContentFromString($collection_policy); |
|
||||||
$collection_policy_datastream->label = 'COLLECTION_POLICY'; |
|
||||||
$collection_object->ingestDatastream($collection_policy_datastream); |
|
||||||
$policy = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY')); |
|
||||||
} |
|
||||||
|
|
||||||
$cp_namespace = $form_state['values']['new_cp_namespace']; |
|
||||||
$cp_content_model = $form_state['values']['content_model_to_add']; |
|
||||||
$content_model_object = new FedoraObject($cp_content_model, $rest_connection->repository); |
|
||||||
$content_model_datastream = $content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); |
|
||||||
|
|
||||||
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); |
|
||||||
$content_model_element = $content_models_element->item(0)->getElementsByTagName('content_model'); |
|
||||||
|
|
||||||
$content_model_element = $collection_policy_xml->createElement('content_model'); |
|
||||||
$content_model_element->setAttribute('name', $content_model_object->label); |
|
||||||
$content_model_element->setAttribute('dsid', variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM')); |
|
||||||
$content_model_element->setAttribute('namespace', $cp_namespace); |
|
||||||
$content_model_element->setAttribute('pid', $content_model_object->id); |
|
||||||
$content_models_element->item(0)->appendChild($content_model_element); |
|
||||||
|
|
||||||
$new_collection_policy_datastream = $collection_object->getDatastream('COLLECTION_POLICY'); |
|
||||||
$new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML()); |
|
||||||
$new_collection_policy_datastream->label = 'COLLECTION_POLICY'; |
|
||||||
$collection_object->ingestDatastream($new_collection_policy_datastream); |
|
||||||
drupal_set_message(t("Collection model @model successfully added", array('@model' => $content_model_object->label))); |
|
||||||
} |
|
||||||
|
|
||||||
//remove content model from collection policy |
|
||||||
if ($form_state['clicked_button']['#id'] == 'remove_cm') { |
|
||||||
$candidates = $form_state['values']['content_models_to_remove']; |
|
||||||
$count = 0; |
|
||||||
$s = ''; |
|
||||||
foreach ($candidates as $candidate) { |
|
||||||
if (is_string($candidate)) { |
|
||||||
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models'); |
|
||||||
$models = $content_models_element->item(0)->getElementsByTagName('content_model'); |
|
||||||
$found = FALSE; |
|
||||||
for ($i = 0; $found === FALSE && $i < $models->length; $i++) { |
|
||||||
if ($models->item($i)->getAttribute('pid') == $candidate) { |
|
||||||
$found = $models->item($i); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
if ($found !== FALSE && $models->length > 1) { |
|
||||||
$content_models_element->item(0)->removeChild($found); |
|
||||||
$ret = TRUE; |
|
||||||
} |
|
||||||
$count++; |
|
||||||
} |
|
||||||
} |
|
||||||
if ($count > 0) { |
|
||||||
$new_collection_policy_datastream = $collection_object->getDatastream('COLLECTION_POLICY'); |
|
||||||
$new_collection_policy_datastream->setContentFromString($collection_policy_xml->saveXML()); |
|
||||||
$new_collection_policy_datastream->label = 'COLLECTION_POLICY'; |
|
||||||
$collection_object->ingestDatastream($new_collection_policy_datastream); |
|
||||||
if ($count > 1) { |
|
||||||
$s = 's'; |
|
||||||
} |
|
||||||
drupal_set_message(t("$count collection model@s removed", array('@s' => $s))); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,78 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
/** |
|
||||||
* @file |
|
||||||
* MoveCollection.inc |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Create object migration form for the collection manager |
|
||||||
* |
|
||||||
* @param array $form_state |
|
||||||
* @param string $pid |
|
||||||
* |
|
||||||
* @return string |
|
||||||
*/ |
|
||||||
function islandora_collection_migrate_form($form, &$form_state, $pid) { |
|
||||||
module_load_include('inc', 'islandora_basic_collection', 'CollectionManagerTable'); |
|
||||||
$potential_collections = get_collections_as_option_array(); |
|
||||||
$table = islandora_collection_table($pid); |
|
||||||
if (!$table) { |
|
||||||
$form['no_objects'] = array( |
|
||||||
'#type' => 'item', |
|
||||||
'#title' => t('No objects found in this collection'), |
|
||||||
); |
|
||||||
return $form; |
|
||||||
} |
|
||||||
$form = array(); |
|
||||||
|
|
||||||
$form['migrate']['titlebox'] = array( |
|
||||||
'#type' => 'item', |
|
||||||
'#title' => t("Move objects from @collection_pid", array('@collection_pid' => $pid)), |
|
||||||
); |
|
||||||
|
|
||||||
$form['migrate']['new_collection'] = array( |
|
||||||
'#title' => t('New collection'), |
|
||||||
'#description' => t("All content will be migrated from @pid to the selected collection", array('@pid' => $pid)), |
|
||||||
'#type' => 'select', |
|
||||||
'#options' => $potential_collections, |
|
||||||
); |
|
||||||
|
|
||||||
$form['migrate']['table'] = $table; |
|
||||||
|
|
||||||
$form['current'] = array( |
|
||||||
'#type' => 'hidden', |
|
||||||
'#value' => $pid, |
|
||||||
); |
|
||||||
|
|
||||||
$form['migrate']['message'] = array( |
|
||||||
'#type' => 'item', |
|
||||||
'#value' => t(""), |
|
||||||
); |
|
||||||
|
|
||||||
$form['migrate']['submit'] = array( |
|
||||||
'#type' => 'submit', |
|
||||||
'#value' => t('Migrate selected objects'), |
|
||||||
); |
|
||||||
return $form; |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* Submit handler for object migration form |
|
||||||
* |
|
||||||
* @param array $form |
|
||||||
* @param array $form_state |
|
||||||
*/ |
|
||||||
function islandora_collection_migrate_form_submit($form, &$form_state) { |
|
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$rest_connection = new RestConnection(); |
|
||||||
|
|
||||||
$pids = array_filter($form_state['values']['table']); |
|
||||||
$new_collection = $form_state['values']['new_collection']; |
|
||||||
$current = $form_state['values']['current']; |
|
||||||
foreach ($pids as $pid) { |
|
||||||
$fedora_object = new FedoraObject($pid, $rest_connection->repository); |
|
||||||
$fedora_object->relationships->remove(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $current); |
|
||||||
$fedora_object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $new_collection); |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue