diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index df38c15d9..a2b26832e 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -12,7 +12,9 @@ declare(strict_types=1); namespace Chill\MainBundle\Controller; use Chill\MainBundle\Entity\Notification; +use Chill\MainBundle\Entity\NotificationComment; use Chill\MainBundle\Entity\User; +use Chill\MainBundle\Form\NotificationCommentType; use Chill\MainBundle\Form\NotificationType; use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound; use Chill\MainBundle\Notification\NotificationHandlerManager; @@ -177,11 +179,28 @@ class NotificationController extends AbstractController { $this->denyAccessUnlessGranted(NotificationVoter::SEE, $notification); + $notification->addComment($appendComment = new NotificationComment()); + $appendCommentForm = $this->createForm(NotificationCommentType::class, $appendComment); + $appendCommentForm->handleRequest($request); + + if ($appendCommentForm->isSubmitted() && $appendCommentForm->isValid()) { + $this->em->persist($appendComment); + $this->em->flush(); + + $this->addFlash('success', $this->translator->trans('notification.comment_appended')); + + return $this->redirectToRoute('chill_main_notification_show', [ + 'id' => $notification->getId(), + ]); + } + $response = $this->render('@ChillMain/Notification/show.html.twig', [ 'notification' => $notification, 'handler' => $this->notificationHandlerManager->getHandler($notification), + 'appendCommentForm' => $appendCommentForm->createView(), ]); + // we mark the notification as read after having computed the response if ($this->getUser() instanceof User && !$notification->isReadBy($this->getUser())) { $notification->markAsReadBy($this->getUser()); $this->em->flush(); diff --git a/src/Bundle/ChillMainBundle/Entity/NotificationComment.php b/src/Bundle/ChillMainBundle/Entity/NotificationComment.php index 73157eb01..792e4abcc 100644 --- a/src/Bundle/ChillMainBundle/Entity/NotificationComment.php +++ b/src/Bundle/ChillMainBundle/Entity/NotificationComment.php @@ -68,6 +68,16 @@ class NotificationComment implements TrackCreationInterface, TrackUpdateInterfac return $this->content; } + public function getCreatedAt(): ?DateTimeImmutable + { + return $this->createdAt; + } + + public function getCreatedBy(): ?User + { + return $this->createdBy; + } + public function getId(): ?int { return $this->id; @@ -83,6 +93,11 @@ class NotificationComment implements TrackCreationInterface, TrackUpdateInterfac return $this->updateAt; } + public function getUpdatedBy(): ?User + { + return $this->updatedBy; + } + public function setContent(string $content): self { $this->content = $content; diff --git a/src/Bundle/ChillMainBundle/Form/NotificationCommentType.php b/src/Bundle/ChillMainBundle/Form/NotificationCommentType.php new file mode 100644 index 000000000..7aa3a6cb1 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Form/NotificationCommentType.php @@ -0,0 +1,26 @@ +add('content', ChillTextareaType::class, [ + 'required' => false, + ]); + } +} diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig index 1fbe7693b..9dd1c7cf6 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/show.html.twig @@ -16,6 +16,37 @@ {{ notification.message|chill_markdown_to_html }} + {% if notification.comments|length > 0 %} + {% for comment in notification.comments %} +
+ {{ comment.content|chill_markdown_to_html }} ++ + {% if is_granted('CHILL_MAIN_NOTIFICATION_COMMENT_EDIT', comment) %} + + {% endif %} +