From 02c7aaff53da28137793c89c32d9994b93db61fb Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Wed, 25 Jun 2008 01:09:03 +0200 Subject: [PATCH] Top members converted --- NDWeb/Pages/Points.pm | 68 --------------------------------- database/group_roles.sql | 9 +++++ lib/NDWeb.pm | 1 + lib/NDWeb/Controller/Members.pm | 63 ++++++++++++++++++++++++++++++ root/lib/site/leftbar.tt2 | 10 ++--- root/src/members/points.tt2 | 23 +++++++++++ t/controller_Members.t | 10 +++++ templates/points.tmpl | 24 ------------ 8 files changed, 111 insertions(+), 97 deletions(-) delete mode 100644 NDWeb/Pages/Points.pm create mode 100644 lib/NDWeb/Controller/Members.pm create mode 100644 root/src/members/points.tt2 create mode 100644 t/controller_Members.t delete mode 100644 templates/points.tmpl diff --git a/NDWeb/Pages/Points.pm b/NDWeb/Pages/Points.pm deleted file mode 100644 index 250900b..0000000 --- a/NDWeb/Pages/Points.pm +++ /dev/null @@ -1,68 +0,0 @@ -#************************************************************************** -# Copyright (C) 2006 by Michael Andreen * -# * -# 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; diff --git a/database/group_roles.sql b/database/group_roles.sql index d6b9628..3ae93d4 100644 --- a/database/group_roles.sql +++ b/database/group_roles.sql @@ -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'); diff --git a/lib/NDWeb.pm b/lib/NDWeb.pm index bf88819..238e5f4 100644 --- a/lib/NDWeb.pm +++ b/lib/NDWeb.pm @@ -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 index 0000000..e25a69b --- /dev/null +++ b/lib/NDWeb/Controller/Members.pm @@ -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; diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index be71cf3..450cfdc 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -28,18 +28,18 @@ [% IF user.attacker %]

Member menu

[% ELSE %] [% IF c.user.planet %]

Update your fleet to see member menu

[% ELSE %] -
+

We need your planet's coordinates: diff --git a/root/src/members/points.tt2 b/root/src/members/points.tt2 new file mode 100644 index 0000000..01c9ff5 --- /dev/null +++ b/root/src/members/points.tt2 @@ -0,0 +1,23 @@ +[% META title = 'Top members' %] + + + + + + + + + + +[% FOR m IN members %] + + + + + + + + + +[% END %] +
UserTotalDefensesAttacksRaidScansHumor
[% m.username %][% m.total_points %][% m.defense_points %][% m.attack_points %][% m.raid_points %][% m.scan_points %][% m.humor_points %]
diff --git a/t/controller_Members.t b/t/controller_Members.t new file mode 100644 index 0000000..87ee870 --- /dev/null +++ b/t/controller_Members.t @@ -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 index 9136843..0000000 --- a/templates/points.tmpl +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - -
UserTotalDefensesAttacksRaidScansHumorND Rank
-- 2.39.2