mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Display notification using services (draft)
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\MainBundle\Repository\NotificationRepository;
|
||||
use Chill\MainBundle\Notification\NotificationRenderer;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Symfony\Component\Security\Core\Security;
|
||||
|
||||
class NotificationController extends AbstractController
|
||||
{
|
||||
private $security;
|
||||
|
||||
public function __construct(Security $security)
|
||||
{
|
||||
$this->security = $security;
|
||||
}
|
||||
|
||||
public function showAction(NotificationRepository $notificationRepository, NotificationRenderer $notificationRenderer)
|
||||
{
|
||||
$currentUser = $this->security->getUser();
|
||||
|
||||
$notifications = $notificationRepository->findAllForAttendee($currentUser);
|
||||
|
||||
$templateData = array();
|
||||
foreach ($notifications as $notification) {
|
||||
$data = [
|
||||
'template' => $notificationRenderer->getTemplate($notification),
|
||||
'template_data' => $notificationRenderer->getTemplateData($notification),
|
||||
'notification' => $notification
|
||||
];
|
||||
$templateData[] = $data;
|
||||
}
|
||||
|
||||
return $this->render('ChillMainBundle:Notification:show.html.twig', [
|
||||
'datas' => $templateData,
|
||||
'notifications' => $notifications,
|
||||
]);
|
||||
}
|
||||
}
|
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\MainBundle\Notification;
|
||||
|
||||
use Chill\MainBundle\Entity\Notification;
|
||||
use Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer;
|
||||
use Chill\ActivityBundle\Notification\ActivityNotificationRenderer;
|
||||
|
||||
final class NotificationRenderer
|
||||
{
|
||||
private array $renderers;
|
||||
|
||||
public function __construct(
|
||||
AccompanyingPeriodNotificationRenderer $accompanyingPeriodNotificationRenderer,
|
||||
ActivityNotificationRenderer $activityNotificationRenderer)
|
||||
{
|
||||
// TODO configure automatically
|
||||
// TODO CREER UNE INTERFACE POUR ETRE SUR QUE LES RENDERERS SONT OK
|
||||
|
||||
$this->renderers[] = $accompanyingPeriodNotificationRenderer;
|
||||
$this->renderers[] = $activityNotificationRenderer;
|
||||
}
|
||||
|
||||
private function getRenderer(Notification $notification)
|
||||
{
|
||||
foreach ($this->renderers as $renderer) {
|
||||
if($renderer->supports($notification)) {
|
||||
return $renderer;
|
||||
}
|
||||
}
|
||||
|
||||
throw new \Exception('No renderer for '. $notification);
|
||||
}
|
||||
|
||||
public function getTemplate(Notification $notification)
|
||||
{
|
||||
return $this->getRenderer($notification)->getTemplate();
|
||||
}
|
||||
|
||||
public function getTemplateData(Notification $notification)
|
||||
{
|
||||
return $this->getRenderer($notification)->getTemplateData($notification);
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
{% extends "@ChillMain/layout.html.twig" %}
|
||||
|
||||
{% block content %}
|
||||
<div id="container content">
|
||||
<div class="grid-8 centered">
|
||||
<h1>{{ "Notifications list" | trans }}</h1>
|
||||
<!-- TODO : UNREAD & READ -->
|
||||
|
||||
{%for data in datas %}
|
||||
{% set notification = data.notification %}
|
||||
|
||||
<dl class="chill_view_data">
|
||||
<dt class="inline">{{ 'Message'|trans }}</dt>
|
||||
<dd>{{ notification.message }}</dd>
|
||||
</dl>
|
||||
|
||||
<dl class="chill_view_data">
|
||||
<dt class="inline">{{ 'Date'|trans }}</dt>
|
||||
<dd>{{ notification.date | date('long') }}</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
<dl class="chill_view_data">
|
||||
<dt class="inline">{{ 'Sender'|trans }}</dt>
|
||||
<dd>{{ notification.sender }}</dd>
|
||||
</dl>
|
||||
|
||||
<dl class="chill_view_data">
|
||||
<dt class="inline">{{ 'Addressees'|trans }}</dt>
|
||||
<dd>{{ notification.addressees |join(', ') }}</dd>
|
||||
</dl>
|
||||
|
||||
<dl class="chill_view_data">
|
||||
<dt class="inline">{{ 'Entity'|trans }}</dt>
|
||||
<dd>
|
||||
{% include data.template with data.template_data %}
|
||||
</dd>
|
||||
</dl>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endblock content %}
|
@@ -34,6 +34,10 @@ chill_password_recover:
|
||||
resource: "@ChillMainBundle/config/routes/password_recover.yaml"
|
||||
prefix: "public/{_locale}/password"
|
||||
|
||||
chill_main_notification:
|
||||
resource: "@ChillMainBundle/config/routes/notification.yaml"
|
||||
prefix: "{_locale}/notification"
|
||||
|
||||
chill_crud:
|
||||
resource: "@ChillMainBundle"
|
||||
type: CRUD
|
||||
|
@@ -0,0 +1,3 @@
|
||||
chill_main_notification_show:
|
||||
path: /show
|
||||
controller: Chill\MainBundle\Controller\NotificationController::showAction
|
@@ -33,3 +33,8 @@ services:
|
||||
$logger: '@Psr\Log\LoggerInterface'
|
||||
$validator: '@Symfony\Component\Validator\Validator\ValidatorInterface'
|
||||
tags: ['controller.service_arguments']
|
||||
|
||||
Chill\MainBundle\Controller\NotificationController:
|
||||
arguments:
|
||||
$security: '@Symfony\Component\Security\Core\Security'
|
||||
tags: ['controller.service_arguments']
|
||||
|
@@ -4,7 +4,11 @@ services:
|
||||
$logger: '@Psr\Log\LoggerInterface'
|
||||
$twig: '@Twig\Environment'
|
||||
$mailer: '@swiftmailer.mailer.default'
|
||||
# $mailerTransporter: '@swiftmailer.transport'
|
||||
# $mailerTransporter: '@swiftmailer.transport'
|
||||
$router: '@Symfony\Component\Routing\RouterInterface'
|
||||
$translator: '@Symfony\Component\Translation\TranslatorInterface'
|
||||
$routeParameters: '%chill_main.notifications%'
|
||||
|
||||
Chill\MainBundle\Notification\NotificationRenderer:
|
||||
autoconfigure: true
|
||||
autowire: true
|
||||
|
Reference in New Issue
Block a user