'; 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; Yii::trace('Input value: '.$start. ' -> output timestamp: '.$object->$attribute, 'ccwn.astaf.format'); $end = $this->compareValue; Yii::trace('Input value: '.$end. ' -> output timestamp: '.$this->compareValue, 'ccwn.astaf.format'); //a little php trick - safe than eval and easier than a big switch statement if (version_compare($start, $end, $this->operator)) { return; } else { $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)))); } } }