You are here

public function UpdateEnrollRequestController::updateEnrollmentRequest in Open Social 8.9

Same name and namespace in other branches
  1. 10.3.x modules/social_features/social_event/src/Controller/UpdateEnrollRequestController.php \Drupal\social_event\Controller\UpdateEnrollRequestController::updateEnrollmentRequest()
  2. 10.0.x modules/social_features/social_event/src/Controller/UpdateEnrollRequestController.php \Drupal\social_event\Controller\UpdateEnrollRequestController::updateEnrollmentRequest()
  3. 10.1.x modules/social_features/social_event/src/Controller/UpdateEnrollRequestController.php \Drupal\social_event\Controller\UpdateEnrollRequestController::updateEnrollmentRequest()
  4. 10.2.x modules/social_features/social_event/src/Controller/UpdateEnrollRequestController.php \Drupal\social_event\Controller\UpdateEnrollRequestController::updateEnrollmentRequest()

Updates the enrollment request.

Parameters

\Drupal\node\NodeInterface $node: The current event node.

\Drupal\social_event\EventEnrollmentInterface $event_enrollment: The entity event_enrollment.

int $approve: Approve the enrollment request, TRUE(1) or FALSE(0).

Return value

\Symfony\Component\HttpFoundation\RedirectResponse Return to the original destination from the current request.

Throws

\Drupal\Core\Entity\EntityStorageException

1 string reference to 'UpdateEnrollRequestController::updateEnrollmentRequest'
social_event.routing.yml in modules/social_features/social_event/social_event.routing.yml
modules/social_features/social_event/social_event.routing.yml

File

modules/social_features/social_event/src/Controller/UpdateEnrollRequestController.php, line 75

Class

UpdateEnrollRequestController
Updates a pending enrollment request.

Namespace

Drupal\social_event\Controller

Code

public function updateEnrollmentRequest(NodeInterface $node, EventEnrollmentInterface $event_enrollment, $approve) {

  // Just some sanity checks.
  if ($node instanceof Node && !empty($event_enrollment)) {

    // First, lets delete all messages to keep the messages clean.
    $this
      ->messenger()
      ->deleteAll();

    // When the user approved,
    // we set the field_request_or_invite_status to approved.
    if ($approve === '1') {
      $event_enrollment->field_request_or_invite_status->value = EventEnrollmentInterface::REQUEST_APPROVED;
      $event_enrollment->field_enrollment_status->value = '1';
      $this
        ->messenger()
        ->addStatus(t('The event enrollment request has been approved.'));
    }
    elseif ($approve === '0') {
      $event_enrollment->field_request_or_invite_status->value = EventEnrollmentInterface::REQUEST_OR_INVITE_DECLINED;
      $this
        ->messenger()
        ->addStatus(t('The event enrollment request has been declined.'));
    }

    // In order for the notifications to be sent correctly we're updating the
    // owner here. The account is still linked to the actual enrollee.
    // The owner is always used as the actor.
    // @see activity_creator_message_insert().
    $event_enrollment
      ->setOwnerId($this->currentUser
      ->id());

    // And finally save (update) this updated $event_enrollment.
    // @todo: maybe think of deleting approved/declined records from the db?
    $event_enrollment
      ->save();
  }

  // Get the redirect destination we're given in the request for the response.
  $destination = $this->requestStack
    ->getCurrentRequest()->query
    ->get('destination');
  return new RedirectResponse($destination);
}