You are here

function date_views_argument_handler::init in Date 7

Same name and namespace in other branches
  1. 8 date_views/includes/date_views_argument_handler.inc \date_views_argument_handler::init()
  2. 7.3 date_views/includes/date_views_argument_handler.inc \date_views_argument_handler::init()
  3. 7.2 date_views/includes/date_views_argument_handler.inc \date_views_argument_handler::init()

Get granularity and use it to create the formula and a format for the results.

Overrides views_handler_argument::init

File

date_views/includes/date_views_argument_handler.inc, line 25
Date API views argument handler.

Class

date_views_argument_handler
Date API argument handler.

Code

function init(&$view, &$options) {
  parent::init($view, $options);

  // Identify the type of display we're using.
  $this->display_handler = $view->display_handler->definition['handler'];

  // Add a date handler to the display.
  $this->date_handler->granularity = $this->options['granularity'];
  $this->format = $this->date_handler
    ->views_formats($this->date_handler->granularity, 'display');
  $this->sql_format = $this->date_handler
    ->views_formats($this->date_handler->granularity, 'sql');
  if (empty($this->view->date_info)) {
    $this->view->date_info = new stdClass();
  }

  // Set the view range, do this only if not already set in case there are multiple date arguments.
  if (empty($this->view->date_info->min_allowed_year)) {
    $range = date_range_years($this->options['year_range']);
    $this->view->date_info->min_allowed_year = !empty($range) && is_array($range) ? $range[0] : variable_get('min_allowed_year', 100);
    $this->view->date_info->max_allowed_year = !empty($range) && is_array($range) ? $range[1] : variable_get('max_allowed_year', 4000);
  }
  if (empty($this->view->date_info->date_fields)) {
    $this->view->date_info->date_fields = array();
  }
  $this->view->date_info->date_fields = array_merge($this->view->date_info->date_fields, $this->options['date_fields']);
}