View source
<?php
class availability_calendar_handler_argument_availability extends views_handler_argument_date {
protected $date_handler;
protected $date_parts;
protected $min_date;
protected $max_date;
public function init(&$view, &$options) {
parent::init($view, $options);
if (module_exists('date_api')) {
module_load_include('inc', 'date_api', 'date_api_sql');
$this->date_handler = new date_sql_handler(DATE_UNIX);
}
}
public function option_definition() {
$options = parent::option_definition();
$options['end_date_exclusive'] = array(
'default' => $this->definition['allocation_type'] == AC_ALLOCATION_TYPE_OVERNIGHT,
'bool' => TRUE,
);
return $options;
}
public function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
$form['end_date_exclusive'] = array(
'#type' => 'checkbox',
'#title' => t('Exclude end date'),
'#description' => t('If selected, the end date itself will not be taken into account when filtering on availability, typical for overnight rental. This setting will be ignored if only a single date is passed in.'),
'#default_value' => !empty($this->options['end_date_exclusive']),
);
}
public function query($group_by = FALSE) {
if (empty($this->argument)) {
return;
}
if (module_exists('date_api')) {
$this->date_parts = $this->date_handler
->arg_parts($this->argument);
$this->min_date = new DateTime($this->date_handler
->complete_date($this->date_parts[0]['date'], 'min'));
$this->max_date = count($this->date_parts) > 1 ? new DateTime($this->date_handler
->complete_date($this->date_parts[1]['date'], 'min')) : clone $this->min_date;
}
else {
$this->date_parts = explode('--', $this->argument);
$this->min_date = availability_calendar_parse_iso_date($this->date_parts[0]);
$this->max_date = count($this->date_parts) > 1 ? availability_calendar_parse_iso_date($this->date_parts[1]) : clone $this->min_date;
}
if (!empty($this->options['end_date_exclusive']) && $this->min_date < $this->max_date) {
$this->max_date
->modify('-1 day');
}
$this
->ensure_my_table();
module_load_include('inc', 'availability_calendar', 'availability_calendar');
availability_calendar_query_available($this->query, $this->table_alias, $this->real_field, $this->min_date, $this->max_date, $this->definition['default_state']);
}
public function get_sort_name() {
return t('Numeric', array(), array(
'context' => 'Sort order',
));
}
}