diff options
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 47 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/IsleOfWight.pm | 16 |
2 files changed, 12 insertions, 51 deletions
diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index 97a0ab53a..a2dea1df4 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -131,51 +131,8 @@ sub munge_load_and_group_problems { return unless $where->{category} && $self->{c}->stash->{body}->name eq 'Isle of Wight Council'; - $where->{category} = $self->expand_triage_cat_list($where->{category}); -} - -sub expand_triage_cat_list { - my ($self, $categories) = @_; - - my $b = $self->{c}->stash->{body}; - - 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'); - my $groups = $cat->get_extra_metadata('group'); - $groups = ref $groups eq 'ARRAY' ? $groups : [ $groups ]; - for my $group ( @$groups ) { - $group_to_category{$group} //= []; - push @{ $group_to_category{$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 && $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; + my $iow = FixMyStreet::Cobrand->get_class_for_moniker( 'isleofwight' )->new({ c => $self->{c} }); + $where->{category} = $iow->expand_triage_cat_list($where->{category}, $self->{c}->stash->{body}); } sub title_list { diff --git a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm index a46b540ad..db0a20b9c 100644 --- a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm +++ b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm @@ -142,7 +142,7 @@ sub munge_load_and_group_problems { return unless $where->{category}; - $where->{category} = $self->expand_triage_cat_list($where->{category}); + $where->{category} = $self->_expand_triage_cat_list($where->{category}); } sub munge_around_filter_category_list { @@ -151,17 +151,21 @@ sub munge_around_filter_category_list { my $c = $self->{c}; return unless $c->stash->{filter_category}; - my $cat_names = $self->expand_triage_cat_list([ keys %{$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 }; } +sub _expand_triage_cat_list { + my ($self, $categories) = @_; + my $b = $self->{c}->model('DB::Body')->for_areas( $self->council_area_id )->first; + return $self->expand_triage_cat_list($categories, $b); +} + # 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 ($self, $categories, $b) = @_; my $all_cats = $self->{c}->model('DB::Contact')->not_deleted->search( { @@ -190,7 +194,7 @@ sub expand_triage_cat_list { my @cat_names; while ( my $cat = $cats->next ) { - if ( $cat->send_method eq 'Triage' ) { + if ( $cat->send_method && $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}; |