aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--perllib/FixMyStreet/App/Controller/Photo.pm3
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm15
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/Update.pm11
-rw-r--r--perllib/FixMyStreet/DB/Result/Comment.pm20
-rw-r--r--perllib/FixMyStreet/DB/Result/Problem.pm20
-rw-r--r--templates/web/default/report/display.html6
-rw-r--r--templates/web/default/report/photo.html6
-rw-r--r--templates/web/default/report/updates.html4
8 files changed, 62 insertions, 23 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Photo.pm b/perllib/FixMyStreet/App/Controller/Photo.pm
index 3dc1275f0..9b828f894 100644
--- a/perllib/FixMyStreet/App/Controller/Photo.pm
+++ b/perllib/FixMyStreet/App/Controller/Photo.pm
@@ -35,8 +35,7 @@ sub index :Path :Args(0) {
my $photo;
if ( $comment ) {
- # FIXME implement comment photos
- return;
+ $photo = $c->model('DB::Comment')->find( {id => $comment, state => 'confirmed' } );
} else {
$photo = $c->model('DB::Problem')->find( {id => $id, state => 'confirmed' } );
}
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index ff4bb080c..ff471d7cd 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -200,7 +200,6 @@ sub format_problem_for_display : Private {
$c->stash->{email} = $c->req->param('rznvy');
$c->forward('generate_map_tags');
- $c->forward('generate_problem_photo');
$c->forward('generate_problem_meta');
# problem_updates => Page::display_problem_updates($input{id}, $q),
@@ -243,20 +242,6 @@ sub generate_map_tags : Private {
return 1;
}
-sub generate_problem_photo : Private {
- my ( $self, $c ) = @_;
-
- my $problem = $c->stash->{problem};
-
- if ( $c->cobrand->allow_photo_display and $problem->photo ) {
- my $photo = {};
- ( $photo->{width}, $photo->{height} ) =
- Image::Size::imgsize( \$problem->photo );
- $photo->{url} = '/photo/?id=' . $problem->id;
- $c->stash->{photo} = $photo;
- }
-}
-
sub generate_problem_meta : Private {
my ( $self, $c ) = @_;
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm
index bac3c5b17..691a4ecc9 100644
--- a/perllib/FixMyStreet/App/Controller/Report/Update.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm
@@ -4,6 +4,8 @@ use Moose;
use namespace::autoclean;
BEGIN { extends 'Catalyst::Controller'; }
+use Path::Class;
+
=head1 NAME
FixMyStreet::App::Controller::Report::Update
@@ -68,6 +70,7 @@ sub report_update : Path : Args(0) {
$c->forward('setup_page')
&& $c->forward('process_user')
&& $c->forward('process_update')
+ && $c->forward('/report/new/process_photo')
&& $c->forward('check_for_errors')
or $c->go( '/report/display', [ $c->req->param('id') ] );
@@ -212,6 +215,14 @@ sub save_update : Private {
$update->confirm;
}
+ # If there was a photo add that too
+ if ( my $fileid = $c->stash->{upload_fileid} ) {
+ my $file = file( $c->config->{UPLOAD_CACHE}, "$fileid.jpg" );
+ my $blob = $file->slurp;
+ $file->remove;
+ $update->photo($blob);
+ }
+
if ( $update->in_storage ) {
$update->update;
} else {
diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm
index 7259087be..73c5876d6 100644
--- a/perllib/FixMyStreet/DB/Result/Comment.pm
+++ b/perllib/FixMyStreet/DB/Result/Comment.pm
@@ -97,4 +97,24 @@ sub confirm {
$self->state( 'confirmed' );
$self->confirmed( \'ms_current_timestamp()' );
}
+
+=head2 get_photo_params
+
+Returns a hashref of details of any attached photo for use in templates.
+Hashref contains height, width and url keys.
+
+=cut
+
+sub get_photo_params {
+ my $self = shift;
+
+ return {} unless $self->photo;
+
+ my $photo = {};
+ ( $photo->{width}, $photo->{height} ) =
+ Image::Size::imgsize( \$self->photo );
+ $photo->{url} = '/photo/?c=' . $self->id;
+
+ return $photo;
+}
1;
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm
index 57bbf5fb8..d91e8c324 100644
--- a/perllib/FixMyStreet/DB/Result/Problem.pm
+++ b/perllib/FixMyStreet/DB/Result/Problem.pm
@@ -225,4 +225,24 @@ sub url {
return "/report/" . $self->id;
}
+=head2 get_photo_params
+
+Returns a hashref of details of any attached photo for use in templates.
+Hashref contains height, width and url keys.
+
+=cut
+
+sub get_photo_params {
+ my $self = shift;
+
+ return {} unless $self->photo;
+
+ my $photo = {};
+ ( $photo->{width}, $photo->{height} ) =
+ Image::Size::imgsize( \$self->photo );
+ $photo->{url} = '/photo/?id=' . $self->id;
+
+ return $photo;
+}
+
1;
diff --git a/templates/web/default/report/display.html b/templates/web/default/report/display.html
index e35dfcd75..48b799978 100644
--- a/templates/web/default/report/display.html
+++ b/templates/web/default/report/display.html
@@ -23,11 +23,7 @@
</p>
[% END %]
-[% IF photo %]
-<p align="center">
- <img alt="" height="[% photo.height %]" width="[% photo.width %]" src="[% photo.url %]">
-</p>
-[% END %]
+[% INCLUDE 'report/photo.html' object=problem center=1 %]
<p align="right">
<small>
diff --git a/templates/web/default/report/photo.html b/templates/web/default/report/photo.html
new file mode 100644
index 000000000..451a0479c
--- /dev/null
+++ b/templates/web/default/report/photo.html
@@ -0,0 +1,6 @@
+[% IF c.cobrand.allow_photo_display && object.photo %]
+[% photo = object.get_photo_params %]
+<p[% ' align="center"' IF center %]>
+ <img alt="" height="[% photo.height %]" width="[% photo.width %]" src="[% photo.url %]">
+</p>
+[% END %]
diff --git a/templates/web/default/report/updates.html b/templates/web/default/report/updates.html
index 1a7254712..188bacca6 100644
--- a/templates/web/default/report/updates.html
+++ b/templates/web/default/report/updates.html
@@ -22,7 +22,9 @@
</p>
[% END %]
</div>
- [%# images %]
+
+ [% INCLUDE 'report/photo.html' object=update %]
+
</div>
[% '</div>' IF loop.last %]
[% END %]