class EventMaxEnrollService in Open Social 10.1.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
- 8.5 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
- 8.6 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
- 8.7 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
- 8.8 modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
- 10.3.x modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
- 10.0.x modules/social_features/social_event/modules/social_event_max_enroll/src/Service/EventMaxEnrollService.php \Drupal\social_event_max_enroll\Service\EventMaxEnrollService
- 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
- class \Drupal\social_event_max_enroll\Service\EventMaxEnrollService implements EventMaxEnrollServiceInterface
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\ServiceView 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.
*
* @throws \Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EventMaxEnrollService:: |
protected | property | The configuration factory. | |
EventMaxEnrollService:: |
protected | property | The social event enroll. | |
EventMaxEnrollService:: |
protected | property | The event enrollment storage. | |
EventMaxEnrollService:: |
public | function |
Get number of enrollments still possible per event. Overrides EventMaxEnrollServiceInterface:: |
|
EventMaxEnrollService:: |
public | function |
Get count of enrollments per event. Overrides EventMaxEnrollServiceInterface:: |
|
EventMaxEnrollService:: |
public | function |
Check if anonymous enrollment is allowed for given event. Overrides EventMaxEnrollServiceInterface:: |
|
EventMaxEnrollService:: |
public | function | EventMaxEnrollService constructor. |