From c7e7551e1d2d0362280a328319d03b7b5a6a91e5 Mon Sep 17 00:00:00 2001 From: Banana Date: Sun, 29 Dec 2019 20:57:34 +0100 Subject: [PATCH] some rewrite and sorting in tag overview --- ChangeLog | 3 +- webroot/lib/management.class.php | 60 +++++++++++++++++++++----------- webroot/view/overview.inc.php | 22 +++++------- webroot/view/overview.php | 2 ++ 4 files changed, 53 insertions(+), 34 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3a49000..4f0a24b 100755 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,8 @@ version x.x - Guardian of Steel (tba) + Improved documentation + Delete single local storage of a link ++ Done by uncheck the store image locally option - + Sorting in category view + + Sorting in category overview + + Sorting in tag overview + Fixed a bug in tag selection SQL query version 2.2 - Guardian of Ice - (2019-02-27) diff --git a/webroot/lib/management.class.php b/webroot/lib/management.class.php index a91b3cc..f5e0d26 100644 --- a/webroot/lib/management.class.php +++ b/webroot/lib/management.class.php @@ -299,18 +299,22 @@ class Management { return $ret; } - /** - * find all links by given tag string or id. - * Return array sorted by creation date DESC - * @param int $id - * @param string $string - * @param int $limit - * @param bool $offset - * @return array - */ - public function linksByTag($id, $string, $limit=5, $offset=false) { + /** + * find all links by given tag string or id. + * Return array sorted by creation date DESC + * @param int $id Tag id + * @param string $string Tag as string + * @param array $options Array with limit|offset|sort|sortDirection + * @return array + */ + public function linksByTag($id, $string, $options=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 ".self::COMBINED_SELECT_VALUES; $queryFrom = " FROM `".DB_PREFIX."_combined` AS t"; $queryWhere = " WHERE ".$this->_decideLinkTypeForQuery(); @@ -324,16 +328,32 @@ class Management { return $ret; } - $queryOrder = "GROUP BY t.hash - ORDER BY t.created DESC"; - $queryLimit = ''; - if(!empty($limit)) { - $queryLimit .= " LIMIT $limit"; - if($offset !== false) { - $queryLimit .= " OFFSET $offset"; - } - } - $query = $this->DB->query($querySelect.$queryFrom.$queryWhere.$queryOrder.$queryLimit); + $queryGroup = " GROUP BY t.hash"; + $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.$queryGroup.$queryOrder.$queryLimit); + if(!empty($query) && $query->num_rows > 0) { while($result = $query->fetch_assoc()) { $linkObj = new Link($this->DB); diff --git a/webroot/view/overview.inc.php b/webroot/view/overview.inc.php index eea682b..2e5c822 100644 --- a/webroot/view/overview.inc.php +++ b/webroot/view/overview.inc.php @@ -73,17 +73,20 @@ if(Summoner::simpleAuthCheck() === true) { $sortLink['active'] = 'default'; $sortLink['activeDirection'] = false; -$_saveSort = false; +$_LinkColllectionQueryOptions = array( + 'limit' => RESULTS_PER_PAGE, + 'offset' =>(RESULTS_PER_PAGE * ($_curPage-1)) +); + if(!empty($_sort) && $_sort === 'title') { $currentGetParameters['s'] = 'title'; $sortLink['active'] = 'title'; - $_saveSort = 'title'; + $_LinkColllectionQueryOptions['sort'] = 'title'; } -$_saveSortDirection = false; if(!empty($_sortDirection) && $_sortDirection === 'asc') { $currentGetParameters['sd'] = 'asc'; $sortLink['activeDirection'] = true; - $_saveSortDirection = 'asc'; + $_LinkColllectionQueryOptions['sortDirection'] = 'asc'; } switch($_requestMode) { @@ -95,7 +98,7 @@ switch($_requestMode) { $tagname = $tagObj->getData('name'); $subHeadline = $tagname.' '; - $linkCollection = $Management->linksByTag($_id,false,RESULTS_PER_PAGE, (RESULTS_PER_PAGE * ($_curPage-1))); + $linkCollection = $Management->linksByTag($_id,'', $_LinkColllectionQueryOptions); $currentGetParameters['id'] = $_id; } @@ -113,14 +116,7 @@ switch($_requestMode) { $catname = $catObj->getData('name'); $subHeadline = $catname.' '; - $_options = array( - 'limit' => RESULTS_PER_PAGE, - 'offset' =>(RESULTS_PER_PAGE * ($_curPage-1)) - ); - if(!empty($_saveSort)) $_options['sort'] = $_saveSort; - if(!empty($_saveSortDirection)) $_options['sortDirection'] = $_saveSortDirection; - - $linkCollection = $Management->linksByCategory($_id,'',$_options); + $linkCollection = $Management->linksByCategory($_id,'', $_LinkColllectionQueryOptions); $currentGetParameters['id'] = $_id; } diff --git a/webroot/view/overview.php b/webroot/view/overview.php index 081bd32..f0a29db 100644 --- a/webroot/view/overview.php +++ b/webroot/view/overview.php @@ -93,6 +93,7 @@
+
default @@ -101,6 +102,7 @@
+
-- 2.39.5