diff options
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Body.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index 82015ad2d..6481d5cfc 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -121,18 +121,52 @@ __PACKAGE__->has_many( # Created by DBIx::Class::Schema::Loader v0.07035 @ 2017-02-13 15:11:11 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:BOJANVwg3kR/1VjDq0LykA +use Moo; +use namespace::clean; + +with 'FixMyStreet::Roles::Translatable'; + sub url { my ( $self, $c, $args ) = @_; # XXX $areas_info was used here for Norway parent - needs body parents, I guess return $c->uri_for( '/reports/' . $c->cobrand->short_name( $self ), $args || {} ); } +__PACKAGE__->might_have( + "translations", + "FixMyStreet::DB::Result::Translation", + sub { + my $args = shift; + return { + "$args->{foreign_alias}.object_id" => { -ident => "$args->{self_alias}.id" }, + "$args->{foreign_alias}.tbl" => { '=' => \"?" }, + "$args->{foreign_alias}.col" => { '=' => \"?" }, + "$args->{foreign_alias}.lang" => { '=' => \"?" }, + }; + }, + { cascade_copy => 0, cascade_delete => 0 }, +); + +around name => \&translate_around; + sub areas { my $self = shift; my %ids = map { $_->area_id => 1 } $self->body_areas->all; return \%ids; } +sub first_area_children { + my ( $self, $c ) = @_; + + my $area_id = $self->body_areas->first->area_id; + + my $children = mySociety::MaPit::call('area/children', $area_id, + type => $c->cobrand->area_types_children, + ); + + return $children; +} + =head2 get_cobrand_handler Get a cobrand object for this body, if there is one. |