From a399becb6b6f5178faa2197c37b369ecbf3a9248 Mon Sep 17 00:00:00 2001 From: Michael Andreen Date: Thu, 6 Nov 2008 19:54:43 +0100 Subject: [PATCH] Search for intel by nick --- lib/NDWeb/Controller/Intel.pm | 13 +++++++++++++ root/src/intel/find.tt2 | 15 ++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/NDWeb/Controller/Intel.pm b/lib/NDWeb/Controller/Intel.pm index 55f6643..fd84472 100644 --- a/lib/NDWeb/Controller/Intel.pm +++ b/lib/NDWeb/Controller/Intel.pm @@ -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); + } } } diff --git a/root/src/intel/find.tt2 b/root/src/intel/find.tt2 index 55a9e50..dd356b6 100644 --- a/root/src/intel/find.tt2 +++ b/root/src/intel/find.tt2 @@ -1,9 +1,22 @@ [% META title = 'Find' %] -

Could not find: "[% c.req.param('coords') | html %]"

+

Could not find a single planet matching: "[% searchterm | html %]"

+ +[% IF planets %] + + + [% FOR p IN planets %] + + + + + [% END %] +
CoordsNick
[% p.coords %][% p.nick %]
+[% END %]

The following syntaxes are possible:

-- 2.39.2