Exemplo n.º 1
0
 /**
  * @param int $pollId
  * @return int
  */
 protected function hasAlreadyVoted($pollId)
 {
     // Check, whether the logged user has already voted
     if ($this->user->isAuthenticated() === true) {
         $votes = $this->voteRepository->getVotesByUserId($pollId, $this->user->getUserId(), $this->request->getSymfonyRequest()->getClientIp());
     } else {
         // For guest users check against the ip address
         $votes = $this->voteRepository->getVotesByIpAddress($pollId, $this->request->getSymfonyRequest()->getClientIp());
     }
     return $votes > 0;
 }
 /**
  * @param int $pollId
  * @param string $ipAddress
  * @return mixed
  */
 protected function getVotes($pollId, $ipAddress)
 {
     // Check, whether the logged user has already voted
     if ($this->userModel->isAuthenticated() === true) {
         $votes = $this->voteRepository->getVotesByUserId($pollId, $this->userModel->getUserId(), $ipAddress);
     } else {
         // For guest users check against the ip address
         $votes = $this->voteRepository->getVotesByIpAddress($pollId, $ipAddress);
     }
     return $votes;
 }
Exemplo n.º 3
0
 /**
  * @param array $formData
  * @param int $pollId
  * @param string $ipAddress
  * @param string $time
  * @return bool|int
  * @throws Core\Validation\Exceptions\ValidationRuleNotFoundException
  */
 public function vote(array $formData, $pollId, $ipAddress, $time)
 {
     $answers = $formData['answer'];
     $bool = false;
     $userId = $this->userModel->isAuthenticated() ? $this->userModel->getUserId() : null;
     // Multiple Answers
     if (is_array($answers) === false) {
         $answers = [$answers];
     }
     foreach ($answers as $answer) {
         if ($this->validator->is(IntegerValidationRule::class, $answer) === true) {
             $insertValues = ['poll_id' => $pollId, 'answer_id' => $answer, 'user_id' => $userId, 'ip' => $ipAddress, 'time' => $time];
             $bool = $this->voteRepository->insert($insertValues);
         }
     }
     return $bool;
 }
Exemplo n.º 4
0
 /**
  * @param int $pollId
  * @return bool|int
  */
 public function resetVotesByPollId($pollId)
 {
     return $this->voteRepository->delete($pollId, 'poll_id');
 }