diff --git a/assets/vue/components/ccalendarevent/CCalendarEventForm.vue b/assets/vue/components/ccalendarevent/CCalendarEventForm.vue
index ff9418bc61..4dd36e3677 100644
--- a/assets/vue/components/ccalendarevent/CCalendarEventForm.vue
+++ b/assets/vue/components/ccalendarevent/CCalendarEventForm.vue
@@ -41,46 +41,18 @@
'.$event->getTitle().'
'; - - if ($event->isAllDay()) { - $eventDetails[] = ''.get_lang('AllDay').'
'; - } else { - $eventDetails[] = sprintf( - ''.get_lang('FromDateX').'
', - api_get_local_time($event->getStartDate(), null, null, false, true, true) - ); - - if (!empty($event->getEnddate())) { - $eventDetails[] = sprintf( - ''.get_lang('UntilDateX').'
', - api_get_local_time($event->getEnddate(), null, null, false, true, true) - ); - } - } - - if (!empty($event->getContent())) { - $eventDetails[] = $event->getContent(); - } - - $messageSubject = sprintf(get_lang('ReminderXEvent'), $event->getTitle()); - $messageContent = implode(PHP_EOL, $eventDetails); - - MessageManager::send_message_simple( - $event->getResourceNode()->getCreator()->getId(), - $messageSubject, - $messageContent, - $event->getResourceNode()->getCreator()->getId() - ); - - - $getInviteesForEvent = function ($eventId) use ($em) { - $event = $em->find(\Chamilo\CourseBundle\Entity\CCalendarEvent::class, $eventId); - if (!$event) { - return []; - } - - $resourceLinks = $event->getResourceLinkEntityList(); - $inviteeList = []; - foreach ($resourceLinks as $resourceLink) { - $user = $resourceLink->getUser(); - if ($user) { - $inviteeList[] = [ - 'id' => $user->getId(), - 'name' => $user->getFullname(), - ]; - } - } - - return $inviteeList; - }; - - if ($agendaCollectiveInvitations) { - $invitees = $getInviteesForEvent($reminder->getEventId()); - $inviteesIdList = array_column($invitees, 'id'); - foreach ($inviteesIdList as $userId) { - MessageManager::send_message_simple( - $userId, - $messageSubject, - $messageContent, - $event->getResourceNode()->getCreator()->getId() - ); - } - } - } - - if ('course' === $reminder->getType()) { - - $event = $em->getRepository(\Chamilo\CourseBundle\Entity\CCalendarEvent::class)->find($reminder->getEventId()); - if (null === $event) { - continue; - } - - $notificationDate = clone $event->getStartDate(); - $notificationDate->sub($reminder->getDateInterval()); - - if ($notificationDate > $now) { - continue; - } - - $eventDetails = [ - sprintf('%s
', $event->getTitle()), - $event->isAllDay() ? 'All Day
' : sprintf( - 'From %s
', - $event->getStartDate()->format('Y-m-d H:i:s') - ) - ]; - - if ($event->getEndDate()) { - $eventDetails[] = sprintf( - 'Until %s
', - $event->getEndDate()->format('Y-m-d H:i:s') - ); - } - - if ($event->getContent()) { - $eventDetails[] = $event->getContent(); - } - - if ($event->getComment()) { - $eventDetails[] = sprintf('%s
', $event->getComment()); - } - - $messageSubject = sprintf('Reminder: %s', $event->getTitle()); - $messageContent = implode(PHP_EOL, $eventDetails); - - $resourceLinks = $event->getResourceNode()->getResourceLinks(); - $userIdList = []; - $groupUserIdList = []; - - foreach ($resourceLinks as $resourceLink) { - if ($resourceLink->getUser()) { - $userIdList[] = $resourceLink->getUser()->getId(); - } elseif ($resourceLink->getGroup()) { - $groupUsers = GroupManager::get_users($resourceLink->getGroup()->getId(), false, null, null, false, $event->getSessionId()); - foreach ($groupUsers as $groupUserId) { - $groupUserIdList[] = $groupUserId; - } - } - } - - $userIdList = array_unique($userIdList); - $groupUserIdList = array_unique($groupUserIdList); - - foreach ($userIdList as $userId) { - MessageManager::send_message_simple( - $userId, - $messageSubject, - $messageContent, - $senderId - ); - } - - foreach ($groupUserIdList as $groupUserId) { - MessageManager::send_message_simple( - $groupUserId, - $messageSubject, - $messageContent, - $senderId - ); - } - } - - $reminder->setSent(true); - - $em->persist($reminder); - - $batchCounter++; - - if (($batchCounter % $batchSize) === 0) { - $em->flush(); - } -} - -$em->flush(); -$em->clear(); diff --git a/public/main/inc/lib/api.lib.php b/public/main/inc/lib/api.lib.php index 20ac597831..a948d812a7 100644 --- a/public/main/inc/lib/api.lib.php +++ b/public/main/inc/lib/api.lib.php @@ -7134,7 +7134,7 @@ function api_mail_html( } try { - //$bus = Container::getMessengerBus(); + $bus = Container::getMessengerBus(); //$sendMessage = new \Chamilo\CoreBundle\Message\SendMessage(); //$bus->dispatch($sendMessage); diff --git a/src/CoreBundle/Controller/Api/DeleteRemindersByEventAction.php b/src/CoreBundle/Controller/Api/DeleteRemindersByEventAction.php deleted file mode 100644 index 14493117a0..0000000000 --- a/src/CoreBundle/Controller/Api/DeleteRemindersByEventAction.php +++ /dev/null @@ -1,36 +0,0 @@ -getContent(), true); - $eventId = $data['eventId'] ?? null; - - if (!$eventId) { - return $this->json(['message' => 'Event ID is required.'], Response::HTTP_BAD_REQUEST); - } - - $repository = $em->getRepository(AgendaReminder::class); - $reminders = $repository->findBy(['eventId' => $eventId]); - - foreach ($reminders as $reminder) { - $em->remove($reminder); - } - $em->flush(); - - return $this->json(['message' => 'All reminders for the event have been deleted.']); - } -} diff --git a/src/CoreBundle/Controller/PlatformConfigurationController.php b/src/CoreBundle/Controller/PlatformConfigurationController.php index cf9ef6a3e6..f15a55f459 100644 --- a/src/CoreBundle/Controller/PlatformConfigurationController.php +++ b/src/CoreBundle/Controller/PlatformConfigurationController.php @@ -58,7 +58,7 @@ class PlatformConfigurationController extends AbstractController 'agenda.allow_personal_agenda', 'agenda.personal_calendar_show_sessions_occupation', - 'agenda.agenda_reminders', + // 'agenda.agenda_reminders', 'agenda.agenda_collective_invitations', 'agenda.agenda_event_subscriptions', diff --git a/src/CoreBundle/Entity/AgendaReminder.php b/src/CoreBundle/Entity/AgendaReminder.php index 6a6f64c721..94a4041ed1 100644 --- a/src/CoreBundle/Entity/AgendaReminder.php +++ b/src/CoreBundle/Entity/AgendaReminder.php @@ -6,37 +6,12 @@ declare(strict_types=1); namespace Chamilo\CoreBundle\Entity; -use ApiPlatform\Core\Annotation\ApiFilter; -use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter; -use ApiPlatform\Metadata\GetCollection; -use Chamilo\CoreBundle\Controller\Api\DeleteRemindersByEventAction; -use Chamilo\CoreBundle\State\AgendaReminderProcessor; use Chamilo\CoreBundle\Traits\TimestampableTypedEntity; use DateInterval; use Doctrine\ORM\Mapping as ORM; -use ApiPlatform\Metadata\ApiResource; -use ApiPlatform\Metadata\Post; -use Symfony\Component\Serializer\Annotation\Groups; #[ORM\Entity] #[ORM\Table(name: 'agenda_reminder')] -#[ApiResource( - operations: [ - new GetCollection(), - new Post(processor: AgendaReminderProcessor::class), - new Post( - uriTemplate: '/agenda_reminders/delete_by_event', - controller: DeleteRemindersByEventAction::class, - openapiContext: ['summary' => 'Deletes all reminders for a specific event'], - denormalizationContext: ['groups' => ['agenda_reminder:delete_by_event']], - security: "is_granted('ROLE_USER')" - ), - ], - normalizationContext: ['groups' => ['agenda_reminder:read']], - denormalizationContext: ['groups' => ['agenda_reminder:write']], - security: "is_granted('ROLE_USER')" -)] -#[ApiFilter(SearchFilter::class, properties: ['eventId' => 'exact'])] class AgendaReminder { use TimestampableTypedEntity; @@ -47,25 +22,20 @@ class AgendaReminder protected ?int $id = null; #[ORM\Column(name: 'type', type: 'string')] - #[Groups(['agenda_reminder:write', 'agenda_reminder:read'])] protected string $type; #[ORM\Column(name: 'event_id', type: 'integer')] - #[Groups(['agenda_reminder:write', 'agenda_reminder:read'])] protected int $eventId; #[ORM\Column(name: 'date_interval', type: 'dateinterval')] - #[Groups(['agenda_reminder:write', 'agenda_reminder:read'])] protected DateInterval $dateInterval; #[ORM\Column(name: 'sent', type: 'boolean')] - #[Groups(['agenda_reminder:write', 'agenda_reminder:read'])] protected bool $sent; public function __construct() { $this->sent = false; - $this->type = 'personal'; } public function getId(): ?int diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php b/src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php index 42541873fb..ea59dd9637 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php @@ -6,7 +6,6 @@ declare(strict_types=1); namespace Chamilo\CoreBundle\Migrations\Schema\V200; -use Chamilo\CoreBundle\Entity\AgendaReminder; use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; use Chamilo\CoreBundle\Repository\Node\CourseRepository; @@ -22,7 +21,7 @@ final class Version20201215072918 extends AbstractMigrationChamilo { public function getDescription(): string { - return 'Migrate c_calendar_event, calendar_event_attachment and update agenda_reminder'; + return 'Migrate c_calendar_event, calendar_event_attachment'; } public function up(Schema $schema): void @@ -42,7 +41,6 @@ final class Version20201215072918 extends AbstractMigrationChamilo $kernel = $container->get('kernel'); $rootPath = $kernel->getProjectDir(); $admin = $this->getAdmin(); - $oldNewEventIdMap = []; $q = $em->createQuery('SELECT c FROM Chamilo\CoreBundle\Entity\Course c'); @@ -57,7 +55,6 @@ final class Version20201215072918 extends AbstractMigrationChamilo $events = $result->fetchAllAssociative(); foreach ($events as $eventData) { $id = $eventData['iid']; - $oldEventId = $id; /** @var CCalendarEvent $event */ $event = $eventRepo->find($id); @@ -103,9 +100,6 @@ final class Version20201215072918 extends AbstractMigrationChamilo $em->persist($event); $em->flush(); - - $newEventId = $event->getId(); - $oldNewEventIdMap[$oldEventId] = $newEventId; } $sql = "SELECT * FROM c_calendar_event_attachment WHERE c_id = {$courseId} @@ -143,22 +137,6 @@ final class Version20201215072918 extends AbstractMigrationChamilo $em->flush(); } } - - $this->updateAgendaReminders($oldNewEventIdMap, $em); - } - - private function updateAgendaReminders($oldNewEventIdMap, $em): void - { - $reminders = $em->getRepository(AgendaReminder::class)->findBy(['type' => 'course']); - foreach ($reminders as $reminder) { - $oldEventId = $reminder->getEventId(); - if (array_key_exists($oldEventId, $oldNewEventIdMap)) { - $newEventId = $oldNewEventIdMap[$oldEventId]; - $reminder->setEventId($newEventId); - $em->persist($reminder); - } - } - $em->flush(); } public function down(Schema $schema): void {} diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230904173400.php b/src/CoreBundle/Migrations/Schema/V200/Version20230904173400.php index 310d9bf8c3..e6688d98d2 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20230904173400.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20230904173400.php @@ -6,7 +6,6 @@ declare(strict_types=1); namespace Chamilo\CoreBundle\Migrations\Schema\V200; -use Chamilo\CoreBundle\Entity\AgendaReminder; use Chamilo\CoreBundle\Entity\User; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; use Chamilo\CourseBundle\Entity\CCalendarEvent; @@ -20,7 +19,7 @@ class Version20230904173400 extends AbstractMigrationChamilo { public function getDescription(): string { - return 'Migrate personal_agenda to c_calendar_event and update agenda_reminder'; + return 'Migrate personal_agenda to c_calendar_event'; } /** @@ -45,7 +44,6 @@ class Version20230904173400 extends AbstractMigrationChamilo $personalAgendas = $this->getPersonalEvents(); $utc = new DateTimeZone('UTC'); - $oldNewEventIdMap = []; /** @var array $personalAgenda */ foreach ($personalAgendas as $personalAgenda) { @@ -72,7 +70,6 @@ class Version20230904173400 extends AbstractMigrationChamilo $map[$personalAgenda['id']] = $calendarEvent; $em->persist($calendarEvent); - $em->flush(); if ($collectiveInvitationsEnabled) { $invitationsOrSubscriptionsInfo = []; @@ -119,11 +116,9 @@ class Version20230904173400 extends AbstractMigrationChamilo } } } - $oldNewEventIdMap[$personalAgenda['id']] = $calendarEvent->getIid(); } $em->flush(); - $this->updateAgendaReminders($oldNewEventIdMap, $em); } private function getPersonalEvents(): array @@ -221,18 +216,4 @@ class Version20230904173400 extends AbstractMigrationChamilo return []; } } - - private function updateAgendaReminders(array $oldNewEventIdMap, $em): void - { - $reminders = $em->getRepository(AgendaReminder::class)->findBy(['type' => 'personal']); - foreach ($reminders as $reminder) { - $oldEventId = $reminder->getEventId(); - if (array_key_exists($oldEventId, $oldNewEventIdMap)) { - $newEventId = $oldNewEventIdMap[$oldEventId]; - $reminder->setEventId($newEventId); - $em->persist($reminder); - } - } - $em->flush(); - } } diff --git a/src/CoreBundle/State/AgendaReminderProcessor.php b/src/CoreBundle/State/AgendaReminderProcessor.php deleted file mode 100644 index b14ad70f5e..0000000000 --- a/src/CoreBundle/State/AgendaReminderProcessor.php +++ /dev/null @@ -1,65 +0,0 @@ -requestStack->getCurrentRequest(); - if ($request) { - $payload = json_decode($request->getContent(), true); - $eventId = $payload['eventId'] ?? null; - $event = $this->eventRepository->find($eventId); - - if (!$event) { - throw new \Exception("Event not found with ID: $eventId"); - } - - $type = $this->eventRepository->determineEventType($event); - $data->setType($type); - $data->setEventId($eventId); - - $count = $payload['count'] ?? 0; - $period = $payload['period'] ?? ''; - - $data->setDateInterval($this->convertToInterval((int) $count, $period)); - } - - $this->entityManager->persist($data); - $this->entityManager->flush(); - - return $data; - } - - private function convertToInterval(int $count, string $period): DateInterval - { - return match ($period) { - 'i' => new DateInterval("PT{$count}M"), - 'h' => new DateInterval("PT{$count}H"), - 'd' => new DateInterval("P{$count}D"), - default => throw new \InvalidArgumentException("Period not valid: $period"), - }; - } -}