Internal: Implement automatic session repetition and coach notifications - refs BT#22057

pull/5831/head
Christian Beeznest 9 months ago
parent 8f8fa4f161
commit 7b665990e7
  1. 20
      src/CoreBundle/Command/ReinscriptionCheckCommand.php
  2. 6
      src/CoreBundle/Command/SessionRepetitionCommand.php
  3. 7
      src/CoreBundle/Repository/SessionRepository.php

@ -62,6 +62,14 @@ class ReinscriptionCheckCommand extends Command
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) {
@ -171,4 +179,16 @@ class ReinscriptionCheckCommand extends Command
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;
}
}

@ -105,7 +105,7 @@ class SessionRepetitionCommand extends Command
->setCoachAccessStartDate($newStartDate)
->setCoachAccessEndDate($newEndDate)
->setVisibility($session->getVisibility())
->setDuration($duration)
->setDuration(0)
->setDescription($session->getDescription() ?? '')
->setShowDescription($session->getShowDescription() ?? false)
->setCategory($session->getCategory())
@ -123,7 +123,9 @@ class SessionRepetitionCommand extends Command
// 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

@ -559,7 +559,12 @@ class SessionRepository extends ServiceEntityRepository
->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);

Loading…
Cancel
Save