Notification: add a counter for notifications

This commit is contained in:
2022-01-04 16:44:01 +01:00
parent 5bb5468198
commit 3a207b2c5d
12 changed files with 211 additions and 29 deletions

View File

@@ -209,9 +209,6 @@ class NotificationController extends AbstractController
{
$this->denyAccessUnlessGranted(NotificationVoter::NOTIFICATION_SEE, $notification);
$appendComment = new NotificationComment();
$appendCommentForm = $this->createForm(NotificationCommentType::class, $appendComment);
if ($request->query->has('edit')) {
$commentId = $request->query->getInt('edit');
$editedComment = $notification->getComments()->filter(static function (NotificationComment $c) use ($commentId) {
@@ -222,6 +219,8 @@ class NotificationController extends AbstractController
throw $this->createNotFoundException("Comment with id {$commentId} does not exists nor belong to this notification");
}
$this->denyAccessUnlessGranted(NotificationVoter::COMMENT_EDIT, $editedComment);
$editedCommentForm = $this->createForm(NotificationCommentType::class, $editedComment);
if (Request::METHOD_POST === $request->getMethod() && 'edit' === $request->request->get('form')) {
@@ -240,26 +239,31 @@ class NotificationController extends AbstractController
}
}
if (Request::METHOD_POST === $request->getMethod() && 'append' === $request->request->get('form')) {
$appendCommentForm->handleRequest($request);
if ($this->isGranted(NotificationVoter::COMMENT_ADD, $notification)) {
$appendComment = new NotificationComment();
$appendCommentForm = $this->createForm(NotificationCommentType::class, $appendComment);
if ($appendCommentForm->isSubmitted() && $appendCommentForm->isValid()) {
$notification->addComment($appendComment);
$this->em->persist($appendComment);
$this->em->flush();
if (Request::METHOD_POST === $request->getMethod() && 'append' === $request->request->get('form')) {
$appendCommentForm->handleRequest($request);
$this->addFlash('success', $this->translator->trans('notification.comment_appended'));
if ($appendCommentForm->isSubmitted() && $appendCommentForm->isValid()) {
$notification->addComment($appendComment);
$this->em->persist($appendComment);
$this->em->flush();
return $this->redirectToRoute('chill_main_notification_show', [
'id' => $notification->getId(),
]);
$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(),
'appendCommentForm' => isset($appendCommentForm) ? $appendCommentForm->createView() : null,
'editedCommentForm' => isset($editedCommentForm) ? $editedCommentForm->createView() : null,
'editedCommentId' => $commentId ?? null,
]);