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");
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 {
[% 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 %]
--- /dev/null
+[% 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 %]
+++ /dev/null
-[% 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 %]
<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>