You are here

function _date_views_filters in Date 5

Same name and namespace in other branches
  1. 5.2 date/date_views.inc \_date_views_filters()

Views filters for Date fields.

1 call to _date_views_filters()
date_views_filters in ./date.module
Wrapper functions for views hooks.

File

./date_views.inc, line 6

Code

function _date_views_filters($field) {
  switch ($field['type']) {
    case 'date':
      $handler = 'date_views_filter_handler';
      $ymd_handler = 'date_views_handler_filter_ymd';
      break;
    case 'datestamp':
      $handler = 'date_views_timestamp_filter_handler';
      $ymd_handler = 'date_views_timestamp_handler_filter_ymd';
      break;
  }
  include_once drupal_get_path('module', 'date_api') . '/date.inc';
  $formats = date_get_formats($field);
  $format = $formats['input']['desc'];

  // use this to default to current time
  $current = array(
    '' => t('<all>'),
    'now' => t('now'),
  );
  $months = $current + drupal_map_assoc(range(1, 12), 'map_month');
  $days = $current + drupal_map_assoc(range(1, 31));
  $operator = array(
    '=' => t('is equal to'),
    '<>' => t('is not equal to'),
    '>' => t('greater than'),
    '>=' => t('greater than or equal to'),
    '<' => t('less than'),
    '<=' => t('less than or equal to'),
  );
  $filters = array(
    'default' => array(
      'name' => t('Date'),
      'operator' => $operator,
      'value' => date_views_handler_filter_date_value_form($field),
      'option' => 'string',
      'handler' => $handler,
      'type' => 'DATE',
      'extra' => array(
        'column' => 'value',
        'field' => $field,
      ),
      'help' => t('This filter allows events to be filtered by their date. Enter dates in the format: %format. Enter \'now\' to use the current time. You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now. If you have the jscalendar module from jstools installed, you can use a popup date picker here.', array(
        '%format' => $format,
      )),
    ),
    'year' => array(
      'name' => t('Year'),
      'operator' => $operator,
      'handler' => $handler,
      'option' => 'string',
      'type' => 'YEAR',
      'extra' => array(
        'column' => 'value',
        'field' => $field,
      ),
      'help' => t('Filter by year. Enter \'now\' to use the current year.  You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now. '),
    ),
    'month' => array(
      'name' => t('Month'),
      'operator' => $operator,
      'list' => $months,
      'list-type' => 'select',
      'handler' => $handler,
      'option' => 'string',
      'type' => 'MONTH',
      'extra' => array(
        'column' => 'value',
        'field' => $field,
      ),
      'help' => t('Filter by month. Enter \'now\' to use the current month.  You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now. '),
    ),
    'day' => array(
      'name' => t('Day'),
      'operator' => $operator,
      'list' => $days,
      'list-type' => 'select',
      'handler' => $handler,
      'option' => 'string',
      'type' => 'DAY',
      'extra' => array(
        'column' => 'value',
        'field' => $field,
      ),
      'help' => t('Filter by day. Enter \'now\' to use the current day.  You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now. '),
    ),
  );

  // Differentiate from and to dates with a prefix that is not likely to ever be used normally.
  if ($field['todate']) {
    $filters2 = array(
      'to|default' => array(
        'name' => t('To Date'),
        'operator' => $operator,
        'value' => date_views_handler_filter_date_value_form($field),
        'option' => 'string',
        'handler' => $handler,
        'type' => 'DATE',
        'extra' => array(
          'column' => 'value2',
          'field' => $field,
        ),
        'help' => t('This filter allows events to be filtered by their date. Enter dates in the format: %format. Enter \'now\' to use the current time. You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now. If you have the jscalendar module from jstools installed, you can use a popup date picker here.', array(
          '%format' => $format,
        )),
      ),
      'to|year' => array(
        'name' => t('To Year'),
        'operator' => $operator,
        'handler' => $handler,
        'option' => 'string',
        'type' => 'YEAR',
        'extra' => array(
          'column' => 'value2',
          'field' => $field,
        ),
        'help' => t('Filter by year. Enter \'now\' to use the current year.  You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now. '),
      ),
      'to|month' => array(
        'name' => t('To Month'),
        'operator' => $operator,
        'list' => $months,
        'list-type' => 'select',
        'handler' => $handler,
        'option' => 'string',
        'type' => 'MONTH',
        'extra' => array(
          'column' => 'value2',
          'field' => $field,
        ),
        'help' => t('Filter by month. Enter \'now\' to use the current month.  You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now. '),
      ),
      'to|day' => array(
        'name' => t('To Day'),
        'operator' => $operator,
        'list' => $days,
        'list-type' => 'select',
        'handler' => $handler,
        'option' => 'string',
        'type' => 'DAY',
        'extra' => array(
          'column' => 'value2',
          'field' => $field,
        ),
        'help' => t('Filter by day. Enter \'now\' to use the current day.  You may enter a delta (in seconds) to the option that will be added to the time; this is most useful when combined with now. '),
      ),
    );
    $filters += $filters2;
  }
  return $filters;
}