summaryrefslogtreecommitdiff
path: root/protected/components/DateRangeValidator.php
blob: 8b963a8db748edea0df60ebb272fdb874f1598cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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));
		}
	}
}