You are here

function calendar_views_query_alter in Calendar 7

Same name and namespace in other branches
  1. 5.2 calendar.module \calendar_views_query_alter()
  2. 5 calendar.module \calendar_views_query_alter()
  3. 6.2 includes/calendar.views.inc \calendar_views_query_alter()
  4. 7.2 includes/calendar.views.inc \calendar_views_query_alter()

Implementation of hook_views_query()

Handle the date_popup calendar goto date.

File

includes/calendar.views.inc, line 7
Creates calendar displays of Views results.

Code

function calendar_views_query_alter(&$view, &$query) {

  // Check if a new date has been selected and if so redirect.
  if (isset($_POST['calendar_goto']) && $_POST['view_name'] == $view->name) {
    $format = date_limit_format(variable_get('date_format_short', 'm/d/Y - H:i'), array(
      'year',
      'month',
      'day',
    ));
    $date = new DateObject($_POST['calendar_goto']['date'], date_default_timezone(), $format);
    switch ($_POST['calendar_type']) {
      case 'year':
        $arg = $date
          ->format('Y');
        break;
      case 'month':
        $arg = $date
          ->format('Y-m');
        break;
      case 'week':
        $arg = $date
          ->format('Y') . '-W' . date_pad(date_week($date));
        break;
      default:
        $arg = $date
          ->format('Y-m-d');
        break;
    }
    drupal_goto(str_replace($_POST['calendar_previous_arg'], $arg, $_POST['view_url']));
  }
}