aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/Page.pm47
-rw-r--r--perllib/Problems.pm16
-rwxr-xr-xweb/ajax.cgi4
-rwxr-xr-xweb/index.cgi4
4 files changed, 27 insertions, 44 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm
index bd6d9253c..cad967593 100644
--- a/perllib/Page.pm
+++ b/perllib/Page.pm
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Page.pm,v 1.122 2008-10-15 22:07:25 matthew Exp $
+# $Id: Page.pm,v 1.123 2008-10-17 18:55:16 matthew Exp $
#
package Page;
@@ -359,7 +359,7 @@ sub display_pin {
}
sub map_pins {
- my ($q, $x, $y, $sx, $sy) = @_;
+ my ($q, $x, $y, $sx, $sy, $interval) = @_;
my $pins = '';
my $min_e = Page::tile_to_os($x-2); # Extra space to left/below due to rounding, I think
@@ -373,49 +373,30 @@ sub map_pins {
my $max_e = Page::tile_to_os($x+3);
my $max_n = Page::tile_to_os($y+3);
- my $around_map = Problems::around_map($min_e, $max_e, $min_n, $max_n);
+ my $around_map = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval);
my @ids = ();
- #my $count_prob = 1;
- #my $count_fixed = 1;
foreach (@$around_map) {
push(@ids, $_->{id});
my $px = Page::os_to_px($_->{easting}, $sx);
my $py = Page::os_to_px($_->{northing}, $sy, 1);
my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
- $pins .= Page::display_pin($q, $px, $py, $col); # , $count_prob++);
+ $pins .= Page::display_pin($q, $px, $py, $col);
}
my ($lat, $lon) = mySociety::GeoUtil::national_grid_to_wgs84($mid_e, $mid_n, 'G');
my $dist = mySociety::Gaze::get_radius_containing_population($lat, $lon, 200000);
$dist = int($dist*10+0.5)/10;
- # XXX: Change to only show problems with extract(epoch from ms_current_timestamp()-lastupdate) < 8 weeks
- # And somehow display/link to old problems somewhere else...
- my $nearby = [];
- #if (@$current_map < 9) {
- my $limit = 20; # - @$current_map;
- $nearby = Problems::nearby($dist, join(',', @ids), $limit, $mid_e, $mid_n);
- foreach (@$nearby) {
- my $px = Page::os_to_px($_->{easting}, $sx);
- my $py = Page::os_to_px($_->{northing}, $sy, 1);
- my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
- $pins .= Page::display_pin($q, $px, $py, $col); #, $count_prob++);
- }
- #} else {
- # @$current_map = @$current_map[0..8];
- #}
-
- #my $fixed = Problems::fixed_nearby($dist, $mid_e, $mid_n);
- #foreach (@$fixed) {
- # my $px = Page::os_to_px($_->{easting}, $sx);
- # my $py = Page::os_to_px($_->{northing}, $sy, 1);
- # $pins .= Page::display_pin($q, $px, $py, 'green'); # , $count_fixed++);
- #}
- #if (@$fixed > 9) {
- # @$fixed = @$fixed[0..8];
- #}
-
- return ($pins, $around_map, $nearby, $dist); # , $current_map, $current, '', $dist); # $fixed, $dist);
+ my $limit = 20; # - @$current_map;
+ my $nearby = Problems::nearby($dist, join(',', @ids), $limit, $mid_e, $mid_n, $interval);
+ foreach (@$nearby) {
+ my $px = Page::os_to_px($_->{easting}, $sx);
+ my $py = Page::os_to_px($_->{northing}, $sy, 1);
+ my $col = $_->{state} eq 'fixed' ? 'green' : 'red';
+ $pins .= Page::display_pin($q, $px, $py, $col);
+ }
+
+ return ($pins, $around_map, $nearby, $dist);
}
sub compass ($$$) {
diff --git a/perllib/Problems.pm b/perllib/Problems.pm
index 2c01b456d..6c29a256e 100644
--- a/perllib/Problems.pm
+++ b/perllib/Problems.pm
@@ -6,7 +6,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: Problems.pm,v 1.7 2008-09-19 10:24:55 matthew Exp $
+# $Id: Problems.pm,v 1.8 2008-10-17 18:55:16 matthew Exp $
#
package Problems;
@@ -127,22 +127,24 @@ sub recent {
# Problems around a location
sub around_map {
- my ($min_e, $max_e, $min_n, $max_n) = @_;
+ my ($min_e, $max_e, $min_n, $max_n, $interval) = @_;
select_all(
"select id,title,easting,northing,state from problem
where state in ('confirmed', 'fixed')
- and easting>=? and easting<? and northing>=? and northing<?
- $site_restriction
+ and easting>=? and easting<? and northing>=? and northing<? " .
+ ($interval ? " and ms_current_timestamp()-lastupdate < '$interval'::interval" : '') .
+ " $site_restriction
order by created desc", $min_e, $max_e, $min_n, $max_n);
}
sub nearby {
- my ($dist, $ids, $limit, $mid_e, $mid_n) = @_;
+ my ($dist, $ids, $limit, $mid_e, $mid_n, $interval) = @_;
select_all(
"select id, title, easting, northing, distance, state
from problem_find_nearby(?, ?, $dist) as nearby, problem
- where nearby.problem_id = problem.id
- and state in ('confirmed', 'fixed')" . ($ids ? ' and id not in (' . $ids . ')' : '') . "
+ where nearby.problem_id = problem.id " .
+ ($interval ? " and ms_current_timestamp()-lastupdate < '$interval'::interval" : '') .
+ " and state in ('confirmed', 'fixed')" . ($ids ? ' and id not in (' . $ids . ')' : '') . "
$site_restriction
order by distance, created desc limit $limit", $mid_e, $mid_n);
}
diff --git a/web/ajax.cgi b/web/ajax.cgi
index 0a79fee6c..b7adb177a 100755
--- a/web/ajax.cgi
+++ b/web/ajax.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: ajax.cgi,v 1.4 2008-10-09 14:20:54 matthew Exp $
+# $Id: ajax.cgi,v 1.5 2008-10-17 18:55:16 matthew Exp $
use strict;
use Standard;
@@ -31,7 +31,7 @@ sub main {
$sx ||= 0; $sx += 0;
$sy ||= 0; $sy += 0;
- my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $sx, $sy);
+ my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $sx, $sy, '6 months');
my $list = '';
foreach (@$on_map) {
diff --git a/web/index.cgi b/web/index.cgi
index 8965c2cf1..5f36e38aa 100755
--- a/web/index.cgi
+++ b/web/index.cgi
@@ -6,7 +6,7 @@
# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
# Email: matthew@mysociety.org. WWW: http://www.mysociety.org
#
-# $Id: index.cgi,v 1.219 2008-10-13 14:06:44 matthew Exp $
+# $Id: index.cgi,v 1.220 2008-10-17 18:55:16 matthew Exp $
use strict;
use Standard;
@@ -721,7 +721,7 @@ sub display_location {
return Page::geocode_choice($error, '/') if (ref($error) eq 'ARRAY');
return front_page($q, $error) if ($error);
- my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $x, $y);
+ my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $x, $y, '6 months');
my $out = Page::display_map($q, x => $x, y => $y, type => 1, pins => $pins );
$out .= $q->h1(_('Problems in this area'));
my $email_me = _('Email me new local problems');