You are here

function signup_user in Signup 6

Same name and namespace in other branches
  1. 5.2 signup.module \signup_user()
  2. 5 signup.module \signup_user()
  3. 6.2 signup.module \signup_user()

Implementation of hook_user().

When a user is deleted, cancel all of that user's signups to remove all instances of that user from the {signup_log} table, free up space in nodes with signup limits, etc.

Related topics

File

./signup.module, line 631
The Signup module (http://drupal.org/project/signup) manages replies to nodes. In particular, it's good for event management. Signup supports sending reminder emails and automatically closing signups for nodes with a start time, via the Event…

Code

function signup_user($type, &$edit, &$account, $category = NULL) {
  switch ($type) {
    case 'register':

      // Get a list of nodes that should appear on the user registration form.
      $query = db_query(db_rewrite_sql("SELECT n.nid FROM {node} n INNER JOIN {signup} s on n.nid = s.nid WHERE s.user_reg_form = 1 AND s.status = 1 AND n.status = 1"));
      while ($result = db_fetch_object($query)) {
        $nids[] = $result->nid;
      }

      // Allow other modules to alter the list of nids.
      drupal_alter('signup_user_reg_nids', $nids);

      // If there is at least one node, add the Signup fieldset.
      if (!empty($nids)) {
        $form['signup'] = array(
          '#type' => 'fieldset',
          '#title' => t('Event signup'),
          '#tree' => TRUE,
          '#description' => t('You will be automatically signed up once your account is created.'),
        );

        // Each node gets a checkbox.
        foreach ($nids as $nid) {
          $node = node_load($nid);
          $form['signup'][$nid] = array(
            '#type' => 'checkbox',
            '#title' => theme('signup_node_title', $node),
            '#default_value' => 0,
          );
        }
        return $form;
      }
      break;
    case 'delete':
      $uids = array();
      if (is_array($edit['accounts'])) {

        // A multi-user delete from Admin > User management > Users.
        $uids = $edit['accounts'];
      }
      else {

        // A single-user delete from the edit tab on the user's profile.
        if (!empty($account->uid)) {
          $uids[] = $account->uid;
        }
      }
      if (!empty($uids) && is_array($uids)) {
        foreach ($uids as $uid) {
          $query = db_query("SELECT * FROM {signup_log} WHERE uid = %d", $uid);
          while ($signup = db_fetch_object($query)) {
            signup_cancel_signup($signup);
          }
        }
      }
      break;
    case 'insert':

      // Create signups for new users who signed up via
      // the user registration form.
      if (!empty($edit['signup'])) {
        foreach ($edit['signup'] as $nid => $value) {
          if ($value) {
            $signup_form = array();
            $signup_form['nid'] = $nid;
            $signup_form['uid'] = $account->uid;
            signup_sign_up_user($signup_form, TRUE);
          }
        }
      }
  }
}