You are here

public function SocialEventInviteConfigOverride::validateInviteData in Open Social 10.3.x

Same name and namespace in other branches
  1. 10.1.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteConfigOverride.php \Drupal\social_event_invite\SocialEventInviteConfigOverride::validateInviteData()
  2. 10.2.x modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteConfigOverride.php \Drupal\social_event_invite\SocialEventInviteConfigOverride::validateInviteData()

Validate invite data.

Parameters

string $invitee_mail: Encoded email address of invited user.

string $destination: The url of invited group.

Return value

bool TRUE if invited data is valid.

1 call to SocialEventInviteConfigOverride::validateInviteData()
SocialEventInviteConfigOverride::loadOverrides in modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteConfigOverride.php
Load overrides.

File

modules/social_features/social_event/modules/social_event_invite/src/SocialEventInviteConfigOverride.php, line 119

Class

SocialEventInviteConfigOverride
Provides an overridden elements.

Namespace

Drupal\social_event_invite

Code

public function validateInviteData($invitee_mail, $destination) {
  if (empty($invitee_mail) || empty($destination)) {
    return FALSE;
  }

  // Get decoded email of invited user from params.
  $invitee_mail = base64_decode(str_replace([
    '-',
    '_',
  ], [
    '+',
    '/',
  ], $invitee_mail));
  if (!$this->emailValidator
    ->isValid($invitee_mail)) {
    return FALSE;
  }

  // Get event id to which user was invited from params.
  $path = $this
    ->getPathByAlias($destination);
  $path = explode('/', $path);
  $id = array_pop($path);
  if (empty($id) || !is_numeric($id)) {
    return FALSE;
  }

  // Verify is it really was requested invite and it still is actual.
  $query = $this->database
    ->select('event_enrollment__field_email', 'eefe');
  $query
    ->fields('eefe', [
    'entity_id',
  ]);
  $query
    ->condition('eefe.field_email_value', $invitee_mail);
  $query
    ->join('event_enrollment__field_request_or_invite_status', 'enfroi', 'eefe.entity_id = enfroi.entity_id');
  $query
    ->condition('enfroi.field_request_or_invite_status_value', [
    '4',
    '5',
  ], 'IN');
  $query
    ->join('event_enrollment__field_event', 'eefev', 'eefe.entity_id = eefev.entity_id');
  $query
    ->condition('eefev.field_event_target_id', $id);
  $invitations = $query
    ->execute()
    ->fetchField();
  if (empty($invitations)) {
    return FALSE;
  }
  else {
    return TRUE;
  }
}