]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Controller/Intel.pm
Added page to list def channels and alliance for planets
[ndwebbie.git] / lib / NDWeb / Controller / Intel.pm
index 94bbfa15841418ccb574ba9ec14ce30046ddbfab..bbdf0f749ad461fb16fd0ffaa1101569ddf60105 100644 (file)
@@ -2,6 +2,7 @@ package NDWeb::Controller::Intel;
 
 use strict;
 use warnings;
+use feature ':5.10';
 use parent 'Catalyst::Controller';
 
 use NDWeb::Include;
@@ -49,7 +50,7 @@ sub index :Path : Args(0) {
                while ($coords =~ m/(\d+:\d+:\d+)/g){
                        push @coords,$1;
                }
-               my $planets = $dbh->prepare(q{SELECT id,coords(x,y,z), alliance
+               my $planets = $dbh->prepare(q{SELECT id,coords(x,y,z), alliance, nick
                        FROM current_planet_stats p
                        WHERE coords(x,y,z) = ANY($1)
                        ORDER BY alliance, p.x, p.y, p.z
@@ -97,6 +98,27 @@ sub planet : Local {
 
 }
 
+sub channels : Local {
+       my ( $self, $c, $order ) = @_;
+       my $dbh = $c->model;
+
+       if ($order ~~ /(alliance|channel)/){
+               $order = "lower($1) ASC";
+       }elsif ($order ~~ /(coords)/){
+               $order = "x,y,z";
+       }else{
+               $order = 'lower(channel)';
+       }
+
+       my $query = $dbh->prepare(q{
+SELECT id,coords(x,y,z),nick,channel,alliance FROM current_planet_stats
+WHERE channel <> '' and channel IS NOT NULL
+ORDER BY } . $order
+       );
+       $query->execute;
+       $c->stash(planets => $query->fetchall_arrayref({}) );
+}
+
 sub postplanetcomment : Local {
        my ($self, $c, $p) = @_;