From 4e766d6a6508d2001240c12adfebb8c264f6ef2b Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 30 May 2012 10:31:00 -0300 Subject: [PATCH] Generalized some datastream functions --- includes/datastream.inc | 21 +++++++++++++++++++++ islandora.module | 24 +++++++----------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 4d5ad968..8ac9e9de 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -364,3 +364,24 @@ function islandora_add_datastream_form($form, &$form_state, $object_id) { } return $form; } + +function islandora_datastream_get_human_readable_size($ds) { + module_load_include('inc', 'islandora', 'includes/utilities'); + + // we return - if we don't have a size + if($ds->controlGroup == 'M' || $ds->controlGroup == 'X') { + return islandora_convert_bytes_to_human_readable($ds->size); + } + else { + return '-'; + } +} + +function islandora_datastream_get_url($ds, $type = 'download') { + if($ds->controlGroup == 'R') { + return $ds->url; + } + else { + return "islandora/object/{$ds->parent->id}/datastream/{$ds->id}/$type"; + } +} \ No newline at end of file diff --git a/islandora.module b/islandora.module index 5025e273..15813359 100644 --- a/islandora.module +++ b/islandora.module @@ -607,23 +607,13 @@ function islandora_preprocess_islandora_default(&$variables) { $pid = $islandora_object->id; $id = $ds->id; $label = $ds->label; - if($ds->controlGroup != 'R') { - $download_path = 'islandora/object/' . $pid . '/datastream/' . $id . '/download'; - } - else { - $download_path = $ds->url; - } + $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; - if($ds->controlGroup == 'M' || $ds->controlGroup == 'X') { - $datastreams[$id]['size'] = islandora_convert_bytes_to_human_readable($ds->size); - } - else { - $datastreams[$id]['size'] = '-'; - } + $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)); } @@ -686,16 +676,16 @@ function islandora_preprocess_islandora_default_edit(&$variables) { array('data' => t('Operations'), 'colspan' => '2'), //array('data' => t('Delete')), ); - $table_attributes = array('class' => array('manage-datastrea')); + $table_attributes = array('class' => array('manage-datastreams')); $rows = array(); foreach ($islandora_object as $ds) { $rows[] = array( - array('class' => 'datastream-id', 'data' => $ds->id), - array('class' => 'datastream-label', 'data' => l($ds->label, $ds->controlGroup != 'R' ? $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/view' : $ds->url)), + 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' => $ds->controlGroup == 'M' || $ds->controlGroup == 'X' ? islandora_convert_bytes_to_human_readable($ds->size) : '-'), - array('class' => 'datastream-download', 'data' => l(t('download'), $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/download')), + 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' => 'datastream-delete', 'data' => l(t('delete'), $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/' . $ds->id . '/delete')), ); }