diff options
author | Matthew Somerville <matthew@mysociety.org> | 2019-09-11 17:53:28 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2019-10-25 14:07:13 +0100 |
commit | 1016181d70363325e989c0ec8598341ec1f34ec6 (patch) | |
tree | 255cfc9e30ad8c76444cb080251a951e2b7a67cd /perllib/FixMyStreet/DB/Result/Problem.pm | |
parent | 3a149039167145ef6d8cd0218a30ec8d98741bc4 (diff) |
Allow cobrands to override category display.
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 08b768719..97f0666e0 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -404,7 +404,28 @@ sub confirm { sub category_display { my $self = shift; - $self->translate_column('category'); + my $contact = $self->category_row; + return $self->category unless $contact; # Fallback; shouldn't happen, but some tests + return $contact->category_display; +} + +=head2 category_row + +Returns the corresponding Contact object for this problem's category and body. +If the report was sent to multiple bodies, only returns the first. + +=cut + +sub category_row { + my $self = shift; + my $schema = $self->result_source->schema; + my $body_id = $self->bodies_str_ids->[0]; + return unless $body_id && $body_id =~ /^[0-9]+$/; + my $contact = $schema->resultset("Contact")->find({ + body_id => $body_id, + category => $self->category, + }); + return $contact; } sub bodies_str_ids { |