Skip to content

Commit

Permalink
Internal: Implement automatic session repetition and coach notificati…
Browse files Browse the repository at this point in the history
…ons - refs BT#22057
  • Loading branch information
christianbeeznest committed Dec 4, 2024
1 parent 8f8fa4f commit 7b66599
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
20 changes: 20 additions & 0 deletions src/CoreBundle/Command/ReinscriptionCheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
foreach ($expiredViews as $view) {
$user = $view->getUser();
$session = $view->getSession();

if ($this->isUserAlreadyEnrolledInChildSession($user, $session)) {
if ($debug) {
$output->writeln(sprintf('User %d is already enrolled in a valid child session.', $user->getId()));
}
continue;
}

$lp = $view->getLp();

if ($debug) {
Expand Down Expand Up @@ -171,4 +179,16 @@ private function findValidSessionInHierarchy(Session $session): ?Session
return null;
}

private function isUserAlreadyEnrolledInChildSession($user, $parentSession): bool
{
$childSessions = $this->sessionRepository->findChildSessions($parentSession);

foreach ($childSessions as $childSession) {
if ($this->findUserSubscriptionInSession($user, $childSession)) {
return true;
}
}

return false;
}
}
6 changes: 4 additions & 2 deletions src/CoreBundle/Command/SessionRepetitionCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private function duplicateSession(Session $session, bool $debug, OutputInterface
->setCoachAccessStartDate($newStartDate)
->setCoachAccessEndDate($newEndDate)
->setVisibility($session->getVisibility())
->setDuration($duration)
->setDuration(0)
->setDescription($session->getDescription() ?? '')
->setShowDescription($session->getShowDescription() ?? false)
->setCategory($session->getCategory())
Expand All @@ -123,7 +123,9 @@ private function duplicateSession(Session $session, bool $debug, OutputInterface
// Copy the courses from the original session
foreach ($session->getCourses() as $sessionRelCourse) {
$course = $sessionRelCourse->getCourse();
$newSession->addCourse($course);
if ($course) {
$newSession->addCourse($course);
}
}

// Copy the general coaches from the original session
Expand Down
7 changes: 6 additions & 1 deletion src/CoreBundle/Repository/SessionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,12 @@ public function findSessionsWithoutChildAndReadyForRepetition()
->andWhere('s.daysToNewRepetition IS NOT NULL')
->andWhere('s.lastRepetition = :false')
->andWhere(':currentDate BETWEEN DATE_SUB(s.accessEndDate, s.daysToNewRepetition, \'DAY\') AND s.accessEndDate')
->andWhere('NOT EXISTS (SELECT 1 FROM Chamilo\CoreBundle\Entity\Session child WHERE child.parentId = s.id)')
->andWhere('NOT EXISTS (
SELECT 1
FROM Chamilo\CoreBundle\Entity\Session child
WHERE child.parentId = s.id
AND child.accessEndDate >= :currentDate
)')
->setParameter('false', false)
->setParameter('currentDate', $currentDate);

Expand Down

0 comments on commit 7b66599

Please sign in to comment.