From: Matthias Schmidt Date: Sat, 23 Apr 2016 16:18:49 +0000 (+0200) Subject: Use Page objects for page condition X-Git-Tag: 3.0.0_Beta_1~1835 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=57052f8ecd728862a28f534fddff386a05287234;p=GitHub%2FWoltLab%2FWCF.git Use Page objects for page condition --- diff --git a/com.woltlab.wcf/objectType.xml b/com.woltlab.wcf/objectType.xml index 91e6426c8e..08badc908f 100644 --- a/com.woltlab.wcf/objectType.xml +++ b/com.woltlab.wcf/objectType.xml @@ -590,9 +590,9 @@ - com.woltlab.wcf.page.controller + com.woltlab.wcf.page com.woltlab.wcf.condition.notice - + com.woltlab.wcf.page @@ -749,9 +749,9 @@ - com.woltlab.wcf.page.controller + com.woltlab.wcf.page com.woltlab.wcf.condition.ad - + com.woltlab.wcf.page @@ -1102,5 +1102,20 @@ userOptions + + + + com.woltlab.wcf.page.controller + com.woltlab.wcf.condition.notice + + com.woltlab.wcf.page + + + com.woltlab.wcf.page.controller + com.woltlab.wcf.condition.ad + + com.woltlab.wcf.page + + diff --git a/wcfsetup/install/files/lib/system/condition/AbstractMultiSelectCondition.class.php b/wcfsetup/install/files/lib/system/condition/AbstractMultiSelectCondition.class.php index 5b996b706d..75ed722c08 100644 --- a/wcfsetup/install/files/lib/system/condition/AbstractMultiSelectCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/AbstractMultiSelectCondition.class.php @@ -16,25 +16,24 @@ use wcf\util\ArrayUtil; */ abstract class AbstractMultiSelectCondition extends AbstractSelectCondition { /** - * @see \wcf\system\condition\AbstractSelectCondition::$fieldValue + * selected values + * @var mixed[] */ - protected $fieldValue = array(); + protected $fieldValue = []; /** - * @see \wcf\system\condition\ICondition::getData() + * @inheritDoc */ public function getData() { if (!empty($this->fieldValue)) { - return array( - $this->fieldName => $this->fieldValue - ); + return [$this->fieldName => $this->fieldValue]; } return null; } /** - * @see \wcf\system\condition\AbstractSingleFieldCondition::getFieldElement() + * @inheritDoc */ protected function getFieldElement() { $options = $this->getOptions(); @@ -54,28 +53,28 @@ abstract class AbstractMultiSelectCondition extends AbstractSelectCondition { } /** - * @see \wcf\system\condition\AbstractSelectCondition::getOptionCode() + * @inheritDoc */ protected function getOptionCode($value, $label) { return ''; } /** - * @see \wcf\system\condition\ICondition::readFormParameters() + * @inheritDoc */ public function readFormParameters() { if (isset($_POST[$this->fieldName]) && is_array($_POST[$this->fieldName])) $this->fieldValue = ArrayUtil::toIntegerArray($_POST[$this->fieldName]); } /** - * @see \wcf\system\condition\ICondition::validate() + * @inheritDoc */ public function reset() { $this->fieldValue = array(); } /** - * @see \wcf\system\condition\ICondition::validate() + * @inheritDoc */ public function validate() { $options = $this->getOptions(); diff --git a/wcfsetup/install/files/lib/system/condition/MultiPageControllerCondition.class.php b/wcfsetup/install/files/lib/system/condition/MultiPageControllerCondition.class.php index 7940eb14f0..391331fb0b 100644 --- a/wcfsetup/install/files/lib/system/condition/MultiPageControllerCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/MultiPageControllerCondition.class.php @@ -10,58 +10,32 @@ use wcf\system\WCF; * Condition implementation for selecting multiple page controllers. * * @author Matthias Schmidt - * @copyright 2001-2015 WoltLab GmbH + * @copyright 2001-2016 WoltLab GmbH * @license GNU Lesser General Public License * @package com.woltlab.wcf * @subpackage system.condition * @category Community Framework + * @deprecated since 2.2 */ class MultiPageControllerCondition extends AbstractMultiSelectCondition implements IContentCondition { /** - * @see \wcf\system\condition\AbstractSingleFieldCondition::$label + * @inheritDoc */ - protected $description = 'wcf.global.multiSelect'; - - /** - * @see \wcf\system\condition\AbstractSelectCondition::$fieldName - */ - protected $fieldName = 'pageControllers'; - - /** - * @see \wcf\system\condition\AbstractSingleFieldCondition::$label - */ - protected $label = 'wcf.page.requestedPage'; - - /** - * @see \wcf\system\condition\AbstractSelectCondition::getOptionCode() - */ - protected function getOptionCode($value, $label) { - return ''; + protected function getFieldElement() { + return ''; } /** - * @see \wcf\system\condition\AbstractSelectCondition::getOptions() + * @inheritDoc */ protected function getOptions() { - return PageManager::getInstance()->getSelection(); + return []; } /** - * @see \wcf\system\condition\IContentCondition::showContent() + * @inheritDoc */ public function showContent(Condition $condition) { - $requestClassName = RequestHandler::getInstance()->getActiveRequest()->getClassName(); - $requestClassName = ltrim($requestClassName, '\\'); // remove leading backslash - $pageControllers = $condition->pageControllers; - foreach ($pageControllers as $objectTypeID) { - $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID); - if ($objectType === null) return false; - - if ($requestClassName == $objectType->className) { - return true; - } - } - return false; } } diff --git a/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php b/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php new file mode 100644 index 0000000000..f47d1db2b5 --- /dev/null +++ b/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php @@ -0,0 +1,86 @@ + + * @package com.woltlab.wcf + * @subpackage system.condition.page + * @category Community Framework + * @deprecated since 2.2 + */ +class MultiPageCondition extends AbstractMultiSelectCondition implements IContentCondition { + /** + * @inheritDoc + */ + protected $description = 'wcf.global.multiSelect'; + + /** + * @inheritDoc + */ + protected $fieldName = 'pageIDs'; + + /** + * @inheritDoc + */ + protected $label = 'wcf.page.requestedPage'; + + /** + * @inheritDoc + */ + protected function getFieldElement() { + $pageNodes = (new PageNodeTree())->getNodeList(); + + $fieldElement = '"; + + return $fieldElement; + } + + /** + * @inheritDoc + */ + protected function getOptions() { + return []; + } + + /** + * @inheritDoc + */ + public function showContent(Condition $condition) { + $pageID = RequestHandler::getInstance()->getActiveRequest()->getPageID(); + if ($pageID && $condition->pageIDs && is_array($condition->pageIDs)) { + return in_array($pageID, $condition->pageIDs); + } + + return false; + } + + /** + * @inheritDoc + */ + public function validate() { + foreach ($this->fieldValue as $value) { + if (PageCache::getInstance()->getPage($value) === null) { + $this->errorMessage = 'wcf.global.form.error.noValidSelection'; + + throw new UserInputException($this->fieldName, 'noValidSelection'); + } + } + } +} \ No newline at end of file diff --git a/wcfsetup/install/files/lib/system/request/Request.class.php b/wcfsetup/install/files/lib/system/request/Request.class.php index 31436fd3f6..3b3cbb3825 100644 --- a/wcfsetup/install/files/lib/system/request/Request.class.php +++ b/wcfsetup/install/files/lib/system/request/Request.class.php @@ -166,7 +166,7 @@ class Request { /** * Returns the current page id. * - * @return integer current page id or `0` if unknown + * @return integer current page id or `0` if unknown */ public function getPageID() { if ($this->pageID === null) {