예제 #1
0
 /**
  * Create an xml node for a page
  *
  * Calls itself recursivly to capture all children
  * @param DomDocument $xml
  * @param \Jazzee\Entity\Page $page
  */
 public function pageXml(DOMDocument $dom, $page)
 {
     $pxml = $dom->createElement('page');
     $pxml->setAttribute('title', htmlentities($page->getTitle(), ENT_COMPAT, 'utf-8'));
     $pxml->setAttribute('min', $page->getMin());
     $pxml->setAttribute('max', $page->getMax());
     $pxml->setAttribute('required', $page->isRequired());
     $pxml->setAttribute('answerStatusDisplay', $page->answerStatusDisplay());
     $pxml->appendChild($this->createCdataElement($dom, 'instructions', $page->getInstructions()));
     $pxml->appendChild($this->createCdataElement($dom, 'leadingText', $page->getLeadingText()));
     $pxml->appendChild($this->createCdataElement($dom, 'trailingText', $page->getTrailingText()));
     if ($page instanceof \Jazzee\Entity\ApplicationPage) {
         $pxml->setAttribute('weight', $page->getWeight());
         $pxml->setAttribute('kind', $page->getKind());
         $pxml->setAttribute('name', $page->getName());
         $page = $page->getPage();
         if ($page->isGlobal()) {
             $pxml->setAttribute('globalPageUuid', $page->getUuid());
         }
     }
     $pxml->setAttribute('class', $page->getType()->getClass());
     $elements = $pxml->appendChild($dom->createElement('elements'));
     foreach ($page->getElements() as $element) {
         $exml = $dom->createElement('element');
         $exml->setAttribute('title', $element->getTitle());
         $exml->setAttribute('name', $element->getName());
         $exml->setAttribute('class', $element->getType()->getClass());
         $exml->setAttribute('fixedId', $element->getFixedId());
         $exml->setAttribute('weight', $element->getWeight());
         $exml->setAttribute('min', $element->getMin());
         $exml->setAttribute('max', $element->getMax());
         $exml->setAttribute('required', $element->isRequired());
         $exml->setAttribute('instructions', htmlentities($element->getInstructions(), ENT_COMPAT, 'utf-8'));
         $exml->setAttribute('format', htmlentities($element->getFormat(), ENT_COMPAT, 'utf-8'));
         $exml->setAttribute('defaultValue', $element->getDefaultValue());
         $listItems = $exml->appendChild($dom->createElement('listitems'));
         foreach ($element->getListItems() as $item) {
             //only export active items
             if ($item->isActive()) {
                 $ixml = $this->createCdataElement($dom, 'item', $item->getValue());
                 $ixml->setAttribute('active', (int) $item->isActive());
                 $ixml->setAttribute('weight', $item->getWeight());
                 $ixml->setAttribute('name', $item->getName());
                 $listItems->appendChild($ixml);
                 unset($ixml);
             }
         }
         $elements->appendChild($exml);
     }
     $children = $pxml->appendChild($dom->createElement('children'));
     foreach ($page->getChildren() as $child) {
         $children->appendChild($this->pageXml($dom, $child));
     }
     $variables = $pxml->appendChild($dom->createElement('variables'));
     foreach ($page->getVariables() as $var) {
         $variable = $dom->createElement('variable', (string) $var->getValue());
         $variable->setAttribute('name', $var->getName());
         $variables->appendChild($variable);
     }
     return $pxml;
 }