+++ /dev/null
-#**************************************************************************
-# 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;
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');
__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
--- /dev/null
+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;
[% 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">
--- /dev/null
+[% 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>
--- /dev/null
+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' );
+
+
+++ /dev/null
-<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>