diff options
| author | Tristan Zur <tzur@ccwn.org> | 2012-05-16 18:14:03 +0200 |
|---|---|---|
| committer | Tristan Zur <tzur@ccwn.org> | 2012-05-16 18:14:03 +0200 |
| commit | 48f25c5eadd2a82a365b034a59b3cba4536a1e74 (patch) | |
| tree | 687b9437d4afe02d9595ec38b850cfc04bf10c27 | |
| parent | 13044f64bf51001ea0c9df5b1f6e7f16b6857151 (diff) | |
Bugfix: Die Datumsvalidierung funktionierte nicht, weil Vergleich auf
der Basis von Strings durchgeführt wurde
| -rw-r--r-- | protected/components/DateCompareValidator.php | 12 | ||||
| -rw-r--r-- | protected/components/DateRangeValidator.php | 4 | ||||
| -rw-r--r-- | protected/models/User.php | 2 |
3 files changed, 14 insertions, 4 deletions
diff --git a/protected/components/DateCompareValidator.php b/protected/components/DateCompareValidator.php index efa6763..13a4126 100644 --- a/protected/components/DateCompareValidator.php +++ b/protected/components/DateCompareValidator.php @@ -41,15 +41,23 @@ class DateCompareValidator extends CValidator { } $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'); + + $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)))); } diff --git a/protected/components/DateRangeValidator.php b/protected/components/DateRangeValidator.php index 8b963a8..529f185 100644 --- a/protected/components/DateRangeValidator.php +++ b/protected/components/DateRangeValidator.php @@ -10,10 +10,10 @@ class DateRangeValidator extends DateCompareValidator { $object->clearErrors($attribute); } $this->compareValue = $this->minDate; - $this->operator = '>'; + $this->operator = '>='; parent::validateAttribute($object, $attribute); $this->compareValue = $this->maxDate; - $this->operator = '<'; + $this->operator = '<='; parent::validateAttribute($object, $attribute); $addRangeError = false; diff --git a/protected/models/User.php b/protected/models/User.php index 13163c3..e0a5eeb 100644 --- a/protected/models/User.php +++ b/protected/models/User.php @@ -85,7 +85,9 @@ class User extends CActiveRecord $this->salt = $this->generateRandomKey(); } + if (!$this->checkPassword($this->password)) { $this->password = $this->encryptPassword($this->password); + } return parent::beforeSave(); } |
