Skip to content

Commit

Permalink
forum date time
Browse files Browse the repository at this point in the history
  • Loading branch information
WolfyWin committed Dec 7, 2023
1 parent 0c57a58 commit 6a86715
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 16 deletions.
47 changes: 47 additions & 0 deletions src/plugin/forum/Installation/Migrations/Version20231207143300.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Claroline\ForumBundle\Installation\Migrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

final class Version20231207143300 extends AbstractMigration
{
public function up(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`, \'%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\'
');
}
}
24 changes: 13 additions & 11 deletions src/plugin/forum/Messenger/NotifyUsersOnMessageCreatedHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion src/plugin/forum/Resources/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 8 additions & 1 deletion src/plugin/forum/Resources/translations/template.en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
9 changes: 8 additions & 1 deletion src/plugin/forum/Resources/translations/template.fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>%message%</p>
<p>Posted by %author% on %date%</p>
<p>Posted by %author% on %post_datetime%</p>
<br/>
<a href="%subject_url%">Voir le sujet</a>
<br/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<p>%message%</p>
<p>Posté par %author% le %date%.</p>
<p>Posté par %author% le %post_datetime%.</p>
<br/>
<a href="%subject_url%">Voir le sujet</a>
<br/>
Expand Down

0 comments on commit 6a86715

Please sign in to comment.