Index: votingapi_views.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/votingapi/votingapi_views.inc,v
retrieving revision 1.11.2.7
diff -u -u -p -r1.11.2.7 votingapi_views.inc
--- votingapi_views.inc	19 Jul 2007 14:13:44 -0000	1.11.2.7
+++ votingapi_views.inc	14 Jan 2008 15:06:32 -0000
@@ -55,7 +55,10 @@ function votingapi_views_tables() {
           ),
         ),  
         "sorts" => array(
-          "value" => array('name' => t("VotingAPI !type !tag vote", array('!tag' => $vote_tag, '!type' => $vote_type))),
+          "value" => array(
+            'name' => t("VotingAPI !type !tag vote", array('!tag' => $vote_tag, '!type' => $vote_type)),
+            'handler' => 'votingapi_views_handler_sort_value',
+          ),
           "uid" => array('name' => t("VotingAPI !type !tag voter", array('!tag' => $vote_tag, '!type' => $vote_type))),
           "timestamp" => array('name' => t("VotingAPI !type !tag timestamp", array('!tag' => $vote_tag, '!type' => $vote_type))),
         ),
@@ -134,7 +137,10 @@ function votingapi_views_tables() {
           ),
         ),  
         "sorts" => array(
-          "value" => array('name' => t("VotingAPI !type !tag vote", array('!tag' => $vote_tag, '!type' => $vote_type))),
+          "value" => array(
+            'name' => t("VotingAPI !type !tag vote", array('!tag' => $vote_tag, '!type' => $vote_type)),
+            'handler' => 'votingapi_views_handler_sort_value',
+          ),
           "timestamp" => array('name' => t("VotingAPI !type !tag timestamp", array('!tag' => $vote_tag, '!type' => $vote_type))),
         ),
         'filters' => array(
@@ -200,7 +206,10 @@ function votingapi_views_tables() {
             ),
           ),  
           "sorts" => array(
-            "value" => array('name' => t("VotingAPI !type !tag result (!function)", array('!tag' => $cache_tag, '!type' => $cache_type, '!function' => $cache_function))),
+            "value" => array(
+              'name' => t("VotingAPI !type !tag result (!function)", array('!tag' => $cache_tag, '!type' => $cache_type, '!function' => $cache_function)),
+              'handler' => 'votingapi_views_handler_sort_value',
+            ),
           ),
           'filters' => array(
             'value' => array(
@@ -220,6 +229,14 @@ function votingapi_views_tables() {
   return $tables;
 }
 
+function votingapi_views_handler_sort_value($op, &$query, $sortinfo, $sort) {
+  $field = explode('.', $sort['field']);
+  $alias = implode('_', $field);
+  $query->ensure_table($field[0]);
+  $query->add_field('COALESCE('. $sort['field'] .', 0)', '', $alias);
+  $query->orderby[] = $alias .' '. $sort['sortorder'];
+}
+
 function votingapi_views_handler_field_username($fieldinfo, $fielddata, $value, $data) {
   if ($value === NULL) {
     return '';
