aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm58
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm7
2 files changed, 63 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index 0eff48b00..e60b673b4 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -336,5 +336,61 @@ sub report_check_for_errors {
return %errors;
}
-1;
+=head2 get_body_handler_for_problem
+
+Returns a cobrand for the body that a problem was logged against.
+
+ my $handler = $cobrand->get_body_handler_for_problem($row);
+ my $handler = $cobrand_class->get_body_handler_for_problem($row);
+
+If the UK council in bodies_str has a FMS.com cobrand then an instance of that
+cobrand class is returned, otherwise the default FixMyStreet cobrand is used.
+
+=cut
+
+sub get_body_handler_for_problem {
+ my ($self, $row) = @_;
+
+ my @bodies = values %{$row->bodies};
+ my %areas = map { %{$_->areas} } @bodies;
+
+ foreach my $avail ( FixMyStreet::Cobrand->available_cobrand_classes ) {
+ my $class = FixMyStreet::Cobrand->get_class_for_moniker($avail->{moniker});
+ my $cobrand = $class->new({});
+ next unless $cobrand->can('council_id');
+ return $cobrand if $areas{$cobrand->council_id};
+ }
+ return ref $self ? $self : $self->new;
+}
+
+=head2 link_to_council_cobrand
+
+If a problem was sent to a UK council who has a FMS cobrand and the report is
+currently being viewed on a different cobrand, then link the council's name to
+that problem on the council's cobrand.
+
+=cut
+
+sub link_to_council_cobrand {
+ my ( $self, $problem ) = @_;
+ # If the report was sent to a cobrand that we're not currently on,
+ # include a link to view it on the responsible cobrand.
+ # This only occurs if the report was sent to a single body and we're not already
+ # using the body name as a link to all problem reports.
+ my $handler = $self->get_body_handler_for_problem($problem);
+ $self->{c}->log->debug( sprintf "bodies: %s areas: %s self: %s handler: %s", $problem->bodies_str, $problem->areas, $self->moniker, $handler->moniker );
+ my $bodies_str_ids = $problem->bodies_str_ids;
+ if ( !mySociety::Config::get('AREA_LINKS_FROM_PROBLEMS') &&
+ scalar(@$bodies_str_ids) == 1 && $handler->is_council &&
+ $handler->moniker ne $self->{c}->cobrand->moniker
+ ) {
+ my $url = sprintf("%s%s", $handler->base_url, $problem->url);
+ return sprintf("<a href='%s'>%s</a>", $url, $problem->body( $self->{c} ));
+ } else {
+ return $problem->body( $self->{c} );
+ }
+}
+
+
+1;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index d6bcea55c..bc72cf9da 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -658,7 +658,12 @@ sub can_display_external_id {
sub duration_string {
my ( $problem, $c ) = @_;
- my $body = $problem->body( $c );
+ my $body;
+ if ( $c->cobrand->can('link_to_council_cobrand') ) {
+ $body = $c->cobrand->link_to_council_cobrand($problem);
+ } else {
+ $body = $problem->body( $c );
+ }
return sprintf(_('Sent to %s %s later'), $body,
Utils::prettify_duration($problem->whensent->epoch - $problem->confirmed->epoch, 'minute')
);