@@ -132,35 +132,51 @@ public function getCurrentSessionsOfUserInUrl(User $user, AccessUrl $url): array
132
132
$ sessions = $ this ->getSubscribedSessionsOfUserInUrl ($ user , $ url );
133
133
134
134
$ 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 );
138
135
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 ));
141
146
}
142
147
143
- $ session ->setCourses ( new ArrayCollection ( $ validCourses ) );
148
+ $ userIsCoach = $ session ->hasCoach ( $ user );
144
149
145
150
// Check if session has a duration
146
151
if ($ session ->getDuration () > 0 ) {
147
152
$ daysLeft = $ session ->getDaysLeftByUser ($ user );
148
153
149
- return $ daysLeft >= 0 ;
154
+ return $ daysLeft >= 0 || $ userIsCoach ;
150
155
}
151
156
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
152
168
$ now = new DateTime ();
153
- $ sessionStartDate = $ session ->getAccessStartDate ();
154
- $ sessionEndDate = $ session ->getAccessEndDate ();
155
169
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 ();
157
174
158
- return $ isWithinDateRange ;
175
+ // Check if the current date is within the start and end dates
176
+ return $ now >= $ sessionStartDate && (!$ sessionEndDate || $ now <= $ sessionEndDate );
159
177
};
160
178
161
- $ filteredSessions = array_filter ($ sessions , $ filterCurrentSessions );
162
-
163
- return $ filteredSessions ;
179
+ return array_filter ($ sessions , $ filterCurrentSessions );
164
180
}
165
181
166
182
/**
0 commit comments