Beispiel #1
0
 /**
  * Record the LOR answer as a child answer
  * @param \Foundation\Form\Input $input
  * @param \Jazzee\Entity\Answer $parent
  */
 public function newLorAnswer(\Foundation\Form\Input $input, \Jazzee\Entity\Answer $parent)
 {
     if ($parent->getChildren()->count() == 0) {
         $page = $parent->getPage()->getChildren()->first();
         $child = new \Jazzee\Entity\Answer();
         $parent->addChild($child);
         $child->setPage($page);
         $child->setApplicant($parent->getApplicant());
         foreach ($page->getElements() as $element) {
             $element->getJazzeeElement()->setController($this->_controller);
             foreach ($element->getJazzeeElement()->getElementAnswers($input->get('el' . $element->getId())) as $elementAnswer) {
                 $child->addElementAnswer($elementAnswer);
             }
         }
         $this->_form->applyDefaultValues();
         $this->_controller->getEntityManager()->persist($child);
         //flush here so the answerId will be correct when we view
         $this->_controller->getEntityManager()->flush();
     }
 }
Beispiel #2
0
 public function updateLorAnswer(\Foundation\Form\Input $input, \Jazzee\Entity\Answer $answer)
 {
     foreach ($answer->getElementAnswers() as $ea) {
         $this->_controller->getEntityManager()->remove($ea);
         $answer->getElementAnswers()->removeElement($ea);
     }
     foreach ($answer->getChildren() as $childAnswer) {
         $this->_controller->getEntityManager()->remove($childAnswer);
         $answer->getChildren()->removeElement($childAnswer);
     }
     $branch = new \Jazzee\Entity\Answer();
     $answer->addChild($branch);
     $branch->setPage($answer->getPage()->getChildById($input->get('branching')));
     foreach ($branch->getPage()->getElements() as $element) {
         foreach ($element->getJazzeeElement()->getElementAnswers($input->get('el' . $element->getId())) as $elementAnswer) {
             $branch->addElementAnswer($elementAnswer);
         }
     }
     $this->_form = null;
     $this->_controller->getEntityManager()->persist($branch);
 }