diff options
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/JSON.pm | 20 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311.pm | 22 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report.pm | 9 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 25 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 2 |
9 files changed, 44 insertions, 62 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index 8c37f0f2e..d5bce9283 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -569,7 +569,7 @@ sub search_reports : Path('search_reports') { -or => $query, }, { - -select => [ 'me.*', qw/problem.council problem.state/ ], + -select => [ 'me.*', qw/problem.bodies_str problem.state/ ], prefetch => [qw/user problem/], order_by => [\"(me.state='hidden')",\"(problem.state='hidden')",'me.created'] } diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 00220deff..a355606f4 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -109,7 +109,7 @@ sub index : Path : Args(0) { $c->stash->{category} = $c->req->param('category'); my %where = ( - council => $council, # XXX This will break in a two tier council. Restriction needs looking at... + bodies_str => $council, # XXX This will break in a two tier council. Restriction needs looking at... 'problem.state' => [ FixMyStreet::DB::Result::Problem->visible_states() ], ); $where{areas} = { 'like', '%,' . $c->stash->{ward} . ',%' } diff --git a/perllib/FixMyStreet/App/Controller/JSON.pm b/perllib/FixMyStreet/App/Controller/JSON.pm index f3607341a..1a7c1915b 100644 --- a/perllib/FixMyStreet/App/Controller/JSON.pm +++ b/perllib/FixMyStreet/App/Controller/JSON.pm @@ -92,7 +92,7 @@ sub problems : Local { my @problems = $c->cobrand->problems->search( $query, { order_by => { -asc => 'confirmed' }, columns => [ - 'id', 'title', 'council', 'category', + 'id', 'title', 'bodies_str', 'category', 'detail', 'name', 'anonymous', 'confirmed', 'whensent', 'service', 'latitude', 'longitude', 'used_map', @@ -100,23 +100,13 @@ sub problems : Local { ] } ); - my @councils; foreach my $problem (@problems) { $problem->name( '' ) if $problem->anonymous == 1; $problem->service( 'Web interface' ) if $problem->service eq ''; - if ($problem->council) { - (my $council = $problem->council) =~ s/\|.*//g; - my @council_ids = split /,/, $council; - push(@councils, @council_ids); - $problem->council( \@council_ids ); - } - } - @councils = uniq @councils; - my $areas_info = mySociety::MaPit::call('areas', \@councils); - foreach my $problem (@problems) { - if ($problem->council) { - my @council_names = map { $areas_info->{$_}->{name} } @{$problem->council} ; - $problem->council( join(' and ', @council_names) ); + my $bodies = $problem->bodies; + if (keys %$bodies) { + my @body_names = map { $_->name } values %$bodies; + $problem->bodies_str( join(' and ', @body_names) ); } } diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index b1e685c1c..62cdaffaf 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -164,11 +164,11 @@ sub get_services : Private { if ($lat || $lon) { my $area_types = $c->cobrand->area_types; - my $all_councils = mySociety::MaPit::call('point', + my $all_areas = mySociety::MaPit::call('point', "4326/$lon,$lat", type => $area_types); $categories = $categories->search( { - 'body.area_id' => [ keys %$all_councils ], + 'body.area_id' => [ keys %$all_areas ], }, { join => 'body' } ); } @@ -223,19 +223,11 @@ sub output_requests : Private { ); my @problemlist; - my @councils; while ( my $problem = $problems->next ) { my $id = $problem->id; $problem->service( 'Web interface' ) unless $problem->service; - if ($problem->council) { - (my $council = $problem->council) =~ s/\|.*//g; - my @council_ids = split(/,/, $council); - push(@councils, @council_ids); - $problem->council( \@council_ids ); - } - $problem->state( $statusmap{$problem->state} ); my $request = @@ -256,7 +248,7 @@ sub output_requests : Private { 'service_code' => [ $problem->category ], 'service_name' => [ $problem->category ], # 'service_notice' => [ {} ], - 'agency_responsible' => $problem->council , # FIXME Not according to Open311 v2 + 'agency_responsible' => $problem->bodies , # FIXME Not according to Open311 v2 # 'zipcode' => [ {} ], 'interface_used' => [ $problem->service ], # Not in Open311 v2 }; @@ -288,12 +280,12 @@ sub output_requests : Private { } push(@problemlist, $request); } - my $areas_info = mySociety::MaPit::call('areas', \@councils); + foreach my $request (@problemlist) { if ($request->{agency_responsible}) { - my @council_names = map { $areas_info->{$_}->{name} } @{$request->{agency_responsible}} ; + my @body_names = map { $_->name } values %{$request->{agency_responsible}} ; $request->{agency_responsible} = - [ {'recipient' => [ @council_names ] } ]; + [ {'recipient' => [ @body_names ] } ]; } } $c->forward( 'format_output', [ { @@ -319,7 +311,7 @@ sub get_requests : Private { service_request_id => [ '=', 'id' ], service_code => [ '=', 'category' ], status => [ 'IN', 'state' ], - agency_responsible => [ '~', 'council' ], + agency_responsible => [ '~', 'bodies_str' ], interface_used => [ '=', 'service' ], has_photo => [ '=', 'photo' ], ); diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm index 2c56cd182..41aee3869 100644 --- a/perllib/FixMyStreet/App/Controller/Report.pm +++ b/perllib/FixMyStreet/App/Controller/Report.pm @@ -147,7 +147,7 @@ sub format_problem_for_display : Private { $c->stash->{add_alert} = 1; } - $c->stash->{extra_name_info} = $problem->council && $problem->council eq '2482' ? 1 : 0; + $c->stash->{extra_name_info} = $problem->bodies_str && $problem->bodies_str eq '2482' ? 1 : 0; $c->forward('generate_map_tags'); @@ -187,11 +187,10 @@ sub delete :Local :Args(1) { return $c->res->redirect($uri) unless $c->user_exists; - my $council = $c->user->obj->from_body; - return $c->res->redirect($uri) unless $council; + my $body = $c->user->obj->from_body; + return $c->res->redirect($uri) unless $body; - my %councils = map { $_ => 1 } @{$p->councils}; - return $c->res->redirect($uri) unless $councils{$council}; + return $c->res->redirect($uri) unless $p->bodies->{$body}; $p->state('hidden'); $p->lastupdate( \'ms_current_timestamp()' ); diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index bb8f8f03f..0cb56d67a 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -587,7 +587,7 @@ sub setup_categories_and_bodies : Private { = $c # ->model('DB::Contact') # ->not_deleted # - ->search( { body => [ keys %bodies ] } ) + ->search( { body_id => [ keys %bodies ] } ) ->all; # variables to populate @@ -816,7 +816,7 @@ sub process_report : Private { if ( $c->cobrand->moniker eq 'emptyhomes' ) { $bodies = join( ',', @{ $c->stash->{bodies_to_list} } ) || -1; - $report->bodies( $bodies ); + $report->bodies_str( $bodies ); } elsif ( $first_area->{id} == COUNCIL_ID_BARNET ) { @@ -824,14 +824,14 @@ sub process_report : Private { unless ( exists Utils::barnet_categories()->{ $report->category } ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); } - $report->bodies( $first_area->{id} ); + $report->bodies_str( $first_area->{id} ); } 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->area( $first_area->{id} ); + $report->bodies_str( $first_area->{id} ); } elsif ( $report->category ) { @@ -842,14 +842,14 @@ sub process_report : Private { ->not_deleted # ->search( { - body => [ keys %$bodies ], + body_id => [ keys %$bodies ], category => $report->category } )->all; unless ( @contacts ) { $c->stash->{field_errors}->{category} = _('Please choose a category'); - $report->bodies( -1 ); + $report->bodies_str( -1 ); return 1; } @@ -860,7 +860,7 @@ sub process_report : Private { $body_string .= '|' . join( ',', @{ $c->stash->{missing_details_bodies} } ) if $body_string && @{ $c->stash->{missing_details_bodies} }; - $report->bodies($body_string); + $report->bodies_str($body_string); my @extra = (); my $metas = $contacts[0]->extra; @@ -897,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->bodies( -1 ); + $report->bodies_str( -1 ); } @@ -1016,7 +1016,7 @@ sub save_user_and_report : Private { $report->category( _('Other') ) unless $report->category; # Set unknown to DB unknown - $report->bodies( undef ) if $report->bodies eq '-1'; + $report->bodies_str( undef ) if $report->bodies_str 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+$/) { diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index c3843c9af..4467a7036 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -201,14 +201,14 @@ sub process_update : Private { if ( $params{state} ) { $params{state} = 'fixed - council' - if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_body( $update->problem->council ); + if $params{state} eq 'fixed' && $c->user && $c->user->belongs_to_body( $update->problem->bodies_str ); $update->problem_state( $params{state} ); } my @extra; # Next function fills this, but we don't need it here. # This is just so that the error checkign for these extra fields runs. # TODO Use extra here as it is used on reports. - $c->cobrand->process_extras( $c, $update->problem->council, \@extra ); + $c->cobrand->process_extras( $c, $update->problem->bodies_str, \@extra ); if ( $c->req->param('fms_extra_title') ) { my %extras = (); @@ -246,7 +246,7 @@ sub check_for_errors : Private { # they have to be an authority user to update the state if ( $c->req->param('state') ) { my $error = 0; - $error = 1 unless $c->user && $c->user->belongs_to_body( $c->stash->{update}->problem->council ); + $error = 1 unless $c->user && $c->user->belongs_to_body( $c->stash->{update}->problem->bodies_str ); my $state = $c->req->param('state'); $error = 1 unless ( grep { $state eq $_ } ( qw/confirmed closed fixed investigating planned/, 'in progress', 'fixed', 'fixed - user', 'fixed - council' ) ); diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index ec41dc17f..ec722fd6f 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -325,7 +325,7 @@ sub load_and_group_problems : Private { }; if ($c->stash->{ward}) { $where->{areas} = { 'like', '%,' . $c->stash->{ward}->{id} . ',%' }; - $where->{council} = [ + $where->{bodies_str} = [ undef, $c->stash->{council}->{id}, { 'like', $c->stash->{council}->{id} . ',%' }, @@ -336,7 +336,7 @@ sub load_and_group_problems : Private { $where->{'lower(external_body)'} = lc $c->stash->{council}->{name}; } elsif ($c->stash->{council}) { $where->{areas} = { 'like', '%,' . $c->stash->{council}->{id} . ',%' }; - $where->{council} = [ + $where->{bodies_str} = [ undef, $c->stash->{council}->{id}, { 'like', $c->stash->{council}->{id} . ',%' }, @@ -347,7 +347,7 @@ sub load_and_group_problems : Private { $where, { columns => [ - 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', + 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', #{ duration => { extract => "epoch from current_timestamp-lastupdate" } }, #{ age => { extract => "epoch from current_timestamp-confirmed" } }, { confirmed => { extract => 'epoch from confirmed' } }, @@ -364,7 +364,7 @@ sub load_and_group_problems : Private { my ( %problems, @pins ); my $re_councils = join('|', keys %{$c->stash->{areas_info}}); - my @cols = ( 'id', 'council', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' ); + my @cols = ( 'id', 'bodies_str', 'state', 'areas', 'latitude', 'longitude', 'title', 'cobrand', 'confirmed', 'whensent', 'lastupdate', 'photo' ); while ( my @problem = $problems->next ) { my %problem = zip @cols, @problem; $problem{is_fixed} = FixMyStreet::DB::Result::Problem->fixed_states()->{$problem{state}}; @@ -374,18 +374,19 @@ sub load_and_group_problems : Private { add_row( \%problem, 0, \%problems, \@pins ); next; } - if ( !$problem{council} ) { - # Problem was not sent to any council, add to possible councils - $problem{councils} = 0; + if ( !$problem{bodies_str} ) { + # Problem was not sent to any body, add to possible councils XXX + $problem{bodies} = 0; while ($problem{areas} =~ /,($re_councils)(?=,)/g) { add_row( \%problem, $1, \%problems, \@pins ); } } else { - # Add to councils it was sent to - (my $council = $problem{council}) =~ s/\|.*$//; - my @council = split( /,/, $council ); - $problem{councils} = scalar @council; - foreach ( @council ) { + # Add to bodies it was sent to + # XXX Assumes body ID matches "council ID" + (my $bodies = $problem{bodies_str}) =~ s/\|.*$//; + my @bodies = split( /,/, $bodies ); + $problem{bodies} = scalar @bodies; + foreach ( @bodies ) { next if $_ != $c->stash->{council}->{id}; add_row( \%problem, $_, \%problems, \@pins ); } diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index baaa3b927..b275cfcf7 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -257,7 +257,7 @@ sub add_row : Private { my $hashref_restriction = $c->cobrand->site_restriction; my $base_url = $c->cobrand->base_url; - if ( $hashref_restriction && $hashref_restriction->{council} && $row->{council} && $row->{council} ne $hashref_restriction->{council} ) { + if ( $hashref_restriction && $hashref_restriction->{council} && $row->{bodies_str} && $row->{bodies_str} ne $hashref_restriction->{council} ) { $base_url = $c->config->{BASE_URL}; } my $url = $base_url . $link; |