You are here

function _votingapi_query in Voting API 6

Same name and namespace in other branches
  1. 6.2 votingapi.module \_votingapi_query()
3 calls to _votingapi_query()
votingapi_select_results in ./votingapi.module
Select cached vote results from the database.
votingapi_select_single_result_value in ./votingapi.module
Simple wrapper function for votingapi_select_results. Returns the value of the first result matching the criteria passed in.
votingapi_select_votes in ./votingapi.module
Select individual votes from the database.

File

./votingapi.module, line 462

Code

function _votingapi_query($table = 'vote', $criteria = array(), $limit = 0) {
  $criteria += array(
    'vote_id' => NULL,
    'vote_cache_id' => NULL,
    'content_id' => NULL,
    'content_type' => NULL,
    'value_type' => NULL,
    'value' => NULL,
    'tag' => NULL,
    'uid' => NULL,
    'timestamp' => NULL,
    'vote_source' => NULL,
    'function' => NULL,
  );
  $query = "SELECT * FROM {votingapi_" . $table . "} v WHERE 1 = 1";
  $args = array();
  if (!empty($criteria['vote_id'])) {
    _votingapi_query_builder('vote_id', $criteria['vote_id'], $query, $args);
  }
  elseif (!empty($criteria['vote_cache_id'])) {
    _votingapi_query_builder('vote_cache_id', $criteria['vote_cache_id'], $query, $args);
  }
  else {
    _votingapi_query_builder('content_type', $criteria['content_type'], $query, $args, TRUE);
    _votingapi_query_builder('content_id', $criteria['content_id'], $query, $args);
    _votingapi_query_builder('value_type', $criteria['value_type'], $query, $args, TRUE);
    _votingapi_query_builder('tag', $criteria['tag'], $query, $args, TRUE);
    _votingapi_query_builder('function', $criteria['function'], $query, $args);
    _votingapi_query_builder('uid', $criteria['uid'], $query, $args);
    _votingapi_query_builder('vote_source', $criteria['vote_source'], $query, $args, TRUE);
    _votingapi_query_builder('timestamp', $criteria['timestamp'], $query, $args);
  }
  return $limit ? db_query_range($query, $args, 0, $limit) : db_query($query, $args);
}