@ -1,11 +1,13 @@
<?php
<?php
/**
/**
* @file datastream.inc
* @file
* This file contains the admin form and callback functions for datastream manipulations.
*/
*/
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
/**
/**
* Callback function to view or download a datastream.
*
*
* @global object $user
* @global object $user
* @param string $object_id
* @param string $object_id
@ -55,7 +57,9 @@ function islandora_datastream_get_parents($islandora_object) {
$parent_collections[$pid]['label'] = $object->label;
$parent_collections[$pid]['label'] = $object->label;
$parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']);
$parent_collections[$pid]['label_link'] = l($parent_collections[$pid]['label'], $parent_collections[$pid]['url']);
}
}
catch (RepositoryException $e) {}
catch (RepositoryException $e) {
}
}
}
return $parent_collections;
return $parent_collections;
@ -168,9 +172,9 @@ function islandora_get_add_datastream_form($object, &$form_state) {
);
);
if (!empty($unused_dsids)) {
if (!empty($unused_dsids)) {
$dsidsForF orm = array();
$dsids_for_f orm = array();
foreach ($unused_dsids as $key => $value) {
foreach ($unused_dsids as $key => $value) {
$dsidsForF orm[$key] = $key;
$dsids_for_f orm[$key] = $key;
}
}
$form['add_fieldset']['stream_id'] = array(
$form['add_fieldset']['stream_id'] = array(
'#type' => 'select',
'#type' => 'select',
@ -179,7 +183,7 @@ function islandora_get_add_datastream_form($object, &$form_state) {
'#weight' => '-1',
'#weight' => '-1',
'#description' => t('Datastream IDs defined by the content model.'),
'#description' => t('Datastream IDs defined by the content model.'),
);
);
$form['add_fieldset']['stream_id']['#options'] = $dsidsForF orm;
$form['add_fieldset']['stream_id']['#options'] = $dsids_for_f orm;
}
}
else {
else {
$form['add_fieldset']['stream_id'] = array(
$form['add_fieldset']['stream_id'] = array(
@ -220,11 +224,11 @@ function islandora_add_datastream_form_submit($form, &$form_state) {
$dsid = $form_state['values']['stream_id'];
$dsid = $form_state['values']['stream_id'];
$ds_label = $form_state['values']['stream_label'];
$ds_label = $form_state['values']['stream_label'];
$dformat = $mimetype->getMimeType($file);
$dformat = $mimetype->getMimeType($file);
$controlG roup = "M";
$control_g roup = "M";
try {
try {
$fedora_object = islandora_object_load($object_id);
$fedora_object = islandora_object_load($object_id);
$ds = $fedora_object->constructDatastream($dsid, $controlG roup);
$ds = $fedora_object->constructDatastream($dsid, $control_g roup);
$ds->label = $ds_label;
$ds->label = $ds_label;
$ds->mimetype = $dformat;
$ds->mimetype = $dformat;
$ds->setContentFromFile($file);
$ds->setContentFromFile($file);
@ -235,7 +239,7 @@ function islandora_add_datastream_form_submit($form, &$form_state) {
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error');
return;
return;
}
}
drupal_set_message("Successfully Added Datastream!");
drupal_set_message(t( "Successfully Added Datastream!") );
drupal_goto("islandora/object/$object_id");
drupal_goto("islandora/object/$object_id");
}
}
@ -254,8 +258,8 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
return;
return;
}
}
$dsid = $form_state['values']['stream_id'];
$dsid = $form_state['values']['stream_id'];
$dsL abel = $form_state['values']['stream_label'];
$ds_l abel = $form_state['values']['stream_label'];
if (strlen($dsid) > 64) {
if (drupal_ strlen($dsid) > 64) {
form_set_error('', t('Data stream ID cannot be more than 64 characters.'));
form_set_error('', t('Data stream ID cannot be more than 64 characters.'));
return FALSE;
return FALSE;
}
}
@ -263,11 +267,11 @@ function islandora_add_datastream_form_validate($form, &$form_state) {
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid))));
form_set_error('', t("Data stream ID (@dsid) has to start with a letter.", array('@dsid' => check_plain($dsid))));
return FALSE;
return FALSE;
}
}
if (strlen($dsL abel) > 64) {
if (drupal_strlen($ds_l abel) > 64) {
form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
form_set_error('', t('Data stream Label cannot be more than 64 characters.'));
return FALSE;
return FALSE;
}
}
if (strpos($dsL abel, '/')) {
if (strpos($ds_l abel, '/')) {
form_set_error('', t('Data stream Label cannot contain a "/".'));
form_set_error('', t('Data stream Label cannot contain a "/".'));
return FALSE;
return FALSE;
}
}
@ -356,19 +360,19 @@ function islandora_add_datastream_form($form, &$form_state, $object) {
);
);
$unused_dsids = islandora_get_unused_dsids($object);
$unused_dsids = islandora_get_unused_dsids($object);
$dsidsForF orm = '';
$dsids_for_f orm = '';
$i = 0;
$i = 0;
foreach ($unused_dsids as $key => $value) {
foreach ($unused_dsids as $key => $value) {
if ($i++) {
if ($i++) {
$dsidsForF orm .= ", ";
$dsids_for_f orm .= ", ";
}
}
$dsidsForF orm .= "'$key'";
$dsids_for_f orm .= "'$key'";
}
}
$form['add_fieldset']['stream_id'] = array(
$form['add_fieldset']['stream_id'] = array(
'#title' => 'Datastream ID',
'#title' => 'Datastream ID',
'#required' => 'TRUE',
'#required' => 'TRUE',
'#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores. Datastreams that are defined by the content model dont currently exist: < b > ' . $dsidsForF orm . '< / b > .'),
'#description' => t('An ID for this stream that is unique to this object. Must start with a letter and contain only alphanumeric characters and dashes and underscores. Datastreams that are defined by the content model dont currently exist: < b > ' . $dsids_for_f orm . '< / b > .'),
'#type' => 'textfield',
'#type' => 'textfield',
'#weight' => -1,
'#weight' => -1,
'#autocomplete_path' => "islandora/object/$object->id/manage/datastreams/add/autocomplete",
'#autocomplete_path' => "islandora/object/$object->id/manage/datastreams/add/autocomplete",