View source
<?php
namespace Drupal\poll;
use Drupal\Core\Entity\Sql\SqlContentEntityStorage;
use Drupal\Core\Session\AccountInterface;
class PollStorage extends SqlContentEntityStorage implements PollStorageInterface {
public function getTotalVotes(PollInterface $poll) {
return \Drupal::service('poll_vote.storage')
->getTotalVotes($poll);
}
public function deleteVotes(PollInterface $poll) {
return \Drupal::service('poll_vote.storage')
->deleteVotes($poll);
}
public function getUserVote(PollInterface $poll) {
return \Drupal::service('poll_vote.storage')
->getUserVote($poll);
}
public function saveVote(array $options) {
return \Drupal::service('poll_vote.storage')
->saveVote($options);
}
public function getVotes(PollInterface $poll) {
return \Drupal::service('poll_vote.storage')
->getVotes($poll);
}
public function cancelVote(PollInterface $poll, AccountInterface $account = NULL) {
\Drupal::service('poll_vote.storage')
->cancelVote($poll, $account);
}
public function getPollDuplicates(PollInterface $poll) {
$query = \Drupal::entityQuery('poll');
$query
->condition('question', $poll
->label());
if ($poll
->id()) {
$query
->condition('id', $poll
->id(), '<>');
}
return $this
->loadMultiple($query
->execute());
}
public function getMostRecentPoll() {
$query = \Drupal::entityQuery('poll')
->condition('status', POLL_PUBLISHED)
->sort('created', 'DESC')
->pager(1);
return $this
->loadMultiple($query
->execute());
}
public function getExpiredPolls() {
$query = $this->database
->query('SELECT id FROM {poll_field_data} WHERE (:timestamp > (created + runtime)) AND status = 1 AND runtime <> 0', [
':timestamp' => \Drupal::time()
->getCurrentTime(),
]);
return $this
->loadMultiple($query
->fetchCol());
}
}