Esempio 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();
 }
Esempio n. 2
0
 /**
  * @return array
  */
 public function execute()
 {
     $this->setCacheResponseCacheable($this->config->getSettings(Schema::MODULE_NAME)['cache_lifetime']);
     $polls = $this->pollRepository->getAll($this->date->getCurrentDateTime());
     $cPolls = count($polls);
     for ($i = 0; $i < $cPolls; ++$i) {
         if ($this->hasAlreadyVoted($polls[$i]['id']) || $polls[$i]['start'] !== $polls[$i]['end'] && $this->date->timestamp($polls[$i]['end']) <= $this->date->timestamp()) {
             $polls[$i]['link'] = 'result';
         } else {
             $polls[$i]['link'] = 'vote';
         }
     }
     return ['polls' => $polls];
 }
Esempio n. 3
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();
 }
Esempio n. 4
0
 /**
  * @return array
  */
 public function execute()
 {
     $poll = $this->pollRepository->getLatestPoll($this->date->getCurrentDateTime());
     $answers = [];
     $this->setTemplate('Polls/Widget/index.vote.tpl');
     if (!empty($poll)) {
         $answers = $this->answerRepository->getAnswersWithVotesByPollId($poll['id']);
         if ($this->hasAlreadyVoted($poll['id'])) {
             $totalVotes = $poll['total_votes'];
             $cAnswers = count($answers);
             for ($i = 0; $i < $cAnswers; ++$i) {
                 $votes = $answers[$i]['votes'];
                 $answers[$i]['votes'] = $votes > 1 ? $this->translator->t('polls', 'number_of_votes', ['%votes%' => $votes]) : $this->translator->t('polls', $votes == 1 ? 'one_vote' : 'no_votes');
                 $answers[$i]['percent'] = $totalVotes > 0 ? round(100 * $votes / $totalVotes, 2) : '0';
             }
             $this->setTemplate('Polls/Widget/index.result.tpl');
         }
     }
     return ['sidebar_polls' => $poll, 'sidebar_poll_answers' => $answers];
 }