aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/phpbb/pagination.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2013-12-12 02:30:56 +0100
committerJoas Schilling <nickvergessen@gmx.de>2013-12-18 18:35:16 +0100
commit725c51246822320ad8a723ac73c7ea4dd61bed39 (patch)
tree2f60e098c60aeca9365355950e945fdefc9f76a6 /phpBB/phpbb/pagination.php
parentfcfa1a35cc73471e4f8844920cdcf4d4990ce6b0 (diff)
downloadforums-725c51246822320ad8a723ac73c7ea4dd61bed39.tar
forums-725c51246822320ad8a723ac73c7ea4dd61bed39.tar.gz
forums-725c51246822320ad8a723ac73c7ea4dd61bed39.tar.bz2
forums-725c51246822320ad8a723ac73c7ea4dd61bed39.tar.xz
forums-725c51246822320ad8a723ac73c7ea4dd61bed39.zip
[ticket/11849] Replace pagination in viewforum.php with class
PHPBB3-11849
Diffstat (limited to 'phpBB/phpbb/pagination.php')
-rw-r--r--phpBB/phpbb/pagination.php41
1 files changed, 39 insertions, 2 deletions
diff --git a/phpBB/phpbb/pagination.php b/phpBB/phpbb/pagination.php
index 134e503c5d..467dc2157f 100644
--- a/phpBB/phpbb/pagination.php
+++ b/phpBB/phpbb/pagination.php
@@ -222,7 +222,7 @@ class pagination
* @param int $start the item which should be considered currently active, used to determine the page we're on
* @return int Current page number
*/
- protected function get_on_page($per_page, $start)
+ public function get_on_page($per_page, $start)
{
return floor($start / $per_page) + 1;
}
@@ -253,8 +253,9 @@ class pagination
/**
* Get current page number
*
- * @param int $per_page the number of items, posts, etc. per page
* @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @param int $per_page the number of items, posts, etc. per page
+ * @param int $num_items the total number of items, posts, topics, etc.
* @return int Current page number
*/
public function validate_start($start, $per_page, $num_items)
@@ -266,4 +267,40 @@ class pagination
return $start;
}
+
+ /**
+ * Get new start when searching from the end
+ *
+ * If the user is trying to reach late pages, start searching from the end.
+ *
+ * @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @param int $limit the number of items, posts, etc. to display
+ * @param int $num_items the total number of items, posts, topics, etc.
+ * @return int Current page number
+ */
+ public function reverse_start($start, $limit, $num_items)
+ {
+ return max(0, $num_items - $limit - $start);
+ }
+
+ /**
+ * Get new item limit when searching from the end
+ *
+ * If the user is trying to reach late pages, start searching from the end.
+ * In this case the items to display might be lower then the actual per_page setting.
+ *
+ * @param int $start the item which should be considered currently active, used to determine the page we're on
+ * @param int $per_page the number of items, posts, etc. per page
+ * @param int $num_items the total number of items, posts, topics, etc.
+ * @return int Current page number
+ */
+ public function reverse_limit($start, $per_page, $num_items)
+ {
+ if ($start + $per_page > $num_items)
+ {
+ return min($per_page, max(1, $num_items - $start));
+ }
+
+ return $per_page;
+ }
}