[Bast-commits] r8849 - in ironman:
IronMan-Web/lib/IronMan/Web/Controller
IronMan-Web/root/archive plagger/lib/IronMan/Schema/Result
fade at dev.catalyst.perl.org
fade at dev.catalyst.perl.org
Tue Mar 2 16:50:55 GMT 2010
Author: fade
Date: 2010-03-02 16:50:55 +0000 (Tue, 02 Mar 2010)
New Revision: 8849
Modified:
ironman/IronMan-Web/lib/IronMan/Web/Controller/Archive.pm
ironman/IronMan-Web/root/archive/day.tt
ironman/plagger/lib/IronMan/Schema/Result/Post.pm
Log:
next/previous now search for the next/previous post, rather than doing a calendar-based check
Modified: ironman/IronMan-Web/lib/IronMan/Web/Controller/Archive.pm
===================================================================
--- ironman/IronMan-Web/lib/IronMan/Web/Controller/Archive.pm 2010-03-02 13:48:24 UTC (rev 8848)
+++ ironman/IronMan-Web/lib/IronMan/Web/Controller/Archive.pm 2010-03-02 16:50:55 UTC (rev 8849)
@@ -60,26 +60,26 @@
'second' => 0,
);
- my $posts = $c->model('FeedDB::Post')->posts_for_month($dt_month);
+ my @posts = $c->model('FeedDB::Post')->posts_for_month($dt_month)->all;
tie(my %posts_per_day, 'Tie::IxHash');
- foreach my $post ($posts->all) {
+ foreach my $post (@posts) {
my $day = $post->posted_on->day;
push( @{$posts_per_day{$day}}, $post);
}
$c->stash( 'posts_per_day' => \%posts_per_day );
$c->stash( 'month' => $dt_month );
- my $next_month = $dt_month->clone->subtract( 'months' => 1 );
- if ($c->model('FeedDB::Post')->posts_for_month($next_month)->count) {
- my $older_url = $c->uri_for($c->action, $next_month->year, $next_month->month );
+ my $next_post = $posts[-1]->next_post;
+ if (defined($next_post)) {
+ my $older_url = $c->uri_for($c->action, $next_post->posted_on->year, $next_post->posted_on->month );
$c->stash( 'older_url' => $older_url );
}
- my $prev_month = $dt_month->clone->add( 'months' => 1 );
- if ($c->model('FeedDB::Post')->posts_for_month($prev_month)->count) {
- my $younger_url = $c->uri_for($c->action, $prev_month->year, $prev_month->month );
+ my $prev_post = $posts[0]->prev_post;
+ if (defined($prev_post)) {
+ my $younger_url = $c->uri_for($c->action, $prev_post->posted_on->year, $prev_post->posted_on->month );
$c->stash( 'younger_url' => $younger_url );
}
@@ -102,21 +102,22 @@
'second' => 0,
);
- my $posts = $c->model('FeedDB::Post')->posts_for_day($dt_day);
- $c->stash( 'posts' => $posts );
+ my @posts = $c->model('FeedDB::Post')->posts_for_day($dt_day)->all;
+ $c->stash( 'posts' => \@posts );
$c->stash( 'day' => $dt_day );
- my $next_day = $dt_day->clone->subtract( 'days' => 1 );
- if ($c->model('FeedDB::Post')->posts_for_day($next_day)->count) {
- my $older_url = $c->uri_for($c->action, $next_day->year, $next_day->month, $next_day->day );
+ my $next_post = $posts[-1]->next_post;
+ if (defined($next_post)) {
+ my $older_url = $c->uri_for($c->action, $next_post->posted_on->year, $next_post->posted_on->month, $next_post->posted_on->day );
$c->stash( 'older_url' => $older_url );
}
- my $prev_day = $dt_day->clone->add( 'days' => 1 );
- if ($c->model('FeedDB::Post')->posts_for_day($prev_day)->count) {
- my $younger_url = $c->uri_for($c->action, $prev_day->year, $prev_day->month, $prev_day->day );
+ my $prev_post = $posts[0]->prev_post;
+ if (defined($prev_post)) {
+ my $younger_url = $c->uri_for($c->action, $prev_post->posted_on->year, $prev_post->posted_on->month, $prev_post->posted_on->day );
$c->stash( 'younger_url' => $younger_url );
}
+
}
=head1 AUTHOR
Modified: ironman/IronMan-Web/root/archive/day.tt
===================================================================
--- ironman/IronMan-Web/root/archive/day.tt 2010-03-02 13:48:24 UTC (rev 8848)
+++ ironman/IronMan-Web/root/archive/day.tt 2010-03-02 16:50:55 UTC (rev 8849)
@@ -1,7 +1,7 @@
Daily archive for [% day.strftime('%A, %d %B %Y') %]
-[% FOREACH post IN posts.all %]
+[% FOREACH post IN posts %]
[% INCLUDE 'inc/post_teaser.tt'
post = post
Modified: ironman/plagger/lib/IronMan/Schema/Result/Post.pm
===================================================================
--- ironman/plagger/lib/IronMan/Schema/Result/Post.pm 2010-03-02 13:48:24 UTC (rev 8848)
+++ ironman/plagger/lib/IronMan/Schema/Result/Post.pm 2010-03-02 16:50:55 UTC (rev 8849)
@@ -65,4 +65,30 @@
'deflate' => sub { return join(',', @{$_[0]}) },
});
+sub next_post {
+ my $self = shift;
+
+ my $dt_parser = $self->result_source->storage->datetime_parser;
+
+ return $self->result_source->resultset->search({
+ 'posted_on' => { '<' => $dt_parser->format_datetime($self->posted_on) },
+ },{
+ 'order_by' => \'posted_on DESC',
+ 'rows' => 1,
+ })->first;
+}
+
+sub prev_post {
+ my $self = shift;
+
+ my $dt_parser = $self->result_source->storage->datetime_parser;
+
+ return $self->result_source->resultset->search({
+ 'posted_on' => { '>' => $dt_parser->format_datetime($self->posted_on) },
+ },{
+ 'order_by' => \'posted_on ASC',
+ 'rows' => 1,
+ })->first;
+}
+
1;
More information about the Bast-commits
mailing list