diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports/New.pm | 183 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 132 | ||||
-rw-r--r-- | templates/web/default/reports/new/fill_in_details.html | 3 | ||||
-rw-r--r-- | templates/web/default/reports/new/some_councils_text.html | 4 |
4 files changed, 168 insertions, 154 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Reports/New.pm b/perllib/FixMyStreet/App/Controller/Reports/New.pm index 10a10b55d..9b7a55cdb 100644 --- a/perllib/FixMyStreet/App/Controller/Reports/New.pm +++ b/perllib/FixMyStreet/App/Controller/Reports/New.pm @@ -79,7 +79,7 @@ sub report_new : Path : Args(0) { # work out the location for this report and do some checks return unless $c->forward('determine_location') - && $c->forward('check_councils'); + && $c->forward('load_councils'); # create a problem from the submitted details $c->stash->{template} = "reports/new/fill_in_details.html"; @@ -247,13 +247,14 @@ sub determine_location_from_pc : Private { return; } -=head2 check_councils +=head2 load_councils -Load all the councils and check that they are ok. Do a small amount of cleanup. +Try to load councils for this location and check that we have at least one. If +there are no councils then return false. =cut -sub check_councils : Private { +sub load_councils : Private { my ( $self, $c ) = @_; my $latitude = $c->stash->{latitude}; my $longitude = $c->stash->{longitude}; @@ -261,7 +262,7 @@ sub check_councils : Private { # Look up councils and do checks for the point we've got my @area_types = $c->cobrand->area_types(); - # XXX: I think we want in_gb_locale around the next line, needs testing + # TODO: I think we want in_gb_locale around the next line, needs testing my $all_councils = mySociety::MaPit::call( 'point', "4326/$longitude,$latitude", type => \@area_types ); @@ -275,9 +276,32 @@ sub check_councils : Private { return; } + # If we don't have any councils we can't accept the report + if ( !scalar keys %$all_councils ) { + $c->stash->{location_error} = + _( 'That spot does not appear to be covered by a council. If you' + . ' have tried to report an issue past the shoreline, for' + . ' example, please specify the closest point on land.' ); + return; + } + + # edit hash in-place + _remove_redundant_councils($all_councils); + + # all good if we have some councils left + $c->stash->{all_councils} = $all_councils; + $c->stash->{all_council_names} = + [ map { $_->{name} } values %$all_councils ]; + return 1; +} + +# FIXME - should not be here. +# These are country specific tweaks that should be in the cobrands +sub _remove_redundant_councils { + my $all_councils = shift; + # UK specific tweaks - # FIXME - move into cobrand - if ( mySociety::Config::get('COUNTRY') eq 'GB' ) { + if ( FixMyStreet->config('COUNTRY') eq 'GB' ) { # Ipswich & St Edmundsbury are responsible for everything in their # areas, not Suffolk @@ -291,28 +315,13 @@ sub check_councils : Private { } # Norway specific tweaks - # FIXME - move into cobrand - if ( mySociety::Config::get('COUNTRY') eq 'NO' ) { + if ( FixMyStreet->config('COUNTRY') eq 'NO' ) { # Oslo is both a kommune and a fylke, we only want to show it once delete $all_councils->{301} # if $all_councils->{3}; } - # were councils found for this location - if ( !scalar keys %$all_councils ) { - $c->stash->{location_error} = - _( 'That spot does not appear to be covered by a council. If you' - . ' have tried to report an issue past the shoreline, for' - . ' example, please specify the closest point on land.' ); - 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 ]; - return 1; } =head2 setup_categories_and_councils @@ -334,15 +343,19 @@ sub setup_categories_and_councils : Private { ->all; # variables to populate - my @area_ids_to_list = (); - my @category_options = (); - my $category_label = undef; + my @area_ids_to_list = (); # Areas with categories assigned + my @category_options = (); # categories to show + my $category_label = undef; # what to call them # FIXME - implement in cobrand if ( $c->cobrand->moniker eq 'emptyhomes' ) { + + # add all areas found to the list foreach (@contacts) { push @area_ids_to_list, $_->area_id; } + + # set our own categories @category_options = ( _('-- Pick a property type --'), _('Empty house or bungalow'), @@ -363,32 +376,32 @@ sub setup_categories_and_councils : Private { unless $contact->category eq _('Other'); } - # defunct... - # if ( $q->{site} eq 'scambs' ) { - # @categories = Page::scambs_categories(); - # } - if (@category_options) { @category_options = ( _('-- Pick a category --'), @category_options, _('Other') ); $category_label = _('Category:'); } - } - # put results onto stash + # put results onto stash for display $c->stash->{area_ids_to_list} = \@area_ids_to_list; - $c->stash->{category_options} = \@category_options; $c->stash->{category_label} = $category_label; + $c->stash->{category_options} = \@category_options; # add some conveniant things to the stash my $all_councils = $c->stash->{all_councils}; my %area_ids_to_list_hash = map { $_ => 1 } @area_ids_to_list; - my @missing = - grep { !$area_ids_to_list_hash{$_} } keys %$all_councils; - my @missing_names = map { $all_councils->{$_}->{name} } @missing; - $c->stash->{missing} = @missing; - $c->stash->{missing_names} = @missing_names; + + my @missing_details_councils = + grep { !$area_ids_to_list_hash{$_} } # + keys %$all_councils; + + my @missing_details_council_names = + map { $all_councils->{$_}->{name} } # + @missing_details_councils; + + $c->stash->{missing_details_councils} = @missing_details_councils; + $c->stash->{missing_details_council_names} = @missing_details_council_names; } =head2 process_user @@ -458,8 +471,8 @@ sub process_report : Private { map { $_ => scalar $c->req->param($_) } # ( 'title', 'detail', 'pc', # - 'name', 'may_show_name', # - 'council', 'category', # + 'name', 'may_show_name', # + 'category', # 'partial', 'skipped', 'upload_fileid', # ); @@ -494,57 +507,63 @@ sub process_report : Private { my $areas = mySociety::MaPit::call( 'point', $mapit_query ); $report->areas( ',' . join( ',', sort keys %$areas ) . ',' ); - # council = -1 - none - # council = 1,2,3 - all found - # council = 1,2|3,4 - found|missing - if ( $params{council} =~ m{^\d} ) { - - my ( $found_council_str, $missing_council_str ) = - split( m{\|}, $params{council}, 2 ); + # determine the area_types that this cobrand is interested in + my @area_types = $c->cobrand->area_types(); + my %area_types_lookup = map { $_ => 1 } @area_types; - my @area_types = $c->cobrand->area_types(); - my %area_types_lookup = map { $_ => 1 } @area_types; + # get all the councils that are of these types and cover this area + my %councils = + map { $_ => 1 } # + grep { $area_types_lookup{ $areas->{$_}->{type} } } # + keys %$areas; - my %councils = - map { $_ => 1 } # - grep { $area_types_lookup{ $areas->{$_}->type } } # - keys %$areas; + # partition the councils onto these two arrays + my @councils_with_category = (); + my @councils_without_category = (); - my @input_councils = split /,|\|/, $params{council}; + # all councils have all categories for emptyhomes + if ( $c->cobrand->moniker eq 'emptyhomes' ) { + @councils_with_category = keys %councils; + } + else { - foreach (@input_councils) { - if ( !$councils{$_} ) { - push( @errors, _('That location is not part of that council') ); - last; + my @contacts = $c-> # + model('DB::Contact') # + ->not_deleted # + ->search( + { + area_id => [ keys %councils ], # + category => $report->category } - } + )->all; - if ($missing_council_str) { - $input{council} =~ $found_council_str; - @input_councils = split /,/, $input{council}; - } + # clear category if it is not in db for possible councils + $report->category(undef) unless @contacts; - # Check category here, won't be present if council is -1 - my @valid_councils = @input_councils; - if ( $input{category} && $q->{site} ne 'emptyhomes' ) { - my $categories = select_all( - "select area_id from contacts - where deleted='f' and area_id in (" - . $input{council} . ') and category = ?', $input{category} - ); - $field_errors{category} = _('Please choose a category') - unless @$categories; - @valid_councils = map { $_->{area_id} } @$categories; - foreach my $c (@valid_councils) { - if ( $no_details =~ /$c/ ) { - push( @errors, _('We have details for that council') ); - $no_details =~ s/,?$c//; - } - } + my %councils_with_contact_for_category = + map { $_->area_id => 1 } @contacts; + + foreach my $council_key ( keys %councils ) { + $councils_with_contact_for_category{$council_key} + ? push( @councils_with_category, $council_key ) + : push( @councils_without_category, $council_key ); } - $input{council} = join( ',', @valid_councils ) . $no_details; + } + # construct the council string: + # 'x,x' - x are councils_ids that have this category + # 'x,x|y,y' - x are councils_ids that have this category, y don't + # '-1' - no councils have this category + my $council_string = join '|', grep { $_ } # + ( + join( ',', @councils_with_category ), + join( ',', @councils_without_category ) + ); + $council_string ||= '-1'; # no councils found with categories + $report->council($council_string); + warn "council_string: $council_string"; + # my $image; # if ($fh) { # try { diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 953f663ba..cc009ee81 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -10,77 +10,76 @@ use base 'DBIx::Class::Core'; __PACKAGE__->table("problem"); __PACKAGE__->add_columns( - "id", - { - data_type => "integer", - is_auto_increment => 1, - is_nullable => 0, - sequence => "problem_id_seq", - }, - "postcode", - { data_type => "text", is_nullable => 0 }, - "council", - { data_type => "text", is_nullable => 1 }, - "areas", - { data_type => "text", is_nullable => 0 }, - "category", - { data_type => "text", default_value => "Other", is_nullable => 0 }, - "title", - { data_type => "text", is_nullable => 0 }, - "detail", - { data_type => "text", is_nullable => 0 }, - "photo", - { data_type => "bytea", is_nullable => 1 }, - "used_map", - { data_type => "boolean", is_nullable => 0 }, - "name", - { data_type => "text", is_nullable => 0 }, - "anonymous", - { data_type => "boolean", is_nullable => 0 }, - "created", - { - data_type => "timestamp", - default_value => \"ms_current_timestamp()", - is_nullable => 0, - }, - "confirmed", - { data_type => "timestamp", is_nullable => 1 }, - "state", - { data_type => "text", is_nullable => 0 }, - "lang", - { data_type => "text", default_value => "en-gb", is_nullable => 0 }, - "service", - { data_type => "text", default_value => "", is_nullable => 0 }, - "cobrand", - { data_type => "text", default_value => "", is_nullable => 0 }, - "cobrand_data", - { data_type => "text", default_value => "", is_nullable => 0 }, - "lastupdate", - { - data_type => "timestamp", - default_value => \"ms_current_timestamp()", - is_nullable => 0, - }, - "whensent", - { data_type => "timestamp", is_nullable => 1 }, - "send_questionnaire", - { data_type => "boolean", default_value => \"true", is_nullable => 0 }, - "latitude", - { data_type => "double precision", is_nullable => 0 }, - "longitude", - { data_type => "double precision", is_nullable => 0 }, - "user_id", - { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, + "id", + { + data_type => "integer", + is_auto_increment => 1, + is_nullable => 0, + sequence => "problem_id_seq", + }, + "postcode", + { data_type => "text", is_nullable => 0 }, + "council", + { data_type => "text", is_nullable => 1 }, + "areas", + { data_type => "text", is_nullable => 0 }, + "category", + { data_type => "text", default_value => "Other", is_nullable => 0 }, + "title", + { data_type => "text", is_nullable => 0 }, + "detail", + { data_type => "text", is_nullable => 0 }, + "photo", + { data_type => "bytea", is_nullable => 1 }, + "used_map", + { data_type => "boolean", is_nullable => 0 }, + "name", + { data_type => "text", is_nullable => 0 }, + "anonymous", + { data_type => "boolean", is_nullable => 0 }, + "created", + { + data_type => "timestamp", + default_value => \"ms_current_timestamp()", + is_nullable => 0, + }, + "confirmed", + { data_type => "timestamp", is_nullable => 1 }, + "state", + { data_type => "text", is_nullable => 0 }, + "lang", + { data_type => "text", default_value => "en-gb", is_nullable => 0 }, + "service", + { data_type => "text", default_value => "", is_nullable => 0 }, + "cobrand", + { data_type => "text", default_value => "", is_nullable => 0 }, + "cobrand_data", + { data_type => "text", default_value => "", is_nullable => 0 }, + "lastupdate", + { + data_type => "timestamp", + default_value => \"ms_current_timestamp()", + is_nullable => 0, + }, + "whensent", + { data_type => "timestamp", is_nullable => 1 }, + "send_questionnaire", + { data_type => "boolean", default_value => \"true", is_nullable => 0 }, + "latitude", + { data_type => "double precision", is_nullable => 0 }, + "longitude", + { data_type => "double precision", is_nullable => 0 }, + "user_id", + { data_type => "integer", is_foreign_key => 1, is_nullable => 0 }, ); __PACKAGE__->set_primary_key("id"); __PACKAGE__->belongs_to( - "user", - "FixMyStreet::DB::Result::User", - { id => "user_id" }, - { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, + "user", + "FixMyStreet::DB::Result::User", + { id => "user_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); - # Created by DBIx::Class::Schema::Loader v0.07010 @ 2011-03-23 12:42:18 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:hXAYqPHjda6+DoSiQexpEg @@ -140,4 +139,3 @@ sub check_for_errors { return \%errors; } -1; diff --git a/templates/web/default/reports/new/fill_in_details.html b/templates/web/default/reports/new/fill_in_details.html index daa73084c..5030f1b47 100644 --- a/templates/web/default/reports/new/fill_in_details.html +++ b/templates/web/default/reports/new/fill_in_details.html @@ -12,13 +12,10 @@ [% IF area_ids_to_list.size == 0 %] [% INCLUDE 'reports/new/no_councils_text.html' %] - <input type="hidden" name="council" value="-1"> [% ELSIF area_ids_to_list.size == all_councils.size %] [% INCLUDE 'reports/new/all_councils_text.html' %] - <input type="hidden" name="council" value="[% all_councils.keys.join(',') %]"> [% ELSE %] [% INCLUDE 'reports/new/some_councils_text.html' %] - <input type="hidden" name="council" value="[% area_ids_to_list.join(',') %]|[% missing.join(',') %]"> [% END %] diff --git a/templates/web/default/reports/new/some_councils_text.html b/templates/web/default/reports/new/some_councils_text.html index 8bb764332..7de7c3f45 100644 --- a/templates/web/default/reports/new/some_councils_text.html +++ b/templates/web/default/reports/new/some_councils_text.html @@ -13,12 +13,12 @@ nget( 'We do <strong>not</strong> yet have details for the other council that covers this location.', 'We do <strong>not</strong> yet have details for the other councils that cover this location.', - missing.size + missing_details_councils.size ); tprintf( loc("You can help us by finding a contact email address for local problems for %s and emailing it to us at <a href='mailto:%s'>%s</a>."), - missing_names.join( loc(' or ') ), + missing_details_council_names.join( loc(' or ') ), c.cobrand.contact_email, c.cobrand.contact_email ); |