Browse Source

Latest changes to the content model for islandora_form_builder_support.

pull/105/head
Nigel Banks 14 years ago
parent
commit
142335ef39
  1. 41
      ContentModel.inc
  2. 4
      islandoracm.xsd

41
ContentModel.inc

@ -2056,33 +2056,48 @@ class ContentModel extends XMLDatastream {
/** /**
* Adds the named form. * Adds the named form.
* *
* @param string $name * @param string $element
* Name of the form to add. * Name of the form to add.
* *
* @return boolean * @return boolean
* TRUE on success, FALSE otherwise. * TRUE on success, FALSE otherwise.
*/ */
public function addForm($name) { public function addForm($element) {
$result = $this->xpath->query("//cm:form[@name='$name']");
if ($result->length != 0) {
return FALSE; // Already Exists.
}
$result = $this->xpath->query("//cm:forms"); $result = $this->xpath->query("//cm:forms");
if ($result->length == 0) { // Forms doesn't exist if ($result->length == 0) { // Forms doesn't exist
$forms = $this->xml->createElement('forms'); $forms = $this->xml->createElement('forms');
$form = $this->xml->createElement('form'); $element = $this->xml->importNode($element);
$form->setAttribute('name', $name); $forms->appendChild($element);
$forms->appendChild($form);
$result = $this->xpath->query("//cm:content_model"); $result = $this->xpath->query("//cm:content_model");
$result->item(0)->appendChild($forms); $result->item(0)->appendChild($forms);
return TRUE; return TRUE;
} }
else { // Forms exists just create form. else if ($result->length == 1) {
$form = $this->xml->createElement($name); $element = $this->xml->importNode($element);
$form->setAttribute('name', $name); $result->item(0)->appendChild($element);
$result->item(0)->appendChild($form);
return TRUE; return TRUE;
} }
return FALSE;
}
/**
* Edits a form element with attribute name='$name' from the 'forms' element.
*
* @param String $name
*/
public function editForm($name, $element) {
if (!$this->validate()) {
return FALSE;
}
$result = $this->xpath->query("//cm:form[@name='$name']");
if($result->length == 1) {
$element = $this->xml->importNode($element);
$form = $result->item(0);
$form->parentNode->replaceChild($element, $form);
return TRUE;
}
return FALSE;
} }
/** /**

4
islandoracm.xsd

@ -182,6 +182,10 @@
<xsd:complexContent> <xsd:complexContent>
<xsd:extension base="formElementType"> <xsd:extension base="formElementType">
<xsd:attribute name="name" type="xsd:normalizedString" use="required"/> <xsd:attribute name="name" type="xsd:normalizedString" use="required"/>
<xsd:attribute name="module" type="xsd:normalizedString" use="required"/>
<xsd:attribute name="file" type="xsd:normalizedString" use="required"/>
<xsd:attribute name="class" type="xsd:normalizedString" use="required"/>
<xsd:attribute name="dsid" type="xsd:normalizedString" use="required"/>
</xsd:extension> </xsd:extension>
</xsd:complexContent> </xsd:complexContent>
</xsd:complexType> </xsd:complexType>

Loading…
Cancel
Save