Skip to content

Commit 2fb5d4c

Browse files
committed
Minor: Format code
1 parent 518ef60 commit 2fb5d4c

13 files changed

+86
-69
lines changed

src/CoreBundle/Command/LpProgressReminderCommand.php

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
use Chamilo\CoreBundle\ServiceHelper\MessageHelper;
1616
use DateTime;
1717
use DateTimeZone;
18-
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
19-
use Symfony\Contracts\Translation\TranslatorInterface;
20-
use Twig\Environment;
18+
use Exception;
2119
use Symfony\Component\Console\Command\Command;
2220
use Symfony\Component\Console\Input\InputInterface;
2321
use Symfony\Component\Console\Input\InputOption;
2422
use Symfony\Component\Console\Output\OutputInterface;
23+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
24+
use Symfony\Contracts\Translation\TranslatorInterface;
25+
use Twig\Environment;
2526

2627
class LpProgressReminderCommand extends Command
2728
{
@@ -44,8 +45,7 @@ public function __construct(
4445
parent::__construct();
4546
}
4647

47-
48-
protected function configure()
48+
protected function configure(): void
4949
{
5050
$this
5151
->setDescription('Send LP progress reminders to users based on "number_of_days_for_completion".')
@@ -54,7 +54,8 @@ protected function configure()
5454
null,
5555
InputOption::VALUE_NONE,
5656
'If set, will output detailed debug information'
57-
);
57+
)
58+
;
5859
}
5960

6061
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -65,11 +66,12 @@ protected function execute(InputInterface $input, OutputInterface $output): int
6566
// Retrieve LPs with completion days
6667
$lpItems = $this->extraFieldValuesRepository->getLpIdWithDaysForCompletion();
6768
if ($debugMode && !empty($lpItems)) {
68-
$output->writeln('LP Items retrieved: ' . print_r($lpItems, true));
69+
$output->writeln('LP Items retrieved: '.print_r($lpItems, true));
6970
}
7071

7172
if (empty($lpItems)) {
7273
$output->writeln('No learning paths with days for completion found.');
74+
7375
return Command::SUCCESS;
7476
}
7577

@@ -82,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8284
// Retrieve all courses from the CourseRepository
8385
$courses = $this->courseRepository->findAll();
8486
if ($debugMode && !empty($courses)) {
85-
$output->writeln('Courses retrieved: ' . count($courses));
87+
$output->writeln('Courses retrieved: '.\count($courses));
8688
}
8789

8890
foreach ($courses as $course) {
@@ -94,14 +96,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
9496
$sessionCourseUsers = $this->sessionRelCourseRelUserRepository->getSessionCourseUsers($courseId, $lpIds);
9597

9698
if ($debugMode && (!empty($courseUsers) || !empty($sessionCourseUsers))) {
97-
$output->writeln('Processing course ID: ' . $courseId);
99+
$output->writeln('Processing course ID: '.$courseId);
98100
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));
101103
}
102104
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));
105107
}
106108
}
107109

@@ -113,6 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
113115
}
114116

115117
$output->writeln('LP progress reminder process finished.');
118+
116119
return Command::SUCCESS;
117120
}
118121

@@ -129,7 +132,7 @@ private function processCourseUsers(array $users, array $lpItems, int $courseId,
129132

130133
$sessionId = $checkSession ? ($user['sessionId'] ?? 0) : 0;
131134

132-
if ($lpId === null) {
135+
if (null === $lpId) {
133136
foreach ($lpItems as $lpId => $nbDaysForLpCompletion) {
134137
$this->sendReminderIfNeeded(
135138
$userId,
@@ -177,11 +180,12 @@ private function sendReminderIfNeeded(
177180
if ($debugMode) {
178181
echo "No registration date found for user $userId in course $courseId (session ID: $sessionId).\n";
179182
}
183+
180184
return;
181185
}
182186

183187
if ($debugMode) {
184-
$sessionInfo = $sessionId > 0 ? "in session ID $sessionId" : "without a session";
188+
$sessionInfo = $sessionId > 0 ? "in session ID $sessionId" : 'without a session';
185189
echo "Registration date: {$registrationDate->format('Y-m-d H:i:s')}, Days for completion: $nbDaysForLpCompletion, LP ID: {$lpId}, $sessionInfo\n";
186190
}
187191

@@ -202,8 +206,8 @@ private function sendReminderIfNeeded(
202206
private function logReminderSent(int $userId, string $courseTitle, int $nbRemind, bool $debugMode, int $lpId, int $sessionId = 0): void
203207
{
204208
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(
207211
"Reminder number %d sent to user ID %d for the course %s (LP ID: %d) %s.\n",
208212
$nbRemind,
209213
$userId,
@@ -244,19 +248,18 @@ private function isTimeToRemindUser(DateTime $registrationDate, int $nbDaysForLp
244248
$interval = $reminderStartDate->diff($currentDate);
245249
$diffDays = (int) $interval->format('%a');
246250

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;
249253
}
250254

251-
252255
/**
253256
* Sends a reminder email to the user regarding their LP progress.
254257
*/
255258
private function sendLpReminder(int $toUserId, string $courseName, int $lpProgress, DateTime $registrationDate, int $nbRemind): bool
256259
{
257260
$user = $this->userRepository->find($toUserId);
258261
if (!$user) {
259-
throw new \Exception("User not found");
262+
throw new Exception('User not found');
260263
}
261264

262265
$platformUrl = $this->urlGenerator->generate('index', [], UrlGeneratorInterface::ABSOLUTE_URL);
@@ -265,17 +268,17 @@ private function sendLpReminder(int $toUserId, string $courseName, int $lpProgre
265268
$trainingCenterName = 'Your Training Center';
266269
$trainers = 'Trainer Name';
267270

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.');
271274
$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');
273276

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);
279282

280283
$messageContent = $this->twig->render('@ChamiloCore/Mailer/Legacy/lp_progress_reminder_body.html.twig', [
281284
'HelloX' => $hello,
@@ -288,13 +291,13 @@ private function sendLpReminder(int $toUserId, string $courseName, int $lpProgre
288291
try {
289292
$this->messageHelper->sendMessageSimple(
290293
$toUserId,
291-
sprintf("Reminder number %d for the course %s", $nbRemind, $courseName),
294+
\sprintf('Reminder number %d for the course %s', $nbRemind, $courseName),
292295
$messageContent
293296
);
294297

295298
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());
298301
}
299302
}
300303
}

src/CoreBundle/Command/SendEventRemindersCommand.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ protected function configure(): void
4747
$this
4848
->setDescription('Send notification messages to users that have reminders from events in their agenda.')
4949
->addOption('debug', null, InputOption::VALUE_NONE, 'Enable debug mode')
50-
->setHelp('This command sends notifications to users who have pending reminders for calendar events.');
50+
->setHelp('This command sends notifications to users who have pending reminders for calendar events.')
51+
;
5152
}
5253

5354
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -127,6 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
127128
$this->sendReminderMessage($user, $event, $senderId, $debug, $io, $sentRemindersCount);
128129
}
129130
}
131+
130132
break;
131133

132134
case 'course':
@@ -146,6 +148,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
146148
if ($debug) {
147149
error_log("No course found for resource link in session ID: {$session->getId()}");
148150
}
151+
149152
break;
150153
}
151154

src/CoreBundle/Controller/CourseController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ public function getAutoLaunchExerciseId(
784784
public function getAutoLaunchLPId(
785785
Request $request,
786786
Course $course,
787-
CLPRepository $lpRepository,
787+
CLpRepository $lpRepository,
788788
EntityManagerInterface $em
789789
): JsonResponse {
790790
$data = $request->getContent();

src/CoreBundle/Entity/ExtraField.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
denormalizationContext: [
3535
'groups' => ['extra_field:write'],
3636
],
37-
security: "is_granted('ROLE_ADMIN')"),
37+
security: "is_granted('ROLE_ADMIN')"
38+
),
3839
]
3940
#[ORM\Table(name: 'extra_field')]
4041
#[ORM\Entity]

src/CoreBundle/Migrations/Schema/V200/Version20230913162700.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ private function createNewDocument($videoPath, $courseId)
210210
$existingDocument = $documentRepo->findResourceByTitleInCourse($title, $course);
211211
if ($existingDocument) {
212212
error_log("Document '$title' already exists for course {$course->getId()}. Skipping creation.");
213+
213214
return $existingDocument;
214215
}
215216

@@ -230,6 +231,7 @@ private function createNewDocument($videoPath, $courseId)
230231
$documentRepo->addFileFromPath($document, $title, $appCourseOldPath);
231232

232233
error_log("Document '$title' successfully created for course $courseId.");
234+
233235
return $document;
234236
}
235237
$generalCoursesPath = $this->getUpdateRootPath().'/app/courses/';
@@ -255,9 +257,10 @@ private function createNewDocument($videoPath, $courseId)
255257
}
256258

257259
error_log("File '$title' not found for course $courseId. Skipping.");
260+
258261
return null;
259262
} catch (Exception $e) {
260-
error_log('Error in createNewDocument: ' . $e->getMessage());
263+
error_log('Error in createNewDocument: '.$e->getMessage());
261264

262265
return null;
263266
}

src/CoreBundle/Migrations/Schema/V200/Version20231022124700.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
use Doctrine\DBAL\Schema\Schema;
1313
use Exception;
1414

15-
use const PREG_NO_ERROR;
16-
1715
final class Version20231022124700 extends AbstractMigrationChamilo
1816
{
1917
public function getDescription(): string
@@ -123,7 +121,8 @@ function ($matches) {
123121
$code = $matches[5] ?? null;
124122

125123
if (!$code) {
126-
error_log('Missing cidReq in URL: ' . $matches[0]);
124+
error_log('Missing cidReq in URL: '.$matches[0]);
125+
127126
return $matches[0];
128127
}
129128

@@ -137,7 +136,8 @@ function ($matches) {
137136
}
138137

139138
if (null === $courseId) {
140-
error_log('Course ID not found for cidReq: ' . $code);
139+
error_log('Course ID not found for cidReq: '.$code);
140+
141141
return $matches[0];
142142
}
143143

@@ -152,7 +152,7 @@ function ($matches) {
152152

153153
// Ensure other parameters are maintained
154154
if (!empty($remainingParams)) {
155-
$newParams .= '&' . ltrim($remainingParams, '&amp;');
155+
$newParams .= '&'.ltrim($remainingParams, '&amp;');
156156
}
157157

158158
$finalUrl = $matches[1].'?'.$beforeCidReqParams.$newParams;
@@ -163,11 +163,13 @@ function ($matches) {
163163
);
164164

165165
if (false === $newContent || null === $newContent) {
166-
error_log('preg_replace_callback failed for content: ' . substr($content, 0, 500));
166+
error_log('preg_replace_callback failed for content: '.substr($content, 0, 500));
167+
167168
return $content;
168169
}
169170
} catch (Exception $e) {
170-
error_log('Exception in replaceURLParametersInContent: ' . $e->getMessage());
171+
error_log('Exception in replaceURLParametersInContent: '.$e->getMessage());
172+
171173
return $content;
172174
}
173175

src/CoreBundle/Migrations/Schema/V200/Version20241209103000.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,18 @@
1111

1212
class Version20241209103000 extends AbstractMigrationChamilo
1313
{
14-
1514
public function getDescription(): string
1615
{
17-
return "Change extra field boolean columns (visible_to_self, visible_to_others, changeable, filter) to not accept null values.";
16+
return 'Change extra field boolean columns (visible_to_self, visible_to_others, changeable, filter) to not accept null values.';
1817
}
1918

20-
/**
21-
* @inheritDoc
22-
*/
2319
public function up(Schema $schema): void
2420
{
25-
$this->addSql("UPDATE extra_field SET visible_to_self = 0 WHERE visible_to_self IS NULL");
26-
$this->addSql("UPDATE extra_field SET visible_to_others = 0 WHERE visible_to_others IS NULL");
27-
$this->addSql("UPDATE extra_field SET changeable = 0 WHERE changeable IS NULL");
28-
$this->addSql("UPDATE extra_field SET filter = 0 WHERE filter IS NULL");
21+
$this->addSql('UPDATE extra_field SET visible_to_self = 0 WHERE visible_to_self IS NULL');
22+
$this->addSql('UPDATE extra_field SET visible_to_others = 0 WHERE visible_to_others IS NULL');
23+
$this->addSql('UPDATE extra_field SET changeable = 0 WHERE changeable IS NULL');
24+
$this->addSql('UPDATE extra_field SET filter = 0 WHERE filter IS NULL');
2925

30-
$this->addSql("ALTER TABLE extra_field CHANGE visible_to_self visible_to_self TINYINT(1) DEFAULT 0 NOT NULL, CHANGE visible_to_others visible_to_others TINYINT(1) DEFAULT 0 NOT NULL, CHANGE changeable changeable TINYINT(1) DEFAULT 0 NOT NULL, CHANGE filter filter TINYINT(1) DEFAULT 0 NOT NULL");
26+
$this->addSql('ALTER TABLE extra_field CHANGE visible_to_self visible_to_self TINYINT(1) DEFAULT 0 NOT NULL, CHANGE visible_to_others visible_to_others TINYINT(1) DEFAULT 0 NOT NULL, CHANGE changeable changeable TINYINT(1) DEFAULT 0 NOT NULL, CHANGE filter filter TINYINT(1) DEFAULT 0 NOT NULL');
3127
}
32-
}
28+
}

src/CoreBundle/Repository/CourseRelUserRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function getCourseUsers(int $courseId, array $lpIds): array
3535
->andWhere('rn.parent = c.resourceNode')
3636
->andWhere('(lpv.progress < 100 OR lpv.progress IS NULL)')
3737
->setParameter('courseId', $courseId)
38-
->setParameter('lpIds', $lpIds);
38+
->setParameter('lpIds', $lpIds)
39+
;
3940

4041
return $qb->getQuery()->getResult();
4142
}

src/CoreBundle/Repository/ExtraFieldValuesRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ public function getLpIdWithDaysForCompletion(): array
193193
->innerJoin(CLp::class, 'lp', 'WITH', 'lp.iid = efv.itemId')
194194
->where('ef.variable = :variable')
195195
->andWhere('efv.fieldValue > 0')
196-
->setParameter('variable', 'number_of_days_for_completion');
196+
->setParameter('variable', 'number_of_days_for_completion')
197+
;
197198

198199
return $qb->getQuery()->getResult();
199200
}

src/CoreBundle/Repository/SessionRelCourseRelUserRepository.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ public function getSessionCourseUsers(int $courseId, array $lpIds): array
3535
->andWhere('rn.parent = c.resourceNode')
3636
->andWhere('(lpv.progress < 100 OR lpv.progress IS NULL)')
3737
->setParameter('courseId', $courseId)
38-
->setParameter('lpIds', $lpIds);
38+
->setParameter('lpIds', $lpIds)
39+
;
3940

4041
return $qb->getQuery()->getResult();
4142
}

0 commit comments

Comments
 (0)