]> git.decadent.org.uk Git - memories.git/blobdiff - Memories/Photo.pm
Add SQL and code for the counter (References #4), but no interface yet; adds SQL...
[memories.git] / Memories / Photo.pm
index 960810d59ab8fcf6414489c4fa35b430492d2496..4279dc97c0eb4c622ec365390d97dd424938ae3e 100644 (file)
@@ -5,7 +5,7 @@ use base qw(Memories::DBI Maypole::Model::CDBI::Plain);
 use Time::Piece;
 use Image::Seek;
 use constant PAGER_SYNTAX => "LimitXY";
-__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y));
+__PACKAGE__->columns(Essential => qw(id title uploader uploaded x y rating rated hit_count));
 __PACKAGE__->untaint_columns(printable => [qw/title/]);
 __PACKAGE__->columns(TEMP => qw/exif_object/);
 __PACKAGE__->set_sql(recent => q{
@@ -30,7 +30,10 @@ sub do_upload :Exported {
     my $photo = $self->create({
         uploader => $r->user,
         uploaded => Time::Piece->new(),
-        title => $r->params->{title}
+        title => $r->params->{title},
+        hit_count => 0,
+        rating => 0,
+        rated => 0, # Oh, the potential for divide by zero errors...
     });
 
     # Dump content
@@ -71,8 +74,9 @@ sub do_upload :Exported {
 
 sub view :Exported {
     my ($self, $r) = @_;
+    my $photo = $r->{objects}[0];
+    $photo->hit_count($photo->hit_count()+1);
     if ($r->{session}{last_search}) {
-        my $photo = $r->{objects}[0];
         # This is slightly inefficient
         my @search = split/,/, $r->{session}{last_search};
         my $found = -1;