You are here

function Mongodb_VoteStorage::selectVotes in Voting API 7.3

Same name and namespace in other branches
  1. 8.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 161
Provides hook documentation for the VotingAPI module.

Class

Mongodb_VoteStorage

Code

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