]> git.decadent.org.uk Git - memories.git/commitdiff
Add interface to "most popular photos"
authorSimon Cozens <simon@simon-cozens.org>
Sat, 10 Feb 2007 00:54:00 +0000 (00:54 +0000)
committerSimon Cozens <simon@simon-cozens.org>
Sat, 10 Feb 2007 00:54:00 +0000 (00:54 +0000)
git-svn-id: http://svn.simon-cozens.org/memories/trunk@19 041978f6-d955-411f-a9d7-1d8545c9c3c7

Memories/Photo.pm
templates/macros
templates/photo/paged [new file with mode: 0644]
templates/photo/recent [deleted file]
templates/rhs

index 771c3a6ba3f6e619ed704b1d9f783394426b161d..ce0cd2003a777277b06e5e535389e14c1be033ba 100644 (file)
@@ -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 {
index 514f270cb5c4047ce0f1d7df31b4762d273413d7..6acc624c20a3227563e97b10f979af595ad1c21f 100644 (file)
@@ -29,8 +29,9 @@ IF photo.rated > 0; %]
         [% SET r = photo.approx_rating %]
         <br/>
 [% IF r > 0 OR photo.hit_count > 0 %]
-    [% photo.hit_count %] views
-    [% IF r > 0 %] <br> [% ministar(r, photo) %] in [%photo.rated %] ratings [% END %]
+    [% photo.hit_count %] view[%IF photo.hit_count>1%]s[% END %]
+    [% IF r > 0 %] <br> [% ministar(r, photo) %] in [%photo.rated %]
+    rating[%IF photo.rated > 1%]s[%END%] [% END %]
 [% END %]
     </td></tr>
         [% IF request.user %]
diff --git a/templates/photo/paged b/templates/photo/paged
new file mode 100644 (file)
index 0000000..8009fe8
--- /dev/null
@@ -0,0 +1,18 @@
+[% INCLUDE header %]
+[% PROCESS macros %]
+<h1> Most [% request.action %] photos </h1>
+<table class="userlist">
+[% WHILE photos.size > 0 %]
+[% SET triple = photos.splice(0,3) %]
+    <tr>
+        [% FOR photo = triple %]
+        <td> 
+        [% thumb(photo, 1) %]
+        </td>
+        [% END %]
+    </tr>
+[% END %]
+</table>
+
+[% INCLUDE pager %]
+[% INCLUDE footer %]
diff --git a/templates/photo/recent b/templates/photo/recent
deleted file mode 100644 (file)
index 37d1ae3..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-[% INCLUDE header %]
-[% PROCESS macros %]
-<h1> Recent photos </h1>
-<table class="userlist">
-[% WHILE photos.size > 0 %]
-[% SET triple = photos.splice(0,3) %]
-    <tr>
-        [% FOR photo = triple %]
-        <td> 
-        [% thumb(photo, 1) %]
-        </td>
-        [% END %]
-    </tr>
-[% END %]
-</table>
-
-[% INCLUDE pager %]
-[% INCLUDE footer %]
index 2816a7343ab4a0254f0efcb337963890e3cd0a99..a90478d616ba5e6d8e9dde7ba13296fde3d10bd1 100644 (file)
@@ -17,6 +17,9 @@
 <td><a href="[%base%]/photo/recent">Recently uploaded</a></td>
 </tr>
 <tr>
+<td><a href="[%base%]/photo/popular">Most popular</a></td>
+</tr>
+<tr>
 <td><a href="[%base%]/album/list">List albums</a></td>
 </tr>