function date_field_schema in Date 7.2
Same name and namespace in other branches
- 8 date.install \date_field_schema()
- 7.3 date.install \date_field_schema()
- 7 date.install \date_field_schema()
Implements hook_field_schema().
File
- ./
date.install, line 11 - Install, update and uninstall functions for the Date module.
Code
function date_field_schema($field) {
$db_columns = array();
switch ($field['type']) {
case 'datestamp':
$db_columns['value'] = array(
'type' => 'int',
'size' => 'big',
'not null' => FALSE,
'sortable' => TRUE,
'views' => TRUE,
);
break;
case 'datetime':
$db_columns['value'] = array(
'type' => 'datetime',
'mysql_type' => 'datetime',
'pgsql_type' => 'timestamp without time zone',
'sqlite_type' => 'varchar',
'sqlsrv_type' => 'smalldatetime',
'not null' => FALSE,
'sortable' => TRUE,
'views' => TRUE,
);
break;
default:
$db_columns['value'] = array(
'type' => 'varchar',
'length' => 20,
'not null' => FALSE,
'sortable' => TRUE,
'views' => TRUE,
);
}
// If a second date is needed for 'End date', make a copy of the first one.
if (!empty($field['settings']['todate'])) {
$db_columns['value2'] = $db_columns['value'];
// We don't want Field API to create additional columns, just the first.
// We modify them our own way in views data.
$db_columns['value2']['views'] = FALSE;
// Create a compound index on value and value2 and an index on value2.
$indexes = array(
'value' => array(
'value',
'value2',
),
'value2' => array(
'value2',
),
);
}
else {
// Otherwise just an index on value.
$indexes = array(
'value' => array(
'value',
),
);
}
// Timezone and offset columns are used only if date-specific dates are used.
if (isset($field['settings']['tz_handling']) && $field['settings']['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['settings']['todate'])) {
$db_columns['offset2'] = array(
'type' => 'int',
'not null' => FALSE,
'sortable' => TRUE,
'views' => FALSE,
);
}
}
if (isset($field['settings']['repeat']) && $field['settings']['repeat'] == 1) {
$db_columns['rrule'] = array(
'type' => 'text',
'not null' => FALSE,
'sortable' => FALSE,
'views' => FALSE,
);
}
return array(
'columns' => $db_columns,
'indexes' => $indexes,
);
}