You are here

function _votingapi_get_raw_votes in Voting API 5

An internal utility function used to pull raw votes for processing. Undocumented at the moment..

3 calls to _votingapi_get_raw_votes()
votingapi_get_content_votes in ./votingapi.module
A helper function that returns an array of votes for one piece of content, keyed by the user who cast them.
votingapi_get_user_votes in ./votingapi.module
A simple helper function that returns all votes cast by a given user for a piece of content.
votingapi_recalculate_results in ./votingapi.module
Loads all votes for a given piece of content, then calculates and caches the aggregate vote results. This is only intended for modules that have assumed responsibility for the full voting cycle: the votingapi_set_vote() function recalculates…

File

./votingapi.module, line 258

Code

function _votingapi_get_raw_votes($content_type, $content_id, $value_type = NULL, $tag_list = NULL, $uid = NULL) {
  if ($tag_list) {
    $filter_string .= " AND v.tag IN ('" . implode("','", $tag_list) . "')";
  }

  // Still not sure all this checking is necessary, but a quick cast can't hurt.
  if (is_numeric($uid)) {
    $filter_string .= ' AND v.uid = ' . (int) $uid;
  }
  elseif (is_array($uid)) {
    $uid_list = array();
    foreach ($uid as $discrete_uid) {
      if (is_numeric($discrete_uid)) {
        $uid_list[] = $discrete_uid;
      }
    }
    if (count($uid_list)) {
      $filter_string .= " AND v.uid IN ('" . implode("','", $uid_list) . "')";
    }
  }
  if (isset($value_type)) {
    $filter_string .= " AND v.value_type = '" . $value_type . "'";
  }
  $votes = array();
  $result = db_query("SELECT * FROM {votingapi_vote} v WHERE content_type='%s' AND content_id=%d {$filter_string}", $content_type, $content_id);
  while ($vobj = db_fetch_object($result)) {

    // Give other modules a chance to alter the vote object, add additional data, etc.
    votingapi_invoke('load', $vobj);
    $votes[] = $vobj;
  }
  return $votes;
}