Block for displaying

2ge - October 3, 2005 - 09:22
Project:Voting
Version:HEAD
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:active
Description

I like this module, it is nice, but I missed block for displaying high rated nodes, so I did a block (I'm using drupal 2 days, so there should be errors, please correct me, if something is wrong) - but I tested it on drupal 4.6.3 and voting 4.6.0 and everything seems to work. So here we come:

<?php
$min_votes
= 1;
$max_items = 10;
$node_type = 'page';
$most_rated = db_query("
     SELECT title, content_id, count(content_id) as cnt, sum(vote)/count(content_id) as rating
       FROM votes
  LEFT JOIN node ON content_id = nid
      WHERE type = '$node_type'
   GROUP BY content_id
     HAVING cnt >= $min_votes
   ORDER BY rating desc
      LIMIT $max_items
"
);
while(
$rated_post = db_fetch_object($most_rated)) {
 
$output[] = l($rated_post->title, "node/$rated_post->content_id") . "($rated_post->rating)<br />";
}
print
theme_item_list($output);
?>

 
 

Drupal is a registered trademark of Dries Buytaert.