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) {
|
sub get_posts($self, $this_page = undef) {
|
||||||
if ($this_page) {
|
if ($this_page) {
|
||||||
my $row_count = $self->{'max_posts'};
|
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();
|
$self->pg->db->query(<<~'END_SQL', $row_count, $offset)->arrays();
|
||||||
SELECT to_char(message_date, 'Dy Mon DD HH:MI:SS AM TZ YYYY'),
|
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) {
|
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
|
# Add a page if we have "remainder" posts
|
||||||
if ($post_count % $self->{'max_posts'}) {
|
return $post_count % $self->{'max_posts'} ? ++$last_page : $last_page;
|
||||||
sprintf('%d', $post_count / $self->{'max_posts'}) + 1
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
sprintf('%d', $post_count / $self->{'max_posts'})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_post_count($self) {
|
sub get_post_count($self) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user