123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <?php
- class ConditionalNotEmpty extends Zend_Validate_Abstract
- {
- const KEY_IS_EMPTY = 'keyIsEmpty';
- protected $_messageTemplates;
- protected $_fieldValues;
-
- public function __construct($fieldValues)
- {
- $this->_fieldValues = $fieldValues;
- $this->_messageTemplates = array(
- self::KEY_IS_EMPTY => _("Value is required and can't be empty")
- );
- }
-
- public function isValid($value, $context = null)
- {
- if ($value != "") {
- return true;
- }
- if (is_array($context)) {
- foreach ($this->_fieldValues as $fieldName=>$fieldValue) {
- if (!isset($context[$fieldName]) || $context[$fieldName] != $fieldValue) {
- return true;
- }
- }
- } elseif (is_string($context)) {
- if (!isset($context) || $context != $fieldValue) {
- return true;
- }
- }
- $this->_error(self::KEY_IS_EMPTY);
- return false;
- }
- }
|