I am using Drupal 6 and have multiple flags on my nodes each with a value such as: interesting, boring, intelligent, funny, abusive, etc. Views is currently able to sort results by the flag count for each individual flag but I need to sort my nodes by the total combined flag count of all the flags on each note. The 'rate' module comes fairly close to doing this but I need to use the flag module so that I can use the flag solr module to allow searching by flag. I just really don't know where to start... any suggestions as to an approach I could take?
Here's the current views query;
SELECT node.nid AS nid,
flag_counts_node.count AS flag_counts_node_count,
flag_counts_node_1.count AS flag_counts_node_1_count,
flag_counts_node_2.count AS flag_counts_node_2_count,
flag_counts_node_3.count AS flag_counts_node_3_count,
flag_counts_node_4.count AS flag_counts_node_4_count FROM node node
LEFT JOIN flag_counts flag_counts_node ON node.nid = flag_counts_node.content_id AND flag_counts_node.fid = 7
LEFT JOIN flag_counts flag_counts_node_1 ON node.nid = flag_counts_node_1.content_id AND flag_counts_node_1.fid = 6
LEFT JOIN flag_counts flag_counts_node_2 ON node.nid = flag_counts_node_2.content_id AND flag_counts_node_2.fid = 4
LEFT JOIN flag_counts flag_counts_node_3 ON node.nid = flag_counts_node_3.content_id AND flag_counts_node_3.fid = 5
LEFT JOIN flag_counts flag_counts_node_4 ON node.nid = flag_counts_node_4.content_id AND flag_counts_node_4.fid = 3
WHERE (node.type in ('rpodcast', 'upodcast')) AND (node.status = 1) ORDER BY flag_counts_node_count ASC, flag_counts_node_1_count ASC, flag_counts_node_2_count ASC, flag_counts_node_3_count ASC, flag_counts_node_4_count ASC
Here the module code so far ;
<?php
function flagcountview_views_pre_execute(&$view){
if ($view->name == 'audio') {
$sql = $view->build_info['query'];
$flag_count = "flag_counts_node.count + flag_counts_node_1.count + flag_counts_node_2.count + flag_counts_node_3.count";
$sql .= "ORDER BY $flag_count DESC";
$view->build_info['query'] = $sql;
}
}