diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:42:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:42:35 +0000 |
commit | 18db984057b83ca4962c89b6b79bdce6a660b58f (patch) | |
tree | 2c9f23c086b4dfcb3e7eb2ec69210206b0782d3c /library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-businessprocess-18db984057b83ca4962c89b6b79bdce6a660b58f.tar.xz icingaweb2-module-businessprocess-18db984057b83ca4962c89b6b79bdce6a660b58f.zip |
Adding upstream version 2.4.0.upstream/2.4.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php')
-rw-r--r-- | library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php b/library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php new file mode 100644 index 0000000..9676de0 --- /dev/null +++ b/library/Businessprocess/Web/Form/Validator/NoDuplicateChildrenValidator.php @@ -0,0 +1,57 @@ +<?php + +namespace Icinga\Module\Businessprocess\Web\Form\Validator; + +use Icinga\Module\Businessprocess\BpConfig; +use Icinga\Module\Businessprocess\BpNode; +use Icinga\Module\Businessprocess\Forms\EditNodeForm; +use Icinga\Module\Businessprocess\Web\Form\QuickForm; +use Zend_Validate_Abstract; + +class NoDuplicateChildrenValidator extends Zend_Validate_Abstract +{ + const CHILD_FOUND = 'childFound'; + + /** @var QuickForm */ + protected $form; + + /** @var BpConfig */ + protected $bp; + + /** @var BpNode */ + protected $parent; + + /** @var string */ + protected $label; + + public function __construct(QuickForm $form, BpConfig $bp, BpNode $parent = null) + { + $this->form = $form; + $this->bp = $bp; + $this->parent = $parent; + + $this->_messageVariables['label'] = 'label'; + $this->_messageTemplates = [ + self::CHILD_FOUND => mt('businessprocess', '%label% is already defined in this process') + ]; + } + + public function isValid($value) + { + if ($this->parent === null) { + $found = $this->bp->hasRootNode($value); + } elseif ($this->form instanceof EditNodeForm && $this->form->getNode()->getName() === $value) { + $found = false; + } else { + $found = $this->parent->hasChild($value); + } + + if (! $found) { + return true; + } + + $this->label = $this->form->getElement('children')->getMultiOptions()[$value]; + $this->_error(self::CHILD_FOUND); + return false; + } +} |