Internal: Fix LP progress reminder query and add resend notification param - refs BT#22063

pull/5832/head
christianbeeznst 11 months ago
parent 412463657b
commit c059b8bcf2
  1. 27
      src/CoreBundle/Command/LpProgressReminderCommand.php
  2. 2
      src/CoreBundle/Repository/ExtraFieldValuesRepository.php
  3. 10
      src/CoreBundle/Repository/TrackEDefaultRepository.php

@ -26,6 +26,8 @@ class LpProgressReminderCommand extends Command
{
protected static $defaultName = 'app:lp-progress-reminder';
private const NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION = 3;
public function __construct(
private CourseRepository $courseRepository,
private CourseRelUserRepository $courseRelUserRepository,
@ -81,8 +83,9 @@ class LpProgressReminderCommand extends Command
$output->writeln('Processing course ID: ' . $courseId);
}
// Retrieve users for the course and session
$courseUsers = $this->courseRelUserRepository->getCourseUsers($courseId, array_keys($lpItems), false);
// Retrieve users for the course (without session)
$courseUsers = $this->courseRelUserRepository->getCourseUsers($courseId, array_keys($lpItems));
// Retrieve users for the course session
$sessionCourseUsers = $this->courseRelUserRepository->getCourseUsers($courseId, array_keys($lpItems), true);
if ($debugMode) {
@ -90,11 +93,11 @@ class LpProgressReminderCommand extends Command
$output->writeln('Session users retrieved: ' . count($sessionCourseUsers));
}
// Process users from the main course
$this->processCourseUsers($courseUsers, $lpItems, $courseId, $debugMode);
// Process users from the main course (sessionId = 0 or null)
$this->processCourseUsers($courseUsers, $lpItems, $courseId);
// Process users from the course session
$this->processCourseUsers($sessionCourseUsers, $lpItems, $courseId, $debugMode, true);
// Process users from the course session (sessionId > 0)
$this->processCourseUsers($sessionCourseUsers, $lpItems, $courseId, true);
}
$output->writeln('LP progress reminder process finished.');
@ -112,7 +115,13 @@ class LpProgressReminderCommand extends Command
$lpId = $user['lpId'];
$progress = (int) $user['progress'];
$nbDaysForLpCompletion = (int) $lpItems[$lpId]['ndays'];
$sessionId = $checkSession && isset($user['session_id']) ? $user['session_id'] : null;
if ($checkSession && isset($user['session_id']) && $user['session_id'] > 0) {
$sessionId = $user['session_id'];
} else {
$sessionId = 0;
}
$registrationDate = $this->trackEDefaultRepository->getUserCourseRegistrationAt($courseId, $userId, $sessionId);
if ($registrationDate && $this->isTimeToRemindUser($registrationDate, $nbDaysForLpCompletion)) {
@ -135,7 +144,7 @@ class LpProgressReminderCommand extends Command
$interval = $date1->diff($date2);
$diffDays = (int) $interval->format('%a');
return (int) ceil($diffDays / 3) + 1;
return (int) ceil($diffDays / self::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION) + 1;
}
/**
@ -153,7 +162,7 @@ class LpProgressReminderCommand extends Command
if ($startDate < $now) {
$interval = $date1->diff($date2);
$diffDays = (int) $interval->format('%a');
return (0 === $diffDays % 3);
return (0 === $diffDays % self::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION);
}
return $startDate === $now;

@ -9,6 +9,7 @@ namespace Chamilo\CoreBundle\Repository;
use Chamilo\CoreBundle\Entity\ExtraField;
use Chamilo\CoreBundle\Entity\ExtraFieldItemInterface;
use Chamilo\CoreBundle\Entity\ExtraFieldValues;
use Chamilo\CourseBundle\Entity\CLp;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\ORM\NonUniqueResultException;
use Doctrine\ORM\Query\Expr\Join;
@ -189,6 +190,7 @@ class ExtraFieldValuesRepository extends ServiceEntityRepository
$qb = $this->createQueryBuilder('efv')
->select('efv.itemId as lp_id, efv.fieldValue as ndays')
->innerJoin('efv.field', 'ef')
->innerJoin(CLp::class, 'lp', 'WITH', 'lp.iid = efv.itemId')
->where('ef.variable = :variable')
->andWhere('efv.fieldValue > 0')
->setParameter('variable', 'number_of_days_for_completion');

@ -40,8 +40,16 @@ class TrackEDefaultRepository extends ServiceEntityRepository
$qb->andWhere('te.sessionId = :sessionId')
->setParameter('sessionId', $sessionId);
}
else if ($sessionId === 0) {
$qb->andWhere('te.sessionId = 0');
}
else {
$qb->andWhere('te.sessionId IS NULL');
}
$result = $qb->getQuery()->getOneOrNullResult();
$qb->setMaxResults(1);
$query = $qb->getQuery();
$result = $query->getOneOrNullResult();
return $result ? $result['defaultDate'] : null;
}

Loading…
Cancel
Save