diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Dashboard.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/User.pm | 33 |
4 files changed, 30 insertions, 25 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index d64ca4862..56789b81c 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -827,7 +827,7 @@ sub user_edit : Path('user_edit') : Args(1) { if ( $user->email ne $c->req->param('email') || $user->name ne $c->req->param('name' ) || - $user->from_body != $c->req->param('body') ) { + $user->from_body->id != $c->req->param('body') ) { $edited = 1; } diff --git a/perllib/FixMyStreet/App/Controller/Dashboard.pm b/perllib/FixMyStreet/App/Controller/Dashboard.pm index a355606f4..3a66cf1e0 100644 --- a/perllib/FixMyStreet/App/Controller/Dashboard.pm +++ b/perllib/FixMyStreet/App/Controller/Dashboard.pm @@ -88,19 +88,19 @@ Show the dashboard table. sub index : Path : Args(0) { my ( $self, $c ) = @_; - my $council = $c->forward('check_page_allowed'); + my $body = $c->forward('check_page_allowed'); # Set up the data for the dropdowns - my $council_detail = mySociety::MaPit::call('area', $council ); + my $council_detail = mySociety::MaPit::call('area', $body->area_id ); $c->stash->{council} = $council_detail; - my $children = mySociety::MaPit::call('area/children', $council, + my $children = mySociety::MaPit::call('area/children', $body->area_id, type => $c->cobrand->area_types_children, ); $c->stash->{children} = $children; - $c->stash->{all_areas} = { $council => $council_detail }; + $c->stash->{all_areas} = { $body->area_id => $council_detail }; $c->forward( '/report/new/setup_categories_and_bodies' ); # See if we've had anything from the dropdowns @@ -109,7 +109,7 @@ sub index : Path : Args(0) { $c->stash->{category} = $c->req->param('category'); my %where = ( - bodies_str => $council, # XXX This will break in a two tier council. Restriction needs looking at... + bodies_str => $body->id, # XXX Does this 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/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index 7f5777908..e4725d141 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -58,10 +58,16 @@ __PACKAGE__->has_many( { "foreign.body_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->has_many( + "users", + "FixMyStreet::DB::Result::User", + { "foreign.from_body" => "self.id" }, + { cascade_copy => 0, cascade_delete => 0 }, +); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-13 12:36:19 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:Yl1KHSUzPi7KDjMenUe8qw +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 09:23:59 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:tvTHtIa0GrtptadZYHEM1Q # You can replace this text with custom code or comments, and it will be preserved on regeneration diff --git a/perllib/FixMyStreet/DB/Result/User.pm b/perllib/FixMyStreet/DB/Result/User.pm index 997577b69..481b654c9 100644 --- a/perllib/FixMyStreet/DB/Result/User.pm +++ b/perllib/FixMyStreet/DB/Result/User.pm @@ -27,7 +27,7 @@ __PACKAGE__->add_columns( "password", { data_type => "text", default_value => "", is_nullable => 0 }, "from_body", - { data_type => "integer", is_nullable => 1 }, + { data_type => "integer", is_foreign_key => 1, is_nullable => 1 }, "flagged", { data_type => "boolean", default_value => \"false", is_nullable => 0 }, "title", @@ -53,6 +53,17 @@ __PACKAGE__->has_many( { "foreign.user_id" => "self.id" }, { cascade_copy => 0, cascade_delete => 0 }, ); +__PACKAGE__->belongs_to( + "from_body", + "FixMyStreet::DB::Result::Body", + { id => "from_body" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); __PACKAGE__->has_many( "problems", "FixMyStreet::DB::Result::Problem", @@ -61,8 +72,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-12 13:06:09 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:L6gtjOQeVkebGUIHJcHuUA +# Created by DBIx::Class::Schema::Loader v0.07017 @ 2012-12-14 09:23:59 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:aw374WQraL5ysOvUmUIU3w __PACKAGE__->add_columns( "password" => { @@ -146,20 +157,8 @@ sub alert_for_problem { sub body { my $self = shift; - return '' unless $self->from_body; - - my $key = 'body_name:' . $self->from_body; - my $result = Memcached::get($key); - - ### TODO: Add a 'name' column to body which is used instead of calling mapit - unless ($result) { - my $area_info = mySociety::MaPit::call('area', $self->from_body); - $result = $area_info->{name}; - Memcached::set($key, $result, 86400); - } - - return $result; + return $self->from_body->name; } =head2 belongs_to_body @@ -176,7 +175,7 @@ sub belongs_to_body { my %bodies = map { $_ => 1 } split ',', $bodies; - return 1 if $self->from_body && $bodies{ $self->from_body }; + return 1 if $self->from_body && $bodies{ $self->from_body->id }; return 0; } |