summaryrefslogtreecommitdiffstats
path: root/inc/pagination.inc.php
diff options
context:
space:
mode:
authorSimon Rettberg2016-05-19 17:00:35 +0200
committerSimon Rettberg2016-05-19 17:00:35 +0200
commit4e65c3bc0bccf6be849cceb185aacd18e337f7f4 (patch)
treeb877d3502b3d48fa3f65a316e4615465d41af8a8 /inc/pagination.inc.php
parentFix CSRF token checking; improve token/sid generation (diff)
downloadslx-admin-4e65c3bc0bccf6be849cceb185aacd18e337f7f4.tar.gz
slx-admin-4e65c3bc0bccf6be849cceb185aacd18e337f7f4.tar.xz
slx-admin-4e65c3bc0bccf6be849cceb185aacd18e337f7f4.zip
[usermanagement] Merge changes from 'gitlab.c3sl.ufpr.br/cdn/slx-admin.git'
Diffstat (limited to 'inc/pagination.inc.php')
-rw-r--r--inc/pagination.inc.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/inc/pagination.inc.php b/inc/pagination.inc.php
new file mode 100644
index 00000000..65785a36
--- /dev/null
+++ b/inc/pagination.inc.php
@@ -0,0 +1,47 @@
+<?php
+
+/**
+ * TODO: Why does this class exist?
+ * There's already the Paginate class which works more efficient by using the LIMIT statement
+ * for the query, and has more options. Consider refactoring the places where this class is
+ * used (see syslog or eventlog for usage examples), then get rid of this one.
+ */
+class Pagination
+{
+ private $items;
+ private $page;
+ private $maxItems;
+
+ public function __construct($par1, $par2)
+ {
+ $this->items = $par1;
+ $this->page = $par2;
+
+ $this->maxItems = 5;
+ }
+
+ public function getPagination()
+ {
+ $ret = array();
+ $n = ceil(count($this->items) / $this->maxItems);
+ for ($i = 1; $i <= $n; $i++) {
+ $class = ($i == $this->page) ? 'active' : '';
+ $ret[] = array(
+ 'class' => $class,
+ 'page' => $i
+ );
+ }
+ return $ret;
+ }
+
+ public function getItems()
+ {
+ $ret = array();
+ $first = ($this->page - 1) * $this->maxItems;
+ for ($i = 0; $i < $this->maxItems; $i++) {
+ if ($first + $i < count($this->items))
+ $ret[] = $this->items[$first + $i];
+ }
+ return $ret;
+ }
+} \ No newline at end of file