You are here

class EventMaxEnrollService in Open Social 8.8

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
  2. 8.5 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
  3. 8.6 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
  4. 8.7 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
  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
  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
  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
  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

Class EventMaxEnrollService.

@package Drupal\social_event_max_enroll\Service

Hierarchy

Expanded class hierarchy of EventMaxEnrollService

1 string reference to 'EventMaxEnrollService'
social_event_max_enroll.services.yml in modules/social_features/social_event/modules/social_event_max_enroll/social_event_max_enroll.services.yml
modules/social_features/social_event/modules/social_event_max_enroll/social_event_max_enroll.services.yml
1 service uses EventMaxEnrollService
social_event_max_enroll.service in modules/social_features/social_event/modules/social_event_max_enroll/social_event_max_enroll.services.yml
Drupal\social_event_max_enroll\Service\EventMaxEnrollService

File

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

Namespace

Drupal\social_event_max_enroll\Service
View source
class EventMaxEnrollService implements EventMaxEnrollServiceInterface {

  /**
   * The event enrollment storage.
   *
   * @var \Drupal\Core\Entity\EntityStorageInterface
   */
  protected $storage;

  /**
   * The configuration factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * The social event enroll.
   *
   * @var \Drupal\social_event\Service\SocialEventEnrollServiceInterface
   */
  protected $socialEventEnroll;

  /**
   * EventMaxEnrollService constructor.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
   *   Injection of the configFactory.
   * @param \Drupal\social_event\Service\SocialEventEnrollServiceInterface $social_event_enroll
   *   The social event enroll.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $configFactory, SocialEventEnrollServiceInterface $social_event_enroll) {
    $this->storage = $entity_type_manager
      ->getStorage('event_enrollment');
    $this->configFactory = $configFactory;
    $this->socialEventEnroll = $social_event_enroll;
  }

  /**
   * {@inheritdoc}
   */
  public function getEnrollmentsNumber(NodeInterface $node) {
    return $this->storage
      ->getQuery()
      ->condition('field_event', $node
      ->id())
      ->condition('field_enrollment_status', 1)
      ->count()
      ->execute();
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

  /**
   * {@inheritdoc}
   */
  public function isEnabled(NodeInterface $node) {

    // Check if we're working with an event.
    if ($this->socialEventEnroll
      ->isEnabled($node)) {
      $config = $this->configFactory
        ->get('social_event_max_enroll.settings');

      // Check if feature is enabled.
      if ($config
        ->get('max_enroll')) {

        // Get enrollment configuration for this event.
        $is_event_max_enroll = !$node->field_event_max_enroll
          ->isEmpty() && $node->field_event_max_enroll->value;
        $is_event_max_enroll_num = !$node->field_event_max_enroll_num
          ->isEmpty();
        return $is_event_max_enroll && $is_event_max_enroll_num;
      }
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EventMaxEnrollService::$configFactory protected property The configuration factory.
EventMaxEnrollService::$socialEventEnroll protected property The social event enroll.
EventMaxEnrollService::$storage protected property The event enrollment storage.
EventMaxEnrollService::getEnrollmentsLeft public function Get number of enrollments still possible per event. Overrides EventMaxEnrollServiceInterface::getEnrollmentsLeft
EventMaxEnrollService::getEnrollmentsNumber public function Get count of enrollments per event. Overrides EventMaxEnrollServiceInterface::getEnrollmentsNumber
EventMaxEnrollService::isEnabled public function Check if anonymous enrollment is allowed for given event. Overrides EventMaxEnrollServiceInterface::isEnabled
EventMaxEnrollService::__construct public function EventMaxEnrollService constructor.