Ejemplo n.º 1
0
 /**
  * @param int $id
  *
  * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
  * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
  */
 public function execute($id)
 {
     $answer = $this->request->getPost()->get('answer');
     $time = $this->date->getCurrentDateTime();
     if ($this->pollRepository->pollExists($id, $time, is_array($answer)) === true) {
         if (!empty($answer) || is_array($answer) === true) {
             return $this->executePost($this->request->getPost()->all(), $time, $id);
         }
         $poll = $this->pollRepository->getOneById($id);
         return ['question' => $poll['title'], 'multiple' => $poll['multiple'], 'answers' => $this->answerRepository->getAnswersByPollId($id)];
     }
     throw new Core\Controller\Exception\ResultNotExistsException();
 }
Ejemplo n.º 2
0
 /**
  * @param int $id
  *
  * @return array
  * @throws \ACP3\Core\Controller\Exception\ResultNotExistsException
  */
 public function execute($id)
 {
     $this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
     if ($this->pollRepository->pollExists($id, $this->date->getCurrentDateTime()) === true) {
         $question = $this->pollRepository->getOneByIdWithTotalVotes($id);
         $answers = $this->answerRepository->getAnswersWithVotesByPollId($id);
         $cAnswers = count($answers);
         $totalVotes = $question['total_votes'];
         for ($i = 0; $i < $cAnswers; ++$i) {
             $answers[$i]['percent'] = $totalVotes > 0 ? round(100 * $answers[$i]['votes'] / $totalVotes, 2) : '0';
         }
         return ['question' => $question['title'], 'answers' => $answers, 'total_votes' => $totalVotes];
     }
     throw new Core\Controller\Exception\ResultNotExistsException();
 }