コード例 #1
0
 /**
  * Add a new page
  *
  * Do this in a deperate funciton so it can call itself
  * @param \Jazzee\Entity\Page $previousPage
  * @return \Jazzee\Entity\Page
  */
 protected function addPage(\Jazzee\Entity\Page $previousPage)
 {
     if ($previousPage->isGlobal()) {
         $page = $previousPage;
     } else {
         $page = new \Jazzee\Entity\Page();
         $page->setType($previousPage->getType());
         $page->setTitle($previousPage->getTitle());
         $page->setMin($previousPage->getMin());
         $page->setMax($previousPage->getMax());
         if ($previousPage->isRequired()) {
             $page->required();
         } else {
             $page->optional();
         }
         if ($previousPage->answerStatusDisplay()) {
             $page->showAnswerStatus();
         } else {
             $page->hideAnswerStatus();
         }
         $page->setInstructions($previousPage->getInstructions());
         $page->setLeadingText($previousPage->getLeadingText());
         $page->setTrailingText($previousPage->getTrailingText());
         $page->notGlobal();
         $this->_em->persist($page);
         foreach ($previousPage->getElements() as $previousElement) {
             $element = new \Jazzee\Entity\Element();
             $element->setType($previousElement->getType());
             $element->setFixedId($previousElement->getFixedId());
             $element->setTitle($previousElement->getTitle());
             $element->setMin($previousElement->getMin());
             $element->setMax($previousElement->getMax());
             $element->setName($previousElement->getName());
             if ($previousElement->isRequired()) {
                 $element->required();
             } else {
                 $element->optional();
             }
             $element->setInstructions($previousElement->getInstructions());
             $element->setFormat($previousElement->getFormat());
             $element->setWeight($previousElement->getWeight());
             $page->addElement($element);
             foreach ($previousElement->getListItems() as $previousItem) {
                 $listItem = new \Jazzee\Entity\ElementListItem();
                 $listItem->setValue($previousItem->getValue());
                 $listItem->setWeight($previousItem->getWeight());
                 $listItem->setName($previousItem->getName());
                 if ($previousItem->isActive()) {
                     $listItem->activate();
                 } else {
                     $listItem->deactivate();
                 }
                 $element->addItem($listItem);
                 $this->_em->persist($listItem);
             }
             $this->_em->persist($element);
         }
         foreach ($previousPage->getVariables() as $previousVar) {
             $var = $page->setVar($previousVar->getName(), $previousVar->getValue());
             $this->_em->persist($var);
         }
         foreach ($previousPage->getChildren() as $previousChild) {
             $childPage = $this->addPage($previousChild);
             $page->addChild($childPage);
         }
     }
     return $page;
 }
コード例 #2
0
 /**
  * Copy a Page
  * @param \Doctrine\ORM\EntityManager $em
  * @param \Jazzee\Entity\Page $page
  * @return \Jazzee\Entity\Page
  */
 public function copyPage(\Doctrine\ORM\EntityManager $em, \Jazzee\Entity\Page $page)
 {
     $newPage = new \Jazzee\Entity\Page();
     $newPage->setTitle($page->getTitle());
     $newPage->setMax($page->getMax());
     $newPage->setInstructions($page->getInstructions());
     $newPage->setLeadingText($page->getLeadingText());
     $newPage->setTrailingText($page->getTrailingText());
     $newPage->setFixedId($page->getFixedId());
     $newPage->setType($em->getRepository('\\Jazzee\\Entity\\PageType')->findOneByClass($page->getType()->getClass()));
     if ($page->isGlobal()) {
         $newPage->makeGlobal();
     } else {
         $newPage->notGlobal();
     }
     if ($page->isRequired()) {
         $newPage->required();
     } else {
         $newPage->optional();
     }
     foreach ($page->getChildren() as $child) {
         $newPage->addChild($this->copyPage($em, $child));
     }
     foreach ($page->getVariables() as $variable) {
         $newPage->setVar($variable->getName(), $variable->getValue());
     }
     foreach ($newPage->getVariables() as $variable) {
         $em->persist($variable);
     }
     foreach ($page->getElements() as $element) {
         $newElement = new \Jazzee\Entity\Element();
         $newElement->setType($em->getRepository('\\Jazzee\\Entity\\ElementType')->findOneByClass($element->getType()->getClass()));
         $newElement->setWeight($element->getWeight());
         $newElement->setFixedId($element->getFixedId());
         $newElement->setTitle($element->getTitle());
         $newElement->setMax($element->getMax());
         $newElement->setMin($element->getMin());
         $newElement->setInstructions($element->getInstructions());
         $newElement->setDefaultValue($element->getDefaultValue());
         $newElement->setFormat($element->getFormat());
         if ($element->isRequired()) {
             $newElement->required();
         } else {
             $newElement->optional();
         }
         foreach ($element->getListItems() as $item) {
             $newItem = new \Jazzee\Entity\ElementListItem();
             $newItem->setValue($item->getValue());
             $newItem->setWeight($item->getWeight());
             $newElement->addItem($newItem);
             $em->persist($newItem);
         }
         $em->persist($newElement);
         $newPage->addElement($newElement);
     }
     $em->persist($newPage);
     return $newPage;
 }
コード例 #3
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;
 }