You are here

public function AccessStorage::addTermPermissionsByUserIds in Permissions by Term 8

Same name and namespace in other branches
  1. 8.2 src/Service/AccessStorage.php \Drupal\permissions_by_term\Service\AccessStorage::addTermPermissionsByUserIds()

Parameters

array $aUserIdsGrantedAccess:

int $term_id:

string $langcode:

Throws

\Exception

1 call to AccessStorage::addTermPermissionsByUserIds()
AccessStorage::saveTermPermissions in src/Service/AccessStorage.php
*

File

src/Service/AccessStorage.php, line 308

Class

AccessStorage
Class AccessStorage.

Namespace

Drupal\permissions_by_term\Service

Code

public function addTermPermissionsByUserIds($aUserIdsGrantedAccess, $term_id, $langcode = '') {
  $langcode = $langcode === '' ? \Drupal::languageManager()
    ->getCurrentLanguage()
    ->getId() : $langcode;
  foreach ($aUserIdsGrantedAccess as $iUserIdGrantedAccess) {
    $queryResult = $this->database
      ->query("SELECT uid FROM {permissions_by_term_user} WHERE tid = :tid AND uid = :uid AND langcode = :langcode", [
      ':tid' => $term_id,
      ':uid' => $iUserIdGrantedAccess,
      ':langcode' => $langcode,
    ])
      ->fetchField();
    if (empty($queryResult)) {
      $this->database
        ->insert('permissions_by_term_user')
        ->fields([
        'tid',
        'uid',
        'langcode',
      ], [
        $term_id,
        $iUserIdGrantedAccess,
        $langcode,
      ])
        ->execute();
    }
  }
}