Example #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;
 }
 /**
  * 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;
 }
 protected function addPageFromXml(SimpleXMLElement $xml)
 {
     $attributes = $xml->attributes();
     if (!empty($attributes['globalPageUuid'])) {
         $page = $this->_em->getRepository('\\Jazzee\\Entity\\Page')->findOneBy(array('isGlobal' => true, 'uuid' => (string) $attributes['globalPageUuid']));
         if (!$page) {
             $this->addMessage('error', (string) $attributes['title'] . ' page in import references global page with uuid ' . (string) $attributes['globalPageUuid'] . ' but this page does not exist.  You need to import it before importing this application.');
             $this->_em->clear();
             $this->redirectPath('setup/importapplication');
         }
     } else {
         $page = new \Jazzee\Entity\Page();
         $page->setType($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->findOneBy(array('class' => (string) $attributes['class'])));
         $page->setTitle(html_entity_decode((string) $attributes['title']));
         $page->setMin((string) $attributes['min']);
         $page->setMax((string) $attributes['max']);
         if ((string) $attributes['required']) {
             $page->required();
         } else {
             $page->optional();
         }
         if ((string) $attributes['answerStatusDisplay']) {
             $page->showAnswerStatus();
         } else {
             $page->hideAnswerStatus();
         }
         $eattr = $xml->xpath('instructions');
         $page->setInstructions((string) $eattr[0]);
         $eattr = $xml->xpath('leadingText');
         $page->setLeadingText((string) $eattr[0]);
         $eattr = $xml->xpath('trailingText');
         $page->setTrailingText((string) $eattr[0]);
         $page->notGlobal();
         $this->_em->persist($page);
         foreach ($xml->xpath('elements/element') as $elementElement) {
             $attributes = $elementElement->attributes();
             $element = new \Jazzee\Entity\Element();
             $element->setType($this->_em->getRepository('\\Jazzee\\Entity\\ElementType')->findOneBy(array('class' => (string) $attributes['class'])));
             if ((string) $attributes['fixedId']) {
                 $element->setFixedId((string) $attributes['fixedId']);
             }
             $element->setTitle((string) $attributes['title']);
             $element->setName((string) $attributes['name']);
             $element->setMin((string) $attributes['min']);
             $element->setMax((string) $attributes['max']);
             if ((string) $attributes['required']) {
                 $element->required();
             } else {
                 $element->optional();
             }
             $element->setInstructions(html_entity_decode((string) $attributes['instructions']));
             $element->setFormat(html_entity_decode((string) $attributes['format']));
             $element->setWeight((string) $attributes['weight']);
             $page->addElement($element);
             foreach ($elementElement->xpath('listitems/item') as $listElement) {
                 $attributes = $listElement->attributes();
                 $listItem = new \Jazzee\Entity\ElementListItem();
                 $listItem->setValue((string) $listElement);
                 $listItem->setWeight((string) $attributes['weight']);
                 $listItem->setName((string) $attributes['name']);
                 if ((string) $attributes['active']) {
                     $listItem->activate();
                 } else {
                     $listItem->deactivate();
                 }
                 $element->addItem($listItem);
                 $this->_em->persist($listItem);
             }
             $this->_em->persist($element);
         }
         foreach ($xml->xpath('variables/variable') as $element) {
             $var = $page->setVar($element['name'], (string) $element);
             $this->_em->persist($var);
         }
         foreach ($xml->xpath('children/page') as $element) {
             $childPage = $this->addPageFromXml($element);
             $page->addChild($childPage);
         }
     }
     return $page;
 }