diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 22 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/IsleOfWight.pm | 88 |
3 files changed, 116 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index 203296c4d..cebc4ed85 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -236,10 +236,15 @@ sub check_and_stash_category : Private { $csv->combine(@list_of_names); $c->{stash}->{list_of_names_as_string} = $csv->string; + my $where = { body_id => [ keys %bodies ], }; + + my $cobrand_where = $c->cobrand->call_hook('munge_category_where', $where ); + if ( $cobrand_where ) { + $where = $cobrand_where; + } + my @categories = $c->model('DB::Contact')->not_deleted->search( - { - body_id => [ keys %bodies ], - }, + $where, { columns => [ 'category', 'extra' ], order_by => [ 'category' ], @@ -252,6 +257,7 @@ sub check_and_stash_category : Private { my $categories = [ $c->get_param_list('filter_category', 1) ]; my %valid_categories = map { $_ => 1 } grep { $_ && $categories_mapped{$_} } @$categories; $c->stash->{filter_category} = \%valid_categories; + $c->cobrand->call_hook('munge_filter_category'); } sub map_features : Private { @@ -312,6 +318,7 @@ sub ajax : Path('/ajax') { my %valid_categories = map { $_ => 1 } $c->get_param_list('filter_category', 1); $c->stash->{filter_category} = \%valid_categories; + $c->cobrand->call_hook('munge_filter_category'); $c->forward('map_features', [ { bbox => $c->stash->{bbox} } ]); $c->forward('/reports/ajax', [ 'around/on_map_list_items.html' ]); diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index e5327b084..377253955 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -7,6 +7,7 @@ use warnings; use mySociety::Random; use constant COUNCIL_ID_BROMLEY => 2482; +use constant COUNCIL_ID_ISLEOFWIGHT => 2636; sub on_map_default_status { return 'open'; } @@ -41,9 +42,24 @@ sub munge_category_list { my ($self, $options, $contacts, $extras) = @_; # No TfL Traffic Lights category in Hounslow - my %bodies = map { $_->body->name => 1 } @$contacts; - return unless $bodies{'Hounslow Borough Council'}; - @$options = grep { ($_->{category} || $_->category) !~ /^Traffic lights$/i } @$options; + my %bodies = map { $_->body->name => $_->body } @$contacts; + if ( $bodies{'Hounslow Borough Council'} ) { + @$options = grep { ($_->{category} || $_->category) !~ /^Traffic lights$/i } @$options; + } + + if ( $bodies{'Isle of Wight Council'} ) { + my $user = $self->{c}->user; + if ( $user && ( $user->is_superuser || $user->belongs_to_body( $bodies{'Isle of Wight Council'}->id ) ) ) { + @$contacts = grep { !$_->send_method || $_->send_method ne 'Triage' } @$contacts; + my $seen = { map { $_->category => 1 } @$contacts }; + @$options = grep { my $c = ($_->{category} || $_->category); $c =~ 'Pick a category' || $seen->{ $c } } @$options; + return; + } + + @$contacts = grep { $_->send_method && $_->send_method eq 'Triage' } @$contacts; + my $seen = { map { $_->category => 1 } @$contacts }; + @$options = grep { my $c = ($_->{category} || $_->category); $c =~ 'Pick a category' || $seen->{ $c } } @$options; + } } sub title_list { diff --git a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm index f2cd1a687..c8fc75eaa 100644 --- a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm +++ b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm @@ -87,6 +87,7 @@ sub open311_munge_update_params { $params->{description} = "FMS-Update: " . $params->{description}; } +# this handles making sure the user sees the right categories on the new report page sub munge_category_list { my ($self, $options, $contacts, $extras) = @_; @@ -95,14 +96,99 @@ sub munge_category_list { my $b = $bodies{'Isle of Wight Council'}; if ( $user && ( $user->is_superuser || $user->belongs_to_body( $b->id ) ) ) { + @$contacts = grep { !$_->send_method || $_->send_method ne 'Triage' } @$contacts; + my $seen = { map { $_->category => 1 } @$contacts }; + @$options = grep { my $c = ($_->{category} || $_->category); $c =~ 'Pick a category' || $seen->{ $c } } @$options; return; } - @$contacts = grep { $_->send_method eq 'Triage' } @$contacts; + @$contacts = grep { $_->send_method && $_->send_method eq 'Triage' } @$contacts; my $seen = { map { $_->category => 1 } @$contacts }; @$options = grep { my $c = ($_->{category} || $_->category); $c =~ 'Pick a category' || $seen->{ $c } } @$options; } +sub munge_category_where { + my ($self, $where) = @_; + + my $user = $self->{c}->user; + my $b = $self->{c}->model('DB::Body')->for_areas( $self->council_area_id )->first; + if ( $user && ( $user->is_superuser || $user->belongs_to_body( $b->id ) ) ) { + $where = { + body_id => $where->{body_id}, + send_method => [ { '!=' => 'Triage' }, undef ], + }; + return $where; + } + + $where->{'send_method'} = 'Triage'; + return $where; +} + +sub munge_load_and_group_problems { + my ($self, $where, $filter) = @_; + + return unless $where->{category}; + + my @cat_names = $self->expand_triage_cat_list($where->{category}); + + $where->{category} = \@cat_names; + my $problems = $self->problems->search($where, $filter); + return $problems; +} + +sub munge_filter_category { + my $self = shift; + + my $c = $self->{c}; + return unless $c->stash->{filter_category}; + + my @cat_names = $self->expand_triage_cat_list([ keys %{$c->stash->{filter_category}} ]); + $c->stash->{filter_category} = { map { $_ => 1 } @cat_names }; +} + +# this assumes that each Triage category has the same name as a group +# and uses this to generate a list of categories that a triage category +# could be triaged to +sub expand_triage_cat_list { + my ($self, $categories) = @_; + + my $b = $self->{c}->model('DB::Body')->for_areas( $self->council_area_id )->first; + + my $all_cats = $self->{c}->model('DB::Contact')->not_deleted->search( + { + body_id => $b->id, + send_method => [{ '!=', 'Triage'}, undef] + } + ); + + my %group_to_category; + while ( my $cat = $all_cats->next ) { + next unless $cat->get_extra_metadata('group'); + $group_to_category{$cat->get_extra_metadata('group')} //= []; + push @{ $group_to_category{$cat->get_extra_metadata('group')} }, $cat->category; + } + + my $cats = $self->{c}->model('DB::Contact')->not_deleted->search( + { + body_id => $b->id, + category => $categories + } + ); + + my @cat_names; + while ( my $cat = $cats->next ) { + if ( $cat->send_method eq 'Triage' ) { + # include the category itself + push @cat_names, $cat->category; + push @cat_names, @{ $group_to_category{$cat->category} } if $group_to_category{$cat->category}; + } else { + push @cat_names, $cat->category; + } + } + + return @cat_names; +} + sub open311_get_update_munging { my ($self, $comment) = @_; |