diff options
author | Dave Arter <davea@mysociety.org> | 2014-05-30 17:09:01 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-07-08 15:28:22 +0100 |
commit | 18b68734f0d425875a4e3abbd4416a7952d1089f (patch) | |
tree | 5df410c002d8baffb9b1b37a297147205bded203 /perllib/FixMyStreet/Cobrand/UK.pm | |
parent | d2ef2aaa0155809b31ea577c8c26afeff5bec98b (diff) |
Include link back to originating cobrand on fms.com reports
When viewing a report on FMS.com whose recipient council has a
FMS cobrand, turns the council name into a link to view the same report
on that council's cobranded site.
Includes methods cribbed from Hakim's Open311 refactor branch from
commit 47daa02420a4f5a4264c31efcf2a2e8611c2f23e.
Diffstat (limited to 'perllib/FixMyStreet/Cobrand/UK.pm')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 58 |
1 files changed, 57 insertions, 1 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; |