You are here

public function DashboardForm::checkLimitPermissions in Opigno statistics 8

Same name and namespace in other branches
  1. 3.x src/Form/DashboardForm.php \Drupal\opigno_statistics\Form\DashboardForm::checkLimitPermissions()

Get array of learning paths ID's where user have role 'student manager'.

1 call to DashboardForm::checkLimitPermissions()
DashboardForm::buildForm in src/Form/DashboardForm.php
Form constructor.

File

src/Form/DashboardForm.php, line 594

Class

DashboardForm
Implements the statistics dashboard.

Namespace

Drupal\opigno_statistics\Form

Code

public function checkLimitPermissions(AccountInterface $account) {
  $connection = Database::getConnection();
  $query = $connection
    ->select('group_content_field_data', 'g_c_f_d')
    ->fields('g_c_f_d', [
    'gid',
  ]);
  $query
    ->leftJoin('group_content__group_roles', 'g_c_g_r', 'g_c_f_d.id = g_c_g_r.entity_id');
  $query
    ->condition('g_c_g_r.group_roles_target_id', 'learning_path-user_manager');
  $query
    ->condition('g_c_f_d.entity_id', $account
    ->id());
  $query
    ->condition('g_c_f_d.type', 'learning_path-group_membership');
  $result = $query
    ->execute()
    ->fetchAllAssoc('gid');
  $lp_ids = [];
  foreach ($result as $row) {
    $lp_ids[] = $row->gid;
  }
  return $lp_ids;
}