You are here

function node_registration_cancel_action in Node registration 7

Action handler: cancel registration.

1 call to node_registration_cancel_action()
node_registration_cancel_confirm_submit in includes/node_registration.forms.inc
Execute node registration cancellation.

File

includes/node_registration.actions.inc, line 142
Actions, triggers and rules -- callbacks, definitions and hooks.

Code

function node_registration_cancel_action($registration, $force = FALSE) {
  $node = node_load($registration->nid);
  $settings = $node->registration;

  // Cancel.
  $registration->cancelled = REQUEST_TIME;
  if (TRUE === $force) {
    $registration
      ->save();
  }
  $token_data = array(
    'node' => $node,
    'node-registration' => $registration,
  );

  // Send e-mail to registree.
  if ($settings->send_cancel_mail_to_registree) {
    $subject = $settings->cancel_mail_to_registree_subject;
    $message = $settings->cancel_mail_to_registree_body;
    $options = array(
      'bcc' => token_replace($settings->cancel_mail_to_registree_bcc, $token_data, array(
        'clear' => TRUE,
      )),
    );
    node_registration_send_broadcast($node, $subject, $message, array(
      $registration,
    ), $options);
  }

  // Send e-mail to admin.
  if ($settings->send_cancel_mail_to_admin) {
    $subject = token_replace($settings->cancel_mail_to_admin_subject, $token_data);
    $message = token_replace($settings->cancel_mail_to_admin_body, $token_data);
    $recipients = token_replace($settings->cancel_mail_to_admin_recipients, $token_data);
    _node_registration_send_email($recipients, $subject, $message, $token_data);
  }

  // Log cancellation.
  watchdog('node_registration', 'Registration %id cancelled.', array(
    '%id' => $registration->registration_id,
  ));
}