function _calendar_fields in Calendar 5.2
Same name and namespace in other branches
- 5 calendar_admin.inc \_calendar_fields()
Identify all potential date/timestamp fields.
Return value
array with fieldname, type, and table
1 call to _calendar_fields()
- calendar_fields in ./
calendar.module - Identify all potential date/timestamp fields
File
- ./
calendar_admin.inc, line 113 - This file contains administrative functions used only when setting up the calendar and views_hooks() that are called infrequently and cached. No need to parse all this code the rest of the time.
Code
function _calendar_fields() {
$cid = 'calendar_fields';
cache_clear_all($cid, 'cache_views');
$delta = 0;
$event_fields_processed = array();
views_load_cache();
foreach (_views_get_fields() as $name => $val) {
$fromto = array();
$tmp = explode('.', $name);
$field_name = $val['content_field']['field_name'] ? $val['content_field']['field_name'] : $tmp[1];
// We need to treat event_start and event_end as a single date, all other fields have
// the same field_name for both start and end dates.
$processed_name = strstr($field_name, 'event_') ? 'event' : $field_name;
$type = '';
// for cck fields, get the date type
if ($val['content_field']['type'] == 'date' || $val['content_field']['type'] == 'datestamp') {
$type = $val['content_field']['type'] == 'date' ? 'cck_string' : 'cck_timestamp';
}
elseif ($val['handler'] == views_handler_field_dates()) {
$type = 'timestamp';
}
// Don't do anything if this is not a date field we can handle.
if ($type && $name != 'event.event_start' && $name != 'event.event_end') {
$fromto = array(
$name,
$name,
);
$tz_handling = 'site';
$related_fields = array();
$timezone_field = '';
$delta_field = '';
// dates with from and to dates need to handle both fields as one
// add the from and to dates to the first one found and ignore the second
// Handling for content field dates
if ($val['content_field']['tz_handling']) {
$tz_handling = $val['content_field']['tz_handling'];
if ($tz_handling == 'date') {
$offset_field = $val['table'] . '.' . $val['content_db_info']['columns']['offset']['column'];
$timezone_field = $val['table'] . '.' . $field_name . '_timezone';
$related_fields = array(
$val['table'] . '.' . $field_name . '_value',
$val['table'] . '.' . $field_name . '_value2',
$val['table'] . '.' . $field_name . '_timezone',
$val['table'] . '.' . $field_name . '_offset',
$val['table'] . '.' . $field_name . '_offset2',
);
}
else {
$related_fields = array(
$val['table'] . '.' . $field_name . '_value',
$val['table'] . '.' . $field_name . '_value2',
);
}
if (!empty($val['content_field']['repeat'])) {
$related_fields[] = $val['table'] . '.' . $field_name . '_rrule';
}
}
// Get the delta value into the query.
if (!empty($val['content_field']['multiple'])) {
array_push($related_fields, $val['table'] . '.delta');
$delta_field = $val['table'] . '_delta';
}
// Handling for cck fromto dates
if (!in_array($processed_name, $event_fields_processed)) {
switch ($val['content_field']['type']) {
case 'datestamp':
$fromto = array(
$val['table'] . '.' . $field_name . '_value',
$val['table'] . '.' . ($val['content_field']['todate'] ? $field_name . '_value2' : $field_name . '_value'),
);
break;
case 'date':
$fromto = array(
$val['table'] . '.' . $field_name . '_value',
$val['table'] . '.' . ($val['content_field']['todate'] ? $field_name . '_value2' : $field_name . '_value'),
);
break;
}
$event_fields_processed[] = $processed_name;
}
// skip this step on second occurrence of fromto date fields, if more than one exists in view
// cck fields append a column name to the field, others do not
// need a real field_name with no column name appended for cck date formatters
switch ($type) {
case 'cck_string':
$sql_type = DATE_ISO;
break;
case 'cck_datetime':
$sql_type = DATE_DATETIME;
break;
default:
$sql_type = DATE_UNIX;
break;
}
// skip this step on second occurrence of fromto date fields, if more than one exists in view
if (!in_array($processed_name, $event_fields_processed) || $fromto) {
// cck fields append a column name to the field, others do not
// need a real field_name with no column name appended for cck date formatters
$fields[$tmp[1]] = array(
'type' => $type,
'sql_type' => $sql_type,
'delta' => $delta,
'label' => $val['name'],
'fullname' => $name,
'table' => $tmp[0],
'field' => $tmp[1],
'field_name' => $field_name,
'query_name' => str_replace('.', '_', $name),
'fromto' => $fromto,
'tz_handling' => $tz_handling,
'offset_field' => $offset_field,
'timezone_field' => $timezone_field,
'delta_field' => $delta_field,
'related_fields' => $related_fields,
);
}
}
}
//cache_set($cid, 'cache_views', serialize($fields));
return $fields;
}