diff --git a/src/Bundle/ChillMainBundle/Controller/NotificationController.php b/src/Bundle/ChillMainBundle/Controller/NotificationController.php index d876241a5..2e4948aa9 100644 --- a/src/Bundle/ChillMainBundle/Controller/NotificationController.php +++ b/src/Bundle/ChillMainBundle/Controller/NotificationController.php @@ -11,10 +11,8 @@ declare(strict_types=1); namespace Chill\MainBundle\Controller; -use Chill\ActivityBundle\Entity\Activity; use Chill\MainBundle\Entity\Notification; use Chill\MainBundle\Entity\NotificationComment; -use Chill\MainBundle\Entity\NotificationFlagEnum; use Chill\MainBundle\Form\NotificationCommentType; use Chill\MainBundle\Form\NotificationType; use Chill\MainBundle\Notification\Exception\NotificationHandlerNotFound; @@ -24,9 +22,6 @@ use Chill\MainBundle\Repository\NotificationRepository; use Chill\MainBundle\Repository\UserRepository; use Chill\MainBundle\Security\Authorization\NotificationVoter; 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 Psr\Log\LoggerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; @@ -58,29 +53,12 @@ class NotificationController extends AbstractController 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 ->setRelatedEntityClass($request->query->get('entityClass')) ->setRelatedEntityId($request->query->getInt('entityId')) ->setSender($this->security->getUser()) - ->setType($notificationType); + ->setType('notif-by-user'); $tos = $request->query->all('tos'); diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index 38b4b195e..87c5c95ed 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -110,8 +110,8 @@ class Notification implements TrackUpdateInterface #[ORM\ManyToOne(targetEntity: User::class)] private ?User $updatedBy = null; - #[ORM\Column(name: 'type', type: Types::STRING, nullable: true, enumType: NotificationFlagEnum::class)] - private NotificationFlagEnum $type; + #[ORM\Column(name: 'type', type: Types::STRING, nullable: true)] + private string $type; public function __construct() { @@ -455,14 +455,14 @@ class Notification implements TrackUpdateInterface return $this; } - public function setType(NotificationFlagEnum $type): self + public function setType(string $type): self { $this->type = $type; return $this; } - public function getType(): NotificationFlagEnum + public function getType(): string { return $this->type; } diff --git a/src/Bundle/ChillMainBundle/Entity/NotificationFlagEnum.php b/src/Bundle/ChillMainBundle/Entity/NotificationFlagEnum.php deleted file mode 100644 index 2ee4345d8..000000000 --- a/src/Bundle/ChillMainBundle/Entity/NotificationFlagEnum.php +++ /dev/null @@ -1,23 +0,0 @@ -has('immediate_email')) { $flagForm->get('immediate_email')->setData($immediateEmailChecked); @@ -45,6 +46,9 @@ final readonly class NotificationFlagDataMapper implements DataMapperInterface if ($flagForm->has('daily_email')) { $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'; } - if (empty($viewData[$flag])) { + if ($flagForm['no_email']->getData()) { $viewData[$flag][] = 'no-email'; } } diff --git a/src/Bundle/ChillMainBundle/Form/Type/NotificationFlagsType.php b/src/Bundle/ChillMainBundle/Form/Type/NotificationFlagsType.php index 9c21b59d1..fb25c9ae0 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/NotificationFlagsType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/NotificationFlagsType.php @@ -43,13 +43,19 @@ class NotificationFlagsType extends AbstractType ->add('immediate_email', CheckboxType::class, [ 'label' => false, 'required' => false, - 'mapped' => false, // Keep this here for the individual checkboxes + 'mapped' => false, ]) ->add('daily_email', CheckboxType::class, [ 'label' => 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, + ]) + ; } } diff --git a/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseNotificationFlagProvider.php b/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseNotificationFlagProvider.php deleted file mode 100644 index 50d72531a..000000000 --- a/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseNotificationFlagProvider.php +++ /dev/null @@ -1,21 +0,0 @@ -value; - } - - public function getLabel(): TranslatableInterface - { - return new TranslatableMessage('notification.flags.acc-course'); - } -} diff --git a/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseWorkEvalDocNotificationFlagProvider.php b/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseWorkEvalDocNotificationFlagProvider.php deleted file mode 100644 index 3e96f6361..000000000 --- a/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseWorkEvalDocNotificationFlagProvider.php +++ /dev/null @@ -1,21 +0,0 @@ -value; - } - - public function getLabel(): TranslatableInterface - { - return new TranslatableMessage('notification.flags.acc-course-work-eval-doc'); - } -} diff --git a/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseWorkNotificationFlagProvider.php b/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseWorkNotificationFlagProvider.php deleted file mode 100644 index b71abf5d4..000000000 --- a/src/Bundle/ChillMainBundle/Notification/FlagProviders/AccompanyingCourseWorkNotificationFlagProvider.php +++ /dev/null @@ -1,21 +0,0 @@ -value; - } - - public function getLabel(): TranslatableInterface - { - return new TranslatableMessage('notification.flags.acc-course-work'); - } -} diff --git a/src/Bundle/ChillMainBundle/Notification/FlagProviders/DesignatedReferrerNotificationFlagProvider.php b/src/Bundle/ChillMainBundle/Notification/FlagProviders/DesignatedReferrerNotificationFlagProvider.php index 335d4339e..582cd231b 100644 --- a/src/Bundle/ChillMainBundle/Notification/FlagProviders/DesignatedReferrerNotificationFlagProvider.php +++ b/src/Bundle/ChillMainBundle/Notification/FlagProviders/DesignatedReferrerNotificationFlagProvider.php @@ -2,7 +2,6 @@ namespace Chill\MainBundle\Notification\FlagProviders; -use Chill\MainBundle\Entity\NotificationFlagEnum; use Symfony\Component\Translation\TranslatableMessage; use Symfony\Contracts\Translation\TranslatableInterface; @@ -11,7 +10,7 @@ class DesignatedReferrerNotificationFlagProvider implements NotificationFlagProv public function getFlag(): string { - return NotificationFlagEnum::REFERRER_ACC_COURSE->value; + return 'referrer-acc-course-notif'; } public function getLabel(): TranslatableInterface diff --git a/src/Bundle/ChillMainBundle/Notification/FlagProviders/ActivityNotificationFlagProvider.php b/src/Bundle/ChillMainBundle/Notification/FlagProviders/NotificationByUserFlagProvider.php similarity index 53% rename from src/Bundle/ChillMainBundle/Notification/FlagProviders/ActivityNotificationFlagProvider.php rename to src/Bundle/ChillMainBundle/Notification/FlagProviders/NotificationByUserFlagProvider.php index 78515d72d..9c29c062c 100644 --- a/src/Bundle/ChillMainBundle/Notification/FlagProviders/ActivityNotificationFlagProvider.php +++ b/src/Bundle/ChillMainBundle/Notification/FlagProviders/NotificationByUserFlagProvider.php @@ -2,20 +2,19 @@ namespace Chill\MainBundle\Notification\FlagProviders; -use Chill\MainBundle\Entity\NotificationFlagEnum; use Symfony\Component\Translation\TranslatableMessage; use Symfony\Contracts\Translation\TranslatableInterface; -class ActivityNotificationFlagProvider implements NotificationFlagProviderInterface +class NotificationByUserFlagProvider implements NotificationFlagProviderInterface { public function getFlag(): string { - return NotificationFlagEnum::ACTIVITY->value; + return 'notif-by-user'; } public function getLabel(): TranslatableInterface { - return new TranslatableMessage('notification.flags.activity'); + return new TranslatableMessage('notification.flags.by-user'); } } diff --git a/src/Bundle/ChillMainBundle/Notification/FlagProviders/PersonAddressMoveNotificationFlagProvider.php b/src/Bundle/ChillMainBundle/Notification/FlagProviders/PersonAddressMoveNotificationFlagProvider.php index 6f33fa427..5842681ea 100644 --- a/src/Bundle/ChillMainBundle/Notification/FlagProviders/PersonAddressMoveNotificationFlagProvider.php +++ b/src/Bundle/ChillMainBundle/Notification/FlagProviders/PersonAddressMoveNotificationFlagProvider.php @@ -2,7 +2,6 @@ namespace Chill\MainBundle\Notification\FlagProviders; -use Chill\MainBundle\Entity\NotificationFlagEnum; use Symfony\Component\Translation\TranslatableMessage; use Symfony\Contracts\Translation\TranslatableInterface; @@ -11,7 +10,7 @@ class PersonAddressMoveNotificationFlagProvider implements NotificationFlagProvi public function getFlag(): string { - return NotificationFlagEnum::PERSON_MOVE->value; + return 'person-move-notif'; } public function getLabel(): TranslatableInterface diff --git a/src/Bundle/ChillMainBundle/Notification/FlagProviders/WorkflowTransitionNotificationFlagProvider.php b/src/Bundle/ChillMainBundle/Notification/FlagProviders/WorkflowTransitionNotificationFlagProvider.php index 3e48c400c..a048c91a5 100644 --- a/src/Bundle/ChillMainBundle/Notification/FlagProviders/WorkflowTransitionNotificationFlagProvider.php +++ b/src/Bundle/ChillMainBundle/Notification/FlagProviders/WorkflowTransitionNotificationFlagProvider.php @@ -2,7 +2,6 @@ namespace Chill\MainBundle\Notification\FlagProviders; -use Chill\MainBundle\Entity\NotificationFlagEnum; use Symfony\Component\Translation\TranslatableMessage; use Symfony\Contracts\Translation\TranslatableInterface; @@ -11,7 +10,7 @@ class WorkflowTransitionNotificationFlagProvider implements NotificationFlagProv public function getFlag(): string { - return NotificationFlagEnum::WORKFLOW_TRANS->value; + return 'workflow-trans-notif'; } public function getLabel(): TranslatableInterface diff --git a/src/Bundle/ChillMainBundle/Resources/views/User/profile.html.twig b/src/Bundle/ChillMainBundle/Resources/views/User/profile.html.twig index 4448cae54..7a432332c 100644 --- a/src/Bundle/ChillMainBundle/Resources/views/User/profile.html.twig +++ b/src/Bundle/ChillMainBundle/Resources/views/User/profile.html.twig @@ -52,6 +52,7 @@ {{ 'notification.flags.type'|trans }} {{ 'notification.flags.preferences.immediate_email'|trans }} {{ 'notification.flags.preferences.daily_email'|trans }} + {{ 'notification.flags.preferences.no_email'|trans }} @@ -66,6 +67,9 @@ {{ form_widget(flag.daily_email) }} + + {{ form_widget(flag.no_email) }} + {% endfor %} diff --git a/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php b/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php index df0dc205c..c1cf38f79 100644 --- a/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php +++ b/src/Bundle/ChillMainBundle/Workflow/EventSubscriber/NotificationOnTransition.php @@ -12,7 +12,6 @@ declare(strict_types=1); namespace Chill\MainBundle\Workflow\EventSubscriber; use Chill\MainBundle\Entity\Notification; -use Chill\MainBundle\Entity\NotificationFlagEnum; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Entity\UserGroup; 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)) ->setMessage($this->engine->render('@ChillMain/Workflow/workflow_notification_on_transition_completed_content.fr.txt.twig', $context)) ->addAddressee($subscriber) - ->setType(NotificationFlagEnum::WORKFLOW_TRANS); + ->setType('workflow-trans-notif'); $this->entityManager->persist($notification); } } diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index 2b66d9a4e..929bcac0d 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -719,17 +719,15 @@ notification: flags: 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 - 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: Notification sur un usager workflow-trans: Notification sur une transition d'un workflow preferences: immediate_email: Recevoir un email immédiatement daily_email: Recevoir un récapitulatif quotidien + no_email: Ne pas recevoir un email diff --git a/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/PersonAddressMoveEventSubscriber.php b/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/PersonAddressMoveEventSubscriber.php index b5c3f988b..2c63a5f7d 100644 --- a/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/PersonAddressMoveEventSubscriber.php +++ b/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/PersonAddressMoveEventSubscriber.php @@ -13,7 +13,6 @@ namespace Chill\PersonBundle\AccompanyingPeriod\Events; use Chill\MainBundle\Entity\Address; use Chill\MainBundle\Entity\Notification; -use Chill\MainBundle\Entity\NotificationFlagEnum; use Chill\MainBundle\Notification\NotificationPersisterInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; use Chill\PersonBundle\Event\Person\PersonAddressMoveEvent; @@ -67,7 +66,7 @@ class PersonAddressMoveEventSubscriber implements EventSubscriberInterface 'oldPersonLocation' => $person, 'period' => $period, ])) - ->setType(NotificationFlagEnum::PERSON_MOVE); + ->setType('person-move-notif'); $this->notificationPersister->persist($notification); } diff --git a/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/UserRefEventSubscriber.php b/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/UserRefEventSubscriber.php index f2f4d677c..9e42afc67 100644 --- a/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/UserRefEventSubscriber.php +++ b/src/Bundle/ChillPersonBundle/AccompanyingPeriod/Events/UserRefEventSubscriber.php @@ -12,7 +12,6 @@ declare(strict_types=1); namespace Chill\PersonBundle\AccompanyingPeriod\Events; use Chill\MainBundle\Entity\Notification; -use Chill\MainBundle\Entity\NotificationFlagEnum; use Chill\MainBundle\Entity\User; use Chill\MainBundle\Notification\NotificationPersisterInterface; use Chill\PersonBundle\Entity\AccompanyingPeriod; @@ -75,7 +74,7 @@ class UserRefEventSubscriber implements EventSubscriberInterface ] )) ->addAddressee($period->getUser()) - ->setType(NotificationFlagEnum::REFERRER_ACC_COURSE); + ->setType('referrer-acc-course-notif'); $this->notificationPersister->persist($notification); }