/** * check vote ok from cookie * * checks against the settings if cookie block is used. if so checks if a cookie exists * for the current simplePoll. if so, checks the timestamp in the cookie to decide if the * user can vote again. if he votes and cookies are used, a cookie with the current timstamp is written * * @param \Pixelink\Simplepoll\Domain\Model\SimplePoll $simplePoll * @return mixed TRUE if the user is allowed to vote, string with the error message if not */ protected function checkVoteOkFromCookie(\Pixelink\Simplepoll\Domain\Model\SimplePoll $simplePoll) { // get the settings for cookie blocking $cookieBlock = $this->settings['cookieBlock']; if (!(strtolower($cookieBlock) == 'true' || $cookieBlock == '1')) { // cookies are not blocked, so the user can vote return TRUE; } // get the settings for multiple votes either global or local if ($this->settings['useTyposcriptSettings'] == 'true' || $this->settings['useTyposcriptSettings'] == '1') { $allowMultipleVote = $this->settings['allowMultipleVote']; } else { $allowMultipleVote = $simplePoll->getAllowMultipleVote(); } // check if there already is a cookie. that would mean the user is not allowed to vote right now. $cookieExists = isset($_COOKIE['simplePoll-' . $simplePoll->getUid()]); if ($cookieExists) { if ($allowMultipleVote) { return \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_simplepoll.voteNotNow', 'Simplepoll'); } else { return \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('tx_simplepoll.voteOnlyOnce', 'Simplepoll'); } } // set the cookie for the current poll, so other polls won't be affected. // if multiple votes are not allowed we set the cookie valid for one month if ($allowMultipleVote) { setcookie('simplePoll-' . $simplePoll->getUid(), time(), time() + $this->settings['garbageCollectorInterval']); } else { setcookie('simplePoll-' . $simplePoll->getUid(), time(), time() + 60 * 60 * 24 * 30); } return TRUE; }
public function getIpInPoll(\Pixelink\Simplepoll\Domain\Model\SimplePoll $simplePoll, $userIp) { $query = $this->createQuery(); $query->matching($query->logicalAnd($query->equals('simplepoll', $simplePoll->getUid()), $query->equals('address', $userIp))); return $query->execute()->getFirst(); }