drupal/modules/rating.module

55 lines
1.8 KiB
Plaintext

<?php
$module = array("cron" => "rating_cron",
"help" => "rating_help",
"page" => "rating_page",
"block" => "rating_block");
function rating_cron() {
$r1 = db_query("SELECT id FROM users ORDER BY rating DESC");
while ($account = db_fetch_object($r1)) {
db_query("UPDATE users SET rating = '". user_gravity($account->id) ."' WHERE id = '$account->id'");
$rating[$account->id] = ++$i;
}
db_query("DELETE FROM rating");
$r2 = db_query("SELECT id FROM users ORDER BY rating DESC");
while ($account = db_fetch_object($r2)) {
db_query("INSERT INTO rating (user, new, old) VALUES ('$account->id', '". ++$j ."', '". $rating[$account->id] ."')");
}
}
function rating_help() {
?>
<P>The rating cron will periodically calculate each user's gravity, the overall time-weighted rating of each user's contributions.</P>
<?
}
function rating_list($limit) {
$result = db_query("SELECT u.userid, u.rating, r.* FROM users u LEFT JOIN rating r ON u.id = r.user ORDER BY u.rating DESC LIMIT $limit");
$output .= "<TABLE CELLPADDING=\"1\" CELLSPACING=\"1\">\n";
while ($account = db_fetch_object($result)) {
$ranking = $account->old - $account->new;
$output .= "<TR><TD ALIGN=\"right\">". ++$i ."</TD><TD>". format_username($account->userid) ."</TD><TD ALIGN=\"right\">". check_output($account->rating) ."</TD><TD>(". ($ranking < 0 ? "" : "+") ."$ranking)</TD></TR>";
}
$output .= "</TABLE>\n";
return $output;
}
function rating_page() {
global $theme;
$theme->header();
$theme->box("Top 100 users", rating_list(100));
$theme->footer();
}
function rating_block() {
$block[0][subject] = "Top 10:<BR>users";
$block[0][content] = rating_list(10);
$block[0][info] = "Top 10: users";
return $block;
}
?>