Changeset 21

Show
Ignore:
Timestamp:
02/10/07 11:42:22 (2 years ago)
Author:
simon
Message:

Later we'll have to add a coefficient of commenting, but this is good for now.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/Memories/Photo.pm

    r20 r21  
    33use Carp qw(cluck confess); 
    44use base qw(Memories::DBI Maypole::Model::CDBI::Plain); 
     5use constant INTERESTINGNESS_ALGORITHM => '((rating+3)/(rated+1))*(1+rated/hit_count)*(1+hit_count/(select max(hit_count) from photo))'; 
    56use Time::Piece; 
    67use Image::Seek; 
     
    910__PACKAGE__->untaint_columns(printable => [qw/title/]); 
    1011__PACKAGE__->columns(TEMP => qw/exif_object/); 
    11 __PACKAGE__->set_sql(recent => q{ 
    12 SELECT __ESSENTIAL__ 
    13 FROM __TABLE__ 
    14 ORDER BY uploaded DESC 
    15 LIMIT 4 
    16 }); 
    17 __PACKAGE__->set_sql(popular => q{ 
    18 SELECT __ESSENTIAL__ 
    19 FROM __TABLE__ 
    20 ORDER BY hit_count DESC 
    21 LIMIT 4 
    22 }); 
    23  
     12 
     13BEGIN { 
     14my %order_by = ( 
     15     recent => "uploaded", 
     16     popular => "hit_count", 
     17     interesting => INTERESTINGNESS_ALGORITHM 
     18); 
     19 
     20while (my($label, $how) = each %order_by) { 
     21    __PACKAGE__->set_sql($label => qq{ 
     22    SELECT __ESSENTIAL__ 
     23    FROM __TABLE__ 
     24    ORDER BY $how DESC 
     25    LIMIT 4 
     26    }); 
     27    no strict; 
     28    *$label = sub { 
     29        my ($self, $r) = @_; 
     30        $self->view_paged_ordered($r, "$how desc"); 
     31    }; 
     32    __PACKAGE__->MODIFY_CODE_ATTRIBUTES(*{$label}{CODE}, "Exported"); # Hack 
     33
     34
    2435__PACKAGE__->has_many(comments => "Memories::Comment"); 
    2536__PACKAGE__->has_a(uploader => "Memories::User"); 
     
    140151} 
    141152 
    142 sub recent :Exported { 
    143     my ($self, $r) = @_; 
    144     $self->view_paged_ordered($r, "uploaded desc"); 
    145 } 
    146  
    147 sub popular :Exported { 
    148     my ($self, $r) = @_; 
    149     $self->view_paged_ordered($r, "hit_count desc"); 
    150 } 
    151  
    152153sub add_comment :Exported { 
    153154    my ($self, $r, $photo) = @_; 
  • trunk/templates/rhs

    r19 r21  
    1919<tr> 
    2020<td><a href="[%base%]/photo/popular">Most popular</a></td> 
     21</tr> 
     22<tr> 
     23<td><a href="[%base%]/photo/interesting">Most interesting</a></td> 
    2124</tr> 
    2225<tr>