'; public $compareAttribute; public $compareValue; /** * Validates the attribute of the object. * If there is any error, the error message is added to the object. * @param CModel $object the object being validated * @param string $attribute the attribute being validated */ protected function validateAttribute($object, $attribute) { if ((empty($this->compareAttribute) && empty($this->compareValue)) || empty($this->operator)) { $this->addError($attribute, 'Invalid Parameters to dateCompare'); } $compareAttribute = $this->compareAttribute; $this->compareValue = empty($compareAttribute) ? $this->compareValue : $object->$compareAttribute;; if ($this->allowEmpty && empty($this->compareValue)) { return; } $start = $object->$attribute; $end = $this->compareValue; $pattern = '/[0-9]{2}\.[0-9]{2}\.[0-9]{4}\s[0-9]{2}:[0-9]{2}/'; if (preg_match($pattern, $start)) { $start = CDateTimeParser::parse($start, "dd.MM.yyyy HH:mm"); } if (preg_match($pattern, $end)) { $end = CDateTimeParser::parse($end, "dd.MM.yyyy HH:mm"); } //a little php trick - safe than eval and easier than a big switch statement if (version_compare($start, $end, $this->operator)) { Yii::trace('Input value: '.$start.' - compare value: '.$end.' - operator: '.$this->operator.' - result: OK', 'ccwn.astaf.date.validate'); return; } else { Yii::trace('Input value: '.$start.' - compare value: '.$end.' - operator: '.$this->operator.' - result: FAIL', 'ccwn.astaf.date.validate'); $message = $this->message !== null ? $this->message : Yii::t('astaf', 'The value of {attribute} ({value}) is not {operator} {compareAttribute} ({compareValue}).'); $this->addError($object, $attribute, $message, array('{operator}'=>$this->operator, '{compareValue}'=>$this->compareValue, '{value}'=>$object->$attribute, '{compareAttribute}'=>($object->getAttributeLabel($this->compareAttribute)))); } } }