aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB
diff options
context:
space:
mode:
authorHakim Cassimally <hakim@mysociety.org>2015-02-09 14:40:48 +0000
committerMatthew Somerville <matthew-github@dracos.co.uk>2015-06-16 17:33:24 +0100
commit1df64a30dd0939d8d9b8b1854f7f7e421d9b20ab (patch)
tree6e817af4ecb0bcdfa161bbaeb820c5e82ad4628b /perllib/FixMyStreet/DB
parentcee9d93ea8e7fefecdb435bada240445b44022a3 (diff)
Add hidden_states and updating functions.
To allow visible/hidden states to be manipulated at runtime.
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm96
1 files changed, 64 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