You are here

function date_api_argument_handler::init in Date 6.2

Same name and namespace in other branches
  1. 6 date_api.views.inc \date_api_argument_handler::init()

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

File

includes/date_api_argument_handler.inc, line 24
Views argument handler.

Class

date_api_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.
  $date_handler = $this->date_handler;
  $date_handler->granularity = $this->options['granularity'];
  $this->format = $date_handler
    ->views_formats($date_handler->granularity, 'display');
  $this->sql_format = $date_handler
    ->views_formats($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']);
}