function _votingapi_get_standard_results in Voting API 6.2
Builds the default VotingAPI results for the three supported voting styles.
1 call to _votingapi_get_standard_results()
- votingapi_recalculate_results in ./
votingapi.module - Recalculates the aggregate results of all votes for a piece of content.
File
- ./
votingapi.module, line 504 - A generalized voting API for Drupal.
Code
function _votingapi_get_standard_results($content_type, $content_id) {
$cache = array();
$sql = "SELECT v.value_type, v.tag, ";
$sql .= "COUNT(v.value) as value_count, SUM(v.value) as value_sum ";
$sql .= "FROM {votingapi_vote} v ";
$sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type IN ('points', 'percent') ";
$sql .= "GROUP BY v.value_type, v.tag";
$results = db_query($sql, $content_type, $content_id);
while ($result = db_fetch_array($results)) {
$cache[$result['tag']][$result['value_type']]['count'] = $result['value_count'];
$cache[$result['tag']][$result['value_type']]['average'] = $result['value_sum'] / $result['value_count'];
if ($result['value_type'] == 'points') {
$cache[$result['tag']][$result['value_type']]['sum'] = $result['value_sum'];
}
}
$sql = "SELECT v.tag, v.value, v.value_type, COUNT(1) AS score ";
$sql .= "FROM {votingapi_vote} v ";
$sql .= "WHERE v.content_type = '%s' AND v.content_id = %d AND v.value_type = 'option' ";
$sql .= "GROUP BY v.value, v.tag, v.value_type";
$results = db_query($sql, $content_type, $content_id);
while ($result = db_fetch_array($results)) {
$cache[$result['tag']][$result['value_type']]['option-' . $result['value']] = $result['score'];
}
return $cache;
}