mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
notificaiton: load interface automatically
This commit is contained in:
parent
5cebcfddb7
commit
f6f0786d38
@ -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());
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
<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 %}
|
||||
@ -36,6 +35,8 @@
|
||||
{% include data.template with data.template_data %}
|
||||
</dd>
|
||||
</dl>
|
||||
{% else %}
|
||||
<p class="chill-no-data-statement">{{ notification.Any notification received }}</p>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user