]> 91.132.146.200 Git - insipid.git/commitdiff
Fixed pagination and sort options in all links view
authorBanana <mail@bananas-playground.net>
Tue, 27 Dec 2022 21:58:35 +0000 (22:58 +0100)
committerBanana <mail@bananas-playground.net>
Tue, 27 Dec 2022 21:58:35 +0000 (22:58 +0100)
ChangeLog
webroot/lib/management.class.php
webroot/view/overview.inc.php

index 4cb8f6cb8f2d70d2c5e5d3b2ff734525b4ad4144..d4698c1da7c7fd1e0f65d36d0e8d99b1fd8ebb5f 100644 (file)
--- 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)
 
index 74c9ab52def27980b90ec41b7ee539063fea525b..772c63121ccafffa8f0d59210dec5ed2810b9e6c 100644 (file)
@@ -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()) {
index 146a5bd4b0cbeaad7a9abef14a55b0572263a2f8..8145e780a1c5bd9e8359bd70cbc981e706637389 100644 (file)
@@ -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'])) {