You are here

protected function WebformAccessGroupStorage::doLoadMultiple in Webform 8.5

Same name and namespace in other branches
  1. 6.x modules/webform_access/src/WebformAccessGroupStorage.php \Drupal\webform_access\WebformAccessGroupStorage::doLoadMultiple()

Performs storage-specific loading of entities.

Override this method to add custom functionality directly after loading. This is always called, while self::postLoad() is only called when there are actual results.

Parameters

array|null $ids: (optional) An array of entity IDs, or NULL to load all entities.

Return value

\Drupal\Core\Entity\EntityInterface[] Associative array of entities, keyed on the entity ID.

Overrides ConfigEntityStorage::doLoadMultiple

File

modules/webform_access/src/WebformAccessGroupStorage.php, line 81

Class

WebformAccessGroupStorage
Storage controller class for "webform_access_group" configuration entities.

Namespace

Drupal\webform_access

Code

protected function doLoadMultiple(array $ids = NULL) {

  /** @var \Drupal\webform_access\WebformAccessGroupInterface[] $webform_access_groups */
  $webform_access_groups = parent::doLoadMultiple($ids);

  // Load admin.
  $result = $this->database
    ->select('webform_access_group_admin', 'gu')
    ->fields('gu', [
    'group_id',
    'uid',
  ])
    ->condition('group_id', $ids, 'IN')
    ->orderBy('group_id')
    ->orderBy('uid')
    ->execute();
  $admins = [];
  while ($record = $result
    ->fetchAssoc()) {
    $admins[$record['group_id']][] = $record['uid'];
  }
  foreach ($webform_access_groups as $group_id => $webform_access_group) {
    $webform_access_group
      ->setAdminIds(isset($admins[$group_id]) ? $admins[$group_id] : []);
  }

  // Load users.
  $result = $this->database
    ->select('webform_access_group_user', 'gu')
    ->fields('gu', [
    'group_id',
    'uid',
  ])
    ->condition('group_id', $ids, 'IN')
    ->orderBy('group_id')
    ->orderBy('uid')
    ->execute();
  $users = [];
  while ($record = $result
    ->fetchAssoc()) {
    $users[$record['group_id']][] = $record['uid'];
  }
  foreach ($webform_access_groups as $group_id => $webform_access_group) {
    $webform_access_group
      ->setUserIds(isset($users[$group_id]) ? $users[$group_id] : []);
  }

  // Load entities.
  $result = $this->database
    ->select('webform_access_group_entity', 'ge')
    ->fields('ge', [
    'group_id',
    'entity_type',
    'entity_id',
    'field_name',
    'webform_id',
  ])
    ->condition('group_id', $ids, 'IN')
    ->orderBy('group_id')
    ->execute();
  $entities = [];
  while ($record = $result
    ->fetchAssoc()) {
    $group_id = $record['group_id'];
    unset($record['group_id']);
    $entities[$group_id][] = implode(':', $record);
  }
  foreach ($webform_access_groups as $group_id => $webform_access_group) {
    $webform_access_group
      ->setEntityIds(isset($entities[$group_id]) ? $entities[$group_id] : []);
  }
  return $webform_access_groups;
}