You are here

function _node_registration_reset_waitinglist in Node registration 7

Reset waitinglist flags for an event.

2 calls to _node_registration_reset_waitinglist()
node_registration_form_submit in includes/node_registration.forms.inc
Submit handler for node_registration_form().
node_registration_node_registration_update in ./node_registration.module
Implements hook_node_registration_update().

File

includes/node_registration.api.inc, line 74
Registration API functions.

Code

function _node_registration_reset_waitinglist($node) {
  $capacity = (int) $node->registration
    ->capacity();
  $registration_ids = db_select('node_registration', 'nr')
    ->fields('nr', array(
    'registration_id',
  ))
    ->condition('nid', $node->nid)
    ->condition('cancelled', 0)
    ->orderBy('weight', 'ASC')
    ->addTag('nr_waitinglist')
    ->execute()
    ->fetchCol();
  $registrations = node_registration_load_multiple($registration_ids);
  $change = FALSE;
  $slots = 0;
  foreach ($registrations as $registration) {
    $slots += $registration->slots;
    $old_waitinglist = (bool) $registration->waitinglist;
    $new_waitinglist = $capacity && $slots > $capacity;

    // Waitinglist status changed.
    if ($old_waitinglist != $new_waitinglist) {
      $registration->waitinglist = (int) $new_waitinglist;
      $registration
        ->save();

      // Save change for return value.
      $change = TRUE;
    }
  }
  return $change;
}