Paul Pound
13 years ago
29 changed files with 567 additions and 691 deletions
@ -1,11 +1,9 @@ |
|||||||
<?php |
<?php |
||||||
|
|
||||||
function islandora_get_breadcrumbs($pid) { |
function islandora_get_breadcrumbs($object) { |
||||||
module_load_include('inc', 'islandora', 'RestConnection'); |
|
||||||
$breadcrumbs = array(); |
$breadcrumbs = array(); |
||||||
|
|
||||||
$connection = new RestConnection(); |
islandora_get_breadcrumbs_recursive($object->id, $breadcrumbs, $object->repository); |
||||||
islandora_get_breadcrumbs_recursive($pid, $breadcrumbs, $connection->repository); |
|
||||||
|
|
||||||
if(isset($breadcrumbs[0])) { |
if(isset($breadcrumbs[0])) { |
||||||
unset($breadcrumbs[0]); |
unset($breadcrumbs[0]); |
@ -0,0 +1,160 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* Gives the option of deleting or purging and object. |
||||||
|
* |
||||||
|
* The default behaviour is to purge the object to reduce maintenance. |
||||||
|
* If a solution pack wants to change this behaviour and have the object set to deleted then |
||||||
|
* it can respond to the 'islandora_pre_purge_object' hook with an array containing the pair |
||||||
|
* 'delete' => TRUE. |
||||||
|
* Once the object has been deleted/purged then a second call lets the solution packs know that |
||||||
|
* the object has been dealt with. In this call the object id and content models are sent out so |
||||||
|
* that the solution packs can act on this news. There is no guarantee that the object still exists |
||||||
|
* and so the object object isn't sent. |
||||||
|
* |
||||||
|
* @param string $object_id |
||||||
|
* ID of the object |
||||||
|
* @return type |
||||||
|
*/ |
||||||
|
function islandora_purge_object_submit($form, &$form_state) { |
||||||
|
|
||||||
|
$object_id = $form_state['values']['pid']; |
||||||
|
$collection = $form_state['values']['col']; |
||||||
|
|
||||||
|
if (!$object_id) { |
||||||
|
drupal_set_message(t('Cannot remove object, object id not set')); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
$object = islandora_object_load($object_id); |
||||||
|
|
||||||
|
if (!$object) { |
||||||
|
drupal_set_message(t('Could not remove object, object not found')); |
||||||
|
return; |
||||||
|
} |
||||||
|
$content_models = $object->models; |
||||||
|
$arr = module_invoke_all('islandora_pre_purge_object', $object); //notify modules of pending deletion |
||||||
|
if (isset($arr['delete']) && $arr['delete']) { |
||||||
|
try { |
||||||
|
$object->delete(); |
||||||
|
} catch (Exception $e) { |
||||||
|
drupal_set_message(t('Error deleting Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
try { |
||||||
|
$object->repository->purgeObject($object_id); |
||||||
|
} catch (Exception $e) { |
||||||
|
drupal_set_message(t('Error purging Islandora object %s %e', array('%s' => $object_id, '%e' => $e)), 'error'); |
||||||
|
return ""; |
||||||
|
} |
||||||
|
} |
||||||
|
module_invoke_all('islandora_post_purge_object', $object_id, $content_models); //notify modules post deletion |
||||||
|
drupal_goto($collection); |
||||||
|
} |
||||||
|
|
||||||
|
function islandora_purge_object($form, &$form_state, $object) { |
||||||
|
module_load_include('inc', 'islandora', 'includes/datastream'); |
||||||
|
|
||||||
|
$parent = islandora_datastream_get_parents($object); |
||||||
|
$key = array_keys($parent); |
||||||
|
|
||||||
|
if (count($key) > 0) { |
||||||
|
$redirect = "islandora/object/$key[0]"; |
||||||
|
} |
||||||
|
else { |
||||||
|
$redirect = "islandora"; |
||||||
|
} |
||||||
|
|
||||||
|
$form['pid'] = array('#type' => 'value', '#value' => $object->id); |
||||||
|
$form['col'] = array('#type' => 'value', '#value' => $redirect); |
||||||
|
|
||||||
|
return confirm_form($form, |
||||||
|
t('Are you sure you want to delete %title?', array('%title' => $object->label)), |
||||||
|
"islandora/object/$object->id", |
||||||
|
t('This action cannot be undone.'), |
||||||
|
t('Delete'), |
||||||
|
t('Cancel') |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
function islandora_purge_datastream($form, &$form_state, $object, $datastream_id) { |
||||||
|
module_load_include('inc', 'islandora', 'includes/datastream'); |
||||||
|
|
||||||
|
$datastream = $object->getDatastream($datastream_id); |
||||||
|
|
||||||
|
$redirect = "islandora/object/$object->id"; |
||||||
|
|
||||||
|
$form['pid'] = array('#type' => 'value', '#value' => $object->id); |
||||||
|
$form['dsid'] = array('#type' => 'value', '#value' => $datastream_id); |
||||||
|
$form['col'] = array('#type' => 'value', '#value' => $redirect); |
||||||
|
|
||||||
|
return confirm_form($form, |
||||||
|
t('Are you sure you want to delete the %dsid datastream?', array('%dsid' => $datastream->id)), |
||||||
|
"islandora/object/$object->id", |
||||||
|
t('This action cannot be undone.'), |
||||||
|
t('Delete'), |
||||||
|
t('Cancel') |
||||||
|
); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Gives the option of purging or deleting a datastream. |
||||||
|
* |
||||||
|
* The default behaviour is to purge the datastream but this can be overridden using the |
||||||
|
* 'islandora_pre_purge_datastream' hook. The returned array can include a 'block' => TRUE |
||||||
|
* pair which will prevent the datastream from being deleted if it particularly needed for |
||||||
|
* a certain function. Returning 'delete' => TRUE will cause the datastream to be put into |
||||||
|
* a deleted state. |
||||||
|
* |
||||||
|
* @param string $object_id |
||||||
|
* ID of the object |
||||||
|
* @param string $datastream_id |
||||||
|
* ID of the datastream |
||||||
|
* |
||||||
|
*/ |
||||||
|
function islandora_purge_datastream_submit($form, &$form_state) { |
||||||
|
$object_id = $form_state['values']['pid']; |
||||||
|
$datastream_id = $form_state['values']['dsid']; |
||||||
|
|
||||||
|
if (!isset($datastream_id)) { |
||||||
|
drupal_set_message(t('Cannot remove datastream, datastream id not set')); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
$object = islandora_object_load($object_id); |
||||||
|
|
||||||
|
if (!isset($object)) { |
||||||
|
drupal_set_message(t('Could not remove object, object not found')); |
||||||
|
return; |
||||||
|
} |
||||||
|
|
||||||
|
//notify modules of pending deletion so we can update rels etc |
||||||
|
$arr = module_invoke_all('islandora_pre_purge_datastream', $object[$datastream_id]); |
||||||
|
|
||||||
|
if (isset($arr['block']) && $arr['block']) { |
||||||
|
drupal_set_message(t('Purging of the %d datastream was blocked', array('%d' => $datastream_id)), 'warning'); |
||||||
|
return; |
||||||
|
} |
||||||
|
if (isset($arr['delete']) && $arr['delete']) { |
||||||
|
try { |
||||||
|
$object[$datastream_id]->state = 'D'; |
||||||
|
} catch (Exception $e) { |
||||||
|
drupal_set_message(t('Error deleting %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object->id, '%e' => $e)), 'error'); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
else { |
||||||
|
try { |
||||||
|
$object->purgeDatastream($datastream_id); |
||||||
|
} catch (Exception $e) { |
||||||
|
drupal_set_message(t('Error purging %s datastream from Islandora object %o %e', array('%s' => $datastream_id, '%o' => $object_id, '%e' => $e)), 'error'); |
||||||
|
return; |
||||||
|
} |
||||||
|
} |
||||||
|
//notify modules post deletion |
||||||
|
module_invoke_all('islandora_post_purge_datastream', $object, $datastream_id); |
||||||
|
drupal_set_message(t('%d datastream sucessfully purged from Islandora object %o', array('%d' => $datastream_id, '%o' => $object->label))); |
||||||
|
drupal_goto('islandora/object/' . $object->id); |
||||||
|
} |
@ -0,0 +1,91 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
/** |
||||||
|
* preprocess the edit template |
||||||
|
* @global string $base_url |
||||||
|
* @param array $variables |
||||||
|
* theme variables for the edit template |
||||||
|
*/ |
||||||
|
function islandora_preprocess_islandora_default_edit(&$variables) { |
||||||
|
$islandora_object = $variables['islandora_object']; |
||||||
|
global $base_url; |
||||||
|
$datastreams = array(); |
||||||
|
$variables['islandora_editmetadata_url'] = $base_url . '/islandora/edit_form/' . $islandora_object->id; |
||||||
|
module_load_include('inc', 'islandora', 'includes/datastream'); |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
// $variables['add_datastream_form'] = drupal_get_form('islandora_add_datastream_form', $islandora_object->id); |
||||||
|
$header = array( |
||||||
|
array('data' => t('ID')), |
||||||
|
array('data' => t('Label')), |
||||||
|
array('data' => t('Type')), |
||||||
|
array('data' => t('Mime type')), |
||||||
|
array('data' => t('Size')), |
||||||
|
array('data' => t('Operations'), 'colspan' => '3'), |
||||||
|
//array('data' => t('Delete')), |
||||||
|
); |
||||||
|
$table_attributes = array('class' => array('manage-datastreams')); |
||||||
|
$rows = array(); |
||||||
|
foreach ($islandora_object as $ds) { |
||||||
|
$rows[] = array( |
||||||
|
array('class' => 'datastream-id', 'data' => l($ds->id, islandora_datastream_get_url($ds, 'view'))), |
||||||
|
array('class' => 'datastream-label', 'data' => $ds->label), |
||||||
|
array('class' => 'datastream-control', 'data' => islandora_control_group_to_human_readable($ds->controlGroup)), |
||||||
|
array('class' => 'datastream-mime', 'data' => $ds->mimeType), |
||||||
|
array('class' => 'datastream-size', 'data' => islandora_datastream_get_human_readable_size($ds)), |
||||||
|
array('class' => 'datastream-download', 'data' => l(t('download'), islandora_datastream_get_url($ds, 'download'))), |
||||||
|
array('class' => 'datstream-edit', 'data' => islandora_datastream_edit_get_link($islandora_object, $ds->id)), |
||||||
|
array('class' => 'datastream-delete', 'data' => islandora_datastream_get_delete_link($ds)), |
||||||
|
); |
||||||
|
} |
||||||
|
$caption = $islandora_object->label . ' - ' . $islandora_object->id; |
||||||
|
$table = array('colgroups' => NULL, 'sticky' => TRUE, 'empty' => 'Error loading datastreams', 'caption' => $caption, 'header' => $header, 'rows' => $rows, 'attributes' => $table_attributes); |
||||||
|
$variables['datastream_table'] = theme_table($table); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* preprocess for the default view template |
||||||
|
* @global string $base_url |
||||||
|
* @param array $variables |
||||||
|
*/ |
||||||
|
function islandora_preprocess_islandora_default(&$variables) { |
||||||
|
drupal_add_js('misc/form.js'); |
||||||
|
drupal_add_js('misc/collapse.js'); |
||||||
|
$islandora_object = $variables['islandora_object']; |
||||||
|
module_load_include('inc', 'islandora', 'includes/islandora_dublin_core'); |
||||||
|
module_load_include('inc', 'islandora', 'includes/utilities'); |
||||||
|
module_load_include('inc', 'islandora', 'includes/datastream'); |
||||||
|
|
||||||
|
$variables['parent_collections'] = islandora_datastream_get_parents($islandora_object); |
||||||
|
|
||||||
|
$datastreams = array(); |
||||||
|
foreach ($islandora_object as $ds) { |
||||||
|
$pid = $islandora_object->id; |
||||||
|
$id = $ds->id; |
||||||
|
$label = $ds->label; |
||||||
|
$download_path = islandora_datastream_get_url($ds, 'download'); |
||||||
|
$datastreams[$id]['id'] = $id; |
||||||
|
$datastreams[$id]['label'] = $label; |
||||||
|
$datastreams[$id]['label_link'] = l($label, $download_path); |
||||||
|
$datastreams[$id]['download_url'] = $download_path; |
||||||
|
$datastreams[$id]['mimetype'] = $ds->mimetype; |
||||||
|
$datastreams[$id]['size'] = islandora_datastream_get_human_readable_size($ds); |
||||||
|
$datastreams[$id]['created_date'] = $ds->createdDate->format("Y-m-d"); |
||||||
|
$datastreams[$id]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $id)); |
||||||
|
} |
||||||
|
$variables['datastreams'] = $datastreams; |
||||||
|
try { |
||||||
|
$dc = $islandora_object['DC']->content; |
||||||
|
//$dc_xml = simplexml_load_string($dc); |
||||||
|
$dc_object = Dublin_Core::import_from_xml_string($dc); |
||||||
|
} catch (Exception $e) { |
||||||
|
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error'); |
||||||
|
} |
||||||
|
$variables['dc_array'] = $dc_object->as_formatted_array(); |
||||||
|
$variables['islandora_dublin_core'] = $dc_object; |
||||||
|
$variables['islandora_object_label'] = $islandora_object->label; |
||||||
|
global $base_url; |
||||||
|
if (isset($islandora_object['TN'])) { |
||||||
|
$variables['islandora_thumbnail_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/TN/view'; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue