diff --git a/src/CoreBundle/Entity/Session.php b/src/CoreBundle/Entity/Session.php index 190af9d23d..5346a07022 100644 --- a/src/CoreBundle/Entity/Session.php +++ b/src/CoreBundle/Entity/Session.php @@ -1323,6 +1323,10 @@ class Session implements ResourceWithAccessUrlInterface, Stringable { // Session duration per student. if ($this->getDuration() > 0) { + if ($this->hasCoach($user)) { + return self::AVAILABLE; + } + $duration = $this->getDuration() * 24 * 60 * 60; $courseAccess = $user->getFirstAccessToSession($this); @@ -1376,9 +1380,9 @@ class Session implements ResourceWithAccessUrlInterface, Stringable return self::AVAILABLE; } - public function setAccessVisibilityByUser(User $user): int + public function setAccessVisibilityByUser(User $user, bool $ignoreVisibilityForAdmins = true): int { - if ($user->isAdmin() || $user->isSuperAdmin()) { + if (($user->isAdmin() || $user->isSuperAdmin()) && $ignoreVisibilityForAdmins) { $this->accessVisibility = self::AVAILABLE; } elseif (!$this->getAccessStartDate() && !$this->getAccessEndDate()) { // I don't care the session visibility. diff --git a/src/CoreBundle/Repository/SessionRepository.php b/src/CoreBundle/Repository/SessionRepository.php index b996262298..3be808cb0f 100644 --- a/src/CoreBundle/Repository/SessionRepository.php +++ b/src/CoreBundle/Repository/SessionRepository.php @@ -93,16 +93,19 @@ class SessionRepository extends ServiceEntityRepository $filterPastSessions = function (Session $session) use ($user) { $now = new DateTime(); + // Determine if the user is a coach + $userIsCoach = $session->hasCoach($user); // Check if the session has a duration if ($session->getDuration() > 0) { $daysLeft = $session->getDaysLeftByUser($user); + $session->setTitle($session->getTitle().'<-'.$daysLeft); - return $daysLeft < 0; + return $daysLeft < 0 && !$userIsCoach; } // Get the appropriate end date based on whether the user is a coach - $sessionEndDate = $session->hasCoach($user) && $session->getCoachAccessEndDate() + $sessionEndDate = $userIsCoach && $session->getCoachAccessEndDate() ? $session->getCoachAccessEndDate() : $session->getAccessEndDate(); @@ -128,16 +131,16 @@ class SessionRepository extends ServiceEntityRepository $sessions = $this->getSubscribedSessionsOfUserInUrl($user, $url); $filterCurrentSessions = function (Session $session) use ($user) { + // Determine if the user is a coach + $userIsCoach = $session->hasCoach($user); + // Check if session has a duration if ($session->getDuration() > 0) { $daysLeft = $session->getDaysLeftByUser($user); - return $daysLeft >= 0; + return $daysLeft >= 0 || $userIsCoach; } - // Determine if the user is a coach - $userIsCoach = $session->hasCoach($user); - // Determine the start date based on whether the user is a coach $sessionStartDate = $userIsCoach && $session->getCoachAccessStartDate() ? $session->getCoachAccessStartDate() @@ -401,12 +404,12 @@ class SessionRepository extends ServiceEntityRepository public function getSubscribedSessionsOfUserInUrl( User $user, AccessUrl $url, - bool $ignoreVisibilityForAdmin = false, + bool $ignoreVisibilityForAdmins = false, ): array { $sessions = $this->getSessionsByUser($user, $url)->getQuery()->getResult(); - $filterSessions = function (Session $session) use ($user, $ignoreVisibilityForAdmin) { - $visibility = $session->setAccessVisibilityByUser($user); + $filterSessions = function (Session $session) use ($user, $ignoreVisibilityForAdmins) { + $visibility = $session->setAccessVisibilityByUser($user, $ignoreVisibilityForAdmins); if (Session::VISIBLE !== $visibility) { $closedOrHiddenCourses = $session->getClosedOrHiddenCourses(); @@ -423,7 +426,7 @@ class SessionRepository extends ServiceEntityRepository break; case Session::INVISIBLE: - if (!$ignoreVisibilityForAdmin) { + if (!$ignoreVisibilityForAdmins) { return false; } }