You are here

function vud_votingapi_results_alter in Vote Up/Down 6.2

Same name and namespace in other branches
  1. 6.3 vud.module \vud_votingapi_results_alter()
  2. 7.2 vud.module \vud_votingapi_results_alter()
  3. 7 vud.module \vud_votingapi_results_alter()

Implementation of votingapi hook_votingapi_results_alter().

Add positive/negative aggregations for VotingAPI cache points.

File

./vud.module, line 223

Code

function vud_votingapi_results_alter(&$cache, $content_type, $content_id) {

  // positive points
  $sql = "SELECT SUM(v.value) as value_positives, v.tag ";
  $sql .= "FROM {votingapi_vote} v ";
  $sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type = 'points' AND v.value > 0 ";
  $sql .= "GROUP BY v.value_type, v.tag";
  $result = db_query($sql, $content_type, $content_id);
  while ($record = db_fetch_object($result)) {
    $cache[$record->tag]['points']['positives'] = $record->value_positives;
  }

  // negative points
  $sql = "SELECT SUM(v.value) as value_negatives, v.tag ";
  $sql .= "FROM {votingapi_vote} v ";
  $sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type = 'points' AND v.value < 0 ";
  $sql .= "GROUP BY v.value_type, v.tag";
  $result = db_query($sql, $content_type, $content_id);
  while ($record = db_fetch_object($result)) {
    $cache[$record->tag]['points']['negatives'] = $record->value_negatives;
  }
}