X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=Memories%2FPhoto.pm;h=771c3a6ba3f6e619ed704b1d9f783394426b161d;hb=92f8c80c61d9b1f90c0cd25e79710fc8e7963f4c;hp=f2999c3c110541b6f85cbb7043273e42df5ba4da;hpb=944db1a7ad953f6ed4ff66e75ad174b1859155bb;p=memories.git 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];