From b48aef3162a6b482fdca15af629e69480e52232f Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 30 May 2012 11:11:30 -0300 Subject: [PATCH 1/7] Autocomplete --- includes/datastream.inc | 15 ++++++++++++++- islandora.module | 17 +++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 8ac9e9de..75404f68 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -339,6 +339,7 @@ function islandora_add_datastream_form($form, &$form_state, $object_id) { '#value' => t('Add Datastream') ); + /* if (!empty($unused_dsids)) { $dsidsForForm = array(); foreach ($unused_dsids as $key => $value) { @@ -354,17 +355,29 @@ function islandora_add_datastream_form($form, &$form_state, $object_id) { $form['add_fieldset']['stream_id']['#options'] = $dsidsForForm; } else { + * + */ $form['add_fieldset']['stream_id'] = array( '#title' => 'Datastream ID', '#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.'), '#type' => 'textfield', '#weight' => -1, + '#autocomplete_path' => "islandora/object/$object_id/manage/datastreams/add/autocomplete", ); - } + //} return $form; } +function islandora_datastream_autocomplete_callback($object_id) { + $dsids = islandora_get_unused_dsids($object_id); + $output = array(); + foreach($dsids as $id => $ds) { + $output[$id] = $id; + } + drupal_json_output($output); +} + function islandora_datastream_get_human_readable_size($ds) { module_load_include('inc', 'islandora', 'includes/utilities'); diff --git a/islandora.module b/islandora.module index 15813359..76697a1e 100644 --- a/islandora.module +++ b/islandora.module @@ -170,16 +170,13 @@ function islandora_menu() { 'access arguments' => array(FEDORA_ADD_DS) ); - - // $items['islandora/object/%/add'] = array( - // 'title' => 'Add to an object', - // 'file' => 'includes/datastream.inc', - // 'page callback' => 'drupal_get_form', - // 'page arguments' => array('islandora_add_datastream_form',2), - // 'type' => MENU_NORMAL_ITEM, - // 'access arguments' => array(FEDORA_ADD_DS) - // ); - + $items['islandora/object/%/manage/datastreams/add/autocomplete'] = array( + 'file' => 'includes/datastream.inc', + 'page callback' => 'islandora_datastream_autocomplete_callback', + 'page arguments' => array(2), + 'type' => MENU_CALLBACK, + 'access arguments' => array(FEDORA_ADD_DS) + ); $items['islandora/object/%/datastream/%'] = array( 'title' => 'View datastream', From 93cb63b95951e9f974da16907de7721e35a1565c Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 30 May 2012 11:17:07 -0300 Subject: [PATCH 2/7] datastream --- includes/datastream.inc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 75404f68..31d14bf9 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -369,11 +369,19 @@ function islandora_add_datastream_form($form, &$form_state, $object_id) { return $form; } -function islandora_datastream_autocomplete_callback($object_id) { +function islandora_datastream_autocomplete_callback($object_id, $string = '') { $dsids = islandora_get_unused_dsids($object_id); $output = array(); foreach($dsids as $id => $ds) { - $output[$id] = $id; + if(trim($string) == '') { + $output[$id] = $id; + } + else { + $ret = stripos($id, $string); + if($ret !== FALSE) { + $output[$id] = $id; + } + } } drupal_json_output($output); } From bea8e8063b0de3a8ec8898c857b273e4f254e79f Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 30 May 2012 11:54:21 -0300 Subject: [PATCH 3/7] Updated datastream a little. --- includes/datastream.inc | 91 ++++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 31d14bf9..14fea9a0 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -210,27 +210,30 @@ function islandora_get_add_datastream_form($object_id, &$form_state) { */ function islandora_add_datastream_form_submit($form, &$form_state) { global $base_url; + module_load_include('inc', 'islandora', 'RestConnection'); if (!empty($form_state['submit']) && $form_state['submit'] == 'OK') { $form_state['rebuild'] = TRUE; return; } + module_load_include('inc', 'islandora', 'includes/MimeClass'); + $mimetype = new MimeClass(); + $file = $form_state['values']['add-stream-file-location']; $file = drupal_realpath($file); + $object_id = $form_state['values']['pid']; $dsid = $form_state['values']['stream_id']; - $ds_label = $form_state['values']['stream_label']; // Add the file extention to the end of the label.; - //$dformat = $mimetype->getType($file); + $ds_label = $form_state['values']['stream_label']; + $dformat = $mimetype->getMimeType($file); $controlGroup = "M"; - //if ($dformat == 'text/xml') { - // $controlGroup = 'X'; - //} - global $user; + try { - $restConnection = new RestConnection($user); - $fedora_object = new FedoraObject($object_id, $restConnection->repository); + $restConnection = new RestConnection(); + $fedora_object = $restConnection->repository->getObject($object_id); $ds = $fedora_object->constructDatastream($dsid, $controlGroup); $ds->label = $ds_label; + $ds->mimetype = $dformat; $ds->setContentFromFile($file); $fedora_object->ingestDatastream($ds); $d_file = file_load($form_state['values']['fid']); @@ -239,7 +242,8 @@ function islandora_add_datastream_form_submit($form, &$form_state) { drupal_set_message(t('@message', array('@message' => check_plain($e->getMessage()))), 'error'); return; } - $form_state['rebuild'] = TRUE; + drupal_set_message("Successfully Added Datastream!"); + drupal_goto("islandora/object/$object_id"); } /** @@ -251,6 +255,7 @@ function islandora_add_datastream_form_submit($form, &$form_state) { */ function islandora_add_datastream_form_validate($form, &$form_state) { module_load_include('inc', 'islandora', 'includes/MimeClass'); + module_load_include('inc', 'islandora', 'RestConnection'); $mimetype = new MimeClass(); if ($form_state['clicked_button']['#value'] == 'OK') { $form_state['rebuild'] = TRUE; @@ -274,13 +279,32 @@ function islandora_add_datastream_form_validate($form, &$form_state) { form_set_error('', t('Data stream Label cannot contain a "/".')); return FALSE; } + + $object_id = $form_state['values']['pid']; + $restConnection = new RestConnection(); + $fedora_object = $restConnection->repository->getObject($object_id); + + if(isset($fedora_object[$dsid])) { + form_set_error('', t('Data stream ID already exists in object.')); + return FALSE; + } + $mimetype = new MimeClass(); $unused_dsids = islandora_get_unused_dsids($form_state['values']['pid']); - $types_allowed = $unused_dsids[$dsid]; - $arr = array(); - foreach ($types_allowed as $type) { - $arr[] = $mimetype->getExtension($type); + if(isset($unused_dsids[$dsid])) { + $types_allowed = $unused_dsids[$dsid]; + $arr = array(); + foreach ($types_allowed as $type) { + $arr[] = $mimetype->getExtension($type); + } } + else { + // todo: this is unsafe, should probably be fixed see: + // http://api.drupal.org/api/drupal/includes!file.inc/function/file_save_upload/7 + $arr = array(); + } + + $file = file_save_upload('add-stream-file-location', array('file_validate_extensions' => $arr)); if ($file) { $form_state['values']['add-stream-file-location'] = $file->uri; @@ -339,33 +363,24 @@ function islandora_add_datastream_form($form, &$form_state, $object_id) { '#value' => t('Add Datastream') ); - /* - if (!empty($unused_dsids)) { - $dsidsForForm = array(); - foreach ($unused_dsids as $key => $value) { - $dsidsForForm[$key] = $key; + $unused_dsids = islandora_get_unused_dsids($object_id); + $dsidsForForm = ''; + $i = 0; + foreach ($unused_dsids as $key => $value) { + if($i++) { + $dsidsForForm .= ", "; } - $form['add_fieldset']['stream_id'] = array( - '#type' => 'select', - '#title' => t('Datastream ID'), - '#default_value' => variable_get('feed_item_length', 'teaser'), - '#weight' => '-1', - '#description' => t('Datastream IDs defined by the content model.'), - ); - $form['add_fieldset']['stream_id']['#options'] = $dsidsForForm; + $dsidsForForm .= "'$key'"; } - else { - * - */ - $form['add_fieldset']['stream_id'] = array( - '#title' => 'Datastream ID', - '#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.'), - '#type' => 'textfield', - '#weight' => -1, - '#autocomplete_path' => "islandora/object/$object_id/manage/datastreams/add/autocomplete", - ); - //} + + $form['add_fieldset']['stream_id'] = array( + '#title' => 'Datastream ID', + '#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: ' . $dsidsForForm . '.'), + '#type' => 'textfield', + '#weight' => -1, + '#autocomplete_path' => "islandora/object/$object_id/manage/datastreams/add/autocomplete", + ); return $form; } From ddc5ad96db347e60c659aa756ecbd0e7e5528f12 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 30 May 2012 12:59:02 -0300 Subject: [PATCH 4/7] Breadcrumbs --- includes/Breadcrumbs.inc | 78 ++++++++++++++++++++++++++++++++++++++++ islandora.module | 2 ++ 2 files changed, 80 insertions(+) create mode 100644 includes/Breadcrumbs.inc diff --git a/includes/Breadcrumbs.inc b/includes/Breadcrumbs.inc new file mode 100644 index 00000000..eb36111c --- /dev/null +++ b/includes/Breadcrumbs.inc @@ -0,0 +1,78 @@ +repository); + + if(isset($breadcrumbs[0])) { + unset($breadcrumbs[0]); + } + + $breadcrumbs = array_reverse($breadcrumbs); + + return $breadcrumbs; +} + +/** + * Builds an array of drupal links for use in breadcrumbs. + * + * @todo Make fully recursive... + * + * @global type $base_url + * @param type $pid + * @param type $breadcrumbs + * @param type $level + */ +function islandora_get_breadcrumbs_recursive($pid, &$breadcrumbs, $repository) { + // Before executing the query, we hve a base case of accessing the top-level collection + global $base_url; + static $max_level = 10; + static $level = -1; + + if (count($breadcrumbs) === 0) { + $level = $max_level; + } + + $root = variable_get('islandora_repository_pid', 'islandora:root'); + if ($pid == $root) { + $breadcrumbs[] = l(menu_get_active_title(), 'islandora'); + $breadcrumbs[] = l(t('Home'), ''); + } + else { + $query_string = 'select $parentObject $title $content from <#ri> + where ( + $title + and $parentObject $content + and ( + $parentObject + or $parentObject + or $parentObject + ) + and $parentObject + ) + minus $content + order by $title desc'; + $results = $repository->ri->itqlQuery($query_string); + + if (count($results) > 0 && $level > 0) { + $parent = $results[0]['parentObject']['value']; + $this_title = $results[0]['title']['value']; + + if (empty($this_title)) { + $this_title = t('-'); + } + + $breadcrumbs[] = l($this_title, "islandora/object/$pid"); + + $level--; + islandora_get_breadcrumbs_recursive($parent, $breadcrumbs, $repository); + } + else { + $breadcrumbs[] = '...'; //Add an non-link, as we don't know how to get back to the root. + islandora_get_breadcrumbs_recursive($root, $breadcrumbs, $repository); //And render the last two links and break (on the next pass). + } + } +} \ No newline at end of file diff --git a/islandora.module b/islandora.module index 76697a1e..3e1dabe3 100644 --- a/islandora.module +++ b/islandora.module @@ -480,6 +480,8 @@ function islandora_view_default_object() { * @return string */ function islandora_view_object($object_id = NULL) { + module_load_include('inc', 'islandora', 'includes/Breadcrumbs'); + drupal_set_breadcrumb(islandora_get_breadcrumbs($object_id)); //return $object_id; if (!isset($object_id)) { $object_id = variable_get('islandora_repository_pid', 'islandora:root'); From 2cd4ca5eeb979c883f2e5aa94b80f153369d69b6 Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 30 May 2012 13:40:07 -0300 Subject: [PATCH 5/7] Updated collection manager. --- .../includes/ChangeContentModels.inc | 2 +- .../includes/ChildCollection.inc | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/islandora_basic_collection/includes/ChangeContentModels.inc b/islandora_basic_collection/includes/ChangeContentModels.inc index b1f956da..4448c57b 100644 --- a/islandora_basic_collection/includes/ChangeContentModels.inc +++ b/islandora_basic_collection/includes/ChangeContentModels.inc @@ -28,7 +28,7 @@ function islandora_change_content_models_form($form, &$form_state, $collection_p $collection_policy_datastream = $collection_object->getDatastream($collection_policy_dsid); $supported_collection_models = array(); - if ($collection_policy_datastream->content) { + if ($collection_policy_datastream && $collection_policy_datastream->content) { $collection_policy = new CollectionPolicy($collection_policy_datastream->content); $supported_collection_models = $collection_policy->getContentModels(); } diff --git a/islandora_basic_collection/includes/ChildCollection.inc b/islandora_basic_collection/includes/ChildCollection.inc index 682004dc..12382cfa 100644 --- a/islandora_basic_collection/includes/ChildCollection.inc +++ b/islandora_basic_collection/includes/ChildCollection.inc @@ -86,18 +86,15 @@ function islandora_create_child_collection_form_validate($form, &$form_state) { } function islandora_create_child_collection_form_submit($form, &$form_state) { - global $base_root; + global $base_url; module_load_include('inc', 'islandora', '/includes/islandora.ingest'); - $thumbnail = $base_root . '/' . drupal_get_path('module', 'islandora_basic_collection') . '/Crystal_Clear_filesystem_folder_grey.png'; + $thumbnail = $base_url . '/' . drupal_get_path('module', 'islandora_basic_collection') . '/Crystal_Clear_filesystem_folder_grey.png'; $new_collection_pid = $form_state['values']['new_collection_pid']; $new_collection_label = $form_state['values']['collection_name']; $namespace = $form_state['values']['collection_namespace']; // $all_cModels = get_content_models_as_option_array(); - $content_models = array('islandora:collectionCModel'); - $relationship = array( - 'uri' => FEDORA_RELS_EXT_URI, - 'value' => 'isMemberOfCollection', - ); + $content_models = array(array('pid' => 'islandora:collectionCModel')); + $relationship = 'isMemberOfCollection'; $fedora_object = islandora_ingest_get_object($content_models, $form_state['values']['current'], $relationship, $new_collection_pid); $fedora_object->label = $new_collection_label; From b600074575f712f3322dd7d181a7415cbb6d33ca Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 30 May 2012 14:03:33 -0300 Subject: [PATCH 6/7] Fixed datastream error handling --- includes/datastream.inc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 14fea9a0..696eef7c 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -19,21 +19,20 @@ function islandora_datastream_as_attachment($object_id, $dsid) { try { $restConnection = new RestConnection($user); $fedora_object = new FedoraObject($object_id, $restConnection->repository); + header('Content-type: ' . $fedora_object[$dsid]->mimetype); + if($fedora_object[$dsid]->controlGroup == 'M' || $fedora_object[$dsid]->controlGroup == 'X') { + header('Content-length: ' . $fedora_object[$dsid]->size); + } + header("Cache-control: private"); + $method = arg(5); + if (isset($method) && $method == 'download') { + header("Content-Disposition: attachment; filename=\"" . $fedora_object[$dsid]->label); + } + print($fedora_object[$dsid]->content); + exit(); } catch (Exception $e) { - drupal_set_message(t('Error getting Islanndora datastream $d for object %s', array('%s' => $object_id, '%d' => $dsid)), 'error'); - return""; - } - header('Content-type: ' . $fedora_object[$dsid]->mimetype); - if($fedora_object[$dsid]->controlGroup == 'M' || $fedora_object[$dsid]->controlGroup == 'X') { - header('Content-length: ' . $fedora_object[$dsid]->size); - } - header("Cache-control: private"); - $method = arg(5); - if (isset($method) && $method == 'download') { - header("Content-Disposition: attachment; filename=\"" . $fedora_object[$dsid]->label); + return drupal_not_found();; } - print($fedora_object[$dsid]->content); - exit(); } function islandora_get_datastream_parents($islandora_object) { From 5499cfd659f3ada66430cbfbdc6c140903a00dbe Mon Sep 17 00:00:00 2001 From: jonathangreen Date: Wed, 30 May 2012 14:07:32 -0300 Subject: [PATCH 7/7] Getting rid of datastream not found messages. --- includes/datastream.inc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 696eef7c..d643b984 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -19,6 +19,12 @@ function islandora_datastream_as_attachment($object_id, $dsid) { try { $restConnection = new RestConnection($user); $fedora_object = new FedoraObject($object_id, $restConnection->repository); + + // if the object exists but the datastream doesn't + if(!isset($fedora_object[$dsid])) { + return drupal_not_found(); + } + header('Content-type: ' . $fedora_object[$dsid]->mimetype); if($fedora_object[$dsid]->controlGroup == 'M' || $fedora_object[$dsid]->controlGroup == 'X') { header('Content-length: ' . $fedora_object[$dsid]->size); @@ -31,7 +37,7 @@ function islandora_datastream_as_attachment($object_id, $dsid) { print($fedora_object[$dsid]->content); exit(); } catch (Exception $e) { - return drupal_not_found();; + return drupal_not_found(); } }