You are here

function registration_event_count in Entity Registration 8.2

Same name and namespace in other branches
  1. 8 registration.module \registration_event_count()
  2. 7.2 registration.module \registration_event_count()
  3. 7 registration.module \registration_event_count()

Determines current number of spaces filled for a host entity.

Parameters

string $entity_type: The host entity type.

int $entity_id: The host entity ID.

int $registration_id: The registration ID. If specified, exclude identified registration from count.

Return value

int The number of spaces remaining for a host entity.

See also

registration_has_room()

6 calls to registration_event_count()
registration_form in includes/registration.forms.inc
Form callback: create or edit a registration.
registration_handler_field_entity_capacity_used::render in src/registration_handler_field_entity_capacity_used.php
registration_handler_field_entity_capacity_used::render in modules/registration_views/includes/registration_handler_field_entity_capacity_used.inc
registration_handler_field_entity_capacity_used::render in modules/registration_views/src/registration_handler_field_entity_capacity_used.php
registration_has_room in ./registration.module
Determines if a host entity has spaces remaining.

... See full list

File

./registration.module, line 828

Code

function registration_event_count($entity_type, $entity_id, $registration_id = NULL, $reset = FALSE) {
  $count =& drupal_static(__FUNCTION__ . '_' . $entity_type . '_' . $entity_id . '_' . $registration_id, FALSE);
  if (!$count || $reset) {
    $query = db_select('registration', 'r');
    $query
      ->addExpression('sum(count)', 'count');
    $query
      ->condition('entity_id', $entity_id);
    $query
      ->condition('entity_type', $entity_type);
    if ($registration_id != NULL) {
      $query
        ->condition('registration_id', $registration_id, '<>');
    }
    $active_held_states = array_merge(registration_get_active_states(), registration_get_held_states());
    if (!empty($active_held_states)) {
      $query
        ->condition('state', $active_held_states, 'IN');
    }
    $result = $query
      ->execute();
    $count = $result
      ->fetchField();
    $count = $count == '' ? 0 : $count;
  }

  // Allow other mods to override count.
  $settings = registration_entity_settings($entity_type, $entity_id);
  $context = array(
    'entity_type' => $entity_type,
    'entity_id' => $entity_id,
    'registration_id' => $registration_id,
    'settings' => $settings,
  );
  \Drupal::moduleHandler()
    ->alter('registration_event_count', $count, $context);
  return $count;
}