Move SessionManager::getSessionsFollowedByUser to SessionRepository::getUserFollowedSessionsInAccessUrl

pull/5179/head
Angel Fernando Quiroz Campos 9 months ago
parent eee222c9f1
commit 9389b053d1
  1. 31
      src/CoreBundle/Repository/SessionRepository.php

@ -242,4 +242,35 @@ class SessionRepository extends ServiceEntityRepository
return $qb;
}
public function getUserFollowedSessionsInAccessUrl(User $user, AccessUrl $url): QueryBuilder
{
$callback = fn (Session $session) => $session->getId();
if ($user->isHRM()) {
$idList = array_map($callback, $user->getDRHSessions());
} elseif ($user->isTeacher() || COURSEMANAGER === $user->getStatus()) {
$idListAsCoach = $user
->getSessionsByStatusInCourseSubscription(Session::COURSE_COACH)
->map($callback)
->getValues()
;
$idListAsGeneralCoach = array_map($callback, $user->getSessionsAsGeneralCoach());
$idList = array_merge($idListAsCoach, $idListAsGeneralCoach);
} elseif ($user->isSessionAdmin()) {
$idList = array_map($callback, $user->getSessionsAsAdmin());
} else {
$idList = array_map($callback, $user->getSessionsAsStudent());
}
$qb = $this->createQueryBuilder('s');
$qb
->innerJoin('s.urls', 'u')
->where($qb->expr()->eq('u.url', $url->getId()))
->andWhere($qb->expr()->in('s.id', ':id_list'))
->setParameter('id_list', $idList)
;
return $qb;
}
}

Loading…
Cancel
Save