[TASK] Add condition negotiation to re-display fields properly and set the copyright...
authorOliver Eglseder <oliver.eglseder@in2code.de>
Thu, 3 Sep 2015 13:44:55 +0000 (15:44 +0200)
committerOliver Eglseder <oliver.eglseder@in2code.de>
Thu, 3 Sep 2015 13:44:55 +0000 (15:44 +0200)
Classes/Controller/ConditionController.php
Classes/Domain/Comparator/Comparator.php
Classes/Domain/Model/Condition.php
Classes/Domain/Model/ConditionContainer.php
Classes/Domain/Model/Rule.php
Classes/Domain/Repository/ConditionRepository.php
Classes/Domain/Validator/ConditionAwareValidator.php
Classes/UserFunc/GetPowermailFields.php
Classes/Utility/ArrayUtility.php
Resources/Public/JavaScript/PowermailCondition.js

index 2d6838b..3e7bb3b 100644 (file)
@@ -61,6 +61,8 @@ class ConditionController extends ActionController {
         */
        public function buildConditionAction() {
                $arguments = GeneralUtility::_GP('tx_powermail_pi1');
+               unset($arguments['__referrer']);
+               unset($arguments['__trustedProperties']);
                /** @var Form $form */
                $form = $this->formRepository->findByIdentifier($arguments['mail']['form']);
                /** @var Page $page */
index 141f76d..878ab01 100644 (file)
@@ -1,6 +1,32 @@
 <?php
 namespace In2code\PowermailCond\Domain\Comparator;
 
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2015 in2code.de
+ *  Alex Kellner <alexander.kellner@in2code.de>,
+ *  Oliver Eglseder <oliver.eglseder@in2code.de>
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
 use In2code\PowermailCond\Domain\Model\Rule;
 
 /**
index c610610..d1e2a67 100644 (file)
@@ -1,15 +1,12 @@
 <?php
 namespace In2code\PowermailCond\Domain\Model;
 
-use In2code\Powermail\Domain\Model\Field;
-use In2code\Powermail\Domain\Model\Form;
-use In2code\Powermail\Domain\Model\Page;
-use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
-
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2015 Alex Kellner <alexander.kellner@in2code.de>, in2code.de
+ *  (c) 2015 in2code.de
+ *  Alex Kellner <alexander.kellner@in2code.de>,
+ *  Oliver Eglseder <oliver.eglseder@in2code.de>
  *
  *  All rights reserved
  *
@@ -30,12 +27,17 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use In2code\Powermail\Domain\Model\Field;
+use In2code\Powermail\Domain\Model\Form;
+use In2code\Powermail\Domain\Model\Page;
+use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
+
 /**
  * Condition Model
  *
  * @package powermail_cond
  * @license http://www.gnu.org/licenses/lgpl.html
- *                     GNU Lesser General Public License, version 3 or later
+ *            GNU Lesser General Public License, version 3 or later
  */
 class Condition extends AbstractEntity {
 
@@ -254,24 +256,56 @@ class Condition extends AbstractEntity {
         * @return array
         */
        public function apply(Form $form, array $arguments) {
-               $affectedFieldMarker = '';
                /** @var Page $page */
                foreach ($form->getPages() as $page) {
                        /** @var Field $field */
                        foreach ($page->getFields() as $field) {
                                if ($field->getUid() === (int) $this->targetField) {
-                                       $affectedFieldMarker = $field->getMarker();
+                                       $arguments['todo'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
+                                               'action' => self::$actionNumberMap[$this->actions],
+                                               'matchingCondition' => $this->getUid(),
+                                       );
                                        break;
                                }
                        }
                }
-               if ($affectedFieldMarker !== '') {
-                       $arguments['todo'][$affectedFieldMarker] = self::$actionNumberMap[$this->actions];
+               return $arguments;
+       }
+
+       /**
+        * @param Form $form
+        * @param array $arguments
+        * @return array
+        */
+       public function negate(Form $form, array $arguments) {
+               /** @var Page $page */
+               foreach ($form->getPages() as $page) {
+                       /** @var Field $field */
+                       foreach ($page->getFields() as $field) {
+                               if ($field->getUid() === (int) $this->targetField) {
+                                       $arguments['todo'][$form->getUid()][$page->getUid()][$field->getMarker()] = array(
+                                               'action' => $this->getNegatedActionString(),
+                                               'matchingCondition' => $this->getUid(),
+                                       );
+                                       break;
+                               }
+                       }
                }
                return $arguments;
        }
 
        /**
+        * @return array
+        */
+       protected function getNegatedActionString() {
+               if ($this->actions === self::ACTION_HIDE) {
+                       return self::getActionNumberMap(self::ACTION_UN_HIDE);
+               } elseif($this->actions === self::ACTION_UN_HIDE) {
+                       return self::getActionNumberMap(self::ACTION_HIDE);
+               }
+       }
+
+       /**
         * @param int|NULL $action
         * @return array
         */
@@ -281,5 +315,4 @@ class Condition extends AbstractEntity {
                }
                return self::$actionNumberMap;
        }
-
 }
index 3b6764c..2b5d573 100644 (file)
@@ -1,6 +1,32 @@
 <?php
 namespace In2code\PowermailCond\Domain\Model;
 
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2015 in2code.de
+ *  Alex Kellner <alexander.kellner@in2code.de>,
+ *  Oliver Eglseder <oliver.eglseder@in2code.de>
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
 use In2code\Powermail\Domain\Model\Form;
 use TYPO3\CMS\Extbase\Persistence\Generic\QueryResult;
 
@@ -71,11 +97,13 @@ class ConditionContainer {
                        foreach ($this->conditions as $condition) {
                                if ($condition->applies($form)) {
                                        $newArguments = $condition->apply($form, $arguments);
-                                       if ($newArguments !== $arguments) {
-                                               $this->somethingChanged = TRUE;
-                                       }
-                                       $arguments = $newArguments;
+                               } else {
+                                       $newArguments = $condition->negate($form, $arguments);
+                               }
+                               if ($newArguments !== $arguments) {
+                                       $this->somethingChanged = TRUE;
                                }
+                               $arguments = $newArguments;
                        }
                }
                return $arguments;
index a5c4fd5..ae4ff02 100644 (file)
@@ -1,16 +1,12 @@
 <?php
 namespace In2code\PowermailCond\Domain\Model;
 
-use In2code\Powermail\Domain\Model\Field;
-use In2code\Powermail\Domain\Model\Form;
-use In2code\Powermail\Domain\Model\Page;
-use In2code\PowermailCond\Domain\Comparator\Comparator;
-use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
-
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2015 Alex Kellner <alexander.kellner@in2code.de>, in2code.de
+ *  (c) 2015 in2code.de
+ *  Alex Kellner <alexander.kellner@in2code.de>,
+ *  Oliver Eglseder <oliver.eglseder@in2code.de>
  *
  *  All rights reserved
  *
@@ -31,6 +27,12 @@ use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use In2code\Powermail\Domain\Model\Field;
+use In2code\Powermail\Domain\Model\Form;
+use In2code\Powermail\Domain\Model\Page;
+use In2code\PowermailCond\Domain\Comparator\Comparator;
+use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
+
 /**
  * Rule Model
  *
index d2fb524..ab2261a 100644 (file)
@@ -1,13 +1,13 @@
 <?php
 namespace In2code\PowermailCond\Domain\Repository;
 
-use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
-use TYPO3\CMS\Extbase\Persistence\Repository;
-
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2015 in2code GmbH <info@in2code.de>
+ *  (c) 2015 in2code.de
+ *  Alex Kellner <alexander.kellner@in2code.de>,
+ *  Oliver Eglseder <oliver.eglseder@in2code.de>
+ *
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -27,12 +27,15 @@ use TYPO3\CMS\Extbase\Persistence\Repository;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings;
+use TYPO3\CMS\Extbase\Persistence\Repository;
+
 /**
  * ConditionRepository
  *
  * @package powermail
  * @license http://www.gnu.org/licenses/lgpl.html
- *                     GNU Lesser General Public License, version 3 or later
+ *            GNU Lesser General Public License, version 3 or later
  */
 class ConditionRepository extends Repository {
 
@@ -48,4 +51,4 @@ class ConditionRepository extends Repository {
                $querySettings->setRespectSysLanguage(FALSE);
                $this->setDefaultQuerySettings($querySettings);
        }
-}
\ No newline at end of file
+}
index 9a7049b..9e4bf95 100644 (file)
@@ -1,6 +1,32 @@
 <?php
 namespace In2code\PowermailCond\Domain\Validator;
 
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2015 in2code.de
+ *  Alex Kellner <alexander.kellner@in2code.de>,
+ *  Oliver Eglseder <oliver.eglseder@in2code.de>
+ *
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
 use In2code\Powermail\Domain\Model\Field;
 use In2code\Powermail\Domain\Validator\InputValidator;
 use In2code\PowermailCond\Domain\Model\Condition;
index 0337367..387cdd7 100644 (file)
@@ -1,14 +1,12 @@
 <?php
 namespace In2code\PowermailCond\UserFunc;
 
-use In2code\PowermailCond\Utility\ArrayUtility;
-use TYPO3\CMS\Backend\Form\FormEngine;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 2015 Alex Kellner <alexander.kellner@in2code.de>, in2code.de
+ *  (c) 2015 in2code.de
+ *  Alex Kellner <alexander.kellner@in2code.de>,
+ *  Oliver Eglseder <oliver.eglseder@in2code.de>
  *
  *  All rights reserved
  *
@@ -29,6 +27,10 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use In2code\PowermailCond\Utility\ArrayUtility;
+use TYPO3\CMS\Backend\Form\FormEngine;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+
 /**
  * List powermail fields in Backend for powermail_cond rules
  *
@@ -256,4 +258,4 @@ class GetPowermailFields {
                $fieldTypes = $this->getDefaultFieldTypes();
                return ArrayUtility::getQuotedList($fieldTypes);
        }
-}
\ No newline at end of file
+}
index 44f9624..3ce1872 100644 (file)
@@ -1,13 +1,12 @@
 <?php
 namespace In2code\PowermailCond\Utility;
 
-use TYPO3\CMS\Extbase\Utility\ArrayUtility as ArrayUtilityExtbase;
-
 /***************************************************************
  *  Copyright notice
  *
  *  (c) 2015 in2code.de
- *  Alex Kellner <alexander.kellner@in2code.de>
+ *  Alex Kellner <alexander.kellner@in2code.de>,
+ *  Oliver Eglseder <oliver.eglseder@in2code.de>
  *
  *  All rights reserved
  *
@@ -28,6 +27,8 @@ use TYPO3\CMS\Extbase\Utility\ArrayUtility as ArrayUtilityExtbase;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use TYPO3\CMS\Extbase\Utility\ArrayUtility as ArrayUtilityExtbase;
+
 /**
  * Class ArrayUtility
  *
index 90f6c41..6a85941 100644 (file)
@@ -47,17 +47,21 @@ function PowermailCondition($formElement) {
                        success: function(data) {
                                console.log(data);
                                if (data.todo !== undefined) {
-                                       var form = $('.powermail_form_' + data.mail.form)
-                                       for (var key in data.todo) {
-                                               var input = form.find('#powermail_field_' + key);
-                                               if (data.todo[key] === 'hide') {
-                                                       input.val('');
-                                                       input.prop('disabled', true);
-                                                       input.closest('.powermail_fieldwrap').hide();
-                                               }
-                                               if (data.todo[key] === 'un_hide') {
-                                                       input.prop('disabled', false);
-                                                       input.closest('.powermail_fieldwrap').show();
+                                       for (var formUid in data.todo) {
+                                               var form = $('.powermail_form_' + formUid)
+                                               for (var pageUid in data.todo[formUid]) {
+                                                       for (var fieldMarker in data.todo[formUid][pageUid]) {
+                                                               var input = form.find('#powermail_field_' + fieldMarker);
+                                                               if (data.todo[formUid][pageUid][fieldMarker]['action'] === 'hide') {
+                                                                       input.val('');
+                                                                       input.prop('disabled', true);
+                                                                       input.closest('.powermail_fieldwrap').hide();
+                                                               }
+                                                               if (data.todo[formUid][pageUid][fieldMarker]['action'] === 'un_hide') {
+                                                                       input.prop('disabled', false);
+                                                                       input.closest('.powermail_fieldwrap').show();
+                                                               }
+                                                       }
                                                }
                                        }
                                }