示例#1
0
 /**
  * magic method - gets an Answer property
  * @param $aID
  * @return Answer
  * @throws \Exception
  */
 public function __get($aID)
 {
     $id = str_replace("a", "", $aID);
     $optionDefinitions = $this->questionDefinition->getOptionDefinitions();
     $answers = $this->poll->getAnswers();
     foreach ($optionDefinitions as $optionDefinition) {
         if ($optionDefinition->getId() == $id) {
             if ($answers->isEmpty()) {
                 $answer = new Answer();
                 $answer->setPoll($this->poll);
                 $answer->setOptionDefinition($optionDefinition);
                 return $answer;
             } else {
                 $contains = false;
                 $foundAnswer = null;
                 foreach ($answers as $an) {
                     if ($an->getOptionDefinition()->getId() == $id) {
                         $contains = true;
                         $foundAnswer = $an;
                     }
                 }
                 if ($contains) {
                     return $foundAnswer;
                 } else {
                     $answer = new Answer();
                     $answer->setPoll($this->poll);
                     $answer->setOptionDefinition($optionDefinition);
                     return $answer;
                 }
             }
         }
     }
     throw new \Exception("invalid id");
 }
 /**
  * soft deletes question definition
  * @param PollDefinition $pollDefinition
  * @param QuestionDefinition $questionDefinition
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  * @Route("/poll-definition/{pollDefinition}/question-definition/{$questionDefinition}/inactivate", name="questionDefinition_inactivate")
  * @Security("has_role('ROLE_EMPLOYER')")
  */
 public function inactivateAction(PollDefinition $pollDefinition, QuestionDefinition $questionDefinition)
 {
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository('AkPollBundle:QuestionDefinition')->find($questionDefinition->getId());
     $entity->setInactivated(true);
     $em->flush();
     return $this->redirect($this->generateUrl('questionDefinition', array('pollDefinition' => $pollDefinition->getId())));
 }
 /**
  * edits an option definition
  * @param Request $request
  * @param QuestionDefinition $questionDefinition
  * @param $id
  * @return \Symfony\Component\HttpFoundation\RedirectResponse|Response
  * @Route("/question-definition/{questionDefinition}/option-definition/{id}/edit", name="optionDefinition_edit")
  * @Security("has_role('ROLE_EMPLOYER')")
  */
 public function editAction(Request $request, QuestionDefinition $questionDefinition, $id)
 {
     $entity = new OptionDefinitionChoice();
     $em = $this->getDoctrine()->getManager();
     $entity = $em->getRepository("AkPollBundle:optionDefinition")->find($id);
     $form = $this->createForm(new OptionDefinitionType(), $entity, array('method' => 'POST'));
     $form->add('submit', 'submit', array('label' => 'Update'));
     $form->handleRequest($request);
     if ($form->isValid()) {
         $em->flush();
         return $this->redirect($this->generateUrl('optionDefinition_show', array('questionDefinition' => $questionDefinition->getId(), 'id' => $entity->getId())));
     }
     return $this->render('optionDefinition/form.html.twig', array('form' => $form->createView()));
 }