]> ruin.nu Git - ndwebbie.git/commitdiff
Top members converted
authorMichael Andreen <harv@ruin.nu>
Tue, 24 Jun 2008 23:09:03 +0000 (01:09 +0200)
committerMichael Andreen <harv@ruin.nu>
Tue, 24 Jun 2008 23:17:04 +0000 (01:17 +0200)
NDWeb/Pages/Points.pm [deleted file]
database/group_roles.sql
lib/NDWeb.pm
lib/NDWeb/Controller/Members.pm [new file with mode: 0644]
root/lib/site/leftbar.tt2
root/src/members/points.tt2 [new file with mode: 0644]
t/controller_Members.t [new file with mode: 0644]
templates/points.tmpl [deleted file]

diff --git a/NDWeb/Pages/Points.pm b/NDWeb/Pages/Points.pm
deleted file mode 100644 (file)
index 250900b..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-#**************************************************************************
-#   Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu>               *
-#                                                                         *
-#   This program is free software; you can redistribute it and/or modify  *
-#   it under the terms of the GNU General Public License as published by  *
-#   the Free Software Foundation; either version 2 of the License, or     *
-#   (at your option) any later version.                                   *
-#                                                                         *
-#   This program is distributed in the hope that it will be useful,       *
-#   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
-#   GNU General Public License for more details.                          *
-#                                                                         *
-#   You should have received a copy of the GNU General Public License     *
-#   along with this program; if not, write to the                         *
-#   Free Software Foundation, Inc.,                                       *
-#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
-#**************************************************************************/
-
-package NDWeb::Pages::Points;
-use strict;
-use warnings FATAL => 'all';
-use CGI qw/:standard/;
-use NDWeb::Include;
-
-use base qw/NDWeb::XMLPage/;
-
-$NDWeb::Page::PAGES{points} = __PACKAGE__;
-
-
-sub render_body {
-       my $self = shift;
-       my ($BODY) = @_;
-       $self->{TITLE} = 'Top Members';
-       my $DBH = $self->{DBH};
-
-       return $self->noAccess unless $self->isMember;
-
-       my $type = "total";
-       if (defined param('type') && param('type') =~ /^(defense|attack|total|humor|scan|rank|raid)$/){
-               $type = $1;
-       }
-       $type .= '_points' unless ($type eq 'rank');
-
-       my $order = 'DESC';
-       $order = 'ASC' if ($type eq 'rank');
-
-       my $limit = 'LIMIT 10';
-       $limit = '' if $self->isOfficer;
-
-       my $query = $DBH->prepare(qq{SELECT username,defense_points,attack_points,scan_points,humor_points
-               ,(attack_points+defense_points+scan_points/20) as total_points, rank, count(NULLIF(rc.launched,FALSE)) AS raid_points
-               FROM users u LEFT OUTER JOIN raid_claims rc USING (uid)
-               WHERE uid IN (SELECT uid FROM groupmembers WHERE gid = 2)
-               GROUP BY username,defense_points,attack_points,scan_points,humor_points,rank
-               ORDER BY $type $order $limit});
-       $query->execute;
-
-       my @members;
-       while (my ($username,$defense,$attack,$scan,$humor,$total,$rank,$raid) = $query->fetchrow){
-               push @members,{Username => $username, Defense => $defense, Attack => $attack, Raid => $raid
-                       , Scan => $scan, Humor => $humor, Total => $total, Rank => $rank};
-       }
-       $BODY->param(Members => \@members);
-       return $BODY;
-}
-
-1;
index d6b962885e0061343f5523a5cb4b6348797ab464..3ae93d42be22c5e0bb168a1c9dd67e9a90f5c327 100644 (file)
@@ -19,14 +19,23 @@ INSERT INTO roles VALUES('admin_users');
 INSERT INTO roles VALUES('rankings_planet_intel');
 INSERT INTO roles VALUES('alliances_resources');
 INSERT INTO roles VALUES('graphs_intel');
+INSERT INTO roles VALUES('members');
+INSERT INTO roles VALUES('members_points_nolimit');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'member_menu');
 INSERT INTO group_roles (gid,role) VALUES(2,'attack_menu');
+INSERT INTO group_roles (gid,role) VALUES(2,'members');
+
 INSERT INTO group_roles (gid,role) VALUES(6,'dc_menu');
+
 INSERT INTO group_roles (gid,role) VALUES(4,'bc_menu');
+
 INSERT INTO group_roles (gid,role) VALUES(5,'intel_menu');
+
 INSERT INTO group_roles (gid,role) VALUES(8,'no_fleet_update');
 
+INSERT INTO group_roles (gid,role) VALUES(9,'members_points_nolimit');
+
 INSERT INTO group_roles (gid,role) VALUES(1,'dc_menu');
 INSERT INTO group_roles (gid,role) VALUES(1,'bc_menu');
 INSERT INTO group_roles (gid,role) VALUES(1,'hc_menu');
index bf888193665579a3e4a7727afdcb81315c17eb40..238e5f409e057a63575d2fb37a6b16521751fff8 100644 (file)
@@ -71,6 +71,7 @@ __PACKAGE__->deny_access_unless('/users',[qw/admin_users/]);
 __PACKAGE__->deny_access_unless('/alliances/resources',[qw/alliances_resources/]);
 __PACKAGE__->deny_access_unless('/graphs/alliancevsintel',[qw/graphs_intel/]);
 __PACKAGE__->deny_access_unless('/graphs/avgalliancevsintel',[qw/graphs_intel/]);
+__PACKAGE__->deny_access_unless('/members',[qw/members/]);
 
 =head1 NAME
 
diff --git a/lib/NDWeb/Controller/Members.pm b/lib/NDWeb/Controller/Members.pm
new file mode 100644 (file)
index 0000000..e25a69b
--- /dev/null
@@ -0,0 +1,63 @@
+package NDWeb::Controller::Members;
+
+use strict;
+use warnings;
+use parent 'Catalyst::Controller';
+
+=head1 NAME
+
+NDWeb::Controller::Members - Catalyst Controller
+
+=head1 DESCRIPTION
+
+Catalyst Controller.
+
+=head1 METHODS
+
+=cut
+
+
+=head2 index 
+
+=cut
+
+sub points : Local {
+       my ( $self, $c, $order ) = @_;
+       my $dbh = $c->model;
+
+       if ($order =~ /^((?:defense|attack|total|humor|scan|raid)_points)$/){
+               $order = "$1 DESC";
+       }else{
+               $order = 'total_points DESC';
+       }
+
+       my $limit = 'LIMIT 10';
+       $limit = '' if $c->check_user_roles(qw/members_points_nolimit/);
+
+       my $query = $dbh->prepare(qq{SELECT username,defense_points,attack_points
+               ,scan_points,humor_points
+               ,(attack_points+defense_points+scan_points/20) as total_points
+               , count(NULLIF(rc.launched,FALSE)) AS raid_points
+               FROM users u LEFT OUTER JOIN raid_claims rc USING (uid)
+               WHERE uid IN (SELECT uid FROM groupmembers WHERE gid = 2)
+               GROUP BY username,defense_points,attack_points,scan_points,humor_points,rank
+               ORDER BY $order $limit});
+       $query->execute;
+       my @members;
+       while (my $member = $query->fetchrow_hashref){
+               push @members,$member;
+       }
+       $c->stash(members => \@members);
+}
+
+=head1 AUTHOR
+
+Michael Andreen (harv@ruin.nu)
+
+=head1 LICENSE
+
+GPL 2.0, or later.
+
+=cut
+
+1;
index be71cf35b7159dd43699802e9115f894323f12df..450cfdc71e0dedd93d74cb8f461b52a43ec63f65 100644 (file)
        [% IF user.attacker %]
 <p>Member menu</p>
 <ul class="linkbar">
-       <li><a href="/points">Top members</a></li>
-       <li><a href="/addintel">Add intel/scans</a></li>
-       <li><a href="/launchConfirmation">Launch confirmation</a></li>
+       <li><a href="/members/points">Top members</a></li>
+       <li><a href="/members/addintel">Add intel/scans</a></li>
+       <li><a href="/members/launchConfirmation">Launch confirmation</a></li>
        <li><a href="/covop">CovOp targets</a></li>
        <li><a href="/covop?list=distwhores">Distwhores</a></li>
-       <li><a href="/defrequest">Request defense</a></li>
+       <li><a href="/members/defrequest">Request defense</a></li>
 </ul>
        [% ELSE %]
                [% IF c.user.planet %]
        <p><b>Update your fleet to see member menu</b></p>
                [% ELSE %]
-       <form action="/main/setcoords" method="post">
+       <form action="/members/setcoords" method="post">
                <p>We need your planet's coordinates: 
                <input type="text" name="planet" value="">
                <input type="submit" value="Submit">
diff --git a/root/src/members/points.tt2 b/root/src/members/points.tt2
new file mode 100644 (file)
index 0000000..01c9ff5
--- /dev/null
@@ -0,0 +1,23 @@
+[% META title = 'Top members' %]
+<table>
+       <tr>
+       <th>User</th>
+       <th><a href="[% c.uri_for('points','total_points') %]">Total</a></th>
+       <th><a href="[% c.uri_for('points','defense_points') %]">Defenses</a></th>
+       <th><a href="[% c.uri_for('points','attack_points') %]">Attacks</a></th>
+       <th><a href="[% c.uri_for('points','raid_points') %]">Raid</a></th>
+       <th><a href="[% c.uri_for('points','scan_points') %]">Scans</a></th>
+       <th><a href="[% c.uri_for('points','humor_points') %]">Humor</a></th>
+       </tr>
+[% FOR m IN members %]
+       <tr class="[% loop.count % 2 == 0 ? 'even' : 'odd' %]">
+       <td>[% m.username %]</td>
+       <td>[% m.total_points %]</td>
+       <td>[% m.defense_points %]</td>
+       <td>[% m.attack_points %]</td>
+       <td>[% m.raid_points %]</td>
+       <td>[% m.scan_points %]</td>
+       <td>[% m.humor_points %]</td>
+       </tr>
+[% END %]
+</table>
diff --git a/t/controller_Members.t b/t/controller_Members.t
new file mode 100644 (file)
index 0000000..87ee870
--- /dev/null
@@ -0,0 +1,10 @@
+use strict;
+use warnings;
+use Test::More tests => 3;
+
+BEGIN { use_ok 'Catalyst::Test', 'NDWeb' }
+BEGIN { use_ok 'NDWeb::Controller::Members' }
+
+ok( request('/members')->is_success, 'Request should succeed' );
+
+
diff --git a/templates/points.tmpl b/templates/points.tmpl
deleted file mode 100644 (file)
index 9136843..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<table>
-       <tr>
-       <th>User</th>
-       <th><a href="/<TMPL_VAR NAME=PAGE>?type=total">Total</a></th>
-       <th><a href="/<TMPL_VAR NAME=PAGE>?type=defense">Defenses</a></th>
-       <th><a href="/<TMPL_VAR NAME=PAGE>?type=attack">Attacks</a></th>
-       <th><a href="/<TMPL_VAR NAME=PAGE>?type=raid">Raid</a></th>
-       <th><a href="/<TMPL_VAR NAME=PAGE>?type=scan">Scans</a></th>
-       <th><a href="/<TMPL_VAR NAME=PAGE>?type=humor">Humor</a></th>
-       <th><a href="/<TMPL_VAR NAME=PAGE>?type=rank">ND Rank</a></th>
-       </tr>
-       <TMPL_LOOP Members>
-       <tr class="<TMPL_IF __odd__>odd<TMPL_ELSE>even</TMPL_IF>">
-       <td><TMPL_VAR NAME=Username></td>
-       <td><TMPL_VAR NAME=Total></td>
-       <td><TMPL_VAR NAME=Defense></td>
-       <td><TMPL_VAR NAME=Attack></td>
-       <td><TMPL_VAR NAME=Raid></td>
-       <td><TMPL_VAR NAME=Scan></td>
-       <td><TMPL_VAR NAME=Humor></td>
-       <td><TMPL_VAR NAME=Rank></td>
-       </tr>
-       </TMPL_LOOP>
-</table>