From 16c1312e95cb099767d61d628553a36fa583e629 Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Wed, 13 Nov 2024 23:07:42 -0500 Subject: [PATCH] Internal: Fix reminder logic to include users with null lpId - refs BT#22063 --- .../Command/LpProgressReminderCommand.php | 70 ++++++++++++++----- 1 file changed, 52 insertions(+), 18 deletions(-) diff --git a/src/CoreBundle/Command/LpProgressReminderCommand.php b/src/CoreBundle/Command/LpProgressReminderCommand.php index 55491f064c..bc549869bc 100644 --- a/src/CoreBundle/Command/LpProgressReminderCommand.php +++ b/src/CoreBundle/Command/LpProgressReminderCommand.php @@ -127,28 +127,62 @@ class LpProgressReminderCommand extends Command $lpId = $user['lpId']; $progress = (int) $user['progress']; - if (!isset($lpItems[$lpId])) { - continue; + if ($lpId === null) { + foreach ($lpItems as $lpId => $nbDaysForLpCompletion) { + $this->sendReminderIfNeeded( + $userId, + $courseTitle, + $courseId, + $sessionId ?? 0, + (int) $nbDaysForLpCompletion, + $debugMode, + $lpId, + $progress + ); + } + } else { + $nbDaysForLpCompletion = (int) ($lpItems[$lpId] ?? self::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION); + $this->sendReminderIfNeeded( + $userId, + $courseTitle, + $courseId, + $sessionId ?? 0, + $nbDaysForLpCompletion, + $debugMode, + $lpId, + $progress + ); } + } + } - $sessionId = $checkSession && isset($user['sessionId']) && $user['sessionId'] > 0 ? $user['sessionId'] : 0; - - $registrationDate = $this->trackEDefaultRepository->getUserCourseRegistrationAt($courseId, $userId, $sessionId); - $nbDaysForLpCompletion = (int) $lpItems[$lpId]; - - if ($registrationDate) { + /** + * Sends a progress reminder to a user if the conditions for reminder timing are met, + * based on their registration date and learning path completion criteria. + */ + private function sendReminderIfNeeded( + int $userId, + string $courseTitle, + int $courseId, + int $sessionId, + int $nbDaysForLpCompletion, + bool $debugMode, + ?int $lpId, + int $progress + ): void { + $registrationDate = $this->trackEDefaultRepository->getUserCourseRegistrationAt($courseId, $userId, $sessionId); + if ($registrationDate) { + if ($debugMode) { + $sessionInfo = $sessionId > 0 ? "in session ID $sessionId" : "without a session"; + echo "Registration date: {$registrationDate->format('Y-m-d H:i:s')}, Days for completion: $nbDaysForLpCompletion, LP ID: {$lpId}, $sessionInfo\n"; + } + if ($this->isTimeToRemindUser($registrationDate, $nbDaysForLpCompletion)) { + $nbRemind = $this->getNbReminder($registrationDate, $nbDaysForLpCompletion); if ($debugMode) { - $sessionInfo = $sessionId > 0 ? "in session ID $sessionId" : "without a session"; - echo "Registration date: {$registrationDate->format('Y-m-d H:i:s')}, Days for completion: $nbDaysForLpCompletion, LP ID: $lpId, $sessionInfo\n"; - } - if ($this->isTimeToRemindUser($registrationDate, $nbDaysForLpCompletion)) { - $nbRemind = $this->getNbReminder($registrationDate, $nbDaysForLpCompletion); - if ($debugMode) { - echo "Sending reminder to user $userId for course $courseTitle (LP ID: $lpId) $sessionInfo\n"; - $this->logReminderSent($userId, $courseTitle, $nbRemind, $debugMode, $lpId, $sessionId); - } - $this->sendLpReminder($userId, $courseTitle, $progress, $registrationDate, $nbRemind); + echo "Sending reminder to user $userId for course $courseTitle (LP ID: {$lpId}) $sessionInfo\n"; + $this->logReminderSent($userId, $courseTitle, $nbRemind, $debugMode, $lpId, $sessionId); } + $this->sendLpReminder($userId, $courseTitle, $progress, $registrationDate, $nbRemind); } } }