You are here

function _signup_date_autoclose_sql in Signup 6.2

Same name and namespace in other branches
  1. 5.2 includes/date.5x-2.inc \_signup_date_autoclose_sql()
  2. 5.2 includes/date.5x-1.inc \_signup_date_autoclose_sql()
  3. 6 includes/date.inc \_signup_date_autoclose_sql()
  4. 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.inc, line 344
Code to support using CCK date fields for time-based signup functionality.

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);

  // 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,
  );
}