From 6a867152960c14466cefdf68258422cdc70f3498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9becca=20Tinchon?= Date: Thu, 7 Dec 2023 13:31:14 +0100 Subject: [PATCH] forum date time --- .../Migrations/Version20231207143300.php | 47 +++++++++++++++++++ .../NotifyUsersOnMessageCreatedHandler.php | 24 +++++----- src/plugin/forum/Resources/config/config.yml | 7 ++- .../Resources/translations/template.en.json | 9 +++- .../Resources/translations/template.fr.json | 9 +++- .../template/forum_new_message.en.html.twig | 2 +- .../template/forum_new_message.fr.html.twig | 2 +- 7 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 src/plugin/forum/Installation/Migrations/Version20231207143300.php diff --git a/src/plugin/forum/Installation/Migrations/Version20231207143300.php b/src/plugin/forum/Installation/Migrations/Version20231207143300.php new file mode 100644 index 00000000000..dd94a65d3f9 --- /dev/null +++ b/src/plugin/forum/Installation/Migrations/Version20231207143300.php @@ -0,0 +1,47 @@ +addSql(' + UPDATE `claro_template_content` + LEFT JOIN `claro_template` ct on ct.id = `claro_template_content`.`template_id` + LEFT JOIN `claro_template_type` ctt on ctt.id = ct.`claro_template_type` + SET `title` = REPLACE(`title`, \'%date%\', \'%post_datetime%\') + WHERE `title` LIKE \'%date%\' AND ctt.entity_name = \'forum_new_message\' + '); + + $this->addSql(' + UPDATE `claro_template_content` + LEFT JOIN `claro_template` ct on ct.id = `claro_template_content`.`template_id` + LEFT JOIN `claro_template_type` ctt on ctt.id = ct.`claro_template_type` + SET `content` = REPLACE(`content`, \'%date%\', \'%post_datetime%\') + WHERE `content` LIKE \'%date%\' AND ctt.entity_name = \'forum_new_message\' + '); + } + + public function down(Schema $schema): void + { + $this->addSql(' + UPDATE `claro_template_content` + LEFT JOIN `claro_template` ct on ct.id = `claro_template_content`.`template_id` + LEFT JOIN `claro_template_type` ctt on ctt.id = ct.`claro_template_type` + SET `title` = REPLACE(`title`, \'%post_datetime%\', \'%date%\') + WHERE `title` LIKE \'%post_datetime%\' AND ctt.entity_name = \'forum_new_message\' + '); + + $this->addSql(' + UPDATE `claro_template_content` + LEFT JOIN `claro_template` ct on ct.id = `claro_template_content`.`template_id` + LEFT JOIN `claro_template_type` ctt on ctt.id = ct.`claro_template_type` + SET `content` = REPLACE(`content`, \'%post_datetime%\', \'%date%\') + WHERE `content` LIKE \'%post_datetime%\' AND ctt.entity_name = \'forum_new_message\' + '); + } +} diff --git a/src/plugin/forum/Messenger/NotifyUsersOnMessageCreatedHandler.php b/src/plugin/forum/Messenger/NotifyUsersOnMessageCreatedHandler.php index ad1dfdcc2c8..38c428f3e52 100644 --- a/src/plugin/forum/Messenger/NotifyUsersOnMessageCreatedHandler.php +++ b/src/plugin/forum/Messenger/NotifyUsersOnMessageCreatedHandler.php @@ -56,18 +56,20 @@ public function __invoke(NotifyUsersOnMessageCreated $forumNotification) ->getRepository(UserValidation::class) ->findBy(['forum' => $forum, 'notified' => true]); - $placeholders = [ - 'forum' => $forum->getName(), - 'subject' => $subject->getTitle(), - 'message' => $message->getContent(), - 'date' => $message->getCreationDate() ? $message->getCreationDate()->format('d/m/Y H:m:s') : null, - 'author' => $message->getCreator() ? $message->getCreator()->getFullName() : null, - 'workspace' => $forum->getResourceNode()->getWorkspace()->getName(), + $placeholders = array_merge([ + 'forum' => $forum->getName(), + 'subject' => $subject->getTitle(), + 'message' => $message->getContent(), + 'date' => $message->getCreationDate() ? $message->getCreationDate()->format('d/m/Y H:m:s') : null, + 'author' => $message->getCreator() ? $message->getCreator()->getFullName() : null, + 'workspace' => $forum->getResourceNode()->getWorkspace()->getName(), - 'workspace_url' => $this->routing->workspaceUrl($forum->getResourceNode()->getWorkspace()), - 'forum_url' => $this->routing->resourceUrl($forum->getResourceNode()), - 'subject_url' => $this->routing->resourceUrl($forum->getResourceNode()).'/subjects/show/'.$subject->getUuid(), - ]; + 'workspace_url' => $this->routing->workspaceUrl($forum->getResourceNode()->getWorkspace()), + 'forum_url' => $this->routing->resourceUrl($forum->getResourceNode()), + 'subject_url' => $this->routing->resourceUrl($forum->getResourceNode()).'/subjects/show/'.$subject->getUuid(), + ], + $this->templateManager->formatDatePlaceholder('post', $message->getCreationDate()), + ); $subject = $this->templateManager->getTemplate('forum_new_message', $placeholders, null, 'title'); $body = $this->templateManager->getTemplate('forum_new_message', $placeholders); diff --git a/src/plugin/forum/Resources/config/config.yml b/src/plugin/forum/Resources/config/config.yml index ae7a88c2794..ed9899405a6 100644 --- a/src/plugin/forum/Resources/config/config.yml +++ b/src/plugin/forum/Resources/config/config.yml @@ -23,7 +23,12 @@ plugin: - subject - subject_url - message - - date + - post_datetime_utc + - post_date_utc + - post_time_utc + - post_datetime + - post_date + - post_time - author - workspace - workspace_url diff --git a/src/plugin/forum/Resources/translations/template.en.json b/src/plugin/forum/Resources/translations/template.en.json index 720126f2bf2..8aa4e08587b 100644 --- a/src/plugin/forum/Resources/translations/template.en.json +++ b/src/plugin/forum/Resources/translations/template.en.json @@ -5,5 +5,12 @@ "forum_url_desc": "URL to the forum", "subject_desc": "Subject name", "subject_url_desc": "URL to the subject", - "message_desc": "Message" + "message_desc": "Message", + + "post_datetime_utc_desc": "The date and time the post was made (UTC)", + "post_date_utc_desc": "The date the post was made (UTC)", + "post_time_utc_desc": "The time the post was made (UTC)", + "post_datetime_desc": "The date and time the post was made", + "post_date_desc": "The date the post was made", + "post_time_desc": "The time the post was made" } diff --git a/src/plugin/forum/Resources/translations/template.fr.json b/src/plugin/forum/Resources/translations/template.fr.json index a3f9f54ff97..643e5a6f68f 100644 --- a/src/plugin/forum/Resources/translations/template.fr.json +++ b/src/plugin/forum/Resources/translations/template.fr.json @@ -5,5 +5,12 @@ "forum_url_desc": "URL du forum", "subject_desc": "Nom du sujet", "subject_url_desc": "URL du sujet", - "message_desc": "Message" + "message_desc": "Message", + + "post_datetime_utc_desc": "La date et l'heure du message (UTC)", + "post_date_utc_desc": "La date du message (UTC)", + "post_time_utc_desc": "L'heure du message (UTC)", + "post_datetime_desc": "L'heure et la date du message", + "post_date_desc": "La date du message", + "post_time_desc": "L'heure du message" } diff --git a/src/plugin/forum/Resources/views/template/forum_new_message.en.html.twig b/src/plugin/forum/Resources/views/template/forum_new_message.en.html.twig index b62eaf1ac7a..2617b768c68 100644 --- a/src/plugin/forum/Resources/views/template/forum_new_message.en.html.twig +++ b/src/plugin/forum/Resources/views/template/forum_new_message.en.html.twig @@ -1,5 +1,5 @@

%message%

-

Posted by %author% on %date%

+

Posted by %author% on %post_datetime%


Voir le sujet
diff --git a/src/plugin/forum/Resources/views/template/forum_new_message.fr.html.twig b/src/plugin/forum/Resources/views/template/forum_new_message.fr.html.twig index 1431f50d263..231c8aaf4ab 100644 --- a/src/plugin/forum/Resources/views/template/forum_new_message.fr.html.twig +++ b/src/plugin/forum/Resources/views/template/forum_new_message.fr.html.twig @@ -1,5 +1,5 @@

%message%

-

Posté par %author% le %date%.

+

Posté par %author% le %post_datetime%.


Voir le sujet