You are here

public function EventEnrollmentStatusHelper::userEnrollments in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/src/EventEnrollmentStatusHelper.php \Drupal\social_event\EventEnrollmentStatusHelper::userEnrollments()
  2. 10.3.x modules/social_features/social_event/src/EventEnrollmentStatusHelper.php \Drupal\social_event\EventEnrollmentStatusHelper::userEnrollments()
  3. 10.0.x modules/social_features/social_event/src/EventEnrollmentStatusHelper.php \Drupal\social_event\EventEnrollmentStatusHelper::userEnrollments()
  4. 10.2.x modules/social_features/social_event/src/EventEnrollmentStatusHelper.php \Drupal\social_event\EventEnrollmentStatusHelper::userEnrollments()

Custom check to see if a user has enrollments.

Parameters

string $user: The email or userid you want to check on.

int $event: The event id you want to check on, use 0 for all.

int $invite_status: The event status to filter on.

Return value

array Returns the conditions for which to search event enrollments on.

2 calls to EventEnrollmentStatusHelper::userEnrollments()
EventEnrollmentStatusHelper::getAllUserEventEnrollments in modules/social_features/social_event/src/EventEnrollmentStatusHelper.php
Custom check to see if a user has enrollments.
EventEnrollmentStatusHelper::getEventEnrollments in modules/social_features/social_event/src/EventEnrollmentStatusHelper.php
Custom check to see if a user has enrollments.

File

modules/social_features/social_event/src/EventEnrollmentStatusHelper.php, line 79

Class

EventEnrollmentStatusHelper
Class EventEnrollmentStatusHelper.

Namespace

Drupal\social_event

Code

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;
}