You are here

public function Mongodb_VoteStorage::selectVotes in Voting API 8.3

Same name and namespace in other branches
  1. 7.3 votingapi.api.php \Mongodb_VoteStorage::selectVotes()

Select individual votes from the database.

Parameters

$criteria: instance of VotingApi_Criteria.

$limit: An integer specifying the maximum number of votes to return. 0 means unlimited and is the default.

Return value

An array of VotingApi_Vote objects matching the criteria.

File

./votingapi.api.php, line 183
Provides hook documentation for the VotingAPI module.

Class

Mongodb_VoteStorage

Code

public function selectVotes($criteria, $limit) {
  $find = [];
  foreach ($criteria as $key => $value) {
    $find[$key] = is_array($value) ? [
      '$in' => $value,
    ] : $value;
  }
  $cursor = mongodb_collection('votingapi_vote')
    ->find($find);
  if (!empty($limit)) {
    $cursor
      ->limit($limit);
  }
  $votes = [];
  foreach ($cursor as $vote) {
    $votes[] = $vote;
  }
  return $votes;
}