Changeset 21
- Timestamp:
- 02/10/07 11:42:22 (2 years ago)
- Files:
-
- trunk/Memories/Photo.pm (modified) (3 diffs)
- trunk/templates/rhs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/Memories/Photo.pm
r20 r21 3 3 use Carp qw(cluck confess); 4 4 use base qw(Memories::DBI Maypole::Model::CDBI::Plain); 5 use constant INTERESTINGNESS_ALGORITHM => '((rating+3)/(rated+1))*(1+rated/hit_count)*(1+hit_count/(select max(hit_count) from photo))'; 5 6 use Time::Piece; 6 7 use Image::Seek; … … 9 10 __PACKAGE__->untaint_columns(printable => [qw/title/]); 10 11 __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 13 BEGIN { 14 my %order_by = ( 15 recent => "uploaded", 16 popular => "hit_count", 17 interesting => INTERESTINGNESS_ALGORITHM 18 ); 19 20 while (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 } 24 35 __PACKAGE__->has_many(comments => "Memories::Comment"); 25 36 __PACKAGE__->has_a(uploader => "Memories::User"); … … 140 151 } 141 152 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 152 153 sub add_comment :Exported { 153 154 my ($self, $r, $photo) = @_; trunk/templates/rhs
r19 r21 19 19 <tr> 20 20 <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> 21 24 </tr> 22 25 <tr>
