Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_form_validators_Equals | |
0.00% |
0 / 13 |
|
0.00% |
0 / 2 |
72 | |
0.00% |
0 / 1 |
| setOptions | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
30 | |||
| evaluate | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * compares two form elements |
| 27 | * possible options: |
| 28 | * 'reference' FormElement, the form element to compare to |
| 29 | * 'invert' boolean, validates only if values are not equal |
| 30 | * |
| 31 | * @access public |
| 32 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 33 | * @package tao |
| 34 | |
| 35 | */ |
| 36 | class tao_helpers_form_validators_Equals extends tao_helpers_form_Validator |
| 37 | { |
| 38 | // --- ASSOCIATIONS --- |
| 39 | |
| 40 | |
| 41 | // --- ATTRIBUTES --- |
| 42 | |
| 43 | // --- OPERATIONS --- |
| 44 | |
| 45 | public function setOptions(array $options) |
| 46 | { |
| 47 | parent::setOptions($options); |
| 48 | |
| 49 | if (!$this->hasOption('reference') || !$this->getOption('reference') instanceof tao_helpers_form_FormElement) { |
| 50 | throw new common_Exception("No FormElement provided as reference for Equals validator"); |
| 51 | } |
| 52 | $reference = $this->getOption('reference'); |
| 53 | if ($this->hasOption('invert') && $this->getOption('invert')) { |
| 54 | $this->setMessage(__('This should not equal %s', $reference->getDescription())); |
| 55 | } else { |
| 56 | $this->setMessage(__('This should equal %s', $reference->getDescription())); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * Short description of method evaluate |
| 63 | * |
| 64 | * @access public |
| 65 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 66 | * @param values |
| 67 | * @return boolean |
| 68 | */ |
| 69 | public function evaluate($values) |
| 70 | { |
| 71 | $returnValue = (bool) false; |
| 72 | |
| 73 | |
| 74 | $invert = $this->hasOption('invert') ? $this->getOption('invert') : false; |
| 75 | $reference = $this->getOption('reference'); |
| 76 | $equals = ($values == $reference->getRawValue()); |
| 77 | $returnValue = $invert ? !$equals : $equals; |
| 78 | |
| 79 | |
| 80 | return (bool) $returnValue; |
| 81 | } |
| 82 | } |