From: Simon Cozens Date: Sat, 10 Feb 2007 00:54:00 +0000 (+0000) Subject: Add interface to "most popular photos" X-Git-Tag: 1.2+svn20070808~49 X-Git-Url: https://git.decadent.org.uk/gitweb/?p=memories.git;a=commitdiff_plain;h=0462f25b10e5adb4eacc0e11f4ced5165784f38f Add interface to "most popular photos" git-svn-id: http://svn.simon-cozens.org/memories/trunk@19 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- diff --git a/Memories/Photo.pm b/Memories/Photo.pm index 771c3a6..ce0cd20 100644 --- a/Memories/Photo.pm +++ b/Memories/Photo.pm @@ -14,6 +14,12 @@ FROM __TABLE__ ORDER BY uploaded DESC LIMIT 4 }); +__PACKAGE__->set_sql(popular => q{ +SELECT __ESSENTIAL__ +FROM __TABLE__ +ORDER BY hit_count DESC +LIMIT 4 +}); __PACKAGE__->has_many(comments => "Memories::Comment"); __PACKAGE__->has_a(uploader => "Memories::User"); @@ -118,18 +124,29 @@ sub similar :Exported {} use Class::DBI::Plugin::Pager; use Class::DBI::Plugin::AbstractCount; -sub recent :Exported { - my ($self, $r) = @_; +sub view_paged_ordered { + my ($self, $r, $how) = @_; my $page = $r->params->{page} || 1; my $pager = $self->pager( per_page => Memories->config->{photos_per_page}, page => $page, syntax => PAGER_SYNTAX, - order_by => "uploaded desc" + order_by => $how ); $r->objects([$pager->retrieve_all ]); $r->{template_args}{pager} = $pager; $r->last_search; + $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 { diff --git a/templates/macros b/templates/macros index 514f270..6acc624 100644 --- a/templates/macros +++ b/templates/macros @@ -29,8 +29,9 @@ IF photo.rated > 0; %] [% SET r = photo.approx_rating %]
[% IF r > 0 OR photo.hit_count > 0 %] - [% photo.hit_count %] views - [% IF r > 0 %]
[% ministar(r, photo) %] in [%photo.rated %] ratings [% END %] + [% photo.hit_count %] view[%IF photo.hit_count>1%]s[% END %] + [% IF r > 0 %]
[% ministar(r, photo) %] in [%photo.rated %] + rating[%IF photo.rated > 1%]s[%END%] [% END %] [% END %] [% IF request.user %] diff --git a/templates/photo/paged b/templates/photo/paged new file mode 100644 index 0000000..8009fe8 --- /dev/null +++ b/templates/photo/paged @@ -0,0 +1,18 @@ +[% INCLUDE header %] +[% PROCESS macros %] +

Most [% request.action %] photos

+ +[% WHILE photos.size > 0 %] +[% SET triple = photos.splice(0,3) %] + + [% FOR photo = triple %] + + [% END %] + +[% END %] +
+ [% thumb(photo, 1) %] +
+ +[% INCLUDE pager %] +[% INCLUDE footer %] diff --git a/templates/photo/recent b/templates/photo/recent deleted file mode 100644 index 37d1ae3..0000000 --- a/templates/photo/recent +++ /dev/null @@ -1,18 +0,0 @@ -[% INCLUDE header %] -[% PROCESS macros %] -

Recent photos

- -[% WHILE photos.size > 0 %] -[% SET triple = photos.splice(0,3) %] - - [% FOR photo = triple %] - - [% END %] - -[% END %] -
- [% thumb(photo, 1) %] -
- -[% INCLUDE pager %] -[% INCLUDE footer %] diff --git a/templates/rhs b/templates/rhs index 2816a73..a90478d 100644 --- a/templates/rhs +++ b/templates/rhs @@ -17,6 +17,9 @@ Recently uploaded +Most popular + + List albums