diff -rup vote_up_down/vud.module vote_up_down_new/vud.module --- vote_up_down/vud.module 2010-10-22 17:46:25.000000000 +1100 +++ vud.module 2010-11-01 10:17:35.929303888 +1100 @@ -214,8 +214,25 @@ function vud_ctools_plugin_directory($mo * Implementation of votingapi hook_votingapi_results_alter(). */ function vud_votingapi_results_alter(&$cache, $content_type, $content_id) { - $vud_cache = _vud_get_standard_results($content_type, $content_id); - $cache = array_merge_recursive($cache, $vud_cache); + // 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; + } } /** @@ -234,36 +251,3 @@ function vud_votingapi_metadata_alter(&$ ); } -/** - * Calculate positive/negative results for VotingAPI cache. - * - * We provide 0 if not votes found. - */ -function _vud_get_standard_results($content_type, $content_id) { - $cache = array(); - $tag = variable_get('vud_tag', 'vote'); - - $sql = "SELECT SUM(v.value) as value_positives "; - $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"; - $value_positives = db_result(db_query($sql, $content_type, $content_id)); - - if ($value_positives === FALSE) { - $value_positives = 0; - } - $cache[$tag]['points']['positives'] = $value_positives; - - $sql = "SELECT SUM(v.value) as value_negatives "; - $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"; - $value_negatives = db_result(db_query($sql, $content_type, $content_id)); - - if ($value_negatives === FALSE) { - $value_negatives = 0; - } - $cache[$tag]['points']['negatives'] = $value_negatives; - - return $cache; -}