You are here

function simple_access_get_profiles in Simple Access 8.3

Same name and namespace in other branches
  1. 5.2 simple_access.module \simple_access_get_profiles()
  2. 6.2 simple_access.module \simple_access_get_profiles()
  3. 7.2 simple_access.module \simple_access_get_profiles()

Get simple access profiles.

1 call to simple_access_get_profiles()
simple_access_get_profiles_select in ./simple_access.module
Get all profiles as options for a select list.

File

./simple_access.module, line 383
Builds simple access definition for content access.

Code

function simple_access_get_profiles($pid = NULL) {
  $profiles = [];
  $query = \Drupal::database()
    ->select('simple_access_profiles', 'p')
    ->fields('p', [
    'pid',
    'name',
  ])
    ->orderBy('weight', 'ASC')
    ->orderBy('name');
  if ($pid) {
    $query
      ->condition('pid', $pid);
  }
  $profiles = $query
    ->execute()
    ->fetchAllAssoc('pid', PDO::FETCH_ASSOC);
  $query = \Drupal::database()
    ->select('simple_access_profiles_access', 'a')
    ->fields('a', [
    'pid',
    'gid',
    'sa_view',
    'sa_update',
    'sa_delete',
  ])
    ->orderBy('pid');
  if ($pid) {
    $query
      ->condition('pid', $pid);
  }
  $result = $query
    ->execute();
  while ($a = $result
    ->fetchAssoc(PDO::FETCH_ASSOC)) {
    if (isset($profiles[$a['pid']])) {
      $profiles[$a['pid']]['access'][$a['gid']] = $a;
    }
  }
  return isset($pid) ? $profiles[$pid] : $profiles;
}