Browse Source

Fix my mistakes in collection manager.

pull/123/merge
jonathangreen 13 years ago
parent
commit
ea91ee6dd3
  1. 28
      includes/utilities.inc
  2. 8
      islandora_basic_collection/includes/change_content_models.inc
  3. 19
      islandora_basic_collection/includes/child_collection.inc
  4. 4
      islandora_basic_collection/includes/collection_management.inc
  5. 6
      islandora_basic_collection/includes/delete_collection.inc
  6. 2
      islandora_basic_collection/includes/manage_policies.inc
  7. 3
      islandora_basic_collection/includes/move_collection.inc

28
includes/utilities.inc

@ -45,4 +45,32 @@ function islandora_control_group_to_human_readable($control_group) {
default:
return $control_group;
}
}
/**
* valid pid ??
* @param type $pid
* @return boolean
*/
function islandora_validate_pid($pid) {
$valid = FALSE;
if (strlen(trim($pid)) <= 64 && preg_match('/^([A-Za-z0-9]|-|\.)+:(([A-Za-z0-9])|-|\.|~|_|(%[0-9A-F]{2}))+$/', trim($pid))) {
$valid = TRUE;
}
return $valid;
}
/**
* Valid Dsid ??
* @param type $dsid
* @return boolean
*/
function islandora_validadte_dsid($dsid) {
$valid = FALSE;
if (strlen(trim($dsid)) <= 64 && preg_match('/^[a-zA-Z0-9\_\-\.]+$/', trim($dsid))) {
$valid = TRUE;
}
return $valid;
}

8
islandora_basic_collection/includes/change_content_models.inc

@ -86,7 +86,7 @@ function islandora_change_content_models_form_submit($form, &$form_state) {
$collection_pid = $form_state['values']['collection_pid'];
$current_content_model_object = islandora_object_load($current_content_model);
$collection_object = islandora_load_object($form_state['values']['collection_pid']);
$collection_object = islandora_object_load($form_state['values']['collection_pid']);
$collection_policy_datastream = $collection_object->getDatastream(variable_get('Islandora_Collection_Policy_DSID', 'COLLECTION_POLICY'));
$policy = new CollectionPolicy($collection_policy_datastream->content);
@ -105,7 +105,7 @@ function islandora_change_content_models_form_submit($form, &$form_state) {
}
}
if ($add_to_policy) {
$new_content_model_object = new FedoraObject($new_content_model, $rest_connection->repository);
$new_content_model_object = islandora_object_load($new_content_model);
$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');
@ -129,14 +129,14 @@ function islandora_change_content_models_form_submit($form, &$form_state) {
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');
$objects = $collection_object->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 = islandora_object_load($object['object']['value']);
$fedora_item->relationships->remove(FEDORA_MODEL_URI, 'hasModel', $current_content_model);
$fedora_item->relationships->add(FEDORA_MODEL_URI, 'hasModel', $new_content_model);
$count++;

19
islandora_basic_collection/includes/child_collection.inc

@ -119,7 +119,20 @@ function islandora_create_child_collection_form($form, &$form_state, $collection
}
function islandora_create_child_collection_form_validate($form, &$form_state) {
module_load_include('inc', 'islandora', 'includes/utilities');
$new_collection_pid = $form_state['values']['new_collection_pid'];
if($new_collection_pid) {
$valid = islandora_validate_pid($new_collection_pid);
if(!$valid) {
form_set_error('new_collection_pid', 'Collection PID is Invalid.');
}
else {
$object = islandora_object_load($new_collection_pid);
if($object !== NULL) {
form_set_error('new_collection_pid', 'Collection PID already exists.');
}
}
}
}
/**
@ -136,7 +149,7 @@ function islandora_create_child_collection_form_submit($form, &$form_state) {
$new_collection_pid = $form_state['values']['new_collection_pid'];
$this_collection_pid = $form_state['values']['current'];
if(empty($new_collection_pid)) {
$collection_namespace = substr($this_collection_pid, 0, strpos($this_collection_pid, ":"));
$new_collection_pid = substr($this_collection_pid, 0, strpos($this_collection_pid, ":"));
}
$new_collection_label = $form_state['values']['collection_name'];
$namespace = $form_state['values']['collection_namespace'];
@ -185,5 +198,5 @@ function islandora_create_child_collection_form_submit($form, &$form_state) {
$fedora_object->ingestDatastream($policy_datastream);
$new_fedora_object = islandora_ingest_add_object($fedora_object);
drupal_goto('/islandora/object/' . $new_collection_pid);
drupal_goto('/islandora/object/' . $fedora_object->id);
}

4
islandora_basic_collection/includes/collection_management.inc

@ -37,7 +37,7 @@ function get_child_collections($object) {
$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>
and \$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$object->id>
EOD;
$lines = $object->repository->ri->itqlQuery($query, 'unlimited', '0');
@ -49,7 +49,7 @@ function islandora_collections_get_collection_from_pid($object) {
$query = 'select $parent from <#ri>
where ($object <fedora-rels-ext:isMemberOf> $parent
or $object <fedora-rels-ext:isMemberOfCollection> $parent)
and $object <dc:identifier> \'' . $pid . '\'
and $object <dc:identifier> \'' . $object->id . '\'
order by $object';
$object_pids = $object->repository->ri->itqlQuery($query, 'unlimited', '0');

6
islandora_basic_collection/includes/delete_collection.inc

@ -67,7 +67,7 @@ function islandora_collection_deletion_form($form, &$form_state, $object) {
function islandora_collection_deletion_form_submit($form, &$form_state) {
$collection_pid = $form_state['values']['current'];
$fedora_object = islandora_object_load($collection_object);
$fedora_object = islandora_object_load($collection_pid);
$parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection');
$parents = islandora_collections_get_collection_from_pid($fedora_object);
@ -77,14 +77,14 @@ function islandora_collection_deletion_form_submit($form, &$form_state) {
drupal_goto("islandora/object/" . $parents[0]['parent']['value']);
}
$child_collections = get_child_collections($collection_pid);
$child_collections = get_child_collections($fedora_object);
$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(islandora_object_load($child), 'isMemberOfCollection');
$child_pids = get_related_items_as_array(islandora_object_load($child['object']['value']), 'isMemberOfCollection');
if (!empty($child_pids)) {
$populated_child_collections[] = $child;
}

2
islandora_basic_collection/includes/manage_policies.inc

@ -166,7 +166,7 @@ function islandora_manage_policies_form_submit($form, &$form_state) {
$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_object = islandora_object_load($cp_content_model);
$content_model_datastream = $content_model_object->getDatastream(variable_get('Islandora_Content_Model_DSID', 'ISLANDORACM'));
$content_models_element = $collection_policy_xml->getElementsByTagName('content_models');

3
islandora_basic_collection/includes/move_collection.inc

@ -64,7 +64,6 @@ function islandora_collection_migrate_form($form, &$form_state, $object) {
* @param array $form_state
*/
function islandora_collection_migrate_form_submit($form, &$form_state) {
$pids = array_filter($form_state['values']['table']);
$new_collection = $form_state['values']['new_collection'];
$current = $form_state['values']['current'];
@ -73,4 +72,6 @@ function islandora_collection_migrate_form_submit($form, &$form_state) {
$fedora_object->relationships->remove(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $current);
$fedora_object->relationships->add(FEDORA_RELS_EXT_URI, 'isMemberOfCollection', $new_collection);
}
drupal_set_message("@count objects successfully migrated!", array('@count' => count($pids)));
}
Loading…
Cancel
Save