Browse Source

updated preprocess function for basic collection cmodel

pull/111/merge
Paul Pound 13 years ago
parent
commit
490896a7de
  1. 51
      islandora_basic_collection/islandora_basic_collection.module

51
islandora_basic_collection/islandora_basic_collection.module

@ -36,7 +36,7 @@ function islandora_basic_collection_menu() {
'access callback' => 'islandora_basic_collection_access',
'access arguments' => array(2),
);
$items['admin/islandora/basic_collection'] = array(
'title' => 'Islandora Basic Collection',
'description' => 'Configure the basic Collection solution pack.',
@ -46,7 +46,7 @@ function islandora_basic_collection_menu() {
'file' => 'admin/islandora_basic_collection.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
/* an example of adding a tab for view
$items['islandora/object/%/view/collection'] = array(
'title' => 'Collection View',
@ -69,8 +69,6 @@ function islandora_basic_collection_manage_object($object_id) {
return 'Collection CModel edit function ' . $object_id;
}
/**
* determines whether or not to show this modules manage tab
* @global object $user
@ -111,8 +109,8 @@ function islandora_basic_collection_theme($existing, $type, $theme, $path) {
'islandora_basic_collection' => array(
'template' => 'islandora-basic-collection',
'pattern' => 'islandora_basic_collection__', //we can add pids to the end of this pattern in our preprocess function
// and templates will be able to have have a pid appended to the template name to overide a template on a per object basis
//an example template would be named islandora-basic-image--islandora-27.tpl.phps
// and templates will be able to have have a pid appended to the template name to overide a template on a per object basis
//an example template would be named islandora-basic-image--islandora-27.tpl.phps
'variables' => array('islandora_object' => NULL),
)
);
@ -129,7 +127,7 @@ function islandora_basic_collection_theme($existing, $type, $theme, $path) {
function islandora_basic_collection_islandora_get_types() {
$types = array();
$types['islandora:collectionCModel'][ISLANDORA_VIEW_HOOK] = variable_get('islandora_basic_collection_use_for_default_tab', TRUE);
//$types['islandora:collectionCModel'][ISLANDORA_EDIT_HOOK] = FALSE;
//$types['islandora:collectionCModel'][ISLANDORA_EDIT_HOOK] = FALSE;
return $types;
}
@ -146,7 +144,7 @@ function islandora_basic_collection_islandora_get_types() {
* themed html
*/
function islandora_basic_collection_islandora_view_object($object, $user, $page_number, $page_size) {
//global $user;
//global $user;
$cmodel_list = islandora_basic_collection_islandora_get_types();
$models = $object->models;
foreach ($object->models as $model) {
@ -165,9 +163,9 @@ function islandora_basic_collection_islandora_view_object($object, $user, $page_
* an array of variables that will be passed to the theme function
*/
function islandora_basic_collection_preprocess_islandora_basic_collection(&$variables) {
// base url
// base url
global $base_url;
// base path
// base path
global $base_path;
$islandora_object = $variables['islandora_object'];
module_load_include('inc', 'islandora', 'includes/islandora_dublin_core');
@ -195,21 +193,50 @@ function islandora_basic_collection_preprocess_islandora_basic_collection(&$vari
}
$associated_objects_array = array();
foreach($variables['islandora_associated_objects'] as $key => $value) {
foreach ($variables['islandora_associated_objects'] as $key => $value) {
$pid = $variables['islandora_associated_objects'][$key]['object']['value'];
$fc_object = islandora_basic_collection_get_object($pid);
if (!isset($fc_object)) {
continue; //null object so don't show in collection view;
}
$associated_objects_array[$pid]['object'] = $fc_object;
try {
$dc = $fc_object['DC']->content;
$dc_object = Dublin_Core::import_from_xml_string($dc);
$associated_objects_array[$pid]['dc_array'] = $dc_object->as_formatted_array();
} catch (Exception $e) {
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error');
}
$object_url = 'islandora/object/' . $pid;
$thumbnail_img = '<img src="' . $base_path . $object_url . '/datastream/TN/view"' . '/>';
$title = $variables['islandora_associated_objects'][$key]['title']['value'];
$associated_objects_array[$pid]['pid'] = $pid;
$associated_objects_array[$pid]['path'] = $object_url;
$associated_objects_array[$pid]['title'] = $title;
$associated_objects_array[$pid]['class'] = strtolower( preg_replace('/[^A-Za-z0-9]/', '-', $pid));
$associated_objects_array[$pid]['class'] = strtolower(preg_replace('/[^A-Za-z0-9]/', '-', $pid));
if(isset($fc_object['TN'])){
$thumbnail_img = '<img src="' . $base_path . $object_url . '/datastream/TN/view"' . '/>';
} else {
$thumbnail_img = '<img src="http://codesprint-centos.islandora.ca/islandora/object/islandora%3A52/datastream/TN"' . '/>';
}
$associated_objects_array[$pid]['thumbnail'] = $thumbnail_img;
$associated_objects_array[$pid]['title_link'] = l($title, $object_url, array('html' => TRUE, 'attributes' => array('title' => $title)));
$associated_objects_array[$pid]['thumb_link'] = l($thumbnail_img, $object_url, array('html' => TRUE, 'attributes' => array('title' => $title)));
}
$variables['associated_objects_array'] = $associated_objects_array;
}
function islandora_basic_collection_get_object($object_id) {
module_load_include('inc', 'islandora', 'RestConnection');
global $user;
try {
$restConnection = new RestConnection($user);
$fedora_object = new FedoraObject($object_id, $restConnection->repository);
} catch (Exception $e) {
//drupal_set_message(t('Error getting Islandora object %s', array('%s' => $object_id)), 'error');
return NULL;
}
return $fedora_object;
}
function islandora_basic_collection_get_objects($object) {

Loading…
Cancel
Save