diff options
Diffstat (limited to 'perllib/FixMyStreet/App')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 15 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Around.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 18 |
5 files changed, 9 insertions, 40 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index a5c29fce3..9c63a890f 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -1938,11 +1938,9 @@ sub check_page_allowed : Private { sub fetch_all_bodies : Private { my ($self, $c ) = @_; - my @bodies = $c->model('DB::Body')->all_translated; + my @bodies = $c->model('DB::Body')->translated->all_sorted; if ( $c->cobrand->moniker eq 'zurich' ) { @bodies = $c->cobrand->admin_fetch_all_bodies( @bodies ); - } else { - @bodies = sort { strcoll($a->name, $b->name) } @bodies; } $c->stash->{bodies} = \@bodies; @@ -1952,20 +1950,15 @@ sub fetch_all_bodies : Private { sub fetch_body_areas : Private { my ($self, $c, $body ) = @_; - my $body_area = $body->body_areas->first; - - unless ( $body_area ) { + my $children = $body->first_area_children; + unless ($children) { # Body doesn't have any areas defined. delete $c->stash->{areas}; delete $c->stash->{fetched_areas_body_id}; return; } - my $areas = mySociety::MaPit::call('area/children', [ $body_area->area_id ], - type => $c->cobrand->area_types_children, - ); - - $c->stash->{areas} = [ sort { strcoll($a->{name}, $b->{name}) } values %$areas ]; + $c->stash->{areas} = [ sort { strcoll($a->{name}, $b->{name}) } values %$children ]; # Keep track of the areas we've fetched to prevent a duplicate fetch later on $c->stash->{fetched_areas_body_id} = $body->id; } diff --git a/perllib/FixMyStreet/App/Controller/Around.pm b/perllib/FixMyStreet/App/Controller/Around.pm index da17cbd56..7cef7ccaa 100644 --- a/perllib/FixMyStreet/App/Controller/Around.pm +++ b/perllib/FixMyStreet/App/Controller/Around.pm @@ -225,10 +225,7 @@ sub check_and_stash_category : Private { my ( $self, $c ) = @_; my $all_areas = $c->stash->{all_areas}; - my @bodies = $c->model('DB::Body')->search( - { 'body_areas.area_id' => [ keys %$all_areas ], deleted => 0 }, - { join => 'body_areas' } - )->all; + my @bodies = $c->model('DB::Body')->active->for_areas(keys %$all_areas)->all; my %bodies = map { $_->id => $_ } @bodies; my @contacts = $c->model('DB::Contact')->not_deleted->search( diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index 926e941f6..7a6e82093 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -86,11 +86,7 @@ sub index : Path : Args(0) { if ($body) { $c->stash->{body_name} = $body->name; - my $area_id = $body->body_areas->first->area_id; - my $children = mySociety::MaPit::call('area/children', $area_id, - type => $c->cobrand->area_types_children, - ); - $c->stash->{children} = $children; + my $children = $c->stash->{children} = $body->first_area_children; $c->forward('/admin/fetch_contacts'); $c->stash->{contacts} = [ $c->stash->{contacts}->all ]; diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index ca4fa2fd2..d74af5a84 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -617,10 +617,7 @@ sub setup_categories_and_bodies : Private { my $all_areas = $c->stash->{all_areas}; my $first_area = ( values %$all_areas )[0]; - my @bodies = $c->model('DB::Body')->search( - { 'body_areas.area_id' => [ keys %$all_areas ], deleted => 0 }, - { join => 'body_areas' } - )->all; + my @bodies = $c->model('DB::Body')->active->for_areas(keys %$all_areas)->all; my %bodies = map { $_->id => $_ } @bodies; my $first_body = ( values %bodies )[0]; diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index ec7a192b3..315cfc074 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -5,7 +5,6 @@ use namespace::autoclean; use JSON::MaybeXS; use List::MoreUtils qw(any); use Path::Tiny; -use POSIX qw(strcoll); use RABX; use mySociety::MaPit; @@ -93,18 +92,8 @@ sub index : Path : Args(0) { $c->stash->{children} = $children; } } else { - # Fetch all bodies - my @bodies = $c->model('DB::Body')->search({ - deleted => 0, - }, { - '+select' => [ { count => 'area_id' } ], - '+as' => [ 'area_count' ], - join => 'body_areas', - distinct => 1, - })->all; - @bodies = sort { strcoll($a->name, $b->name) } @bodies; + my @bodies = $c->model('DB::Body')->active->with_area_count->all_sorted; $c->stash->{bodies} = \@bodies; - $c->stash->{any_empty_bodies} = any { $_->get_column('area_count') == 0 } @bodies; } # Down here so that error pages aren't cached. @@ -457,10 +446,7 @@ sub summary : Private { $c->stash->{group_by_default} = 'category'; - my $area_id = $c->stash->{body}->body_areas->first->area_id; - my $children = mySociety::MaPit::call('area/children', $area_id, - type => $c->cobrand->area_types_children, - ); + my $children = $c->stash->{body}->first_area_children; $c->stash->{children} = $children; $c->forward('/admin/fetch_contacts'); |