You are here

function signup_admin_form_sql in Signup 6.2

Same name and namespace in other branches
  1. 5.2 signup.module \signup_admin_form_sql()
  2. 6 includes/admin.signup_administration.inc \signup_admin_form_sql()
1 call to signup_admin_form_sql()
signup_admin_form in includes/admin.signup_administration.inc
Form builder for the main form on the signup administration page.

File

includes/admin.signup_administration.inc, line 142
Code related to the Signup administration page (admin/content/signup).

Code

function signup_admin_form_sql() {
  $admin_common_sql = array(
    'primary' => '{node} n',
    'fields' => array(
      'n.nid',
      'n.title',
      'n.type',
      's.status AS signup_status',
      'COUNT(s_l.nid) AS signup_total',
      's.close_signup_limit AS signup_close_signup_limit',
    ),
    'group_by' => array(
      'n.nid',
      'n.title',
      'signup_status',
      'signup_close_signup_limit',
    ),
    'joins' => array(
      'INNER JOIN {signup} s ON s.nid = n.nid',
      'LEFT JOIN {signup_log} s_l ON s.nid = s_l.nid',
    ),
  );
  $type = $_SESSION['signup_status_filter'];
  if ($type == 'open') {
    $filter_status = 1;
  }
  elseif ($type == 'closed') {
    $filter_status = 0;
  }
  if (isset($filter_status)) {
    $admin_common_sql['where'] = array(
      "s.status = {$filter_status}",
    );
  }

  // Get the right query elements from the currently installed backend
  $admin_sql = array();
  foreach (signup_content_types() as $type) {
    $admin_sql = array_merge_recursive($admin_sql, signup_admin_sql($type));
  }

  // Build the main query.
  $sql = _signup_build_query($admin_common_sql, $admin_sql);

  // Construct the proper pager query using just the WHERE clauses (if any).
  $all_fragments = array_merge_recursive($admin_common_sql, $admin_sql);
  $sql_count = "SELECT COUNT(s.nid) FROM {signup} s";
  if (!empty($all_fragments['where'])) {
    $sql_count .= ' WHERE ' . implode(' AND ', $all_fragments['where']);
  }
  return array(
    db_rewrite_sql($sql),
    db_rewrite_sql($sql_count, 's'),
  );
}