From e3d87e31652374c184db31c915814f8bc4d7cbd4 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Tue, 15 Jul 2008 17:15:31 +0200 Subject: [PATCH] Converted def leeches --- NDWeb/Pages/DefLeeches.pm | 58 ----------------------------------- database/group_roles.sql | 4 +++ lib/NDWeb.pm | 1 + lib/NDWeb/Controller/Calls.pm | 22 +++++++++++++ root/lib/site/leftbar.tt2 | 2 +- root/src/calls/defleeches.tt2 | 19 ++++++++++++ templates/defLeeches.tmpl | 19 ------------ 7 files changed, 47 insertions(+), 78 deletions(-) delete mode 100644 NDWeb/Pages/DefLeeches.pm create mode 100644 root/src/calls/defleeches.tt2 delete mode 100644 templates/defLeeches.tmpl diff --git a/NDWeb/Pages/DefLeeches.pm b/NDWeb/Pages/DefLeeches.pm deleted file mode 100644 index d187bb6..0000000 --- a/NDWeb/Pages/DefLeeches.pm +++ /dev/null @@ -1,58 +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::DefLeeches; -use strict; -use warnings FATAL => 'all'; -use CGI qw/:standard/; -use NDWeb::Include; - -use base qw/NDWeb::XMLPage/; - -$NDWeb::Page::PAGES{defLeeches} = __PACKAGE__; - - -sub render_body { - my $self = shift; - my ($BODY) = @_; - $self->{TITLE} = 'Def Leeches'; - my $DBH = $self->{DBH}; - - return $self->noAccess unless $self->isDC; - - my $query = $DBH->prepare(q{SELECT username,defense_points,count(id) AS calls, SUM(fleets) AS fleets, SUM(recalled) AS recalled - FROM (SELECT username,defense_points,c.id,count(f.target) AS fleets, count(NULLIF(f.tick + f.eta -1 = f.back,TRUE)) AS recalled - FROM users u JOIN calls c ON c.member = u.uid LEFT OUTER JOIN fleets f ON u.planet = f.target AND c.landing_tick = f.tick - WHERE (f.mission = 'Defend' AND f.uid > 0 AND f.back IS NOT NULL AND NOT ingal) - OR f.target IS NULL - GROUP BY username,defense_points,c.id - ) d - GROUP BY username,defense_points ORDER BY fleets DESC, defense_points - }); - $query->execute; - - my @members; - while ( my $member = $query->fetchrow_hashref){ - push @members,$member; - } - $BODY->param(Members => \@members); - return $BODY; -} - -1; diff --git a/database/group_roles.sql b/database/group_roles.sql index fa2fd16..c5bcd32 100644 --- a/database/group_roles.sql +++ b/database/group_roles.sql @@ -24,6 +24,7 @@ INSERT INTO roles VALUES('members_points_nolimit'); INSERT INTO roles VALUES('covop'); INSERT INTO roles VALUES('calls_list'); INSERT INTO roles VALUES('calls_edit'); +INSERT INTO roles VALUES('calls_leeches'); INSERT INTO roles VALUES('raids_info'); INSERT INTO roles VALUES('raids_edit'); INSERT INTO roles VALUES('stats_intel'); @@ -45,6 +46,7 @@ INSERT INTO group_roles (gid,role) VALUES(2,'stats_planetdata'); INSERT INTO group_roles (gid,role) VALUES(6,'dc_menu'); INSERT INTO group_roles (gid,role) VALUES(6,'calls_list'); INSERT INTO group_roles (gid,role) VALUES(6,'calls_edit'); +INSERT INTO group_roles (gid,role) VALUES(6,'calls_leeches'); INSERT INTO group_roles (gid,role) VALUES(4,'bc_menu'); INSERT INTO group_roles (gid,role) VALUES(4,'raids_info'); @@ -68,6 +70,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'alliances_resources'); INSERT INTO group_roles (gid,role) VALUES(1,'graphs_intel'); INSERT INTO group_roles (gid,role) VALUES(1,'calls_list'); INSERT INTO group_roles (gid,role) VALUES(1,'calls_edit'); +INSERT INTO group_roles (gid,role) VALUES(1,'calls_leeches'); INSERT INTO group_roles (gid,role) VALUES(1,'raids_info'); INSERT INTO group_roles (gid,role) VALUES(1,'raids_edit'); INSERT INTO group_roles (gid,role) VALUES(1,'intel'); @@ -82,6 +85,7 @@ INSERT INTO group_roles (gid,role) VALUES(3,'alliances_resources'); INSERT INTO group_roles (gid,role) VALUES(3,'graphs_intel'); INSERT INTO group_roles (gid,role) VALUES(3,'calls_list'); INSERT INTO group_roles (gid,role) VALUES(3,'calls_edit'); +INSERT INTO group_roles (gid,role) VALUES(3,'calls_leeches'); INSERT INTO group_roles (gid,role) VALUES(3,'raids_info'); INSERT INTO group_roles (gid,role) VALUES(3,'raids_edit'); INSERT INTO group_roles (gid,role) VALUES(3,'intel'); diff --git a/lib/NDWeb.pm b/lib/NDWeb.pm index 4edbcd0..d2f1517 100644 --- a/lib/NDWeb.pm +++ b/lib/NDWeb.pm @@ -77,6 +77,7 @@ __PACKAGE__->deny_access_unless('/calls/list',[qw/calls_list/]); __PACKAGE__->deny_access_unless('/calls/postcallcomment',[qw/calls_edit/]); __PACKAGE__->deny_access_unless('/calls/postcallupdate',[qw/calls_edit/]); __PACKAGE__->deny_access_unless('/calls/postattackerupdate',[qw/calls_edit/]); +__PACKAGE__->deny_access_unless('/calls/defleeches',[qw/calls_leeches/]); __PACKAGE__->deny_access_unless('/raids',[qw/raids_edit/]); __PACKAGE__->allow_access_if('/raids/index',1); __PACKAGE__->allow_access_if('/raids/view',1); diff --git a/lib/NDWeb/Controller/Calls.pm b/lib/NDWeb/Controller/Calls.pm index cf468a8..eca27be 100644 --- a/lib/NDWeb/Controller/Calls.pm +++ b/lib/NDWeb/Controller/Calls.pm @@ -205,6 +205,28 @@ sub edit : Local { $c->forward('/forum/findPosts',[$call->{ftid}]); } +sub defleeches : Local { + my ( $self, $c, $type ) = @_; + my $dbh = $c->model; + + my $query = $dbh->prepare(q{SELECT username,defense_points,count(id) AS calls + , SUM(fleets) AS fleets, SUM(recalled) AS recalled + FROM (SELECT username,defense_points,c.id,count(f.target) AS fleets + , count(NULLIF(f.tick + f.eta -1 = f.back,TRUE)) AS recalled + FROM users u JOIN calls c ON c.member = u.uid + LEFT OUTER JOIN fleets f ON u.planet = f.target + AND c.landing_tick = f.tick + WHERE (f.mission = 'Defend' AND f.uid > 0 AND f.back IS NOT NULL AND NOT ingal) + OR f.target IS NULL + GROUP BY username,defense_points,c.id + ) d + GROUP BY username,defense_points ORDER BY fleets DESC, defense_points + }); + $query->execute; + + $c->stash(members => $query->fetchall_arrayref({}) ); +} + sub postcallcomment : Local { my ($self, $c, $call) = @_; diff --git a/root/lib/site/leftbar.tt2 b/root/lib/site/leftbar.tt2 index fc7258c..0926e50 100644 --- a/root/lib/site/leftbar.tt2 +++ b/root/lib/site/leftbar.tt2 @@ -72,7 +72,7 @@ [% IF c.check_user_roles("dc_menu") %]

DC menu