diff options
Diffstat (limited to 'perllib/FixMyStreet/App/Controller/Report.pm')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index fde28dcbe..debf27cde 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -661,6 +661,33 @@ sub check_has_permission_to : Private { return \%permissions; }; + +sub stash_category_groups : Private { + my ( $self, $c, $contacts, $combine_multiple ) = @_; + + my %category_groups = (); + for my $category (@$contacts) { + my $group = $category->{group} // $category->get_extra_metadata('group') // ['']; + # this could be an array ref or a string + my @groups = ref $group eq 'ARRAY' ? @$group : ($group); + if (scalar @groups > 1 && $combine_multiple) { + @groups = sort @groups; + $category->{group} = \@groups; + push( @{$category_groups{_('Multiple Groups')}}, $category ); + } else { + push( @{$category_groups{$_}}, $category ) for @groups; + } + } + + my @category_groups = (); + for my $group ( grep { $_ ne _('Other') && $_ ne _('Multiple Groups') } sort keys %category_groups ) { + push @category_groups, { name => $group, categories => $category_groups{$group} }; + } + push @category_groups, { name => _('Other'), categories => $category_groups{_('Other')} } if ($category_groups{_('Other')}); + push @category_groups, { name => _('Multiple Groups'), categories => $category_groups{_('Multiple Groups')} } if ($category_groups{_('Multiple Groups')}); + $c->stash->{category_groups} = \@category_groups; +} + __PACKAGE__->meta->make_immutable; 1; |