Merge branch 'master' of github.com:chamilo/chamilo-lms

pull/5441/head
Yannick Warnier 2 years ago
commit 07d43554a2
  1. 498
      composer.lock
  2. 54
      public/main/cron/agenda_reminders.php
  3. 2
      public/main/exercise/exercise.class.php
  4. 4
      public/main/session/session_add.php
  5. 6
      src/CoreBundle/Controller/Api/UpdateCCalendarEventAction.php
  6. 4
      src/CoreBundle/Controller/ResourceController.php
  7. 15
      src/CoreBundle/Entity/AgendaReminder.php
  8. 11
      src/CoreBundle/Entity/Session.php
  9. 1
      src/CoreBundle/Entity/User.php
  10. 21
      src/CoreBundle/Migrations/Schema/V200/Version20201215072918.php
  11. 6
      src/CoreBundle/Migrations/Schema/V200/Version20230216122950.php
  12. 22
      src/CoreBundle/Migrations/Schema/V200/Version20230904173400.php
  13. 5
      src/CoreBundle/Migrations/Schema/V200/Version20240112131200.php
  14. 32
      src/CoreBundle/Migrations/Schema/V200/Version20240323181500.php
  15. 34
      src/CoreBundle/Migrations/Schema/V200/Version20240425192900.php
  16. 2
      src/CoreBundle/State/CCalendarEventStateProcessor.php
  17. 3
      symfony.lock
  18. 1
      translations/messages.fr.po

498
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -7,6 +7,8 @@
*/
use Chamilo\CoreBundle\Entity\AgendaReminder;
use Chamilo\CoreBundle\Entity\CourseRelUser;
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
use Chamilo\CourseBundle\Entity\CCalendarEvent;
require_once __DIR__.'/../../main/inc/global.inc.php';
@ -40,28 +42,28 @@ foreach ($reminders as $reminder) {
continue;
}
if ('personal' === $event->determineType()) {
$notificationDate = clone $event->getStartDate();
$notificationDate->sub($reminder->getDateInterval());
$notificationDate = clone $event->getStartDate();
$notificationDate->sub($reminder->getDateInterval());
if ($notificationDate > $now) {
continue;
}
if ($notificationDate > $now) {
continue;
}
if ('course' !== $event->determineType()) {
$eventDetails = [];
$eventDetails[] = '<p><strong>'.$event->getTitle().'</strong></p>';
if ($event->isAllDay()) {
$eventDetails[] = '<p class="small">'.get_lang('AllDay').'</p>';
$eventDetails[] = '<p class="small">'.get_lang('All day').'</p>';
} else {
$eventDetails[] = sprintf(
'<p class="small">'.get_lang('FromDateX').'</p>',
'<p class="small">'.get_lang('From %s').'</p>',
api_get_local_time($event->getStartDate(), null, null, false, true, true)
);
if (!empty($event->getEnddate())) {
$eventDetails[] = sprintf(
'<p class="small">'.get_lang('UntilDateX').'</p>',
'<p class="small">'.get_lang('Until %s').'</p>',
api_get_local_time($event->getEnddate(), null, null, false, true, true)
);
}
@ -71,7 +73,7 @@ foreach ($reminders as $reminder) {
$eventDetails[] = $event->getContent();
}
$messageSubject = sprintf(get_lang('ReminderXEvent'), $event->getTitle());
$messageSubject = sprintf(get_lang('Reminder for event : %s'), $event->getTitle());
$messageContent = implode(PHP_EOL, $eventDetails);
MessageManager::send_message_simple(
@ -81,7 +83,6 @@ foreach ($reminders as $reminder) {
$event->getResourceNode()->getCreator()->getId()
);
$getInviteesForEvent = function (?CCalendarEvent $event) use ($em) {
if (!$event) {
return [];
@ -112,16 +113,7 @@ foreach ($reminders as $reminder) {
$event->getResourceNode()->getCreator()->getId()
);
}
}
if ('course' === $event->determineType()) {
$notificationDate = clone $event->getStartDate();
$notificationDate->sub($reminder->getDateInterval());
if ($notificationDate > $now) {
continue;
}
} else {
$eventDetails = [
sprintf('<p><strong>%s</strong></p>', $event->getTitle()),
$event->isAllDay() ? '<p class="small">All Day</p>' : sprintf(
@ -167,6 +159,24 @@ foreach ($reminders as $reminder) {
foreach ($groupUsers as $groupUserId) {
$groupUserIdList[] = $groupUserId;
}
} else {
$course = $resourceLink->getCourse();
if ($session = $resourceLink->getSession()) {
$userSubscriptions = $session->getSessionRelCourseRelUserInCourse($course)->getValues();
$userIdList = array_map(
fn(SessionRelCourseRelUser $sessionCourseUserSubscription) => $sessionCourseUserSubscription->getUser()->getId(),
$userSubscriptions
);
} else {
$userSubscriptions = $course->getUsers()->getValues();
$userIdList = array_map(
fn(CourseRelUser $courseUserSubscription) => $courseUserSubscription->getUser()->getId(),
$userSubscriptions
);
}
}
}
@ -194,8 +204,6 @@ foreach ($reminders as $reminder) {
$reminder->setSent(true);
$em->persist($reminder);
$batchCounter++;
if (($batchCounter % $batchSize) === 0) {

@ -6172,7 +6172,7 @@ class Exercise
) {
$setting = api_get_course_setting('email_alert_manager_on_new_quiz');
if (empty($setting) && empty($this->getNotifications())) {
if ((empty($setting) || !is_array($setting)) && empty($this->getNotifications())) {
return false;
}

@ -165,7 +165,7 @@ $(function() {
function repopulateFormValues() {
var formValues = JSON.parse(sessionStorage.getItem('formValues'));
$.each(formValues, function(i, field) {
if (field.name === 'coach_username' || field.name === 'name' || field.name === 'system_template') {
if (field.name === 'coach_username' || field.name === 'title' || field.name === 'system_template') {
$('[name=\"' + field.name + '\"]').val(field.value);
}
});
@ -213,7 +213,7 @@ $(function() {
sessionStorage.removeItem('system_templateValues');
sessionStorage.removeItem('formValues');
});
".$result['js']."
});
</script>";

@ -44,11 +44,7 @@ class UpdateCCalendarEventAction extends BaseResourceFileAction
$reminder = new AgendaReminder();
$reminder->count = $reminderInfo['count'];
$reminder->period = $reminderInfo['period'];
$reminder
->setType('')
->decodeDateInterval()
;
$reminder->decodeDateInterval();
$calendarEvent->addReminder($reminder);
}

@ -146,7 +146,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$user = $this->userHelper->getCurrent();
$firstResourceLink = $resourceNode->getResourceLinks()->first();
if ($firstResourceLink) {
if ($firstResourceLink && $user) {
$resourceLinkId = $firstResourceLink->getId();
$url = $resourceNode->getResourceFile()->getOriginalName();
$downloadRepository = $entityManager->getRepository(TrackEDownloads::class);
@ -156,7 +156,7 @@ class ResourceController extends AbstractResourceController implements CourseCon
$cid = (int) $request->query->get('cid');
$sid = (int) $request->query->get('sid');
$allUserInfo = null;
if ($cid) {
if ($cid && $user) {
$allUserInfo = $this->getAllInfoToCertificate(
$user->getId(),
$cid,

@ -24,9 +24,6 @@ class AgendaReminder
#[Groups(['calendar_event:read'])]
protected ?int $id = null;
#[ORM\Column(name: 'type', type: 'string')]
protected string $type;
#[ORM\Column(name: 'date_interval', type: 'dateinterval')]
protected DateInterval $dateInterval;
@ -53,18 +50,6 @@ class AgendaReminder
return $this->id;
}
public function getType(): string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
public function getDateInterval(): DateInterval
{
return $this->dateInterval;

@ -965,6 +965,17 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
return $this->sessionRelCourseRelUsers->matching($criteria);
}
public function getSessionRelCourseRelUserInCourse(Course $course): Collection
{
$criteria = Criteria::create()
->where(
Criteria::expr()->eq('course', $course)
)
;
return $this->sessionRelCourseRelUsers->matching($criteria);
}
public function getIssuedSkills(): Collection
{
return $this->issuedSkills;

@ -710,6 +710,7 @@ class User implements UserInterface, EquatableInterface, ResourceInterface, Reso
'social_post:read',
'course:read',
'course_rel_user:read',
'message:read',
])]
protected string $fullName;

@ -133,7 +133,9 @@ final class Version20201215072918 extends AbstractMigrationChamilo
}
}
$this->updateAgendaReminders($oldNewEventMap);
if ($schema->hasTable('agenda_reminder')) {
$this->updateAgendaReminders($oldNewEventMap);
}
}
/**
@ -141,18 +143,21 @@ final class Version20201215072918 extends AbstractMigrationChamilo
*/
private function updateAgendaReminders(array $oldNewEventMap): void
{
$reminders = $this->entityManager->getRepository(AgendaReminder::class)->findBy(['type' => 'course']);
$result = $this->connection->executeQuery("SELECT * FROM agenda_reminder WHERE type = 'course'");
/** @var AgendaReminder $reminder */
foreach ($reminders as $reminder) {
$oldEventId = $reminder->getEvent()->getIid();
while (($reminder = $result->fetchAssociative()) !== false) {
$oldEventId = $reminder['event_id'];
if (\array_key_exists($oldEventId, $oldNewEventMap)) {
$newEvent = $oldNewEventMap[$oldEventId];
$reminder->setEvent($newEvent);
$this->entityManager->persist($reminder);
$this->addSql(
sprintf(
"UPDATE agenda_reminder SET event_id = %d WHERE id = %d",
$newEvent->getIid(),
$reminder['id']
)
);
}
}
$this->entityManager->flush();
}
public function down(Schema $schema): void {}

@ -60,12 +60,6 @@ final class Version20230216122950 extends AbstractMigrationChamilo
}
}
if (!$schema->hasTable('agenda_reminder')) {
$this->addSql(
'CREATE TABLE agenda_reminder (id INT AUTO_INCREMENT NOT NULL, type VARCHAR(255) NOT NULL, event_id INT NOT NULL, date_interval VARCHAR(255) NOT NULL COMMENT "(DC2Type:dateinterval)", sent TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT "(DC2Type:datetime)", updated_at DATETIME NOT NULL COMMENT "(DC2Type:datetime)", PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;'
);
}
if (!$schema->hasTable('notification_event_rel_user')) {
$this->addSql('CREATE TABLE notification_event_rel_user (
id INT UNSIGNED AUTO_INCREMENT NOT NULL,

@ -123,7 +123,10 @@ class Version20230904173400 extends AbstractMigrationChamilo
}
$this->entityManager->flush();
$this->updateAgendaReminders($oldNewEventIdMap);
if ($schema->hasTable('agenda_reminder')) {
$this->updateAgendaReminders($oldNewEventIdMap);
}
}
private function getPersonalEvents(): array
@ -227,17 +230,20 @@ class Version20230904173400 extends AbstractMigrationChamilo
*/
private function updateAgendaReminders(array $oldNewEventIdMap): void
{
$reminders = $this->entityManager->getRepository(AgendaReminder::class)->findBy(['type' => 'personal']);
$result = $this->connection->executeQuery("SELECT * FROM agenda_reminder WHERE type = 'personal'");
/** @var AgendaReminder $reminder */
foreach ($reminders as $reminder) {
$oldEventId = $reminder->getEvent()->getIid();
while (($reminder = $result->fetchAssociative()) !== false) {
$oldEventId = $reminder['event_id'];
if (\array_key_exists($oldEventId, $oldNewEventIdMap)) {
$newEvent = $oldNewEventIdMap[$oldEventId];
$reminder->setEvent($newEvent);
$this->entityManager->persist($reminder);
$this->addSql(
sprintf(
"UPDATE agenda_reminder SET event_id = %d WHERE id = %d",
$newEvent->getIid(),
$reminder['id']
)
);
}
}
$this->entityManager->flush();
}
}

@ -115,11 +115,6 @@ final class Version20240112131200 extends AbstractMigrationChamilo
$this->addSql('ALTER TABLE message_feedback CHANGE id id INT AUTO_INCREMENT NOT NULL, CHANGE message_id message_id INT NOT NULL;');
}
if ($schema->hasTable('agenda_reminder')) {
error_log('Perform the changes in the agenda_reminder table');
$this->addSql('ALTER TABLE agenda_reminder CHANGE id id INT AUTO_INCREMENT NOT NULL;');
}
if ($schema->hasTable('c_quiz_rel_category')) {
error_log('Perform the changes in the c_quiz_rel_category table');
$this->addSql('ALTER TABLE c_quiz_rel_category CHANGE iid iid INT AUTO_INCREMENT NOT NULL;');

@ -26,6 +26,8 @@ class Version20240323181500 extends AbstractMigrationChamilo
$sysCalendars = $this->connection->fetchAllAssociative('SELECT * FROM sys_calendar');
$utc = new DateTimeZone('UTC');
$oldNewEventIdMap = [];
$admin = $this->getAdmin();
foreach ($sysCalendars as $sysCalendar) {
$calendarEvent = $this->createCCalendarEvent(
@ -39,10 +41,18 @@ class Version20240323181500 extends AbstractMigrationChamilo
);
$this->entityManager->persist($calendarEvent);
$this->entityManager->flush();
$this->addGlobalResourceLinkToNode($calendarEvent->getResourceNode());
$oldNewEventIdMap[$sysCalendar['id']] = $calendarEvent;
}
$this->entityManager->flush();
if ($schema->hasTable('agenda_reminder')) {
$this->updateAgendaReminders($oldNewEventIdMap);
}
}
private function createCCalendarEvent(
@ -95,6 +105,28 @@ class Version20240323181500 extends AbstractMigrationChamilo
}
}
/**
* @param array<int, CCalendarEvent> $oldNewEventIdMap
*/
private function updateAgendaReminders(array $oldNewEventIdMap): void
{
$result = $this->connection->executeQuery("SELECT * FROM agenda_reminder WHERE type = 'admin'");
while (($reminder = $result->fetchAssociative()) !== false) {
$oldEventId = $reminder['event_id'];
if (\array_key_exists($oldEventId, $oldNewEventIdMap)) {
$newEvent = $oldNewEventIdMap[$oldEventId];
$this->addSql(
sprintf(
"UPDATE agenda_reminder SET event_id = %d WHERE id = %d",
$newEvent->getIid(),
$reminder['id']
)
);
}
}
}
public function down(Schema $schema): void
{
// Down migration is not defined, as data migration cannot be easily reverted

@ -0,0 +1,34 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
class Version20240425192900 extends AbstractMigration
{
public function getDescription(): string
{
return 'Changes on the agenda_reminder structure';
}
/**
* @inheritDoc
*/
public function up(Schema $schema): void
{
if (!$schema->hasTable('agenda_reminder')) {
$this->addSql(
'CREATE TABLE agenda_reminder (id INT AUTO_INCREMENT NOT NULL, event_id INT NOT NULL, date_interval VARCHAR(255) NOT NULL COMMENT "(DC2Type:dateinterval)", sent TINYINT(1) NOT NULL, created_at DATETIME NOT NULL COMMENT "(DC2Type:datetime)", updated_at DATETIME NOT NULL COMMENT "(DC2Type:datetime)", PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB ROW_FORMAT = DYNAMIC;'
);
} else {
$this->addSql('ALTER TABLE agenda_reminder DROP type');
$this->addSql('ALTER TABLE agenda_reminder CHANGE id id INT AUTO_INCREMENT NOT NULL;');
}
$this->addSql('ALTER TABLE agenda_reminder ADD CONSTRAINT FK_416FFA2471F7E88B FOREIGN KEY (event_id) REFERENCES c_calendar_event (iid)');
$this->addSql('CREATE INDEX IDX_416FFA2471F7E88B ON agenda_reminder (event_id)');
}
}

@ -44,8 +44,6 @@ final class CCalendarEventStateProcessor implements ProcessorInterface
}
$data->getReminders()->forAll(function (int $i, AgendaReminder $reminder) {
$reminder->setType('');
return $reminder->decodeDateInterval();
});

@ -89,6 +89,9 @@
"ref": "a9f2e49180f75cdc71ae279a929c4b2e0638de84"
}
},
"gregwar/captcha-bundle": {
"version": "v2.2.0"
},
"hautelook/alice-bundle": {
"version": "2.12",
"recipe": {

@ -25997,7 +25997,6 @@ msgstr "Mon profil"
msgid "Number of times this answer was selected"
msgstr "Nombre de fois que cette réponse a été sélectionnée"
#, fuzzy
msgid "Back to tests list"
msgstr "Retour à la liste des tests"

Loading…
Cancel
Save