aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin/Triage.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Around.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm8
-rw-r--r--perllib/FixMyStreet/App/Controller/Reports.pm3
-rw-r--r--perllib/FixMyStreet/Cobrand/Peterborough.pm2
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm3
-rw-r--r--perllib/FixMyStreet/DB/Result/Contact.pm15
-rw-r--r--perllib/FixMyStreet/DB/ResultSet/Contact.pm23
8 files changed, 46 insertions, 14 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Triage.pm b/perllib/FixMyStreet/App/Controller/Admin/Triage.pm
index 50d1b1437..0eabd340d 100644
--- a/perllib/FixMyStreet/App/Controller/Admin/Triage.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin/Triage.pm
@@ -57,8 +57,7 @@ sub index : Path : Args(0) {
my @categories = $c->stash->{body}->contacts->not_deleted->search( undef, {
columns => [ 'id', 'category', 'extra' ],
distinct => 1,
- order_by => [ 'category' ],
- } )->all;
+ } )->all_sorted;
$c->stash->{filter_categories} = \@categories;
$c->stash->{filter_category} = { map { $_ => 1 } $c->get_param_list('filter_category', 1) };
my $pins = $c->stash->{pins} || [];
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm
index f14d116cc..377449719 100644
--- a/perllib/FixMyStreet/App/Controller/Around.pm
+++ b/perllib/FixMyStreet/App/Controller/Around.pm
@@ -248,10 +248,9 @@ sub check_and_stash_category : Private {
$where,
{
columns => [ 'category', 'extra' ],
- order_by => [ 'category' ],
distinct => 1
}
- )->all;
+ )->all_sorted;
$c->stash->{filter_categories} = \@categories;
my %categories_mapped = map { $_->category => 1 } @categories;
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index 612c76c0c..8dec06e86 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -7,7 +7,6 @@ BEGIN { extends 'Catalyst::Controller'; }
use Encode;
use List::MoreUtils qw(uniq);
use List::Util 'first';
-use POSIX 'strcoll';
use HTML::Entities;
use Path::Class;
use Utils;
@@ -285,7 +284,7 @@ sub by_category_ajax_data : Private {
if ( $c->stash->{category_extras}->{$category} && @{ $c->stash->{category_extras}->{$category} } >= 1 ) {
my $disable_form = $c->forward('disable_form_message');
- $body->{disable_form} = $disable_form if $disable_form;
+ $body->{disable_form} = $disable_form if %$disable_form;
}
my $unresponsive = $c->stash->{unresponsive}->{$category};
@@ -677,7 +676,7 @@ sub setup_categories_and_bodies : Private {
->model('DB::Contact') #
->active
->search( { 'me.body_id' => [ keys %bodies ] }, { prefetch => 'body' } );
- my @contacts = $c->cobrand->categories_restriction($contacts)->all;
+ my @contacts = $c->cobrand->categories_restriction($contacts)->all_sorted;
# variables to populate
my %bodies_to_list = (); # Bodies with categories assigned
@@ -703,9 +702,6 @@ sub setup_categories_and_bodies : Private {
$c->stash->{unresponsive}{$k} = { map { $_ => 1 } keys %bodies };
}
- # keysort does not appear to obey locale so use strcoll (see i18n.t)
- @contacts = sort { strcoll( $a->category, $b->category ) } @contacts;
-
my %seen;
foreach my $contact (@contacts) {
diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm
index 85e647f65..271513df3 100644
--- a/perllib/FixMyStreet/App/Controller/Reports.pm
+++ b/perllib/FixMyStreet/App/Controller/Reports.pm
@@ -187,8 +187,7 @@ sub setup_categories_and_map :Private {
my @categories = $c->stash->{body}->contacts->not_deleted->search( undef, {
columns => [ 'id', 'category', 'extra', 'body_id', 'send_method' ],
distinct => 1,
- order_by => [ 'category' ],
- } )->all;
+ } )->all_sorted;
$c->cobrand->call_hook('munge_reports_category_list', \@categories);
diff --git a/perllib/FixMyStreet/Cobrand/Peterborough.pm b/perllib/FixMyStreet/Cobrand/Peterborough.pm
index dd9bb0670..eb9208645 100644
--- a/perllib/FixMyStreet/Cobrand/Peterborough.pm
+++ b/perllib/FixMyStreet/Cobrand/Peterborough.pm
@@ -13,6 +13,8 @@ sub council_area { 'Peterborough' }
sub council_name { 'Peterborough City Council' }
sub council_url { 'peterborough' }
+sub send_questionnaires { 0 }
+
sub disambiguate_location {
my $self = shift;
my $string = shift;
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 6cbaa285b..6bbbdc775 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -334,9 +334,8 @@ sub report_page_data {
my @categories = $c->model('DB::Contact')->not_deleted->search(undef, {
columns => [ 'category', 'extra' ],
- order_by => [ 'category' ],
distinct => 1
- })->all;
+ })->all_sorted;
$c->stash->{filter_categories} = \@categories;
$c->stash->{filter_category} = { map { $_ => 1 } $c->get_param_list('filter_category', 1) };
diff --git a/perllib/FixMyStreet/DB/Result/Contact.pm b/perllib/FixMyStreet/DB/Result/Contact.pm
index d8695683c..affc6d480 100644
--- a/perllib/FixMyStreet/DB/Result/Contact.pm
+++ b/perllib/FixMyStreet/DB/Result/Contact.pm
@@ -93,6 +93,21 @@ __PACKAGE__->many_to_many( response_templates => 'contact_response_templates', '
__PACKAGE__->many_to_many( response_priorities => 'contact_response_priorities', 'response_priority' );
__PACKAGE__->many_to_many( defect_types => 'contact_defect_types', 'defect_type' );
+__PACKAGE__->might_have(
+ "translations",
+ "FixMyStreet::DB::Result::Translation",
+ sub {
+ my $args = shift;
+ return {
+ "$args->{foreign_alias}.object_id" => { -ident => "$args->{self_alias}.id" },
+ "$args->{foreign_alias}.tbl" => { '=' => \"?" },
+ "$args->{foreign_alias}.col" => { '=' => \"?" },
+ "$args->{foreign_alias}.lang" => { '=' => \"?" },
+ };
+ },
+ { cascade_copy => 0, cascade_delete => 0 },
+);
+
sub category_display {
my $self = shift;
$self->get_extra_metadata('display_name') || $self->translate_column('category');
diff --git a/perllib/FixMyStreet/DB/ResultSet/Contact.pm b/perllib/FixMyStreet/DB/ResultSet/Contact.pm
index 7b3258262..1643f9931 100644
--- a/perllib/FixMyStreet/DB/ResultSet/Contact.pm
+++ b/perllib/FixMyStreet/DB/ResultSet/Contact.pm
@@ -3,6 +3,7 @@ use base 'DBIx::Class::ResultSet';
use strict;
use warnings;
+use POSIX qw(strcoll);
sub me { join('.', shift->current_source_alias, shift || q{}) }
@@ -24,6 +25,28 @@ sub active {
$rs->search( { $rs->me('state') => [ 'unconfirmed', 'confirmed' ] } );
}
+sub translated {
+ my $rs = shift;
+ my $schema = $rs->result_source->schema;
+ $rs->search(undef, {
+ '+columns' => { 'msgstr' => 'translations.msgstr' },
+ join => 'translations',
+ bind => [ 'category', $schema->lang, 'contact' ],
+ });
+}
+
+sub all_sorted {
+ my $rs = shift;
+
+ my @contacts = $rs->translated->all;
+ @contacts = sort {
+ my $a_name = $a->get_extra_metadata('display_name') || $a->get_column('msgstr') || $a->category;
+ my $b_name = $b->get_extra_metadata('display_name') || $b->get_column('msgstr') || $b->category;
+ strcoll($a_name, $b_name)
+ } @contacts;
+ return @contacts;
+}
+
sub summary_count {
my ( $rs, $restriction ) = @_;