aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/DB
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet/DB')
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm38
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm41
2 files changed, 56 insertions, 23 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 41e8cf315..3ae56591f 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -97,7 +97,6 @@ __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn");
__PACKAGE__->rabx_column('extra');
use Moo;
-use Utils::Photo;
use namespace::clean -except => [ 'meta' ];
with 'FixMyStreet::Roles::Abuser';
@@ -148,15 +147,44 @@ sub confirm {
$self->confirmed( \'current_timestamp' );
}
-=head2 get_photo_params
+=head2 get_photoset
-Returns a hashref of details of any attached photo for use in templates.
+Return a PhotoSet object for all photos attached to this field
+
+ my $photoset = $obj->get_photoset;
+ print $photoset->num_images;
+ return $photoset->get_image_data(num => 0, size => 'full');
=cut
-sub get_photo_params {
+sub get_photoset {
+ my ($self) = @_;
+ my $class = 'FixMyStreet::App::Model::PhotoSet';
+ eval "use $class";
+ return $class->new({
+ db_data => $self->photo,
+ object => $self,
+ });
+}
+
+sub photos {
my $self = shift;
- return Utils::Photo::get_photo_params($self, 'c');
+ 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/c/$id.$i.$format?$cachebust",
+ url_full => "/photo/c/$id.$i.full.$format?$cachebust",
+ idx => $i++,
+ }
+ } map { $_->[0] } $photoset->all_images;
+ return \@photos;
}
=head2 meta_problem_state
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",