Browse Source

start of drupal 7 module

pull/105/merge
Paul Pound 13 years ago
commit
02ba0e8085
  1. 144
      admin/islandora.admin.inc
  2. 210
      admin/islandora.solutionpacks.inc
  3. 33
      fedora_repository/fedora-repository-view-object.tpl.php
  4. 30
      fedora_repository/fedora-repository-view-objects.tpl.php
  5. 4
      fedora_repository/fedora_repository.info
  6. 159
      fedora_repository/fedora_repository.module
  7. 11
      islandora.api.php
  8. 5
      islandora.info
  9. 0
      islandora.install
  10. 324
      islandora.module

144
admin/islandora.admin.inc

@ -0,0 +1,144 @@
<?php
/**
* Create admin form
* @return array
*/
function islandora_repository_admin() {
if (!user_access('administer site configuration')) {
drupal_set_message(t('You must be a site administrator to edit the Fedora collections list.'), 'error');
return;
}
$form = array();
$form['islandora_repository_pid'] = array(
'#type' => 'textfield',
'#title' => t('Root Collection PID'),
'#default_value' => variable_get('islandora_repository_pid', 'islandora:root'),
'#description' => t('The PID of the Root Collection Object'),
'#required' => TRUE,
'#weight' => -18
);
$form['islandora_base_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora base URL'),
'#default_value' => variable_get('islandora_base_url', 'http://localhost:8080/fedora'),
'#description' => t('The URL to use for REST-type connections'),
'#required' => TRUE,
'#weight' => -16,
);
$form['islandora_repository_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora RISearch URL'),
'#default_value' => variable_get('islandora_repository_url', 'http://localhost:8080/fedora/risearch'),
'#description' => t('The url of the Fedora server'), '#required' => TRUE,
'#weight' => -14
);
$form['islandora_soap_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora SOAP Url'),
'#default_value' => variable_get('islandora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'),
'#description' => t('The URL to use for SOAP connections'),
'#required' => TRUE,
'#weight' => -12,
);
$form['islandora_soap_manage_url'] = array(
'#type' => 'textfield',
'#title' => t('Fedora SOAP management URL'),
'#default_value' => variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/wsdl?api=API-M'), '#description' => t('The URL to use for SOAP API-M connections'),
'#required' => TRUE,
'#weight' => -10
);
// will allow admin user to remove namepsace restrictions if not explicitly disallowed in settings.php
if (variable_get('allow_open_namespace', TRUE)) {
$form['islandora_namespace'] = array(
'#type' => 'fieldset',
);
$form['islandora_namespace']['islandora_namespace_restriction_enforced'] = array(
'#weight' => -1,
'#type' => 'radios',
'#title' => t('Enforce namespace restrictions'),
'#options' => array(
TRUE => t('Enabled'),
FALSE => t('Disabled')
),
'#description' => t('Allow administrator to restrict user\'s access to the PID namepaces listed below'),
'#default_value' => variable_get('islandora_namespace_restriction_enforced', TRUE)
);
$form['islandora_namespace']['fedora_pids_allowed'] = array(
'#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '),
'#description' => t('A space separated list of PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos.'),
'#weight' => 0
);
}
else {
$form['islandora_pids_allowed'] = array(
'#type' => 'textfield',
'#title' => t('PID namespaces allowed in this Drupal install'),
'#default_value' => variable_get('islandora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '),
'#description' => t('A space separated list of PID namespaces that users are permitted to access from this Drupal installation. <br /> This could be more than a simple namespace ie demo:mydemos.'),
'#weight' => 0
);
}
//have tabs options (like disable)
$form['tabs'] = array(
'#type' => 'fieldset',
'#title' => t('Tabs Configuration'),
'#description' => t('Configure the tabs avaialble when viewing Fedora objects.'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
//when checked show object details tab
$form['tabs']['islandora_repository_show_object_details_tab'] = array(
'#type' => 'checkbox',
'#title' => t('Show Object Details Tab'),
'#default_value' => variable_get('islandora_repository_show_object_details_tab', TRUE),
'#description' => t("When enabled, the 'Object Details' tab will be visible to users with the correct permissions when viewing an object in the repository"),
);
$form['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Advanced configuration options'),
'#description' => t('Advanced configuration. Under normal circumstances these will not be touched'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$form['advanced']['islandora_object_restrict_datastreams'] = array(
'#type' => 'checkbox',
'#title' => t('Restrict Access to Fedora Object Datastreams'),
'#default_value' => variable_get('islandora_object_restrict_datastreams', FALSE),
'#description' => t('When enabled, restricts access to fedora object datastreams that are not listed in the Islandora Content Model for the object (unless the user is an administrator).'),
);
//Export functionality
$form['advanced']['module']['islandora_export_area'] = array(
'#type' => 'textfield',
'#title' => t('Export area'),
'#default_value' => variable_get('islandora_export_area', file_directory_path() . '/fedora_export_area'),
'#description' => t("Path to the export area. It must be accessible by druapl (i.e. apache user)."),
'#required' => TRUE,
);
$form['#attributes'] = array('enctype' => "multipart/form-data");
return system_settings_form($form);
}
?>

210
admin/islandora.solutionpacks.inc

@ -0,0 +1,210 @@
<?php
/**
* @file
* Invokes a hook to any dependent modules asking them if their installations require
* any fedora objects to be present. Modules implementing this hook should return an array
* of arrays of the form:
*
* array( 'pid', 'path-to-foxml-file', 'dsid', 'path-to-datastream-file', int dsversion)
*
* where the last three options are optional. A module can either point to a simple
* foxml file to install, or can specify a datastreamstream to check for, with a
* path to load the datastream from if it isn't there. Optionally a version number
* can be included, to enable updating of content model or collection policy streams
* that may have been updated. THis is a simple whole number that should be incremented
* when changed. This value appears in as an attribute of the topmost element of the stream,
* e.g.,:
*
* <?xml version="1.0" encoding="utf-8"?> <content_model name="Collection" version="2" ...
*
* Datastreams which don't have this element are assumed to be at version 0.
*/
function fedora_repository_solution_packs_page() {
$enabled_solution_packs = module_invoke_all('required_fedora_objects');
$output = '';
foreach ($enabled_solution_packs as $solution_pack_module => $solution_pack_info) {
$objects = array();
foreach ($solution_pack_info as $field => $value) {
switch ($field) {
case 'title':
$solution_pack_name = $value;
break;
case 'objects':
$objects = $value;
break;
}
}
$output .= drupal_get_form('fedora_repository_solution_pack_form_' . $solution_pack_module, $solution_pack_module, $solution_pack_name, $objects);
}
return $output;
}
/**
* Check for installed objects and add a 'Update' or 'Install' button if some objects are missing.
* @param array $solution_pack
*/
function fedora_repository_solution_pack_form(&$form_state, $solution_pack_module, $solution_pack_name, $objects = array()) {
// Check each object to see if it is in the repository.
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
global $base_path;
$needs_update = FALSE;
$needs_install = FALSE;
$form = array();
$form['solution_pack_module'] = array(
'#type' => 'hidden',
'#value' => $solution_pack_module,
);
if (!$form_state['submitted']) {
$form['solution_pack_name'] = array(
'#type' => 'markup',
'#value' => t($solution_pack_name),
'#prefix' => '<h3>',
'#suffix' => '</h3>',
);
$form['objects'] = array(
'#type' => 'fieldset',
'#title' => "Objects",
'#weight' => 10,
'#attributes' => array('class' => 'collapsed'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$table_header = array('PID', 'Status');
$table_rows = array();
foreach ($objects as $object) {
$datastreams = NULL;
if (isset($object['pid'])) {
$pid = $object['pid'];
$item = new Fedora_Item($pid);
$table_row = array($object['pid']);
$object_status = t('Up-to-date');
if (!$item->exists()) {
$object_status = 'Missing';
$needs_install = TRUE;
}
else {
if (isset($object['dsid']) && isset($object['datastream_file']) && isset($object['dsversion'])) {
$datastreams = array(
array(
'dsid' => $object['dsid'],
'datastream_file' => $object['datastream_file'],
'dsversion' => $object['dsversion'],
),
);
}
elseif (!empty($object['datastreams'])) {
$datastreams = $object['datastreams'];
}
if (!empty($datastreams) && is_array($datastreams)) {
foreach ($datastreams as $ds) {
$ds_list = $item->get_datastreams_list_as_array();
if (!array_key_exists($ds['dsid'], $ds_list)) {
$needs_update = TRUE;
$object_status = 'Missing datastream';
break;
}
elseif (isset($ds['dsversion'])) {
// Check if the datastream is versioned and needs updating.
$installed_version = fedora_repository_get_islandora_datastream_version($item, $ds['dsid']);
$available_version = fedora_repository_get_islandora_datastream_version(NULL, NULL, $ds['datastream_file']);
if ($available_version > $installed_version) {
$needs_update = TRUE;
$object_status = 'Out of date';
break;
}
}
}
}
}
array_push($table_row, $object_status);
$table_rows[] = $table_row;
}
}
$form['objects']['table'] = array(
'#type' => 'markup',
'#value' => theme_table($table_header, $table_rows),
);
}
$form['install_status'] = array(
'#type' => 'markup',
'#prefix' => '<strong>' . t('Object status:') . '&nbsp;</strong>',
'#suffix' => '&nbsp;',
);
if (!$needs_install && !$needs_update) {
$form['install_status']['#value'] = theme_image('misc/watchdog-ok.png') . t('All required objects are installed and up-to-date.');
$submit_button_text = t("Force Reinstallation of Fedora Objects");
}
else {
$form['install_status']['#value'] = theme_image('misc/watchdog-warning.png') . t('Some objects must be re-ingested. See Objects list for details.');
$submit_button_text = t("Install Fedora Objects");
}
$form['submit'] = array(
'#value' => $submit_button_text,
'#type' => 'submit',
'#name' => $solution_pack_module,
);
$form['#submit'] = array(
'fedora_repository_solution_pack_form_submit',
);
return $form;
}
function fedora_repository_solution_pack_form_submit($form, &$form_state) {
$what = $form_state;
$module_name = $form_state['values']['solution_pack_module'];
// This should be replaced with module_invoke
//$solution_pack_info = call_user_func($module_name . '_required_fedora_objects');
$solution_pack_info = module_invoke($module_name, 'required_fedora_objects');
$batch = array(
'title' => t('Installing / updating solution pack objects'),
'file' => drupal_get_path('module', 'fedora_repository') . '/fedora_repository.module',
'operations' => array(),
);
foreach ($solution_pack_info[$module_name]['objects'] as $object) {
// Add this object to the batch job queue.
$batch['operations'][] = array('fedora_repository_batch_reingest_object', array($object));
}
batch_set($batch);
}
function solution_pack_add_form($form_name, $form_xml) {
$result = db_result(db_query('Select name from {xml_forms} where name = "%s"', $form_name));
if (!$result) {
$object = new stdClass();
$object->name = $form_name;
$object->form = $form_xml;
$result = drupal_write_record('xml_forms', $object);
drupal_set_message(t("Added @name", array("@name" => $form_name)));
}
}
function solution_pack_add_form_association($content_model, $form_name) {
$result = db_result(db_query('Select content_model from {islandora_content_model_forms} where content_model = "%s" and form_name = "%s"',
$content_model, $form_name));
if (!$result) {
$object = new stdClass();
$object->content_model = $content_model;
$object->form_name = $form_name;
$object->dsid = 'MODS';
$object->title_field = "['titleInfo']['title']";
$object->transform = 'mods_to_dc.xsl';
$result = drupal_write_record('islandora_content_model_forms', $object);
drupal_set_message(t("Added association between @cm and @name", array("@cm" => $content_model, "@name"=>$form_name)));
}
}

33
fedora_repository/fedora-repository-view-object.tpl.php

@ -0,0 +1,33 @@
<?php
/*
* fedora-repository-view-object.tpl.php
*
* Copyright (c) 2012 Paul Pound.
*
* This file is part of CMR.
*
* 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/>.
*/
/**
*
* @author paul
*/
?>
<?php print $variables['count'];
foreach($variables['results'] as $object){
print_r ($object);
}?>

30
fedora_repository/fedora-repository-view-objects.tpl.php

@ -0,0 +1,30 @@
<?php
/*
* fedora-repository-object.tpl.php
*
* Copyright (c) 2012 Paul Pound.
*
* This file is part of CMR.
*
* 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/>.
*/
?>
<?php
foreach($variables['results'] as $object){
print_r($object->label);
}?>

4
fedora_repository/fedora_repository.info

@ -0,0 +1,4 @@
name = "Fedora Repository"
description = "A default Fedora Repository module"
dependencies[] = islandora
core = 7.x

159
fedora_repository/fedora_repository.module

@ -0,0 +1,159 @@
<?php
/*
* @file fedora_repository.module
*
* Copyright (c) 2012 Paul Pound.
*
* This file is part of CMR.
*
* 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.
* @param array $metadata
* @param array $render_array
* @return array
*/
function fedora_repository_show_metadata($metadata, &$render_array) {
$header = array(t('Label'), t('Value'));
$table_attributes = array('class' => array('cmr_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
* @param array $variables
* @return string
*/
function theme_fedora_repository_view_object($variables) {
$object = $variables['object'];
$metadata = $object->metadata;
$render_array = array('title' => array(
'#type' => 'markup',
'#markup' => '<h2>' . $object->label . '</h2>',
));
fedora_repository_show_metadata($metadata, $render_array);
fedora_repository_list_datastreams($object, $render_array);
return drupal_render($render_array);
}
/**
*
* @global object $user
* @param ActiveMongo $object
* @param string $render_array
* @return type
*/
function fedora_repository_list_datastreams($object, &$render_array) {
module_load_include('inc', 'CmrAPIDrupal', 'cmr');
global $user;
$api = new CmrAPIDrupal($user);
$datastreams = $object->datastreams;
if (!isset($datastreams)) {
return $render_array;
}
foreach ($datastreams as $datastream) {
foreach ($datastream as $key => $value) {
if ($key == 'cmr:data') {
$d = new CmrDatastream();
$d->find($value);
if (isset($d)) {
// $id = $d->getID()->id;
$render_array[(string)$d->getID()] = array('type' => 'markup', '#markup' => '<div class = "cmr-external-link">'.l($d->label, $d->path,array('html'=>TRUE)).'</div>');
}
}
if($key = 'cmr:metaData'){
$d = new CmrDatastream();
$d->find($value);
if(isset($d)){
//@TODO: do something here
}
}
}
}
}
/**
* Theme registry function
* @return array
*/
function fedora_repository_theme() {
return array(
'fedora_repository_view_objects' => array(
'template' => 'fedora-repository-view-objects',
'variables' => array('objects' => NULL),
),
'fedora_repository_view_object' => array(
'varibles' => array('object'),
)
);
}
/**
* tells the main module what types of objects we support.
* @return array
*/
function fedora_repository_get_types() {
return array('islandora:pdfCModel');
}
/**
* this modules implentation of view_object will handle objects of type islandora:pdfCmodel as registered in its return types
* Other modules would handle objects
* of other types.
* @param FedoraObject $object
* @param object $user
* @param string $page_number
* @param string $page_size
* @return string
* themed html
*/
function fedora_repository_view_object($object, $user, $page_number, $page_size) {
//global $user;
if ($object->type != 'islandora:pdfCModel' && $object->type != 'cmr:basicObject') {
return NULL;
}
$output = theme('fedora_repository_view_object', array('object' => $object));
$api = new CmrAPIDrupal($user);
try {
$results = $api->listObjectsByRelationship($object, 'cmr:isPartOf', $user, array('offset' => $page_number, 'limit' => $page_size));
} catch (CmrRelationshipException $e) {
drupal_set_message(t('error executing list objects query, %s', array('%s' => $e)));
}
pager_default_initialize($results['count'], $page_size);
$pager = theme('pager', array('quantity' => $results['count']));
$output .= $pager;
if ($results['count'] > 0) {
$output .= theme('fedora_repository_view_objects', $results);
}
$output .= $pager;
return $output;
}
?>

11
islandora.api.php

@ -0,0 +1,11 @@
<?php
function hook_islandora_purge_datastream ($object_id, $datastream_id){}
function hook_islandora_purge_object($object_id) {}
function hook_islandora_view_object($object_id){}
function hook_islandora_get_types(){}
function hook_islandora_add_datastream($object_id) {}

5
islandora.info

@ -0,0 +1,5 @@
name = Islandora Repository
description = "View and manage Fedora objects"
package = Islandora
version = 7.x-dev
core = 7.x

0
islandora.install

324
islandora.module

@ -0,0 +1,324 @@
<?php
/*
* @file islandora.module
* defines paths (drupal menu items) as entry points and acts as a hub for dispatching tasks to other modules.
*
*
* 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/>.
*/
/**
*
* @author paul
*/
define('FEDORA_VIEW', 'view fedora repository');
define('FEDORA_METADATA_EDIT', 'edit fedora metadata');
define('FEDORA_ADD_DS', 'add fedora datastreams');
define('FEDORA_INGEST', 'ingest fedora objects');
define('FEDORA_PURGE', 'purge fedora objects and datastreams');
define('FEDORA_MODIFY_STATE', 'modify fedora state');
/**
* Implementation of hook_menu.
* we need some standard entry points so we can have consistent urls for different Object actions
*/
function islandora_menu() {
$items = array();
$items['admin/settings/islandora'] = array(
'title' => t('Islandora Configuration'),
'description' => t("Configure Islandora's interaction with Fedora"),
'page callback' => 'drupal_get_form',
'page arguments' => array('islandora_repository_admin'),
'file' => 'admin/islandora.admin.inc',
'access arguments' => array('administer site configuration'),
'type' => MENU_NORMAL_ITEM,
);
$items['admin/settings/islandora/collection'] = array(
'title' => t('Islandora Configuration'),
'description' => t('Enter the Islandora collection information here.'),
'access arguments' => array('administer site configuration'),
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => 0,
);
$items['admin/settings/islandora/demoobjects'] = array(
'title' => t('Solution Packs'),
'description' => t('Install content models and collections required by installed solution packs.'),
'page callback' => 'islandora_solution_packs_page',
'access arguments' => array(FEDORA_ADD_DS),
'file' => 'admin/islandora.solutionpacks.inc',
'type' => MENU_LOCAL_TASK,
);
$items['islandoracm.xsd'] = array(
'title' => t('Islandora Content Model XML Schema Definition'),
'page callback' => 'islandora_display_schema',
'page arguments' => array('islandoracm.xsd'),
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_VIEW),
);
$items['collection_policy.xsd'] = array(
'title' => t('Islandora Content Model XML Schema Definition'),
'page callback' => 'islandora_display_schema',
'page arguments' => array('collection_policy.xsd'),
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_VIEW),
);
$items['islandora/object/%'] = array(
'title' => 'Repository',
'page callback' => 'islandora_view_object',
'page arguments' => array(2),
'type' => MENU_NORMAL_ITEM,
'access arguments' => array(FEDORA_VIEW),
);
/*$items['fedora/repository/service'] = array(
'page callback' => 'repository_service',
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_VIEW),
);*/
$items['islandora/object/%/datastream/%/download'] = array(
'title' => t('Download object'),
'page callback' => 'islandora_object_as_attachment',
'page arguments' => array(2, 4),
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_VIEW)
);
/* $items['fedora/repository/editmetadata'] = array(
'title' => t('Edit metadata'),
'page callback' => 'fedora_repository_edit_qdc_page',
'type' => MENU_CALLBACK,
'access arguments' => array('edit fedora meta data')
); */
$items['islandora/object/%/datastream/%/purge'] = array(
'title' => t('Purge data stream'),
'page callback' => 'islandora_purge_stream',
'page arguments' => array(2, 4),
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_PURGE)
);
/* $items['fedora/repository/replaceStream'] = array(
'title' => t('Replace Stream'),
'page callback' => 'fedora_repository_replace_stream',
'type' => MENU_CALLBACK,
'access arguments' => array('add fedora datastreams'),
); */
$items['islandora/object/%/purge'] = array(
'title' => t('Purge object'),
'page callback' => 'islandora_purge_object',
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_PURGE)
);
$items['islandora/object/%/datastream/%/add'] = array(
'title' => t('Add stream'),
'page callback' => 'islandora_add_stream',
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_ADD_DS)
);
/* $items['fedora/repository/collection'] = array(
'title' => t('Collection view'),
'page callback' => 'fedora_collection_view',
'type' => MENU_CALLBACK,
'access argruments' => array('view fedora collection'),
); */
//new for mnpl******************************************
$items['islandora/object/ingest'] = array(
'title' => t('Ingest object'),
'page callback' => 'islandora_ingest_object',
'type' => MENU_CALLBACK,
'access arguments' => array(FEDORA_INGEST)
);
return $items;
}
/**
* determines whether we can see the object or not
* checks PID namespace permissions, and user permissions
* @global object $user
* @param string $op
* @param string $pid
*
* @return boolean
*/
function islandora_node_access($op, $pid = NULL, $as_user = NULL) {
//$returnValue = FALSE;
if ($pid == NULL) {
$pid = variable_get('fedora_repository_pid', 'islandora:root');
}
$isRestricted = variable_get('fedora_namespace_restriction_enforced', TRUE);
$namespace_access = NULL;
if (!$isRestricted) {
$namespace_access = TRUE;
}
else {
$pid_namespace = substr($pid, 0, strpos($pid, ':') + 1); //Get the namespace (with colon)
$allowed_namespaces = explode(" ", variable_get('fedora_pids_allowed', 'default: demo: changeme: islandora: ilives: islandora-book: books: newspapers: '));
$namespace_access = in_array($pid_namespace, $allowed_namespaces);
}
return ($namespace_access && user_access($op, $as_user));
}
/**
*
* @param type $object_id
* @return type
*/
function islandora_purge_object($object_id) {
if (!isset($object_id)) {
drupal_set_message('Cannot remove object, object id not set');
return;
}
$object = new Object($object_id);
if (!isset($object)) {
drupal_set_message('Could not remove object, object not found');
return;
}
module_invoke_all('islandora_purge_object', $object); //notify modules of pending deletion
$object->delete();
}
/**
* returns an array listing object types provided by sub modules
* @return array
*/
function islandora_get_types() {
return module_invoke_all('islandora_get_types');
}
/**
* DO WE EVEN WANT TO DEFINE THIS HERE OR SHOULD EACH MODULE HANDLE IT EVEN AT THE MENU/PATH LEVEL?
* @paramstring $datastream_id
* @return type
*/
function islandora_purge_datastream($object_id, $datastream_id) {
if (!isset($datastream_id)) {
drupal_set_message('Cannot remove datastream, datastream id not set');
return;
}
$object = new Object($object_id);
if (!isset($object)) {
drupal_set_message('Could not remove object, object not found');
return;
}
module_invoke_all('islandora_purge_datastream', $datastream); //notify modules of pending deletion so we can update rels etc
$object->deleteDatastream();
}
/**
*
* @global object $user
* @param string $object_id
*
* @return string
*/
function islandora_view_object($object_id) {
return $object_id;
if (!isset($object_id)) {
drupal_set_message('Cannot view object, object id not set');
return;
}
$page_number = (empty($_GET['page'])) ? '1' : $_GET['page'];
$object = new IslandoraObject($object_id);
if (!isset($object)) {
drupal_set_message(t('Cannot view object, object not found'), 'error');
return"";
}
global $user;
drupal_alter('islandora_view_object', $object); //modify object if required before it is passed along
$arr = module_invoke_all('islandora_view_object', $object, $user, $page_number, $page_size); //allow submodules to decide how to handle content base on object type
if ($arr[0] == NULL) {
drupal_set_message(t('No module registered to handle objects of type %s', array('%s' => $object->type)));
return "";
}
return $arr[0]; //just an example as we could have more then one array element
}
/**
* drupal hook_permissions function
* @return array
*/
function islandora_permission() {
return array(
FEDORA_VIEW => array(
'title' => t('View Fedora Repository objects and datastreams'),
'description' => t('Users with this permission will be allowed to view Fedora objects and datastreams. Unless Fedora XACML security policies limits this functionality to certain objects.')
),
FEDORA_ADD_DS => array(
'title' => t('Add Fedora streams to Fedora objects'),
'description' => t('Users with this permission will be allowed to add datastreams to Fedora objects. Unless Fedora XACML security policies limits this functionality to certain objects.')
),
FEDORA_METADATA_EDIT => array(
'title' => t('Edit Fedora Metadata'),
'description' => t('Users with this permission will be allowed to edit Fedora Metadata streams')
),
FEDORA_INGEST => array(
'title' => t('Create new Fedora objects'),
'description' => t('Users with this permission will be allowed to create new objects in the Fedora repository')
),
FEDORA_PURGE => array(
'title' => t('Permanently remove objects from the Fedora repository'),
'description' => t('Users with this permission will be allowed to Permantly remove objects from the Fedora repository.')
),
FEDORA_MODIFY_STATE => array(
'title' => t('Change a Fedora objects state'),
'description' => t('Users with this permission will be allowed to change a Fedora objects state.')
),
);
}
/**
* DO WE EVEN WANT TO DEFINE THIS HERE OR SHOULD EACH MODULE HANDLE IT EVEN AT THE MENU/PATH LEVEL?
* @param string $object_id
* @return type
*/
function islandora_add_datastream($object_id) {
if (!isset($object_id)) {
drupal_set_message('Cannot add datastream to object, object id not set');
return;
}
//send message to synapse
$object = new IslandoraObject($object_id);
if (!isset($object)) {
drupal_set_message('Could not remove object, object not found');
return;
}
module_invoke_all('islandora_add_datastream', $object); //allow submodules to handle add datastream based on object type
}
?>
Loading…
Cancel
Save