From 1be38b1aee57d277af50666e7312a9c7cceaf39a Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 28 Nov 2013 15:58:22 -0400 Subject: [PATCH 1/4] added responsibility filed to versions --- includes/datastream.version.inc | 92 +++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 22 deletions(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index 507a182f..15720bdf 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -1,4 +1,5 @@ parent; drupal_set_title(t("@dsid Previous Versions", array('@dsid' => $datastream->id))); + $audit_values = islandora_get_audit_trail($parent->id, $datastream->id); $header = array(); $header[] = array('data' => t('Created Date')); $header[] = array('data' => t('Size')); $header[] = array('data' => t('Label')); + $header[] = array('data' => t('Responsibility')); $header[] = array('data' => t('Mime type')); $header[] = array('data' => t('Operations'), 'colspan' => '2'); $rows = array(); foreach ($datastream as $version => $datastream_version) { $row = array(); + $reponsibility = $parent->owner; + foreach ($audit_values as $audit_value) { + $internal = $datastream_version->createdDate; + if ($audit_value['date'] == $datastream_version->createdDate) { + $reponsibility = $audit_value['responsibility']; + } + } + $user = user_load_by_name($reponsibility); + if ($user) { + $user_id = $user->uid; + $user_val = l($reponsibility, "user/$user_id"); + } + else { + $user_val = $reponsibility; + } $row[] = array( 'class' => 'datastream-date', 'data' => theme('islandora_datastream_view_link', array( @@ -39,6 +57,10 @@ function islandora_datastream_version_table($datastream) { 'class' => 'datastream-label', 'data' => $datastream_version->label, ); + $row[] = array( + 'class' => 'datastream-responsibility', + 'data' => $user_val, + ); $row[] = array( 'class' => 'datastream-mime', 'data' => $datastream_version->mimeType, @@ -85,12 +107,7 @@ function islandora_delete_datastream_version_form(array $form, array &$form_stat $form_state['datastream'] = $datastream; $form_state['version'] = $version; - return confirm_form($form, - t('Are you sure you want to delete version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), - "islandora/object/{$datastream->parent->id}", - t('This action cannot be undone.'), - t('Delete'), - t('Cancel') + return confirm_form($form, t('Are you sure you want to delete version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), "islandora/object/{$datastream->parent->id}", t('This action cannot be undone.'), t('Delete'), t('Cancel') ); } @@ -120,15 +137,15 @@ function islandora_delete_datastream_version_form_submit(array $form, array &$fo } catch (Exception $e) { drupal_set_message(t('Error deleting version %v of %s datastream from object %o %e', array( - '%v' => $version, - '%s' => $datastream_id, - '%o' => $object->label, - '%e' => $e->getMessage())), 'error'); + '%v' => $version, + '%s' => $datastream_id, + '%o' => $object->label, + '%e' => $e->getMessage())), 'error'); } drupal_set_message(t('%d datastream version successfully deleted from Islandora object %o', array( - '%d' => $datastream_id, - '%o' => $object->label))); + '%d' => $datastream_id, + '%o' => $object->label))); $form_state['redirect'] = "islandora/object/{$object->id}/datastream/{$datastream->id}/version"; } @@ -157,12 +174,7 @@ function islandora_revert_datastream_version_form(array $form, array &$form_stat $form_state['object_id'] = $datastream->parent->id; $form_state['version'] = $version; - return confirm_form($form, - t('Are you sure you want to revert to version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), - "islandora/object/{$datastream->parent->id}", - "", - t('Revert'), - t('Cancel') + return confirm_form($form, t('Are you sure you want to revert to version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), "islandora/object/{$datastream->parent->id}", "", t('Revert'), t('Cancel') ); } @@ -202,9 +214,45 @@ function islandora_revert_datastream_version_form_submit(array $form, array &$fo } drupal_set_message(t('%d datastream successfully reverted to version %v for Islandora object %o', array( - '%d' => $datastream_to_revert->id, - '%v' => $version, - '%o' => $islandora_object->label))); + '%d' => $datastream_to_revert->id, + '%v' => $version, + '%o' => $islandora_object->label))); $form_state['redirect'] = "islandora/object/{$islandora_object->id}/datastream/{$datastream_to_revert->id}/version"; } + +/** + * Gets Audit datastream values from foxml. + * + * @param String $pid + * PID of parent object + * + * @return array + * Array of audit values + */ +function islandora_get_audit_trail($pid, $dsid) { + $url = variable_get('islandora_base_url', 'http://localhost:8080/fedora'); + $connection = islandora_get_tuque_connection(NULL, $url); + $xml = $connection->api->m->getObjectXml($pid); + $simple_xml = simplexml_load_string($xml); + $fox_ns = "info:fedora/fedora-system:def/foxml#"; + $audit_ns = 'info:fedora/fedora-system:def/audit#'; + $foxml_nodes = $simple_xml->children($fox_ns); + foreach ($foxml_nodes as $node) { + if ($node->attributes()->ID == "AUDIT") { + $content = $node->datastreamVersion->xmlContent; + $audit_nodes = $content->children($audit_ns); + } + } + $audit_values = array(); + if (isset($audit_nodes)) { + foreach ($audit_nodes->auditTrail->record as $record) { + if ($dsid == $record->componentID) { + $values['responsibility'] = $record->responsibility; + $values['date'] = $record->date; + $audit_values[] = $values; + } + } + } + return $audit_values; +} From 28dda16086105d962e6361e4f1f13a9a81c56ea1 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 28 Nov 2013 16:02:10 -0400 Subject: [PATCH 2/4] added responsibility filed to versions --- includes/datastream.version.inc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index 15720bdf..6f501cc6 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -107,7 +107,12 @@ function islandora_delete_datastream_version_form(array $form, array &$form_stat $form_state['datastream'] = $datastream; $form_state['version'] = $version; - return confirm_form($form, t('Are you sure you want to delete version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), "islandora/object/{$datastream->parent->id}", t('This action cannot be undone.'), t('Delete'), t('Cancel') + return confirm_form($form, + t('Are you sure you want to delete version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), + "islandora/object/{$datastream->parent->id}", + t('This action cannot be undone.'), + t('Delete'), + t('Cancel') ); } From 82ffcea0c2a847eae2b83420d902cf4210ff06f3 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 28 Nov 2013 16:08:41 -0400 Subject: [PATCH 3/4] reverted formatting --- includes/datastream.version.inc | 35 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index 6f501cc6..3e926f37 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -108,11 +108,11 @@ function islandora_delete_datastream_version_form(array $form, array &$form_stat $form_state['datastream'] = $datastream; $form_state['version'] = $version; return confirm_form($form, - t('Are you sure you want to delete version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), - "islandora/object/{$datastream->parent->id}", - t('This action cannot be undone.'), - t('Delete'), - t('Cancel') + t('Are you sure you want to delete version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), + "islandora/object/{$datastream->parent->id}", + t('This action cannot be undone.'), + t('Delete'), + t('Cancel') ); } @@ -142,15 +142,15 @@ function islandora_delete_datastream_version_form_submit(array $form, array &$fo } catch (Exception $e) { drupal_set_message(t('Error deleting version %v of %s datastream from object %o %e', array( - '%v' => $version, - '%s' => $datastream_id, - '%o' => $object->label, - '%e' => $e->getMessage())), 'error'); + '%v' => $version, + '%s' => $datastream_id, + '%o' => $object->label, + '%e' => $e->getMessage())), 'error'); } drupal_set_message(t('%d datastream version successfully deleted from Islandora object %o', array( - '%d' => $datastream_id, - '%o' => $object->label))); + '%d' => $datastream_id, + '%o' => $object->label))); $form_state['redirect'] = "islandora/object/{$object->id}/datastream/{$datastream->id}/version"; } @@ -179,7 +179,12 @@ function islandora_revert_datastream_version_form(array $form, array &$form_stat $form_state['object_id'] = $datastream->parent->id; $form_state['version'] = $version; - return confirm_form($form, t('Are you sure you want to revert to version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), "islandora/object/{$datastream->parent->id}", "", t('Revert'), t('Cancel') + return confirm_form($form, + t('Are you sure you want to revert to version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), + "islandora/object/{$datastream->parent->id}", + "", + t('Revert'), + t('Cancel') ); } @@ -219,9 +224,9 @@ function islandora_revert_datastream_version_form_submit(array $form, array &$fo } drupal_set_message(t('%d datastream successfully reverted to version %v for Islandora object %o', array( - '%d' => $datastream_to_revert->id, - '%v' => $version, - '%o' => $islandora_object->label))); + '%d' => $datastream_to_revert->id, + '%v' => $version, + '%o' => $islandora_object->label))); $form_state['redirect'] = "islandora/object/{$islandora_object->id}/datastream/{$datastream_to_revert->id}/version"; } From 8242bd272a31145954f26f86a296d91642a7e033 Mon Sep 17 00:00:00 2001 From: Alan Stanley Date: Thu, 28 Nov 2013 16:10:42 -0400 Subject: [PATCH 4/4] reverted formatting --- includes/datastream.version.inc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/datastream.version.inc b/includes/datastream.version.inc index 3e926f37..8c02aaad 100644 --- a/includes/datastream.version.inc +++ b/includes/datastream.version.inc @@ -110,9 +110,9 @@ function islandora_delete_datastream_version_form(array $form, array &$form_stat return confirm_form($form, t('Are you sure you want to delete version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), "islandora/object/{$datastream->parent->id}", - t('This action cannot be undone.'), - t('Delete'), - t('Cancel') + t('This action cannot be undone.'), + t('Delete'), + t('Cancel') ); } @@ -182,9 +182,9 @@ function islandora_revert_datastream_version_form(array $form, array &$form_stat return confirm_form($form, t('Are you sure you want to revert to version @version of the @dsid datastream?', array('@dsid' => $datastream->id, '@version' => $version)), "islandora/object/{$datastream->parent->id}", - "", - t('Revert'), - t('Cancel') + "", + t('Revert'), + t('Cancel') ); }