You are here

public function DashboardForm::access in Opigno statistics 8

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

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

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 619

Class

DashboardForm
Implements the statistics dashboard.

Namespace

Drupal\opigno_statistics\Form

Code

public function access(AccountInterface $account) {
  $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);
    }
  }
}