Browse Source

Fixes for editing

pull/3/merge
Nigel Banks 14 years ago
parent
commit
f6436d4832
  1. 9
      fedora_repository.module
  2. 102
      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');

102
formClass.inc

@ -716,89 +716,30 @@ 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.
$content_model = ContentModel::loadFromObject($pid);
$form_names = islandora_content_model_get_form_names($content_model->pid);
}
$form_state['storage']['xml'] = false;
if (isset($form_state['storage']['step']) || (isset($form_names) && count($form_names) > 0)) {
// Form Exists...
$form_state['storage']['step'] = isset($form_state['storage']['step']) ? $form_state['storage']['step'] : 1;
switch ($form_state['storage']['step']) {
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 { try {
$object = $client->__soapCAll('getDatastreamDissemination', array('parameters' => $params)); $params = array('pid' => "$pid", 'dsID' => "$dsid", 'asOfDateTime' => "");
} catch (Exception $e) { $object = $client->__soapCall('getDatastreamDissemination', array('parameters' => $params));
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 {
if (!isset($dsId)) {
$dsId = 'QDC';
}
//$client = getSoapClient(variable_get('fedora_soap_url', 'http://localhost:8080/fedora/services/access?wsdl'));
$params = array('pid' => "$pid", 'dsID' => "$dsId", 'asOfDateTime' => "");
try {
$object = $client->__soapCAll('getDatastreamDissemination', array('parameters' => $params));
} catch (Exception $e) { } catch (Exception $e) {
return array(); return array();
} }
$content = $object->dissemination->stream; $content = $object->dissemination->stream;
$content = trim($content); $content = trim($content);
$doc = new DOMDocument(); $doc = new DOMDocument();
if (!$doc->loadXML($content)) { if (!$doc->loadXML($content)) {
echo "error loading xml"; echo "error loading xml";
} }
$oai_dc = $doc->getElementsByTagName('dc'); $oai_dc = $doc->getElementsByTagName('dc');
$dcItems = $oai_dc->item(0)->getElementsByTagName('*'); $dcItems = $oai_dc->item(0)->getElementsByTagName('*');
$form = array(); $form = array();
for ($i = 0; $i < $dcItems->length; $i++) { for ($i = 0; $i < $dcItems->length; $i++) {
@ -849,22 +790,35 @@ class formClass {
} }
} }
} }
$form['pid'] = array( $form['pid'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => "$pid" '#value' => "$pid"
); );
$form['dsid'] = array( $form['dsid'] = array(
'#type' => 'hidden', '#type' => 'hidden',
'#value' => "$dsId" '#value' => "$dsid"
); );
$form['submit'] = array( $form['submit'] = array(
'#type' => 'submit', '#type' => 'submit',
'#value' => t('Update Metadata'), '#value' => t('Update Metadata'),
); );
return $form; return $form;
} }
/**
* Creates a drupal form to edit either the QDC or DC datastream
*/
function createMetaDataForm($pid, $dsid, $client, &$form_state) {
if (module_exists('islandora_content_model_forms')) {
module_load_include('inc', 'islandora_content_model_forms', 'EditObjectMetadataForm');
try {
$form = new EditObjectMetadataForm($form_state);
return $form->create($pid, $client, $form_state);
} catch (Exception $e) {
$form_state['storage']['xml'] = false; // An error occured revert back to the QDC Form.
}
}
return $this->createQDCEditForm($pid, $dsid, $client, $form_state);
} }
/** /**

Loading…
Cancel
Save