Minor: Format code

pull/5949/head
Angel Fernando Quiroz Campos 9 months ago
parent 518ef60dda
commit 2fb5d4c29e
No known key found for this signature in database
GPG Key ID: B284841AE3E562CD
  1. 69
      src/CoreBundle/Command/LpProgressReminderCommand.php
  2. 5
      src/CoreBundle/Command/SendEventRemindersCommand.php
  3. 2
      src/CoreBundle/Controller/CourseController.php
  4. 3
      src/CoreBundle/Entity/ExtraField.php
  5. 5
      src/CoreBundle/Migrations/Schema/V200/Version20230913162700.php
  6. 16
      src/CoreBundle/Migrations/Schema/V200/Version20231022124700.php
  7. 18
      src/CoreBundle/Migrations/Schema/V200/Version20241209103000.php
  8. 3
      src/CoreBundle/Repository/CourseRelUserRepository.php
  9. 3
      src/CoreBundle/Repository/ExtraFieldValuesRepository.php
  10. 3
      src/CoreBundle/Repository/SessionRelCourseRelUserRepository.php
  11. 22
      src/CoreBundle/Repository/TrackEDefaultRepository.php
  12. 3
      src/CourseBundle/Repository/CLpRepository.php
  13. 3
      src/CourseBundle/Repository/CQuizRepository.php

@ -15,13 +15,14 @@ use Chamilo\CoreBundle\Repository\TrackEDefaultRepository;
use Chamilo\CoreBundle\ServiceHelper\MessageHelper;
use DateTime;
use DateTimeZone;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
use Exception;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Twig\Environment;
class LpProgressReminderCommand extends Command
{
@ -44,8 +45,7 @@ class LpProgressReminderCommand extends Command
parent::__construct();
}
protected function configure()
protected function configure(): void
{
$this
->setDescription('Send LP progress reminders to users based on "number_of_days_for_completion".')
@ -54,7 +54,8 @@ class LpProgressReminderCommand extends Command
null,
InputOption::VALUE_NONE,
'If set, will output detailed debug information'
);
)
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
@ -65,11 +66,12 @@ class LpProgressReminderCommand extends Command
// Retrieve LPs with completion days
$lpItems = $this->extraFieldValuesRepository->getLpIdWithDaysForCompletion();
if ($debugMode && !empty($lpItems)) {
$output->writeln('LP Items retrieved: ' . print_r($lpItems, true));
$output->writeln('LP Items retrieved: '.print_r($lpItems, true));
}
if (empty($lpItems)) {
$output->writeln('No learning paths with days for completion found.');
return Command::SUCCESS;
}
@ -82,7 +84,7 @@ class LpProgressReminderCommand extends Command
// Retrieve all courses from the CourseRepository
$courses = $this->courseRepository->findAll();
if ($debugMode && !empty($courses)) {
$output->writeln('Courses retrieved: ' . count($courses));
$output->writeln('Courses retrieved: '.\count($courses));
}
foreach ($courses as $course) {
@ -94,14 +96,14 @@ class LpProgressReminderCommand extends Command
$sessionCourseUsers = $this->sessionRelCourseRelUserRepository->getSessionCourseUsers($courseId, $lpIds);
if ($debugMode && (!empty($courseUsers) || !empty($sessionCourseUsers))) {
$output->writeln('Processing course ID: ' . $courseId);
$output->writeln('Processing course ID: '.$courseId);
if (!empty($courseUsers)) {
$output->writeln('Course users retrieved: ' . count($courseUsers));
//$output->writeln('Course retrieved: ' . print_r($courseUsers, true));
$output->writeln('Course users retrieved: '.\count($courseUsers));
// $output->writeln('Course retrieved: ' . print_r($courseUsers, true));
}
if (!empty($sessionCourseUsers)) {
$output->writeln('Session users retrieved: ' . count($sessionCourseUsers));
//$output->writeln('Session retrieved: ' . print_r($sessionCourseUsers, true));
$output->writeln('Session users retrieved: '.\count($sessionCourseUsers));
// $output->writeln('Session retrieved: ' . print_r($sessionCourseUsers, true));
}
}
@ -113,6 +115,7 @@ class LpProgressReminderCommand extends Command
}
$output->writeln('LP progress reminder process finished.');
return Command::SUCCESS;
}
@ -129,7 +132,7 @@ class LpProgressReminderCommand extends Command
$sessionId = $checkSession ? ($user['sessionId'] ?? 0) : 0;
if ($lpId === null) {
if (null === $lpId) {
foreach ($lpItems as $lpId => $nbDaysForLpCompletion) {
$this->sendReminderIfNeeded(
$userId,
@ -177,11 +180,12 @@ class LpProgressReminderCommand extends Command
if ($debugMode) {
echo "No registration date found for user $userId in course $courseId (session ID: $sessionId).\n";
}
return;
}
if ($debugMode) {
$sessionInfo = $sessionId > 0 ? "in session ID $sessionId" : "without a session";
$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";
}
@ -202,8 +206,8 @@ class LpProgressReminderCommand extends Command
private function logReminderSent(int $userId, string $courseTitle, int $nbRemind, bool $debugMode, int $lpId, int $sessionId = 0): void
{
if ($debugMode) {
$sessionInfo = $sessionId > 0 ? sprintf("in session ID %d", $sessionId) : "without a session";
echo sprintf(
$sessionInfo = $sessionId > 0 ? \sprintf('in session ID %d', $sessionId) : 'without a session';
echo \sprintf(
"Reminder number %d sent to user ID %d for the course %s (LP ID: %d) %s.\n",
$nbRemind,
$userId,
@ -244,11 +248,10 @@ class LpProgressReminderCommand extends Command
$interval = $reminderStartDate->diff($currentDate);
$diffDays = (int) $interval->format('%a');
return ($diffDays >= self::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION &&
$diffDays % self::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION === 0) || $diffDays === 0;
return ($diffDays >= self::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION
&& 0 === $diffDays % self::NUMBER_OF_DAYS_TO_RESEND_NOTIFICATION) || 0 === $diffDays;
}
/**
* Sends a reminder email to the user regarding their LP progress.
*/
@ -256,7 +259,7 @@ class LpProgressReminderCommand extends Command
{
$user = $this->userRepository->find($toUserId);
if (!$user) {
throw new \Exception("User not found");
throw new Exception('User not found');
}
$platformUrl = $this->urlGenerator->generate('index', [], UrlGeneratorInterface::ABSOLUTE_URL);
@ -265,17 +268,17 @@ class LpProgressReminderCommand extends Command
$trainingCenterName = 'Your Training Center';
$trainers = 'Trainer Name';
$hello = $this->translator->trans("Hello %s");
$youAreRegCourse = $this->translator->trans("You are registered in the training %s since the %s");
$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.");
$hello = $this->translator->trans('Hello %s');
$youAreRegCourse = $this->translator->trans('You are registered in the training %s since the %s');
$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.');
$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.");
$lpRemindFooter = $this->translator->trans("The training center<p>%s</p>Trainers:<br/>%s");
$lpRemindFooter = $this->translator->trans('The training center<p>%s</p>Trainers:<br/>%s');
$hello = sprintf($hello, $user->getFullName());
$youAreRegCourse = sprintf($youAreRegCourse, $courseName, $registrationDate->format('Y-m-d'));
$thisMessageIsAbout = sprintf($thisMessageIsAbout, $lpProgress);
$stepsToRemind = sprintf($stepsToRemind, $platformUrl, $user->getUsername(), $recoverPasswordUrl);
$lpRemindFooter = sprintf($lpRemindFooter, $trainingCenterName, $trainers);
$hello = \sprintf($hello, $user->getFullName());
$youAreRegCourse = \sprintf($youAreRegCourse, $courseName, $registrationDate->format('Y-m-d'));
$thisMessageIsAbout = \sprintf($thisMessageIsAbout, $lpProgress);
$stepsToRemind = \sprintf($stepsToRemind, $platformUrl, $user->getUsername(), $recoverPasswordUrl);
$lpRemindFooter = \sprintf($lpRemindFooter, $trainingCenterName, $trainers);
$messageContent = $this->twig->render('@ChamiloCore/Mailer/Legacy/lp_progress_reminder_body.html.twig', [
'HelloX' => $hello,
@ -288,13 +291,13 @@ class LpProgressReminderCommand extends Command
try {
$this->messageHelper->sendMessageSimple(
$toUserId,
sprintf("Reminder number %d for the course %s", $nbRemind, $courseName),
\sprintf('Reminder number %d for the course %s', $nbRemind, $courseName),
$messageContent
);
return true;
} catch (\Exception $e) {
throw new \Exception('Error sending reminder: ' . $e->getMessage());
} catch (Exception $e) {
throw new Exception('Error sending reminder: '.$e->getMessage());
}
}
}

@ -47,7 +47,8 @@ class SendEventRemindersCommand extends Command
$this
->setDescription('Send notification messages to users that have reminders from events in their agenda.')
->addOption('debug', null, InputOption::VALUE_NONE, 'Enable debug mode')
->setHelp('This command sends notifications to users who have pending reminders for calendar events.');
->setHelp('This command sends notifications to users who have pending reminders for calendar events.')
;
}
protected function execute(InputInterface $input, OutputInterface $output): int
@ -127,6 +128,7 @@ class SendEventRemindersCommand extends Command
$this->sendReminderMessage($user, $event, $senderId, $debug, $io, $sentRemindersCount);
}
}
break;
case 'course':
@ -146,6 +148,7 @@ class SendEventRemindersCommand extends Command
if ($debug) {
error_log("No course found for resource link in session ID: {$session->getId()}");
}
break;
}

@ -784,7 +784,7 @@ class CourseController extends ToolBaseController
public function getAutoLaunchLPId(
Request $request,
Course $course,
CLPRepository $lpRepository,
CLpRepository $lpRepository,
EntityManagerInterface $em
): JsonResponse {
$data = $request->getContent();

@ -34,7 +34,8 @@ use Symfony\Component\Validator\Constraints as Assert;
denormalizationContext: [
'groups' => ['extra_field:write'],
],
security: "is_granted('ROLE_ADMIN')"),
security: "is_granted('ROLE_ADMIN')"
),
]
#[ORM\Table(name: 'extra_field')]
#[ORM\Entity]

@ -210,6 +210,7 @@ final class Version20230913162700 extends AbstractMigrationChamilo
$existingDocument = $documentRepo->findResourceByTitleInCourse($title, $course);
if ($existingDocument) {
error_log("Document '$title' already exists for course {$course->getId()}. Skipping creation.");
return $existingDocument;
}
@ -230,6 +231,7 @@ final class Version20230913162700 extends AbstractMigrationChamilo
$documentRepo->addFileFromPath($document, $title, $appCourseOldPath);
error_log("Document '$title' successfully created for course $courseId.");
return $document;
}
$generalCoursesPath = $this->getUpdateRootPath().'/app/courses/';
@ -255,9 +257,10 @@ final class Version20230913162700 extends AbstractMigrationChamilo
}
error_log("File '$title' not found for course $courseId. Skipping.");
return null;
} catch (Exception $e) {
error_log('Error in createNewDocument: ' . $e->getMessage());
error_log('Error in createNewDocument: '.$e->getMessage());
return null;
}

@ -12,8 +12,6 @@ use Chamilo\CourseBundle\Repository\CDocumentRepository;
use Doctrine\DBAL\Schema\Schema;
use Exception;
use const PREG_NO_ERROR;
final class Version20231022124700 extends AbstractMigrationChamilo
{
public function getDescription(): string
@ -123,7 +121,8 @@ final class Version20231022124700 extends AbstractMigrationChamilo
$code = $matches[5] ?? null;
if (!$code) {
error_log('Missing cidReq in URL: ' . $matches[0]);
error_log('Missing cidReq in URL: '.$matches[0]);
return $matches[0];
}
@ -137,7 +136,8 @@ final class Version20231022124700 extends AbstractMigrationChamilo
}
if (null === $courseId) {
error_log('Course ID not found for cidReq: ' . $code);
error_log('Course ID not found for cidReq: '.$code);
return $matches[0];
}
@ -152,7 +152,7 @@ final class Version20231022124700 extends AbstractMigrationChamilo
// Ensure other parameters are maintained
if (!empty($remainingParams)) {
$newParams .= '&' . ltrim($remainingParams, '&amp;');
$newParams .= '&'.ltrim($remainingParams, '&amp;');
}
$finalUrl = $matches[1].'?'.$beforeCidReqParams.$newParams;
@ -163,11 +163,13 @@ final class Version20231022124700 extends AbstractMigrationChamilo
);
if (false === $newContent || null === $newContent) {
error_log('preg_replace_callback failed for content: ' . substr($content, 0, 500));
error_log('preg_replace_callback failed for content: '.substr($content, 0, 500));
return $content;
}
} catch (Exception $e) {
error_log('Exception in replaceURLParametersInContent: ' . $e->getMessage());
error_log('Exception in replaceURLParametersInContent: '.$e->getMessage());
return $content;
}

@ -11,22 +11,18 @@ use Doctrine\DBAL\Schema\Schema;
class Version20241209103000 extends AbstractMigrationChamilo
{
public function getDescription(): string
{
return "Change extra field boolean columns (visible_to_self, visible_to_others, changeable, filter) to not accept null values.";
return 'Change extra field boolean columns (visible_to_self, visible_to_others, changeable, filter) to not accept null values.';
}
/**
* @inheritDoc
*/
public function up(Schema $schema): void
{
$this->addSql("UPDATE extra_field SET visible_to_self = 0 WHERE visible_to_self IS NULL");
$this->addSql("UPDATE extra_field SET visible_to_others = 0 WHERE visible_to_others IS NULL");
$this->addSql("UPDATE extra_field SET changeable = 0 WHERE changeable IS NULL");
$this->addSql("UPDATE extra_field SET filter = 0 WHERE filter IS NULL");
$this->addSql('UPDATE extra_field SET visible_to_self = 0 WHERE visible_to_self IS NULL');
$this->addSql('UPDATE extra_field SET visible_to_others = 0 WHERE visible_to_others IS NULL');
$this->addSql('UPDATE extra_field SET changeable = 0 WHERE changeable IS NULL');
$this->addSql('UPDATE extra_field SET filter = 0 WHERE filter IS NULL');
$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");
$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');
}
}
}

@ -35,7 +35,8 @@ class CourseRelUserRepository extends ServiceEntityRepository
->andWhere('rn.parent = c.resourceNode')
->andWhere('(lpv.progress < 100 OR lpv.progress IS NULL)')
->setParameter('courseId', $courseId)
->setParameter('lpIds', $lpIds);
->setParameter('lpIds', $lpIds)
;
return $qb->getQuery()->getResult();
}

@ -193,7 +193,8 @@ class ExtraFieldValuesRepository extends ServiceEntityRepository
->innerJoin(CLp::class, 'lp', 'WITH', 'lp.iid = efv.itemId')
->where('ef.variable = :variable')
->andWhere('efv.fieldValue > 0')
->setParameter('variable', 'number_of_days_for_completion');
->setParameter('variable', 'number_of_days_for_completion')
;
return $qb->getQuery()->getResult();
}

@ -35,7 +35,8 @@ class SessionRelCourseRelUserRepository extends ServiceEntityRepository
->andWhere('rn.parent = c.resourceNode')
->andWhere('(lpv.progress < 100 OR lpv.progress IS NULL)')
->setParameter('courseId', $courseId)
->setParameter('lpIds', $lpIds);
->setParameter('lpIds', $lpIds)
;
return $qb->getQuery()->getResult();
}

@ -10,6 +10,8 @@ use Chamilo\CoreBundle\Entity\TrackEDefault;
use DateTime;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Exception;
use RuntimeException;
class TrackEDefaultRepository extends ServiceEntityRepository
{
@ -21,9 +23,9 @@ class TrackEDefaultRepository extends ServiceEntityRepository
/**
* Retrieves the registration date of a user in a specific course or session.
*/
public function getUserCourseRegistrationAt(int $courseId, int $userId, ?int $sessionId = 0): ?\DateTime
public function getUserCourseRegistrationAt(int $courseId, int $userId, ?int $sessionId = 0): ?DateTime
{
$serializedPattern = sprintf('s:2:"id";i:%d;', $userId);
$serializedPattern = \sprintf('s:2:"id";i:%d;', $userId);
$qb = $this->createQueryBuilder('te')
->select('te.defaultDate')
@ -34,12 +36,14 @@ class TrackEDefaultRepository extends ServiceEntityRepository
->setParameter('courseId', $courseId)
->setParameter('valueType', 'user_object')
->setParameter('eventType', 'user_subscribed')
->setParameter('serializedPattern', '%' . $serializedPattern . '%');
->setParameter('serializedPattern', '%'.$serializedPattern.'%')
;
if ($sessionId > 0) {
$qb->andWhere('te.sessionId = :sessionId')
->setParameter('sessionId', $sessionId);
} elseif ($sessionId === 0) {
->setParameter('sessionId', $sessionId)
;
} elseif (0 === $sessionId) {
$qb->andWhere('te.sessionId = 0');
} else {
$qb->andWhere('te.sessionId IS NULL');
@ -51,12 +55,12 @@ class TrackEDefaultRepository extends ServiceEntityRepository
try {
$result = $query->getOneOrNullResult();
if ($result && isset($result['defaultDate'])) {
return $result['defaultDate'] instanceof \DateTime
return $result['defaultDate'] instanceof DateTime
? $result['defaultDate']
: new \DateTime($result['defaultDate']);
: new DateTime($result['defaultDate']);
}
} catch (\Exception $e) {
throw new \RuntimeException('Error fetching registration date: ' . $e->getMessage());
} catch (Exception $e) {
throw new RuntimeException('Error fetching registration date: '.$e->getMessage());
}
return null;

@ -99,7 +99,8 @@ final class CLpRepository extends ResourceRepository implements ResourceWithLink
{
$qb = $this->getResourcesByCourse($course, $session)
->select('resource.iid')
->andWhere('resource.autolaunch = 1');
->andWhere('resource.autolaunch = 1')
;
$qb->setMaxResults(1);

@ -143,7 +143,8 @@ final class CQuizRepository extends ResourceRepository implements ResourceWithLi
{
$qb = $this->getResourcesByCourse($course, $session)
->select('resource.iid')
->andWhere('resource.autoLaunch = 1');
->andWhere('resource.autoLaunch = 1')
;
$qb->setMaxResults(1);

Loading…
Cancel
Save