diff options
author | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-09-24 14:16:55 +0100 |
---|---|---|
committer | Matthew Somerville <matthew-github@dracos.co.uk> | 2018-10-03 16:41:28 +0100 |
commit | d57fb76a4cb811283e016b593aa3f4d187ed6e96 (patch) | |
tree | d8a1729a4928564c6ade09530e7faed806377fca | |
parent | c50a525da9c8ec5267c4ba9498e4334b87fe851b (diff) |
Some minor function refactoring.
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 31 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 26 |
2 files changed, 29 insertions, 28 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 7dc09186b..c72764f0f 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -274,6 +274,22 @@ sub generate_body_response_time : Private { $c->stash->{body_average} = $avg ? int($avg / 60 / 60 / 24 + 0.5) : 0; } +sub csv_filename { + my ($self, $c) = @_; + my %where = ( + category => $c->stash->{category}, + state => $c->stash->{q_state}, + ward => $c->stash->{ward}, + ); + $where{body} = $c->stash->{body}->id if $c->stash->{body}; + join '-', + $c->req->uri->host, + map { + my $value = $where{$_}; + (defined $value and length $value) ? ($_, $value) : () + } sort keys %where +}; + sub export_as_csv : Private { my ($self, $c) = @_; @@ -324,20 +340,7 @@ sub export_as_csv : Private { 'site_used', 'reported_as', ], - filename => do { - my %where = ( - category => $c->stash->{category}, - state => $c->stash->{q_state}, - ward => $c->stash->{ward}, - ); - $where{body} = $c->stash->{body}->id if $c->stash->{body}; - join '-', - $c->req->uri->host, - map { - my $value = $where{$_}; - (defined $value and length $value) ? ($_, $value) : () - } sort keys %where - }, + filename => $self->csv_filename($c), }; $c->cobrand->call_hook("dashboard_export_add_columns"); $c->forward('generate_csv'); diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 8a4dbe475..b35c5fd0c 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -253,24 +253,22 @@ sub meta_line { return $meta; }; +sub problem_state_processed { + my $self = shift; + return 'fixed - user' if $self->mark_fixed; + return 'confirmed' if $self->mark_open; + return $self->problem_state; +} + sub problem_state_display { my ( $self, $c ) = @_; - my $update_state = ''; - my $cobrand = $c->cobrand->moniker; - - if ($self->mark_fixed) { - return FixMyStreet::DB->resultset("State")->display('fixed', 1); - } elsif ($self->mark_open) { - return FixMyStreet::DB->resultset("State")->display('confirmed', 1); - } elsif ($self->problem_state) { - my $state = $self->problem_state; - my $cobrand_name = $cobrand; - $cobrand_name = 'bromley' if $self->problem->to_body_named('Bromley'); - $update_state = FixMyStreet::DB->resultset("State")->display($state, 1, $cobrand_name); - } + my $state = $self->problem_state_processed; + return '' unless $state; - return $update_state; + my $cobrand_name = $c->cobrand->moniker; + $cobrand_name = 'bromley' if $self->problem->to_body_named('Bromley'); + return FixMyStreet::DB->resultset("State")->display($state, 1, $cobrand_name); } sub is_latest { |