diff options
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 3b7f8bcfd..2a90d0bec 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -157,8 +157,7 @@ __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); __PACKAGE__->rabx_column('geocode'); -use Image::Size; -use Moose; +use Moo; use namespace::clean -except => [ 'meta' ]; use Utils; @@ -363,7 +362,8 @@ around lastupdate => $stz; around service => sub { my ( $orig, $self ) = ( shift, shift ); - my $s = $self->$orig(@_); + # service might be undef if e.g. unsaved code report + my $s = $self->$orig(@_) || ""; $s =~ s/_/ /g; return $s; }; @@ -462,7 +462,7 @@ sub bodies($) { my $self = shift; return {} unless $self->bodies_str; my $bodies = $self->bodies_str_ids; - my @bodies = FixMyStreet::App->model('DB::Body')->search({ id => $bodies })->all; + my @bodies = $self->result_source->schema->resultset('Body')->search({ id => $bodies })->all; return { map { $_->id => $_ } @bodies }; } @@ -477,21 +477,9 @@ sub url { return "/report/" . $self->id; } -=head2 get_photo_params - -Returns a hashref of details of the attached photo, if any, for use in templates. - -NB: this method doesn't currently support multiple photos gracefully. - -Use get_photoset($c) instead to do the right thing with reports with 0, 1, or more photos. - -=cut - -sub get_photo_params { - # use Carp 'cluck'; - # cluck "get_photo_params called"; # TEMPORARY die to make sure I've done right thing with Zurich templates - my $self = shift; - return FixMyStreet::App::get_photo_params($self, 'id'); +sub admin_url { + my ($self, $cobrand) = @_; + return $cobrand->admin_base_url . '/report_edit/' . $self->id; } =head2 is_open @@ -628,7 +616,7 @@ sub body { $body = join( _(' and '), map { my $name = $_->name; - if ($c and mySociety::Config::get('AREA_LINKS_FROM_PROBLEMS')) { + if ($c and FixMyStreet->config('AREA_LINKS_FROM_PROBLEMS')) { '<a href="' . $_->url($c) . '">' . $name . '</a>'; } else { $name; @@ -648,7 +636,7 @@ order of title. sub response_templates { my $problem = shift; - return FixMyStreet::App->model('DB::ResponseTemplate')->search( + return $problem->result_source->schema->resultset('ResponseTemplate')->search( { body_id => $problem->bodies_str_ids }, @@ -754,20 +742,17 @@ sub update_from_open311_service_request { $status_notes = $request->{status_notes}; } - my $update = FixMyStreet::App->model('DB::Comment')->new( - { - problem_id => $self->id, - state => 'confirmed', - created => $updated || \'current_timestamp', - confirmed => \'current_timestamp', - text => $status_notes, - mark_open => 0, - mark_fixed => 0, - user => $system_user, - anonymous => 0, - name => $body->name, - } - ); + my $update = $self->new_related(comments => { + state => 'confirmed', + created => $updated || \'current_timestamp', + confirmed => \'current_timestamp', + text => $status_notes, + mark_open => 0, + mark_fixed => 0, + user => $system_user, + anonymous => 0, + name => $body->name, + }); my $w3c = DateTime::Format::W3CDTF->new; my $req_time = $w3c->parse_datetime( $request->{updated_datetime} ); @@ -833,7 +818,7 @@ sub as_hashref { state_t => _( $self->state ), used_map => $self->used_map, is_fixed => $self->fixed_states->{ $self->state } ? 1 : 0, - photo => $self->get_photo_params, + photos => [ map { $_->{url} } @{$self->photos} ], meta => $self->confirmed ? $self->meta_line( $c ) : '', confirmed_pp => $self->confirmed ? $c->cobrand->prettify_dt( $self->confirmed ): '', created_pp => $c->cobrand->prettify_dt( $self->created ), @@ -855,23 +840,44 @@ sub latest_moderation_log_entry { Return a PhotoSet object for all photos attached to this field - my $photoset = $obj->get_photoset( $c ); + my $photoset = $obj->get_photoset; print $photoset->num_images; return $photoset->get_image_data(num => 0, size => 'full'); =cut sub get_photoset { - my ($self, $c) = @_; + my ($self) = @_; my $class = 'FixMyStreet::App::Model::PhotoSet'; eval "use $class"; return $class->new({ - c => $c, - data => $self->photo, + db_data => $self->photo, object => $self, }); } +sub photos { + my $self = shift; + my $photoset = $self->get_photoset; + my $i = 0; + my $id = $self->id; + my @photos = map { + my $format = 'jpeg'; + my $cachebust = substr($_, 0, 8); + { + id => $_, + url_temp => "/photo/$_.temp.$format", + url_temp_full => "/photo/$_.fulltemp.$format", + url => "/photo/$id.$i.$format?$cachebust", + url_full => "/photo/$id.$i.full.$format?$cachebust", + url_tn => "/photo/$id.$i.tn.$format?$cachebust", + url_fp => "/photo/$id.$i.fp.$format?$cachebust", + idx => $i++, + } + } $photoset->all_ids; + return \@photos; +} + __PACKAGE__->has_many( "admin_log_entries", "FixMyStreet::DB::Result::AdminLog", @@ -894,7 +900,4 @@ sub get_time_spent { return $admin_logs ? $admin_logs->get_column('sum_time_spent') : 0; } -# we need the inline_constructor bit as we don't inherit from Moose -__PACKAGE__->meta->make_immutable( inline_constructor => 0 ); - 1; |