예제 #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 ($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);
     }
 }
예제 #2
0
 /**
  * Create a generic page to use in a preview
  * @param \Jazzee\Entity\Page $page
  * @param stdClass $data
  */
 protected function genericPage(\Jazzee\Entity\Page $page, \stdClass $data)
 {
     $page->tempId();
     $page->notGlobal();
     $page->setType($this->_em->getRepository('\\Jazzee\\Entity\\PageType')->find($data->typeId));
     //create a temporary application page so we can access the JazzeePage and do setup
     if ($data->status == 'new') {
         $applicationPage = new \Jazzee\Entity\ApplicationPage();
         $applicationPage->setPage($page);
         $applicationPage->getJazzeePage()->setController($this);
         $applicationPage->getJazzeePage()->setupNewPage();
         unset($applicationPage);
         //give any created elements a temporary id so they will display in the form
         foreach ($page->getElements() as $element) {
             $element->tempId();
             foreach ($element->getListItems() as $item) {
                 $item->tempId();
             }
         }
     }
     $page->setTitle($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();
     }
     if ($data->answerStatusDisplay) {
         $page->showAnswerStatus();
     } else {
         $page->hideAnswerStatus();
     }
     $page->setInstructions(empty($data->instructions) ? null : $data->instructions);
     $page->setLeadingText(empty($data->leadingText) ? null : $data->leadingText);
     $page->setTrailingText(empty($data->trailingText) ? null : $data->trailingText);
     foreach ($data->variables as $v) {
         $page->setVar($v->name, $v->value);
     }
     foreach ($data->elements as $obj) {
         $element = new \Jazzee\Entity\Element();
         $this->genericElement($element, $obj);
         $page->addElement($element);
     }
     foreach ($data->children as $obj) {
         $childPage = new \Jazzee\Entity\Page();
         $this->genericPage($childPage, $obj);
         $page->addChild($childPage);
     }
     $this->_em->clear();
 }