function vud_votingapi_results_alter in Vote Up/Down 7
Same name and namespace in other branches
- 6.3 vud.module \vud_votingapi_results_alter()
- 6.2 vud.module \vud_votingapi_results_alter()
- 7.2 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 200 - Implements the core voting module on top of Voting API.
Code
function vud_votingapi_results_alter(&$cache, $entity_type, $entity_id) {
// positive points
$sql = "SELECT SUM(v.value) as value_positives, v.tag ";
$sql .= "FROM {votingapi_vote} v ";
$sql .= "WHERE v.entity_type = :entity_type AND v.entity_id = :entity_id AND v.value_type = 'points' AND v.value > 0 ";
$sql .= "GROUP BY v.value_type, v.tag";
$result = db_query($sql, array(
':entity_type' => $entity_type,
':entity_id' => $entity_id,
));
foreach ($result as $record) {
$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.entity_type = :entity_type AND v.entity_id = :entity_id AND v.value_type = 'points' AND v.value < 0 ";
$sql .= "GROUP BY v.value_type, v.tag";
$result = db_query($sql, array(
':entity_type' => $entity_type,
':entity_id' => $entity_id,
));
foreach ($result as $record) {
$cache[$record->tag]['points']['negatives'] = $record->value_negatives;
}
}