diff options
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 96 | ||||
-rw-r--r-- | t/app/model/problem.t | 17 |
2 files changed, 81 insertions, 32 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index bfe87009d..bee2e9bce 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -228,38 +228,6 @@ sub closed_states { =head2 - @states = FixMyStreet::DB::Problem::visible_states(); - -Get a list of states that should be visible on the site. If called in -array context then returns an array of names, otherwise returns a -HASHREF. - -=cut - -my $visible_states = { - 'confirmed' => 1, - 'investigating' => 1, - 'in progress' => 1, - 'planned' => 1, - 'action scheduled' => 1, - 'fixed' => 1, - 'fixed - council' => 1, - 'fixed - user' => 1, - 'unable to fix' => 1, - 'not responsible' => 1, - 'duplicate' => 1, - 'closed' => 1, - 'internal referral' => 1, -}; -sub visible_states { - return wantarray ? keys %{$visible_states} : $visible_states; -} -sub visible_states_add_unconfirmed { - $visible_states->{unconfirmed} = 1; -} - -=head2 - @states = FixMyStreet::DB::Problem::all_states(); Get a list of all states that a problem can have. If called in @@ -293,6 +261,70 @@ sub all_states { =head2 + @visible_states = FixMyStreet::DB::Problem::visible_states(); + @hidden_states = FixMyStreet::DB::Problem::hidden_states(); + +Get a list of states that should be visible (or hidden) on the site. If called +in array context then returns an array of names, otherwise returns a HASHREF. + +=cut + +my $hidden_states = { + 'hidden' => 1, + 'partial' => 1, + 'unconfirmed' => 1, +}; + +my $visible_states = { + map { + $hidden_states->{$_} ? () : ($_ => 1) + } all_states() +}; + ## e.g.: + # 'confirmed' => 1, + # 'investigating' => 1, + # 'in progress' => 1, + # 'planned' => 1, + # 'action scheduled' => 1, + # 'fixed' => 1, + # 'fixed - council' => 1, + # 'fixed - user' => 1, + # 'unable to fix' => 1, + # 'not responsible' => 1, + # 'duplicate' => 1, + # 'closed' => 1, + # 'internal referral' => 1, + +sub hidden_states { + return wantarray ? keys %{$hidden_states} : $hidden_states; +} + +sub visible_states { + return wantarray ? keys %{$visible_states} : $visible_states; +} + +sub visible_states_add { + my ($self, @states) = @_; + for my $state (@states) { + delete $hidden_states->{$state}; + $visible_states->{$state} = 1; + } +} + +sub visible_states_remove { + my ($self, @states) = @_; + for my $state (@states) { + delete $visible_states->{$state}; + $hidden_states->{$state} = 1; + } +} + +sub visible_states_add_unconfirmed { + $_[0]->visible_states_add('unconfirmed') +} + +=head2 + @states = FixMyStreet::DB::Problem::council_states(); Get a list of states that are availble to council users. If called in diff --git a/t/app/model/problem.t b/t/app/model/problem.t index c57f8af3b..1b6488fc7 100644 --- a/t/app/model/problem.t +++ b/t/app/model/problem.t @@ -33,6 +33,23 @@ my $problem = $problem_rs->new( } ); +my $visible_states = $problem->visible_states; +is_deeply $visible_states, { + 'confirmed' => 1, + 'investigating' => 1, + 'in progress' => 1, + 'planned' => 1, + 'action scheduled' => 1, + 'fixed' => 1, + 'fixed - council' => 1, + 'fixed - user' => 1, + 'unable to fix' => 1, + 'not responsible' => 1, + 'duplicate' => 1, + 'closed' => 1, + 'internal referral' => 1, + }, 'visible_states is correct'; + is $problem->confirmed, undef, 'inflating null confirmed ok'; is $problem->whensent, undef, 'inflating null confirmed ok'; is $problem->lastupdate, undef, 'inflating null confirmed ok'; |