Exemplo n.º 1
0
 /**
  * creates new Poll entity
  * @param Request $request
  * @param PollDefinition $pollDefinition
  * @param User $user
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  *
  * @Route("/poll/{pollDefinition}/create/{user}", name="poll_create")
  * @Security("has_role('ROLE_POLLSTER')")
  *
  */
 public function createAction(Request $request, PollDefinition $pollDefinition, User $user)
 {
     $entity = new Poll();
     $entity->setPollDefinition($pollDefinition);
     $entity->setLastAnsweredQuestion(0);
     $em = $this->getDoctrine()->getManager();
     $deals = $em->getRepository('AkPollBundle:Deal')->findBy(array('user' => $user->getID()));
     foreach ($deals as $deal) {
         if ($deal->getPolls()->count() < $deal->getQuantity()) {
             $entity->setDeal($deal);
             break;
         }
     }
     $em->persist($entity);
     $em->flush();
     return $this->redirect($this->generateUrl('poll', array('pollDefinition' => $pollDefinition->getId())));
 }
Exemplo n.º 2
0
 /**
  * magic method - sets and Answer property
  * @param $aID
  * @param Answer $answer
  */
 public function __set($aID, Answer $answer)
 {
     $entities = $this->poll->getAnswers();
     $contains = false;
     foreach ($entities as $entity) {
         if ($entity->getOptionDefinition()->getID() == $answer->getOptionDefinition()->getId()) {
             $contains = true;
             $entity->setFreeText($answer->getFreeText());
             $entity->setChecked($answer->getChecked());
         }
     }
     if (!$contains) {
         $this->poll->addAnswer($answer);
     }
 }
 /**
  * returns list of questionDefinitions
  * @param Poll $poll
  * @return array
  */
 public function getQuestionDefinitions(Poll $poll)
 {
     return $this->questionDefinitionRepository->getQuestionDefinitions($poll->getPollDefinition());
 }
Exemplo n.º 4
0
 /**
  * informs that the poll was completed
  * @param Poll $poll
  * @return Response
  * @throws \Exception
  * @throws \Twig_Error
  * @Route("/poll/{poll}/success" , name="poll_success")
  * @Method("GET")
  * @Security("has_role('ROLE_POLLSTER')")
  */
 public function successAction(Poll $poll)
 {
     $html = $this->container->get('templating')->render('answer/success.html.twig', ['pollDefinition' => $poll->getPollDefinition()]);
     return new Response($html);
 }