diff options
-rw-r--r-- | perllib/Problems.pm | 35 | ||||
-rwxr-xr-x | web/reports.cgi | 24 |
2 files changed, 37 insertions, 22 deletions
diff --git a/perllib/Problems.pm b/perllib/Problems.pm index 1eda3da55..685c0db0b 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.28 2009-11-17 10:41:20 louise Exp $ +# $Id: Problems.pm,v 1.29 2009-11-18 16:43:42 louise Exp $ # package Problems; @@ -277,6 +277,39 @@ sub data_sharing_notification_start { return 1255392000; } +# Report functions + +=item council_problems WARD COUNCIL + +Returns a list of problems for a summary page. If WARD or COUNCIL area ids are given, +will only return problems for that area. Uses any site restriction defined by the +cobrand. + +=cut + +sub council_problems { + my ($ward, $one_council) = @_; + my @params; + my $where_extra = ''; + if ($ward) { + push @params, $ward; + $where_extra = "and areas like '%,'||?||',%'"; + } elsif ($one_council) { + push @params, $one_council; + $where_extra = "and areas like '%,'||?||',%'"; + } + my $problems = select_all( + "select id, title, detail, council, state, areas, + extract(epoch from ms_current_timestamp()-lastupdate) as duration, + extract(epoch from ms_current_timestamp()-confirmed) as age + from problem + where state in ('confirmed', 'fixed') + $where_extra + $site_restriction + order by id desc + ", @params); + return $problems; +} # Admin view functions diff --git a/web/reports.cgi b/web/reports.cgi index 3e8409bb9..58dc67b03 100755 --- a/web/reports.cgi +++ b/web/reports.cgi @@ -7,13 +7,12 @@ # Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved. # Email: matthew@mysociety.org. WWW: http://www.mysociety.org # -# $Id: reports.cgi,v 1.38 2009-11-05 14:40:55 matthew Exp $ +# $Id: reports.cgi,v 1.39 2009-11-18 16:43:41 louise Exp $ use strict; use Standard; use URI::Escape; use mySociety::Alert; -use mySociety::DBHandle qw(select_all); use mySociety::MaPit; use mySociety::Web qw(ent NewURL); use mySociety::VotingArea; @@ -117,28 +116,11 @@ sub main { %councils = map { $_ => 1 } @{mySociety::MaPit::get_areas_by_type(\@types, 10)}; } - my @params; - my $where_extra = ''; - if ($ward) { - push @params, $ward; - $where_extra = "and areas like '%,'||?||',%'"; - } elsif ($one_council) { - push @params, $one_council; - $where_extra = "and areas like '%,'||?||',%'"; - } - my $problem = select_all( - "select id, title, detail, council, state, areas, - extract(epoch from ms_current_timestamp()-lastupdate) as duration, - extract(epoch from ms_current_timestamp()-confirmed) as age - from problem - where state in ('confirmed', 'fixed') - $where_extra - order by id desc - ", @params); + my $problems = Problems::council_problems($ward, $one_council); my (%fixed, %open); my $re_councils = join('|', keys %councils); - foreach my $row (@$problem) { + foreach my $row (@$problems) { if (!$row->{council}) { # Problem was not sent to any council, add to possible councils while ($row->{areas} =~ /,($re_councils)(?=,)/g) { |