Clean up get_last_page()
This commit is contained in:
parent
89712d81a8
commit
328e1f4d4d
|
@ -16,7 +16,7 @@ sub new($class, $pg, $pg_object) {
|
|||
sub get_posts($self, $this_page = undef) {
|
||||
if ($this_page) {
|
||||
my $row_count = $self->{'max_posts'};
|
||||
my $offset = ($this_page - 1) * $row_count;
|
||||
my $offset = ($this_page - 1) * $row_count;
|
||||
|
||||
$self->pg->db->query(<<~'END_SQL', $row_count, $offset)->arrays();
|
||||
SELECT to_char(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
|
||||
|
@ -50,15 +50,11 @@ sub max_posts($self, $value = undef) {
|
|||
}
|
||||
|
||||
sub get_last_page($self) {
|
||||
my $post_count = get_post_count($self);
|
||||
my $post_count = $self->get_post_count();
|
||||
my $last_page = sprintf('%d', $post_count / $self->{'max_posts'});
|
||||
|
||||
# Add a page if we have "remainder" posts
|
||||
if ($post_count % $self->{'max_posts'}) {
|
||||
sprintf('%d', $post_count / $self->{'max_posts'}) + 1
|
||||
}
|
||||
else {
|
||||
sprintf('%d', $post_count / $self->{'max_posts'})
|
||||
}
|
||||
return $post_count % $self->{'max_posts'} ? ++$last_page : $last_page;
|
||||
}
|
||||
|
||||
sub get_post_count($self) {
|
||||
|
|
Loading…
Reference in a new issue