]> ruin.nu Git - ndwebbie.git/blobdiff - lib/NDWeb/Controller/Calls.pm
Minor fixes to remove some warnings
[ndwebbie.git] / lib / NDWeb / Controller / Calls.pm
index cf468a88aaaa4701ed3730d5f883879e32997277..cbb78da89284aefc63a5e27bc4e8440930a6f254 100644 (file)
@@ -57,10 +57,10 @@ sub list : Local {
                        ,(0.2*(attack_points/a.attack)+ 0.4*(defense_points/a.defense)
                                + 0.2*(c.size/a.size) + 0.05*(c.score/a.score)
                                + 0.15*(c.value/a.value))::Numeric(3,2) AS defprio
-                       ,array_accum(race::text) AS race
-                       ,array_accum(amount) AS amount
-                       ,array_accum(eta) AS eta
-                       ,array_accum(shiptype) AS shiptype
+                       ,array_accum(COALESCE(race::text,'')) AS race
+                       ,array_accum(COALESCE(amount,0)) AS amount
+                       ,array_accum(COALESCE(eta,0)) AS eta
+                       ,array_accum(COALESCE(shiptype,'')) AS shiptype
                        ,array_accum(COALESCE(alliance,'?')) AS alliance
                        ,array_accum(coords) AS attackers
                FROM (SELECT c.id, p.x,p.y,p.z,p.id AS planet, p.size, p.value, p.score
@@ -196,7 +196,6 @@ sub edit : Local {
                        }
                        push @missions,$mission;
                }
-               delete $attacker->{planet};
                $attacker->{missions} = \@missions;
                push @attackers,$attacker;
        }
@@ -205,6 +204,28 @@ sub edit : Local {
        $c->forward('/forum/findPosts',[$call->{ftid}]);
 }
 
+sub defleeches : Local {
+       my ( $self, $c, $type ) = @_;
+       my $dbh = $c->model;
+
+       my $query = $dbh->prepare(q{SELECT username,defense_points,count(id) AS calls
+               , SUM(fleets) AS fleets, SUM(recalled) AS recalled
+               FROM (SELECT username,defense_points,c.id,count(f.target) AS fleets
+                       , count(NULLIF(f.tick + f.eta -1 = f.back,TRUE)) AS recalled
+                       FROM users u JOIN calls c ON c.member = u.uid
+                               LEFT OUTER JOIN fleets f ON u.planet = f.target
+                                       AND c.landing_tick = f.tick
+                       WHERE (f.mission = 'Defend' AND f.uid > 0 AND f.back IS NOT NULL AND NOT ingal)
+                               OR f.target IS NULL
+                       GROUP BY username,defense_points,c.id
+               ) d
+               GROUP BY username,defense_points ORDER BY fleets DESC, defense_points
+               });
+       $query->execute;
+
+       $c->stash(members => $query->fetchall_arrayref({}) );
+}
+
 sub postcallcomment : Local {
        my ($self, $c, $call) = @_;
 
@@ -308,7 +329,7 @@ sub findCall : Private {
 
        my $query = $dbh->prepare(q{
                SELECT c.id, coords(p.x,p.y,p.z), c.landing_tick, c.info, covered
-                       ,open, dc.username AS dc, u.defense_points,c.member
+                       ,open, dc.username AS dc, u.defense_points,c.member AS uid
                        ,u.planet, u.username AS member, u.sms,c.ftid
                FROM calls c 
                JOIN users u ON c.member = u.uid
@@ -318,7 +339,7 @@ sub findCall : Private {
                });
        $call = $dbh->selectrow_hashref($query,undef,$call);
 
-       $c->assert_user_roles(qw/calls_edit/) unless $c->user->id == $call->{member};
+       $c->assert_user_roles(qw/calls_edit/) unless $c->user->id == $call->{uid};
        $c->stash(call => $call);
 }