Browse Source

added ingest link to connection cmodel also updated image cmodel so derivatives get created

pull/120/merge
Paul Pound 13 years ago
parent
commit
f37d35e3b6
  1. 78
      includes/Breadcrumbs.inc
  2. 137
      includes/datastream.inc
  3. 23
      islandora.module
  4. 2
      islandora_basic_collection/includes/ChangeContentModels.inc
  5. 11
      islandora_basic_collection/includes/ChildCollection.inc
  6. 31
      islandora_basic_collection/islandora_basic_collection.module
  7. 21
      islandora_basic_image/includes/image_process.inc
  8. 22
      islandora_basic_image/islandora_basic_image.module

78
includes/Breadcrumbs.inc

@ -0,0 +1,78 @@
<?php
function islandora_get_breadcrumbs($pid) {
module_load_include('inc', 'islandora', 'RestConnection');
$breadcrumbs = array();
$connection = new RestConnection();
islandora_get_breadcrumbs_recursive($pid, $breadcrumbs, $connection->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'), '<front>');
}
else {
$query_string = 'select $parentObject $title $content from <#ri>
where (
<info:fedora/' . $pid . '> <fedora-model:label> $title
and $parentObject <fedora-model:hasModel> $content
and (
<info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOfCollection> $parentObject
or <info:fedora/' . $pid . '> <fedora-rels-ext:isMemberOf> $parentObject
or <info:fedora/' . $pid . '> <fedora-rels-ext:isPartOf> $parentObject
)
and $parentObject <fedora-model:state> <info:fedora/fedora-system:def/model#Active>
)
minus $content <mulgara:is> <info:fedora/fedora-system:FedoraObject-3.0>
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).
}
}
}

137
includes/datastream.inc

@ -19,22 +19,27 @@ 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);
}
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);
return drupal_not_found();
}
header("Cache-control: private");
$method = arg(5);
if (isset($method) && $method == 'download') {
header("Content-Disposition: attachment; filename=\"" . $fedora_object[$dsid]->label);
}
//maybe able to use drupal's file transfer here
print($fedora_object[$dsid]->content);
exit();
}
function islandora_get_datastream_parents($islandora_object) {
@ -211,27 +216,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']);
@ -240,7 +248,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");
}
/**
@ -252,6 +261,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;
@ -275,13 +285,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;
@ -340,32 +369,44 @@ 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;
}
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,
);
$dsidsForForm .= "'$key'";
}
$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: <b>' . $dsidsForForm . '</b>.'),
'#type' => 'textfield',
'#weight' => -1,
'#autocomplete_path' => "islandora/object/$object_id/manage/datastreams/add/autocomplete",
);
return $form;
}
function islandora_datastream_autocomplete_callback($object_id, $string = '') {
$dsids = islandora_get_unused_dsids($object_id);
$output = array();
foreach($dsids as $id => $ds) {
if(trim($string) == '') {
$output[$id] = $id;
}
else {
$ret = stripos($id, $string);
if($ret !== FALSE) {
$output[$id] = $id;
}
}
}
drupal_json_output($output);
}
function islandora_datastream_get_human_readable_size($ds) {
module_load_include('inc', 'islandora', 'includes/utilities');

23
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',
@ -483,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');
@ -500,14 +499,14 @@ function islandora_view_object($object_id = NULL) {
drupal_set_message(t('Error getting Islandora object %s', array('%s' => $object_id)), 'error');
return"";
}
drupal_alter('islandora_view_object', $fedora_object); //modify object if required before it is passed along
drupal_alter('islandora_object', $fedora_object); //modify object if required before it is passed along
$arr = module_invoke_all('islandora_view_object', $fedora_object, $user, $page_number, $page_size); //allow submodules to decide how to handle content base on object type
if (empty($arr)) {
//TODO: make sure we iterate over the array as they will be more then one cmodel per object
drupal_set_message(t('there was an error loading the view for islandora object %s', array('%s' => $object_id)), 'error');
return "";
}
//module_invoke_all(islandora_display($arr)),
drupal_alter('islandora_display',$arr);
$output = "";
foreach ($arr as $key => $value) {
$output .= $value; //if we have multiple modules handle one cmodel we need to iterate over multiple

2
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();
}

11
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;

31
islandora_basic_collection/islandora_basic_collection.module

@ -61,6 +61,26 @@ function islandora_basic_collection_menu() {
return $items;
}
/**
* Implements hook_menu_local_tasks_alter().
*/
function islandora_basic_collection_menu_local_tasks_alter(&$data, $router_item, $root_path) {
if (module_exists('islandora_content_model_forms')) {
// Add action link
if ($root_path == 'islandora/object/%/manage/collection') {
$object_id = $router_item['page_arguments'][0];
$item = menu_get_item("islandora/ingest_form/$object_id");
$item['title'] = 'Add a repository item';
if ($item['access']) {
$data['actions']['output'][] = array(
'#theme' => 'menu_local_action',
'#link' => $item,
);
}
}
}
}
/**
* This function is where we create the view for the related menu item
* @param type $object_id
@ -222,9 +242,10 @@ function islandora_basic_collection_islandora_view_object($object, $user) {
foreach ($object->models as $model) {
if (isset($cmodel_list[$model][ISLANDORA_VIEW_HOOK]) && $cmodel_list[$model][ISLANDORA_VIEW_HOOK] == TRUE) {
$display = (empty($_GET['display'])) ? 'list' : $_GET['display'];
if($display == 'grid'){
if ($display == 'grid') {
$output = theme('islandora_basic_collection_grid', array('islandora_object' => $object));
} else {
}
else {
$output = theme('islandora_basic_collection', array('islandora_object' => $object));
}
return array('Collection View' => $output);
@ -238,7 +259,7 @@ function islandora_basic_collection_islandora_view_object($object, $user) {
* currently just calls normal view preprocess as variables are the same
* @param type $variables
*/
function islandora_basic_collection_preprocess_islandora_basic_collection_grid(&$variables){
function islandora_basic_collection_preprocess_islandora_basic_collection_grid(&$variables) {
islandora_basic_collection_preprocess_islandora_basic_collection($variables);
}
@ -266,7 +287,7 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari
$results = islandora_basic_collection_get_objects($islandora_object, $page_number, $page_size);
$total_count = count($results);
pager_default_initialize($total_count, $page_size);
$pager = theme('pager', array('quantity' => $total_count));
$variables['pager'] = $pager;
$variables['islandora_dublin_core'] = $dc_object;
@ -288,7 +309,7 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari
$associated_objects_array = array();
$start = $page_size * ($page_number);
$end = min($start + $page_size, $total_count);
for ($i = $start; $i < $end; $i++) {
$pid = $results[$i]['object']['value'];
$fc_object = islandora_basic_collection_get_object($pid);

21
islandora_basic_image/includes/image_process.inc

@ -1,5 +1,26 @@
<?php
function islandora_basic_image_create_all_derivatives($object){
module_load_include('inc', 'islandora', 'includes/MimeClass');
module_load_include('inc', 'islandora_basic_image', 'includes/image_process');
$mime_class = new MimeClass();
if(!isset($object['OBJ'])){
drupal_set_message(t('Could not create image derivatives for %s. No image file was uploaded.',array('%s' => $object->id)),'error');
return "";
}
$ext = $mime_class->getExtension($object['OBJ']->mimeType);
$file_name = str_replace(':', '-', $object->id);
$original_file = file_save_data($object['OBJ']->content, 'temporary://' . $file_name . 'OBJ.' . $ext);
$tn_file = file_copy($original_file, 'temporary://' . $file_name . 'TN.' . $ext);
if (islandora_basic_image_create_derivative($tn_file, 200, 200)) {
islandora_basic_image_add_datastream($object, 'TN', $tn_file);
}
$medium_file = file_copy($original_file, 'temporary://' . $file_name . 'MEDIUM.' . $ext);
if (islandora_basic_image_create_derivative($medium_file, 500, 700)) {
islandora_basic_image_add_datastream($object, 'MEDIUM_SIZE', $medium_file);
}
}
/**
*

22
islandora_basic_image/islandora_basic_image.module

@ -193,23 +193,15 @@ function islandora_basic_image_islandora_view_object($object, $user, $page_numbe
return NULL;
}
function islandora_basic_image_islandora_ingest_post_ingest($object) {
module_load_include('inc', 'islandora', 'includes/MimeClass');
module_load_include('inc', 'islandora_basic_image','includes/image_process');
$mime_class = new MimeClass();
$ext = $mime_class->getExtension($object['OBJ']->mimeType);
$file_name = str_replace(':', '-', $object->id);
$original_file = file_save_data($object['OBJ']->content, 'temporary://' . $file_name . 'OBJ.' . $ext);
$tn_file = file_copy($original_file, 'temporary://' . $file_name . 'TN.' . $ext);
if(islandora_basic_image_create_derivative($tn_file, 200, 200)){
islandora_basic_image_add_datastream($object, 'TN', $tn_file);
}
$medium_file = file_copy($original_file, 'temporary://' . $file_name . 'MEDIUM.' . $ext);
if(islandora_basic_image_create_derivative($medium_file, 500, 700)){
islandora_basic_image_add_datastream($object, 'MEDIUM_SIZE', $medium_file);
$cmodel_list = islandora_basic_image_islandora_get_types();
$models = $object->models;
foreach ($object->models as $model) {
if (isset($cmodel_list[$model])) {
module_load_include('inc', 'islandora_basic_image', 'includes/image_process');
islandora_basic_image_create_all_derivatives($object);
}
}
}
/**

Loading…
Cancel
Save