From: Matthias Schmidt Date: Sun, 6 Jan 2019 09:44:01 +0000 (+0100) Subject: Add checkbox to reverse logic of multi page condition selection X-Git-Tag: 5.2.0_Alpha_1~370 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=988fc118d188eab587b5c3d13d026aa0c1e8b02f;p=GitHub%2FWoltLab%2FWCF.git Add checkbox to reverse logic of multi page condition selection Close #2683 --- diff --git a/syncTemplates.json b/syncTemplates.json index 46da253f22..d49a5662b7 100644 --- a/syncTemplates.json +++ b/syncTemplates.json @@ -22,6 +22,7 @@ "__itemListFormField", "__mediaSetCategoryDialog", "__multilineTextFormField", + "__multiPageCondition", "__multipleSelectionFormField", "__nonEmptyFormFieldDependency", "__numericFormField", diff --git a/wcfsetup/install/files/acp/templates/__multiPageCondition.tpl b/wcfsetup/install/files/acp/templates/__multiPageCondition.tpl new file mode 100644 index 0000000000..bbe1235467 --- /dev/null +++ b/wcfsetup/install/files/acp/templates/__multiPageCondition.tpl @@ -0,0 +1,9 @@ +
+
+
+ + {lang}wcf.page.requestedPage.condition.reverseLogic.description{/lang} +
+
+ +{@$conditionHtml} diff --git a/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php b/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php index ef352bd5ff..f637b2a613 100644 --- a/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php @@ -30,6 +30,27 @@ class MultiPageCondition extends AbstractMultiSelectCondition implements IConten */ protected $label = 'wcf.page.requestedPage'; + /** + * is `true` if the logic should be reversed, thus all of the non-selected pages fulfill the + * condition + * @var bool + */ + protected $reverseLogic = false; + + /** + * @inheritDoc + */ + public function getData() { + if (!empty($this->fieldValue)) { + return [ + $this->fieldName => $this->fieldValue, + $this->fieldName . '_reverseLogic' => $this->reverseLogic + ]; + } + + return null; + } + /** * @inheritDoc */ @@ -46,7 +67,12 @@ class MultiPageCondition extends AbstractMultiSelectCondition implements IConten * @inheritDoc */ public function getHTML() { - return AbstractSingleFieldCondition::getHTML(); + return WCF::getTPL()->fetch('__multiPageCondition', 'wcf', [ + 'condition' => $this, + 'conditionHtml' => AbstractSingleFieldCondition::getHTML(), + 'fieldName' => $this->fieldName, + 'reverseLogic' => $this->reverseLogic + ]); } /** @@ -56,6 +82,34 @@ class MultiPageCondition extends AbstractMultiSelectCondition implements IConten return []; } + /** + * @inheritDoc + */ + public function readFormParameters() { + parent::readFormParameters(); + + if (isset($_POST[$this->fieldName . '_reverseLogic'])) $this->reverseLogic = (bool)$this->fieldName . '_reverseLogic'; + } + + /** + * @inheritDoc + */ + public function reset() { + $this->fieldValue = []; + $this->reverseLogic = false; + } + + /** + * @inheritDoc + */ + public function setData(Condition $condition) { + parent::setData($condition); + + // backwards compatibility: if the reverse logic condition entry does not exist, + // the logic is not reversed + $this->reverseLogic = $condition->conditionData[$this->fieldName . '_reverseLogic'] ?? false; + } + /** * @inheritDoc */ @@ -63,8 +117,16 @@ class MultiPageCondition extends AbstractMultiSelectCondition implements IConten $activeRequest = RequestHandler::getInstance()->getActiveRequest(); if ($activeRequest !== null) { $pageID = $activeRequest->getPageID(); - if ($pageID && $condition->pageIDs && is_array($condition->pageIDs)) { - return in_array($pageID, $condition->pageIDs); + $pageIDs = $condition->{$this->fieldName}; + + if ($pageID && $condition->pageIDs && is_array($pageIDs)) { + $matchingPageID = in_array($pageID, $pageIDs); + + if ($condition->{$this->fieldName . '_reverseLogic'}) { + return !$matchingPageID; + } + + return $matchingPageID; } } diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index c1a338f5ec..5b497ab9fa 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -4085,6 +4085,8 @@ Dateianhänge: + + keine keine der unter „Aufgerufene Seite“ ausgewählten Seiten sein.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index 4fd437c4e5..6b4d6938e9 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -4031,6 +4031,8 @@ Attachments: + + may not be one of the pages selected under “Requested Page”.]]>