2004-12-08 22:05:56 +00:00
|
|
|
<?php
|
2004-06-30 18:53:35 +00:00
|
|
|
|
2004-12-08 22:05:56 +00:00
|
|
|
require_once("../inc/cache.inc");
|
|
|
|
require_once("../inc/util.inc");
|
|
|
|
require_once("../inc/team.inc");
|
2005-08-16 09:20:25 +00:00
|
|
|
require_once("../inc/db.inc");
|
|
|
|
require_once("../inc/translation.inc");
|
|
|
|
|
2007-10-26 03:57:07 +00:00
|
|
|
$config = get_config();
|
|
|
|
$teams_per_page = parse_config($config, "<teams_per_page>");
|
|
|
|
if (!$teams_per_page) {
|
|
|
|
$teams_per_page = 20;
|
|
|
|
}
|
2007-10-26 21:14:35 +00:00
|
|
|
define('ITEM_LIMIT', 10000);
|
2004-06-30 18:53:35 +00:00
|
|
|
|
2007-11-20 22:58:14 +00:00
|
|
|
function get_top_teams($offset, $sort_by, $type){
|
2007-10-26 03:57:07 +00:00
|
|
|
global $teams_per_page;
|
2007-10-29 16:38:25 +00:00
|
|
|
$db = BoincDb::get(true);
|
2007-11-20 22:58:14 +00:00
|
|
|
$type_clause = null;
|
2005-08-16 09:20:25 +00:00
|
|
|
if ($type){
|
2007-11-20 22:58:14 +00:00
|
|
|
$type_clause = "type=$type";
|
2005-08-16 09:20:25 +00:00
|
|
|
}
|
|
|
|
if ($sort_by == "total_credit") {
|
2006-11-03 04:36:21 +00:00
|
|
|
$sort_order = "total_credit desc";
|
2005-08-16 09:20:25 +00:00
|
|
|
} else {
|
|
|
|
$sort_order = "expavg_credit desc";
|
|
|
|
}
|
2007-11-20 22:58:14 +00:00
|
|
|
return BoincTeam::enum($type_clause, "order by $sort_order limit $offset, $teams_per_page");
|
2005-08-16 09:20:25 +00:00
|
|
|
}
|
|
|
|
|
2006-11-03 04:36:21 +00:00
|
|
|
// These converter functions are here in case we later decide to use something
|
|
|
|
// else than serializing to save temp data
|
|
|
|
//
|
|
|
|
function teams_to_store($participants){
|
|
|
|
return serialize($participants);
|
2005-08-16 09:20:25 +00:00
|
|
|
}
|
|
|
|
function store_to_teams($data){
|
|
|
|
return unserialize($data);
|
|
|
|
}
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2005-05-11 10:03:27 +00:00
|
|
|
if (isset($_GET["sort_by"])) {
|
|
|
|
$sort_by = $_GET["sort_by"];
|
|
|
|
} else {
|
|
|
|
$sort_by = "expavg_credit";
|
|
|
|
}
|
2005-08-16 09:20:25 +00:00
|
|
|
|
2005-02-19 08:06:53 +00:00
|
|
|
$type = get_int("type", true);
|
2004-12-08 22:05:56 +00:00
|
|
|
if ($type < 1 || $type > 7) {
|
2007-11-20 22:58:14 +00:00
|
|
|
$type = 0;
|
2004-12-08 22:05:56 +00:00
|
|
|
}
|
2007-11-20 22:58:14 +00:00
|
|
|
$type_url="";
|
|
|
|
$type_name="";
|
2004-12-08 22:05:56 +00:00
|
|
|
if ($type) {
|
|
|
|
$type_url = "&type=$type";
|
|
|
|
$type_name = team_type_name($type);
|
|
|
|
}
|
2004-06-30 18:53:35 +00:00
|
|
|
|
2005-08-16 09:20:25 +00:00
|
|
|
$offset = get_int("offset", true);
|
|
|
|
if (!$offset) $offset=0;
|
2007-10-26 03:57:07 +00:00
|
|
|
if ($offset % $teams_per_page) $offset = 0;
|
2003-09-08 00:04:55 +00:00
|
|
|
|
2005-08-16 09:20:25 +00:00
|
|
|
if ($offset < ITEM_LIMIT) {
|
2007-11-20 22:58:14 +00:00
|
|
|
$cache_args = "sort_by=$sort_by&offset=$offset$type_url";
|
2006-11-03 04:36:21 +00:00
|
|
|
$cacheddata = get_cached_data(TOP_PAGES_TTL,$cache_args);
|
2007-10-26 03:57:07 +00:00
|
|
|
//If we have got the data in cache
|
|
|
|
if ($cacheddata){
|
2006-11-03 04:36:21 +00:00
|
|
|
$data = store_to_teams($cacheddata); // use the cached data
|
2007-10-26 03:57:07 +00:00
|
|
|
} else {
|
|
|
|
//if not do queries etc to generate new data
|
2006-11-03 04:36:21 +00:00
|
|
|
$data = get_top_teams($offset,$sort_by,$type);
|
2006-11-03 18:41:34 +00:00
|
|
|
|
2007-11-07 17:23:29 +00:00
|
|
|
// Calculate nusers before storing into the cache
|
2007-10-29 16:38:25 +00:00
|
|
|
foreach ($data as $team) {
|
2007-11-07 17:23:29 +00:00
|
|
|
$team->nusers = team_count_members($team->id);
|
2006-11-03 18:41:34 +00:00
|
|
|
}
|
2007-10-26 03:57:07 +00:00
|
|
|
//save data in cache
|
|
|
|
set_cache_data(teams_to_store($data),$cache_args);
|
2006-11-03 18:41:34 +00:00
|
|
|
}
|
2004-12-08 22:05:56 +00:00
|
|
|
} else {
|
2005-08-16 09:20:25 +00:00
|
|
|
error_page("Limit exceeded - Sorry, first ".ITEM_LIMIT." items only");
|
2004-12-08 22:05:56 +00:00
|
|
|
}
|
2002-11-11 19:40:22 +00:00
|
|
|
|
2004-12-08 22:05:56 +00:00
|
|
|
|
2006-11-03 04:36:21 +00:00
|
|
|
// Now display what we've got (either gotten from cache or from DB)
|
2007-11-02 14:43:02 +00:00
|
|
|
page_head(tra("Top %1 teams", $type_name));
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2007-11-20 22:58:14 +00:00
|
|
|
if (count($data) == 0) {
|
|
|
|
echo "There are no $type_name teams";
|
|
|
|
} else {
|
|
|
|
start_table();
|
|
|
|
team_table_start($sort_by, $type_url);
|
|
|
|
$i = 1 + $offset;
|
|
|
|
$n = sizeof($data);
|
|
|
|
foreach ($data as $team) {
|
|
|
|
show_team_row($team, $i);
|
|
|
|
$i++;
|
|
|
|
}
|
|
|
|
echo "</table>\n<p>";
|
|
|
|
if ($offset > 0) {
|
|
|
|
$new_offset = $offset - $teams_per_page;
|
|
|
|
echo "<a href=top_teams.php?sort_by=$sort_by&offset=$new_offset".$type_url.">Previous ".$teams_per_page."</a> | ";
|
|
|
|
|
|
|
|
}
|
|
|
|
if ($n==$teams_per_page){ //If we aren't on the last page
|
|
|
|
$new_offset = $offset + $teams_per_page;
|
|
|
|
echo "<a href=top_teams.php?sort_by=$sort_by&offset=$new_offset".$type_url.">Next ".$teams_per_page."</a>";
|
|
|
|
}
|
2005-09-07 16:00:27 +00:00
|
|
|
}
|
2005-08-16 09:20:25 +00:00
|
|
|
page_tail();
|
2004-06-07 03:34:07 +00:00
|
|
|
|
2004-12-08 22:05:56 +00:00
|
|
|
?>
|