You are here

public function DashboardForm::access in Opigno statistics 3.x

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

Access callback to check that the user can access to view global statistic.

Parameters

\Drupal\Core\Session\AccountInterface $account: The user account.

Return value

\Drupal\Core\Access\AccessResult The access result.

1 string reference to 'DashboardForm::access'
opigno_statistics.routing.yml in ./opigno_statistics.routing.yml
opigno_statistics.routing.yml

File

src/Form/DashboardForm.php, line 657

Class

DashboardForm
Implements the statistics dashboard.

Namespace

Drupal\opigno_statistics\Form

Code

public function access(AccountInterface $account) : AccessResult {
  $uid = $account
    ->id();
  if ($account
    ->hasPermission('view global statistics') || $account
    ->hasPermission('view any user statistics') || $uid == 1) {
    return AccessResult::allowed();
  }
  else {

    // Check if user has role 'student manager' in any of trainings.
    $is_user_manager = LearningPathAccess::memberHasRole('user_manager', $account);
    if ($is_user_manager) {
      return AccessResultAllowed::allowed()
        ->mergeCacheMaxAge(0);
    }
    else {
      return AccessResultAllowed::forbidden()
        ->mergeCacheMaxAge(0);
    }
  }
}