Skip to content

Commit c0d7c68

Browse files
authored
Merge pull request #5738 from christianbeeznest/ofaj-21604-3
Internal: Fix course visibility in My Sessions page - refs BT#21604
2 parents 8b4b139 + cfd13bc commit c0d7c68

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/CoreBundle/Repository/SessionRepository.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Chamilo\CoreBundle\Settings\SettingsManager;
1717
use DateTime;
1818
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
19+
use Doctrine\Common\Collections\ArrayCollection;
1920
use Doctrine\ORM\Query\Expr\Join;
2021
use Doctrine\ORM\QueryBuilder;
2122
use Doctrine\Persistence\ManagerRegistry;
@@ -130,8 +131,20 @@ public function getCurrentSessionsOfUserInUrl(User $user, AccessUrl $url): array
130131
{
131132
$sessions = $this->getSubscribedSessionsOfUserInUrl($user, $url);
132133

133-
$filterCurrentSessions = function (Session $session) use ($user) {
134-
// Determine if the user is a coach
134+
$filterCurrentSessions = function (Session $session) use ($user, $url) {
135+
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));
146+
}
147+
135148
$userIsCoach = $session->hasCoach($user);
136149

137150
// Check if session has a duration

0 commit comments

Comments
 (0)