Hi everyone,
I’m doing a specific validator to check my date and time, but i have some doubts about a good way to make a validator. Well, here is my current validator:
array('beginning_date, beginning_time, terminus_date, terminus_time', 'consistentDateAndTime')
public function consistentDateAndTime()
{
// Change this for data validation
if(!empty($this->beginning_date) && !empty($this->terminus_date))
{
$beginning_date = DateTimeFormatter::convertDate($this->beginning_date, 'br', 'us');
$terminus_date = DateTimeFormatter::convertDate($this->terminus_date, 'br', 'us');
if(strtotime($beginning_date) >= strtotime(date('Y-m-d')))
{
if(strtotime($beginning_date) > strtotime($terminus_date))
$this->addError('beginning_date', Yii::t('message', 'Beginning date cannot be greater than Terminus date'));
else if(strtotime($this->beginning_date) == strtotime($this->terminus_date))
{
if(strtotime($this->beginning_time) == strtotime($this->terminus_time))
{
$this->addError('beginning_time', Yii::t('message', 'Beginning time cannot be equal to Terminus time'));
}
else if(strtotime($this->beginning_time) > strtotime($this->terminus_time))
$this->addError('beginning_time', Yii::t('message', 'Beginning time cannot be greater than Terminus time'));
}
}
else
{
$this->addError('beginning_date', Yii::t('message',
'Cannot insert an unavailability in the past'));
}
}
}
1ª - What is the best way to get the attribute values?
2ª - I pretend call the data validation rule inside this validator (for check data format), how i can do that?
3ª - Considering I have four attributes, it’s possible get the four labels to put in error messages?
4ª - THE LAST ONE! I am using four attributes to compare them, but with ajax validation this give me four error messages (the same). What’s the best solution here? Split into multiple rules or put all in one?