From 0462f25b10e5adb4eacc0e11f4ced5165784f38f Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Sat, 10 Feb 2007 00:54:00 +0000 Subject: [PATCH] Add interface to "most popular photos" git-svn-id: http://svn.simon-cozens.org/memories/trunk@19 041978f6-d955-411f-a9d7-1d8545c9c3c7 --- Memories/Photo.pm | 23 ++++++++++++++++++++--- templates/macros | 5 +++-- templates/photo/{recent => paged} | 2 +- templates/rhs | 3 +++ 4 files changed, 27 insertions(+), 6 deletions(-) rename templates/photo/{recent => paged} (87%) 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/recent b/templates/photo/paged similarity index 87% rename from templates/photo/recent rename to templates/photo/paged index 37d1ae3..8009fe8 100644 --- a/templates/photo/recent +++ b/templates/photo/paged @@ -1,6 +1,6 @@ [% INCLUDE header %] [% PROCESS macros %] -

Recent photos

+

Most [% request.action %] photos

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