public function PollVoteStorage::getUserVote in Poll 8
Get a user's votes for a poll.
Parameters
PollInterface $poll:
Return value
mixed
Overrides PollVoteStorageInterface::getUserVote
File
- src/
PollVoteStorage.php, line 135
Class
- PollVoteStorage
- Controller class for poll vote storage.
Namespace
Drupal\pollCode
public function getUserVote(PollInterface $poll) {
$uid = \Drupal::currentUser()
->id();
$key = $poll
->id() . ':' . $uid;
if (isset($this->currentUserVote[$key])) {
return $this->currentUserVote[$key];
}
$this->currentUserVote[$key] = FALSE;
if ($uid || $poll
->getAnonymousVoteAllow()) {
if ($uid) {
$query = $this->connection
->query("SELECT * FROM {poll_vote} WHERE pid = :pid AND uid = :uid", array(
':pid' => $poll
->id(),
':uid' => $uid,
));
}
else {
$query = $this->connection
->query("SELECT * FROM {poll_vote} WHERE pid = :pid AND hostname = :hostname AND uid = 0", array(
':pid' => $poll
->id(),
':hostname' => \Drupal::request()
->getClientIp(),
));
}
$this->currentUserVote[$key] = $query
->fetchAssoc();
}
return $this->currentUserVote[$key];
}