You are here

function signup_cancel_signup in Signup 7

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

Cancel the given signup.

Parameters

stdClass $signup: Information about the signup to cancel. Can be either the integer signup ID (sid), or a full object of data about the signup (a complete row from the {signup_log} table.

bool $notify_user: When set to TRUE, a confirmation message is displayed via drupal_set_message().

3 calls to signup_cancel_signup()
signup_cancel_action in ./signup.module
Action callback to cancel a given signup.
signup_cancel_link_confirm_form_submit in includes/signup_cancel.inc
@todo Please document this function.
signup_user_cancel in ./signup.module
Implements hook_user_cancel().

File

./signup.module, line 1168
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_cancel_signup($signup, $notify_user = TRUE) {

  // If we only have a numeric sid argument, load the full signup object.
  if (is_numeric($signup)) {
    $query = db_query('SELECT * FROM {signup_log} WHERE sid = :sid', array(
      ':sid' => $signup,
    ));
    $signup = $query
      ->fetchObject();
  }
  $node = node_load($signup->nid);
  $effective_total_changed = FALSE;
  $node->signup_total--;
  if (!empty($signup->count_towards_limit)) {
    $node->signup_effective_total -= $signup->count_towards_limit;
    $effective_total_changed = TRUE;
  }

  // Invoke hook_signup_cancel().
  module_invoke_all('signup_cancel', $signup, $node);

  // Delete the record from the {signup_log} table.
  // TODO Please review the conversion of this statement to the D7 database API syntax.

  /* db_query('DELETE FROM {signup_log} WHERE sid = %d', $signup->sid) */
  db_delete('signup_log')
    ->condition('sid', $signup->sid)
    ->execute();
  if ($notify_user) {
    drupal_set_message(t('Signup to !title cancelled.', array(
      '!title' => l($node->title, "node/{$node->nid}"),
    )));
  }
  if ($effective_total_changed) {

    // See if signups should be re-opened if the total dropped below the limit.
    _signup_check_limit($node, 'total');
  }
}