You are here

function calendar_plugin_style::query in Calendar 7

Same name and namespace in other branches
  1. 6.2 includes/calendar_plugin_style.inc \calendar_plugin_style::query()
  2. 7.2 includes/calendar_plugin_style.inc \calendar_plugin_style::query()

Add anything to the query that we might need to.

Overrides views_plugin_style::query

File

includes/calendar_plugin_style.inc, line 115
Views navigation style plugin for the Calendar module.

Class

calendar_plugin_style
Style plugin to create the calendar navigation and links.

Code

function query() {
  module_load_include('inc', 'date_api', 'date_api_sql');

  //$this->view->date_info->display_types = $this->display_types();
  $style_options = $this->view->style_plugin->options;

  // Evaluate our argument values and figure out which
  // calendar display we need to create.
  $i = 0;
  foreach ($this->view->argument as $id => $argument) {
    if ($argument->field == 'date_argument') {

      // TODO Decide if we want to provide a date here or not.
      // Adding this now is to prevent fatal errors later if the
      // view is used in unexpected ways without a date being set.
      if (empty($argument->min_date)) {
        $value = $argument
          ->get_default_argument();
        $range = $argument->date_handler
          ->arg_range($value);
        $argument->min_date = $range[0];
        $argument->max_date = $range[1];
      }
      $this->view->date_info->granularity = !empty($argument->granularity) ? $argument->granularity : $argument->options['granularity'];
      $this->view->date_info->date_arg = !empty($this->view->args) ? $this->view->args[$argument->position] : '';
      $this->view->date_info->date_arg_pos = $i;
      $this->view->date_info->year = isset($argument->year) ? $argument->year : NULL;
      $this->view->date_info->month = isset($argument->month) ? $argument->month : NULL;
      $this->view->date_info->day = isset($argument->day) ? $argument->day : NULL;
      $this->view->date_info->week = isset($argument->week) ? $argument->week : NULL;
      $this->view->date_info->min_date = $argument->min_date;
      $this->view->date_info->max_date = $argument->max_date;
      $this->view->date_info->min_date_date = date_format($this->view->date_info->min_date, DATE_FORMAT_DATE);
      $this->view->date_info->max_date_date = date_format($this->view->date_info->max_date, DATE_FORMAT_DATE);
      $this->view->date_info->forbid = isset($argument->forbid) ? $argument->forbid : FALSE;

      // Stop after the first date argument, if there is more than one.
      break;
    }
    $i++;
  }
  $this->view->date_info->display_types = $this
    ->display_types();
  $keys = drupal_map_assoc(array_keys(calendar_display_types()));
  $this->view->date_info->calendar_display = $keys[$this->view->date_info->granularity];

  // bring the node type into the query so we can use it in the theme
  $this->view->query
    ->add_field('node', 'type');
  parent::query();
}