diff options
-rw-r--r-- | perllib/Page.pm | 27 | ||||
-rw-r--r-- | perllib/Problems.pm | 117 | ||||
-rwxr-xr-x | web/ajax.cgi | 4 | ||||
-rwxr-xr-x | web/index.cgi | 4 |
4 files changed, 120 insertions, 32 deletions
diff --git a/perllib/Page.pm b/perllib/Page.pm index c7d8f66b5..86b54c731 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.205 2009-11-11 16:03:26 louise Exp $ +# $Id: Page.pm,v 1.206 2009-11-16 10:55:42 louise Exp $ # package Page; @@ -532,8 +532,9 @@ sub map_pins { #my $map_rn = Page::tile_to_os($y+2); 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, $interval); + my $cobrand = Page::get_cobrand($q); + my $around_limit = Cobrand::on_map_list_limit($cobrand); + my $around_map = Problems::around_map($min_e, $max_e, $min_n, $max_n, $interval, $around_limit); my @ids = (); foreach (@$around_map) { push(@ids, $_->{id}); @@ -1052,24 +1053,4 @@ sub scambs_categories { 'Litter', 'Neighbourhood noise'); } -=item apply_on_map_list_limit ON_MAP AROUND_MAP LIMIT - -Apply any defined limit to the list of reports on the map, moving any extra items to the -'around the map' list - -=cut -sub apply_on_map_list_limit { - my ($on_map, $around_map, $limit) = @_; - my $on_map_size = scalar @{$on_map}; - if (!$limit || $limit >= $on_map_size){ - return ($on_map, $around_map); - } - my @on_map = @$on_map; - my @around_map = @$around_map; - my @extras = @on_map[$limit..$on_map_size-1]; - @on_map = @on_map[0..$limit-1]; - push (@extras, @around_map); - return (\@on_map, \@extras); -} - 1; diff --git a/perllib/Problems.pm b/perllib/Problems.pm index 251294b63..e4136cdec 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.24 2009-11-12 14:39:06 louise Exp $ +# $Id: Problems.pm,v 1.25 2009-11-16 10:55:42 louise Exp $ # package Problems; @@ -20,6 +20,7 @@ use mySociety::MaPit; my $site_restriction = ''; my $site_key = 0; + sub set_site_restriction { my $q = shift; my $site = $q->{site}; @@ -162,14 +163,19 @@ sub front_stats { # Problems around a location sub around_map { - my ($min_e, $max_e, $min_n, $max_n, $interval) = @_; + my ($min_e, $max_e, $min_n, $max_n, $interval, $limit) = @_; + my $limit_clause = ''; + if ($limit) { + $limit_clause = " limit $limit"; + } mySociety::Locale::in_gb_locale { select_all( "select id,title,easting,northing,state from problem where state in ('confirmed', 'fixed') 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); + order by created desc + $limit_clause", $min_e, $max_e, $min_n, $max_n); }; } @@ -273,4 +279,109 @@ sub data_sharing_notification_start { } +# Admin view functions + +=item problem_search SEARCH + +Returns all problems containing the search term in their name, email, title, +detail or council, or whose ID is the search term. Uses any site_restriction +defined by a cobrand. + +=cut +sub problem_search { + my ($search) = @_; + my $search_n = 0; + $search_n = int($search) if $search =~ /^\d+$/; + my $problems = select_all("select id, council, category, title, name, + email, anonymous, cobrand, cobrand_data, created, confirmed, state, service, lastupdate, + whensent, send_questionnaire from problem where (id=? or email ilike + '%'||?||'%' or name ilike '%'||?||'%' or title ilike '%'||?||'%' or + detail ilike '%'||?||'%' or council like '%'||?||'%') + $site_restriction + order by created", $search_n, + $search, $search, $search, $search, $search); + return $problems; +} + +=item update_search SEARCH + +Returns all updates containing the search term in their name, email or text, or whose ID +is the search term. Uses any site_restriction defined by a cobrand. + +=cut +sub update_search { + my ($search) = @_; + my $search_n = 0; + $search_n = int($search) if $search =~ /^\d+$/; + my $updates = select_all("select comment.* from comment, problem where problem.id = comment.problem_id + and (comment.id=? or + problem_id=? or comment.email ilike '%'||?||'%' or comment.name ilike '%'||?||'%' or + comment.text ilike '%'||?||'%') + $site_restriction + order by created", $search_n, $search_n, $search, $search, + $search); +} + +=item update_counts + +An array reference of updates grouped by state. Uses any site_restriction defined by a cobrand. + +=cut + +sub update_counts { + return dbh()->selectcol_arrayref("select comment.state, count(comment.*) as c from comment, problem + where problem.id = comment.problem_id + $site_restriction + group by comment.state", { Columns => [1,2] }); +} + +=item problem_counts + +An array reference of problems grouped by state. Uses any site_restriction defined by a cobrand. + +=cut + +sub problem_counts { + return dbh()->selectcol_arrayref("select state, count(*) as c from problem + where id=id $site_restriction + group by state", { Columns => [1,2] }); +} + +=item + +An array reference of alerts grouped by state (specific to the cobrand if there is one). + +=cut + +sub alert_counts { + my ($cobrand) = @_; + my $cobrand_clause = ''; + if ($cobrand) { + $cobrand_clause = " where cobrand = '$cobrand'"; + } + return dbh()->selectcol_arrayref("select confirmed, count(*) as c + from alert + $cobrand_clause + group by confirmed", { Columns => [1,2] }); +} + +=item + +An array reference of questionnaires. Restricted to questionnaires related to +problems submitted through the cobrand if a cobrand is specified. + +=cut +sub questionnaire_counts { + my ($cobrand) = @_; + my $cobrand_clause = ''; + if ($cobrand) { + $cobrand_clause = " and cobrand = '$cobrand'"; + } + my $questionnaires = dbh()->selectcol_arrayref("select (whenanswered is not null), count(questionnaire.*) as c + from questionnaire, problem + where problem.id = questionnaire.problem_id + $cobrand_clause + group by (whenanswered is not null)", { Columns => [1,2] }); +} + 1; diff --git a/web/ajax.cgi b/web/ajax.cgi index 4c668704c..aa640a854 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.15 2009-10-21 15:05:55 louise Exp $ +# $Id: ajax.cgi,v 1.16 2009-11-16 10:55:42 louise Exp $ use strict; use Standard; @@ -37,8 +37,6 @@ sub main { } my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $sx, $sy, $interval); my $cobrand = Page::get_cobrand($q); - my $limit = Cobrand::on_map_list_limit($cobrand); - ($on_map, $around_map) = Page::apply_on_map_list_limit($on_map, $around_map, $limit); my $list = ''; my $link = ''; foreach (@$on_map) { diff --git a/web/index.cgi b/web/index.cgi index b88a55979..355c63ded 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.317 2009-11-12 14:59:35 louise Exp $ +# $Id: index.cgi,v 1.318 2009-11-16 10:55:42 louise Exp $ use strict; use Standard; @@ -829,8 +829,6 @@ sub display_location { $interval = '6 months'; } my ($pins, $on_map, $around_map, $dist) = Page::map_pins($q, $x, $y, $x, $y, $interval); - my $limit = Cobrand::on_map_list_limit($cobrand); - ($on_map, $around_map) = Page::apply_on_map_list_limit($on_map, $around_map, $limit); if ($input{no_pins}) { $hide_link = NewURL($q, -retain=>1, no_pins=>undef); $hide_text = _('Show pins'); |