15
15
use Chamilo \CoreBundle \ServiceHelper \MessageHelper ;
16
16
use DateTime ;
17
17
use DateTimeZone ;
18
- use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
19
- use Symfony \Contracts \Translation \TranslatorInterface ;
20
- use Twig \Environment ;
18
+ use Exception ;
21
19
use Symfony \Component \Console \Command \Command ;
22
20
use Symfony \Component \Console \Input \InputInterface ;
23
21
use Symfony \Component \Console \Input \InputOption ;
24
22
use Symfony \Component \Console \Output \OutputInterface ;
23
+ use Symfony \Component \Routing \Generator \UrlGeneratorInterface ;
24
+ use Symfony \Contracts \Translation \TranslatorInterface ;
25
+ use Twig \Environment ;
25
26
26
27
class LpProgressReminderCommand extends Command
27
28
{
@@ -44,8 +45,7 @@ public function __construct(
44
45
parent ::__construct ();
45
46
}
46
47
47
-
48
- protected function configure ()
48
+ protected function configure (): void
49
49
{
50
50
$ this
51
51
->setDescription ('Send LP progress reminders to users based on "number_of_days_for_completion". ' )
@@ -54,7 +54,8 @@ protected function configure()
54
54
null ,
55
55
InputOption::VALUE_NONE ,
56
56
'If set, will output detailed debug information '
57
- );
57
+ )
58
+ ;
58
59
}
59
60
60
61
protected function execute (InputInterface $ input , OutputInterface $ output ): int
@@ -65,11 +66,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
65
66
// Retrieve LPs with completion days
66
67
$ lpItems = $ this ->extraFieldValuesRepository ->getLpIdWithDaysForCompletion ();
67
68
if ($ debugMode && !empty ($ lpItems )) {
68
- $ output ->writeln ('LP Items retrieved: ' . print_r ($ lpItems , true ));
69
+ $ output ->writeln ('LP Items retrieved: ' . print_r ($ lpItems , true ));
69
70
}
70
71
71
72
if (empty ($ lpItems )) {
72
73
$ output ->writeln ('No learning paths with days for completion found. ' );
74
+
73
75
return Command::SUCCESS ;
74
76
}
75
77
@@ -82,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
82
84
// Retrieve all courses from the CourseRepository
83
85
$ courses = $ this ->courseRepository ->findAll ();
84
86
if ($ debugMode && !empty ($ courses )) {
85
- $ output ->writeln ('Courses retrieved: ' . count ($ courses ));
87
+ $ output ->writeln ('Courses retrieved: ' . \ count ($ courses ));
86
88
}
87
89
88
90
foreach ($ courses as $ course ) {
@@ -94,14 +96,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
94
96
$ sessionCourseUsers = $ this ->sessionRelCourseRelUserRepository ->getSessionCourseUsers ($ courseId , $ lpIds );
95
97
96
98
if ($ debugMode && (!empty ($ courseUsers ) || !empty ($ sessionCourseUsers ))) {
97
- $ output ->writeln ('Processing course ID: ' . $ courseId );
99
+ $ output ->writeln ('Processing course ID: ' . $ courseId );
98
100
if (!empty ($ courseUsers )) {
99
- $ output ->writeln ('Course users retrieved: ' . count ($ courseUsers ));
100
- //$output->writeln('Course retrieved: ' . print_r($courseUsers, true));
101
+ $ output ->writeln ('Course users retrieved: ' . \ count ($ courseUsers ));
102
+ // $output->writeln('Course retrieved: ' . print_r($courseUsers, true));
101
103
}
102
104
if (!empty ($ sessionCourseUsers )) {
103
- $ output ->writeln ('Session users retrieved: ' . count ($ sessionCourseUsers ));
104
- //$output->writeln('Session retrieved: ' . print_r($sessionCourseUsers, true));
105
+ $ output ->writeln ('Session users retrieved: ' . \ count ($ sessionCourseUsers ));
106
+ // $output->writeln('Session retrieved: ' . print_r($sessionCourseUsers, true));
105
107
}
106
108
}
107
109
@@ -113,6 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
113
115
}
114
116
115
117
$ output ->writeln ('LP progress reminder process finished. ' );
118
+
116
119
return Command::SUCCESS ;
117
120
}
118
121
@@ -129,7 +132,7 @@ private function processCourseUsers(array $users, array $lpItems, int $courseId,
129
132
130
133
$ sessionId = $ checkSession ? ($ user ['sessionId ' ] ?? 0 ) : 0 ;
131
134
132
- if ($ lpId === null ) {
135
+ if (null === $ lpId ) {
133
136
foreach ($ lpItems as $ lpId => $ nbDaysForLpCompletion ) {
134
137
$ this ->sendReminderIfNeeded (
135
138
$ userId ,
@@ -177,11 +180,12 @@ private function sendReminderIfNeeded(
177
180
if ($ debugMode ) {
178
181
echo "No registration date found for user $ userId in course $ courseId (session ID: $ sessionId). \n" ;
179
182
}
183
+
180
184
return ;
181
185
}
182
186
183
187
if ($ debugMode ) {
184
- $ sessionInfo = $ sessionId > 0 ? "in session ID $ sessionId " : " without a session " ;
188
+ $ sessionInfo = $ sessionId > 0 ? "in session ID $ sessionId " : ' without a session ' ;
185
189
echo "Registration date: {$ registrationDate ->format ('Y-m-d H:i:s ' )}, Days for completion: $ nbDaysForLpCompletion, LP ID: {$ lpId }, $ sessionInfo \n" ;
186
190
}
187
191
@@ -202,8 +206,8 @@ private function sendReminderIfNeeded(
202
206
private function logReminderSent (int $ userId , string $ courseTitle , int $ nbRemind , bool $ debugMode , int $ lpId , int $ sessionId = 0 ): void
203
207
{
204
208
if ($ debugMode ) {
205
- $ sessionInfo = $ sessionId > 0 ? sprintf (" in session ID %d " , $ sessionId ) : " without a session " ;
206
- echo sprintf (
209
+ $ sessionInfo = $ sessionId > 0 ? \ sprintf (' in session ID %d ' , $ sessionId ) : ' without a session ' ;
210
+ echo \ sprintf (
207
211
"Reminder number %d sent to user ID %d for the course %s (LP ID: %d) %s. \n" ,
208
212
$ nbRemind ,
209
213
$ userId ,
@@ -244,19 +248,18 @@ private function isTimeToRemindUser(DateTime $registrationDate, int $nbDaysForLp
244
248
$ interval = $ reminderStartDate ->diff ($ currentDate );
245
249
$ diffDays = (int ) $ interval ->format ('%a ' );
246
250
247
- return ($ diffDays >= self ::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION &&
248
- $ diffDays % self ::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION === 0 ) || $ diffDays === 0 ;
251
+ return ($ diffDays >= self ::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION
252
+ && 0 === $ diffDays % self ::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION ) || 0 === $ diffDays ;
249
253
}
250
254
251
-
252
255
/**
253
256
* Sends a reminder email to the user regarding their LP progress.
254
257
*/
255
258
private function sendLpReminder (int $ toUserId , string $ courseName , int $ lpProgress , DateTime $ registrationDate , int $ nbRemind ): bool
256
259
{
257
260
$ user = $ this ->userRepository ->find ($ toUserId );
258
261
if (!$ user ) {
259
- throw new \ Exception (" User not found " );
262
+ throw new Exception (' User not found ' );
260
263
}
261
264
262
265
$ platformUrl = $ this ->urlGenerator ->generate ('index ' , [], UrlGeneratorInterface::ABSOLUTE_URL );
@@ -265,17 +268,17 @@ private function sendLpReminder(int $toUserId, string $courseName, int $lpProgre
265
268
$ trainingCenterName = 'Your Training Center ' ;
266
269
$ trainers = 'Trainer Name ' ;
267
270
268
- $ hello = $ this ->translator ->trans (" Hello %s " );
269
- $ youAreRegCourse = $ this ->translator ->trans (" You are registered in the training %s since the %s " );
270
- $ thisMessageIsAbout = $ this ->translator ->trans (" You are receiving this message because you have completed a learning path with a %s progress of your training.<br/>Your progress must be 100 to consider that your training was carried out.<br/>If you have the slightest problem, you should contact with your trainer. " );
271
+ $ hello = $ this ->translator ->trans (' Hello %s ' );
272
+ $ youAreRegCourse = $ this ->translator ->trans (' You are registered in the training %s since the %s ' );
273
+ $ thisMessageIsAbout = $ this ->translator ->trans (' You are receiving this message because you have completed a learning path with a %s progress of your training.<br/>Your progress must be 100 to consider that your training was carried out.<br/>If you have the slightest problem, you should contact with your trainer. ' );
271
274
$ stepsToRemind = $ this ->translator ->trans ("As a reminder, to access the training platform:<br/>1. Connect to the platform at the address: %s <br/>2. Then enter: <br/>Your username: %s <br/>Your password: This was emailed to you.<br/>if you forgot it and can't find it, you can retrieve it by going to %s <br/><br/>Thank you for doing what is necessary. " );
272
- $ lpRemindFooter = $ this ->translator ->trans (" The training center<p>%s</p>Trainers:<br/>%s " );
275
+ $ lpRemindFooter = $ this ->translator ->trans (' The training center<p>%s</p>Trainers:<br/>%s ' );
273
276
274
- $ hello = sprintf ($ hello , $ user ->getFullName ());
275
- $ youAreRegCourse = sprintf ($ youAreRegCourse , $ courseName , $ registrationDate ->format ('Y-m-d ' ));
276
- $ thisMessageIsAbout = sprintf ($ thisMessageIsAbout , $ lpProgress );
277
- $ stepsToRemind = sprintf ($ stepsToRemind , $ platformUrl , $ user ->getUsername (), $ recoverPasswordUrl );
278
- $ lpRemindFooter = sprintf ($ lpRemindFooter , $ trainingCenterName , $ trainers );
277
+ $ hello = \ sprintf ($ hello , $ user ->getFullName ());
278
+ $ youAreRegCourse = \ sprintf ($ youAreRegCourse , $ courseName , $ registrationDate ->format ('Y-m-d ' ));
279
+ $ thisMessageIsAbout = \ sprintf ($ thisMessageIsAbout , $ lpProgress );
280
+ $ stepsToRemind = \ sprintf ($ stepsToRemind , $ platformUrl , $ user ->getUsername (), $ recoverPasswordUrl );
281
+ $ lpRemindFooter = \ sprintf ($ lpRemindFooter , $ trainingCenterName , $ trainers );
279
282
280
283
$ messageContent = $ this ->twig ->render ('@ChamiloCore/Mailer/Legacy/lp_progress_reminder_body.html.twig ' , [
281
284
'HelloX ' => $ hello ,
@@ -288,13 +291,13 @@ private function sendLpReminder(int $toUserId, string $courseName, int $lpProgre
288
291
try {
289
292
$ this ->messageHelper ->sendMessageSimple (
290
293
$ toUserId ,
291
- sprintf (" Reminder number %d for the course %s " , $ nbRemind , $ courseName ),
294
+ \ sprintf (' Reminder number %d for the course %s ' , $ nbRemind , $ courseName ),
292
295
$ messageContent
293
296
);
294
297
295
298
return true ;
296
- } catch (\ Exception $ e ) {
297
- throw new \ Exception ('Error sending reminder: ' . $ e ->getMessage ());
299
+ } catch (Exception $ e ) {
300
+ throw new Exception ('Error sending reminder: ' . $ e ->getMessage ());
298
301
}
299
302
}
300
303
}
0 commit comments