示例#1
0
 /**
  * Save data from editing a page
  * @param integer $pageId
  */
 public function actionSavePage($pageId)
 {
     $data = json_decode($this->post['data']);
     switch ($data->status) {
         case 'delete':
             if ($page = $this->_em->getRepository('\\Jazzee\\Entity\\Page')->findOneBy(array('id' => $pageId, 'isGlobal' => true))) {
                 $applicationPages = $this->_em->getRepository('\\Jazzee\\Entity\\ApplicationPage')->findBy(array('page' => $page->getId()));
                 if ($applicationPages) {
                     $this->setLayoutVar('status', 'error');
                     $this->addMessage('error', $page->getTitle() . ' could not be deleted becuase it is part of at least one application');
                 } else {
                     if ($this->_em->getRepository('\\Jazzee\\Entity\\Page')->hasAnswers($page)) {
                         $this->setLayoutVar('status', 'error');
                         $this->addMessage('error', $page->getTitle() . '  could not be deleted becuase it has applicant information associated with it.');
                     } else {
                         $this->addMessage('success', $page->getTitle() . ' deleted');
                         $this->_em->remove($page);
                     }
                 }
             }
             break;
         case 'import':
             $page = new \Jazzee\Entity\Page();
             $page->makeGlobal();
             $page->setType($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->find($data->typeId));
             $page->setUuid($data->uuid);
             $this->savePage($page, $data);
             break;
         case 'new':
         case 'copy':
             $page = new \Jazzee\Entity\Page();
             $page->makeGlobal();
             $page->setType($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->find($data->typeId));
             //create a fake application page to work with so we can run setupNewPage
             $page->getApplicationPageJazzeePage()->setController($this);
             //only do setup for new pages, copies already have elements
             if ($data->status == 'new') {
                 $page->getApplicationPageJazzeePage()->setupNewPage();
             }
             $this->addMessage('success', $data->title . ' created.');
             $this->savePage($page, $data);
             break;
         default:
             $page = $this->_em->getRepository('\\Jazzee\\Entity\\Page')->findOneBy(array('id' => $pageId, 'isGlobal' => true));
             $this->savePage($page, $data);
     }
 }
示例#2
0
 /**
  * Save data from editing a page
  * @param integer $pageId
  */
 public function actionSavePage($pageId)
 {
     $data = json_decode($this->post['data']);
     switch ($data->status) {
         case 'delete':
             if ($applicationPage = $this->_em->getRepository('\\Jazzee\\Entity\\ApplicationPage')->findOneBy(array('page' => $pageId, 'application' => $this->_application->getId()))) {
                 if ($this->_em->getRepository('\\Jazzee\\Entity\\Page')->hasApplicationAnswers($applicationPage->getPage(), $this->_application)) {
                     $this->setLayoutVar('status', 'error');
                     $this->addMessage('error', $applicationPage->getTitle() . ' could not be deleted becuase it has applicant information associated with it.');
                 } else {
                     if (!$applicationPage->getPage()->isGlobal()) {
                         $this->_em->remove($applicationPage->getPage());
                     }
                     $this->_em->remove($applicationPage);
                     $this->addMessage('success', $applicationPage->getTitle() . ' deleted');
                 }
             }
             break;
         case 'new-global':
             $applicationPage = new \Jazzee\Entity\ApplicationPage();
             $applicationPage->setPage($this->_em->getRepository('\\Jazzee\\Entity\\Page')->findOneBy(array('id' => $pageId, 'isGlobal' => true)));
             $applicationPage->setKind($data->kind);
             $applicationPage->setApplication($this->_application);
             $applicationPage->setWeight($data->weight);
             $applicationPage->setTitle($data->title);
             $applicationPage->setMin($data->min);
             $applicationPage->setMax($data->max);
             if ($data->isRequired) {
                 $applicationPage->required();
             } else {
                 $applicationPage->optional();
             }
             $applicationPage->setInstructions($data->instructions);
             $applicationPage->setLeadingText($data->leadingText);
             $applicationPage->setTrailingText($data->trailingText);
             $this->_em->persist($applicationPage);
             $this->addMessage('success', $data->title . ' created.');
             break;
         case 'new':
         case 'copy':
             $page = new \Jazzee\Entity\Page();
             $page->notGlobal();
             $page->setType($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->find($data->typeId));
             $this->_em->persist($page);
             $applicationPage = new \Jazzee\Entity\ApplicationPage();
             $applicationPage->setPage($page);
             $applicationPage->setKind($data->kind);
             $applicationPage->setWeight($data->weight);
             $applicationPage->setApplication($this->_application);
             $applicationPage->getJazzeePage()->setController($this);
             //only do setup for new pages, copies lready ahve elements
             if ($data->status == 'new') {
                 $applicationPage->getJazzeePage()->setupNewPage();
             }
             $this->addMessage('success', $data->title . ' created.');
         default:
             if (!isset($applicationPage)) {
                 $applicationPage = $this->_em->getRepository('\\Jazzee\\Entity\\ApplicationPage')->findOneBy(array('page' => $pageId, 'application' => $this->_application->getId()));
             }
             $this->savePage($applicationPage, $data);
     }
 }
示例#3
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);
     }
 }
示例#4
0
 /**
  * @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);
 }
 /**
  * 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;
 }
示例#6
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;
 }
示例#7
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;
 }
示例#8
0
 /**
  * Save a page
  * @param \Jazzee\Entity\Page $page
  */
 public function savePage($page, $data)
 {
     $htmlPurifier = $this->getFilter();
     $page->setTitle($htmlPurifier->purify($data->title));
     $page->setMin(empty($data->min) ? null : $data->min);
     $page->setMax(empty($data->max) ? null : $data->max);
     if ($data->isRequired) {
         $page->required();
     } else {
         $page->optional();
     }
     $page->hideAnswerStatus();
     if ($data->answerStatusDisplay) {
         if ($page instanceof \Jazzee\Entity\ApplicationPage) {
             $interfaces = class_implements($page->getPage()->getType()->getClass());
         } else {
             $interfaces = class_implements($page->getType()->getClass());
         }
         if (in_array('Jazzee\\Interfaces\\StatusPage', $interfaces)) {
             $page->showAnswerStatus();
         }
     }
     $page->setInstructions(empty($data->instructions) ? null : $htmlPurifier->purify($data->instructions));
     $page->setLeadingText(empty($data->leadingText) ? null : $htmlPurifier->purify($data->leadingText));
     $page->setTrailingText(empty($data->trailingText) ? null : $htmlPurifier->purify($data->trailingText));
     $this->_em->persist($page);
     if ($page instanceof \Jazzee\Entity\ApplicationPage) {
         $page->setWeight($data->weight);
         $page->setName($data->name);
         //if this is a global page then we are done
         //programs can't edit any of the remaining properties on a globa page
         if ($page->getPage()->isGlobal()) {
             $this->addMessage('success', $page->getTitle() . ' page saved.');
             return;
         }
         //otherwise continue making changes by swaping the $page varialbe for the correct \Jazzee\Entity\Page class
         $page = $page->getPage();
     }
     $page->setFixedId(empty($data->fixedId) ? null : $data->fixedId);
     foreach ($data->variables as $v) {
         $jazzeePage = $page->getApplicationPageJazzeePage();
         $jazzeePage->setController($this);
         $jazzeePage->setVar($v->name, $v->value);
     }
     $this->savePageElements($page, $data->elements);
     foreach ($data->children as $child) {
         switch ($child->status) {
             case 'delete':
                 $childPage = $page->getChildById($child->id);
                 if ($childPage) {
                     $this->log(" ==> about to delete child");
                     $this->_em->remove($childPage);
                     $page->getChildren()->removeElement($childPage);
                     $this->addMessage('success', $childPage->getTitle() . ' page deleted.');
                 } else {
                     $this->log("EntityManager is not aware of child page, skipping delete");
                 }
                 break;
             case 'import':
                 $childPage = new \Jazzee\Entity\Page();
                 $childPage->setParent($page);
                 $childPage->notGlobal();
                 $childPage->setType($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->find($child->typeId));
                 $childPage->setUuid($child->uuid);
                 $this->savePage($childPage, $child);
                 break;
             case 'new':
             case 'copy':
                 $childPage = new \Jazzee\Entity\Page();
                 $childPage->setParent($page);
                 $childPage->notGlobal();
                 $childPage->setType($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->find($child->typeId));
                 $this->savePage($childPage, $child);
                 break;
             default:
                 $childPage = $page->getChildById($child->id);
                 $this->savePage($childPage, $child);
                 break;
         }
         unset($childPage);
     }
     $this->addMessage('success', $page->getTitle() . ' page saved.');
 }