availability_calendar_handler_filter_sql_date.inc in Availability Calendars 7.5
File
views/availability_calendar_handler_filter_sql_date.inc
View source
<?php
class availability_calendar_handler_filter_sql_date extends views_handler_filter_date {
public function value_form(&$form, &$form_state) {
parent::value_form($form, $form_state);
if (isset($form['value']['type']['#options'])) {
$form['value']['type']['#options']['date'] = t('A date in any machine readable format. CCYY-MM-DD is preferred.');
$form['value']['type']['#options']['offset'] = t('An offset from the current date such as "!example1" or "!example2"', array(
'!example1' => '+1 day',
'!example2' => '-2 weeks',
));
}
}
public function op_between($field) {
if ($this->value['type'] === 'offset') {
$from = new DateTime('@' . REQUEST_TIME);
$from
->modify($this->value['min']);
$to = new DateTime('@' . REQUEST_TIME);
$to
->modify($this->value['max']);
}
else {
$from = new DateTime($this->value['min']);
$to = new DateTime($this->value['max']);
}
$from
->setTime(0, 0, 0);
$from = $from
->format(AC_ISODATE);
$to
->setTime(0, 0, 0);
$to = $to
->format(AC_ISODATE);
$this->query
->add_where_expression($this->options['group'], "{$field} {$this->operator} '{$from}' AND '{$to}'");
}
public function op_simple($field) {
if ($this->value['type'] === 'offset') {
$value = new DateTime('@' . REQUEST_TIME);
$value
->modify($this->value['value']);
}
else {
$value = new DateTime($this->value['min']);
}
$value
->setTime(0, 0, 0);
$value = $value
->format(AC_ISODATE);
$this->query
->add_where_expression($this->options['group'], "{$field} {$this->operator} '{$value}'");
}
}