diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Zurich.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 27 |
3 files changed, 22 insertions, 23 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 7cdf150aa..866deb98e 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -360,21 +360,16 @@ sub generate_csv : Private { my $fixed_states = FixMyStreet::DB::Result::Problem->fixed_states; my $closed_states = FixMyStreet::DB::Result::Problem->closed_states; - my $wards = 0; - my $comments = 0; - foreach (@{$c->stash->{csv}->{columns}}) { - $wards = 1 if $_ eq 'wards'; - $comments = 1 if $_ eq 'acknowledged'; - } + my %asked_for = map { $_ => 1 } @{$c->stash->{csv}->{columns}}; my $problems = $c->stash->{csv}->{problems}; while ( my $report = $problems->next ) { - my $hashref = $report->as_hashref($c); + my $hashref = $report->as_hashref($c, \%asked_for); $hashref->{user_name_display} = $report->anonymous ? '(anonymous)' : $report->user->name; - if ($comments) { + if ($asked_for{acknowledged}) { for my $comment ($report->comments) { my $problem_state = $comment->problem_state or next; next unless $comment->state eq 'confirmed'; @@ -389,7 +384,7 @@ sub generate_csv : Private { } } - if ($wards) { + if ($asked_for{wards}) { $hashref->{wards} = join ', ', map { $c->stash->{children}->{$_}->{name} } grep {$c->stash->{children}->{$_} } diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm index c8af63987..453300cd5 100644 --- a/perllib/FixMyStreet/Cobrand/Zurich.pm +++ b/perllib/FixMyStreet/Cobrand/Zurich.pm @@ -1172,11 +1172,12 @@ sub admin_stats { sub export_as_csv { my ($self, $c, $params) = @_; + $c->model('DB')->schema->storage->sql_maker->quote_char('"'); my $csv = $c->stash->{csv} = { problems => $c->model('DB::Problem')->search_rs( $params, { - join => 'admin_log_entries', + join => ['admin_log_entries', 'user'], distinct => 1, columns => [ 'id', 'created', @@ -1190,6 +1191,7 @@ sub export_as_csv { 'service', 'extra', { sum_time_spent => { sum => 'admin_log_entries.time_spent' } }, + 'name', 'user.id', 'user.email', 'user.phone', 'user.name', ] } ), @@ -1258,6 +1260,7 @@ sub export_as_csv { filename => 'stats', }; $c->forward('/dashboard/generate_csv'); + $c->model('DB')->schema->storage->sql_maker->quote_char(''); } sub problem_confirm_email_extras { diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 2deeb3084..fac0fc7ef 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -653,7 +653,8 @@ sub body { my $body; if ($problem->external_body) { if ($problem->cobrand eq 'zurich') { - $body = $c->model('DB::Body')->find({ id => $problem->external_body }); + my $cache = $problem->result_source->schema->cache; + return $cache->{bodies}{$problem->external_body} //= $c->model('DB::Body')->find({ id => $problem->external_body }); } else { $body = $problem->external_body; } @@ -918,12 +919,11 @@ sub add_send_method { } sub as_hashref { - my $self = shift; - my $c = shift; + my ($self, $c, $cols) = @_; my $state_t = FixMyStreet::DB->resultset("State")->display($self->state); - return { + my $out = { id => $self->id, title => $self->title, category => $self->category, @@ -935,16 +935,17 @@ sub as_hashref { state => $self->state, state_t => $state_t, used_map => $self->used_map, - is_fixed => $self->fixed_states->{ $self->state } ? 1 : 0, - photos => [ map { $_->{url} } @{$self->photos} ], - meta => $self->confirmed ? $self->meta_line( $c ) : '', - ($self->confirmed ? ( - confirmed => $self->confirmed, - confirmed_pp => $c->cobrand->prettify_dt( $self->confirmed ), - ) : ()), - created => $self->created, - created_pp => $c->cobrand->prettify_dt( $self->created ), + created => $self->created, }; + $out->{is_fixed} = $self->fixed_states->{ $self->state } ? 1 : 0 if !$cols || $cols->{is_fixed}; + $out->{photos} = [ map { $_->{url} } @{$self->photos} ] if !$cols || $cols->{photos}; + $out->{meta} = $self->confirmed ? $self->meta_line( $c ) : '' if !$cols || $cols->{meta}; + $out->{created_pp} = $c->cobrand->prettify_dt( $self->created ) if !$cols || $cols->{created_pp}; + if ($self->confirmed) { + $out->{confirmed} = $self->confirmed if !$cols || $cols->{confirmed}; + $out->{confirmed_pp} = $c->cobrand->prettify_dt( $self->confirmed ) if !$cols || $cols->{confirmed_pp}; + } + return $out; } =head2 latest_moderation_log_entry |