@ -2,244 +2,268 @@
// $Id$
// $Id$
/**
* @file
* ModsFormBuilder class
*/
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
module_load_include('inc', 'fedora_repository', 'plugins/FormBuilder');
/**
* ModsFormBuilder class ???
*/
class ModsFormBuilder extends FormBuilder {
class ModsFormBuilder extends FormBuilder {
static $MODS_NS = 'http://www.loc.gov/mods/v3';
static $MODS_NS = 'http://www.loc.gov/mods/v3';
protected $cm;
protected $cm;
protected $item;
protected $item;
protected $pid;
protected $pid;
function __construct($pid=null)
/**
{
* Constructor
parent::__construct();
* @param type $pid
if ($pid !== null)
*/
{
function __construct($pid=null) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
parent::__construct();
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
if ($pid !== null) {
module_load_include('inc', 'fedora_repository', 'ContentModel');
$this->pid=$pid;
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$this->cm = ContentModel::loadFromObject($pid);
$this->item = new fedora_item($pid);
$this->pid = $pid;
}
$this->cm = ContentModel::loadFromObject($pid);
}
$this->item = new fedora_item($pid);
}
function handleEditMetadataForm(& $form_id, & $form_values, & $soap_client)
}
{
/**
* Handle Edit Metadata Form ???
* @param & $form_id
* @param & $form_values
* @param & $soap_client
*/
function handleEditMetadataForm(& $form_id, & $form_values, & $soap_client) {
$dom = new DomDocument("1.0", "UTF-8");
$dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE;
$dom->formatOutput = TRUE;
$mods = $this->modsFromForm($form_values,$dom);
$mods = $this->modsFromForm($form_values, $dom);
$dom->appendChild($mods);
$dom->appendChild($mods);
if ($this->item->modify_datastream_by_value($dom->saveXML(), 'MODS', "MODS Record", 'text/xml') !== NULL) {
if ($this->item->modify_datastream_by_value($dom->saveXML(), 'MODS', "MODS Record", 'text/xml') !== NULL) {
drupal_set_message(t('Successfully updated MODS datastream for object %pid', array('%pid'=>$this->pid)));
drupal_set_message(t('Successfully updated MODS datastream for object %pid', array('%pid' => $this->pid)));
}
}
drupal_goto('/fedora/repository/'.$this->pid);
drupal_goto('/fedora/repository/' . $this->pid);
}
}
function buildEditMetadataForm()
/**
{
* Build Edit Metadata Form
$form['#multistep'] = TRUE; // used so that it triggers a form rebuild every time.
* @return array
$form['indicator2'] = array(
*/
'#type' => 'fieldset',
function buildEditMetadataForm() {
'#title' => t('Edit metadata'),
$form['#multistep'] = TRUE; // used so that it triggers a form rebuild every time.
);
$form['indicator2'] = array(
'#type' => 'fieldset',
'#title' => t('Edit metadata'),
);
if ($this->cm !== FALSE & & $this->item != NULL) {
if ($this->cm !== FALSE & & $this->item != NULL) {
$form['pid'] = array('#type'=>'hidden','#value'=>$this->pid);
$form['pid'] = array('#type' => 'hidden', '#value' => $this->pid);
$elements = $this->cm->getIngestFormElements();
$elements = $this->cm->getIngestFormElements();
$content = $this->item->get_datastream_dissemination('MODS');
$content = $this->item->get_datastream_dissemination('MODS');
if (trim($content) != '') {
if (trim($content) != '') {
$dom = DOMDocument::loadXML($content);
$dom = DOMDocument::loadXML($content);
$xpath = new DOMXPath($dom);
$xpath = new DOMXPath($dom);
// Register the php: namespace (required)
// Register the php: namespace (required)
$xpath->registerNamespace("php", "http://php.net/xpath");
$xpath->registerNamespace("php", "http://php.net/xpath");
// Register PHP functions (no restrictions)
// Register PHP functions (no restrictions)
$xpath->registerPHPFunctions();
$xpath->registerPHPFunctions();
foreach ($elements as $element) {
foreach ($elements as $element) {
$el = array(
$el = array(
'#title' => $element['label'],
'#title' => $element['label'],
'#required' => ($element['required'] ? 1 : 0),
'#required' => ($element['required'] ? 1 : 0),
'#description' => $element['description'],
'#description' => $element['description'],
'#type' => $element['type']
'#type' => $element['type']
);
);
$includeEl = true;
$includeEl = true;
$elname = explode('][', $element['name']);
$elname = explode('][', $element['name']);
$elLocation = &$form['indicator2'];
$elLocation = &$form['indicator2'];
while (isset($elLocation[$name[0]]) & & ($partial = array_shift($elname)) != NULL) {
while (isset($elLocation[$name[0]]) & & ($partial = array_shift($elname)) != NULL) {
$elLocation = &$elLocation[$partial];
$elLocation = &$elLocation[$partial];
}
}
foreach ($element['parameters'] as $key => $val) {
foreach ($element['parameters'] as $key => $val) {
switch ($key) {
switch ($key) {
case '#autocomplete_path':
case '#autocomplete_path':
$val .= '/' . $form_values['storage']['collection_pid'];
$val .= '/' . $form_values['storage']['collection_pid'];
break;
break;
case '#exclude_from_edit_metadata':
case '#exclude_from_edit_metadata':
$includeEl= FALSE;
$includeEl = FALSE;
break;
break;
case '#edit_metadata_xpath':
case '#edit_metadata_xpath':
$nodeList = $xpath->evaluate($val);
$nodeList = $xpath->evaluate($val);
// echo $val. ' '.$nodeList->length.' ';
// echo $val. ' '.$nodeList->length.' ';
// echo $nodeList->item(0)->nodeValue.' ';
// echo $nodeList->item(0)->nodeValue.' ';
// echo '< br / > ';
// echo '< br / > ';
if (is_string($nodeList))
if (is_string($nodeList)) {
{
$el['#default_value'] = $nodeList;
$el['#default_value']=$nodeList;
}
} else if ($nodeList->length > 1)
else if ($nodeList->length > 1) {
{
$el['#default_value'] = array();
$el['#default_value'] = array();
foreach ($nodeList as $node) {
foreach ($nodeList as $node)
$el['#default_value'][] = $node->nodeValue;
{
}
$el['#default_value'][] = $node->nodeValue;
}
}
else if ($nodeList->length > 0) {
} else if ($nodeList->length > 0)
if ($el['#type'] == 'list') {
{
$values = array();
if ($el['#type'] == 'list') {
for ($i = 0; $i < $nodeList->length; $i++) {
$values=array();
$values[] = $nodeList->item($i)->nodeValue;
for ($i=0;$i< $nodeList->length;$i++) {
}
$values[]=$nodeList->item($i)->nodeValue;
$el['#default_value'] = join('; ', $values);
}
}
$el['#default_value']=join('; ',$values);
else {
} else {
$el['#default_value'] = $nodeList->item(0)->nodeValue;
$el['#default_value'] = $nodeList->item(0)->nodeValue;
}
}
}
}
break;
break;
}
}
if ($key != '#sticky') {
if ($key != '#sticky') {
$el[$key] = $val;
$el[$key]=$val;
}
}
}
}
if ($element['type'] == 'people') {
if ($element['type'] == 'people')
$names = $xpath->evaluate('/mods:mods/mods:name');
{
$people = array();
foreach ($names as $mname) {
$names = $xpath->evaluate('/mods:mods/mods:name');
$people=array();
$type = $mname->getAttribute('type');
foreach ($names as $mname) {
$role = $mname->getElementsByTagName('roleTerm')->item(0)->nodeValue;
$type = $mname->getAttribute('type');
$nameParts = $mname->getElementsByTagName('namePart');
$role = $mname->getElementsByTagName('roleTerm')->item(0)->nodeValue;
foreach ($nameParts as $namePart) {
switch ($namePart->getAttribute('type')) {
$nameParts = $mname->getElementsByTagName('namePart');
case 'given': $given = $namePart->nodeValue;
foreach ($nameParts as $namePart)
break;
{
case 'family': $family = $namePart->nodeValue;
switch ($namePart->getAttribute('type')) {
break;
case 'given': $given = $namePart->nodeValue; break;
case 'termsOfAddress': $title = $namePart->nodeValue;
case 'family': $family = $namePart->nodeValue; break;
break;
case 'termsOfAddress': $title = $namePart->nodeValue; break;
case 'date': $date = $namePart->nodeValue;
case 'date': $date = $namePart->nodeValue; break;
break;
default: $name = $namePart->nodeValue; break;
default: $name = $namePart->nodeValue;
break;
}
}
$person = array('role' => $role);
switch ($type) {
case 'personal':
if (isset($given) & & isset($family) & & !isset($name)) {
$name = (isset($title) ? $title . ' ' : '') . $family . ', ' . $family;
}
$person['name'] = $name;
$person['date'] = $date;
break;
case 'organization':
$person['organization'] = $name;
break;
case 'conference':
$person['conference'] = $name;
$person['date'] = $date;
break;
}
$people[] = $person;
}
$names = $xpath->evaluate('/mods:mods/mods:subject/mods:name');
foreach ($names as $mname) {
$type = $mname->getAttribute('type');
$nameParts = $mname->getElementsByTagName('namePart');
foreach ($nameParts as $namePart) {
switch ($namePart->getAttribute('type')) {
case 'given': $given = $namePart->nodeValue;
break;
case 'family': $family = $namePart->nodeValue;
break;
case 'termsOfAddress': $title = $namePart->nodeValue;
break;
case 'date': $date = $namePart->nodeValue;
break;
default: $name = $namePart->nodeValue;
break;
}
}
$person = array('subject' => 1);
switch ($type) {
case 'personal':
if (isset($given) & & isset($family) & & !isset($name)) {
$name = (isset($title) ? $title . ' ' : '') . $family . ', ' . $family;
}
$person['name'] = $name;
$person['date'] = $date;
break;
case 'organization':
$person['organization'] = $name;
break;
case 'conference':
$person['conference'] = $name;
$person['date'] = $date;
break;
}
$people[] = $person;
}
$el['#default_value'] = $people;
}
}
}
$person=array('role'=>$role);
switch ($type)
{
case 'personal':
if (isset($given) & & isset($family) & & !isset($name)) {
$name = (isset($title)?$title.' ':'').$family.', '.$family;
}
$person['name']=$name;
$person['date']=$date;
break;
case 'organization':
$person['organization'] = $name;
break;
case 'conference':
$person['conference']=$name;
$person['date']=$date;
break;
}
$people[]=$person;
}
$names = $xpath->evaluate('/mods:mods/mods:subject/mods:name');
foreach ($names as $mname) {
$type = $mname->getAttribute('type');
$nameParts = $mname->getElementsByTagName('namePart');
foreach ($nameParts as $namePart)
{
switch ($namePart->getAttribute('type')) {
case 'given': $given = $namePart->nodeValue; break;
case 'family': $family = $namePart->nodeValue; break;
case 'termsOfAddress': $title = $namePart->nodeValue; break;
case 'date': $date = $namePart->nodeValue; break;
default: $name = $namePart->nodeValue; break;
}
}
$person=array('subject'=>1);
switch ($type)
{
case 'personal':
if (isset($given) & & isset($family) & & !isset($name)) {
$name = (isset($title)?$title.' ':'').$family.', '.$family;
}
$person['name']=$name;
$person['date']=$date;
break;
case 'organization':
$person['organization'] = $name;
break;
case 'conference':
$person['conference']=$name;
$person['date']=$date;
break;
}
$people[]=$person;
}
$el['#default_value'] = $people;
}
if ($element['type'] == 'select' || $element['type'] == 'other_select') {
$el['#options']= isset($element['authoritative_list'])?$element['authoritative_list']:array();
}
if ($includeEl) {
$elLocation[join('][', $elname)] = $el;
}
}
$form['submit'] = array(
'#type' => 'submit',
'#submit' => array('fedora_repository_edit_qdc_form_submit'),
'#value' => 'Save Metadata'
);
return $form;
if ($element['type'] == 'select' || $element['type'] == 'other_select') {
$el['#options'] = isset($element['authoritative_list']) ? $element['authoritative_list'] : array();
}
if ($includeEl) {
$elLocation[join('][', $elname)] = $el;
}
}
$form['submit'] = array(
'#type' => 'submit',
'#submit' => array('fedora_repository_edit_qdc_form_submit'),
'#value' => 'Save Metadata'
);
return $form;
}
}
}
}
}
}
/**
* Handle Mods Form
function handleModsForm(& $form_values,& $form_state) {
* @param & $form_values
* @param & $form_state
*/
function handleModsForm(& $form_values, & $form_state) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
module_load_include('inc', 'fedora_repository', 'CollectionPolicy');
$form_state['storage']['people']=NULL; //clears out old entities for the next run of the formbuilder.
$form_state['storage']['people'] = NULL; //clears out old entities for the next run of the formbuilder.
$dom = new DomDocument("1.0", "UTF-8");
$dom = new DomDocument("1.0", "UTF-8");
$dom->formatOutput = TRUE;
$dom->formatOutput = TRUE;
$pid=$form_values['pid'];
$pid = $form_values['pid'];
$rootElement = $dom->createElement("foxml:digitalObject");
$rootElement = $dom->createElement("foxml:digitalObject");
$rootElement->setAttribute('VERSION', '1.1');
$rootElement->setAttribute('VERSION', '1.1');
$rootElement->setAttribute('PID', "$pid");
$rootElement->setAttribute('PID', "$pid");
@ -257,9 +281,9 @@ class ModsFormBuilder extends FormBuilder {
$collectionPid = $form_values['collection_pid'];
$collectionPid = $form_values['collection_pid'];
if (($cp = CollectionPolicy::LoadFromCollection($collectionPid)) !== FALSE) {
if (($cp = CollectionPolicy::LoadFromCollection($collectionPid)) !== FALSE) {
$collectionName =trim($cp->getName());
$collectionName = trim($cp->getName());
if (trim($collectionName)!='') {
if (trim($collectionName) != '') {
$form_values['dc_relation']=$collectionName;
$form_values['dc_relation'] = $collectionName;
}
}
}
}
// Create MODS
// Create MODS
@ -276,31 +300,35 @@ class ModsFormBuilder extends FormBuilder {
// echo $dom->saveXML(); exit();
// echo $dom->saveXML(); exit();
try {
try {
$object = Fedora_Item::ingest_from_FOXML($dom);
$object = Fedora_Item::ingest_from_FOXML($dom);
//for some reason, ingest_from_FOXML does not generate a JMS message
//for some reason, ingest_from_FOXML does not generate a JMS message
//I just modify the workflow DS and it sends a JMS message.
//I just modify the workflow DS and it sends a JMS message.
$item = new Fedora_Item($object->pid);
$item = new Fedora_Item($object->pid);
$item->modify_datastream_by_value( $item->get_datastream_dissemination('WORKFLOW'), 'WORKFLOW', "Workflow Record", 'text/xml');
$item->modify_datastream_by_value($item->get_datastream_dissemination('WORKFLOW'), 'WORKFLOW', "Workflow Record", 'text/xml');
if (!empty($object->pid)) {
if (!empty($object->pid)) {
drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/'. $object->pid))), "status");
drupal_set_message(t("Item !pid created successfully.", array('!pid' => l($object->pid, 'fedora/repository/' . $object->pid))), "status");
}
}
if (!empty( $_SESSION['fedora_ingest_files'])) {
if (!empty($_SESSION['fedora_ingest_files'])) {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
foreach ($_SESSION['fedora_ingest_files'] as $dsid => $createdFile) {
file_delete($createdFile);
file_delete($createdFile);
}
}
}
}
file_delete($form_values['ingest-file-location']);
file_delete($form_values['ingest-file-location']);
}
} catch (exception $e) {
catch (exception $e) {
drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error');
drupal_set_message(t('Error ingesting object: !e', array('!e' => $e->getMessage())), 'error');
watchdog(t("Fedora_Repository"), t("Error ingesting object: !e", array('!e' => $e->getMessage())), NULL, WATCHDOG_ERROR);
watchdog(t("Fedora_Repository"), t("Error ingesting object: !e", array('!e' => $e->getMessage())), NULL, WATCHDOG_ERROR);
return;
return;
}
}
}
}
/**
function createCollectionPolicy($form_values, & $dom, & $rootElement) {
* Create Collection Policy ??
* @param $form_values
* @param & $dom
* @param & $rootElement
*/
function createCollectionPolicy($form_values, & $dom, & $rootElement) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$model = new fedora_item($form_values['content_model_pid']);
$model = new fedora_item($form_values['content_model_pid']);
$ds_list = $model->get_datastreams_list_as_array();
$ds_list = $model->get_datastreams_list_as_array();
@ -308,8 +336,8 @@ class ModsFormBuilder extends FormBuilder {
$cp = $model->get_datastream_dissemination('COLLECTION_POLICY_TMPL');
$cp = $model->get_datastream_dissemination('COLLECTION_POLICY_TMPL');
$cpDom = DOMDocument::loadXML($cp);
$cpDom = DOMDocument::loadXML($cp);
$cpRootEl = $cpDom->getElementsByTagName('collection_policy');
$cpRootEl = $cpDom->getElementsByTagName('collection_policy');
if ($cpRootEl->length >0) {
if ($cpRootEl->length > 0) {
$cpRootEl=$cpRootEl->item(0);
$cpRootEl = $cpRootEl->item(0);
$newNode = $dom->importNode($cpRootEl, TRUE);
$newNode = $dom->importNode($cpRootEl, TRUE);
$datastream = $dom->createElement("foxml:datastream");
$datastream = $dom->createElement("foxml:datastream");
@ -329,6 +357,12 @@ class ModsFormBuilder extends FormBuilder {
}
}
}
}
/**
* Create Workflow Stream ??
* @param $form_values
* @param & $dom
* @param & $rootElement
*/
function createWorkflowStream($form_values, & $dom, & $rootElement) {
function createWorkflowStream($form_values, & $dom, & $rootElement) {
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
module_load_include('inc', 'fedora_repository', 'api/fedora_item');
$model = new fedora_item($form_values['content_model_pid']);
$model = new fedora_item($form_values['content_model_pid']);
@ -337,8 +371,8 @@ class ModsFormBuilder extends FormBuilder {
$workflow = $model->get_datastream_dissemination('WORKFLOW_TMPL');
$workflow = $model->get_datastream_dissemination('WORKFLOW_TMPL');
$workflowDom = DOMDocument::loadXML($workflow);
$workflowDom = DOMDocument::loadXML($workflow);
$workflowRootEl = $workflowDom->getElementsByTagName('workflow');
$workflowRootEl = $workflowDom->getElementsByTagName('workflow');
if ($workflowRootEl->length >0) {
if ($workflowRootEl->length > 0) {
$workflowRootEl=$workflowRootEl->item(0);
$workflowRootEl = $workflowRootEl->item(0);
$newNode = $dom->importNode($workflowRootEl, TRUE);
$newNode = $dom->importNode($workflowRootEl, TRUE);
$datastream = $dom->createElement("foxml:datastream");
$datastream = $dom->createElement("foxml:datastream");
@ -358,6 +392,12 @@ class ModsFormBuilder extends FormBuilder {
}
}
}
}
/**
* Create mods Stream ??
* @param $form_values
* @param & $dom
* @param & $rootElement
*/
function createModsStream($form_values, & $dom, & $rootElement) {
function createModsStream($form_values, & $dom, & $rootElement) {
$datastream = $dom->createElement("foxml:datastream");
$datastream = $dom->createElement("foxml:datastream");
@ -372,17 +412,21 @@ class ModsFormBuilder extends FormBuilder {
$content = $dom->createElement("foxml:xmlContent");
$content = $dom->createElement("foxml:xmlContent");
$version->appendChild($content);
$version->appendChild($content);
$mods = $this->modsFromForm($form_values,$dom);
$mods = $this->modsFromForm($form_values, $dom);
$content->appendChild($mods);
$content->appendChild($mods);
$rootElement->appendChild($datastream);
$rootElement->appendChild($datastream);
}
}
/**
* Mods From From ?????
* @param type $form_values
* @param type $dom
* @return type
*/
function modsFromForm(& $form_values, & $dom) {
function modsFromForm(& $form_values,& $dom)
///begin writing MODS
{
///begin writing MODS
$mods = $dom->createElement("mods:mods");
$mods = $dom->createElement("mods:mods");
$mods->setAttribute('version', '3.4');
$mods->setAttribute('version', '3.4');
$mods->setAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink");
$mods->setAttribute('xmlns:xlink', "http://www.w3.org/1999/xlink");
@ -393,37 +437,37 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_title']) & & trim($form_values['mods_title']) != '') {
if (isset($form_values['mods_title']) & & trim($form_values['mods_title']) != '') {
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo = $dom->createElement('mods:titleInfo');
$title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_title']));
$title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_title']));
$titleinfo->appendChild($title);
$titleinfo->appendChild($title);
$mods->appendChild($titleinfo);
$mods->appendChild($titleinfo);
}
}
if (isset($form_values['mods_alternative_titles']) & & trim($form_values['mods_alternative_titles']) != '') {
if (isset($form_values['mods_alternative_titles']) & & trim($form_values['mods_alternative_titles']) != '') {
$titles=preg_split('/\s+\;\s+/',trim($form_values['mods_alternative_titles']));
$titles = preg_split('/\s+\;\s+/', trim($form_values['mods_alternative_titles']));
foreach ($titles as $t) {
foreach ($titles as $t) {
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo->setAttribute('type','alternative') ;
$titleinfo->setAttribute('type', 'alternative');
$title = $dom->createElement('mods:title',$t);
$title = $dom->createElement('mods:title', $t);
$titleinfo->appendChild($title);
$titleinfo->appendChild($title);
$mods->appendChild($titleinfo);
$mods->appendChild($titleinfo);
}
}
}
}
if (isset($form_values['mods_alternative_title']) & & trim($form_values['mods_alternative_title']) != '') {
if (isset($form_values['mods_alternative_title']) & & trim($form_values['mods_alternative_title']) != '') {
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo = $dom->createElement('mods:titleInfo');
$titleinfo->setAttribute('type','alternative') ;
$titleinfo->setAttribute('type', 'alternative');
$title = $dom->createElement('mods:title',trim($form_values['mods_alternative_title']));
$title = $dom->createElement('mods:title', trim($form_values['mods_alternative_title']));
$titleinfo->appendChild($title);
$titleinfo->appendChild($title);
$mods->appendChild($titleinfo);
$mods->appendChild($titleinfo);
}
}
if (isset($form_values['mods_description']) & & trim($form_values['mods_description']) != '') {
if (isset($form_values['mods_description']) & & trim($form_values['mods_description']) != '') {
$abstract = $dom->createElement('mods:abstract', htmlspecialchars(trim($form_values['mods_description'])));
$abstract = $dom->createElement('mods:abstract', htmlspecialchars(trim($form_values['mods_description'])));
$mods->appendChild($abstract);
$mods->appendChild($abstract);
}
}
if (isset($form_values['pid']) & & trim($form_values['pid']) != '') {
if (isset($form_values['pid']) & & trim($form_values['pid']) != '') {
$identifier = $dom->createElement('mods:identifier', htmlspecialchars(trim(preg_replace('/\:/','\/',$form_values['pid']))));
$identifier = $dom->createElement('mods:identifier', htmlspecialchars(trim(preg_replace('/\:/', '\/', $form_values['pid']))));
$identifier->setAttribute('type', 'hdl');
$identifier->setAttribute('type', 'hdl');
$mods->appendChild($identifier);
$mods->appendChild($identifier);
}
}
@ -457,7 +501,7 @@ class ModsFormBuilder extends FormBuilder {
$addOriginInfo = FALSE;
$addOriginInfo = FALSE;
if (isset($form_values['mods_pubinfo_place']) & & trim($form_values['mods_pubinfo_place']) != '') {
if (isset($form_values['mods_pubinfo_place']) & & trim($form_values['mods_pubinfo_place']) != '') {
$place = $dom->createElement('mods:place');
$place = $dom->createElement('mods:place');
$placeTerm=$dom->createElement('mods:placeTerm', htmlspecialchars(trim($form_values['mods_pubinfo_place'])));
$placeTerm = $dom->createElement('mods:placeTerm', htmlspecialchars(trim($form_values['mods_pubinfo_place'])));
$placeTerm->setAttribute('type', 'text');
$placeTerm->setAttribute('type', 'text');
$place->appendChild($placeTerm);
$place->appendChild($placeTerm);
$originInfo->appendChild($place);
$originInfo->appendChild($place);
@ -479,52 +523,52 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_pubinfo_date']) & & trim($form_values['mods_pubinfo_date']) != '' & &
if (isset($form_values['mods_pubinfo_date']) & & trim($form_values['mods_pubinfo_date']) != '' & &
isset($form_values['mods_pubinfo_dateType']) & & trim($form_values['mods_pubinfo_dateType']) != '') {
isset($form_values['mods_pubinfo_dateType']) & & trim($form_values['mods_pubinfo_dateType']) != '') {
if (in_array($form_values['mods_pubinfo_dateType'], array('issued', 'created', 'copyright', 'captured'))) {
if (in_array($form_values['mods_pubinfo_dateType'], array('issued', 'created', 'copyright', 'captured'))) {
$date = $dom->createElement('mods:'. trim($form_values['mods_pubinfo_dateType']) .'Date', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
$date = $dom->createElement('mods:' . trim($form_values['mods_pubinfo_dateType']) . 'Date', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
}
}
else {
else {
//how to handle other types? otherDate?
//how to handle other types? otherDate?
$date= $dom->createElement('mods:otherDate', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
$date = $dom->createElement('mods:otherDate', htmlspecialchars(trim($form_values['mods_pubinfo_date'])));
$date->setAttribute('type', htmlspecialchars(trim($form_values['mods_pubinfo_dateType'])));
$date->setAttribute('type', htmlspecialchars(trim($form_values['mods_pubinfo_dateType'])));
}
}
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
} else {
}
else {
if (isset($form_values['mods_createdDate'])) {
if (isset($form_values['mods_createdDate'])) {
$date = $dom->createElement('mods:createdDate',htmlspecialchars(trim($form_values['mods_createdDate'])));
$date = $dom->createElement('mods:createdDate', htmlspecialchars(trim($form_values['mods_createdDate'])));
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
if (isset($form_values['mods_issuedDate'])) {
if (isset($form_values['mods_issuedDate'])) {
$date = $dom->createElement('mods:issuedDate',htmlspecialchars(trim($form_values['mods_issuedDate'])));
$date = $dom->createElement('mods:issuedDate', htmlspecialchars(trim($form_values['mods_issuedDate'])));
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
if (isset($form_values['mods_copyrightDate'])) {
if (isset($form_values['mods_copyrightDate'])) {
$date = $dom->createElement('mods:copyrightDate',htmlspecialchars(trim($form_values['mods_copyrightDate'])));
$date = $dom->createElement('mods:copyrightDate', htmlspecialchars(trim($form_values['mods_copyrightDate'])));
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
if (isset($form_values['mods_capturedDate'])) {
if (isset($form_values['mods_capturedDate'])) {
$date = $dom->createElement('mods:capturedDate',htmlspecialchars(trim($form_values['mods_capturedDate'])));
$date = $dom->createElement('mods:capturedDate', htmlspecialchars(trim($form_values['mods_capturedDate'])));
$originInfo->appendChild($date);
$originInfo->appendChild($date);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
}
}
if (isset($form_values['mods_pubinfo_journalFreq']) & & trim($form_values['mods_pubinfo_journalFreq']) != '') {
if (isset($form_values['mods_pubinfo_journalFreq']) & & trim($form_values['mods_pubinfo_journalFreq']) != '') {
$frequency = $dom->createElement('mods:frequency', htmlspecialchars(trim($form_values['mods_pubinfo_journalFreq'])));
$frequency = $dom->createElement('mods:frequency', htmlspecialchars(trim($form_values['mods_pubinfo_journalFreq'])));
$originInfo->appendChild($frequency);
$originInfo->appendChild($frequency);
$issuance= $dom->createElement('mods:issuance', 'journal');
$issuance = $dom->createElement('mods:issuance', 'journal');
$originInfo->appendChild($issuance);
$originInfo->appendChild($issuance);
$addOriginInfo = TRUE;
$addOriginInfo = TRUE;
}
}
elseif (isset($form_values['mods_pubinfo_journalFreq'])) {
elseif (isset($form_values['mods_pubinfo_journalFreq'])) {
$issuance= $dom->createElement('mods:issuance', 'monographic');
$issuance = $dom->createElement('mods:issuance', 'monographic');
$originInfo->appendChild($issuance);
$originInfo->appendChild($issuance);
}
}
@ -540,7 +584,7 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_caption']) & & trim($form_values['mods_caption']) != '') {
if (isset($form_values['mods_caption']) & & trim($form_values['mods_caption']) != '') {
$note = $dom->createElement('mods:note', htmlspecialchars(trim($form_values['mods_caption'])));
$note = $dom->createElement('mods:note', htmlspecialchars(trim($form_values['mods_caption'])));
$note->setAttribute('type','caption');
$note->setAttribute('type', 'caption');
$mods->appendChild($note);
$mods->appendChild($note);
}
}
@ -550,16 +594,14 @@ class ModsFormBuilder extends FormBuilder {
}
}
if (isset($form_values['mods_language']) & & trim($form_values['mods_language']) != '')
if (isset($form_values['mods_language']) & & trim($form_values['mods_language']) != '') {
{
$languageList = explode(';', htmlspecialchars($form_values['mods_language']));
$languageList = explode(';', htmlspecialchars($form_values['mods_language']));
foreach ($languageList as $lang)
foreach ($languageList as $lang) {
{
$language = $dom->createElement('mods:language');
$language = $dom->createElement('mods:language');
$langTerm = $dom->createElement('mods:languageTerm', htmlspecialchars($lang));
$langTerm = $dom->createElement('mods:languageTerm',htmlspecialchars($lang));
$langTerm->setAttribute('type', 'text');
$langTerm->setAttribute('type','text');
$language->appendChild($langTerm);
$language->appendChild($langTerm);
$mods->appendChild($language);
$mods->appendChild($language);
}
}
}
}
@ -573,7 +615,7 @@ class ModsFormBuilder extends FormBuilder {
$hasSubject = TRUE;
$hasSubject = TRUE;
$geographic = $dom->createElement('mods:hierarchicalGeographic');
$geographic = $dom->createElement('mods:hierarchicalGeographic');
$country=$dom->createElement('mods:country', htmlspecialchars($form_values['mods_country']));
$country = $dom->createElement('mods:country', htmlspecialchars($form_values['mods_country']));
$geographic->appendChild($country);
$geographic->appendChild($country);
if (isset($form_values['mods_province']) & & trim($form_values['mods_province']) != '') {
if (isset($form_values['mods_province']) & & trim($form_values['mods_province']) != '') {
@ -608,7 +650,7 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_subjtitle']) & & trim($form_values['mods_subjtitle']) != '') {
if (isset($form_values['mods_subjtitle']) & & trim($form_values['mods_subjtitle']) != '') {
$hasSubject = TRUE;
$hasSubject = TRUE;
$titleInfo= $dom->createElement('mods:titleInfo');
$titleInfo = $dom->createElement('mods:titleInfo');
$title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_subjtitle']));
$title = $dom->createElement('mods:title', htmlspecialchars($form_values['mods_subjtitle']));
$titleInfo->appendChild($title);
$titleInfo->appendChild($title);
$subject->appendChild($titleInfo);
$subject->appendChild($titleInfo);
@ -633,23 +675,22 @@ class ModsFormBuilder extends FormBuilder {
if (isset($form_values['mods_cc']['cc']) & & $form_values['mods_cc']['cc']['cc_enable']) {
if (isset($form_values['mods_cc']['cc']) & & $form_values['mods_cc']['cc']['cc_enable']) {
$commercial = trim($form_values['mods_cc']['cc']['cc_commercial']);
$commercial = trim($form_values['mods_cc']['cc']['cc_commercial']);
$modifications = trim($form_values['mods_cc']['cc']['cc_modifications']);
$modifications = trim($form_values['mods_cc']['cc']['cc_modifications']);
$jurisdiction = trim($form_values['mods_cc']['cc']['cc_jurisdiction']);
$jurisdiction = trim($form_values['mods_cc']['cc']['cc_jurisdiction']);
module_load_include('inc','islandora_form_elements','includes/creative_commons.inc');
// Include islandora form elements only if needed ??
module_load_include('inc', 'islandora_form_elements', 'includes/creative_commons.inc');
if (!isset(CreativeCommons::$cc_jurisdiction_vals[$jurisdiction]))
if (!isset(CreativeCommons::$cc_jurisdiction_vals[$jurisdiction]))
$jurisdiction= '';
$jurisdiction = '';
$version = CreativeCommons::$cc_versions[$jurisdiction];
$version = CreativeCommons::$cc_versions[$jurisdiction];
$license = 'by'. ($commercial != ''?'-'.$commercial:'') . ($modifications != ''?'-'.$modifications:'') . '/' . $version . '/'.($jurisdiction != ''?$jurisdiction.'/':'') ;
$license = 'by' . ($commercial != '' ? '-' . $commercial : '') . ($modifications != '' ? '-' . $modifications : '') . '/' . $version . '/' . ($jurisdiction != '' ? $jurisdiction . '/' : '');
$accessCondition = $dom->createElement('mods:accessCondition', htmlspecialchars($license));
$accessCondition = $dom->createElement('mods:accessCondition', htmlspecialchars($license));
$accessCondition->setAttribute('type', 'Creative Commons License');
$accessCondition->setAttribute('type', 'Creative Commons License');
$mods->appendChild($accessCondition);
$mods->appendChild($accessCondition);
}
}
if (isset($form_values['mods_rights']) & & trim($form_values['mods_rights']) != '') {
if (isset($form_values['mods_rights']) & & trim($form_values['mods_rights']) != '') {
@ -658,59 +699,59 @@ class ModsFormBuilder extends FormBuilder {
$mods->appendChild($accessCondition);
$mods->appendChild($accessCondition);
}
}
if (isset($form_values['mods_people']) & & isset($form_values['mods_people']['people']) & & is_array($form_values['mods_people']['people']) ) {
if (isset($form_values['mods_people']) & & isset($form_values['mods_people']['people']) & & is_array($form_values['mods_people']['people'])) {
foreach ($form_values['mods_people']['people'] as $key => $val) {
foreach ($form_values['mods_people']['people'] as $key => $val) {
$name = $dom->createElement('mods:name');
$name = $dom->createElement('mods:name');
$appendName=FALSE;
$appendName = FALSE;
if (isset($val['role'])) {
if (isset($val['role'])) {
$role = $dom->createElement('mods:role');
$role = $dom->createElement('mods:role');
$roleTerm = $dom->createElement('mods:roleTerm', htmlspecialchars(trim($val['role'])));
$roleTerm = $dom->createElement('mods:roleTerm', htmlspecialchars(trim($val['role'])));
$roleTerm->setAttribute('type', 'text');
$roleTerm->setAttribute('type', 'text');
$roleTerm->setAttribute('authority', 'marcrelator');
$roleTerm->setAttribute('authority', 'marcrelator');
$role->appendChild($roleTerm);
$role->appendChild($roleTerm);
$name->appendChild($role);
$name->appendChild($role);
}
}
if (isset($val['organization'])) {
if (isset($val['organization'])) {
$name->setAttribute('type', 'organization');
$name->setAttribute('type', 'organization');
if (trim($val['organization']) != '') {
if (trim($val['organization']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['organization'])));
$namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['organization'])));
$name->appendChild($namePart);
$name->appendChild($namePart);
$appendName=TRUE;
$appendName = TRUE;
}
}
}
}
elseif (isset($val['conference'])) {
elseif (isset($val['conference'])) {
$name->setAttribute('type', 'conference');
$name->setAttribute('type', 'conference');
if (trim($val['conference']) != '') {
if (trim($val['conference']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['conference'])));
$namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['conference'])));
$name->appendChild($namePart);
$name->appendChild($namePart);
$appendName=TRUE;
$appendName = TRUE;
}
}
}
}
else {
else {
$name->setAttribute('type', 'personal');
$name->setAttribute('type', 'personal');
if (trim($val['name']) != '') {
if (trim($val['name']) != '') {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['name'])));
$namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['name'])));
$name->appendChild($namePart);
$name->appendChild($namePart);
$appendName=TRUE;
$appendName = TRUE;
}
}
}
}
if (isset($val['date'])) {
if (isset($val['date'])) {
$namePart=$dom->createElement('mods:namePart', htmlspecialchars(trim($val['date'])));
$namePart = $dom->createElement('mods:namePart', htmlspecialchars(trim($val['date'])));
$namePart->setAttribute('type','date');
$namePart->setAttribute('type', 'date');
$name->appendChild($namePart);
$name->appendChild($namePart);
}
}
if ($appendName) {
if ($appendName) {
if (isset($val['subject'])) {
if (isset($val['subject'])) {
$subject->appendChild($name);
$subject->appendChild($name);
$hasSubject=TRUE;
$hasSubject = TRUE;
} else {
}
else {
$mods->appendChild($name);
$mods->appendChild($name);
}
}
}
}
}
}
}
}