You are here

function calendar_views_query_alter in Calendar 6.2

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. 7 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) {
    require_once './' . drupal_get_path('module', 'date_api') . '/date_api_elements.inc';
    $format = date_limit_format(variable_get('date_format_short', 'm/d/Y - H:i'), array(
      'year',
      'month',
      'day',
    ));
    $date = date_convert_from_custom($_POST['calendar_goto']['date'], $format);
    switch ($_POST['calendar_type']) {
      case 'year':
        $arg = date_pad(date_part_extract($date, 'year'), 4);
        break;
      case 'month':
        $arg = date_pad(date_part_extract($date, 'year'), 4) . '-' . date_pad(date_part_extract($date, 'month'));
        break;
      case 'week':
        $arg = date_pad(date_part_extract($date, 'year'), 4) . '-W' . date_pad(date_week($date));
        break;
      default:
        $arg = date_pad(date_part_extract($date, 'year'), 4) . '-' . date_pad(date_part_extract($date, 'month')) . '-' . date_pad(date_part_extract($date, 'day'));
        break;
    }
    drupal_goto(str_replace($_POST['calendar_previous_arg'], $arg, $_POST['view_url']));
    exit;
  }
}