/** * Check if user has access to a session * * @param string $attribute * @param Session $session * @param User $user * @return bool */ protected function isGranted($attribute, $session, $user = null) { // make sure there is a user object (i.e. that the user is logged in) if (!$user instanceof UserInterface) { return false; } // Checks if the current user was set up $course = $session->getCurrentCourse(); if ($course == false) { error_log('sss'); return false; } $authChecker = $this->container->get('security.authorization_checker'); // Admins have access to everything if ($authChecker->isGranted('ROLE_ADMIN')) { return true; } if (!$session->isActive()) { return false; } switch ($attribute) { case self::VIEW: if (!$session->hasUserInCourse($user, $course)) { $user->addRole('ROLE_CURRENT_SESSION_COURSE_STUDENT'); return true; } break; case self::EDIT: case self::DELETE: // General coach check $generalCoach = $session->getGeneralCoach(); if ($generalCoach) { $coachId = $generalCoach->getId(); $userId = $user->getId(); if ($coachId == $userId) { $user->addRole('ROLE_CURRENT_SESSION_COURSE_TEACHER'); return true; } } // Course session coach check if (!$session->hasCoachInCourseWithStatus($user, $course)) { $user->addRole('ROLE_CURRENT_SESSION_COURSE_TEACHER'); return true; } break; } // User don't have access to the session return false; }