function availability_calendars_handler_filter_availability::validate_valid_time in Availability Calendars 6.2
Validate that the time values convert to something usable.
File
Class
- availability_calendars_handler_filter_availability
- @class availability_calendars_handler_filter_availability Views handler to filter on availability.
Code
function validate_valid_time(&$form, $operator, $value) {
$operators = $this
->operators();
$required = FALSE;
if ($operator === NULL) {
// We are in exposed form validate.
$required = (bool) $this->options['expose']['required'];
$operator = array_key_exists('min', $form) ? 'between' : '=';
}
$now = format_date(time(), 'custom', 'Y-m-d');
if ($operators[$operator]['values'] == 1) {
// Note that the value can be an array with a date and time component.
$value = is_array($value) && array_key_exists('date', $value) ? $value['date'] : $value;
$this
->validate_valid_time_1($form, $value, $required, $now, t('Only future availability can be searched.'));
}
elseif ($operators[$operator]['values'] == 2) {
// Note that the min and max values can be an array with a date and time
// component or a string with a date and time component
// (yyyy-mm-dd hh:mm:ss).
$min_value = is_array($value['min']) && array_key_exists('date', $value['min']) ? $value['min']['date'] : substr($value['min'], 0, 10);
$min_valid = $this
->validate_valid_time_1($form['min'], $min_value, $required, $now, t('Only future availability can be searched.'));
$max_value = is_array($value['max']) && array_key_exists('date', $value['max']) ? $value['max']['date'] : substr($value['max'], 0, 10);
$required = $required || !empty($max_value);
$this
->validate_valid_time_1($form['max'], $max_value, $required, $min_valid ? $min_value : NULL, t('The departure date should be after the arrival date.'));
}
}