Browse Source

Added hooks for processing XMLBased form's during ingestion

pull/3/merge
Nigel Banks 13 years ago
parent
commit
3c4de73302
  1. 122
      fedora_repository.module
  2. 5
      formClass.inc

122
fedora_repository.module

@ -22,8 +22,6 @@ function fedora_repository_admin() {
return $adminForm->createAdminForm();
}
/**
* drupal hook
* calls the fedora_repositorys_admin form
@ -55,8 +53,7 @@ function fedora_repository_purge_object($pid = NULL, $name = NULL) {
drupal_set_message(t('You must specify an object pid to purge an object.'), 'error');
return '';
}
$output = t('Are you sure you wish to purge object %name %pid!<br /><b>This cannot be undone</b><br />',
array(
$output = t('Are you sure you wish to purge object %name %pid!<br /><b>This cannot be undone</b><br />', array(
'%name' => $name,
'%pid' => $pid)
);
@ -122,6 +119,15 @@ function fedora_repository_ingest_object($collection_pid=NULL, $collection_label
function fedora_repository_ingest_form_submit($form, &$form_state) {
//only validate the form if the submit button was pressed (other buttons may be used for AHAH
if (module_exists('xml_form_api')) {
module_load_include('inc', 'xml_form_api', 'XMLForm');
$form = new XMLForm($form_state);
$doc = $form->submit($drupal_form, $form_state);
$document = $doc->document;
dom_document_pretty_print($document);
exit();
}
else {
if ($form_state['clicked_button']['#id'] == 'edit-submit') {
global $base_url;
module_load_include('inc', 'fedora_repository', 'CollectionClass');
@ -160,6 +166,7 @@ function fedora_repository_ingest_form_submit($form, &$form_state) {
$form_state['redirect'] = ($err) ? ' ' : $base_url . "/fedora/repository/{$form_state['values']['collection_pid']}";
}
}
}
}
function fedora_repository_ingest_form_validate($form, &$form_state) {
@ -172,7 +179,12 @@ function fedora_repository_ingest_form_validate($form, &$form_state) {
break;
case 2:
// XML based form.
if (module_exists('xml_form_api')) {
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
$xml_form->validate($form, $form_state);
}
// Get the uploaded file.
$validators = array();
@ -394,8 +406,7 @@ function fedora_repository_purge_stream($pid = NULL, $dsId = NULL, $name = NULL)
return ' ';
}
$output = t('Are you sure you wish to purge this datastream %name<br />',
array(
$output = t('Are you sure you wish to purge this datastream %name<br />', array(
'%name' => $name)
);
$output .= drupal_get_form('fedora_repository_purge_stream_form', $pid, $dsId);
@ -527,8 +538,8 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) {
$dsid = $form_state['values']['dsId'];
$dsLabel = $form_state['values']['dsLabel'];
// Remove the original file extension from the label and add the new one
$indexOfDot = strrpos($dsLabel,'.');//use strrpos to get the last dot
if($indexOfDot !== FALSE){
$indexOfDot = strrpos($dsLabel, '.'); //use strrpos to get the last dot
if ($indexOfDot !== FALSE) {
$dsLabel = substr($dsLabel, 0, $indexOfDot);
$dsLabel .= substr($file->filename, strrpos($file->filename, '.')); // Add the file extention to the end of the label.;
}
@ -550,7 +561,6 @@ function fedora_repository_replace_stream_form_submit($form, &$form_state) {
$item->modify_datastream_by_reference($streamUrl, $dsid, $dsLabel, $dformat);
$form_state['redirect'] = 'fedora/repository/' . $pid;
}
function fedora_repository_edit_qdc_page($pid = NULL, $dsId = NULL) {
@ -727,7 +737,7 @@ function fedora_repository_get_items($pid = NULL, $dsId = NULL, $collection = NU
return '';
}
if ($pid &!validPid($pid)) {
if ($pid & !validPid($pid)) {
drupal_set_message(t("Invalid PID!"), 'error');
return ' ';
@ -1180,7 +1190,6 @@ function fedora_repository_theme() {
'arguments' => array(
'element' => NULL
),
'fedora_repository_solution_packs_list' => array(
'arguments' => array(
'solution_packs' => NULL,
@ -1263,7 +1272,7 @@ function fedora_repository_demo_objects_form() {
);
foreach (array(
'islandora:collectionCModel' => 'Islandora default content models',
'islandora:collectionCModel' => 'Islandora default content models',
'islandora:top' => 'Islandora top-level collection',
'islandora:demos' => 'Islandora demos collection',
'islandora:largeimages' => 'Sample large image content model (requires <a href="http://sourceforge.net/projects/djatoka/">Djatoka</a> and <a href="http://www.kakadusoftware.com/index.php?option=com_content&task=view&id=26&Itemid=22">Kakadu</a>.)',
@ -1454,16 +1463,15 @@ function fedora_repository_demo_objects_form_submit($form, &$form_state) {
}
}
function fedora_repository_required_fedora_objects() {
// array( 'path-to-foxml-file', 'pid', 'dsid', 'path-to-datastream-file', int dsversion, boolean required)
$module_path = drupal_get_path('module', 'fedora_repository');
return array (
return array(
'fedora_repository' => array(
'module' => 'fedora_repository',
'title' => 'Islandora Core',
'objects' => array (
array (
'objects' => array(
array(
'pid' => 'islandora:collectionCModel',
'label' => 'Islandora Collection Content Model',
'dsid' => 'ISLANDORACM',
@ -1471,7 +1479,7 @@ function fedora_repository_required_fedora_objects() {
'dsversion' => 2,
'cmodel' => 'fedora-system:ContentModel-3.0',
),
array (
array(
'pid' => 'islandora:strict_pdf',
'label' => 'Islandora strict PDF content model',
'dsid' => 'ISLANDORACM',
@ -1482,85 +1490,85 @@ function fedora_repository_required_fedora_objects() {
'pid' => 'islandora:top',
'label' => 'Islandora Top-level Collection',
'cmodel' => 'islandora:collectionCModel',
'datastreams' => array (
array (
'datastreams' => array(
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml",
),
array (
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Gnome-emblem-photos.png",
'mimetype' => 'image/png',
),
),
),
array (
array(
'pid' => 'islandora:ContentModelCollection',
'label' => 'Collection of installed content models',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:top',
'datastreams' => array (
array (
'datastreams' => array(
array(
'dsid' => 'COLLECTION_VIEW',
'datastream_file' => "$module_path/collection_views/simple_list_view.xml",
),
array (
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/contentModel.jpg",
'mimetype' => 'image/jpeg',
),
array (
array(
'dsid' => 'QUERY',
'datastream_file' => "$module_path/collection_views/cmodel_collection_query.txt",
'mimetype' => 'text/plain',
),
),
),
array (
array(
'pid' => 'islandora:demos',
'label' => 'Islandora demos collection',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:top',
'datastreams' => array (
array (
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Gnome-emblem-photos.png",
'mimetype' => 'image/png',
),
array (
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/collection_policies/COLLECTION-COLLECTION POLICY.xml",
),
),
),
array (
array(
'pid' => 'islandora:pdf_collection',
'label' => 'Islandora Demo PDF Collection',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:demos',
'datastreams' => array (
array (
'datastreams' => array(
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Crystal_Clear_mimetype_pdf.png",
'mimetype' => 'image/png',
),
array (
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/collection_policies/PDF-COLLECTION POLICY.xml",
),
),
),
array (
array(
'pid' => 'demo:DualResImage',
'foxml_file' => "$module_path/content_models/demo_DualResImage.xml",
'datastreams' => array(
array (
array(
'dsid' => 'ISLANDORACM',
'datastream_file' => "$module_path/content_models/STANDARD JPG.xml",
),
),
),
array (
array(
'pid' => 'demo:DualResImageCollection',
'foxml_file' => "$module_path/content_models/demo_DualResImageCollection.xml",
'datastreams' => array(
@ -1570,47 +1578,47 @@ function fedora_repository_required_fedora_objects() {
),
),
),
array (
array(
'pid' => 'demo:DualResolution',
'foxml_file' => "$module_path/content_models/demo_DualResolution.xml",
),
array (
array(
'pid' => 'demo:DualResImageImpl',
'foxml_file' => "$module_path/content_models/demo_DualResImageImpl.xml",
),
array (
array(
'pid' => 'demo:CollectionImpl',
'foxml_file' => "$module_path/content_models/demo_CollectionImpl.xml",
),
array (
array(
'pid' => 'demo:Collection',
'foxml_file' => "$module_path/content_models/demo_Collection.xml",
),
array (
array(
'pid' => 'islandora:demo_image_collection',
'label' => 'Demo Image Collection',
'cmodel' => 'demo:DualResImageCollection',
'parent' => 'islandora:demos',
'datastreams' => array (
array (
'datastreams' => array(
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/collection_policies/JPG-COLLECTION POLICY.xml",
),
array (
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/images/Gnome-emblem-photos.png",
'mimetype' => 'image/png',
),
array (
array(
'dsid' => 'COLLECTION_VIEW',
'datastream_file' => "$module_path/collection_views/standard_jpeg_collection_view.xml",
),
array (
array(
'dsid' => 'QUERY',
'datastream_file' => "$module_path/collection_views/standard_jpeg_collection_query.txt",
'mimetype' => 'text/plain',
),
array (
array(
'dsid' => 'DC',
'datastream_file' => "$module_path/collection_views/demo_image_collection_dc_record.xml",
),
@ -1939,9 +1947,7 @@ function theme_add_to_basket_link($pid, $type = 'object') {
*/
if (!_is_added_to_basket($pid)) {
return l(
theme('image', drupal_get_path('module', 'Fedora_Repository') . '/images/' . $save, t("Add to basket"), t("Add this @object to my basket", array('@object' => $object))),
"fedora/repository/addToBasket/" . $path,
array('html' => TRUE)
theme('image', drupal_get_path('module', 'Fedora_Repository') . '/images/' . $save, t("Add to basket"), t("Add this @object to my basket", array('@object' => $object))), "fedora/repository/addToBasket/" . $path, array('html' => TRUE)
);
}
@ -1964,7 +1970,6 @@ function fedora_repository_display_schema($file) {
return;
}
function fedora_repository_batch_reingest_object($object, &$context) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_utils');
@ -1989,8 +1994,8 @@ function fedora_repository_batch_reingest_object($object, &$context) {
}
}
if (!empty($object['dsid']) && !empty($object['datastream_file'])) {
$datastreams = array (
array (
$datastreams = array(
array(
'dsid' => $object['dsid'],
'datastream_file' => $object['datastream_file'],
)
@ -2011,7 +2016,7 @@ function fedora_repository_batch_reingest_object($object, &$context) {
if (!empty($object['parent'])) {
$new_item->add_relationship('isMemberOfCollection', $object['parent']);
}
foreach($datastreams as $ds) {
foreach ($datastreams as $ds) {
if ($ds['dsid'] == 'DC') {
$new_item->modify_datastream_by_value(file_get_contents($ds['datastream_file']), $ds['dsid'], $ds['label'], 'text/xml');
}
@ -2037,13 +2042,14 @@ function fedora_repository_get_islandora_datastream_version($item = NULL, $dsid
$return = NULL;
if (isset($item)) {
$doc = simplexml_load_string($item->get_datastream_dissemination($dsid));
} elseif (isset($datastream_file)) {
}
elseif (isset($datastream_file)) {
$doc = simplexml_load_file($datastream_file);
}
if (!empty($doc)) {
$attrs = $doc->attributes();
foreach($attrs as $name => $value) {
foreach ($attrs as $name => $value) {
if ($name == 'version') {
$return = (int) $value;
break;
@ -2063,7 +2069,7 @@ function theme_fedora_repository_solution_packs_list($solution_packs) {
drupal_add_css(drupal_get_path('module', 'update') .'/update.css');
drupal_add_css(drupal_get_path('module', 'update') . '/update.css');
return $output;
}

5
formClass.inc

@ -531,6 +531,7 @@ class formClass {
$contentModelPid = ContentModel::getPidFromIdentifier($form_state['values']['models']);
$contentModelDsid = ContentModel::getDSIDFromIdentifier($form_state['values']['models']);
// XML Forms
if (module_exists('xml_form_api')) {
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
if (isset($form_state['values']['forms']) || $xml_form->isInitialized()) {
@ -545,9 +546,11 @@ class formClass {
$xml_form->initialize($form, $document);
}
$form = $xml_form->toArray();
break;
}
}
// End XML forms
else if (($cm = ContentModel::loadFromModel($contentModelPid, $contentModelDsid)) !== FALSE) {
if (($cm = ContentModel::loadFromModel($contentModelPid, $contentModelDsid)) !== FALSE) {
$form = $cm->buildIngestForm($form, $form_state);
if ($form === FALSE) {

Loading…
Cancel
Save