aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/Cobrand
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/Cobrand')
-rw-r--r--perllib/FixMyStreet/Cobrand/BathNES.pm34
-rw-r--r--perllib/FixMyStreet/Cobrand/Zurich.pm180
2 files changed, 104 insertions, 110 deletions
diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm
index ea9b26e7a..0ccf488c7 100644
--- a/perllib/FixMyStreet/Cobrand/BathNES.pm
+++ b/perllib/FixMyStreet/Cobrand/BathNES.pm
@@ -193,24 +193,16 @@ sub categories_restriction {
] } );
}
-# Do a manual prefetch, as easier than sorting out quoting 'user'
+# Do a manual prefetch of all staff users for contributed_by lookup
sub _dashboard_user_lookup {
my $self = shift;
my $c = $self->{c};
- # Fetch all the relevant user IDs, and look them up
- my @user_ids = $c->stash->{objects_rs}->search({}, { columns => [ 'user_id' ] })->all;
- @user_ids = map { $_->user_id } @user_ids;
- @user_ids = $c->model('DB::User')->search(
- { id => { -in => \@user_ids } },
- { columns => [ 'id', 'email', 'phone' ] })->all;
-
- # Plus all staff users for contributed_by lookup
- push @user_ids, $c->model('DB::User')->search(
+ my @user_ids = $c->model('DB::User')->search(
{ from_body => { '!=' => undef } },
- { columns => [ 'id', 'email', 'phone' ] })->all;
+ { columns => [ 'id', 'email' ] })->all;
- my %user_lookup = map { $_->id => { email => $_->email, phone => $_->phone } } @user_ids;
+ my %user_lookup = map { $_->id => $_->email } @user_ids;
return \%user_lookup;
}
@@ -225,6 +217,10 @@ sub dashboard_export_updates_add_columns {
push @{$c->stash->{csv}->{columns}}, "staff_user";
push @{$c->stash->{csv}->{columns}}, "user_email";
+ $c->stash->{csv}->{objects} = $c->stash->{csv}->{objects}->search(undef, {
+ '+columns' => ['user.email'],
+ prefetch => 'user',
+ });
my $user_lookup = $self->_dashboard_user_lookup;
$c->stash->{csv}->{extra_data} = sub {
@@ -232,11 +228,11 @@ sub dashboard_export_updates_add_columns {
my $staff_user = '';
if ( my $contributed_by = $report->get_extra_metadata('contributed_by') ) {
- $staff_user = $user_lookup->{$contributed_by}{email};
+ $staff_user = $user_lookup->{$contributed_by};
}
return {
- user_email => $user_lookup->{$report->user_id}{email} || '',
+ user_email => $report->user->email || '',
staff_user => $staff_user,
};
};
@@ -264,6 +260,10 @@ sub dashboard_export_problems_add_columns {
"attribute_data",
];
+ $c->stash->{csv}->{objects} = $c->stash->{csv}->{objects}->search(undef, {
+ '+columns' => ['user.email', 'user.phone'],
+ prefetch => 'user',
+ });
my $user_lookup = $self->_dashboard_user_lookup;
$c->stash->{csv}->{extra_data} = sub {
@@ -271,12 +271,12 @@ sub dashboard_export_problems_add_columns {
my $staff_user = '';
if ( my $contributed_by = $report->get_extra_metadata('contributed_by') ) {
- $staff_user = $user_lookup->{$contributed_by}{email};
+ $staff_user = $user_lookup->{$contributed_by};
}
my $attribute_data = join "; ", map { $_->{name} . " = " . $_->{value} } @{ $report->get_extra_fields };
return {
- user_email => $user_lookup->{$report->user_id}{email} || '',
- user_phone => $user_lookup->{$report->user_id}{phone} || '',
+ user_email => $report->user->email || '',
+ user_phone => $report->user->phone || '',
staff_user => $staff_user,
attribute_data => $attribute_data,
};
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm
index 9b6a3b9cb..5fea9a03f 100644
--- a/perllib/FixMyStreet/Cobrand/Zurich.pm
+++ b/perllib/FixMyStreet/Cobrand/Zurich.pm
@@ -460,7 +460,7 @@ sub admin {
my $dir = defined $c->get_param('d') ? $c->get_param('d') : 1;
$c->stash->{order} = $order;
$c->stash->{dir} = $dir;
- $order .= ' desc' if $dir;
+ $order = { -desc => $order } if $dir;
# XXX No multiples or missing bodies
$c->stash->{submitted} = $c->cobrand->problems->search({
@@ -494,7 +494,7 @@ sub admin {
my $dir = defined $c->get_param('d') ? $c->get_param('d') : 1;
$c->stash->{order} = $order;
$c->stash->{dir} = $dir;
- $order .= ' desc' if $dir;
+ $order = { -desc => $order } if $dir;
# XXX No multiples or missing bodies
$c->stash->{reports_new} = $c->cobrand->problems->search( {
@@ -1202,100 +1202,94 @@ sub admin_stats {
sub export_as_csv {
my ($self, $c, $params) = @_;
- try {
- $c->model('DB')->schema->storage->sql_maker->quote_char('"');
- my $csv = $c->stash->{csv} = {
- objects => $c->model('DB::Problem')->search_rs(
- $params,
- {
- join => ['admin_log_entries', 'user'],
- distinct => 1,
- columns => [
- 'id', 'created',
- 'latitude', 'longitude',
- 'cobrand', 'category',
- 'state', 'user_id',
- 'external_body',
- 'title', 'detail',
- 'photo',
- 'whensent', 'lastupdate',
- 'service',
- 'extra',
- { sum_time_spent => { sum => 'admin_log_entries.time_spent' } },
- 'name', 'user.id', 'user.email', 'user.phone', 'user.name',
- ]
- }
- ),
- headers => [
- 'Report ID', 'Created', 'Sent to Agency', 'Last Updated',
- 'E', 'N', 'Category', 'Status', 'Closure Status',
- 'UserID', 'User email', 'User phone', 'User name',
- 'External Body', 'Time Spent', 'Title', 'Detail',
- 'Media URL', 'Interface Used', 'Council Response',
- 'Strasse', 'Mast-Nr.', 'Haus-Nr.', 'Hydranten-Nr.',
- ],
- columns => [
- 'id', 'created', 'whensent',' lastupdate', 'local_coords_x',
- 'local_coords_y', 'category', 'state', 'closure_status',
- 'user_id', 'user_email', 'user_phone', 'user_name',
- 'body_name', 'sum_time_spent', 'title', 'detail',
- 'media_url', 'service', 'public_response',
- 'strasse', 'mast_nr',' haus_nr', 'hydranten_nr',
- ],
- extra_data => sub {
- my $report = shift;
-
- my $body_name = "";
- if ( my $external_body = $report->body($c) ) {
- $body_name = $external_body->name || '[Unknown body]';
- }
- my $detail = $report->detail;
- my $public_response = $report->get_extra_metadata('public_response') || '';
- my $metas = $report->get_extra_fields();
- my %extras;
- foreach my $field (@$metas) {
- $extras{$field->{name}} = $field->{value};
- }
+ my $csv = $c->stash->{csv} = {
+ objects => $c->model('DB::Problem')->search_rs(
+ $params,
+ {
+ join => ['admin_log_entries', 'user'],
+ distinct => 1,
+ columns => [
+ 'id', 'created',
+ 'latitude', 'longitude',
+ 'cobrand', 'category',
+ 'state', 'user_id',
+ 'external_body',
+ 'title', 'detail',
+ 'photo',
+ 'whensent', 'lastupdate',
+ 'service',
+ 'extra',
+ { sum_time_spent => { sum => 'admin_log_entries.time_spent' } },
+ 'name', 'user.id', 'user.email', 'user.phone', 'user.name',
+ ]
+ }
+ ),
+ headers => [
+ 'Report ID', 'Created', 'Sent to Agency', 'Last Updated',
+ 'E', 'N', 'Category', 'Status', 'Closure Status',
+ 'UserID', 'User email', 'User phone', 'User name',
+ 'External Body', 'Time Spent', 'Title', 'Detail',
+ 'Media URL', 'Interface Used', 'Council Response',
+ 'Strasse', 'Mast-Nr.', 'Haus-Nr.', 'Hydranten-Nr.',
+ ],
+ columns => [
+ 'id', 'created', 'whensent',' lastupdate', 'local_coords_x',
+ 'local_coords_y', 'category', 'state', 'closure_status',
+ 'user_id', 'user_email', 'user_phone', 'user_name',
+ 'body_name', 'sum_time_spent', 'title', 'detail',
+ 'media_url', 'service', 'public_response',
+ 'strasse', 'mast_nr',' haus_nr', 'hydranten_nr',
+ ],
+ extra_data => sub {
+ my $report = shift;
+
+ my $body_name = "";
+ if ( my $external_body = $report->body($c) ) {
+ $body_name = $external_body->name || '[Unknown body]';
+ }
- # replace newlines with HTML <br/> element
- $detail =~ s{\r?\n}{ <br/> }g;
- $public_response =~ s{\r?\n}{ <br/> }g if $public_response;
-
- # Assemble photo URL, if report has a photo
- my $photo_to_display = $c->cobrand->allow_photo_display($report);
- my $media_url = (@{$report->photos} && $photo_to_display)
- ? $c->cobrand->base_url . $report->photos->[$photo_to_display-1]->{url}
- : '';
-
- return {
- whensent => $report->whensent,
- lastupdate => $report->lastupdate,
- user_id => $report->user_id,
- user_email => $report->user->email || '',
- user_phone => $report->user->phone || '',
- user_name => $report->name,
- closure_status => $report->get_extra_metadata('closure_status') || '',
- body_name => $body_name,
- sum_time_spent => $report->get_column('sum_time_spent') || 0,
- detail => $detail,
- media_url => $media_url,
- service => $report->service || 'Web interface',
- public_response => $public_response,
- strasse => $extras{'strasse'} || '',
- mast_nr => $extras{'mast_nr'} || '',
- haus_nr => $extras{'haus_nr'} || '',
- hydranten_nr => $extras{'hydranten_nr'} || ''
- };
- },
- filename => 'stats',
- };
- $c->forward('/dashboard/generate_csv');
- } catch {
- die $_;
- } finally {
- $c->model('DB')->schema->storage->sql_maker->quote_char('');
+ my $detail = $report->detail;
+ my $public_response = $report->get_extra_metadata('public_response') || '';
+ my $metas = $report->get_extra_fields();
+ my %extras;
+ foreach my $field (@$metas) {
+ $extras{$field->{name}} = $field->{value};
+ }
+
+ # replace newlines with HTML <br/> element
+ $detail =~ s{\r?\n}{ <br/> }g;
+ $public_response =~ s{\r?\n}{ <br/> }g if $public_response;
+
+ # Assemble photo URL, if report has a photo
+ my $photo_to_display = $c->cobrand->allow_photo_display($report);
+ my $media_url = (@{$report->photos} && $photo_to_display)
+ ? $c->cobrand->base_url . $report->photos->[$photo_to_display-1]->{url}
+ : '';
+
+ return {
+ whensent => $report->whensent,
+ lastupdate => $report->lastupdate,
+ user_id => $report->user_id,
+ user_email => $report->user->email || '',
+ user_phone => $report->user->phone || '',
+ user_name => $report->name,
+ closure_status => $report->get_extra_metadata('closure_status') || '',
+ body_name => $body_name,
+ sum_time_spent => $report->get_column('sum_time_spent') || 0,
+ detail => $detail,
+ media_url => $media_url,
+ service => $report->service || 'Web interface',
+ public_response => $public_response,
+ strasse => $extras{'strasse'} || '',
+ mast_nr => $extras{'mast_nr'} || '',
+ haus_nr => $extras{'haus_nr'} || '',
+ hydranten_nr => $extras{'hydranten_nr'} || ''
+ };
+ },
+ filename => 'stats',
};
+ $c->forward('/dashboard/generate_csv');
}
sub problem_confirm_email_extras {