Create notification flag providers

This commit is contained in:
Julie Lenaerts 2025-06-10 14:32:05 +02:00
parent c917c42789
commit c9c565809a
11 changed files with 231 additions and 0 deletions

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
class AccompanyingCourseNotificationFlagProvider implements NotificationFlagProviderInterface
{
public function getFlag(): string
{
return 'acc-course-notif';
}
public function getLabel(): TranslatableInterface
{
return new TranslatableMessage('notification.flags.acc-course');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
class AccompanyingCourseWorkEvalNotificationFlagProvider implements NotificationFlagProviderInterface
{
public function getFlag(): string
{
return 'acc-course-work-eval-notif';
}
public function getLabel(): TranslatableInterface
{
return new TranslatableMessage('notification.flags.acc-course-work-eval');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
class AccompanyingCourseWorkNotificationFlagProvider implements NotificationFlagProviderInterface
{
public function getFlag(): string
{
return 'acc-course-work-notif';
}
public function getLabel(): TranslatableInterface
{
return new TranslatableMessage('notification.flags.acc-course-work');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
class ActivityNotificationFlagProvider implements NotificationFlagProviderInterface
{
public function getFlag(): string
{
return 'activity-notif';
}
public function getLabel(): TranslatableInterface
{
return new TranslatableMessage('notification.flags.activity');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
class DesignatedReferrerNotificationFlagProvider implements NotificationFlagProviderInterface
{
public function getFlag(): string
{
return 'referrer-acc-course-notif';
}
public function getLabel(): TranslatableInterface
{
return new TranslatableMessage('notification.flags.referrer-acc-course');
}
}

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Contracts\Translation\TranslatableInterface;
use Symfony\Component\DependencyInjection\Attribute\AutoconfigureTag;
#[AutoconfigureTag('chill_main.notification_flag_provider')]
interface NotificationFlagProviderInterface
{
public function getFlag(): string;
public function getLabel(): TranslatableInterface;
}

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
class PersonAddressMoveNotificationFlagProvider implements NotificationFlagProviderInterface
{
public function getFlag(): string
{
return 'person-address-move-notif';
}
public function getLabel(): TranslatableInterface
{
return new TranslatableMessage('notification.flags.person-address-move');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
class PersonNotificationFlagProvider implements NotificationFlagProviderInterface
{
public function getFlag(): string
{
return 'person-notif';
}
public function getLabel(): TranslatableInterface
{
return new TranslatableMessage('notification.flags.person');
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Chill\MainBundle\Notification\FlagProviders;
use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface;
class WorkflowTransitionNotificationFlagProvider implements NotificationFlagProviderInterface
{
public function getFlag(): string
{
return 'workflow-trans-notif';
}
public function getLabel(): TranslatableInterface
{
return new TranslatableMessage('notification.flags.workflow-trans');
}
}

View File

@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
/*
* Chill is a software for social workers
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\MainBundle\Notification;
use Chill\MainBundle\Notification\FlagProviders\NotificationFlagProviderInterface;
final readonly class NotificationFlagManager
{
/**
* @var array<NotificationFlagProviderInterface>
*/
private array $notificationFlagProviders;
public function __construct(
iterable $notificaitonFlagProviders,
) {
$this->notificationFlagProviders = iterator_to_array($notificaitonFlagProviders);
}
public function getAllNotificationFlagProviders(): array
{
return $this->notificationFlagProviders;
}
public function getNotificationFlagProviderByLabel(string $label): ?NotificationFlagProviderInterface
{
foreach ($this->notificationFlagProviders as $provider) {
if ($provider->getLabel() == $label) {
return $provider;
}
}
return null;
}
}

View File

@ -12,6 +12,10 @@ services:
arguments: arguments:
$routeParameters: '%chill_main.notifications%' $routeParameters: '%chill_main.notifications%'
Chill\MainBundle\Notification\NotificationFlagManager:
arguments:
$notificationFlagProviders: !tagged_iterator chill_main.notification_flag_provider
Chill\MainBundle\Notification\NotificationHandlerManager: Chill\MainBundle\Notification\NotificationHandlerManager:
arguments: arguments:
$handlers: !tagged_iterator chill_main.notification_handler $handlers: !tagged_iterator chill_main.notification_handler