diff --git a/islandora_basic_collection/includes/ChangeContentModels.inc b/islandora_basic_collection/includes/ChangeContentModels.inc index 07362b69..b1f956da 100644 --- a/islandora_basic_collection/includes/ChangeContentModels.inc +++ b/islandora_basic_collection/includes/ChangeContentModels.inc @@ -6,9 +6,43 @@ */ 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(); - $represented_content_models = get_represented_content_models($collection_pid); - var_dump($represented_content_models); + $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->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', @@ -18,7 +52,7 @@ function islandora_change_content_models_form($form, &$form_state, $collection_p $form['change_cmodel']['current_content_model'] = array( '#title' => "Choose content model to be changed", '#type' => 'select', - '#options' => $represented_content_models, + '#options' => $current_models_in_policy, '#description' => t("All objects in this collection with the selected content model will be changed."), ); @@ -31,12 +65,12 @@ function islandora_change_content_models_form($form, &$form_state, $collection_p $form['change_cmodel']['collection_pid'] = array( '#type' => 'hidden', - '#value' => $this_collection_pid, + '#value' => $collection_pid, ); $form['change_cmodel']['submit'] = array( '#type' => 'submit', - '#value' => t('Change Content Model Associations'), + '#value' => t('Change content model associations'), '#id' => 'change_model', ); @@ -44,9 +78,73 @@ function islandora_change_content_models_form($form, &$form_state, $collection_p } 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 + and (\$object + or \$object ) + and \$object )"; + + $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))); } \ No newline at end of file diff --git a/islandora_basic_collection/includes/ChildCollection.inc b/islandora_basic_collection/includes/ChildCollection.inc index 767c008b..682004dc 100644 --- a/islandora_basic_collection/includes/ChildCollection.inc +++ b/islandora_basic_collection/includes/ChildCollection.inc @@ -75,7 +75,7 @@ function islandora_create_child_collection_form($form, &$form_state, $this_colle $form['child_creation']['submit'] = array( '#type' => 'submit', - '#value' => t('Create Collection'), + '#value' => t('Create collection'), '#id' => 'create_child' ); return $form; diff --git a/islandora_basic_collection/includes/CollectionManagement.inc b/islandora_basic_collection/includes/CollectionManagement.inc index ead0f199..d72bf080 100644 --- a/islandora_basic_collection/includes/CollectionManagement.inc +++ b/islandora_basic_collection/includes/CollectionManagement.inc @@ -414,9 +414,9 @@ function collection_management_form_submit($form, &$form_state) { */ function delete_objects_as_batch($pid) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); $name = $user->name; - $restConnection->repository->purgeObject($pid); + $rest_connection->repository->purgeObject($pid); } /** @@ -425,8 +425,8 @@ function delete_objects_as_batch($pid) { */ function remove_collection_association($pid, $collection_pid) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); - $fedora_object = new FedoraObject($pid, $restConnection->repository); + $rest_connection = new RestConnection(); + $fedora_object = new FedoraObject($pid, $rest_connection->repository); $fedora_object->relationships->remove(NULL, 'isMemberOfCollection', $collection_pid); } @@ -437,7 +437,7 @@ function remove_collection_association($pid, $collection_pid) { */ function get_represented_content_models($pid) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $query = "select \$model \$title from <#ri> @@ -446,12 +446,14 @@ where (\$object \$model and \$object \$title"; - $model_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $model_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $represented_models = array(); foreach ($model_pids as $model_pid) { - if ($model_pid && $model_pid['model']['value'] != 'fedora-system:FedoraObject-3.0') { - - $represented_models[$model_pid['model']['value']] = $model_pid['model']['value'] . ' ~ ' . $model_pid['title']['value']; + + 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; @@ -459,7 +461,7 @@ where (\$object EOD; - $lines = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $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'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $query = 'select $parent from <#ri> @@ -484,7 +486,7 @@ function Islandora_collections_get_collection_from_pid($pid) { and $object \'' . $pid . '\' order by $object'; - $object_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $object_pids = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $object_pids = array_values(array_filter($object_pids)); return $object_pids; } @@ -499,7 +501,7 @@ function Islandora_collections_get_collection_from_pid($pid) { */ 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'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; global $user; @@ -539,7 +541,7 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe minus $content order by ' . $orderby; - $results = $restConnection->repository->ri->itqlQuery($query_string, $limit, $offset); + $results = $rest_connection->repository->ri->itqlQuery($query_string, $limit, $offset); return $results; } @@ -573,13 +575,13 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe // $collectionHelper = new CollectionClass(); module_load_include('inc', 'islandora', 'RestConnection'); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); $pids = array(); $query = 'select $object from <#ri> where $object and $object '; // $content_models = $collectionHelper->getRelatedItems($pid, $query); - $content_models = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $content_models = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); if (empty($content_models)) { return $pids; @@ -609,7 +611,7 @@ function get_related_items_as_array($collection_pid, $relationship = array('isMe */ function get_content_models_as_option_array() { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); require_once 'sites/all/libraries/tuque/RepositoryQuery.php'; $restricted = variable_get('fedora_namespace_restriction_enforced', TRUE); @@ -627,7 +629,7 @@ function get_content_models_as_option_array() { and $object ) order by $title'; - $list = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0'); + $list = $rest_connection->repository->ri->itqlQuery($query, 'unlimited', '0'); $options = array(); foreach ($list as $item) { //removes blanks if ($item) { @@ -646,10 +648,10 @@ function get_content_models_as_option_array() { function getContentModels($collection_pid, $showError = TRUE) { module_load_include('inc', 'islandora', 'RestConnection'); - $restConnection = new RestConnection(); + $rest_connection = new RestConnection(); // module_load_include('inc', 'Fedora_Repository', 'ContentModel'); $collection_stream = $this->getCollectionPolicyStream($collection_pid); - $collection_object = new FedoraObject($collection_pid, $restConnection->repository); + $collection_object = new FedoraObject($collection_pid, $rest_connection->repository); $collection_stream = $collection_object->getDatastream('COLLECTION_POLICY'); try { $xml = new SimpleXMLElement($collection_stream); diff --git a/islandora_basic_collection/includes/DeleteCollection.inc b/islandora_basic_collection/includes/DeleteCollection.inc index a8598095..42821e37 100644 --- a/islandora_basic_collection/includes/DeleteCollection.inc +++ b/islandora_basic_collection/includes/DeleteCollection.inc @@ -17,7 +17,7 @@ function islandora_collection_deletion_form($form, &$form_state, $pid) { $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"; + $submit_text_message = ($table) ? "Delete selected objects" : "Delete collection"; $form = array(); diff --git a/islandora_basic_collection/includes/ManagePolicies.inc b/islandora_basic_collection/includes/ManagePolicies.inc index 14a94a8b..d4924c1b 100644 --- a/islandora_basic_collection/includes/ManagePolicies.inc +++ b/islandora_basic_collection/includes/ManagePolicies.inc @@ -28,11 +28,6 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { } } - $new_options = array(); - if (is_array($content_models) && is_array($cm_options)) { - $new_options = array_diff_key($content_models, $cm_options); - } - $namespace = substr($collection_pid, 0, strpos($collection_pid, ":")); $collection_policy_dsid = variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'); @@ -94,7 +89,7 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { $form['manage_collection_policy']['add']['submit'] = array( '#type' => 'submit', - '#value' => t('Add Content Model to Collection Policy'), + '#value' => t('Add content model to collection policy'), '#id' => 'add_cm' ); @@ -115,7 +110,7 @@ function islandora_manage_policies_form($form, &$form_state, $collection_pid) { $form['manage_collection_policy']['remove']['submit'] = array( '#type' => 'submit', - '#value' => t('Remove Content Model From Collection Policy'), + '#value' => t('Remove content model from collection policy'), '#id' => 'remove_cm' ); } @@ -127,7 +122,6 @@ function islandora_manage_policies_form_validate($form, &$form_state) { } function islandora_manage_policies_form_submit($form, &$form_state) { - module_load_include('inc', 'islandora_basic_collection', 'CollectionPolicy'); module_load_include('inc', 'islandora', 'RestConnection'); $rest_connection = new RestConnection();