You are here

public function EventMaxEnrollService::getEnrollmentsLeft in Open Social 8.6

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService::getEnrollmentsLeft()
  2. 8.5 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService::getEnrollmentsLeft()
  3. 8.7 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService::getEnrollmentsLeft()
  4. 8.8 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService::getEnrollmentsLeft()
  5. 10.3.x modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService::getEnrollmentsLeft()
  6. 10.0.x modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService::getEnrollmentsLeft()
  7. 10.1.x modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService::getEnrollmentsLeft()
  8. 10.2.x modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService::getEnrollmentsLeft()

Get number of enrollments still possible per event.

Parameters

\Drupal\node\NodeInterface $node: The node to check for.

Return value

int How many spots are left.

Overrides EventMaxEnrollServiceInterface::getEnrollmentsLeft

File

modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php, line 72

Class

EventMaxEnrollService
Class EventMaxEnrollService.

Namespace

Drupal\social_event_max_enroll\Service

Code

public function getEnrollmentsLeft(NodeInterface $node) {

  // Get max enrollment number.
  $max = $node
    ->get('field_event_max_enroll_num')->value;

  // Take into account AN enrollments.
  $current = $this
    ->getEnrollmentsNumber($node);

  // Count how many spots are left, but never display less than 0.
  return $max >= $current ? $max - $current : 0;
}