Browse Source

Generate the download form.

...  As opposed to spitting out markup for it directly.
pull/101/head
Adam Vessey 13 years ago
parent
commit
3696cab9ea
  1. 18
      ObjectHelper.inc
  2. 36
      fedora_repository.module

18
ObjectHelper.inc

@ -359,7 +359,7 @@ class ObjectHelper {
$content = ''; $content = '';
$id = $dataStreamValue->ID; $id = $dataStreamValue->ID;
$label = $dataStreamValue->label; $label = $dataStreamValue->label;
$label = str_replace("_", " ", $label); //$label = str_replace("_", " ", $label);
$label_deslashed = preg_replace('/\//i', '${1}_', $label); // Necessary to handle the case of Datastream labels that contain slashes. Ugh. $label_deslashed = preg_replace('/\//i', '${1}_', $label); // Necessary to handle the case of Datastream labels that contain slashes. Ugh.
$mimeType = $dataStreamValue->MIMEType; $mimeType = $dataStreamValue->MIMEType;
@ -368,20 +368,8 @@ class ObjectHelper {
'target' => '_blank', 'target' => '_blank',
), ),
)); ));
$action = url("fedora/repository/object_download/$pid/$id/$label_deslashed");
$downloadVersion = '<form method="GET" action="' . $action . '"><input type="submit" value="' . t('Download') . '"></form>'; $downloadVersion = drupal_get_form('fedora_repository_download_datastream_form', $pid, $id, $label_deslashed);
if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) {
$versions = $item->get_datastream_history($id);
if (is_array($versions)) {
$downloadVersion = '<form method="GET" action="' . $action . '" onsubmit="this.action=\'' . $action . '\' + \'/\'+this.version.value;">';
$downloadVersion .= '<input type="submit" value="' . t('Download') . '">';
$downloadVersion .= '<select name="version">';
foreach ($versions as $version) {
$downloadVersion .= '<option>' . $version->createDate . '</option>';
}
$downloadVersion .= '</select></form>';
}
}
return array( return array(
array( array(

36
fedora_repository.module

@ -623,6 +623,42 @@ function fedora_repository_purge_stream_form_submit($form, &$form_state) {
$form_state['redirect'] = $base_url . "/fedora/repository/$pid"; $form_state['redirect'] = $base_url . "/fedora/repository/$pid";
} }
function fedora_repository_download_datastream_form(&$form_state, $pid, $dsid, $label) {
$form = array(
'#action' => url("fedora/repository/object_download/$pid/$dsid/$label"),
'submit' => array(
'#type' => 'submit',
'#value' => t('Download'),
),
);
if (user_access(ObjectHelper::$EDIT_FEDORA_METADATA)) {
$item = new Fedora_Item($pid);
$versions = $item->get_datastream_history($dsid);
$version_array = array();
if (is_array($versions)) {
foreach ($versions as $version) {
$version_array[] = $version->createDate;
}
}
else {
$version_array[] = $versions->createDate;
}
if (count($version_array) > 1) {
$form['#attributes'] = array(
'onsubmit' => 'this.action="' . $form['#action'] . '/" + this.version.value;'
);
$form['version'] = array(
'#type' => 'select',
'#options' => array_combine($version_array, $version_array),
);
}
}
return $form;
}
/** /**
* fedora repository replace stream * fedora repository replace stream
* @param type $pid * @param type $pid

Loading…
Cancel
Save