aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/ResultSet/Problem.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB/ResultSet/Problem.pm')
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Problem.pm36
1 files changed, 26 insertions, 10 deletions
diff --git a/perllib/FixMyStreet/DB/ResultSet/Problem.pm b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
index d56fec193..f01ddfff1 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Problem.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Problem.pm
@@ -20,6 +20,18 @@ sub set_restriction {
$site_key = $key;
}
+sub to_body {
+ my ($rs, $bodies) = @_;
+ return $rs unless $bodies;
+ unless (ref $bodies eq 'ARRAY') {
+ $bodies = [ map { ref $_ ? $_->id : $_ } $bodies ];
+ }
+ $rs = $rs->search(
+ \[ "regexp_split_to_array(bodies_str, ',') && ?", [ {} => $bodies ] ]
+ );
+ return $rs;
+}
+
# Front page statistics
sub recent_fixed {
@@ -236,7 +248,7 @@ sub send_reports {
my $states = [ 'confirmed', 'fixed' ];
$states = [ 'unconfirmed', 'confirmed', 'in progress', 'planned', 'closed' ] if $site eq 'zurich';
- my $unsent = FixMyStreet::App->model("DB::Problem")->search( {
+ my $unsent = $rs->search( {
state => $states,
whensent => undef,
bodies_str => { '!=', undef },
@@ -320,15 +332,19 @@ sub send_reports {
$cobrand->process_additional_metadata_for_email($row, \%h);
}
- # XXX Needs locks!
- # XXX Only copes with at most one missing body
- my ($bodies, $missing) = $row->bodies_str =~ /^([\d,]+)(?:\|(\d+))?/;
- my @bodies = split(/,/, $bodies);
- $bodies = FixMyStreet::App->model("DB::Body")->search(
- { id => \@bodies },
+ my $bodies = FixMyStreet::App->model("DB::Body")->search(
+ { id => $row->bodies_str_ids },
{ order_by => 'name' },
);
- $missing = FixMyStreet::App->model("DB::Body")->find($missing) if $missing;
+
+ my $missing;
+ if ($row->bodies_missing) {
+ my @missing = FixMyStreet::App->model("DB::Body")->search(
+ { id => [ split /,/, $row->bodies_missing ] },
+ { order_by => 'name' }
+ )->get_column('name')->all;
+ $missing = join(' / ', @missing) if @missing;
+ }
my @dear;
my %reporters = ();
@@ -400,7 +416,7 @@ sub send_reports {
$h{missing} = '';
if ($missing) {
$h{missing} = '[ '
- . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing->name)
+ . sprintf(_('We realise this problem might be the responsibility of %s; however, we don\'t currently have any contact details for them. If you know of an appropriate contact address, please do get in touch.'), $missing)
. " ]\n\n";
}
@@ -468,7 +484,7 @@ sub send_reports {
}
}
my $sending_errors = '';
- my $unsent = FixMyStreet::App->model("DB::Problem")->search( {
+ my $unsent = $rs->search( {
state => [ 'confirmed', 'fixed' ],
whensent => undef,
bodies_str => { '!=', undef },