From: Banana Date: Thu, 3 Oct 2019 19:17:46 +0000 (+0200) Subject: pagination on overview X-Git-Tag: 2.2_2019-12-27~26 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=f1ca9710679b3051f63a36a4f530f32dbe9f14da;p=insipid.git pagination on overview --- diff --git a/ChangeLog b/ChangeLog index c983c91..cb2b7a4 100755 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ version 2.2alpha - Guardian of Ice - (tba) * email import * code cleanups * using mysql transactions if needed + * pagination version 2.1alpha - Guardian of Fire - (2019-09-29) diff --git a/webroot/config.default.php b/webroot/config.default.php index ef73a95..e645573 100644 --- a/webroot/config.default.php +++ b/webroot/config.default.php @@ -46,6 +46,9 @@ define('LOCAL_STORAGE', 'localdata'); # username and password see above define("USE_PAGE_AUTH",false); +# results per page +define("RESULTS_PER_PAGE",10); + # settings for importing from e-mail # SSL/TLS only # imap diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index cee705f..a26cab7 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -267,7 +267,7 @@ class Management { * @param bool | int $limit * @return array */ - public function links($limit=false) { + public function links($limit=false,$offset=false) { $ret = array(); $queryStr = "SELECT ".$this->COMBINED_SELECT_VALUES." @@ -275,9 +275,21 @@ class Management { WHERE `status` = 2 GROUP BY `hash` ORDER BY `created` DESC"; + if(!empty($limit)) { + $queryStr .= " LIMIT $limit"; + if($offset !== false) { + $queryStr .= " OFFSET $offset"; + } + } $query = $this->DB->query($queryStr); if(!empty($query) && $query->num_rows > 0) { - $ret = $query->fetch_all(MYSQLI_ASSOC); + $ret['results'] = $query->fetch_all(MYSQLI_ASSOC); + + $query = $this->DB->query("SELECT COUNT(DISTINCT(hash)) AS `amount` + FROM `".DB_PREFIX."_combined` + WHERE `status` = 2"); + $result = $query->fetch_assoc(); + $ret['amount'] = $result['amount']; } return $ret; diff --git a/webroot/view/overview.inc.php b/webroot/view/overview.inc.php index 05581ec..09eb95a 100644 --- a/webroot/view/overview.inc.php +++ b/webroot/view/overview.inc.php @@ -36,11 +36,17 @@ if(isset($_GET['id']) && !empty($_GET['id'])) { $_id = trim($_GET['id']); $_id = Summoner::validate($_id,'digit') ? $_id : false; } +$_curPage = 1; +if(isset($_GET['page']) && !empty($_GET['page'])) { + $_curPage = trim($_GET['page']); + $_curPage = Summoner::validate($_curPage,'digit') ? $_curPage : 1; +} $linkCollection = array(); $subHeadline = false; $tagCollection = array(); $categoryCollection = array(); +$pagination = array('pages' => 0); switch($_requestMode) { case 'tag': @@ -72,5 +78,29 @@ switch($_requestMode) { case 'all': default: # show all - $linkCollection = $Management->links(); + $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1))); + if(!empty($linkCollection['amount'])) { + $pagination['pages'] = ceil($linkCollection['amount'] / RESULTS_PER_PAGE); + $pagination['curPage'] = $_curPage; + $pagination['m'] = $_requestMode; + } +} + +if($pagination['pages'] > 11) { + # first pages + $pagination['visibleRange'] = range(1,3); + # last pages + foreach(range($pagination['pages']-2, $pagination['pages']) as $e) { + array_push($pagination['visibleRange'], $e); + } + # pages before and after current page + $cRange = range($pagination['curPage']-1, $pagination['curPage']+1); + foreach($cRange as $e) { + array_push($pagination['visibleRange'], $e); + } + $pagination['currentRangeStart'] = array_shift($cRange); + $pagination['currentRangeEnd'] = array_pop($cRange); +} +else { + $pagination['visibleRange'] = range(1,$pagination['pages']); } diff --git a/webroot/view/overview.php b/webroot/view/overview.php index 79e6536..fc5bc5c 100644 --- a/webroot/view/overview.php +++ b/webroot/view/overview.php @@ -50,12 +50,51 @@ + + 0) { ?> + +
- +
- +