You are here

function votingapi_get_voting_result in Voting API 5

A simple helper function that returns a single cached voting result.

Parameters

$content_type: A string identifying the type of content whose votes are being retrieved. Node, comment, aggregator item, etc.

$content_id: The key ID of the content whose votes are being retrieved.

$value_type: An optional int representing the type of value saved in the vote. Three standard types are defined by votingapi: 'percent' -- 'Value' is a number from 0-100. The API will cache an average for all votes. 'points' -- 'Value' is a positive or negative int. The API will cache the sum of all votes. 'option' -- 'Value' is an int representing a specific option. The API will cache a vote-count for each option.

$tag: A string to separate multiple voting criteria. For example, a voting system that rates software for 'stability' and 'features' would cast two votes, each with a different tag. If none is specified, the default 'vote' tag is used.

$function: A string to indicate the aggregate function being retrieved (average, count, max, etc)

Return value

A single voting result object.

File

./votingapi.module, line 405

Code

function votingapi_get_voting_result($content_type, $content_id, $value_type, $tag, $function) {
  $result = db_query("SELECT * FROM {votingapi_cache} v WHERE content_type='%s' AND content_id=%d AND value_type='%s' AND tag='%s' AND function='%s'", $content_type, $content_id, $value_type, $tag, $function);
  while ($cached = db_fetch_object($result)) {
    $voting_results = $cached;
  }
  return $voting_results;
}