Skip to content

Commit cfd13bc

Browse files
Internal: Fix session display for coach based on duration and access dates - refs BT#21604
1 parent ced5694 commit cfd13bc

File tree

1 file changed

+30
-14
lines changed

1 file changed

+30
-14
lines changed

src/CoreBundle/Repository/SessionRepository.php

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,35 +132,51 @@ public function getCurrentSessionsOfUserInUrl(User $user, AccessUrl $url): array
132132
$sessions = $this->getSubscribedSessionsOfUserInUrl($user, $url);
133133

134134
$filterCurrentSessions = function (Session $session) use ($user, $url) {
135-
$coursesAsCoach = $this->getSessionCoursesByStatusInCourseSubscription($user, $session, Session::COURSE_COACH, $url);
136-
$coursesAsStudent = $this->getSessionCoursesByStatusInCourseSubscription($user, $session, Session::STUDENT, $url);
137-
$validCourses = array_merge($coursesAsCoach, $coursesAsStudent);
138135

139-
if (empty($validCourses)) {
140-
return false;
136+
$userIsGeneralCoach = $session->hasUserAsGeneralCoach($user);
137+
if (!$userIsGeneralCoach) {
138+
$coursesAsCoach = $this->getSessionCoursesByStatusInCourseSubscription($user, $session, Session::COURSE_COACH, $url);
139+
$coursesAsStudent = $this->getSessionCoursesByStatusInCourseSubscription($user, $session, Session::STUDENT, $url);
140+
$validCourses = array_merge($coursesAsCoach, $coursesAsStudent);
141+
142+
if (empty($validCourses)) {
143+
return false;
144+
}
145+
$session->setCourses(new ArrayCollection($validCourses));
141146
}
142147

143-
$session->setCourses(new ArrayCollection($validCourses));
148+
$userIsCoach = $session->hasCoach($user);
144149

145150
// Check if session has a duration
146151
if ($session->getDuration() > 0) {
147152
$daysLeft = $session->getDaysLeftByUser($user);
148153

149-
return $daysLeft >= 0;
154+
return $daysLeft >= 0 || $userIsCoach;
150155
}
151156

157+
// Determine the start date based on whether the user is a coach
158+
$sessionStartDate = $userIsCoach && $session->getCoachAccessStartDate()
159+
? $session->getCoachAccessStartDate()
160+
: $session->getAccessStartDate();
161+
162+
// If there is no start date, consider the session current
163+
if (!$sessionStartDate) {
164+
return true;
165+
}
166+
167+
// Get the current date and time
152168
$now = new DateTime();
153-
$sessionStartDate = $session->getAccessStartDate();
154-
$sessionEndDate = $session->getAccessEndDate();
155169

156-
$isWithinDateRange = $now >= $sessionStartDate && (!$sessionEndDate || $now <= $sessionEndDate);
170+
// Determine the end date based on whether the user is a coach
171+
$sessionEndDate = $userIsCoach && $session->getCoachAccessEndDate()
172+
? $session->getCoachAccessEndDate()
173+
: $session->getAccessEndDate();
157174

158-
return $isWithinDateRange;
175+
// Check if the current date is within the start and end dates
176+
return $now >= $sessionStartDate && (!$sessionEndDate || $now <= $sessionEndDate);
159177
};
160178

161-
$filteredSessions = array_filter($sessions, $filterCurrentSessions);
162-
163-
return $filteredSessions;
179+
return array_filter($sessions, $filterCurrentSessions);
164180
}
165181

166182
/**

0 commit comments

Comments
 (0)