diff options
Diffstat (limited to 'perllib/FixMyStreet/DB/Result/Problem.pm')
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Problem.pm | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/DB/Result/Problem.pm b/perllib/FixMyStreet/DB/Result/Problem.pm index 0092dd8b5..97cb28fe8 100644 --- a/perllib/FixMyStreet/DB/Result/Problem.pm +++ b/perllib/FixMyStreet/DB/Result/Problem.pm @@ -182,6 +182,8 @@ use Utils; use FixMyStreet::Map::FMS; use LWP::Simple qw($ua); use RABX; +use URI; +use URI::QueryParam; my $IM = eval { require Image::Magick; @@ -511,6 +513,30 @@ sub admin_url { return $cobrand->admin_base_url . '/report_edit/' . $self->id; } +=head2 tokenised_url + +Return a url for this problem report that logs a user in + +=cut + +sub tokenised_url { + my ($self, $user, $params) = @_; + + my $token = FixMyStreet::App->model('DB::Token')->create( + { + scope => 'email_sign_in', + data => { + id => $self->id, + email => $user->email, + r => $self->url, + p => $params, + } + } + ); + + return "/M/". $token->token; +} + =head2 is_open Returns 1 if the problem is in a open state otherwise 0. @@ -659,6 +685,20 @@ sub body { return $body; } + +=head2 time_ago + Returns how long ago a problem was reported in an appropriately + prettified duration, depending on the duration. +=cut + +sub time_ago { + my ( $self, $date ) = @_; + $date ||= 'confirmed'; + my $duration = time() - $self->$date->epoch; + + return Utils::prettify_duration( $duration ); +} + =head2 response_templates Returns all ResponseTemplates attached to this problem's bodies, in alphabetical |