notification: add show action

This commit is contained in:
2021-12-28 22:35:15 +01:00
parent f453dbb543
commit 1ad6a958e2
5 changed files with 133 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound;
use Chill\MainBundle\Notification\NotificationHandlerManager;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Repository\NotificationRepository;
use Chill\MainBundle\Security\Authorization\NotificationVoter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\RedirectResponse;
@@ -169,6 +170,26 @@ class NotificationController extends AbstractController
]);
}
/**
* @Route("/{id}/show", name="chill_main_notification_show")
*/
public function showAction(Notification $notification, Request $request): Response
{
$this->denyAccessUnlessGranted(NotificationVoter::SEE, $notification);
$response = $this->render('@ChillMain/Notification/show.html.twig', [
'notification' => $notification,
'handler' => $this->notificationHandlerManager->getHandler($notification),
]);
if ($this->getUser() instanceof User && !$notification->isReadBy($this->getUser())) {
$notification->markAsReadBy($this->getUser());
$this->em->flush();
}
return $response;
}
private function countUnread(): array
{
return [