summaryrefslogtreecommitdiff
path: root/modules/rating.module
blob: c5e66559241851a5b6b082969d2c6d8f4dd829aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?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;
}

?>