You are here

function votingapi_select_results in Voting API 7.2

Same name and namespace in other branches
  1. 6.2 votingapi.module \votingapi_select_results()
  2. 6 votingapi.module \votingapi_select_results()

Select cached vote results from the database.

Parameters

$criteria: A keyed array used to build the select query. Keys can contain a single value or an array of values to be matched. $criteria['vote_cache_id'] (If this is set, all other keys are skipped) $criteria['entity_id'] $criteria['entity_type'] $criteria['value'] $criteria['value_type'] $criteria['tag'] $criteria['function'] $criteria['timestamp'] (If this is set, records with timestamps GREATER THAN the set value will be selected.)

$limit: An optional integer specifying the maximum number of votes to return.

Return value

An array of vote results matching the criteria.

1 call to votingapi_select_results()
votingapi_select_single_result_value in ./votingapi.module
Retrieve the value of the first result matching the criteria passed in.

File

./votingapi.module, line 453
A generalized voting API for Drupal.

Code

function votingapi_select_results($criteria = array(), $limit = 0) {
  $query = db_select('votingapi_cache')
    ->fields('votingapi_cache');
  foreach ($criteria as $key => $value) {
    $query
      ->condition($key, $value, is_array($value) ? 'IN' : '=');
  }
  if (!empty($limit)) {
    $query
      ->range(0, $limit);
  }
  return $query
    ->execute()
    ->fetchAll(PDO::FETCH_ASSOC);
}