Remove the use of notificationFlagEnum

This commit is contained in:
Julie Lenaerts 2025-07-03 17:04:31 +02:00
parent 7d086ed2d9
commit 29f49ee81d
17 changed files with 34 additions and 137 deletions

View File

@ -11,10 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Controller; namespace Chill\MainBundle\Controller;
use Chill\ActivityBundle\Entity\Activity;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\NotificationComment; use Chill\MainBundle\Entity\NotificationComment;
use Chill\MainBundle\Entity\NotificationFlagEnum;
use Chill\MainBundle\Form\NotificationCommentType; use Chill\MainBundle\Form\NotificationCommentType;
use Chill\MainBundle\Form\NotificationType; use Chill\MainBundle\Form\NotificationType;
use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound; use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound;
@ -24,9 +22,6 @@ use Chill\MainBundle\Repository\NotificationRepository;
use Chill\MainBundle\Repository\UserRepository; use Chill\MainBundle\Repository\UserRepository;
use Chill\MainBundle\Security\Authorization\NotificationVoter; use Chill\MainBundle\Security\Authorization\NotificationVoter;
use Chill\MainBundle\Security\ChillSecurity; use Chill\MainBundle\Security\ChillSecurity;
use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWork;
use Chill\PersonBundle\Entity\AccompanyingPeriod\AccompanyingPeriodWorkEvaluation;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
@ -58,29 +53,12 @@ class NotificationController extends AbstractController
throw new BadRequestHttpException('missing entityId parameter'); throw new BadRequestHttpException('missing entityId parameter');
} }
$notificationType = '';
switch ($request->query->get('entityClass')) {
case Activity::class:
$notificationType = NotificationFlagEnum::ACTIVITY;
break;
case AccompanyingPeriod::class:
$notificationType = NotificationFlagEnum::ACC_COURSE;
break;
case AccompanyingPeriodWork::class:
$notificationType = NotificationFlagEnum::ACC_COURSE_WORK;
break;
case AccompanyingPeriod\AccompanyingPeriodWorkEvaluationDocument::class:
$notificationType = NotificationFlagEnum::ACC_COURSE_WORK_EVAL_DOC;
break;
}
$notification = new Notification(); $notification = new Notification();
$notification $notification
->setRelatedEntityClass($request->query->get('entityClass')) ->setRelatedEntityClass($request->query->get('entityClass'))
->setRelatedEntityId($request->query->getInt('entityId')) ->setRelatedEntityId($request->query->getInt('entityId'))
->setSender($this->security->getUser()) ->setSender($this->security->getUser())
->setType($notificationType); ->setType('notif-by-user');
$tos = $request->query->all('tos'); $tos = $request->query->all('tos');

View File

@ -110,8 +110,8 @@ class Notification implements TrackUpdateInterface
#[ORM\ManyToOne(targetEntity: User::class)] #[ORM\ManyToOne(targetEntity: User::class)]
private ?User $updatedBy = null; private ?User $updatedBy = null;
#[ORM\Column(name: 'type', type: Types::STRING, nullable: true, enumType: NotificationFlagEnum::class)] #[ORM\Column(name: 'type', type: Types::STRING, nullable: true)]
private NotificationFlagEnum $type; private string $type;
public function __construct() public function __construct()
{ {
@ -455,14 +455,14 @@ class Notification implements TrackUpdateInterface
return $this; return $this;
} }
public function setType(NotificationFlagEnum $type): self public function setType(string $type): self
{ {
$this->type = $type; $this->type = $type;
return $this; return $this;
} }
public function getType(): NotificationFlagEnum public function getType(): string
{ {
return $this->type; return $this->type;
} }

View File

@ -1,23 +0,0 @@
<?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\Entity;
enum NotificationFlagEnum: string
{
case REFERRER_ACC_COURSE = 'referrer-acc-course-notif';
case PERSON_MOVE = 'person-move-notif';
case ACC_COURSE = 'acc-course-notif';
case WORKFLOW_TRANS = 'workflow-trans-notif';
case ACC_COURSE_WORK = 'acc-course-work-notif';
case ACC_COURSE_WORK_EVAL_DOC = 'acc-course-work-eval-doc-notif';
case ACTIVITY = 'activity-notif';
}

View File

@ -38,6 +38,7 @@ final readonly class NotificationFlagDataMapper implements DataMapperInterface
$immediateEmailChecked = in_array('immediate-email', $viewData[$flag] ?? []); $immediateEmailChecked = in_array('immediate-email', $viewData[$flag] ?? []);
$dailyEmailChecked = in_array('daily-email', $viewData[$flag] ?? []); $dailyEmailChecked = in_array('daily-email', $viewData[$flag] ?? []);
$noEmailChecked = in_array('no-email', $viewData[$flag] ?? []);
if ($flagForm->has('immediate_email')) { if ($flagForm->has('immediate_email')) {
$flagForm->get('immediate_email')->setData($immediateEmailChecked); $flagForm->get('immediate_email')->setData($immediateEmailChecked);
@ -45,6 +46,9 @@ final readonly class NotificationFlagDataMapper implements DataMapperInterface
if ($flagForm->has('daily_email')) { if ($flagForm->has('daily_email')) {
$flagForm->get('daily_email')->setData($dailyEmailChecked); $flagForm->get('daily_email')->setData($dailyEmailChecked);
} }
if ($flagForm->has('no_email')) {
$flagForm->get('no_email')->setData($noEmailChecked);
}
} }
} }
} }
@ -69,7 +73,7 @@ final readonly class NotificationFlagDataMapper implements DataMapperInterface
$viewData[$flag][] = 'daily-email'; $viewData[$flag][] = 'daily-email';
} }
if (empty($viewData[$flag])) { if ($flagForm['no_email']->getData()) {
$viewData[$flag][] = 'no-email'; $viewData[$flag][] = 'no-email';
} }
} }

View File

@ -43,13 +43,19 @@ class NotificationFlagsType extends AbstractType
->add('immediate_email', CheckboxType::class, [ ->add('immediate_email', CheckboxType::class, [
'label' => false, 'label' => false,
'required' => false, 'required' => false,
'mapped' => false, // Keep this here for the individual checkboxes 'mapped' => false,
]) ])
->add('daily_email', CheckboxType::class, [ ->add('daily_email', CheckboxType::class, [
'label' => false, 'label' => false,
'required' => false, 'required' => false,
'mapped' => false, // Keep this here for the individual checkboxes 'mapped' => false,
]); ])
->add('no_email', CheckboxType::class, [
'label' => false,
'required' => false,
'mapped' => false,
])
;
} }
} }

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@
namespace Chill\MainBundle\Notification\FlagProviders; namespace Chill\MainBundle\Notification\FlagProviders;
use Chill\MainBundle\Entity\NotificationFlagEnum;
use Symfony\Component\Translation\TranslatableMessage; use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface; use Symfony\Contracts\Translation\TranslatableInterface;
@ -11,7 +10,7 @@ class DesignatedReferrerNotificationFlagProvider implements NotificationFlagProv
public function getFlag(): string public function getFlag(): string
{ {
return NotificationFlagEnum::REFERRER_ACC_COURSE->value; return 'referrer-acc-course-notif';
} }
public function getLabel(): TranslatableInterface public function getLabel(): TranslatableInterface

View File

@ -2,20 +2,19 @@
namespace Chill\MainBundle\Notification\FlagProviders; namespace Chill\MainBundle\Notification\FlagProviders;
use Chill\MainBundle\Entity\NotificationFlagEnum;
use Symfony\Component\Translation\TranslatableMessage; use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface; use Symfony\Contracts\Translation\TranslatableInterface;
class ActivityNotificationFlagProvider implements NotificationFlagProviderInterface class NotificationByUserFlagProvider implements NotificationFlagProviderInterface
{ {
public function getFlag(): string public function getFlag(): string
{ {
return NotificationFlagEnum::ACTIVITY->value; return 'notif-by-user';
} }
public function getLabel(): TranslatableInterface public function getLabel(): TranslatableInterface
{ {
return new TranslatableMessage('notification.flags.activity'); return new TranslatableMessage('notification.flags.by-user');
} }
} }

View File

@ -2,7 +2,6 @@
namespace Chill\MainBundle\Notification\FlagProviders; namespace Chill\MainBundle\Notification\FlagProviders;
use Chill\MainBundle\Entity\NotificationFlagEnum;
use Symfony\Component\Translation\TranslatableMessage; use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface; use Symfony\Contracts\Translation\TranslatableInterface;
@ -11,7 +10,7 @@ class PersonAddressMoveNotificationFlagProvider implements NotificationFlagProvi
public function getFlag(): string public function getFlag(): string
{ {
return NotificationFlagEnum::PERSON_MOVE->value; return 'person-move-notif';
} }
public function getLabel(): TranslatableInterface public function getLabel(): TranslatableInterface

View File

@ -2,7 +2,6 @@
namespace Chill\MainBundle\Notification\FlagProviders; namespace Chill\MainBundle\Notification\FlagProviders;
use Chill\MainBundle\Entity\NotificationFlagEnum;
use Symfony\Component\Translation\TranslatableMessage; use Symfony\Component\Translation\TranslatableMessage;
use Symfony\Contracts\Translation\TranslatableInterface; use Symfony\Contracts\Translation\TranslatableInterface;
@ -11,7 +10,7 @@ class WorkflowTransitionNotificationFlagProvider implements NotificationFlagProv
public function getFlag(): string public function getFlag(): string
{ {
return NotificationFlagEnum::WORKFLOW_TRANS->value; return 'workflow-trans-notif';
} }
public function getLabel(): TranslatableInterface public function getLabel(): TranslatableInterface

View File

@ -52,6 +52,7 @@
<th>{{ 'notification.flags.type'|trans }}</th> <th>{{ 'notification.flags.type'|trans }}</th>
<th>{{ 'notification.flags.preferences.immediate_email'|trans }}</th> <th>{{ 'notification.flags.preferences.immediate_email'|trans }}</th>
<th>{{ 'notification.flags.preferences.daily_email'|trans }}</th> <th>{{ 'notification.flags.preferences.daily_email'|trans }}</th>
<th>{{ 'notification.flags.preferences.no_email'|trans }}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -66,6 +67,9 @@
<td> <td>
{{ form_widget(flag.daily_email) }} {{ form_widget(flag.daily_email) }}
</td> </td>
<td>
{{ form_widget(flag.no_email) }}
</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>

View File

@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\MainBundle\Workflow\EventSubscriber; namespace Chill\MainBundle\Workflow\EventSubscriber;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\NotificationFlagEnum;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\UserGroup; use Chill\MainBundle\Entity\UserGroup;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow; use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
@ -127,7 +126,7 @@ class NotificationOnTransition implements EventSubscriberInterface
->setTitle($this->engine->render('@ChillMain/Workflow/workflow_notification_on_transition_completed_title.fr.txt.twig', $context)) ->setTitle($this->engine->render('@ChillMain/Workflow/workflow_notification_on_transition_completed_title.fr.txt.twig', $context))
->setMessage($this->engine->render('@ChillMain/Workflow/workflow_notification_on_transition_completed_content.fr.txt.twig', $context)) ->setMessage($this->engine->render('@ChillMain/Workflow/workflow_notification_on_transition_completed_content.fr.txt.twig', $context))
->addAddressee($subscriber) ->addAddressee($subscriber)
->setType(NotificationFlagEnum::WORKFLOW_TRANS); ->setType('workflow-trans-notif');
$this->entityManager->persist($notification); $this->entityManager->persist($notification);
} }
} }

View File

@ -719,17 +719,15 @@ notification:
flags: flags:
type: Type de notification type: Type de notification
by-user: Notification envoyé par un autre utilisateur
referrer-acc-course: Notification lors de la désignation comme référent referrer-acc-course: Notification lors de la désignation comme référent
acc-course-work-eval-doc: Notification sur un document d'évaluation
acc-course-work: Notification sur un action d'accompagnement
activity: Notification sur un échange
acc-course: Notification sur un parcours d'accompagnement
person-address-move: Notification lors que l'usager qui localise un parcours a déménagé person-address-move: Notification lors que l'usager qui localise un parcours a déménagé
person: Notification sur un usager person: Notification sur un usager
workflow-trans: Notification sur une transition d'un workflow workflow-trans: Notification sur une transition d'un workflow
preferences: preferences:
immediate_email: Recevoir un email immédiatement immediate_email: Recevoir un email immédiatement
daily_email: Recevoir un récapitulatif quotidien daily_email: Recevoir un récapitulatif quotidien
no_email: Ne pas recevoir un email

View File

@ -13,7 +13,6 @@ namespace Chill\PersonBundle\AccompanyingPeriod\Events;
use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\NotificationFlagEnum;
use Chill\MainBundle\Notification\NotificationPersisterInterface; use Chill\MainBundle\Notification\NotificationPersisterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent; use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent;
@ -67,7 +66,7 @@ class PersonAddressMoveEventSubscriber implements EventSubscriberInterface
'oldPersonLocation' => $person, 'oldPersonLocation' => $person,
'period' => $period, 'period' => $period,
])) ]))
->setType(NotificationFlagEnum::PERSON_MOVE); ->setType('person-move-notif');
$this->notificationPersister->persist($notification); $this->notificationPersister->persist($notification);
} }

View File

@ -12,7 +12,6 @@ declare(strict_types=1);
namespace Chill\PersonBundle\AccompanyingPeriod\Events; namespace Chill\PersonBundle\AccompanyingPeriod\Events;
use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\Notification;
use Chill\MainBundle\Entity\NotificationFlagEnum;
use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Notification\NotificationPersisterInterface; use Chill\MainBundle\Notification\NotificationPersisterInterface;
use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Entity\AccompanyingPeriod;
@ -75,7 +74,7 @@ class UserRefEventSubscriber implements EventSubscriberInterface
] ]
)) ))
->addAddressee($period->getUser()) ->addAddressee($period->getUser())
->setType(NotificationFlagEnum::REFERRER_ACC_COURSE); ->setType('referrer-acc-course-notif');
$this->notificationPersister->persist($notification); $this->notificationPersister->persist($notification);
} }