class EventEnrollmentStatusHelper in Open Social 10.0.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/src/EventEnrollmentStatusHelper.php \Drupal\social_event\EventEnrollmentStatusHelper
- 10.3.x modules/social_features/social_event/src/EventEnrollmentStatusHelper.php \Drupal\social_event\EventEnrollmentStatusHelper
- 10.1.x modules/social_features/social_event/src/EventEnrollmentStatusHelper.php \Drupal\social_event\EventEnrollmentStatusHelper
- 10.2.x modules/social_features/social_event/src/EventEnrollmentStatusHelper.php \Drupal\social_event\EventEnrollmentStatusHelper
Class EventEnrollmentStatusHelper.
Providers service to get the enrollments for a user.
Hierarchy
- class \Drupal\social_event\EventEnrollmentStatusHelper
Expanded class hierarchy of EventEnrollmentStatusHelper
2 files declare their use of EventEnrollmentStatusHelper
- EnrollInviteUserForm.php in modules/
social_features/ social_event/ modules/ social_event_invite/ src/ Form/ EnrollInviteUserForm.php - EnrollRequestDeclineForm.php in modules/
social_features/ social_event/ src/ Form/ EnrollRequestDeclineForm.php
1 string reference to 'EventEnrollmentStatusHelper'
- social_event.services.yml in modules/
social_features/ social_event/ social_event.services.yml - modules/social_features/social_event/social_event.services.yml
1 service uses EventEnrollmentStatusHelper
- social_event.status_helper in modules/
social_features/ social_event/ social_event.services.yml - Drupal\social_event\EventEnrollmentStatusHelper
File
- modules/
social_features/ social_event/ src/ EventEnrollmentStatusHelper.php, line 17
Namespace
Drupal\social_eventView source
class EventEnrollmentStatusHelper {
/**
* The route match.
*
* @var \Drupal\Core\Routing\RouteMatchInterface
*/
protected $routeMatch;
/**
* Entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The current user.
*
* @var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* Configuration factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* EventInvitesAccess constructor.
*
* @param \Drupal\Core\Routing\RouteMatchInterface $routeMatch
* The route match.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
* The entity type manager.
* @param \Drupal\Core\Session\AccountProxyInterface $currentUser
* The current user.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* Configuration factory.
*/
public function __construct(RouteMatchInterface $routeMatch, EntityTypeManagerInterface $entityTypeManager, AccountProxyInterface $currentUser, ConfigFactoryInterface $configFactory) {
$this->routeMatch = $routeMatch;
$this->entityTypeManager = $entityTypeManager;
$this->currentUser = $currentUser;
$this->configFactory = $configFactory;
}
/**
* Custom check to see if a user has enrollments.
*
* @param string $user
* The email or userid you want to check on.
* @param int $event
* The event id you want to check on, use 0 for all.
* @param int $invite_status
* The event status to filter on.
*
* @return array
* Returns the conditions for which to search event enrollments on.
*/
public function userEnrollments($user, $event, $invite_status = NULL) {
$current_user = $this->currentUser;
$uid = $current_user
->id();
$nid = $this->routeMatch
->getRawParameter('node');
if ($event) {
$nid = $event;
}
// If there is no trigger get the enrollment for the current user.
$conditions = [
'field_account' => $uid,
'field_event' => $nid,
'field_request_or_invite_status' => EventEnrollmentInterface::INVITE_PENDING_REPLY,
];
if ($user) {
// Always assume the trigger is emails unless the ID is a user.
$conditions = [
'field_email' => $user,
'field_event' => $nid,
];
/** @var \Drupal\user\Entity\User $user */
$account = User::load($user);
if ($account instanceof UserInterface) {
$conditions = [
'field_account' => $account
->id(),
'field_event' => $nid,
'field_request_or_invite_status' => EventEnrollmentInterface::INVITE_PENDING_REPLY,
];
}
}
return $conditions;
}
/**
* Custom check to get all enrollments for an event.
*
* @param int $event
* The event id you want to check on.
* @param int $invite_status
* The event status to filter on.
*
* @return array
* Returns the conditions for which to search event enrollments on.
*/
public function eventEnrollments($event, $invite_status = NULL) {
$nid = $this->routeMatch
->getRawParameter('node');
if ($event) {
$nid = $event;
}
// If there is no trigger get the enrollment for the current user.
$conditions = [
'field_event' => $nid,
'field_request_or_invite_status' => EventEnrollmentInterface::INVITE_PENDING_REPLY,
];
return $conditions;
}
/**
* Custom check to see if a user has enrollments.
*
* @param string $user
* The email or userid you want to check on.
*
* @return bool|\Drupal\Core\Entity\EntityInterface|mixed
* Returns all the enrollments for a user.
*/
public function getAllUserEventEnrollments($user) {
$conditions = $this
->userEnrollments($user, NULL);
unset($conditions['field_event']);
return $this->entityTypeManager
->getStorage('event_enrollment')
->loadByProperties($conditions);
}
/**
* Custom check to see if a user has enrollments.
*
* @param string $user
* The email or userid you want to check on.
* @param int $event
* The event id you want to check on.
* @param bool $ignore_all_status
* Default FALSE, if set to TRUE then ignore any request_or_invite status.
*
* @return \Drupal\Core\Entity\EntityInterface[]
* Returns a specific event enrollment for a user.
*/
public function getEventEnrollments($user, $event, $ignore_all_status = FALSE) {
$conditions = $this
->userEnrollments($user, $event);
// If the $ignore_all_status parameter is TRUE, and we have the field
// field_request_or_invite_status in our $conditions, unset this field.
if ($ignore_all_status === TRUE && isset($conditions['field_request_or_invite_status'])) {
unset($conditions['field_request_or_invite_status']);
}
return $this->entityTypeManager
->getStorage('event_enrollment')
->loadByProperties($conditions);
}
/**
* Custom check to get all enrollments for an event.
*
* @param int $event
* The event id you want to check on.
* @param bool $ignore_all_status
* Default FALSE, if set to TRUE then ignore any request_or_invite status.
*
* @return \Drupal\Core\Entity\EntityInterface[]
* Returns all enrollments for an event.
*/
public function getAllEventEnrollments($event, $ignore_all_status = FALSE) {
$conditions = $this
->eventEnrollments($event);
// If the $ignore_all_status parameter is TRUE, and we have the field
// field_request_or_invite_status in our $conditions, unset this field.
if ($ignore_all_status === TRUE && isset($conditions['field_request_or_invite_status'])) {
unset($conditions['field_request_or_invite_status']);
}
return $this->entityTypeManager
->getStorage('event_enrollment')
->loadByProperties($conditions);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EventEnrollmentStatusHelper:: |
protected | property | Configuration factory. | |
EventEnrollmentStatusHelper:: |
protected | property | The current user. | |
EventEnrollmentStatusHelper:: |
protected | property | Entity type manager. | |
EventEnrollmentStatusHelper:: |
protected | property | The route match. | |
EventEnrollmentStatusHelper:: |
public | function | Custom check to get all enrollments for an event. | |
EventEnrollmentStatusHelper:: |
public | function | Custom check to get all enrollments for an event. | |
EventEnrollmentStatusHelper:: |
public | function | Custom check to see if a user has enrollments. | |
EventEnrollmentStatusHelper:: |
public | function | Custom check to see if a user has enrollments. | |
EventEnrollmentStatusHelper:: |
public | function | Custom check to see if a user has enrollments. | |
EventEnrollmentStatusHelper:: |
public | function | EventInvitesAccess constructor. |