diff options
| author | Patrick Seeger <pseeger@ccwn.org> | 2012-04-30 10:18:11 +0200 |
|---|---|---|
| committer | Patrick Seeger <pseeger@ccwn.org> | 2012-04-30 10:18:11 +0200 |
| commit | acec2b5dc35302147f9a9c73d837dce2f3f9958e (patch) | |
| tree | 2f88a3a657a9211331e1e63e056a089189bd0dd2 /protected/components/DateRangeValidator.php | |
| parent | 56593a21209f3ce55fe66d303dbe01b8e081778b (diff) | |
| parent | 148a216bba21cec1cbe07b60b5191791e0016d6f (diff) | |
Merge branch 'master' of ssh://proxy.ccwn.org:9044/home/ccwn/git-repos/admin.astaf.de
Diffstat (limited to 'protected/components/DateRangeValidator.php')
| -rw-r--r-- | protected/components/DateRangeValidator.php | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/protected/components/DateRangeValidator.php b/protected/components/DateRangeValidator.php new file mode 100644 index 0000000..8b963a8 --- /dev/null +++ b/protected/components/DateRangeValidator.php @@ -0,0 +1,32 @@ +<?php +class DateRangeValidator extends DateCompareValidator { + public $minDate; + public $maxDate; + + protected function validateAttribute($object, $attribute) { + $errors = null; + if ($object->hasErrors($attribute)) { + $errors = $object->getErrors($attribute); + $object->clearErrors($attribute); + } + $this->compareValue = $this->minDate; + $this->operator = '>'; + parent::validateAttribute($object, $attribute); + $this->compareValue = $this->maxDate; + $this->operator = '<'; + parent::validateAttribute($object, $attribute); + + $addRangeError = false; + if ($object->hasErrors($attribute)) { + $object->clearErrors($attribute); + $addRangeError = true; + } + if (!empty($errors)) { + $object->addErrors($errors); + } + if ($addRangeError) { + $message = $this->message !== null ? $this->message : Yii::t('astaf', 'The value of {attribute} ({value}) is not between {minDate} and {maxDate}.'); + $this->addError($object, $attribute, $message, array('{operator}'=>$this->operator, '{minDate}'=>$this->minDate, '{value}'=>$object->$attribute, '{maxDate}'=>$this->maxDate)); + } + } +}
\ No newline at end of file |
