diff options
author | Matthew Somerville <matthew@mysociety.org> | 2012-12-13 15:41:08 +0000 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2012-12-15 00:11:06 +0000 |
commit | 48d290abd549a623e3af4b62127668cf92018d9c (patch) | |
tree | d12bd6717105464b36699c64c9da08bfa274b74e /perllib/FixMyStreet/App | |
parent | de87d4217334114bc5f92552b29c0c4a59428ca5 (diff) |
Update reporting to use bodies.
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Alert.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 12 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Council.pm | 52 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 103 |
5 files changed, 91 insertions, 88 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Alert.pm b/perllib/FixMyStreet/App/Controller/Alert.pm index 91ea61fbc..e821b7467 100644 --- a/perllib/FixMyStreet/App/Controller/Alert.pm +++ b/perllib/FixMyStreet/App/Controller/Alert.pm @@ -407,13 +407,13 @@ Generate the details required to display the council/ward/area RSS feeds sub setup_council_rss_feeds : Private { my ( $self, $c ) = @_; - $c->stash->{council_check_action} = 'alert'; - unless ( $c->forward('/council/load_and_check_councils_and_wards') ) { + $c->stash->{area_check_action} = 'alert'; + unless ( $c->forward('/council/load_and_check_areas_and_wards') ) { $c->go('index'); } ( $c->stash->{options}, $c->stash->{reported_to_options} ) = - $c->cobrand->council_rss_alert_options( $c->stash->{all_councils}, $c ); + $c->cobrand->council_rss_alert_options( $c->stash->{all_areas}, $c ); return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index f2bb23350..200dbd696 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -44,7 +44,7 @@ sub around_index : Path : Args(0) { unless $c->forward('/location/determine_location_from_coords') || $c->forward('/location/determine_location_from_pc'); - # Check to see if the spot is covered by a council - if not show an error. + # Check to see if the spot is covered by a area - if not show an error. return unless $c->cobrand->moniker eq 'fixmybarangay' || $c->forward('check_location_is_acceptable'); # If we have a partial - redirect to /report/new so that it can be @@ -212,7 +212,7 @@ sub display_location : Private { =head2 check_location_is_acceptable -Find the lat and lon in stash and check that they are acceptable to the council, +Find the lat and lon in stash and check that they are acceptable to the area, and that they are in UK (if we are in UK). =cut @@ -220,10 +220,10 @@ and that they are in UK (if we are in UK). sub check_location_is_acceptable : Private { my ( $self, $c ) = @_; - # check that there are councils that can accept this location - $c->stash->{council_check_action} = 'submit_problem'; - $c->stash->{remove_redundant_councils} = 1; - return $c->forward('/council/load_and_check_councils'); + # check that there are areas that can accept this location + $c->stash->{area_check_action} = 'submit_problem'; + $c->stash->{remove_redundant_areas} = 1; + return $c->forward('/council/load_and_check_areas'); } =head2 /ajax diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm index cb9e78421..5d95c2538 100644 --- a/perllib/FixMyStreet/App/Controller/Council.pm +++ b/perllib/FixMyStreet/App/Controller/Council.pm @@ -14,34 +14,34 @@ Catalyst Controller. =head1 METHODS -=head2 load_and_check_councils_and_wards +=head2 load_and_check_areas_and_wards -Try to load councils and wards for this location and check that we have at least one. If -there are no councils then return false. +Try to load areas and wards for this location and check that we have at least one. If +there are no areas then return false. =cut -sub load_and_check_councils_and_wards : Private { +sub load_and_check_areas_and_wards : Private { my ( $self, $c ) = @_; my $area_types = [ @{$c->cobrand->area_types}, @{$c->cobrand->area_types_children} ]; $c->stash->{area_types} = $area_types; - $c->forward('load_and_check_councils'); + $c->forward('load_and_check_areas'); } -=head2 load_and_check_councils +=head2 load_and_check_areas -Try to load councils for this location and check that we have at least one. If -there are no councils then return false. +Try to load areas for this location and check that we have at least one. If +there are no areas then return false. =cut -sub load_and_check_councils : Private { +sub load_and_check_areas : Private { my ( $self, $c ) = @_; my $latitude = $c->stash->{latitude}; my $longitude = $c->stash->{longitude}; - # Look up councils and do checks for the point we've got + # Look up areas and do checks for the point we've got my $area_types; if ( $c->stash->{area_types} and scalar @{ $c->stash->{area_types} } ) { $area_types = $c->stash->{area_types}; @@ -52,49 +52,49 @@ sub load_and_check_councils : Private { my $short_latitude = Utils::truncate_coordinate($latitude); my $short_longitude = Utils::truncate_coordinate($longitude); - my $all_councils; + my $all_areas; if ( $c->stash->{fetch_all_areas} ) { my %area_types = map { $_ => 1 } @$area_types; - my $all_areas = + $all_areas = mySociety::MaPit::call( 'point', "4326/$short_longitude,$short_latitude" ); - $c->stash->{all_areas} = $all_areas; - $all_councils = { + $c->stash->{all_areas_mapit} = $all_areas; + $all_areas = { map { $_ => $all_areas->{$_} } grep { $area_types{ $all_areas->{$_}->{type} } } keys %$all_areas }; } else { - $all_councils = + $all_areas = mySociety::MaPit::call( 'point', "4326/$short_longitude,$short_latitude", type => $area_types ); } - if ($all_councils->{error}) { - $c->stash->{location_error} = $all_councils->{error}; + if ($all_areas->{error}) { + $c->stash->{location_error} = $all_areas->{error}; return; } # Let cobrand do a check my ( $success, $error_msg ) = - $c->cobrand->council_check( { all_councils => $all_councils }, - $c->stash->{council_check_action} ); + $c->cobrand->area_check( { all_areas => $all_areas }, + $c->stash->{area_check_action} ); if ( !$success ) { $c->stash->{location_error} = $error_msg; return; } # edit hash in-place - $c->cobrand->remove_redundant_councils($all_councils) if $c->stash->{remove_redundant_councils}; + $c->cobrand->remove_redundant_areas($all_areas) if $c->stash->{remove_redundant_areas}; - # If we don't have any councils we can't accept the report - if ( !scalar keys %$all_councils ) { + # If we don't have any areas we can't accept the report + if ( !scalar keys %$all_areas ) { $c->stash->{location_error} = _('That location does not appear to be covered by a council; perhaps it is offshore or outside the country. Please try again.'); return; } - # all good if we have some councils left - $c->stash->{all_councils} = $all_councils; - $c->stash->{all_council_names} = - [ map { $_->{name} } values %$all_councils ]; + # all good if we have some areas left + $c->stash->{all_areas} = $all_areas; + $c->stash->{all_area_names} = + [ map { $_->{name} } values %$all_areas ]; return 1; } diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 94450f4f3..00220deff 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -29,7 +29,7 @@ sub example : Local : Args(0) { } # TODO Set up manual version of what the below would do - #$c->forward( '/report/new/setup_categories_and_councils' ); + #$c->forward( '/report/new/setup_categories_and_bodies' ); # See if we've had anything from the dropdowns - perhaps vary results if so $c->stash->{ward} = $c->req->param('ward'); @@ -100,8 +100,8 @@ sub index : Path : Args(0) { ); $c->stash->{children} = $children; - $c->stash->{all_councils} = { $council => $council_detail }; - $c->forward( '/report/new/setup_categories_and_councils' ); + $c->stash->{all_areas} = { $council => $council_detail }; + $c->forward( '/report/new/setup_categories_and_bodies' ); # See if we've had anything from the dropdowns diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 57cf1de49..bb8f8f03f 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -89,7 +89,7 @@ sub report_new : Path : Args(0) { # create a problem from the submitted details $c->stash->{template} = "report/new/fill_in_details.html"; - $c->forward('setup_categories_and_councils'); + $c->forward('setup_categories_and_bodies'); $c->forward('generate_map'); $c->forward('check_for_category'); @@ -119,7 +119,7 @@ sub report_new_ajax : Path('mobile') : Args(0) { return 1; } - $c->forward('setup_categories_and_councils'); + $c->forward('setup_categories_and_bodies'); $c->forward('process_user'); $c->forward('process_report'); $c->forward('/photo/process_photo'); @@ -180,7 +180,7 @@ sub report_form_ajax : Path('ajax') : Args(0) { return; } - $c->forward('setup_categories_and_councils'); + $c->forward('setup_categories_and_bodies'); # render templates to get the html my $category = $c->render_fragment( 'report/new/category.html'); @@ -215,7 +215,7 @@ sub category_extras_ajax : Path('category_extras') : Args(0) { $c->res->body($body); return 1; } - $c->forward('setup_categories_and_councils'); + $c->forward('setup_categories_and_bodies'); my $category_extra = ''; if ( $c->stash->{category_extras}->{ $c->req->param('category') } && @{ $c->stash->{category_extras}->{ $c->req->param('category') } } >= 1 ) { @@ -568,27 +568,30 @@ sub determine_location_from_report : Private { return; } -=head2 setup_categories_and_councils +=head2 setup_categories_and_bodies -Look up categories for this council or councils +Look up categories for the relevant body or bodies. =cut -sub setup_categories_and_councils : Private { +sub setup_categories_and_bodies : Private { my ( $self, $c ) = @_; - my $all_councils = $c->stash->{all_councils}; - my $first_council = ( values %$all_councils )[0]; + my $all_areas = $c->stash->{all_areas}; + my $first_area = ( values %$all_areas )[0]; + + my @bodies = $c->model('DB::Body')->search( { area_id => [ keys %$all_areas ] } )->all; + my %bodies = map { $_->id => $_ } @bodies; my @contacts # = $c # ->model('DB::Contact') # ->not_deleted # - ->search( { body_id => [ keys %$all_councils ] } ) # + ->search( { body => [ keys %bodies ] } ) ->all; # variables to populate - my %area_ids_to_list = (); # Areas with categories assigned + my %bodies_to_list = (); # Bodies with categories assigned my @category_options = (); # categories to show my $category_label = undef; # what to call them my %category_extras = (); # extra fields to fill in for open311 @@ -598,9 +601,9 @@ sub setup_categories_and_councils : Private { # FIXME - implement in cobrand if ( $c->cobrand->moniker eq 'emptyhomes' ) { - # add all areas found to the list + # add all bodies found to the list foreach (@contacts) { - $area_ids_to_list{ $_->body_id } = 1; + $bodies_to_list{ $_->body_id } = 1; } # set our own categories @@ -615,11 +618,12 @@ sub setup_categories_and_councils : Private { ); $category_label = _('Property type:'); - } elsif ($first_council->{id} != COUNCIL_ID_BROMLEY && $first_council->{type} eq 'LBO') { + } elsif ($first_area->{id} != COUNCIL_ID_BROMLEY && $first_area->{type} eq 'LBO') { - $area_ids_to_list{ $first_council->{id} } = 1; + # Assumes body ID and area ID match here + $bodies_to_list{ $first_area->{id} } = 1; my @local_categories; - if ($first_council->{id} == COUNCIL_ID_BARNET) { + if ($first_area->{id} == COUNCIL_ID_BARNET) { @local_categories = sort keys %{ Utils::barnet_categories() } } else { @local_categories = sort keys %{ Utils::london_categories() } @@ -638,7 +642,7 @@ sub setup_categories_and_councils : Private { my %seen; foreach my $contact (@contacts) { - $area_ids_to_list{ $contact->body_id } = 1; + $bodies_to_list{ $contact->body_id } = 1; unless ( $seen{$contact->category} ) { push @category_options, $contact->category; @@ -660,24 +664,21 @@ sub setup_categories_and_councils : Private { } # put results onto stash for display - $c->stash->{area_ids_to_list} = [ keys %area_ids_to_list ]; + $c->stash->{bodies} = \%bodies; + $c->stash->{all_body_names} = [ map { $_->name } values %bodies ]; + $c->stash->{bodies_to_list} = [ keys %bodies_to_list ]; $c->stash->{category_label} = $category_label; $c->stash->{category_options} = \@category_options; $c->stash->{category_extras} = \%category_extras; $c->stash->{non_public_categories} = \%non_public_categories; $c->stash->{category_extras_json} = encode_json \%category_extras; - $c->stash->{extra_name_info} = $first_council->{id} == COUNCIL_ID_BROMLEY ? 1 : 0; - - my @missing_details_councils = - grep { !$area_ids_to_list{$_} } # - keys %$all_councils; + $c->stash->{extra_name_info} = $first_area->{id} == COUNCIL_ID_BROMLEY ? 1 : 0; - my @missing_details_council_names = - map { $all_councils->{$_}->{name} } # - @missing_details_councils; + my @missing_details_bodies = grep { !$bodies_to_list{$_->id} } values %bodies; + my @missing_details_body_names = map { $_->name } @missing_details_bodies; - $c->stash->{missing_details_councils} = \@missing_details_councils; - $c->stash->{missing_details_council_names} = \@missing_details_council_names; + $c->stash->{missing_details_bodies} = \@missing_details_bodies; + $c->stash->{missing_details_body_names} = \@missing_details_body_names; } =head2 check_form_submitted @@ -804,60 +805,62 @@ sub process_report : Private { # set these straight from the params $report->category( _ $params{category} ) if $params{category}; - my $areas = $c->stash->{all_areas}; + my $areas = $c->stash->{all_areas_mapit}; $report->areas( ',' . join( ',', sort keys %$areas ) . ',' ); # From earlier in the process. - my $councils = $c->stash->{all_councils}; - my $first_council = ( values %$councils )[0]; + $areas = $c->stash->{all_areas}; + my $bodies = $c->stash->{bodies}; + my $first_area = ( values %$areas )[0]; if ( $c->cobrand->moniker eq 'emptyhomes' ) { - $councils = join( ',', @{ $c->stash->{area_ids_to_list} } ) || -1; - $report->council( $councils ); + $bodies = join( ',', @{ $c->stash->{bodies_to_list} } ) || -1; + $report->bodies( $bodies ); - } elsif ( $first_council->{id} == COUNCIL_ID_BARNET ) { + } elsif ( $first_area->{id} == COUNCIL_ID_BARNET ) { + # As in setup, assumes body ID == area ID for London unless ( exists Utils::barnet_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); } - $report->council( $first_council->{id} ); + $report->bodies( $first_area->{id} ); - } elsif ( $first_council->{id} != COUNCIL_ID_BROMLEY && $first_council->{type} eq 'LBO') { + } elsif ( $first_area->{id} != COUNCIL_ID_BROMLEY && $first_area->{type} eq 'LBO') { unless ( Utils::london_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); } - $report->council( $first_council->{id} ); + $report->area( $first_area->{id} ); } elsif ( $report->category ) { - # FIXME All contacts were fetched in setup_categories_and_councils, + # FIXME All contacts were fetched in setup_categories_and_bodies, # so can this DB call also be avoided? my @contacts = $c-> # model('DB::Contact') # ->not_deleted # ->search( { - body_id => [ keys %$councils ], + body => [ keys %$bodies ], category => $report->category } )->all; unless ( @contacts ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); - $report->council( -1 ); + $report->bodies( -1 ); return 1; } - # construct the council string: - # 'x,x' - x are council IDs that have this category - # 'x,x|y,y' - x are council IDs that have this category, y council IDs with *no* contact - my $council_string = join( ',', map { $_->body_id } @contacts ); - $council_string .= - '|' . join( ',', @{ $c->stash->{missing_details_councils} } ) - if $council_string && @{ $c->stash->{missing_details_councils} }; - $report->council($council_string); + # construct the bodies string: + # 'x,x' - x are body IDs that have this category + # 'x,x|y' - x are body IDs that have this category, y body IDs with *no* contact + my $body_string = join( ',', map { $_->body_id } @contacts ); + $body_string .= + '|' . join( ',', @{ $c->stash->{missing_details_bodies} } ) + if $body_string && @{ $c->stash->{missing_details_bodies} }; + $report->bodies($body_string); my @extra = (); my $metas = $contacts[0]->extra; @@ -894,7 +897,7 @@ sub process_report : Private { # If we're here, we've been submitted somewhere # where we have no contact information at all. - $report->council( -1 ); + $report->bodies( -1 ); } @@ -1013,7 +1016,7 @@ sub save_user_and_report : Private { $report->category( _('Other') ) unless $report->category; # Set unknown to DB unknown - $report->council( undef ) if $report->council eq '-1'; + $report->bodies( undef ) if $report->bodies eq '-1'; # if there is a Message Manager message ID, pass it back to the client view if ($c->cobrand->moniker eq 'fixmybarangay' && $c->req->param('external_source_id')=~/^\d+$/) { |