You are here

function date_columns in Date 6.2

Same name and namespace in other branches
  1. 5.2 date/date_admin.inc \date_columns()
  2. 5 date_admin.inc \date_columns()
  3. 6 date/date_admin.inc \date_columns()

Callback for field columns.

2 calls to date_columns()
date_field_default_values in date/date_admin.inc
Helper function to create a field array with default values for a date $field, based on field type, widget type, and timezone handling.
_date_field_settings in date/date_admin.inc
Implementation of hook_field_settings().

File

date/date_admin.inc, line 296
Date administration code. Moved to separate file since there is a lot of code here that is not needed often.

Code

function date_columns($field) {
  if ($field['type'] == 'date') {
    $db_columns['value'] = array(
      'type' => 'varchar',
      'length' => 20,
      'not null' => FALSE,
      'sortable' => TRUE,
      'views' => TRUE,
    );
  }
  elseif ($field['type'] == 'datestamp') {
    $db_columns['value'] = array(
      'type' => 'int',
      'not null' => FALSE,
      'sortable' => TRUE,
      'views' => TRUE,
    );
  }
  elseif ($field['type'] == 'datetime') {
    $db_columns['value'] = array(
      'type' => 'datetime',
      'not null' => FALSE,
      'sortable' => TRUE,
      'views' => TRUE,
    );
  }

  // If a second date is needed for 'To date', just make a copy of the first one.
  if (!empty($field['todate'])) {
    $db_columns['value2'] = $db_columns['value'];

    // We don't want CCK to create additional columns, just the first.
    // We modify them our own way in views data.
    $db_columns['value2']['views'] = FALSE;
  }

  // timezone and offset columns are used only if date-specific dates are chosen.
  if (isset($field['tz_handling']) && $field['tz_handling'] == 'date') {
    $db_columns['timezone'] = array(
      'type' => 'varchar',
      'length' => 50,
      'not null' => FALSE,
      'sortable' => TRUE,
      'views' => FALSE,
    );
    $db_columns['offset'] = array(
      'type' => 'int',
      'not null' => FALSE,
      'sortable' => TRUE,
      'views' => FALSE,
    );
    if (!empty($field['todate'])) {
      $db_columns['offset2'] = array(
        'type' => 'int',
        'not null' => FALSE,
        'sortable' => TRUE,
        'views' => FALSE,
      );
    }
  }
  if (isset($field['repeat']) && $field['repeat'] == 1) {
    $db_columns['rrule'] = array(
      'type' => 'text',
      'not null' => FALSE,
      'sortable' => FALSE,
      'views' => FALSE,
    );
  }
  return $db_columns;
}