function registration_waitlist_is_active in Entity Registration 8.2
Same name and namespace in other branches
- 8 modules/registration_waitlist/registration_waitlist.module \registration_waitlist_is_active()
- 7.2 modules/registration_waitlist/registration_waitlist.module \registration_waitlist_is_active()
- 7 modules/registration_waitlist/registration_waitlist.module \registration_waitlist_is_active()
Determine if the waitlist is active for a given registration
Parameters
$entity_type:
$entity_id:
$settings:
Return value
bool
2 calls to registration_waitlist_is_active()
- registration_waitlist_entity_presave in modules/
registration_waitlist/ registration_waitlist.module - Implements hook_entity_presave().
- registration_waitlist_registration_status_alter in modules/
registration_waitlist/ registration_waitlist.module - Implements hook_registration_status_alter().
File
- modules/
registration_waitlist/ registration_waitlist.module, line 141 - Entity Registration waitlist functionality
Code
function registration_waitlist_is_active($entity_type, $entity_id, &$errors = array()) {
$settings = registration_entity_settings($entity_type, $entity_id);
$active = FALSE;
$capacity = $settings['capacity'];
// Not unlimited capacity
if ($capacity && isset($settings['settings']['registration_waitlist_enable']) && $settings['settings']['registration_waitlist_enable']) {
if (in_array(t(REGISTRATION_INSUFFICIENT_SPACES_MESSAGE), $errors)) {
$active = TRUE;
}
// Check wait list capacity against number of registrations on the wait list
$waitlist_capacity = isset($settings['settings']['registration_waitlist_capacity']) ? $settings['settings']['registration_waitlist_capacity'] : 0;
// We only need to check how many people are on the waitlist if there is a capacity other than 0 set
if ($active && $waitlist_capacity) {
$waitlist_state = registration_get_states(REGISTRATION_WAITLIST_STATE);
// get count of registrations with the waitlist state
$query = db_select('registration', 'r');
$query
->addExpression('sum(count)', 'count');
$query
->condition('entity_id', $entity_id);
$query
->condition('entity_type', $entity_type);
$query
->condition('state', $waitlist_state
->identifier());
$result = $query
->execute();
$waitlist_count = $result
->fetchField();
$waitlist_count = $waitlist_count == '' ? 0 : $waitlist_count;
if ($waitlist_capacity - $waitlist_count < 1) {
$active = FALSE;
$errors[] = t('Waitlist is full.');
}
}
}
return $active;
}