@ -4,6 +4,7 @@
* @file datastream.inc
* @file datastream.inc
*/
*/
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
/**
/**
*
*
* @global object $user
* @global object $user
@ -12,9 +13,6 @@
* @return stream
* @return stream
* prints datastream to browser
* prints datastream to browser
*/
*/
define('DS_COMP_STREAM', 'DS-COMPOSITE-MODEL');
function islandora_datastream_as_attachment($object_id, $dsid) {
function islandora_datastream_as_attachment($object_id, $dsid) {
module_load_include('inc', 'islandora', 'RestConnection');
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
global $user;
@ -36,7 +34,6 @@ function islandora_datastream_as_attachment($object_id, $dsid) {
exit();
exit();
}
}
/**
/**
*
*
* @param array $arr
* @param array $arr
@ -44,7 +41,7 @@ function islandora_datastream_as_attachment($object_id, $dsid) {
* @param string $ds_comp_stream
* @param string $ds_comp_stream
* the dscomposite stream as xml
* the dscomposite stream as xml
*/
*/
function islandora_update_available _dsids_array(& $arr, $ds_comp_stream){
function islandora_get_defined _dsids_array(& $arr, $ds_comp_stream) {
$sxml = new SimpleXMLElement($ds_comp_stream);
$sxml = new SimpleXMLElement($ds_comp_stream);
foreach ($sxml->dsTypeModel as $ds) {
foreach ($sxml->dsTypeModel as $ds) {
//$arr[$ds['ID']]
//$arr[$ds['ID']]
@ -61,14 +58,12 @@ function islandora_update_available_dsids_array(&$arr, $ds_comp_stream){
}
}
/**
/**
* this function may not be being used
*
* @param type $pid
* @global type $user
* @param type $form_state
* @param string $object_id
* @return string
* @return string|array
*/
*/
function islandora_add_datastream_form($object_id, & $form_state) {
function islandora_get_unused_dsids($object_id) {
//dump_vars($form_state);
// Populate the list of datastream IDs.
module_load_include('inc', 'islandora', 'RestConnection');
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
global $user;
try {
try {
@ -76,76 +71,62 @@ function islandora_add_datastream_form($object_id, &$form_state) {
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) {
} catch (Exception $e) {
drupal_set_message(t('Error getting Islandora object %s ', array('%s' => $object_id)), 'error');
drupal_set_message(t('Error getting Islandora object %s ', array('%s' => $object_id)), 'error');
return "" ;
return;
}
}
if (!isset($fedora_object)) {
if (!isset($fedora_object)) {
drupal_set_message(t('Could not create add datastream form for %s'), array('%s' => $object_id));
drupal_set_message(t('Could not create add datastream form for %s'), array('%s' => $object_id));
return;
return;
}
}
$models = $fedora_object->models;
$models = $fedora_object->models;
$available _dsids = array();
$defined _dsids = array();
if (isset($models)) {
if (isset($models)) {
foreach ($models as $model) {
foreach ($models as $model) {
try {
try {
$model_object = new FedoraObject($model, $restConnection->repository);
$model_object = new FedoraObject($model, $restConnection->repository);
if (isset($model_object[DS_COMP_STREAM])) {
$dscomposite_stream = $model_object[DS_COMP_STREAM]->content;
$dscomposite_stream = $model_object[DS_COMP_STREAM]->content;
islandora_update_available_dsids_array($available_dsids, $dscomposite_stream);
islandora_get_defined_dsids_array($defined_dsids, $dscomposite_stream);
}
} catch (Exception $e) {
} catch (Exception $e) {
//do nothing as other objects may have a dscompsite stream
//do nothing as other objects may have a dscompsite stream
}
}
//$model_ds_comp =
}
}
}
/*if (!empty($content_models)) {
foreach ($content_models as $content_model) {
$newElements = $content_model->listDatastreams();
if (!empty($newElements)) {
$available_dsids = array_merge($available_dsids, $newElements);
}
}
foreach ($defined_dsids as $key => $value) {
if (isset($fedora_object[$key])) {
unset($defined_dsids[$key]); //ds exists in the object so don't show in the dropdown
}
}
}
}
return $defined_dsids;
$item = new Fedora_Item($pid);
$used_datastreams = $item->get_datastreams_list_as_SimpleXML();
$used_datastream_ids = array();
foreach ($used_datastreams->datastreamDef as $used_datastream) {
array_push($used_datastream_ids, $used_datastream->ID);
}
}
$unused_dsids = array();
if ($form_state['submitted'] & & $form_state['clicked_button']['#value'] != 'OK') {
/**
$form['add_datastream_label'] = array(
* buids the default add datastream form
'#value' => t('< br / > < h3 > The datastream has been uploaded.< / h3 > '),
* @param string $object_id
'#weight' => -10,
* @param array $form_state
);
* @return array
$form['#redirect'] = "fedora/repository/$pid/";
* a form ready to be rendered with a call to Drupal render
$form['submit'] = array(
*/
'#type' => 'submit',
function islandora_get_add_datastream_form($object_id, & $form_state) {
'#value' => t('OK')
$unused_dsids = islandora_get_unused_dsids($object_id); //$defined_dsids;
$form = array();
$form['add_fieldset'] = array(
'#type' => 'fieldset',
'#title' => 'Add a datastream',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
);
return $form;
$form['add_fieldset']['add_datastream_label'] = array(
}
if (!empty($available_dsids)) {
$unused_dsids = array_diff($available_dsids, $used_datastream_ids);
if (empty($unused_dsids)) {
return;
}
}
$form['add_datastream_label'] = array(
'#value' => t('< br / > < h3 > Add Datastream:< / h3 > '),
'#value' => t('< br / > < h3 > Add Datastream:< / h3 > '),
'#weight' => -10,
'#weight' => -10,
);
);
$form['pid'] = array(
$form['pid'] = array(
'#type' => 'hidden',
'#type' => 'hidden',
'#value' => "$p id"
'#value' => "$object_id"
);
);
$form['stream_label'] = array(
$form['add_fieldset'][' stream_label'] = array(
'#title' => 'Datastream Label',
'#title' => 'Datastream Label',
'#required' => 'TRUE',
'#required' => 'TRUE',
'#description' => t('A Human readable label'),
'#description' => t('A Human readable label'),
@ -153,35 +134,35 @@ function islandora_add_datastream_form($object_id, &$form_state) {
);
);
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['#attributes']['enctype'] = 'multipart/form-data';
$form['add-stream-file-location'] = array(
$form['add_fieldset']['add -stream-file-location'] = array(
'#type' => 'file',
'#type' => 'file',
'#title' => t('Upload Document'),
'#title' => t('Upload Document'),
'#size' => 48,
'#size' => 48,
// '#required'=>'TRUE',
// '#required'=>'TRUE',
'#description' => t('The file to upload.')
'#description' => t('The file to upload.')
);
);
$form['#redirect'] = "fedora/repository/$p id/";
$form['#redirect'] = "islandora/object/$object_ id/";
$form['submit'] = array(
$form['add_fieldset'][' submit'] = array(
'#type' => 'submit',
'#type' => 'submit',
'#value' => t('Add Datastream')
'#value' => t('Add Datastream')
);
);
if (!empty($unused_dsids)) {
if (!empty($unused_dsids)) {
$dsidsForForm = array();
$dsidsForForm = array();
foreach ($unused_dsids as $dsid ) {
foreach ($unused_dsids as $key => $value ) {
$dsidsForForm[$dsid] = $dsid ;
$dsidsForForm[$key] = $key ;
}
}
$form['stream_id'] = array(
$form['add_fieldset'][' stream_id'] = array(
'#type' => 'select',
'#type' => 'select',
'#title' => t('Datastream ID'),
'#title' => t('Datastream ID'),
'#default_value' => variable_get('feed_item_length', 'teaser'),
'#default_value' => variable_get('feed_item_length', 'teaser'),
'#weight' => '-1',
'#weight' => '-1',
'#description' => t('Datastream IDs defined by the content model.'),
'#description' => t('Datastream IDs defined by the content model.'),
);
);
$form['stream_id']['#options'] = array_combine($unused_dsids, $unused_dsids) ;
$form['add_fieldset']['stream_id']['#options'] = $dsidsForForm ;
}
}
else {
else {
$form['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.'),
'#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.'),
@ -189,5 +170,5 @@ function islandora_add_datastream_form($object_id, &$form_state) {
'#weight' => -1,
'#weight' => -1,
);
);
}
}
return $form;*/
return $form;
}
}