diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/TfL.pm | 28 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 9 |
3 files changed, 40 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm index 29ff4393f..854f6da89 100644 --- a/perllib/FixMyStreet/Cobrand/Bromley.pm +++ b/perllib/FixMyStreet/Cobrand/Bromley.pm @@ -30,6 +30,9 @@ sub report_validation { sub report_new_munge_before_insert { my ($self, $report) = @_; + # Make sure TfL reports are marked safety critical + $self->SUPER::report_new_munge_before_insert($report); + $report->subcategory($report->get_extra_field_value('service_sub_code')); } diff --git a/perllib/FixMyStreet/Cobrand/TfL.pm b/perllib/FixMyStreet/Cobrand/TfL.pm index ececa1184..846e1e776 100644 --- a/perllib/FixMyStreet/Cobrand/TfL.pm +++ b/perllib/FixMyStreet/Cobrand/TfL.pm @@ -160,4 +160,32 @@ sub update_email_shortlisted_user { } } +sub report_new_munge_before_insert { + my ($self, $report) = @_; + + # Sets the safety critical flag on this report according to category/extra + # fields selected. + + my $safety_critical = 0; + my $categories = $self->feature('safety_critical_categories'); + my $category = $categories->{$report->category}; + if ( ref $category eq 'HASH' ) { + # report is safety critical if any of its field values match + # the critical values from the config + for my $code (keys %$category) { + my $value = $report->get_extra_field_value($code); + my %critical_values = map { $_ => 1 } @{ $category->{$code} }; + $safety_critical ||= $critical_values{$value}; + } + } elsif ($category) { + # the entire category is safety critical + $safety_critical = 1; + } + + my $extra = $report->get_extra_fields; + @$extra = grep { $_->{name} ne 'safety_critical' } @$extra; + push @$extra, { name => 'safety_critical', value => $safety_critical ? 'yes' : 'no' }; + $report->set_extra_fields(@$extra); +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm index 83df590db..2054b5df6 100644 --- a/perllib/FixMyStreet/Cobrand/UK.pm +++ b/perllib/FixMyStreet/Cobrand/UK.pm @@ -413,4 +413,13 @@ sub category_extra_hidden { return $self->SUPER::category_extra_hidden($meta); } +sub report_new_munge_before_insert { + my ($self, $report) = @_; + + if ($report->to_body_named('TfL')) { + my $tfl = FixMyStreet::Cobrand->get_class_for_moniker('tfl')->new(); + $tfl->report_new_munge_before_insert($report); + } +} + 1; |