You are here

public function EventEnrolledOrCreated::query in Open Social 8

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  2. 8.2 modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  3. 8.3 modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  4. 8.4 modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  5. 8.5 modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  6. 8.6 modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  7. 8.7 modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  8. 8.8 modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  9. 10.3.x modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  10. 10.0.x modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  11. 10.1.x modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()
  12. 10.2.x modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php \Drupal\social_event\Plugin\views\filter\EventEnrolledOrCreated::query()

Query for the activity stream on the account pages.

Overrides FilterPluginBase::query

File

modules/social_features/social_event/src/Plugin/views/filter/EventEnrolledOrCreated.php, line 40

Class

EventEnrolledOrCreated
Filters events based on created or enrolled status.

Namespace

Drupal\social_event\Plugin\views\filter

Code

public function query() {

  // Profile user.
  $account_profile = \Drupal::routeMatch()
    ->getParameter('user');
  if (!is_null($account_profile) && is_object($account_profile)) {
    $account_profile = $account_profile
      ->id();
  }

  // Join the event tables.
  $configuration = [
    'table' => 'event_enrollment__field_event',
    'field' => 'field_event_target_id',
    'left_table' => 'node_field_data',
    'left_field' => 'nid',
    'operator' => '=',
  ];
  $join = Views::pluginManager('join')
    ->createInstance('standard', $configuration);
  $this->query
    ->addRelationship('event_enrollment__field_event', $join, 'node_field_data');
  $configuration = [
    'table' => 'event_enrollment_field_data',
    'field' => 'id',
    'left_table' => 'event_enrollment__field_event',
    'left_field' => 'entity_id',
    'operator' => '=',
  ];
  $join = Views::pluginManager('join')
    ->createInstance('standard', $configuration);
  $this->query
    ->addRelationship('event_enrollment_field_data', $join, 'node_field_data');
  $configuration = [
    'table' => 'event_enrollment__field_enrollment_status',
    'field' => 'entity_id',
    'left_table' => 'event_enrollment__field_event',
    'left_field' => 'entity_id',
    'operator' => '=',
  ];
  $join = Views::pluginManager('join')
    ->createInstance('standard', $configuration);
  $this->query
    ->addRelationship('event_enrollment__field_enrollment_status', $join, 'node_field_data');
  $or_condition = db_or();

  // Check if the user is the author of the event.
  $event_creator = db_and();
  $event_creator
    ->condition('node_field_data.uid', $account_profile, '=');
  $event_creator
    ->condition('node_field_data.type', 'event', '=');
  $or_condition
    ->condition($event_creator);

  // Or if he enrolled to the event.
  $enrolled_to_event = db_and();
  $enrolled_to_event
    ->condition('event_enrollment_field_data.user_id', $account_profile, '=');
  $enrolled_to_event
    ->condition('event_enrollment__field_enrollment_status.field_enrollment_status_value', '1', '=');
  $or_condition
    ->condition($enrolled_to_event);
  $this->query
    ->addWhere('enrolled_or_created', $or_condition);
}