function calendar_build_field_query in Calendar 5
Same name and namespace in other branches
- 5.2 calendar.inc \calendar_build_field_query()
Build a filtering query for an individual date field
Parameters
object $query - the query object:
array $field - the view field array:
1 call to calendar_build_field_query()
- calendar_build_filter in ./
calendar.module - Compile the filter query for this view.
File
- ./
calendar.module, line 728 - Adds calendar filtering and displays to Views.
Code
function calendar_build_field_query(&$query, $field) {
$queries = array();
$fields = calendar_fields();
$field_name = $field['field'];
$this_field = $fields[$field_name];
$view_fields[] = $field_name;
if (array_key_exists($field_name, $fields)) {
$query
->ensure_table($this_field['table'], $this_field['table']);
$tz_handling = $this_field['tz_handling'];
$offset_field = $this_field['offset_field'];
$field_type = strstr($this_field['type'], 'string') ? 'iso' : 'int';
// get appropriate timezone offset
switch ($tz_handling) {
case 'user':
global $user;
$start_offset = $end_offset = $user->timezone;
break;
case 'none':
case 'GMT':
$start_offset = $end_offset = 0;
break;
case 'date':
$start_offset = $end_offset = $offset_field;
break;
case 'event':
// event-specific timezones won't work right here because no offset is stored in the database
// the best we can do is treat it the same as if it was a site timezone
default:
$start_offset = $end_offset = variable_get('date_default_timezone', 0);
break;
}
// handling for from and to date ranges
if ($this_field['timestamp_fromto']) {
$queries[] = "(" . date_sql('DATE', $this_field['timestamp_fromto'][1], $field_type, $end_offset) . " >='" . $query->min . "' AND " . date_sql('DATE', $this_field['timestamp_fromto'][0], $field_type, $start_offset) . " <='" . $query->max . "')";
$event_field_processed = TRUE;
}
elseif ($this_field['string_fromto']) {
$queries[] = "(" . date_sql('DATE', $this_field['string_fromto'][1], $field_type, $end_offset) . " >='" . $query->min . "' AND " . date_sql('DATE', $this_field['string_fromto'][0], $field_type, $start_offset) . " <='" . $query->max . "')";
$event_field_processed = TRUE;
}
elseif ($this_field['type'] == 'cck_string') {
$queries[] = "(" . date_sql('DATE', $this_field['fullname'], $field_type, $start_offset) . ">='" . $query->min . "' AND " . date_sql('DATE', $field['fullname'], $field_type, $end_offset) . "<='" . $query->max . "')";
}
elseif (strstr($this_field['type'], 'timestamp')) {
$queries[] = "(" . date_sql('DATE', $this_field['fullname'], $field_type, $start_offset) . ">='" . $query->min . "' AND " . date_sql('DATE', $this_field['fullname'], $field_type, $end_offset) . "<='" . $query->max . "')";
}
}
return $queries;
}