]> ruin.nu Git - ndwebbie.git/commitdiff
Search for planet stats by nick
authorMichael Andreen <harv@ruin.nu>
Thu, 6 Nov 2008 18:50:04 +0000 (19:50 +0100)
committerMichael Andreen <harv@ruin.nu>
Thu, 6 Nov 2008 18:53:25 +0000 (19:53 +0100)
database/group_roles.sql
lib/NDWeb/Controller/Stats.pm
root/src/stats/find.tt2

index b18c28563f694d2f223dcef942235dc24866637e..e14d9d13775c33c99a6cfd74a77bb4a698832c8d 100644 (file)
@@ -38,6 +38,7 @@ INSERT INTO roles VALUES('intel_members');
 INSERT INTO roles VALUES('intel_member');
 INSERT INTO roles VALUES('intel_naps');
 INSERT INTO roles VALUES('textexport_alliance');
+INSERT INTO roles VALUES('stats_find_nick');
 
 INSERT INTO group_roles (gid,role) VALUES(2,'member_menu');
 INSERT INTO group_roles (gid,role) VALUES(2,'attack_menu');
@@ -64,6 +65,7 @@ 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(9,'stats_intel');
+INSERT INTO group_roles (gid,role) VALUES(9,'stats_find_nick');
 
 INSERT INTO group_roles (gid,role) VALUES(1,'dc_menu');
 INSERT INTO group_roles (gid,role) VALUES(1,'bc_menu');
index 63ad6d781dc6828ac64b6296d9723d35114eaf66..1c52a02c62c911bd8cd0733a32edfbcc67afd8ab 100644 (file)
@@ -210,6 +210,7 @@ sub find : Local {
        my $dbh = $c->model;
 
        local $_ = $find || $c->req->param('coords');
+       $c->stash(searchterm => $_);
 
        if (/(\d+)(?: |:)(\d+)(?: |:)(\d+)(?:(?: |:)(\d+))?/){
                my $planet = $dbh->selectrow_array(q{SELECT planetid($1,$2,$3,$4)}
@@ -217,8 +218,19 @@ sub find : Local {
                $c->res->redirect($c->uri_for('planet',$planet));
        }elsif (/(\d+)(?: |:)(\d+)/){
                $c->res->redirect($c->uri_for('galaxy',$1,$2));
+       }elsif($c->check_user_roles(qw/stats_find_nick/)) {
+               my $query = $dbh->prepare(q{SELECT id,coords(x,y,z),nick
+                       FROM current_planet_stats p
+                       WHERE nick ilike $1
+               });
+               $query->execute($_);
+               my $planets = $query->fetchall_arrayref({});
+               if (@{$planets} == 1){
+                       $c->res->redirect($c->uri_for('planet',$planets->[0]->{id}));
+               }else{
+                       $c->stash(planets => $planets);
+               }
        }
-
 }
 
 
index 1e7402b9ffea735615198bda0218e913443a7a4e..e64e55d1a2f54524d012b44ff932824b78b699a9 100644 (file)
@@ -1,10 +1,27 @@
 [% META title = 'Find' %]
 
-<p>Could not find: &quot;[% c.req.param('coords') | html %]&quot;</p>
+<p>Could not find a single planet matching: &quot;[% searchterm | html %]&quot;</p>
+
+[% IF planets %]
+<table>
+       <tr><th>Coords</th><th>Nick</th></tr>
+       [% FOR p IN planets %]
+       <tr>
+               <td><a href="[% c.uri_for('planet',p.id) %]">[% p.coords %]</a></td>
+               <td>[% p.nick %]</td>
+       </tr>
+       [% END %]
+</table>
+[% END %]
+
 
 <p>The following syntaxes are possible:</p>
 <ul>
        <li>X:Y:Z tick (i.e. &quot;1:1:1 37&quot;) Finds the planet that had the coords at the specified tick</li>
        <li>X:Y:Z (i.e.  &quot;1:1:1&quot;) Finds the planet that had the coords at the current tick</li>
        <li>X:Y (i.e.  &quot;1:1&quot;) Finds a galaxy</li>
+       [% IF c.check_user_roles('stats_find_nick') %]
+       <li>A nick, with or without wildcard like %</li>
+       [% END %]
 </ul>
+