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 * @param string $pid
*/ */
function delete_objects_as_batch($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; $name = $user->name;
$item_to_delete = new Fedora_Item($pid); $restConnection->repository->purgeObject($pid);
$item_to_delete->purge("$object purged by $name");
} }
/** /**
@ -419,42 +419,42 @@ function delete_objects_as_batch($pid) {
* @param string $pid * @param string $pid
*/ */
function remove_collection_association($pid, $collection_pid) { function remove_collection_association($pid, $collection_pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'islandora', 'RestConnection');
$item = new Fedora_Item($pid); $restConnection = new RestConnection();
$item->purge_relationship('isMemberOfCollection', $collection_pid); $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 * returns content models associated with all objects in a collection
* @param string $pid * @param string $pid
* @return arrau * @return array
*/ */
function get_represented_content_models($pid) { function get_represented_content_models($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_utils'); module_load_include('inc', 'islandora', 'RestConnection');
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); $restConnection = new RestConnection();
require_once 'sites/all/libraries/tuque/RepositoryQuery.php';
$query = "select \$model from <#ri> $query = "select \$model from <#ri>
where (\$object <info:fedora/fedora-system:def/relations-external#isMemberOf> <info:fedora/$pid> 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>) 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 <info:fedora/fedora-system:def/model#hasModel> \$model";
$query = htmlentities(urlencode($query));
$content = ''; $model_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$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);
$represented_models = array(); $represented_models = array();
foreach ($model_pids as $model_pid) { foreach ($model_pids as $model_pid) {
if ($model_pid && $model_pid != 'fedora-system:FedoraObject-3.0') { if ($model_pid && $model_pid['object']['value'] != 'fedora-system:FedoraObject-3.0') {
$item = new fedora_item($model_pid);
$label = $item->objectProfile->objLabel; $represented_models[$model_pid['object']['value']] = $model_pid['object']['value'] . ' ~ ' . $model_pid['title']['value'];
$represented_models[$model_pid] = "$model_pid ~ $label";
} }
} }
return $represented_models; return $represented_models;
} }
function get_child_collections($collection_pid) { 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 $query = <<<EOD
select \$object from <#ri> 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> and \$object <info:fedora/fedora-system:def/relations-external#isMemberOfCollection> <info:fedora/$collection_pid>
EOD; EOD;
$query = htmlentities(urlencode($query)); $lines = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$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);
$collection_pids = array_values(array_filter($lines)); $collection_pids = array_values(array_filter($lines));
return $collection_pids; return $collection_pids;
} }
function Islandora_collections_get_collection_from_pid($pid) { 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 = 'select $parent from <#ri>
$query_string = 'select $parent from <#ri>
where ($object <fedora-rels-ext:isMemberOf> $parent where ($object <fedora-rels-ext:isMemberOf> $parent
or $object <fedora-rels-ext:isMemberOfCollection> $parent) or $object <fedora-rels-ext:isMemberOfCollection> $parent)
and $object <dc:identifier> \'' . $pid . '\' and $object <dc:identifier> \'' . $pid . '\'
order by $object'; order by $object';
$query_string = htmlentities(urlencode($query_string)); $object_pids = $restConnection->repository->ri->itqlQuery($query, 'unlimited', '0');
$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 = array_values(array_filter($object_pids)); $object_pids = array_values(array_filter($object_pids));
return $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']; $objects[$result['object']['value']] = $result['title']['value'];
$keys[] = $result['object']['value']; $keys[] = $result['object']['value'];
} }
$rows = array();
foreach ($objects as $key => $object) { foreach ($objects as $key => $object) {
$rows[$key] = array( $rows[$key] = array(
'#pid' => $key, '#pid' => $key,
@ -40,6 +40,10 @@ function islandora_collection_table($collection_pid) {
'title' => array('data' => t('Title')), 'title' => array('data' => t('Title')),
); );
if (!$rows) {
return;
}
$table = array( $table = array(
'#type' => 'tableselect', '#type' => 'tableselect',
'#header' => $header, '#header' => $header,
@ -47,6 +51,7 @@ function islandora_collection_table($collection_pid) {
); );
return $table; 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)), '#value' => t('@message', array('@message' => $submit_text_message)),
); );
return $form; return $form;
} }
function islandora_collection_deletion_form_submit($form, &$form_state) { function islandora_collection_deletion_form_submit($form, &$form_state) {
global $user; 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'); module_load_include('inc', 'islandora', 'RestConnection');
$restConnection = new RestConnection(); $restConnection = new RestConnection();
$collection_pid = $form_state['values']['current']; $collection_pid = $form_state['values']['current'];
$fedora_object = new FedoraObject($collection_pid, $restConnection->repository); $fedora_object = new FedoraObject($collection_pid, $restConnection->repository);
$parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection'); $parents = $fedora_object->relationships->get(NULL, 'isMemberOfCollection');
var_dump($parents); $parents = Islandora_collections_get_collection_from_pid($collection_pid);
// exit; $collection_pid = $form_state['values']['current'];
// $parents = Islandora_collections_get_collection_from_pid($collection_pid); if (isset($form_state['values']['delete_root']) && $form_state['values']['delete_root'] == 1) {
// $collection_pid = $form_state['values']['current'];
if ($form_state['values']['delete_root'] == 1) {
delete_root_collection($collection_pid); 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); $child_collections = get_child_collections($collection_pid);
$populated_child_collections = array(); $populated_child_collections = array();
$pids = @array_filter($form_state['values']['table']['selections']); $pids = @array_filter($form_state['values']['table']);
if (!empty($child_collections)) { if (!empty($child_collections)) {
foreach ($child_collections as $child) { 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) { foreach ($pids_to_delete as $pid_to_delete) {
$restConnection->repository->purgeObject($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) { function delete_root_collection($pid) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'islandora', 'RestConnection');
$item = new Fedora_Item($pid); try {
$item->purge(); $restConnection = new RestConnection();
drupal_set_message("$pid deleted."); $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