UserRNGSelection.php in RNG - Events and Registrations 8
File
src/Plugin/EntityReferenceSelection/UserRNGSelection.php
View source
<?php
namespace Drupal\rng\Plugin\EntityReferenceSelection;
use Drupal\rng\RuleGrantsOperationTrait;
use Drupal\rng\RNGConditionInterface;
class UserRNGSelection extends RNGSelectionBase {
use RuleGrantsOperationTrait;
protected function buildEntityQuery($match = NULL, $match_operator = 'CONTAINS') {
$query = parent::buildEntityQuery($match, $match_operator);
if (isset($match)) {
$query
->condition('name', $match, $match_operator);
}
$query
->condition('status', 1);
$query
->condition($this->entityType
->getKey('id'), '0', '<>');
$condition_count = 0;
$rules = $this->eventMeta
->getRules('rng_event.register', TRUE);
foreach ($rules as $rule) {
if ($this
->ruleGrantsOperation($rule, 'create')) {
foreach ($rule
->getConditions() as $condition_storage) {
$condition = $condition_storage
->createInstance();
if ($condition instanceof RNGConditionInterface) {
$condition_count++;
$condition
->alterQuery($query);
}
}
}
}
if (!$condition_count) {
$query
->condition($this->entityType
->getKey('id'), NULL, 'IS NULL');
return $query;
}
$proxy_count = 0;
$all_users = FALSE;
$group = $query
->orConditionGroup();
if ($this->currentUser
->isAuthenticated()) {
if ($this->currentUser
->hasPermission('rng register self')) {
$proxy_count++;
$group
->condition($this->entityType
->getKey('id'), $this->currentUser
->id(), '=');
}
}
foreach (user_roles(TRUE) as $role) {
$role_id = $role
->id();
if ($this->currentUser
->hasPermission("rng register role {$role_id}")) {
if ($role_id == 'authenticated') {
$all_users = TRUE;
break;
}
else {
$proxy_count++;
$group
->condition('roles', $role_id, '=');
}
}
}
if ($all_users) {
}
elseif ($proxy_count) {
$query
->condition($group);
}
else {
$query
->condition($this->entityType
->getKey('id'), NULL, 'IS NULL');
}
return $query;
}
}