Browse Source

Converted some fedora_collection functions to use the new API

pull/112/head
rwincewicz 13 years ago
parent
commit
3b6e7399aa
  1. 62
      islandora_basic_collection/includes/CollectionManagement.inc
  2. 7
      islandora_basic_collection/includes/CollectionManagerTable.inc
  3. 32
      islandora_basic_collection/includes/DeleteCollection.inc

62
islandora_basic_collection/includes/CollectionManagement.inc

@ -408,10 +408,10 @@ function collection_management_form_submit($form, &$form_state) {
* @param string $pid
*/
function delete_objects_as_batch($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$name = $user->name;
$item_to_delete = new Fedora_Item($pid);
$item_to_delete->purge("$object purged by $name");
$restConnection->repository->purgeObject($pid);
}
/**
@ -419,42 +419,42 @@ function delete_objects_as_batch($pid) {
* @param string $pid
*/
function remove_collection_association($pid, $collection_pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
$item->purge_relationship('isMemberOfCollection', $collection_pid);
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$fedora_object = new FedoraObject($pid, $restConnection->repository);
$fedora_object->relationships->remove(NULL, 'isMemberOfCollection', $collection_pid);
}
/**
* returns content models associated with all objects in a collection
* @param string $pid
* @return arrau
* @return array
*/
function get_represented_content_models($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$query = "select \$model 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";
$query = htmlentities(urlencode($query));
$content = '';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=csv&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query;
$content .= do_curl($url);
$results = explode("\n", $content);
$model_pids = preg_replace('/^info:fedora\/|"model"/', '', $results);
$model_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$represented_models = array();
foreach ($model_pids as $model_pid) {
if ($model_pid && $model_pid != 'fedora-system:FedoraObject-3.0') {
$item = new fedora_item($model_pid);
$label = $item->objectProfile->objLabel;
$represented_models[$model_pid] = "$model_pid ~ $label";
if ($model_pid && $model_pid['object']['value'] != 'fedora-system:FedoraObject-3.0') {
$represented_models[$model_pid['object']['value']] = $model_pid['object']['value'] . ' ~ ' . $model_pid['title']['value'];
}
}
return $represented_models;
}
function get_child_collections($collection_pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$query = <<<EOD
select \$object from <#ri>
@ -462,33 +462,23 @@ function get_child_collections($collection_pid) {
and \$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$collection_pid>
EOD;
$query = htmlentities(urlencode($query));
$content = '';
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= "?type=tuples&flush=TRUE&format=csv&limit=$limit&offset=$offset&lang=itql&stream=on&query=" . $query;
$content .= do_curl($url);
$results = explode("\n", $content);
$lines = preg_replace('/info:fedora\/|"object"/', '', $results);
$lines = $restConnection->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();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
$query_string = 'select $parent from <#ri>
$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';
$query_string = htmlentities(urlencode($query_string));
$url = variable_get('fedora_repository_url', 'http://localhost:8080/fedora/risearch');
$url .= '?type=tuples&flush=true&format=csv&limit=13000&lang=itql&stream=on&query=' . $query_string;
$content = do_curl($url, TRUE);
$results = explode("\n", $content);
$object_pids = preg_replace('/^info:fedora\/|"parent"| /', '', $results);
$object_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$object_pids = array_values(array_filter($object_pids));
return $object_pids;
}

7
islandora_basic_collection/includes/CollectionManagerTable.inc

@ -21,7 +21,7 @@ function islandora_collection_table($collection_pid) {
$objects[$result['object']['value']] = $result['title']['value'];
$keys[] = $result['object']['value'];
}
$rows = array();
foreach ($objects as $key => $object) {
$rows[$key] = array(
'#pid' => $key,
@ -40,6 +40,10 @@ function islandora_collection_table($collection_pid) {
'title' => array('data' => t('Title')),
);
if (!$rows) {
return;
}
$table = array(
'#type' => 'tableselect',
'#header' => $header,
@ -47,6 +51,7 @@ function islandora_collection_table($collection_pid) {
);
return $table;
}
/**

32
islandora_basic_collection/includes/DeleteCollection.inc

@ -43,33 +43,28 @@ function islandora_collection_deletion_form($form, &$form_state, $pid) {
'#value' => t('@message', array('@message' => $submit_text_message)),
);
return $form;
return $form;
}
function islandora_collection_deletion_form_submit($form, &$form_state) {
global $user;
// module_load_include('inc', 'fedora_repository', 'api/fedora_item');
// module_load_include('inc', 'fedora_repository', 'api/fedora_collection');
module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection();
$collection_pid = $form_state['values']['current'];
$fedora_object = new FedoraObject($collection_pid, $restConnection->repository);
$parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection');
var_dump($parents);
// exit;
// $parents = Islandora_collections_get_collection_from_pid($collection_pid);
// $collection_pid = $form_state['values']['current'];
if ($form_state['values']['delete_root'] == 1) {
$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/" . $parents[0]);
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']['selections']);
$pids = @array_filter($form_state['values']['table']);
if (!empty($child_collections)) {
foreach ($child_collections as $child) {
@ -93,12 +88,17 @@ function islandora_collection_deletion_form_submit($form, &$form_state) {
foreach ($pids_to_delete as $pid_to_delete) {
$restConnection->repository->purgeObject($pid_to_delete);
}
drupal_goto("islandora/" . $parents[0]);
drupal_goto("islandora/object/" . $collection_pid);
}
function delete_root_collection($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$item = new Fedora_Item($pid);
$item->purge();
drupal_set_message("$pid deleted.");
module_load_include('inc', 'islandora', 'RestConnection');
try {
$restConnection = new RestConnection();
$restConnection->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)));
}

Loading…
Cancel
Save