Exemplo n.º 1
0
 /**
  * Create the school choice form
  */
 public function setupNewPage()
 {
     $entityManager = $this->_controller->getEntityManager();
     $types = $entityManager->getRepository('Jazzee\\Entity\\ElementType')->findAll();
     $elementTypes = array();
     foreach ($types as $type) {
         $elementTypes[$type->getClass()] = $type;
     }
     $standardPageType = $entityManager->getRepository('\\Jazzee\\Entity\\PageType')->findOneBy(array('class' => '\\Jazzee\\Page\\Standard'));
     $newSchool = new \Jazzee\Entity\Page();
     $newSchool->setType($standardPageType);
     $newSchool->setFixedId(self::PAGE_FID_NEWSCHOOL);
     $newSchool->setTitle('New School');
     $this->_applicationPage->getPage()->addChild($newSchool);
     $entityManager->persist($newSchool);
     $elements = array(array('fid' => self::ELEMENT_FID_NAME, 'title' => 'School Name', 'max' => 255, 'required' => true), array('fid' => self::ELEMENT_FID_CITY, 'title' => 'City', 'max' => 64, 'required' => true), array('fid' => self::ELEMENT_FID_STATE, 'title' => 'State or Province', 'max' => 64, 'required' => false), array('fid' => self::ELEMENT_FID_COUNTRY, 'title' => 'Country', 'max' => 64, 'required' => true), array('fid' => self::ELEMENT_FID_POSTALCODE, 'title' => 'Postal Code', 'max' => 10, 'required' => false));
     $count = 1;
     foreach ($elements as $arr) {
         $element = new \Jazzee\Entity\Element();
         $element->setType($elementTypes['\\Jazzee\\Element\\TextInput']);
         $element->setTitle($arr['title']);
         if ($arr['required']) {
             $element->required();
         } else {
             $element->optional();
         }
         $element->setWeight($count++);
         $element->setMax($arr['max']);
         $element->setFixedId($arr['fid']);
         $newSchool->addElement($element);
         $entityManager->persist($element);
     }
     $defaultVars = array('schoolListType' => 'full', 'partialSchoolList' => '');
     foreach ($defaultVars as $name => $value) {
         $var = $this->_applicationPage->getPage()->setVar($name, $value);
         $entityManager->persist($var);
     }
 }
Exemplo n.º 2
0
 /**
  * Create a demo element
  * @param \Jazzee\Entity\ElementType $type
  * $param \Doctrine\ORM\EntityManager $entityManager
  * @return \Jazzee\Entity\Element
  */
 protected function demoElement(\Jazzee\Entity\ElementType $type, \Doctrine\ORM\EntityManager $entityManager)
 {
     $element = new \Jazzee\Entity\Element();
     $element->setType($type);
     switch ($type->getClass()) {
         case '\\Jazzee\\Element\\CheckboxList':
         case '\\Jazzee\\Element\\RadioList':
         case '\\Jazzee\\Element\\SelectList':
             for ($i = 1; $i <= rand(5, 15); $i++) {
                 $item = new \Jazzee\Entity\ElementListItem();
                 $item->setWeight($i);
                 $item->activate();
                 $item->setValue(\Foundation\Utility::ordinalValue($i) . ' item');
                 $entityManager->persist($item);
                 $element->addItem($item);
             }
             break;
         case '\\Jazzee\\Element\\RankingList':
             for ($i = 1; $i <= rand(5, 15); $i++) {
                 $item = new \Jazzee\Entity\ElementListItem();
                 $item->setWeight($i);
                 $item->activate();
                 $item->setValue(\Foundation\Utility::ordinalValue($i) . ' item');
                 $entityManager->persist($item);
                 $element->addItem($item);
             }
             $element->setMin(1);
             $element->setMax(4);
             break;
         case '\\Jazzee\\Element\\Textarea':
             $element->setMax(500);
             break;
     }
     return $element;
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 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;
 }