You are here

function node_registration_node_registration_update in Node registration 7

Implements hook_node_registration_update().

File

./node_registration.module, line 1284

Code

function node_registration_node_registration_update($registration) {
  $now_cancelled = (bool) $registration->cancelled;
  $was_cancelled = (bool) $registration->original->cancelled;

  // Cancelled status changed.
  if ($now_cancelled != $was_cancelled) {
    $action = $now_cancelled ? 'cancel' : 'uncancel';
    $node = $registration->node ?: node_load($registration->nid);
    $new_waitinglist = _node_registration_reset_waitinglist($node);
  }
  $now_waitinglist = (bool) $registration->waitinglist;
  $was_waitinglist = (bool) $registration->original->waitinglist;

  // Waitinglist status changed.
  if ($now_waitinglist != $was_waitinglist) {
    $action = $now_waitinglist ? 'waitinglist' : 'unwaitinglist';
    $node = $registration->node ?: node_load($registration->nid);
    $settings = $node->registration;

    // Moved from waitinglist to normal.
    if (!$now_waitinglist) {
      $send = $settings->send_unwaitinglist_mail_to_registree;
      $subject = $settings->unwaitinglist_mail_to_registree_subject;
      $message = $settings->unwaitinglist_mail_to_registree_body;

      // Send mail to registree
      if ($send && $subject && $message) {
        $registration->node = $node;
        node_registration_send_broadcast($node, $subject, $message, array(
          $registration,
        ));
      }
    }
  }
}