From 92f8c80c61d9b1f90c0cd25e79710fc8e7963f4c Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Thu, 8 Feb 2007 20:37:56 +0000 Subject: [PATCH] Oops, we need this... git-svn-id: http://svn.simon-cozens.org/memories/trunk@15 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- Memories/Photo.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Memories/Photo.pm b/Memories/Photo.pm index f2999c3..771c3a6 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -73,6 +73,23 @@ sub do_upload :Exported { ); } +sub approx_rating { + my $self = shift; + $self->rated or return 0; + int($self->rating/$self->rated*10)/10; +} + +sub add_rating :Exported { + my ($self, $r) = @_; + my $photo = $r->{objects}[0]; + my $delta = $r->{params}{rating}; + if ($delta < 0 or $delta > 5) { return; } # Scammer + # XXX Race + $photo->rating($photo->rating() + $delta); + $photo->rated($photo->rated() + 1); + $r->output(""); # Only used by ajax +} + sub view :Exported { my ($self, $r) = @_; my $photo = $r->{objects}[0]; -- 2.39.5