diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Zurich.pm | 37 | ||||
-rw-r--r-- | t/cobrand/zurich.t | 6 | ||||
-rw-r--r-- | templates/web/zurich/admin/problem_row.html | 2 |
3 files changed, 41 insertions, 4 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Zurich.pm b/perllib/FixMyStreet/Cobrand/Zurich.pm index 30c396d62..0a05fe835 100644 --- a/perllib/FixMyStreet/Cobrand/Zurich.pm +++ b/perllib/FixMyStreet/Cobrand/Zurich.pm @@ -95,6 +95,27 @@ sub prettify_dt { return Utils::prettify_dt( $dt, 'zurich' ); } +# problem already has a concept of is_fixed/is_closed, but Zurich has different +# workflow for this here. +# +# TODO: look at more elegant way of doing this, for example having ::DB::Problem +# consider cobrand specific state config? + +sub zurich_closed_states { + my $states = { + 'fixed - council' => 1, + 'closed' => 1, + 'hidden' => 1, + }; + + return wantarray ? keys %{ $states } : $states; +} + +sub problem_is_closed { + my ($self, $problem) = @_; + return exists $self->zurich_closed_states->{ $problem->state } ? 1 : 0; +} + sub problem_as_hashref { my $self = shift; my $problem = shift; @@ -228,9 +249,10 @@ sub overdue { return $w < DateTime->now() ? 1 : 0; # call with new state - } elsif ( $problem->state eq 'fixed - council' || $problem->state eq 'closed' || $problem->state eq 'hidden' ) { + } elsif ( $self->problem_is_closed($problem) ) { # States which affect the closed_overdue statistic # Five working days from moderation (so 6 from creation) + $w = add_days( $w, 6 ); return $w < DateTime->now() ? 1 : 0; } else { @@ -238,6 +260,17 @@ sub overdue { } } +sub get_or_check_overdue { + my ($self, $problem) = @_; + + # use the cached version is it exists (e.g. when called from template) + my $extra = $problem->extra; + if (exists $extra->{closed_overdue} and defined $extra->{closed_overdue}) { + return $extra->{closed_overdue} + } + return $self->overdue($problem); +} + sub set_problem_state { my ($self, $c, $problem, $new_state) = @_; return if $new_state eq $problem->state; @@ -485,7 +518,7 @@ sub admin_report_edit { $self->set_problem_state($c, $problem, $state); - if ($state eq 'fixed - council' || $state eq 'closed' || $state eq 'hidden') { + if ($self->problem_is_closed($problem)) { $extra->{closed_overdue} //= $self->overdue( $problem ); } if ( $state eq 'hidden' && $c->req->params->{send_rejected_email} ) { diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index f6cbeffed..86bfcccea 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -280,7 +280,11 @@ subtest "report_edit" => sub { is ( $report->extra->{closed_overdue}, 0, 'Marking hidden from scratch also set closed_overdue' ); is get_moderated_count(), 1; - reset_report_state($report); + is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'sanity check'); + $report->update({ created => $created->clone->subtract(days => 10) }); + is (FixMyStreet::Cobrand::Zurich->new->get_or_check_overdue($report), 0, 'overdue call not increased'); + + reset_report_state($report, $created); }; FixMyStreet::override_config { diff --git a/templates/web/zurich/admin/problem_row.html b/templates/web/zurich/admin/problem_row.html index 71b64839a..9b395a1ac 100644 --- a/templates/web/zurich/admin/problem_row.html +++ b/templates/web/zurich/admin/problem_row.html @@ -3,7 +3,7 @@ <tr[% SET classes = []; classes.push('adminhidden') IF problem.state == 'hidden'; - classes.push('overdue') IF c.cobrand.overdue( problem ); + classes.push('overdue') IF c.cobrand.get_or_check_overdue( problem ); classes.push('row-link') IF NOT no_edit; ' class="' _ classes.join(' ') _ '"' IF classes.size; %]> |