aboutsummaryrefslogtreecommitdiffstats
path: root/web/reports.cgi
diff options
context:
space:
mode:
Diffstat (limited to 'web/reports.cgi')
-rwxr-xr-xweb/reports.cgi62
1 files changed, 32 insertions, 30 deletions
diff --git a/web/reports.cgi b/web/reports.cgi
index 6c5796079..bc418db7c 100755
--- a/web/reports.cgi
+++ b/web/reports.cgi
@@ -33,28 +33,31 @@ sub main {
my ($one_council, $area_type, $area_name);
if ($q_council =~ /^(\d\d)([a-z]{2})?([a-z]{2})?$/i) {
- my $va_info = mySociety::MaPit::get_voting_area_info(uc $q_council);
+ my $va_info = mySociety::MaPit::call('area', uc $q_council);
+ if ($va_info->{error}) { # Given a bad/old ONS code
+ print $q->redirect($base_url . '/reports');
+ return;
+ }
$area_name = Page::short_name($va_info->{name});
if (length($q_council) == 6) {
- $va_info = mySociety::MaPit::get_voting_area_info($va_info->{parent_area_id});
+ $va_info = mySociety::MaPit::call('area', $va_info->{parent_area});
$area_name = Page::short_name($va_info->{name}) . '/' . $area_name;
}
$rss = '/rss' if $rss;
print $q->redirect($base_url . $rss . '/reports/' . $area_name);
return;
} elsif ($q_council =~ /\D/) {
- (my $qc = $q_council) =~ s/ and / & /;
- my $areas = mySociety::MaPit::get_voting_area_by_name($qc, $mySociety::VotingArea::council_parent_types, 10);
+ my $areas = mySociety::MaPit::call('areas', $q_council, type => $mySociety::VotingArea::council_parent_types, min_generation=>10 );
if (keys %$areas == 1) {
($one_council) = keys %$areas;
$area_type = $areas->{$one_council}->{type};
$area_name = $areas->{$one_council}->{name};
} else {
foreach (keys %$areas) {
- if ($areas->{$_}->{name} =~ /^\Q$qc\E (Borough|City|District|County) Council$/) {
+ if ($areas->{$_}->{name} =~ /^\Q$q_council\E (Borough|City|District|County) Council$/) {
$one_council = $_;
$area_type = $areas->{$_}->{type};
- $area_name = $qc;
+ $area_name = $q_council;
}
}
}
@@ -63,7 +66,7 @@ sub main {
return;
}
} elsif ($q_council =~ /^\d+$/) {
- my $va_info = mySociety::MaPit::get_voting_area_info($q_council);
+ my $va_info = mySociety::MaPit::call('area', $q_council);
$area_name = $va_info->{name};
print $q->redirect($base_url . '/reports/' . Page::short_name($area_name));
return;
@@ -74,9 +77,9 @@ sub main {
my $q_ward = $q->param('ward') || '';
my $ward;
if ($one_council && $q_ward) {
- my $qw = mySociety::MaPit::get_voting_area_by_name($q_ward, $mySociety::VotingArea::council_child_types, 10);
+ my $qw = mySociety::MaPit::call('areas', $q_ward, type => $mySociety::VotingArea::council_child_types, min_generation => 10);
foreach my $id (sort keys %$qw) {
- if ($qw->{$id}->{parent_area_id} == $one_council) {
+ if ($qw->{$id}->{parent_area} == $one_council) {
$ward = $id;
last;
}
@@ -116,21 +119,21 @@ sub main {
return;
}
- my %councils;
+ my $areas_info;
if ($one_council) {
- %councils = ( $one_council => 1 );
+ $areas_info = mySociety::MaPit::call('areas', $one_council);
} else {
# Show all councils on main report page
my $ignore = 'LGD';
$ignore .= '|CTY' if $q->{site} eq 'emptyhomes';
my @types = grep { !/$ignore/ } @$mySociety::VotingArea::council_parent_types;
- %councils = map { $_ => 1 } @{mySociety::MaPit::get_areas_by_type(\@types, 10)};
+ $areas_info = mySociety::MaPit::call('areas', [ @types ], min_generation=>10 );
}
my $problems = Problems::council_problems($ward, $one_council);
my (%fixed, %open);
- my $re_councils = join('|', keys %councils);
+ my $re_councils = join('|', keys %$areas_info);
foreach my $row (@$problems) {
if (!$row->{council}) {
# Problem was not sent to any council, add to possible councils
@@ -148,7 +151,6 @@ sub main {
}
}
- my $areas_info = mySociety::MaPit::get_voting_areas_info([keys %councils]);
if (!$one_council) {
print Page::header($q, title=>_('Summary reports'), expires=>'+1h');
print $q->p(
@@ -162,7 +164,7 @@ sub main {
print '<th>' . _('Old problems,<br>state unknown') . '</th>';
}
print '<th>' . _('Recently fixed') . '</th><th>' . _('Older fixed') . '</th></tr>';
- foreach (sort { $areas_info->{$a}->{name} cmp $areas_info->{$b}->{name} } keys %councils) {
+ foreach (sort { $areas_info->{$a}->{name} cmp $areas_info->{$b}->{name} } keys %$areas_info) {
print '<tr align="center"';
++$c;
if ($areas_info->{$_}->{generation_high}==10) {
@@ -227,7 +229,7 @@ sub main {
}
if ($open{$one_council}) {
- my $col = list_problems($q, _('New problems'), $open{$one_council}{new}, $all);
+ my $col = list_problems($q, _('New problems'), $open{$one_council}{new}, $all, 0);
my $old = [];
if ($q->{site} eq 'emptyhomes') {
push @$old, @{$open{$one_council}{older}} if $open{$one_council}{older};
@@ -235,15 +237,15 @@ sub main {
} else {
$old = $open{$one_council}{older};
}
- $col .= list_problems($q, _('Older problems'), $old, $all);
+ $col .= list_problems($q, _('Older problems'), $old, $all, 0);
if ($q->{site} ne 'emptyhomes') {
- $col .= list_problems($q, _('Old problems, state unknown'), $open{$one_council}{unknown}, $all);
+ $col .= list_problems($q, _('Old problems, state unknown'), $open{$one_council}{unknown}, $all, 0);
}
$vars{col_problems} = $col;
}
if ($fixed{$one_council}) {
- my $col = list_problems($q, _('Recently fixed'), $fixed{$one_council}{new}, $all);
- $col .= list_problems($q, _('Old fixed'), $fixed{$one_council}{old}, $all);
+ my $col = list_problems($q, _('Recently fixed'), $fixed{$one_council}{new}, $all, 1);
+ $col .= list_problems($q, _('Old fixed'), $fixed{$one_council}{old}, $all, 1);
$vars{col_fixed} = $col;
}
print Page::header($q, context => 'reports', title=>sprintf(_('%s - Summary reports'), $name), rss => [ sprintf(_('Problems within %s, FixMyStreet'), $name), Cobrand::url($cobrand, $rss_url, $q) ]);
@@ -261,11 +263,11 @@ sub add_row {
my $type = ($row->{duration} > 2 * $fourweeks)
? 'unknown'
: ($row->{age} > $fourweeks ? 'older' : 'new');
- my $entry = [ $row->{id}, $row->{title}, $row->{detail}, $councils ];
+ $row->{councils} = $councils;
#Fixed problems are either old or new
- push @{$fixed->{$council}{$duration}}, $entry if $row->{state} eq 'fixed';
+ push @{$fixed->{$council}{$duration}}, $row if $row->{state} eq 'fixed';
# Open problems are either unknown, older, or new
- push @{$open->{$council}{$type}}, $entry if $row->{state} eq 'confirmed';
+ push @{$open->{$council}{$type}}, $row if $row->{state} eq 'confirmed';
}
sub summary_cell {
@@ -276,18 +278,18 @@ sub summary_cell {
}
sub list_problems {
- my ($q, $title, $problems, $all) = @_;
+ my ($q, $title, $problems, $all, $fixed) = @_;
return '' unless $problems;
my $cobrand = Page::get_cobrand($q);
my $out = "<h3>$title</h3>\n<ul>";
- foreach (@$problems) {
- my $url = Cobrand::url($cobrand, "/report/" . $_->[0], $q);
+ foreach (sort { $fixed ? ($a->{duration} <=> $b->{duration}) : ($a->{age} <=> $b->{age}) } @$problems) {
+ my $url = Cobrand::url($cobrand, "/report/" . $_->{id}, $q);
$out .= '<li><a href="' . $url . '">';
- $out .= ent($_->[1]);
+ $out .= ent($_->{title});
$out .= '</a>';
- $out .= ' <small>(sent to both)</small>' if $_->[3]>1;
- $out .= ' <small>(not sent to council)</small>' if $_->[3]==0 && $q->{site} ne 'emptyhomes';
- $out .= '<br><small>' . ent($_->[2]) . '</small>' if $all;
+ $out .= ' <small>(sent to both)</small>' if $_->{councils}>1;
+ $out .= ' <small>(not sent to council)</small>' if $_->{councils}==0 && $q->{site} ne 'emptyhomes';
+ $out .= '<br><small>' . ent($_->{detail}) . '</small>' if $all;
$out .= '</li>';
}
$out .= '</ul>';