From cfa077b16585845015e2ab9858c414452e241d20 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 29 Dec 2017 15:24:12 +0100 Subject: [PATCH] Added missing label filter for articles --- com.woltlab.wcf/templates/articleList.tpl | 59 +++++++++ .../templates/categoryArticleList.tpl | 59 +++++++++ .../files/lib/page/ArticleListPage.class.php | 112 ++++++++++++++++++ .../page/CategoryArticleListPage.class.php | 14 ++- 4 files changed, 241 insertions(+), 3 deletions(-) diff --git a/com.woltlab.wcf/templates/articleList.tpl b/com.woltlab.wcf/templates/articleList.tpl index 820f4f6b9f..452b398d38 100644 --- a/com.woltlab.wcf/templates/articleList.tpl +++ b/com.woltlab.wcf/templates/articleList.tpl @@ -26,6 +26,65 @@ {/capture} {/if} +{capture assign='sidebarRight'} + {if !$labelGroups|empty} +
+
+

{lang}wcf.label.label{/lang}

+ +
+
+ {foreach from=$labelGroups item=labelGroup} + {if $labelGroup|count} +
{$labelGroup->getTitle()}
+
+
    + +
+ +
+ {/if} + {/foreach} +
+
+ +
+
+
+
+ + + {/if} +{/capture} + {include file='header'} {hascontent} diff --git a/com.woltlab.wcf/templates/categoryArticleList.tpl b/com.woltlab.wcf/templates/categoryArticleList.tpl index 12abb84fd5..4a547f2218 100644 --- a/com.woltlab.wcf/templates/categoryArticleList.tpl +++ b/com.woltlab.wcf/templates/categoryArticleList.tpl @@ -30,6 +30,65 @@ {/capture} {/if} +{capture assign='sidebarRight'} + {if !$labelGroups|empty} +
+
+

{lang}wcf.label.label{/lang}

+ +
+
+ {foreach from=$labelGroups item=labelGroup} + {if $labelGroup|count} +
{$labelGroup->getTitle()}
+
+
    + +
+ +
+ {/if} + {/foreach} +
+
+ +
+
+
+
+ + + {/if} +{/capture} + {include file='header'} {hascontent} diff --git a/wcfsetup/install/files/lib/page/ArticleListPage.class.php b/wcfsetup/install/files/lib/page/ArticleListPage.class.php index d137bf6b72..a612dd6277 100644 --- a/wcfsetup/install/files/lib/page/ArticleListPage.class.php +++ b/wcfsetup/install/files/lib/page/ArticleListPage.class.php @@ -1,7 +1,13 @@ 'wcf']; + /** * @inheritDoc */ public function readParameters() { parent::readParameters(); + // read available label groups + $this->labelGroups = ArticleCategory::getAccessibleLabelGroups(); + if (!empty($this->labelGroups) && isset($_REQUEST['labelIDs']) && is_array($_REQUEST['labelIDs'])) { + $this->labelIDs = $_REQUEST['labelIDs']; + + foreach ($this->labelIDs as $groupID => $labelID) { + $isValid = false; + + // ignore zero-values + if (!is_array($labelID) && $labelID) { + if (isset($this->labelGroups[$groupID]) && ($labelID == -1 || $this->labelGroups[$groupID]->isValid($labelID))) { + $isValid = true; + } + } + + if (!$isValid) { + unset($this->labelIDs[$groupID]); + } + } + } + + if (!empty($_POST)) { + $labelParameters = ''; + if (!empty($this->labelIDs)) { + foreach ($this->labelIDs as $groupID => $labelID) { + $labelParameters .= 'labelIDs['.$groupID.']='.$labelID.'&'; + } + } + + HeaderUtil::redirect(LinkHandler::getInstance()->getLink($this->controllerName, $this->controllerParameters, rtrim($labelParameters, '&'))); + exit; + } + $this->canonicalURL = LinkHandler::getInstance()->getLink('ArticleList', [], ($this->pageNo > 1 ? 'pageNo=' . $this->pageNo : '')); } + + /** + * @inheritDoc + */ + protected function initObjectList() { + parent::initObjectList(); + + $this->applyFilters(); + } + + protected function applyFilters() { + // filter by label + if (!empty($this->labelIDs)) { + $objectTypeID = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.label.object', 'com.woltlab.wcf.article')->objectTypeID; + + foreach ($this->labelIDs as $groupID => $labelID) { + if ($labelID == -1) { + $groupLabelIDs = LabelHandler::getInstance()->getLabelGroup($groupID)->getLabelIDs(); + + if (!empty($groupLabelIDs)) { + $this->objectList->getConditionBuilder()->add('article.articleID NOT IN (SELECT objectID FROM wcf'.WCF_N.'_label_object WHERE objectTypeID = ? AND labelID IN (?))', [ + $objectTypeID, + $groupLabelIDs + ]); + } + } + else { + $this->objectList->getConditionBuilder()->add('article.articleID IN (SELECT objectID FROM wcf'.WCF_N.'_label_object WHERE objectTypeID = ? AND labelID = ?)', [ + $objectTypeID, + $labelID + ]); + } + } + } + } + + /** + * @inheritDoc + */ + public function assignVariables() { + parent::assignVariables(); + + WCF::getTPL()->assign([ + 'labelGroups' => $this->labelGroups, + 'labelIDs' => $this->labelIDs, + 'controllerName' => $this->controllerName, + 'controllerObject' => null + ]); + } } diff --git a/wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php b/wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php index 1e124dd272..17bd904ddb 100644 --- a/wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php +++ b/wcfsetup/install/files/lib/page/CategoryArticleListPage.class.php @@ -30,17 +30,22 @@ class CategoryArticleListPage extends ArticleListPage { */ public $categoryID = 0; + /** + * @inheritDoc + */ + public $controllerName = 'CategoryArticleList'; + /** * @inheritDoc */ public function readParameters() { - parent::readParameters(); - if (isset($_REQUEST['id'])) $this->categoryID = intval($_REQUEST['id']); $this->category = ArticleCategory::getCategory($this->categoryID); if ($this->category === null) { throw new IllegalLinkException(); } + $this->controllerParameters['object'] = $this->category; + parent::readParameters(); $this->canonicalURL = LinkHandler::getInstance()->getLink('CategoryArticleList', [ 'object' => $this->category @@ -64,6 +69,8 @@ class CategoryArticleListPage extends ArticleListPage { */ protected function initObjectList() { $this->objectList = new CategoryArticleList($this->categoryID, true); + + $this->applyFilters(); } /** @@ -86,7 +93,8 @@ class CategoryArticleListPage extends ArticleListPage { WCF::getTPL()->assign([ 'categoryID' => $this->categoryID, - 'category' => $this->category + 'category' => $this->category, + 'controllerObject' => $this->category ]); } } -- 2.20.1