diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/BathNES.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Borsetshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Buckinghamshire.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 24 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Lincolnshire.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Northamptonshire.pm | 2 | ||||
-rw-r--r-- | perllib/Open311/PopulateServiceList.pm | 31 |
10 files changed, 65 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 0e47d2238..2ff69b3b5 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -273,8 +273,13 @@ sub update_contacts : Private { if ( $c->get_param('reputation_threshold') ) { $contact->set_extra_metadata( reputation_threshold => int($c->get_param('reputation_threshold')) ); } - if ( my $group = $c->get_param('group') ) { - $contact->set_extra_metadata( group => $group ); + if ( my @group = $c->get_param_list('group') ) { + @group = grep { $_ } @group; + if (scalar @group == 0) { + $contact->unset_extra_metadata( 'group' ); + } else { + $contact->set_extra_metadata( group => \@group ); + } } else { $contact->unset_extra_metadata( 'group' ); } diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 6a6040865..7c7ebd202 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -741,11 +741,13 @@ sub setup_categories_and_bodies : Private { $c->stash->{missing_details_bodies} = \@missing_details_bodies; $c->stash->{missing_details_body_names} = \@missing_details_body_names; - if ( $c->cobrand->call_hook('enable_category_groups') ) { + if ( $c->cobrand->enable_category_groups ) { my %category_groups = (); for my $category (@category_options) { - my $group = $category->{group} // $category->get_extra_metadata('group') // ''; - push @{$category_groups{$group}}, $category; + 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); + push( @{$category_groups{$_}}, $category ) for @groups; } my @category_groups = (); diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm index d726c671e..ea9b26e7a 100644 --- a/perllib/FixMyStreet/Cobrand/BathNES.pm +++ b/perllib/FixMyStreet/Cobrand/BathNES.pm @@ -74,8 +74,6 @@ sub pin_colour { sub send_questionnaires { 0 } -sub enable_category_groups { 1 } - sub default_map_zoom { 3 } sub map_js_extra { diff --git a/perllib/FixMyStreet/Cobrand/Borsetshire.pm b/perllib/FixMyStreet/Cobrand/Borsetshire.pm index a99d2e7b4..f8650169d 100644 --- a/perllib/FixMyStreet/Cobrand/Borsetshire.pm +++ b/perllib/FixMyStreet/Cobrand/Borsetshire.pm @@ -27,6 +27,4 @@ sub send_questionnaires { sub bypass_password_checks { 1 } -sub enable_category_groups { 1 } - 1; diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm index 486e9603d..4c1d0108b 100644 --- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm +++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm @@ -185,8 +185,6 @@ sub map_type { 'Buckinghamshire' } sub default_map_zoom { 3 } -sub enable_category_groups { 1 } - sub _dashboard_export_add_columns { my $self = shift; my $c = $self->{c}; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index cc7f03adb..eaf27e3bc 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -1085,6 +1085,30 @@ sub show_unconfirmed_reports { 0; } +=item enable_category_groups + +Whether body category groups should be displayed on the new report form. If this is +not enabled then any groups will be ignored and a flat list of categories displayed. + +=cut + +sub enable_category_groups { + my $self = shift; + return $self->feature('category_groups'); +} + +=item enable_multiple_category_groups + +Whether a category can be included in multiple groups. Required enable_category_groups +to alse be true. + +=cut + +sub enable_multiple_category_groups { + my $self = shift; + return $self->enable_category_groups && $self->feature('multiple_category_groups'); +} + sub default_problem_state { 'unconfirmed' } sub state_groups_admin { diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index e01f3e23b..7c51eddd1 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -10,8 +10,6 @@ use constant COUNCIL_ID_BROMLEY => 2482; sub on_map_default_status { return 'open'; } -sub enable_category_groups { 1 } - # Special extra sub path_to_web_templates { my $self = shift; diff --git a/perllib/FixMyStreet/Cobrand/Lincolnshire.pm b/perllib/FixMyStreet/Cobrand/Lincolnshire.pm index 3b731b273..ca88f6b8e 100644 --- a/perllib/FixMyStreet/Cobrand/Lincolnshire.pm +++ b/perllib/FixMyStreet/Cobrand/Lincolnshire.pm @@ -18,7 +18,6 @@ sub council_name { return 'Lincolnshire County Council'; } sub council_url { return 'lincolnshire'; } sub is_two_tier { 1 } -sub enable_category_groups { 1 } sub send_questionnaires { 0 } sub report_sent_confirmation_email { 'external_id' } diff --git a/perllib/FixMyStreet/Cobrand/Northamptonshire.pm b/perllib/FixMyStreet/Cobrand/Northamptonshire.pm index 3d5d4b6f2..21a145326 100644 --- a/perllib/FixMyStreet/Cobrand/Northamptonshire.pm +++ b/perllib/FixMyStreet/Cobrand/Northamptonshire.pm @@ -47,8 +47,6 @@ sub privacy_policy_url { 'https://www3.northamptonshire.gov.uk/councilservices/council-and-democracy/transparency/information-policies/privacy-notice/place/Pages/street-doctor.aspx' } -sub enable_category_groups { 1 } - sub is_two_tier { 1 } sub get_geocoder { 'OSM' } diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index 2da67e9cd..5f7ca10a3 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -2,6 +2,7 @@ package Open311::PopulateServiceList; use Moo; use Open311; +use Text::CSV; has bodies => ( is => 'ro' ); has found_contacts => ( is => 'rw', default => sub { [] } ); @@ -262,11 +263,22 @@ sub _normalize_service_name { sub _set_contact_group { my ($self, $contact) = @_; - my $groups_enabled = $self->_current_body_cobrand && $self->_current_body_cobrand->call_hook('enable_category_groups'); + my $groups_enabled = $self->_current_body_cobrand && $self->_current_body_cobrand->enable_category_groups; + my $multi_groups_enabled = $self->_current_body_cobrand && $self->_current_body_cobrand->enable_multiple_category_groups; my $old_group = $contact->get_extra_metadata('group') || ''; my $new_group = $groups_enabled ? $self->_current_service->{group} || '' : ''; - if ($old_group ne $new_group) { + if ($multi_groups_enabled && $new_group =~ /,/) { + my $csv = Text::CSV->new; + if ( $csv->parse($new_group) ) { + $new_group = [ $csv->fields ]; + } else { + warn "error parsing groups for " . $self->_current_body_cobrand->moniker . "contact " . $contact->category . ": $new_group\n"; + $new_group = [ $new_group ]; + } + } + + if ($self->_groups_different($old_group, $new_group)) { if ($new_group) { $contact->set_extra_metadata(group => $new_group); $contact->update({ @@ -300,6 +312,21 @@ sub _set_contact_non_public { }) if $keywords{private}; } +sub _groups_different { + my ($self, $old, $new) = @_; + + my $diff = 1; + if ($old && $new) { + $old = [ $old ] unless ref $old eq 'ARRAY'; + $new = [ $new ] unless ref $new eq 'ARRAY'; + $diff = join( ',', sort(@$old) ) ne join( ',', sort(@$new) ); + } elsif (!$old && !$new) { + $diff = 0; + } + + return $diff; +} + sub _delete_contacts_not_in_service_list { my $self = shift; |