diff options
author | Matthew Somerville <matthew@mysociety.org> | 2011-06-09 00:59:23 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2011-06-09 00:59:23 +0100 |
commit | ba0bd42476b93908529f63bb8b71135ebf7a86ca (patch) | |
tree | d9376ff3c5b8b6f75e3ab92c7ec5d1cbc99f553f /perllib/FixMyStreet/DB/ResultSet/Problem.pm | |
parent | 8756c80504ceb6275f637c75fdcf1a047970d6ff (diff) |
Move the tricky nearby DB call to its own Result/ResultSet, and move more functions.
Diffstat (limited to 'perllib/FixMyStreet/DB/ResultSet/Problem.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/ResultSet/Problem.pm | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm index af850ecd0..ea146cd54 100644 --- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm +++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm @@ -63,6 +63,29 @@ sub recent { return $result; } +# Problems around a location + +sub around_map { + my ( $rs, $min_lat, $max_lat, $min_lon, $max_lon, $interval, $limit ) = @_; + my $attr = { + order_by => { -desc => 'created' }, + columns => [ + 'id', 'title' ,'latitude', 'longitude', 'state', 'confirmed' + ], + }; + $attr->{rows} = $limit if $limit; + + my $q = { + state => [ 'confirmed', 'fixed' ], + latitude => { '>=', $min_lat, '<', $max_lat }, + longitude => { '>=', $min_lon, '<', $max_lon }, + }; + $q->{'current_timestamp - lastupdate'} = { '<', \"'$interval'::interval" }; + + my @problems = mySociety::Locale::in_gb_locale { $rs->search( $q, $attr )->all }; + return \@problems; +} + # Admin functions sub timeline { |