From 006c40622b5547fcbb693fb37e2216e1d0e7bb6e Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sat, 10 Feb 2007 11:42:22 +0000 Subject: [PATCH] Later we'll have to add a coefficient of commenting, but this is good for now. git-svn-id: http://svn.simon-cozens.org/memories/trunk@21 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- Memories/Photo.pm | 45 +++++++++++++++++++++++---------------------- templates/rhs | 3 +++ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Memories/Photo.pm b/Memories/Photo.pm index bcfb59c..5a9b91e 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -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"); diff --git a/templates/rhs b/templates/rhs index a90478d..ab576dc 100644 --- a/templates/rhs +++ b/templates/rhs @@ -20,6 +20,9 @@ Most popular +Most interesting + + List albums -- 2.39.5