diff options
author | Matthew Somerville <matthew@mysociety.org> | 2015-09-25 20:01:36 +0100 |
---|---|---|
committer | Matthew Somerville <matthew@mysociety.org> | 2015-12-02 17:41:34 +0000 |
commit | 0c2a792b154e1b28528db887bbde80b19268b9fe (patch) | |
tree | 16425a46578a213400bb2609a52acd07cb640a48 /perllib | |
parent | bb1e7974955b450520489b93f8ddb6fedaf96008 (diff) |
Move get_photo_params to Utils::Photo.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 36 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Comment.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 4 | ||||
-rw-r--r-- | perllib/Utils/Photo.pm | 41 |
4 files changed, 45 insertions, 40 deletions
diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index e4c113ea1..b8ce2e051 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -432,42 +432,6 @@ sub render_fragment { $c->view('Web')->render($c, $template, $vars); } -=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, $key) = @_; - - return {} unless $self->photo; - - $key = ($key eq 'id') ? '' : "/$key"; - - my $pre = "/photo$key/" . $self->id; - my $post = '.jpeg'; - my $photo = {}; - - if (length($self->photo) == 40) { - $post .= '?' . $self->photo; - $photo->{url_full} = "$pre.full$post"; - # XXX Can't use size here because {url} (currently 250px height) may be - # being used, but at this point it doesn't yet exist to find the width - # $str = FixMyStreet->config('UPLOAD_DIR') . $self->photo . '.jpeg'; - } else { - my $str = \$self->photo; - ( $photo->{width}, $photo->{height} ) = Image::Size::imgsize( $str ); - } - - $photo->{url} = "$pre$post"; - $photo->{url_tn} = "$pre.tn$post"; - $photo->{url_fp} = "$pre.fp$post"; - - return $photo; -} - =head2 get_param $param = $c->get_param('name'); diff --git a/perllib/FixMyStreet/DB/Result/Comment.pm b/perllib/FixMyStreet/DB/Result/Comment.pm index 0caaa8968..04493b5b5 100644 --- a/perllib/FixMyStreet/DB/Result/Comment.pm +++ b/perllib/FixMyStreet/DB/Result/Comment.pm @@ -96,8 +96,8 @@ __PACKAGE__->belongs_to( __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); -use Image::Size; use Moose; +use Utils::Photo; use namespace::clean -except => [ 'meta' ]; with 'FixMyStreet::Roles::Abuser'; @@ -156,7 +156,7 @@ Returns a hashref of details of any attached photo for use in templates. sub get_photo_params { my $self = shift; - return FixMyStreet::App::get_photo_params($self, 'c'); + return Utils::Photo::get_photo_params($self, 'c'); } =head2 meta_problem_state diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 3b7f8bcfd..0cab853de 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -157,10 +157,10 @@ __PACKAGE__->load_components("+FixMyStreet::DB::RABXColumn"); __PACKAGE__->rabx_column('extra'); __PACKAGE__->rabx_column('geocode'); -use Image::Size; use Moose; use namespace::clean -except => [ 'meta' ]; use Utils; +use Utils::Photo; with 'FixMyStreet::Roles::Abuser', 'FixMyStreet::Roles::Extra'; @@ -491,7 +491,7 @@ 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'); + return Utils::Photo::get_photo_params($self, 'id'); } =head2 is_open diff --git a/perllib/Utils/Photo.pm b/perllib/Utils/Photo.pm new file mode 100644 index 000000000..a1af90fe1 --- /dev/null +++ b/perllib/Utils/Photo.pm @@ -0,0 +1,41 @@ +package Utils::Photo; + +use Image::Size; + +=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, $key) = @_; + + return {} unless $self->photo; + + $key = ($key eq 'id') ? '' : "/$key"; + + my $pre = "/photo$key/" . $self->id; + my $post = '.jpeg'; + my $photo = {}; + + if (length($self->photo) == 40) { + $post .= '?' . $self->photo; + $photo->{url_full} = "$pre.full$post"; + # XXX Can't use size here because {url} (currently 250px height) may be + # being used, but at this point it doesn't yet exist to find the width + # $str = FixMyStreet->config('UPLOAD_DIR') . $self->photo . '.jpeg'; + } else { + my $str = \$self->photo; + ( $photo->{width}, $photo->{height} ) = Image::Size::imgsize( $str ); + } + + $photo->{url} = "$pre$post"; + $photo->{url_tn} = "$pre.tn$post"; + $photo->{url_fp} = "$pre.fp$post"; + + return $photo; +} + +1; |