Add checkbox to reverse logic of multi page condition selection
authorMatthias Schmidt <gravatronics@live.com>
Sun, 6 Jan 2019 09:44:01 +0000 (10:44 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Sun, 6 Jan 2019 09:44:01 +0000 (10:44 +0100)
Close #2683

syncTemplates.json
wcfsetup/install/files/acp/templates/__multiPageCondition.tpl [new file with mode: 0644]
wcfsetup/install/files/lib/system/condition/page/MultiPageCondition.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index 46da253f22aaa0f25374b22f8e214574f6362825..d49a5662b7e555e398194dd94a6c75d185dbb634 100644 (file)
@@ -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 (file)
index 0000000..bbe1235
--- /dev/null
@@ -0,0 +1,9 @@
+<dl>
+       <dt></dt>
+       <dd>
+               <label><input type="checkbox" id="{$fieldName}_reverseLogic" name="{$fieldName}_reverseLogic" value="1"{if $reverseLogic} checked{/if}> {lang}wcf.page.requestedPage.condition.reverseLogic{/lang}</label>
+               <small>{lang}wcf.page.requestedPage.condition.reverseLogic.description{/lang}</small>
+       </dd>
+</dl>
+
+{@$conditionHtml}
index ef352bd5ffc4b23317d308dbb8720b8d2825dfb7..f637b2a613576a2799d6c56777c22395e380e751 100644 (file)
@@ -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;
                        }
                }
                
index c1a338f5ec64828c1b3eeb968c71676097aec601..5b497ab9fa6e648d5d3eb098359fe71ad81629f8 100644 (file)
@@ -4085,6 +4085,8 @@ Dateianhänge:
                <item name="wcf.page.sidebar.left"><![CDATA[Linke Seitenleiste]]></item>
                <item name="wcf.page.sidebar.right"><![CDATA[Rechte Seitenleiste]]></item>
                <item name="wcf.page.breadcrumb"><![CDATA[Verlaufsnavigation]]></item>
+               <item name="wcf.page.requestedPage.condition.reverseLogic"><![CDATA[„Aufgerufene Seite“-Auswahl umkehren]]></item>
+               <item name="wcf.page.requestedPage.condition.reverseLogic.description"><![CDATA[Wenn ausgewählt, darf die aufgerufene Seite <strong>keine</strong> keine der unter „Aufgerufene Seite“ ausgewählten Seiten sein.]]></item>
        </category>
        <category name="wcf.paidSubscription">
                <item name="wcf.paidSubscription.availableSubscriptions"><![CDATA[Verfügbare Mitgliedschaften]]></item>
index 4fd437c4e55e60b805bc07352eabe34639ce728c..6b4d6938e90099ee1b2d4158531d0f51030b51f8 100644 (file)
@@ -4031,6 +4031,8 @@ Attachments:
                <item name="wcf.page.sidebar.left"><![CDATA[Left Sidebar]]></item>
                <item name="wcf.page.sidebar.right"><![CDATA[Right Sidebar]]></item>
                <item name="wcf.page.breadcrumb"><![CDATA[Breadcrumb]]></item>
+               <item name="wcf.page.requestedPage.condition.reverseLogic"><![CDATA[Reverse “Requested Page” selection]]></item>
+               <item name="wcf.page.requestedPage.condition.reverseLogic.description"><![CDATA[If selected, the requested page <strong>may not</strong> be one of the pages selected under “Requested Page”.]]></item>
        </category>
        <category name="wcf.acp.page">
                <item name="wcf.acp.page.add"><![CDATA[Add Page]]></item>