diff --git a/src/Bundle/ChillMainBundle/ChillMainBundle.php b/src/Bundle/ChillMainBundle/ChillMainBundle.php index 2ff7ef862..0416edf76 100644 --- a/src/Bundle/ChillMainBundle/ChillMainBundle.php +++ b/src/Bundle/ChillMainBundle/ChillMainBundle.php @@ -22,6 +22,7 @@ use Chill\MainBundle\DependencyInjection\CompilerPass\TimelineCompilerClass; use Chill\MainBundle\DependencyInjection\CompilerPass\WidgetsCompilerPass; use Chill\MainBundle\DependencyInjection\ConfigConsistencyCompilerPass; use Chill\MainBundle\DependencyInjection\RoleProvidersCompilerPass; +use Chill\MainBundle\Notification\NotificationHandlerInterface; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Chill\MainBundle\Search\SearchApiInterface; use Chill\MainBundle\Security\ProvideRoleInterface; @@ -50,6 +51,8 @@ class ChillMainBundle extends Bundle ->addTag('chill.render_entity'); $container->registerForAutoconfiguration(SearchApiInterface::class) ->addTag('chill.search_api_provider'); + $container->registerForAutoconfiguration(NotificationHandlerInterface::class) + ->addTag('chill_main.notification_handler'); $container->addCompilerPass(new SearchableServicesCompilerPass()); $container->addCompilerPass(new ConfigConsistencyCompilerPass()); diff --git a/src/Bundle/ChillMainBundle/Notification/NotificationHandlerManager.php b/src/Bundle/ChillMainBundle/Notification/NotificationHandlerManager.php index a28afd5e9..214f24239 100644 --- a/src/Bundle/ChillMainBundle/Notification/NotificationHandlerManager.php +++ b/src/Bundle/ChillMainBundle/Notification/NotificationHandlerManager.php @@ -11,29 +11,30 @@ declare(strict_types=1); namespace Chill\MainBundle\Notification; -use Chill\ActivityBundle\Notification\ActivityNotificationRenderer; use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound; -use Chill\PersonBundle\Notification\AccompanyingPeriodNotificationRenderer; +use Doctrine\ORM\EntityManagerInterface; final class NotificationHandlerManager { - private array $renderers; + private EntityManagerInterface $em; + + private iterable $handlers; public function __construct( - AccompanyingPeriodNotificationRenderer $accompanyingPeriodNotificationRenderer, - ActivityNotificationRenderer $activityNotificationRenderer + iterable $handlers, + EntityManagerInterface $em ) { - // TODO configure automatically - // TODO CREER UNE INTERFACE POUR ETRE SUR QUE LES RENDERERS SONT OK - - $this->renderers[] = $accompanyingPeriodNotificationRenderer; - $this->renderers[] = $activityNotificationRenderer; + $this->handlers = $handlers; + $this->em = $em; } + /** + * @throw NotificationHandlerNotFound if handler is not found + */ public function getHandler(Notification $notification): NotificationHandlerInterface { - foreach ($this->renderers as $renderer) { + foreach ($this->handlers as $renderer) { if ($renderer->supports($notification)) { return $renderer; } @@ -42,12 +43,12 @@ final class NotificationHandlerManager throw new NotificationHandlerNotFound(); } - public function getTemplate(Notification $notification) + public function getTemplate(Notification $notification): string { return $this->getHandler($notification)->getTemplate(); } - public function getTemplateData(Notification $notification) + public function getTemplateData(Notification $notification): array { return $this->getHandler($notification)->getTemplateData($notification); } diff --git a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig index 34aeee049..4f4f81ba2 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/Notification/list.html.twig @@ -4,7 +4,6 @@

{{ "Notifications list" | trans }}

- {%for data in datas %} {% set notification = data.notification %} @@ -36,6 +35,8 @@ {% include data.template with data.template_data %} + {% else %} +

{{ notification.Any notification received }}

{% endfor %}
diff --git a/src/Bundle/ChillMainBundle/config/services/notification.yaml b/src/Bundle/ChillMainBundle/config/services/notification.yaml index 34027d631..5d4390877 100644 --- a/src/Bundle/ChillMainBundle/config/services/notification.yaml +++ b/src/Bundle/ChillMainBundle/config/services/notification.yaml @@ -13,4 +13,6 @@ services: $translator: '@Symfony\Component\Translation\TranslatorInterface' $routeParameters: '%chill_main.notifications%' - Chill\MainBundle\Notification\NotificationHandlerManager: ~ + Chill\MainBundle\Notification\NotificationHandlerManager: + arguments: + $handlers: !tagged_iterator chill_main.notification_handler