]> ruin.nu Git - ndwebbie.git/commitdiff
Converted hostileAlliances
authorMichael Andreen <harv@ruin.nu>
Wed, 16 Jul 2008 18:11:25 +0000 (20:11 +0200)
committerMichael Andreen <harv@ruin.nu>
Wed, 16 Jul 2008 18:11:25 +0000 (20:11 +0200)
NDWeb/Pages/HostileAlliances.pm [deleted file]
database/group_roles.sql
lib/NDWeb.pm
lib/NDWeb/Controller/Alliances.pm
root/lib/site/leftbar.tt2
root/src/alliances/hostile.tt2 [new file with mode: 0644]
templates/hostileAlliances.tmpl [deleted file]

diff --git a/NDWeb/Pages/HostileAlliances.pm b/NDWeb/Pages/HostileAlliances.pm
deleted file mode 100644 (file)
index 703e8b7..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::HostileAlliances;
-use strict;
-use warnings FATAL => 'all';
-use ND::Include;
-use CGI qw/:standard/;
-use NDWeb::Include;
-
-use base qw/NDWeb::XMLPage/;
-
-$NDWeb::Page::PAGES{hostileAlliances} = __PACKAGE__;
-
-sub render_body {
-       my $self = shift;
-       my ($BODY) = @_;
-       $self->{TITLE} = 'Hostile Alliances';
-       my $DBH = $self->{DBH};
-
-       return $self->noAccess unless $self->isHC;
-
-       my $begintick = 0;
-       my $endtick = $self->{TICK};
-       if (param('ticks')){
-               $begintick = $endtick - param('ticks');
-       }elsif(defined param('begintick') && defined param('endtick')){
-               $begintick = param('begintick');
-               $endtick = param('endtick');
-
-       }
-       my $query = $DBH->prepare(q{
-               SELECT s.alliance_id AS id,s.alliance AS name,count(*) AS hostilecount
-FROM calls c 
-       JOIN incomings i ON i.call = c.id
-       JOIN current_planet_stats s ON i.sender = s.id
-WHERE c.landing_tick - i.eta > $1 and c.landing_tick - i.eta < $2
-GROUP BY s.alliance_id,s.alliance
-ORDER BY hostilecount DESC
-               })or $ND::ERROR .= $DBH->errstr;
-       $query->execute($begintick,$endtick) or $ND::ERROR .= $DBH->errstr;
-       my @alliances;
-       my $tick = $self->{TICK};
-       while (my $alliance = $query->fetchrow_hashref){
-               push @alliances, $alliance;
-       }
-       $BODY->param(Alliances => \@alliances);
-       $BODY->param(Ticks => $endtick - $begintick);
-       $BODY->param(BeginTick =>$begintick);
-       $BODY->param(EndTick =>$endtick);
-       return $BODY;
-}
-1;
index c5bcd3251500285a90eb749453a96c0c7e086e9b..bbb544863a968a70ebd0352eb5508dceef750f40 100644 (file)
@@ -18,6 +18,7 @@ INSERT INTO roles VALUES('no_fleet_update');
 INSERT INTO roles VALUES('admin_users');
 INSERT INTO roles VALUES('rankings_planet_intel');
 INSERT INTO roles VALUES('alliances_resources');
+INSERT INTO roles VALUES('alliances');
 INSERT INTO roles VALUES('graphs_intel');
 INSERT INTO roles VALUES('members');
 INSERT INTO roles VALUES('members_points_nolimit');
@@ -67,6 +68,7 @@ INSERT INTO group_roles (gid,role) VALUES(1,'intel_menu');
 INSERT INTO group_roles (gid,role) VALUES(1,'admin_users');
 INSERT INTO group_roles (gid,role) VALUES(1,'rankings_planet_intel');
 INSERT INTO group_roles (gid,role) VALUES(1,'alliances_resources');
+INSERT INTO group_roles (gid,role) VALUES(1,'alliances');
 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');
@@ -82,6 +84,7 @@ INSERT INTO group_roles (gid,role) VALUES(3,'intel_menu');
 INSERT INTO group_roles (gid,role) VALUES(3,'admin_users');
 INSERT INTO group_roles (gid,role) VALUES(3,'rankings_planet_intel');
 INSERT INTO group_roles (gid,role) VALUES(3,'alliances_resources');
+INSERT INTO group_roles (gid,role) VALUES(3,'alliances');
 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');
index 28191c0465591d97aff89ac1d4458eab603a37b3..819f70e891823f452a840840763faf136074938b 100644 (file)
@@ -71,6 +71,7 @@ __PACKAGE__->setup(qw/
 
 
 __PACKAGE__->deny_access_unless('/users',[qw/admin_users/]);
+__PACKAGE__->deny_access_unless('/alliances',[qw/alliances/]);
 __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/]);
index e82f54270f32cf99a9ef6daa8b734f9842bdc5cc..d7c4257179ac4a33f931e2ae2c542e8af1c481bd 100644 (file)
@@ -27,6 +27,35 @@ sub index :Path :Args(0) {
     $c->response->body('Matched NDWeb::Controller::Alliances in Alliances.');
 }
 
+sub hostile : Local {
+    my ( $self, $c, $order ) = @_;
+       my $dbh = $c->model;
+
+       my $begintick = 0;
+       my $endtick = $c->stash->{TICK};
+       if ($c->req->param('ticks')){
+               $begintick = $endtick - $c->req->param('ticks');
+       }elsif(defined $c->req->param('begintick') && defined $c->req->param('endtick')){
+               $begintick = $c->req->param('begintick');
+               $endtick = $c->req->param('endtick');
+       }
+
+       my $query = $dbh->prepare(q{
+               SELECT s.alliance_id AS id,s.alliance AS name,count(*) AS hostile_count
+FROM calls c 
+       JOIN incomings i ON i.call = c.id
+       JOIN current_planet_stats s ON i.sender = s.id
+WHERE c.landing_tick - i.eta > $1 and c.landing_tick - i.eta < $2
+GROUP BY s.alliance_id,s.alliance
+ORDER BY hostile_count DESC
+               });
+       $query->execute($begintick,$endtick);
+       $c->stash(alliances => $query->fetchall_arrayref({}) );
+       $c->stash(ticks => $endtick - $begintick);
+       $c->stash(begin_tick => $begintick);
+       $c->stash(end_tick => $endtick);
+}
+
 sub resources : Local {
     my ( $self, $c, $order ) = @_;
        my $dbh = $c->model;
index 1adec4ab3d35bf7f4c0378a55767f1ee43daeccc..11598318f3dea2d4af0a4e80432a38274d7a12fa 100644 (file)
@@ -97,7 +97,7 @@
 <ul class="linkbar">
        <li><a href="/users">List users</a></li>
        <li><a href="/alliances">Alliances</a></li>
-       <li><a href="/hostileAlliances">Hostile Alliances</a></li>
+       <li><a href="/alliances/hostile">Hostile Alliances</a></li>
        <li><a href="/memberIntel">Member Intel</a></li>
        <li><a href="/alliances/resources">Alliance resources</a></li>
        <li><a href="/planetNaps">Planet Naps</a></li>
diff --git a/root/src/alliances/hostile.tt2 b/root/src/alliances/hostile.tt2
new file mode 100644 (file)
index 0000000..0996ec6
--- /dev/null
@@ -0,0 +1,23 @@
+[% META title = 'Hostile Alliances' %]
+<form action="[% c.uri_for('hostile') %]" method="post"><p>
+       Show last <input style="width: 4em" type="text" name="ticks" value="[% ticks %]"> ticks
+       <input type="submit" value="Submit">
+       </p>
+</form>
+<form action="[% c.uri_for('hostile') %]" method="post"><p>
+       Show hostile counts between <input style="width: 4em" type="text" name="begintick" value="[% begin_tick %]"> and <input style="width: 4em" type="text" name="endtick" value="[% end_tick %]">
+       <input type="submit" value="Submit">
+       </p>
+</form>
+<table class="stats">
+       <tr>
+               <th>Alliance</th>
+               <th>Hostile Counts</th>
+       </tr>
+[% FOR a IN alliances %]
+       <tr class="[% loop.count % 2 ? 'even' : 'odd' %]">
+               <td><a href="[% c.uri_for('edit',a.id) %]">[% a.name %]</a></td>
+               <td>[% a.hostile_count %]</td>
+       </tr>
+[% END %]
+</table>
diff --git a/templates/hostileAlliances.tmpl b/templates/hostileAlliances.tmpl
deleted file mode 100644 (file)
index bb74b0e..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<form action="/<TMPL_VAR NAME=PAGE>" method="post"><p>
-       Show last <input style="width: 4em" type="text" name="ticks" value="<TMPL_VAR NAME=Ticks>"/> ticks
-       <input type="submit" value="Submit"/>
-       <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
-       </p>
-</form>
-<form action="/<TMPL_VAR NAME=PAGE>" method="post"><p>
-       Show hostile counts between <input style="width: 4em" type="text" name="begintick" value="<TMPL_VAR NAME=BeginTick>"/> and <input style="width: 4em" type="text" name="endtick" value="<TMPL_VAR NAME=EndTick>"/>
-       <input type="submit" value="Submit"/>
-       <input type="hidden" name="page" value="<TMPL_VAR NAME=PAGE>"/>
-       </p>
-</form>
-<table class="stats">
-       <tr>
-               <th>Alliance</th>
-               <th>Hostile Counts</th>
-       </tr>
-<TMPL_LOOP Alliances>
-       <tr class="<TMPL_IF __odd__>odd<TMPL_ELSE>even</TMPL_IF>">
-               <td><a href="/alliances?alliance=<TMPL_VAR NAME=Id>"><TMPL_VAR NAME=Name></a></td>
-               <td><TMPL_VAR NAME=HostileCount></td>
-       </tr>
-</TMPL_LOOP>
-</table>