Browse Source

Added logic for management on page objects

pull/3/merge
Alan Stanley 14 years ago
parent
commit
5242573c41
  1. 49
      ilives/book.inc
  2. 304
      ilives/fedora_ilives.module

49
ilives/book.inc

@ -58,7 +58,6 @@ class IslandoraBook {
'#type' => 'textarea', '#type' => 'textarea',
'#title' => 'MODS Record to Import', '#title' => 'MODS Record to Import',
'#rows' => 20, '#rows' => 20,
); );
if (!empty($mods_save)) { if (!empty($mods_save)) {
@ -128,7 +127,6 @@ class IslandoraBook {
$title = ''; $title = '';
foreach (array('nonSort', 'title') as $title_field) { foreach (array('nonSort', 'title') as $title_field) {
$title .= $title_info->getElementsByTagNameNS('http://www.loc.gov/mods/v3', $title_field)->item(0)->nodeValue . ' '; $title .= $title_info->getElementsByTagNameNS('http://www.loc.gov/mods/v3', $title_field)->item(0)->nodeValue . ' ';
} }
$title = trim($title); $title = trim($title);
$mods_text = $mods_item_doc->saveXML(); $mods_text = $mods_item_doc->saveXML();
@ -155,10 +153,8 @@ class IslandoraBook {
$new_item->add_relationship('hasModel', $form_values['content_model_pid'], FEDORA_MODEL_URI); $new_item->add_relationship('hasModel', $form_values['content_model_pid'], FEDORA_MODEL_URI);
$new_item->add_relationship(!empty($form_values['relationship']) ? $form_values['relationship'] : 'isMemberOfCollection', $form_values['collection_pid']); $new_item->add_relationship(!empty($form_values['relationship']) ? $form_values['relationship'] : 'isMemberOfCollection', $form_values['collection_pid']);
drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($new_item->pid, 'fedora/repository/' . $new_item->pid))), "status"); drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($new_item->pid, 'fedora/repository/' . $new_item->pid))), "status");
} }
public function buildAddPagesForm($form = array()) { public function buildAddPagesForm($form = array()) {
} }
@ -168,7 +164,9 @@ class IslandoraBook {
module_load_include('inc', 'fedora_repository', 'plugins/DarwinCore'); module_load_include('inc', 'fedora_repository', 'plugins/DarwinCore');
module_load_include('module', 'fedora_ilives'); module_load_include('module', 'fedora_ilives');
global $base_url; global $base_url;
$show_purge_tab = (!empty($_POST['form_id']) && ($_POST['form_id'] == 'fedora_ilives_purge_pages_form'));
$first_page = new Fedora_Item($this->pid . '-001');
$hasPage = $first_page->exists();
$tabset = array(); $tabset = array();
global $user; global $user;
@ -179,11 +177,7 @@ class IslandoraBook {
$viewer_url = variable_get('fedora_base_url', '') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer' . $qs; $viewer_url = variable_get('fedora_base_url', '') . '/get/' . $this->pid . '/ilives:viewerSdef/getViewer' . $qs;
$html = '<iframe src="' . $viewer_url . '" scrolling="0" frameborder="0" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>'; $html = '<iframe src="' . $viewer_url . '" scrolling="0" frameborder="0" style="width: 100%; height: 800px;">Errors: unable to load viewer</iframe>';
$tabset['second_tab'] = array(
'#type' => 'tabpage',
'#title' => t('Read'),
'#content' => $html
);
$tabset['first_tab'] = array( $tabset['first_tab'] = array(
// #type and #title are the minimum requirements. // #type and #title are the minimum requirements.
'#type' => 'tabpage', '#type' => 'tabpage',
@ -192,18 +186,35 @@ class IslandoraBook {
'#content' => fedora_ilives_create_book_view($this->pid), '#content' => fedora_ilives_create_book_view($this->pid),
); );
if (user_access('ingest new fedora objects')) { if ($hasPage) {
$tabset['add_pages'] = array( $tabset['second_tab'] = array(
'#type' => 'tabpage',
'#title' => t('Read'),
'#content' => $html
);
}
if (!$hasPage && user_access('ingest new fedora objects')) {
$tabset['third_tab'] = array(
'#type' => 'tabpage', '#type' => 'tabpage',
'#title' => t('Add pages'), '#title' => t('Add pages'),
'#content' => drupal_get_form('book_add_pages_form', $this->pid), '#content' => drupal_get_form('book_add_pages_form', $this->pid),
); );
} }
if ($hasPage && user_access('purge objects and datastreams')) {
$tabset['fourth_tab'] = array(
'#type' => 'tabpage',
'#title' => t('Purge all pages'),
'#selected' => $show_purge_tab,
'#content' => drupal_get_form('fedora_ilives_purge_pages_form', $this->pid),
);
}
return $tabset; return $tabset;
} }
} }
function book_add_pages_form(&$form_state, $pid, $page_cmodel = 'ilives:pageCModel', $relation = 'isMemberOfCollection') { function book_add_pages_form(&$form_state, $pid, $page_cmodel = 'ilives:pageCModel', $relation = 'isMemberOf') {
$form['pid'] = array( $form['pid'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => $pid, '#value' => $pid,
@ -260,10 +271,13 @@ function book_add_pages_form_submit($form, &$form_state) {
*/ */
function ilives_create_page_objects($pid, $image_list = array(), $page_cmodel = 'ilives:pageCModel', $relation = 'isMemberOfCollection') { function ilives_create_page_objects($pid, $image_list = array(), $page_cmodel = 'ilives:pageCModel', $relation = 'isMemberOfCollection') {
module_load_include('inc', 'fedora_repository', 'api/fedora_item'); module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
$book = new Fedora_Item($pid); $book = new Fedora_Item($pid);
if (!$book->exists()) { if (!$book->exists()) {
return FALSE; return FALSE;
} }
$page_pids = array(); $page_pids = array();
$batch = array( $batch = array(
'title' => 'Creating page objects', 'title' => 'Creating page objects',
@ -277,6 +291,15 @@ function ilives_create_page_objects($pid, $image_list = array(), $page_cmodel =
$page_num++; $page_num++;
} }
batch_set($batch); batch_set($batch);
$objectHelper = new ObjectHelper;
$dc_xml = $objectHelper->getStream($pid, 'DC');
$xml = new DOMDocument();
$xml->loadXML($dc_xml);
$root = $xml->documentElement;
$typeNode = $xml->createElement('dc:type', 'ingested');
$typeNode = $xml->createElementNS("http://purl.org/dc/elements/1.1/", 'dc:type', 'ingested');
$root->appendChild($typeNode);
$book->modify_datastream_by_value($xml->saveXML(), 'DC', 'Dublin core', 'text/xml', TRUE, "Added Type of Ingest", FALSE);
} }
function ilives_add_single_page_object($book_pid, $page_file, $page_num = 1, $page_title = NULL, $page_cmodel = 'ilives:pageCModel', $relation = 'isMemberOfCollection') { function ilives_add_single_page_object($book_pid, $page_file, $page_num = 1, $page_title = NULL, $page_cmodel = 'ilives:pageCModel', $relation = 'isMemberOfCollection') {

304
ilives/fedora_ilives.module

@ -1,4 +1,5 @@
<?php <?php
// $Id$ // $Id$
/* /*
@ -41,14 +42,9 @@ function fedora_ilives_menu() {
return $items; return $items;
} }
//function fedora_ilives_book_search($query) { //function fedora_ilives_book_search($query) {
//} //}
//function fedora_ilives_page_search($query) { //function fedora_ilives_page_search($query) {
//} //}
function fedora_ilives_block($op = 'list', $delta = 0, $edit = array()) { function fedora_ilives_block($op = 'list', $delta = 0, $edit = array()) {
@ -166,8 +162,6 @@ and $object <dc:title> $title'),
} }
} }
function fedora_ilives_book_viewer($pid) { function fedora_ilives_book_viewer($pid) {
global $user; global $user;
$qs = ''; $qs = '';
@ -185,8 +179,8 @@ function fedora_ilives_book_viewer($pid) {
'#value' => $html); '#value' => $html);
drupal_add_css(path_to_theme() . '/header-viewer.css', 'theme'); drupal_add_css(path_to_theme() . '/header-viewer.css', 'theme');
return theme('fieldset', $fieldset); return theme('fieldset', $fieldset);
} }
//loads an xslt for the main book page uses mods for most of the display. if there is a $query parameter //loads an xslt for the main book page uses mods for most of the display. if there is a $query parameter
// it will execute it against the book. // it will execute it against the book.
function fedora_ilives_create_book_view($pid, $query = NULL) { function fedora_ilives_create_book_view($pid, $query = NULL) {
@ -390,42 +384,6 @@ function fedora_ilives_book_search_form_submit($form, &$form_state) {
return $searchClass->custom_search($query, $startPage, '/ilives/xsl/results.xsl', 10); return $searchClass->custom_search($query, $startPage, '/ilives/xsl/results.xsl', 10);
} }
/*function custom_search($query) {
module_load_include('inc', 'fedora_repository', 'ObjectHelper');
module_load_include('inc', 'fedora_repository', 'SearchClass');
if (user_access('view fedora collection')) {
$numberOfHistPerPage = '1000';//hack for IR they do not want next button
$luceneQuery = NULL;
//demo search string ?operation=gfindObjects&indexName=DemoOnLucene&query=fgs.DS.first.text%3Achristmas&hitPageStart=11&hitPageSize=10
$indexName = variable_get('fedora_index_name', 'DemoOnLucene');
$query.=$query.'+dc.type:collection';
$query=htmlentities(urlencode($query));
$searchUrl = variable_get('fedora_fgsearch_url', 'http://localhost:8080/fedoragsearch/rest');
$searchString = '?operation=gfindObjects&indexName=' . $indexName . '&restXslt=copyXml&query=' . $query;
$searchString .= '&hitPageSize='.$numberOfHistPerPage.'&hitPageStart=1';
//$searchString = htmlentities($searchString);
$searchUrl .= $searchString;
$objectHelper = new ObjectHelper();
$resultData = $objectHelper->doCurl($searchUrl,1);
//var_dump($resultData);exit(0);
// $doc = new DOMDocument();
// $doc->loadXML($resultData);
$searchClass = new SearchClass();
$output.=$searchClass->applyLuceneXSLT($resultData);
return $output;
}
}*/
function retrieve_unapi_MODS_record($url) { function retrieve_unapi_MODS_record($url) {
$bib_response = drupal_http_request($url); $bib_response = drupal_http_request($url);
$bib_html = $bib_response->data; $bib_html = $bib_response->data;
@ -452,7 +410,6 @@ function retrieve_unapi_MODS_record($url) {
return $mods_data; return $mods_data;
} }
/** /**
* AHAH callback for the 'match type' select. * AHAH callback for the 'match type' select.
* This function handles the actual replace and sets the $form and $form_state arrays. * This function handles the actual replace and sets the $form and $form_state arrays.
@ -512,7 +469,6 @@ function fedora_ilives_retrieve_unapi_submit($form, &$form_state) {
function fedora_ilives_form_alter(&$form, &$form_state, $form_id) { function fedora_ilives_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'fedora_repository_admin') { if ($form_id == 'fedora_repository_admin') {
# Custom settings for book module. # Custom settings for book module.
} }
elseif ($form_id == 'fedora_repository_demo_objects_form') { elseif ($form_id == 'fedora_repository_demo_objects_form') {
if (!Fedora_Item::fedora_item_exists('ilives:bookCModel')) { if (!Fedora_Item::fedora_item_exists('ilives:bookCModel')) {
@ -539,60 +495,6 @@ function fedora_ilives_install_demos_form_submit($form, &$form_state) {
if ($form_state['values']['demo_collections']['ilives:bookCModel'] == 'ilives:bookCModel') { if ($form_state['values']['demo_collections']['ilives:bookCModel'] == 'ilives:bookCModel') {
# The ilives:bookCModel checkbox was checked # The ilives:bookCModel checkbox was checked
install_book_content_model_objects(); install_book_content_model_objects();
}
}
function install_book_content_model_objects() {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$allowed_pids_str = variable_get('fedora_pids_allowed', 'default: demo: changeme: Islandora: ilives: ');
$allowed_pids = explode(' ', $allowed_pids_str);
if (!in_array('ilives:', $allowed_pids)) {
variable_set('fedora_pids_allowed', $allowed_pids_str . ' ilives:');
drupal_set_message('Added ilives: to the set of allowed pidnamespaces.', 'info');
}
if (!Fedora_Item::fedora_item_exists('ilives:bookCModel')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_bookCModel.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:pageCModel')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_pageCModel.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:jp2Sdef')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_jp2Sdef.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:tei2htmlSdef')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_tei2htmlSdef.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:tei2htmlSdep-pageCModel')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_tei2htmlSdep-pageCModel.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:viewerSdef')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_viewerSdef.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:viewerSdep-bookCModel')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_viewerSdep-bookCModel.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:viewerSdep-pageCModel')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_viewerSdep-pageCModel.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:collection')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_collection.xml');
}
if (!Fedora_Item::fedora_item_exists('ilives:CollectionModel')) {
Fedora_Item::ingest_from_foxml_file(drupal_get_path('module', 'fedora_ilives') . '/xml/ilives_CollectionModel.xml');
} }
} }
@ -643,3 +545,205 @@ function _fedora_ilives_viewer_available() {
$response = drupal_http_request("$fedora_host/iiv/images/loading.gif"); $response = drupal_http_request("$fedora_host/iiv/images/loading.gif");
return empty($response->error); return empty($response->error);
} }
function fedora_ilives_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_ilives');
return array(
'fedora_ilives' => array(
'module' => 'fedora_ilives',
'title' => 'Island Lives Books',
'objects' => array(
array(
'foxml_file' => "$module_path/xml/ilives_pageCModel.xml",
'pid' => 'ilives:pageCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_bookCModel.xml",
'pid' => 'ilives:bookCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_jp2Sdef.xml",
'pid' => 'ilives:jp2Sdef',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_viewerSdef.xml",
'pid' => 'ilives:viewerSdef',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_viewerSdep-bookCModel.xml",
'pid' => 'ilives:viewerSdep-bookCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_viewerSdep-pageCModel.xml",
'pid' => 'ilives:viewerSdep-pageCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_tei2htmlSdef.xml",
'pid' => 'ilives:tei2htmlSdef',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_tei2htmlSdep-pageCModel.xml",
'pid' => 'ilives:tei2htmlSdep-pageCModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_collection.xml",
'pid' => 'ilives:collection',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'foxml_file' => "$module_path/xml/ilives_CollectionModel.xml",
'pid' => 'ilives:CollectionModel',
'dsid' => NULL,
'datastream_file' => NULL,
'dsversion' => NULL,
),
array(
'pid' => 'books:collection',
'label' => 'Book Collection',
'cmodel' => 'islandora:collectionCModel',
'parent' => 'islandora:demos',
'datastreams' => array(
array(
'dsid' => 'COLLECTION_POLICY',
'datastream_file' => "$module_path/xml/book_collection_policy.xml",
),
array(
'dsid' => 'TN',
'datastream_file' => "$module_path/Crystal_Clear_mimetype_man.png",
'mimetype' => 'image/png',
),
),
),
),
),
);
}
function fedora_ilives_purge_pages_form(&$form_state, $pid, $referrer = NULL) {
global $base_url;
if (!user_access('purge objects and datastreams')) {
return NULL;
}
if ($pid == NULL) {
return NULL;
}
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
);
if (!strstr(drupal_get_destination(), urlencode('fedora/repository'))) {
$form['referrer'] = array(
'#type' => 'hidden',
'#value' => $referrer,
);
}
if (!isset($form_state['storage']['confirm'])) {
// do your normal $form definition here
$form['submit'] = array(
'#type' => 'image_button',
'#src' => drupal_get_path('module', 'fedora_repository') . '/images/purge_big.png',
'#value' => t('Purge'),
'#suffix' => 'Purge all pages associated with this book',
);
return $form;
}
else {
// ALSO do $form definition here. Your final submit handler (after user clicks Yes, I Confirm) will only see $form_state info defined here. Form you create here passed as param1 to confirm_form
return confirm_form($form, 'Confirm Purge ALL pages?', $referrer, 'Are you sure you want to delete these objects? This action cannot be undone.', 'Purge Pages', 'Cancel'); //Had better luck leaving off last param 'name'
}
return $form;
}
function fedora_ilives_purge_pages_form_submit($form, &$form_state) {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper');
$pid = $form_state['values']['pid'];
if (!isset($form_state['storage']['confirm'])) {
$form_state['storage']['confirm'] = TRUE; // this will cause the form to be rebuilt, entering the confirm part of the form
$form_state['rebuild'] = TRUE; // along with this
}
else {
$query = <<<XML
select \$object \$title from <#ri>
where (\$object <dc:title> \$title
and \$object <fedora-rels-ext:isMemberOf> <info:fedora/$pid>
and \$object <fedora-model:state> <info:fedora/fedora-system:def/model#Active>)
order by \$title
XML;
// this is where you do your processing after they have pressed the confirm button
module_load_include('inc', 'fedora_repoitory', 'CollectionClass');
$collection = new CollectionClass($pid);
$contents = $collection->getRelatedItems($pid, $query);
$results_xml = simplexml_load_string($contents);
$resultsarray = array();
foreach ($results_xml->results->result as $result) {
$pid_to_delete = str_replace('info:fedora/', '', $result->object->attributes()->uri);
//parse contents
$params = array(
"pid" => $pid_to_delete,
"logMessage" => "Purged",
"force" => ""
);
try {
$soapHelper = new ConnectionHelper();
$client = $soapHelper->getSoapClient(variable_get('fedora_soap_manage_url', 'http://localhost:8080/fedora/services/management?wsdl'));
$object = $client->__soapCall('purgeObject', array($params));
unset($form_state['storage']['confirm']);
} catch (exception $e) {
if (preg_match('/org\.fcrepo\.server\.security\.xacml\.pep\.AuthzDeniedException/', $e->getMessage())) {
drupal_set_message(t('Error: Insufficient permissions to purge object.'), 'error');
}
else {
drupal_set_message(t($e->getMessage()), 'error');
}
return;
}
}
if (!empty($form_state['values']['referrer'])) {
$form_state['redirect'] = $form_state['values']['referrer'];
}
elseif (empty($collectionPid) && !empty($_SESSION['fedora_collection']) && $_SESSION['fedora_collection'] != $pid) {
$collectionPid = $_SESSION['fedora_collection'];
$form_state['redirect'] = "fedora/repository/$collectionPid/";
}
else {
$form_state['redirect'] = 'fedora/repository/';
}
}
}

Loading…
Cancel
Save