You are here

function _date_views_argument_range_handler in Date 5

Same name and namespace in other branches
  1. 5.2 date/date_views.inc \_date_views_argument_range_handler()
2 calls to _date_views_argument_range_handler()
date_views_argument_range_handler in ./date.module
_date_views_timestamp_argument_range_handler in ./date_views.inc
Flexible date range argument handler

File

./date_views.inc, line 278

Code

function _date_views_argument_range_handler($op, &$query, $argtype, $arg = '', $field_type = 'iso') {
  static $format;
  include_once drupal_get_path('module', 'date_api') . '/date.inc';
  $name = explode(':', is_array($argtype) ? $argtype['type'] : $argtype);
  $tofield_name = trim($name[1]);
  $field_name = substr($tofield_name, 0, 3) == 'to|' ? substr($tofield_name, 3) : $tofield_name;
  if ($field_name == $tofield_name) {
    $value = 'value';
  }
  else {
    $value = 'value2';
  }
  $field = content_fields($field_name);
  $db_info = content_database_info($field);
  $value = $db_info['columns'][$value]['column'];
  $timezone = $db_info['columns']['timezone']['column'];
  $table = 'node_data_' . $field['field_name'];
  $offset = date_views_offset($field);
  switch ($op) {
    case 'summary':

      // in the summary operation, the arg contains the selected option
      $groupby = $arg;
      switch ($groupby) {
        case 'year':
          $format = 'Y';
          $fieldinfo['field'] = date_sql_concat(array(
            date_sql('YEAR', $table . '.' . $value, $field_type, $offset),
          ));
          break;
        case 'month':
          $format = 'F Y';
          $fieldinfo['field'] = date_sql_concat(array(
            date_sql('YEAR', $table . '.' . $value, $field_type),
            "'-'",
            date_sql_pad(date_sql('MONTH', $table . '.' . $value, $field_type, $offset)),
          ));
          break;
        case 'day':
          $format = 'F j Y';
          $fieldinfo['field'] = date_sql_concat(array(
            date_sql('YEAR', $table . '.' . $value, $field_type),
            "'-'",
            date_sql_pad(date_sql('MONTH', $table . '.' . $value, $field_type, $offset)),
            "'-'",
            date_sql_pad(date_sql('DAY', $table . '.' . $value, $field_type, $offset)),
          ));
          break;
        case 'hour':
          $format = 'F j Y - H';
          $fieldinfo['field'] = date_sql_concat(array(
            date_sql('YEAR', $table . '.' . $value, $field_type),
            "'-'",
            date_sql_pad(date_sql('MONTH', $table . '.' . $value, $field_type, $offset)),
            "'-'",
            date_sql_pad(date_sql('DAY', $table . '.' . $value, $field_type, $offset)),
            "'T'",
            date_sql_pad(date_sql('HOUR', $table . '.' . $value, $field_type, $offset)),
          ));
          break;
        case 'week':
          $format = 'F j Y (W)';
          $fieldinfo['field'] = date_sql_concat(array(
            date_sql('YEAR', $table . '.' . $value, $field_type, $offset),
            "'-W'",
            date_sql('WEEK', $table . '.' . $value, $field_type, $offset),
          ));
          break;
      }
      $fieldinfo['fieldname'] = 'range';
      $query
        ->ensure_table($table);
      $query
        ->add_field($value, $table);
      return $fieldinfo;
      break;
    case 'link':

      // links are created from date range groupings
      $time = $query->{$value} > '' ? $field_type == 'iso' ? date_iso2unix($query->{$value}) : $query->{$value} : '';
      return l(date_format_date($format, $time), $arg . '/' . $query->range);
    case 'sort':
      break;
    case 'filter':
      $range = date_views_date_range($arg, $field);
      $query
        ->ensure_table($table);
      $query
        ->add_field($value, $table);
      $query
        ->add_where(date_sql('DATE', $table . '.' . $value, $field_type, $offset) . ">='" . str_replace('T', ' ', $range[0]) . "'");
      $query
        ->add_where(date_sql('DATE', $table . '.' . $value, $field_type, $offset) . "<='" . str_replace('T', ' ', $range[1]) . "'");
      break;
    case 'title':
      $item = array(
        key($db_info['columns']) => $query,
      );
      return content_format($field, $item, 'default');
  }
}