1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
20 package NDWeb::Pages::PlanetRankings;
22 use warnings FATAL => 'all';
23 use CGI qw/:standard/;
26 use base qw/NDWeb::XMLPage/;
28 $NDWeb::Page::PAGES{planetrankings} = __PACKAGE__;
31 #TODO: Need to fix some links first
32 #if ($uri =~ m{^/[^/]+/(\w+)}){
40 $self->{TITLE} = 'Top planets';
41 my $DBH = $self->{DBH};
43 return $self->noAccess unless $self->isMember;
47 $BODY->param(isHC => $self->isHC);
50 if (defined param('offset') && param('offset') =~ /^(\d+)$/){
53 $BODY->param(Offset => $offset);
54 $BODY->param(PrevOffset => $offset - 100);
55 $BODY->param(NextOffset => $offset + 100);
57 my $order = 'scorerank';
58 if (defined param('order') && param('order') =~ /^(scorerank|sizerank|valuerank|xprank|hit_us)$/){
61 $BODY->param(Order => $order);
62 $order .= ' DESC' if ($order eq 'hit_us');
65 my $extra_columns = '';
67 $extra_columns = ",planet_status,hit_us, alliance,relationship,nick";
69 my $query = $DBH->prepare(qq{SELECT x,y,z,((ruler || ' OF ') || planet) as planet,race,
70 size, size_gain, size_gain_day,
71 score,score_gain,score_gain_day,
72 value,value_gain,value_gain_day,
73 xp,xp_gain,xp_gain_day,
74 sizerank,sizerank_gain,sizerank_gain_day,
75 scorerank,scorerank_gain,scorerank_gain_day,
76 valuerank,valuerank_gain,valuerank_gain_day,
77 xprank,xprank_gain,xprank_gain_day
78 $extra_columns FROM current_planet_stats_full ORDER BY $order LIMIT 100 OFFSET ?});
79 $query->execute($offset) or $error .= p($DBH->errstr);
82 while (my $planet = $query->fetchrow_hashref){
83 for my $type (qw/size score value xp/){
84 #$planet->{$type} = prettyValue($planet->{$type});
85 $planet->{"${type}img"} = 'stay';
86 $planet->{"${type}img"} = 'up' if $planet->{"${type}_gain_day"} > 0;
87 $planet->{"${type}img"} = 'down' if $planet->{"${type}_gain_day"} < 0;
88 $planet->{"${type}rankimg"} = 'stay';
89 $planet->{"${type}rankimg"} = 'up' if $planet->{"${type}rank_gain_day"} < 0;
90 $planet->{"${type}rankimg"} = 'down' if $planet->{"${type}rank_gain_day"} > 0;
91 for my $type ($type,"${type}_gain","${type}_gain_day"){
92 $planet->{$type} =~ s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))|\G\d{3}(?=\d))/$1,/g; #Add comma for ever 3 digits, i.e. 1000 => 1,000
96 $planet->{ODD} = $i % 2;
97 push @planets,$planet;
99 $BODY->param(Planets => \@planets);
100 $BODY->param(Error => $error);