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",
$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");