aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/App/Controller/My.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Bexley.pm5
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm2
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm23
-rw-r--r--perllib/FixMyStreet/Roles/Translatable.pm13
5 files changed, 25 insertions, 20 deletions
diff --git a/perllib/FixMyStreet/App/Controller/My.pm b/perllib/FixMyStreet/App/Controller/My.pm
index ed890ad82..b181acd04 100644
--- a/perllib/FixMyStreet/App/Controller/My.pm
+++ b/perllib/FixMyStreet/App/Controller/My.pm
@@ -161,7 +161,7 @@ sub setup_page_data : Private {
my @categories = $c->stash->{problems_rs}->search({
state => [ FixMyStreet::DB::Result::Problem->visible_states() ],
}, {
- columns => [ 'category' ],
+ columns => [ 'category', 'bodies_str' ],
distinct => 1,
order_by => [ 'category' ],
} )->all;
diff --git a/perllib/FixMyStreet/Cobrand/Bexley.pm b/perllib/FixMyStreet/Cobrand/Bexley.pm
index 0fbb8944b..1a303d633 100644
--- a/perllib/FixMyStreet/Cobrand/Bexley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bexley.pm
@@ -31,10 +31,7 @@ sub open311_munge_update_params {
$params->{service_request_id_ext} = $comment->problem->id;
- my $contact = $comment->result_source->schema->resultset("Contact")->not_deleted->find({
- body_id => $body->id,
- category => $comment->problem->category
- });
+ my $contact = $comment->problem->category_row;
$params->{service_code} = $contact->email;
}
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index a99915fb4..d8695683c 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -95,7 +95,7 @@ __PACKAGE__->many_to_many( defect_types => 'contact_defect_types', 'defect_type'
sub category_display {
my $self = shift;
- $self->translate_column('category');
+ $self->get_extra_metadata('display_name') || $self->translate_column('category');
}
sub groups {
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 {
diff --git a/perllib/FixMyStreet/Roles/Translatable.pm b/perllib/FixMyStreet/Roles/Translatable.pm
index d39d97bf8..0c84bbf0f 100644
--- a/perllib/FixMyStreet/Roles/Translatable.pm
+++ b/perllib/FixMyStreet/Roles/Translatable.pm
@@ -40,19 +40,6 @@ sub _translate {
my $translated = $self->translated->{$col}{$lang};
return $translated if $translated;
- # Deal with the fact problem table has denormalized copy of category string
- if ($table eq 'problem' && $col eq 'category') {
- my $body_id = $self->bodies_str_ids->[0];
- return $fallback unless $body_id && $body_id =~ /^[0-9]+$/;
- my $contact = $schema->resultset("Contact")->find( {
- body_id => $body_id,
- category => $fallback,
- } );
- return $fallback unless $contact; # Shouldn't happen, but some tests
- $table = 'contact';
- $id = $contact->id;
- }
-
if (ref $schema) {
my $translation = $schema->resultset('Translation')->find({
lang => $lang,