aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB/Result/Problem.pm
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2016-01-12 16:33:17 +0000
committerMatthew Somerville <matthew@mysociety.org>2016-01-12 17:31:38 +0000
commitdf98fe4dfff0a707c9800050f658100c57783654 (patch)
treefd39aa3cf82584fbf784334da41265b5f7dbc43c /perllib/FixMyStreet/DB/Result/Problem.pm
parentde6df5e30d4801afc560e93c833a692a117b9547 (diff)
Factor multiple photo details into nicer function.
Remove get_photo_params, which only looked at the first photo, make explicit when we're doing that using `.first`.
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm')
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm41
1 files changed, 23 insertions, 18 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 745d88629..8f9e76ad6 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -160,7 +160,6 @@ __PACKAGE__->rabx_column('geocode');
use Moo;
use namespace::clean -except => [ 'meta' ];
use Utils;
-use Utils::Photo;
with 'FixMyStreet::Roles::Abuser',
'FixMyStreet::Roles::Extra';
@@ -483,22 +482,6 @@ sub admin_url {
return $cobrand->admin_base_url . '/report_edit/' . $self->id;
}
-=head2 get_photo_params
-
-Returns a hashref of details of the attached photo, if any, for use in templates.
-
-NB: this method only returns the first if there are multiple photos. Use
-get_photoset if you wish to access multiple 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 Utils::Photo::get_photo_params($self, 'id');
-}
-
=head2 is_open
Returns 1 if the problem is in a open state otherwise 0.
@@ -835,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 ),
@@ -873,6 +856,28 @@ sub get_photoset {
});
}
+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++,
+ }
+ } map { $_->[0] } $photoset->all_images;
+ return \@photos;
+}
+
__PACKAGE__->has_many(
"admin_log_entries",
"FixMyStreet::DB::Result::AdminLog",