You are here

function views_handler_sort_date in Views (for Drupal 7) 5

3 string references to 'views_handler_sort_date'
comment_views_tables in modules/views_comment.inc
This include file implements views functionality on behalf of comment.module
node_views_tables in modules/views_node.inc
This include file implements views functionality on behalf of node.module
statistics_views_tables in modules/views_statistics.inc
This include file implements views functionality on behalf of statistics.module

File

./views.module, line 1683

Code

function views_handler_sort_date($op, &$query, $sortinfo, $sort) {
  $timezone = _views_get_timezone();
  switch ($sort['options']) {
    case 'normal':
    default:
      $table = $sortinfo['table'];
      $field = $sortinfo['field'];
      break;
    case 'minute':
      $field = "DATE_FORMAT(FROM_UNIXTIME({$sortinfo['table']}.{$sortinfo['field']}), '%Y%m%%d%H%i')";
      break;
    case 'hour':
      $field = "DATE_FORMAT(FROM_UNIXTIME({$sortinfo['table']}.{$sortinfo['field']}), '%Y%m%%d%H')";
      break;
    case 'day':
      $field = "DATE_FORMAT(FROM_UNIXTIME({$sortinfo['table']}.{$sortinfo['field']}+{$timezone}), '%Y%m%%d')";
      break;
    case 'month':
      $field = "DATE_FORMAT(FROM_UNIXTIME({$sortinfo['table']}.{$sortinfo['field']}+{$timezone}), '%Y%m')";
      break;
    case 'year':
      $field = "DATE_FORMAT(FROM_UNIXTIME({$sortinfo['table']}.{$sortinfo['field']}+{$timezone}), '%Y')";
      break;
  }
  $alias = $as = $sortinfo['table'] . '_' . $sortinfo['field'];
  if (!$table) {
    $as .= '_orderby';
    $alias = $field;
  }

  //  $query->add_field($field, $table, $as);
  //  $query->orderby[] = "$alias $sort[sortorder]";
  $query
    ->add_orderby($table, $field, $sort['sortorder'], $as);
}