]> ruin.nu Git - ndwebbie.git/commitdiff
Search for intel by nick
authorMichael Andreen <harv@ruin.nu>
Thu, 6 Nov 2008 18:54:43 +0000 (19:54 +0100)
committerMichael Andreen <harv@ruin.nu>
Thu, 6 Nov 2008 18:54:43 +0000 (19:54 +0100)
lib/NDWeb/Controller/Intel.pm
root/src/intel/find.tt2

index 55f6643ee057f789e51746bff47427703bc32f15..fd844725a0b407eec6ab3f0c7ef69f0eb49f4168 100644 (file)
@@ -159,11 +159,24 @@ 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)}
                        ,undef,$1,$2,$3,$4);
                $c->res->redirect($c->uri_for('planet',$planet));
+       }else{
+               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 55a9e50faad99f01795a62e34c133997784887ae..dd356b649953e84e0e85ef46fc25547e8d21a6d8 100644 (file)
@@ -1,9 +1,22 @@
 [% 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>A nick, with or without wildcard like %</li>
 </ul>