1 package Blog
::Helper
::Post
;
5 use base
'Blog::Helper';
8 my ( $self, $args ) = @_;
10 my $c = Blog
->context;
12 my $posts = $c->model( 'Post' )->manager->list( %$args );
17 $_->column_value_pairs,
18 comment_count
=> $_->comment_count,
26 my ( $self, $args ) = @_;
28 my $c = Blog
->context;
30 my $tag_id = delete $args->{ tag_id
};
33 query
=> [ 't3.tag_id' => $tag_id ],
34 with_objects
=> [ 'post_tag_map' ]
37 return $self->list( $cond );
41 my ( $self, $page ) = @_;
43 $page = 1 unless $page && $page =~ m/^\d+$/o;
45 my $c = Blog
->context;
48 count
=> $c->model( 'Post' )->count(),
49 page_size
=> $c->model( 'Post' )->manager->default_objects_per_page,
55 my ( $self, $limit ) = @_;
57 my $c = Blog
->context;
59 my $posts = $c->model( 'Post' )->manager->recent( $limit || 10 );
61 return [ map { scalar $_->column_value_pairs } @
$posts ];
65 my ( $self, $post ) = @_;
67 my $c = Blog
->context;
69 my $newer_post = $c->model( 'Post' )->manager->newer( $post->{ addtime
} );
71 return unless $newer_post;
73 return scalar $newer_post->column_value_pairs;
77 my ( $self, $post ) = @_;
79 my $c = Blog
->context;
81 my $older_post = $c->model( 'Post' )->manager->older( $post->{ addtime
} );
83 return unless $older_post;
85 return scalar $older_post->column_value_pairs;
91 my $c = Blog
->context;
93 my $oldest = $c->model( 'Post' )->search(
95 sort_by
=> 'addtime ASC',
99 my $newest = $c->model( 'Post' )->search(
101 sort_by
=> 'addtime DESC',
105 $oldest = $oldest->[0];
106 $newest = $newest->[0];
108 return unless $oldest && $newest;
110 $oldest = $oldest->addtime;
111 $newest = $newest->addtime;
115 while ( $dt > $oldest ) {
116 my $count = $c->model( 'Post' )->manager->get_posts_count(
118 addtime
=> { gt => $dt->clone->subtract( months
=> 1 )->epoch },
119 addtime
=> { le => $dt->epoch }
128 month_name
=> $c->helper('Util')->mon2name($dt->month - 1)
132 $dt->subtract( months
=> 1 );
141 my $c = Blog
->context;
143 my $posts = $c->model( 'Post' )->manager->archive( @_ );
148 $_->column_value_pairs,
149 comment_count
=> $_->comment_count,
162 This library is free software, you can redistribute it and/or modify
163 it under the same terms as Perl itself.