public static function LearningPathAccess::memberHasRole in Opigno Learning path 8
Same name and namespace in other branches
- 3.x src/LearningPathAccess.php \Drupal\opigno_learning_path\LearningPathAccess::memberHasRole()
Check if user has needed local role.
Parameters
string $role: User role in group.
\Drupal\Core\Session\AccountInterface $account: User account.
int $gid: Group ID.
Return value
bool Check if user has access to Class or Course.
1 call to LearningPathAccess::memberHasRole()
- LearningPathContentController::getModuleRequiredActivitiesAccess in src/
Controller/ LearningPathContentController.php - Returns Right access conditional activities with the module.
File
- src/
LearningPathAccess.php, line 652
Class
- LearningPathAccess
- Class LearningPathAccess.
Namespace
Drupal\opigno_learning_pathCode
public static function memberHasRole($role, AccountInterface $account, $gid = NULL) {
$role = "learning_path-{$role}";
$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', $role);
$query
->condition('g_c_f_d.entity_id', $account
->id());
$query
->condition('g_c_f_d.type', 'learning_path-group_membership');
if (!empty($gid)) {
$query
->condition('g_c_f_d.gid', $gid);
}
$lp_counts = $query
->countQuery()
->execute()
->fetchField();
return $lp_counts > 0;
}