]> git.decadent.org.uk Git - memories.git/commitdiff
Later we'll have to add a coefficient of commenting, but this is good for now.
authorSimon Cozens <simon@simon-cozens.org>
Sat, 10 Feb 2007 11:42:22 +0000 (11:42 +0000)
committerSimon Cozens <simon@simon-cozens.org>
Sat, 10 Feb 2007 11:42:22 +0000 (11:42 +0000)
git-svn-id: http://svn.simon-cozens.org/memories/trunk@21 041978f6-d955-411f-a9d7-1d8545c9c3c7

Memories/Photo.pm
templates/rhs

index bcfb59c39c8f7db2b3811c6e53fa1eff38f23b1f..5a9b91e56aa133ea4cda60c948a12a6d7e7a9bba 100644 (file)
@@ -2,25 +2,36 @@ package Memories::Photo;
 use strict;
 use Carp qw(cluck confess);
 use base qw(Memories::DBI Maypole::Model::CDBI::Plain);
+use constant INTERESTINGNESS_ALGORITHM => '((rating+3)/(rated+1))*(1+rated/hit_count)*(1+hit_count/(select max(hit_count) from photo))';
 use Time::Piece;
 use Image::Seek;
 use constant PAGER_SYNTAX => "LimitXY";
 __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{
-SELECT __ESSENTIAL__
-FROM __TABLE__
-ORDER BY uploaded DESC
-LIMIT 4
-});
-__PACKAGE__->set_sql(popular => q{
-SELECT __ESSENTIAL__
-FROM __TABLE__
-ORDER BY hit_count DESC
-LIMIT 4
-});
 
+BEGIN {
+my %order_by = (
+     recent => "uploaded",
+     popular => "hit_count",
+     interesting => INTERESTINGNESS_ALGORITHM
+);
+
+while (my($label, $how) = each %order_by) {
+    __PACKAGE__->set_sql($label => qq{
+    SELECT __ESSENTIAL__
+    FROM __TABLE__
+    ORDER BY $how DESC
+    LIMIT 4
+    });
+    no strict;
+    *$label = sub {
+        my ($self, $r) = @_;
+        $self->view_paged_ordered($r, "$how desc");
+    };
+    __PACKAGE__->MODIFY_CODE_ATTRIBUTES(*{$label}{CODE}, "Exported"); # Hack
+}
+}
 __PACKAGE__->has_many(comments => "Memories::Comment");
 __PACKAGE__->has_a(uploader => "Memories::User");
 __PACKAGE__->has_a(uploaded => "Time::Piece",
@@ -139,16 +150,6 @@ sub view_paged_ordered {
     $r->template("paged"); # Set the what using the action name
 }
 
-sub recent :Exported {
-    my ($self, $r) = @_;
-    $self->view_paged_ordered($r, "uploaded desc");
-}
-
-sub popular :Exported {
-    my ($self, $r) = @_;
-    $self->view_paged_ordered($r, "hit_count desc");
-}
-
 sub add_comment :Exported {
     my ($self, $r, $photo) = @_;
     $r->template("view");
index a90478d616ba5e6d8e9dde7ba13296fde3d10bd1..ab576dc0f0d649fdd3532ad9b58649a013958944 100644 (file)
@@ -20,6 +20,9 @@
 <td><a href="[%base%]/photo/popular">Most popular</a></td>
 </tr>
 <tr>
+<td><a href="[%base%]/photo/interesting">Most interesting</a></td>
+</tr>
+<tr>
 <td><a href="[%base%]/album/list">List albums</a></td>
 </tr>