Browse Source

Fixes for editing

pull/3/merge
Nigel Banks 14 years ago
parent
commit
f6436d4832
  1. 9
      fedora_repository.module
  2. 220
      formClass.inc

9
fedora_repository.module

@ -639,12 +639,9 @@ function fedora_repository_edit_qdc_form_validate($form, &$form_state) {
*/ */
function fedora_repository_edit_qdc_form_submit($form, &$form_state) { function fedora_repository_edit_qdc_form_submit($form, &$form_state) {
if ($form_state['storage']['xml']) { if ($form_state['storage']['xml']) {
module_load_include('inc', 'xml_form_api', 'XMLForm'); module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm');
$xml_form = new XMLForm($form_state); $xml_form = new EditObjectMetadataForm($form_state);
$doc = $xml_form->submit($form, $form_state); $xml_form->submit($form, $form_state);
$document = $doc->document;
dom_document_pretty_print($document);
exit();
} }
else { else {
module_load_include('inc', 'fedora_repository', 'ConnectionHelper'); module_load_include('inc', 'fedora_repository', 'ConnectionHelper');

220
formClass.inc

@ -512,7 +512,7 @@ class formClass {
'#type' => 'select', '#type' => 'select',
'#title' => t('Content models available'), '#title' => t('Content models available'),
'#options' => $potential_models, '#options' => $potential_models,
'#default_value' => $selected_model, '#default_value' => $selected_model,
'#description' => t('Content models define datastream composition, relationships between this and other content models, and the mandatory behaviors associated with each digital object.<br /> Additional information may be found <a href="https://wiki.duraspace.org/display/FEDORACREATE/Content+Models+Overview">here.</a> '), '#description' => t('Content models define datastream composition, relationships between this and other content models, and the mandatory behaviors associated with each digital object.<br /> Additional information may be found <a href="https://wiki.duraspace.org/display/FEDORACREATE/Content+Models+Overview">here.</a> '),
), ),
), ),
@ -716,155 +716,109 @@ class formClass {
} }
/** /**
* Creates a drupal form to edit either the QDC or DC datastream * Create edit form.
*
* @param string $pid
* @param string $dsid
* @param object $client
* @param array $form_state
*
* @return string
*/ */
function createMetaDataForm($pid, $dsId = NULL, $client, &$form_state) { function createQDCEditForm($pid, $dsid, $client, &$form_state) {
if (module_exists('islandora_content_model_forms')) { $dsid = empty($dsid) ? 'QDC' : $dsid;
// Get the content model. try {
$content_model = ContentModel::loadFromObject($pid); $params = array('pid' => "$pid", 'dsID' => "$dsid", 'asOfDateTime' => "");
$form_names = islandora_content_model_get_form_names($content_model->pid); $object = $client->__soapCall('getDatastreamDissemination', array('parameters' => $params));
} catch (Exception $e) {
return array();
} }
$form_state['storage']['xml'] = false; $content = $object->dissemination->stream;
if (isset($form_state['storage']['step']) || (isset($form_names) && count($form_names) > 0)) { $content = trim($content);
// Form Exists... $doc = new DOMDocument();
$form_state['storage']['step'] = isset($form_state['storage']['step']) ? $form_state['storage']['step'] : 1; if (!$doc->loadXML($content)) {
switch ($form_state['storage']['step']) { echo "error loading xml";
case 1:
$form['indicator'] = array(
'#type' => 'fieldset',
'#title' => t('Choose edit form.')
);
$form['indicator']['forms'] = array(
'#type' => 'select',
'#title' => t('Forms'),
'#options' => $form_names,
'#description' => t('Select the form to populate the metadata of the new object.')
);
$form['submit'] = array(
'#type' => 'submit',
'#submit' => array('fedora_repository_edit_qdc_form_submit'),
'#value' => 'Next'
);
return $form;
case 2:
// XML Forms
module_load_include('inc', 'xml_form_api', 'XMLForm');
$xml_form = new XMLForm($form_state);
if (isset($form_state['values']['forms']) || $xml_form->isInitialized()) {
if (!$xml_form->isInitialized()) {
module_load_include('inc', 'xml_form_api', 'XMLFormDefinition');
module_load_include('inc', 'xml_form_builder', 'FormBuilder');
$form_name = $form_state['values']['forms'];
$definition = FormBuilder::GetFormDefinition($form_name);
$form = XMLFormDefinition::GetDrupalForm($definition);
$properties = XMLFormDefinition::GetFormProperties($definition);
// XML
$dsid = islandora_content_model_get_dsid($content_model->pid, $form_name);
$params = array('pid' => "$pid", 'dsID' => "$dsid", 'asOfDateTime' => "");
try {
$object = $client->__soapCAll('getDatastreamDissemination', array('parameters' => $params));
} catch (Exception $e) {
return array(); // Empty form?
}
$xml = $object->dissemination->stream;
$xml = trim($xml);
// XML
$document = new XMLDocument($properties['document']['root'], $properties['document']['namespaces'], $properties['document']['schema'], $xml);
$xml_form->initialize($form, $document);
}
$form_state['storage']['xml'] = true;
return $xml_form->toArray();
}
break;
}
} }
else { $oai_dc = $doc->getElementsByTagName('dc');
if (!isset($dsId)) { $dcItems = $oai_dc->item(0)->getElementsByTagName('*');
$dsId = 'QDC'; $form = array();
} for ($i = 0; $i < $dcItems->length; $i++) {
//$client = getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl')); $name = $dcItems->item($i)->nodeName;
$params = array('pid' => "$pid", 'dsID' => "$dsId", 'asOfDateTime' => ""); if ($name == 'dc:description') {
try { $form["$name" . '-' . "$i"] = array(
$object = $client->__soapCAll('getDatastreamDissemination', array('parameters' => $params)); '#title' => $name,
} catch (Exception $e) { '#type' => 'textarea',
return array(); '#default_value' => $dcItems->item($i)->nodeValue,
'#description' => 'Dublin Core ' . substr($dcItems->item($i)->nodeName, 3)
);
} }
elseif ($name == 'dc:title') {
$content = $object->dissemination->stream; $form["$name" . '-' . "$i"] = array(
$content = trim($content); '#title' => $name,
$doc = new DOMDocument(); '#type' => 'textfield',
if (!$doc->loadXML($content)) { '#required' => 'TRUE',
echo "error loading xml"; '#default_value' => $dcItems->item($i)->nodeValue,
'#description' => 'Dublin Core ' . substr($dcItems->item($i)->nodeName, 3)
);
} }
else {
$oai_dc = $doc->getElementsByTagName('dc'); if ($oai_dc->item(0)->nodeName != $dcItems->item($i)->parentNode->nodeName) {
$description = strstr($name, ':');
$dcItems = $oai_dc->item(0)->getElementsByTagName('*'); $form['app_' . "$name" . '-' . "$i"] = array(
$form = array();
for ($i = 0; $i < $dcItems->length; $i++) {
$name = $dcItems->item($i)->nodeName;
if ($name == 'dc:description') {
$form["$name" . '-' . "$i"] = array(
'#title' => $name,
'#type' => 'textarea',
'#default_value' => $dcItems->item($i)->nodeValue,
'#description' => 'Dublin Core ' . substr($dcItems->item($i)->nodeName, 3)
);
}
elseif ($name == 'dc:title') {
$form["$name" . '-' . "$i"] = array(
'#title' => $name, '#title' => $name,
'#type' => 'textfield', '#type' => 'textfield',
'#required' => 'TRUE',
'#default_value' => $dcItems->item($i)->nodeValue, '#default_value' => $dcItems->item($i)->nodeValue,
'#description' => 'Dublin Core ' . substr($dcItems->item($i)->nodeName, 3) '#description' => 'Dublin Core ' . substr($description, 1)
); );
} }
else { else {
if ($oai_dc->item(0)->nodeName != $dcItems->item($i)->parentNode->nodeName) { $field_type = 'textfield';
$description = strstr($name, ':'); $value = $dcItems->item($i)->nodeValue;
$form['app_' . "$name" . '-' . "$i"] = array( if ($name == 'dc:coverage') {
'#title' => $name, $value = '';
'#type' => 'textfield',
'#default_value' => $dcItems->item($i)->nodeValue,
'#description' => 'Dublin Core ' . substr($description, 1)
);
} }
else { if ($name == 'dc:rights') {
$field_type = 'textfield'; $field_type = 'textarea';
$value = $dcItems->item($i)->nodeValue;
if ($name == 'dc:coverage') {
$value = '';
}
if ($name == 'dc:rights') {
$field_type = 'textarea';
}
$description = strstr($name, ':');
$form["$name" . '-' . "$i"] = array(
'#title' => $name,
'#type' => $field_type,
'#default_value' => $value,
'#description' => 'Dublin Core ' . substr($description, 1)
);
} }
$description = strstr($name, ':');
$form["$name" . '-' . "$i"] = array(
'#title' => $name,
'#type' => $field_type,
'#default_value' => $value,
'#description' => 'Dublin Core ' . substr($description, 1)
);
} }
} }
}
$form['pid'] = array(
'#type' => 'hidden',
'#value' => "$pid"
);
$form['dsid'] = array(
'#type' => 'hidden',
'#value' => "$dsid"
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Update Metadata'),
);
return $form;
}
$form['pid'] = array( /**
'#type' => 'hidden', * Creates a drupal form to edit either the QDC or DC datastream
'#value' => "$pid" */
); function createMetaDataForm($pid, $dsid, $client, &$form_state) {
$form['dsid'] = array( if (module_exists('islandora_content_model_forms')) {
'#type' => 'hidden', module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm');
'#value' => "$dsId" try {
); $form = new EditObjectMetadataForm($form_state);
$form['submit'] = array( return $form->create($pid, $client, $form_state);
'#type' => 'submit', } catch (Exception $e) {
'#value' => t('Update Metadata'), $form_state['storage']['xml'] = false; // An error occured revert back to the QDC Form.
); }
return $form;
} }
return $this->createQDCEditForm($pid, $dsid, $client, $form_state);
} }
/** /**

Loading…
Cancel
Save