function _signup_date_autoclose_sql in Signup 5.2
Same name in this branch
- 5.2 includes/date.5x-2.inc \_signup_date_autoclose_sql()
- 5.2 includes/date.5x-1.inc \_signup_date_autoclose_sql()
Same name and namespace in other branches
- 6.2 includes/date.inc \_signup_date_autoclose_sql()
- 6 includes/date.inc \_signup_date_autoclose_sql()
- 7 includes/date.inc \_signup_date_autoclose_sql()
Return value
Array of SQL clauses for cron auto-close query builder.
1 call to _signup_date_autoclose_sql()
- signup_autoclose_sql in includes/
scheduler.inc
File
- includes/
date.5x-2.inc, line 65 - Code required to support version 5.x-2.* of the CCK date field module.
Code
function _signup_date_autoclose_sql($content_type) {
// Get the date field information for this content type.
$field = signup_date_field($content_type);
$start_field = $field['database']['columns']['value']['column'];
// Figure out what TZ we want to do the date comparisons in.
$compare_tz = $field['tz_handling'] == 'none' ? date_default_timezone_name() : 'UTC';
// Get a DateAPI SQL handler class for this field.
$handler = _signup_date_sql_handler($field, $compare_tz);
// Compute a string representing the moment when signups should start
// auto-closing. If the field has no TZ handling, we just want to grab the
// current local time. If the field has any TZ handling, the date will be
// stored in the DB in UTC time, so start from current UTC time. Once we
// have the right current time, we need to add our close-in-advance offset.
$close_early_hours = variable_get('signup_close_early', 1);
$close_date = date_now($compare_tz);
date_modify($close_date, "+{$close_early_hours} hours");
$close_date_str = date_format($close_date, DATE_FORMAT_DATETIME);
// Use the DateAPI SQL handler to construct an appropriate WHERE clause.
// Make sure that the start time is <= NOW plus the auto-close window.
$where = $handler
->sql_where_date('DATE', $start_field, '<=', $close_date_str);
// Work-around evil code in date_api_sql that tries to workaround a views
// bug but breaks other callers. :(
$where = strtr($where, array(
'***SQLD***' => '%%d',
'***SQLS***' => '%%s',
));
// See what fields to SELECT.
$fields[] = $start_field;
if (isset($field['database']['columns']['timezone']['column'])) {
$fields[] = $field['database']['columns']['timezone']['column'];
}
$table = '{' . $field['database']['table'] . '}';
return array(
'fields' => $fields,
'joins' => array(
"INNER JOIN {$table} ON {$table}.vid = n.vid",
),
'where' => $where,
);
}