/** * 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); } }
/** * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output */ protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) { $jazzeeConfiguration = new \Jazzee\Configuration(); if ($jazzeeConfiguration->getStatus() == 'PRODUCTION') { $output->write('<error>You cannot create a demo in production.</error>' . PHP_EOL); exit; } $programName = $input->getOption('programName') ? $input->getOption('programName') : 'Demo'; $shortName = $input->getOption('shortName') ? $input->getOption('shortName') : 'demo'; $entityManager = $this->getHelper('em')->getEntityManager(); if ($entityManager->getRepository('\\Jazzee\\Entity\\Program')->findBy(array('name' => $programName))) { $output->write("<error>A program named '{$programName}' already exists.</error>" . PHP_EOL); exit; } if ($entityManager->getRepository('\\Jazzee\\Entity\\Program')->findBy(array('shortName' => $shortName))) { $output->write("<error>A program with the shortname '{$shortName}' already exists.</error>" . PHP_EOL); exit; } if (!($cycle = $entityManager->getRepository('\\Jazzee\\Entity\\Cycle')->findOneBy(array('name' => 'demo')))) { $cycle = new \Jazzee\Entity\Cycle(); $cycle->setName('demo'); $cycle->setStart('today'); $cycle->setEnd('next year'); $entityManager->persist($cycle); } $program = new \Jazzee\Entity\Program(); $program->setName($programName); $program->setShortName($shortName); $entityManager->persist($program); $application = new \Jazzee\Entity\Application(); $application->setProgram($program); $application->setCycle($cycle); $application->setWelcome('THIS IS A DEMO APP.'); $application->visible(); $application->setOpen('yesterday'); $application->setClose('next year'); $application->publish(true); $entityManager->persist($application); $StandardPageType = $entityManager->getRepository('\\Jazzee\\Entity\\PageType')->findOneBy(array('class' => '\\Jazzee\\Page\\Standard')); $page = new \Jazzee\Entity\Page(); $page->setTitle('Optional Page'); $page->optional(); $page->setType($StandardPageType); $entityManager->persist($page); $count = 1; foreach ($entityManager->getRepository('\\Jazzee\\Entity\\ElementType')->findAll() as $type) { $element = $this->demoElement($type, $entityManager); $element->setTitle($type->getName()); $element->optional(); $element->setWeight($count); $page->addElement($element); $entityManager->persist($element); $count++; } $applicationPage = new \Jazzee\Entity\ApplicationPage(); $applicationPage->setApplication($application); $applicationPage->setPage($page); $applicationPage->setKind(\Jazzee\Entity\ApplicationPage::APPLICATION); $applicationPage->setWeight(1); $entityManager->persist($applicationPage); $page = new \Jazzee\Entity\Page(); $page->setTitle('Required Page'); $page->setType($StandardPageType); $entityManager->persist($page); $count = 1; foreach ($entityManager->getRepository('\\Jazzee\\Entity\\ElementType')->findAll() as $type) { $element = $this->demoElement($type, $entityManager); $element->setTitle($type->getName()); $element->required(); $element->setWeight($count); $page->addElement($element); $entityManager->persist($element); $count++; } $applicationPage = new \Jazzee\Entity\ApplicationPage(); $applicationPage->setApplication($application); $applicationPage->setPage($page); $applicationPage->setKind(\Jazzee\Entity\ApplicationPage::APPLICATION); $applicationPage->setWeight(2); $entityManager->persist($applicationPage); $entityManager->flush(); $output->write("<info>Demo program {$programName} created successfully.</info>" . PHP_EOL); }
/** * 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; }