|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @file islandora_basic_image.module
|
|
|
|
*
|
|
|
|
* an Islandora module to handle basic image cmodels (with ISLANDORACM streams)
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This file is part of Islandora.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with the program. If not, see <http ://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* called by theme function and populates a render array for a table view.
|
|
|
|
* See theme registry. This is also an example function.
|
|
|
|
* @param array $metadata
|
|
|
|
* @param array $render_array
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function islandora_basic_image_render_object($metadata, &$render_array) {
|
|
|
|
$header = array(t('Label'), t('Value'));
|
|
|
|
$table_attributes = array('class' => array('islandora_metadata'));
|
|
|
|
$rows = array();
|
|
|
|
foreach ($metadata as $key => $value) {
|
|
|
|
if (isset($value) && is_array($value)) {
|
|
|
|
$item_list = array('#items' => $value, '#theme' => 'item_list');
|
|
|
|
$rows[] = array($key, array('data' => $item_list));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$rows[] = array($key, $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$render_array['metadata'] = array('#header' => $header, '#theme' => 'table', '#rows' => $rows, '#attributes' => $table_attributes);
|
|
|
|
|
|
|
|
return $render_array;
|
|
|
|
|
|
|
|
} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* returns a drupal render array as a html string
|
|
|
|
* This is an example function. We probably want to use a template
|
|
|
|
* @param array $variables
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
function theme_islandora_basic_image_view_object($variables) {
|
|
|
|
$object = $variables['object'];
|
|
|
|
//$metadata = $object->metadata;
|
|
|
|
$render_array = array('title' => array(
|
|
|
|
'#type' => 'markup',
|
|
|
|
'#markup' => '<h2>' . $object->label . '</h2>',
|
|
|
|
));
|
|
|
|
|
|
|
|
islandora_basic_image_render_object($object, $render_array);
|
|
|
|
|
|
|
|
return drupal_render($render_array);
|
|
|
|
} */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Theme registry function
|
|
|
|
* We supply a pattern so we can overide templates at the theme level if needed.
|
|
|
|
* we can append a pid to a template and the new template file will be called (the pids
|
|
|
|
* colon should be replaced with a dash)
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_theme($existing, $type, $theme, $path) {
|
|
|
|
return array(
|
|
|
|
'islandora_basic_image_objects' => array(
|
|
|
|
'template' => 'islandora-basic-image-view-objects',
|
|
|
|
'variables' => array('islandor_objects' => NULL),
|
|
|
|
),
|
|
|
|
'islandora_basic_image' => array(
|
|
|
|
'template' => 'islandora-basic-image',
|
|
|
|
'pattern' => 'islandora_basic_image__', //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
|
|
|
|
'variables' => array('islandora_object' => NULL),
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tells the main module what types of objects we support. This is used to determine whether or not
|
|
|
|
* this module should attempt to respond.
|
|
|
|
* @return array
|
|
|
|
* array of content model pids that this module supports
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_islandora_get_types() {
|
|
|
|
return array('info:fedora/islandora:imgageCModel', 'info:fedora/islandora:sp_basic_image');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* this modules implentation of view_object will handle objects of type islandora:basicImageCModel and info:fedora/islandora:sp_basic_image
|
|
|
|
* as registered in its return types
|
|
|
|
* Other modules would handle objects of other types.
|
|
|
|
* @param Object $object
|
|
|
|
* a tuque fedora object
|
|
|
|
* @param object $user
|
|
|
|
* @param string $page_number
|
|
|
|
* @param string $page_size
|
|
|
|
* @return string
|
|
|
|
* themed html
|
|
|
|
*/
|
|
|
|
function islandora_basic_image_islandora_view_object($object, $user, $page_number, $page_size) {
|
|
|
|
//global $user;
|
|
|
|
$cmodel_list = islandora_basic_image_islandora_get_types();
|
|
|
|
$combined_list = array_intersect($cmodel_list, $object->models);
|
|
|
|
if (empty($combined_list)) {
|
|
|
|
return NULL; //we don't handle any of this objects cmodels
|
|
|
|
}
|
|
|
|
$output = theme('islandora_basic_image', array('islandora_object' => $object));
|
|
|
|
|
|
|
|
return array('Basic Image Output' => $output);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @global type $base_url
|
|
|
|
* @param array $variables
|
|
|
|
* an array of variables that will be passed to the theme function
|
|
|
|
*/
|
|
|
|
function islandora_preprocess_islandora_basic_image(&$variables) {
|
|
|
|
$islandora_object = $variables['islandora_object'];
|
|
|
|
module_load_include('inc', 'islandora', 'utils/islandora_dublin_core');
|
|
|
|
try {
|
|
|
|
$dc = $islandora_object['DC']->content;
|
|
|
|
$dc_object = Dublin_Core::import_from_xml_string($dc);
|
|
|
|
} catch (Exception $e) {
|
|
|
|
drupal_set_message(t('Error retrieving object %s %t', array('%s' => $islandora_object->id, '%t' => $e->getMessage())), 'error');
|
|
|
|
}
|
|
|
|
$variables['islandora_dublin_core'] = $dc_object;
|
|
|
|
$variables['islandora_object_label'] = $islandora_object->label;
|
|
|
|
$variables['theme_hook_suggestions'][] = 'islandora_basic_image__' . str_replace(':', '_', $islandora_object->id);
|
|
|
|
global $base_url;
|
|
|
|
$variables['islandora_image_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/OBJ/view';
|
|
|
|
$variables['islandora_thumbnail_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/TN/view';
|
|
|
|
$variables['islandora_medium_size_url'] = $base_url . '/islandora/object/' . $islandora_object->id . '/datastream/MEDIUM/view';
|
|
|
|
}
|
|
|
|
|