From: Banana Date: Tue, 27 Dec 2022 21:58:35 +0000 (+0100) Subject: Fixed pagination and sort options in all links view X-Git-Tag: 2.8.1_20221231~4 X-Git-Url: http://91.132.146.200/gitweb/?a=commitdiff_plain;h=b8530e5da900f0d8d72ce28147e94d4d690e3b91;p=insipid.git Fixed pagination and sort options in all links view --- diff --git a/ChangeLog b/ChangeLog index 4cb8f6c..d4698c1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,7 @@ version 2.x - Deathwind Chapel () + Fixed search index update + Fixed missing lang property + Fixed xml ex- and import + + Fixed pagination and sort options in all links view version 2.8 - Wastelands (2022-12-10) diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index 74c9ab5..772c631 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -439,24 +439,45 @@ class Management { /** * return all links and Info we have from the combined view * - * @param int $limit - * @param bool $offset + * @param array $options * @return array */ - public function links(int $limit=10, bool $offset=false): array { + public function links(array $options=array()): array { $ret = array(); + if(!isset($options['limit'])) $options['limit'] = 5; + if(!isset($options['offset'])) $options['offset'] = false; + if(!isset($options['sort'])) $options['sort'] = false; + if(!isset($options['sortDirection'])) $options['sortDirection'] = false; + $querySelect = "SELECT `hash`"; $queryFrom = " FROM `".DB_PREFIX."_link` AS t"; $queryWhere = " WHERE ".$this->_decideLinkTypeForQuery(); - $queryOrder = " ORDER BY `created` DESC"; - $queryLimit = ""; - if(!empty($limit)) { - $queryLimit = " LIMIT $limit"; - if($offset !== false) { - $queryLimit .= " OFFSET $offset"; + + $queryOrder = " ORDER BY"; + if(!empty($options['sort'])) { + $queryOrder .= ' t.'.$options['sort']; + } + else { + $queryOrder .= " t.created"; + } + if(!empty($options['sortDirection'])) { + $queryOrder .= ' '.$options['sortDirection']; + } + else { + $queryOrder .= " DESC"; + } + + $queryLimit = ''; + # this allows the set the limit to false + if(!empty($options['limit'])) { + $queryLimit .= " LIMIT ".$options['limit']; + # offset can be 0 + if($options['offset'] !== false) { + $queryLimit .= " OFFSET ".$options['offset']; } } + $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryOrder.$queryLimit); if(!empty($query) && $query->num_rows > 0) { while($result = $query->fetch_assoc()) { diff --git a/webroot/view/overview.inc.php b/webroot/view/overview.inc.php index 146a5bd..8145e78 100644 --- a/webroot/view/overview.inc.php +++ b/webroot/view/overview.inc.php @@ -133,12 +133,12 @@ switch($_requestMode) { $subHeadline = 'Awaiting moderation'; $Management->setShowAwm(true); - $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1))); + $linkCollection = $Management->links($_LinkColllectionQueryOptions); break; case 'all': default: # show all - $linkCollection = $Management->links(RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1))); + $linkCollection = $Management->links($_LinkColllectionQueryOptions); } if(!empty($linkCollection['amount'])) {