From 72a5e707bb153987e3fa90a7130f46d5a3c40816 Mon Sep 17 00:00:00 2001 From: numew Date: Thu, 30 Jan 2025 12:42:28 +0100 Subject: [PATCH 1/7] add popNotification system #3623 --- assets/scripts/app-back-bo.ts | 2 +- .../{modale_cgu_bo.js => bo_modales.js} | 21 ++++++ migrations/Version20250129155205.php | 28 +++++++ src/Controller/Back/PartnerController.php | 5 ++ .../Back/PopNotificationController.php | 47 ++++++++++++ src/Entity/PopNotification.php | 71 ++++++++++++++++++ src/Entity/User.php | 37 ++++++++++ src/Manager/PopNotificationManager.php | 73 +++++++++++++++++++ src/Repository/PopNotificationRepository.php | 18 +++++ templates/back/base_bo.html.twig | 7 +- .../back/pop-notification/index.html.twig | 64 ++++++++++++++++ templates/base.html.twig | 2 +- .../Manager/PopNotificationManagerTest.php | 56 ++++++++++++++ 13 files changed, 428 insertions(+), 3 deletions(-) rename assets/scripts/vanilla/services/{modale_cgu_bo.js => bo_modales.js} (66%) create mode 100644 migrations/Version20250129155205.php create mode 100644 src/Controller/Back/PopNotificationController.php create mode 100644 src/Entity/PopNotification.php create mode 100644 src/Manager/PopNotificationManager.php create mode 100644 src/Repository/PopNotificationRepository.php create mode 100644 templates/back/pop-notification/index.html.twig create mode 100644 tests/Functional/Manager/PopNotificationManagerTest.php diff --git a/assets/scripts/app-back-bo.ts b/assets/scripts/app-back-bo.ts index 444381542..41c740f8f 100644 --- a/assets/scripts/app-back-bo.ts +++ b/assets/scripts/app-back-bo.ts @@ -6,7 +6,7 @@ import './vue/signalement-carto.ts'; import './vue/dashboard.ts'; import './vanilla/services/data_delete.js' -import './vanilla/services/modale_cgu_bo.js'; +import './vanilla/services/bo_modales.js'; import './vanilla/services/pagination.js' import './vanilla/services/search_filter_form.js' import './vanilla/services/table_sortable.js' diff --git a/assets/scripts/vanilla/services/modale_cgu_bo.js b/assets/scripts/vanilla/services/bo_modales.js similarity index 66% rename from assets/scripts/vanilla/services/modale_cgu_bo.js rename to assets/scripts/vanilla/services/bo_modales.js index ca5a066ff..cf123c38c 100644 --- a/assets/scripts/vanilla/services/modale_cgu_bo.js +++ b/assets/scripts/vanilla/services/bo_modales.js @@ -45,3 +45,24 @@ function handleAcceptButton () { acceptCguBoCheckbox?.addEventListener('click', handleAcceptCheck) acceptCguBoButton?.addEventListener('click', handleAcceptButton) modalCguBo?.addEventListener('dsfr.disclose', handleModalDisclose) + +document.addEventListener('DOMContentLoaded', () => { + const modalPopNotification = document.getElementById('fr-modal-pop-notification') + if(modalPopNotification){ + modalPopNotification.addEventListener('dsfr.conceal', (e) => { + const deletePopNotificationUrl = modalPopNotification.dataset.deleteUrl; + console.log(e) + console.log(deletePopNotificationUrl) + //fetch(deletePopNotificationUrl, {}) + }); + } + + if(modalCguBo && modalPopNotification){ + modalCguBo.addEventListener('dsfr.conceal', (e) => { + dsfr(modalPopNotification).modal.disclose() + }); + }else if(modalPopNotification){ + dsfr(modalPopNotification).modal.disclose() + } +}); + diff --git a/migrations/Version20250129155205.php b/migrations/Version20250129155205.php new file mode 100644 index 000000000..59969c1b4 --- /dev/null +++ b/migrations/Version20250129155205.php @@ -0,0 +1,28 @@ +addSql('CREATE TABLE pop_notification (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', params JSON NOT NULL, INDEX IDX_257F9F96A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('ALTER TABLE pop_notification ADD CONSTRAINT FK_257F9F96A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE pop_notification DROP FOREIGN KEY FK_257F9F96A76ED395'); + $this->addSql('DROP TABLE pop_notification'); + } +} diff --git a/src/Controller/Back/PartnerController.php b/src/Controller/Back/PartnerController.php index b5632a391..d11484b62 100755 --- a/src/Controller/Back/PartnerController.php +++ b/src/Controller/Back/PartnerController.php @@ -19,6 +19,7 @@ use App\Manager\AffectationManager; use App\Manager\InterventionManager; use App\Manager\PartnerManager; +use App\Manager\PopNotificationManager; use App\Manager\UserManager; use App\Repository\AutoAffectationRuleRepository; use App\Repository\JobEventRepository; @@ -360,6 +361,7 @@ public function addUserPartnerMulti( UserRepository $userRepository, UserManager $userManager, NotificationMailerRegistry $notificationMailerRegistry, + PopNotificationManager $popNotificationManager, ): JsonResponse|RedirectResponse { if (!$this->featureMultiTerritories) { throw $this->createNotFoundException(); @@ -375,6 +377,7 @@ public function addUserPartnerMulti( $user = $userRepository->findAgentByEmail($userTmp->getEmail()); if ($user) { $userPartner->setUser($user); + $popNotificationManager->createOrUpdatePopNotification($user, 'addPartner', $partner); $userManager->save($userPartner); $notificationMailerRegistry->send( new NotificationMail( @@ -612,6 +615,7 @@ public function deleteUser( Partner $partner, UserManager $userManager, NotificationMailerRegistry $notificationMailerRegistry, + PopNotificationManager $popNotificationManager, ): Response { $userId = $request->request->get('user_id'); if (!$this->isCsrfTokenValid('partner_user_delete', $request->request->get('_token'))) { @@ -636,6 +640,7 @@ public function deleteUser( if ($user->getUserPartners()->count() > 1) { foreach ($user->getUserPartners() as $userPartner) { if ($userPartner->getPartner()->getId() === $partner->getId()) { + $popNotificationManager->createOrUpdatePopNotification($user, 'removePartner', $partner); $userManager->remove($userPartner); break; } diff --git a/src/Controller/Back/PopNotificationController.php b/src/Controller/Back/PopNotificationController.php new file mode 100644 index 000000000..288085fde --- /dev/null +++ b/src/Controller/Back/PopNotificationController.php @@ -0,0 +1,47 @@ +getUser(); + $popNotification = $user->getPopNotifications()->first(); + $addedPartnersIds = isset($popNotification->getParams()['addedPartners']) ? $popNotification->getParams()['addedPartners'] : []; + $removedPartnersIds = isset($popNotification->getParams()['removedPartners']) ? $popNotification->getParams()['removedPartners'] : []; + $addedPartners = $partnerRepository->findBy(['id' => $addedPartnersIds]); + $removedPartners = $partnerRepository->findBy(['id' => $removedPartnersIds]); + + return $this->render('back/pop-notification/index.html.twig', [ + 'user' => $user, + 'addedPartners' => $addedPartners, + 'removedPartners' => $removedPartners, + ]); + } + + #[Route('/delete', name: 'pop_notification_delete')] + public function delete( + PopNotificationManager $popNotificationManager, + ): JsonResponse { + /** @var ?User $user */ + $user = $this->getUser(); + $popNotification = $user->getPopNotifications()->count() ? $user->getPopNotifications()->first() : null; + if ($popNotification) { + $popNotificationManager->remove($popNotification); + } + + return new JsonResponse(['success' => true]); + } +} diff --git a/src/Entity/PopNotification.php b/src/Entity/PopNotification.php new file mode 100644 index 000000000..fadd59ee1 --- /dev/null +++ b/src/Entity/PopNotification.php @@ -0,0 +1,71 @@ +createdAt = new \DateTimeImmutable(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getUser(): ?User + { + return $this->user; + } + + public function setUser(?User $user): static + { + $this->user = $user; + + return $this; + } + + public function getCreatedAt(): ?\DateTimeImmutable + { + return $this->createdAt; + } + + public function setCreatedAt(\DateTimeImmutable $createdAt): static + { + $this->createdAt = $createdAt; + + return $this; + } + + public function getParams(): array + { + return $this->params; + } + + public function setParams(array $params): static + { + $this->params = $params; + + return $this; + } +} diff --git a/src/Entity/User.php b/src/Entity/User.php index 3bd2b877d..9c6ddd71b 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -178,6 +178,12 @@ class User implements UserInterface, EntityHistoryInterface, PasswordAuthenticat #[ORM\OneToMany(mappedBy: 'user', targetEntity: UserPartner::class, orphanRemoval: true)] private Collection $userPartners; + /** + * @var Collection + */ + #[ORM\OneToMany(mappedBy: 'user', targetEntity: PopNotification::class, orphanRemoval: true)] + private Collection $popNotifications; + public function __construct() { $this->suivis = new ArrayCollection(); @@ -189,6 +195,7 @@ public function __construct() $this->signalementUsagerOccupants = new ArrayCollection(); $this->apiUserTokens = new ArrayCollection(); $this->userPartners = new ArrayCollection(); + $this->popNotifications = new ArrayCollection(); } public function getId(): ?int @@ -840,4 +847,34 @@ public function removeApiUserToken(ApiUserToken $apiUserToken): self return $this; } + + /** + * @return Collection + */ + public function getPopNotifications(): Collection + { + return $this->popNotifications; + } + + public function addPopNotification(PopNotification $popNotification): static + { + if (!$this->popNotifications->contains($popNotification)) { + $this->popNotifications->add($popNotification); + $popNotification->setUser($this); + } + + return $this; + } + + public function removePopNotification(PopNotification $popNotification): static + { + if ($this->popNotifications->removeElement($popNotification)) { + // set the owning side to null (unless already changed) + if ($popNotification->getUser() === $this) { + $popNotification->setUser(null); + } + } + + return $this; + } } diff --git a/src/Manager/PopNotificationManager.php b/src/Manager/PopNotificationManager.php new file mode 100644 index 000000000..f140d033f --- /dev/null +++ b/src/Manager/PopNotificationManager.php @@ -0,0 +1,73 @@ +getStatut()) { + return null; + } + if ($user->getPopNotifications()->count()) { + $popNotification = $user->getPopNotifications()->first(); + } else { + $popNotification = new PopNotification(); + $user->addPopNotification($popNotification); + $this->persist($popNotification); + $popNotification->setUser($user); + } + switch ($type) { + case 'addPartner': + $this->managePartners($popNotification, $partner, 'add'); + break; + case 'removePartner': + $this->managePartners($popNotification, $partner, 'remove'); + break; + } + if (empty($popNotification->getParams()['addedPartners']) && empty($popNotification->getParams()['removedPartners'])) { + $this->remove($popNotification, false); + + return null; + } + + return $popNotification; + } + + private function managePartners(PopNotification $popNotification, Partner $partner, string $type): void + { + $keyToAdd = 'addedPartners'; + $keyToRemove = 'removedPartners'; + if ('remove' === $type) { + $keyToAdd = 'removedPartners'; + $keyToRemove = 'addedPartners'; + } + $list = isset($popNotification->getParams()[$keyToRemove]) ? $popNotification->getParams()[$keyToRemove] : []; + if (!empty($list) && in_array($partner->getId(), $list)) { + unset($list[array_search($partner->getId(), $list)]); + $params = array_merge($popNotification->getParams(), [$keyToRemove => $list]); + $popNotification->setParams($params); + + return; + } + $list = isset($popNotification->getParams()[$keyToAdd]) ? $popNotification->getParams()[$keyToAdd] : []; + $list[] = $partner->getId(); + $params = array_merge($popNotification->getParams(), [$keyToAdd => $list]); + $popNotification->setParams($params); + } +} diff --git a/src/Repository/PopNotificationRepository.php b/src/Repository/PopNotificationRepository.php new file mode 100644 index 000000000..71a84c9f4 --- /dev/null +++ b/src/Repository/PopNotificationRepository.php @@ -0,0 +1,18 @@ + + */ +class PopNotificationRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, PopNotification::class); + } +} diff --git a/templates/back/base_bo.html.twig b/templates/back/base_bo.html.twig index 011b69ca5..89b32f587 100755 --- a/templates/back/base_bo.html.twig +++ b/templates/back/base_bo.html.twig @@ -43,7 +43,7 @@ {% endblock %} -{% block cgumodale %} +{% block bo_modales %} {% if platform.cgu_current_version is not same as app.user.cguVersionChecked %} @@ -95,4 +95,9 @@ {% endif %} + + {% if app.user.popNotifications|length %} + {{ render(controller('App\\Controller\\Back\\PopNotificationController::show')) }} + {% endif %} + {% endblock %} diff --git a/templates/back/pop-notification/index.html.twig b/templates/back/pop-notification/index.html.twig new file mode 100644 index 000000000..16a91f221 --- /dev/null +++ b/templates/back/pop-notification/index.html.twig @@ -0,0 +1,64 @@ + + +
+
+
+
+
+
+
+

+ Modifications sur votre compte +

+
+

Des modifications ont été faites sur votre compte, veuillez en prendre connaissance avant de continuer !

+
+ {% if addedPartners|length %} + Votre compte a été ajouté : +
    + {% for partner in addedPartners %} +
  • au partenaire {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • + {% endfor %} +
+ {% endif %} + {% if removedPartners|length %} + Votre compte a été retiré : +
    + {% for partner in removedPartners %} +
  • du partenaire {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • + {% endfor %} +
+ {% endif %} + Désormais, +
+ 1. Vous avez accès aux signalements de : +
    + {% for partner in user.partners %} +
  • {{partner.nom}} - {{partner.territory.zip}} - {{partner.territory.name}}
  • + {% endfor %} +
+ {% set nb = 2 %} + {% if removedPartners|length %} + {{nb}}. Vous n'avez plus accès aux signalements de : +
    + {% for partner in removedPartners %} +
  • {{partner.nom}} - {{partner.territory.zip}} - {{partner.territory.name}}
  • + {% endfor %} +
+ {% set nb = nb + 1 %} + {% endif %} + {% if user.partners|length > 1 %} +

{{nb}}. Pour vous aider à naviguer, un filtre Territoire est disponible sur votre tableau de bord ainsi que sur la liste des signalements.

+ {% endif %} +

Pour plus d'informations, n'hésitez pas à contacter vos responsables de territoire !

+
+ +
+
+
+
+
\ No newline at end of file diff --git a/templates/base.html.twig b/templates/base.html.twig index 66448867d..4443ec8d6 100755 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -234,6 +234,6 @@ {% block javascripts %}{% endblock %} {% block documentation %}{% endblock %} -{% block cgumodale %}{% endblock %} +{% block bo_modales %}{% endblock %} diff --git a/tests/Functional/Manager/PopNotificationManagerTest.php b/tests/Functional/Manager/PopNotificationManagerTest.php new file mode 100644 index 000000000..b5bed7b42 --- /dev/null +++ b/tests/Functional/Manager/PopNotificationManagerTest.php @@ -0,0 +1,56 @@ +managerRegistry = self::getContainer()->get(ManagerRegistry::class); + $this->popNotificationManager = new PopNotificationManager( + $this->managerRegistry, + PopNotification::class, + ); + } + + public function testCreateOrUpdatePopNotification(): void + { + /** @var UserRepository $userRepository */ + $userRepository = $this->managerRegistry->getRepository(User::class); + /** @var PartnerRepository $partnerRepository */ + $partnerRepository = $this->managerRegistry->getRepository(Partner::class); + + $user = $userRepository->findOneBy(['email' => 'user-13-01@histologe.fr']); + $addPartners = []; + // ajout d'un partenaire + $partner63 = $partnerRepository->findOneBy(['nom' => 'ADIL 63']); + $popNotification = $this->popNotificationManager->createOrUpdatePopNotification($user, 'addPartner', $partner63); + $addPartners[] = $partner63->getId(); + $this->assertEquals($addPartners, $popNotification->getParams()['addedPartners']); + // ajout d'un autre partenaire + $partner89 = $partnerRepository->findOneBy(['nom' => 'ADIL 89']); + $addPartners[] = $partner89->getId(); + $popNotification = $this->popNotificationManager->createOrUpdatePopNotification($user, 'addPartner', $partner89); + $this->assertEquals($addPartners, $popNotification->getParams()['addedPartners']); + // suppression du premier partenaire + $popNotification = $this->popNotificationManager->createOrUpdatePopNotification($user, 'removePartner', $partner63); + unset($addPartners[array_search($partner63->getId(), $addPartners)]); + $this->assertEquals($addPartners, $popNotification->getParams()['addedPartners']); + // suppression du second partenaire + $popNotification = $this->popNotificationManager->createOrUpdatePopNotification($user, 'removePartner', $partner89); + $this->assertNull($popNotification); + } +} From 3ab53c21ffa5ad313abc5efb96a0dbf95cdf4207 Mon Sep 17 00:00:00 2001 From: numew Date: Fri, 31 Jan 2025 09:28:12 +0100 Subject: [PATCH 2/7] fix dsfr loading error #3623 --- assets/scripts/vanilla/services/bo_modales.js | 39 ++++++++++--------- templates/back/base_bo.html.twig | 2 +- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/assets/scripts/vanilla/services/bo_modales.js b/assets/scripts/vanilla/services/bo_modales.js index cf123c38c..94ba8aee5 100644 --- a/assets/scripts/vanilla/services/bo_modales.js +++ b/assets/scripts/vanilla/services/bo_modales.js @@ -46,23 +46,26 @@ acceptCguBoCheckbox?.addEventListener('click', handleAcceptCheck) acceptCguBoButton?.addEventListener('click', handleAcceptButton) modalCguBo?.addEventListener('dsfr.disclose', handleModalDisclose) -document.addEventListener('DOMContentLoaded', () => { - const modalPopNotification = document.getElementById('fr-modal-pop-notification') - if(modalPopNotification){ - modalPopNotification.addEventListener('dsfr.conceal', (e) => { - const deletePopNotificationUrl = modalPopNotification.dataset.deleteUrl; - console.log(e) - console.log(deletePopNotificationUrl) - //fetch(deletePopNotificationUrl, {}) - }); - } +const modalPopNotification = document.getElementById('fr-modal-pop-notification') +if(modalPopNotification){ + //prevent error dsfr is not defined or null + const checkDsfrInterval = setInterval(() => { + if (typeof dsfr !== 'undefined' && dsfr !== null) { + clearInterval(checkDsfrInterval); - if(modalCguBo && modalPopNotification){ - modalCguBo.addEventListener('dsfr.conceal', (e) => { - dsfr(modalPopNotification).modal.disclose() - }); - }else if(modalPopNotification){ - dsfr(modalPopNotification).modal.disclose() - } -}); + modalPopNotification.addEventListener('dsfr.conceal', (e) => { + const deletePopNotificationUrl = modalPopNotification.dataset.deleteUrl; + fetch(deletePopNotificationUrl, {}) + }); + + if (modalCguBo && modalPopNotification) { + modalCguBo.addEventListener('dsfr.conceal', (e) => { + dsfr(modalPopNotification).modal.disclose(); + }); + } else if (modalPopNotification) { + dsfr(modalPopNotification).modal.disclose(); + } + } + }, 100); +} diff --git a/templates/back/base_bo.html.twig b/templates/back/base_bo.html.twig index 89b32f587..c0f3299e7 100755 --- a/templates/back/base_bo.html.twig +++ b/templates/back/base_bo.html.twig @@ -97,7 +97,7 @@ {% endif %} {% if app.user.popNotifications|length %} - {{ render(controller('App\\Controller\\Back\\PopNotificationController::show')) }} + {{ render(controller('App\\Controller\\Back\\PopNotificationController::show')) }} {% endif %} {% endblock %} From aea1185be042b2209540204e41df81032cd56508 Mon Sep 17 00:00:00 2001 From: numew Date: Fri, 31 Jan 2025 09:45:55 +0100 Subject: [PATCH 3/7] add popNotification on partner deletion #3623 --- src/Controller/Back/PartnerController.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Controller/Back/PartnerController.php b/src/Controller/Back/PartnerController.php index d11484b62..a3d430a24 100755 --- a/src/Controller/Back/PartnerController.php +++ b/src/Controller/Back/PartnerController.php @@ -268,6 +268,7 @@ public function delete( WorkflowInterface $interventionPlanningStateMachine, InterventionManager $interventionManager, AffectationManager $affectationManager, + PopNotificationManager $popNotificationManager, ): Response { $partnerId = $request->request->get('partner_id'); /** @var ?Partner $partner */ @@ -285,6 +286,7 @@ public function delete( if ($user->getUserPartners()->count() > 1) { foreach ($user->getUserPartners() as $userPartner) { if ($userPartner->getPartner()->getId() === $partner->getId()) { + $popNotificationManager->createOrUpdatePopNotification($user, 'removePartner', $partner); $entityManager->remove($userPartner); break; } From df713dfa09109362effa365100f115715745178f Mon Sep 17 00:00:00 2001 From: numew Date: Fri, 31 Jan 2025 09:50:40 +0100 Subject: [PATCH 4/7] fix sonar issues #3623 --- assets/scripts/vanilla/services/bo_modales.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assets/scripts/vanilla/services/bo_modales.js b/assets/scripts/vanilla/services/bo_modales.js index 94ba8aee5..761dd3f2f 100644 --- a/assets/scripts/vanilla/services/bo_modales.js +++ b/assets/scripts/vanilla/services/bo_modales.js @@ -58,11 +58,11 @@ if(modalPopNotification){ fetch(deletePopNotificationUrl, {}) }); - if (modalCguBo && modalPopNotification) { + if (modalCguBo) { modalCguBo.addEventListener('dsfr.conceal', (e) => { dsfr(modalPopNotification).modal.disclose(); }); - } else if (modalPopNotification) { + } else { dsfr(modalPopNotification).modal.disclose(); } } From 0003d599ae935c70dfbf393e55ab1a4e61aa624a Mon Sep 17 00:00:00 2001 From: numew Date: Tue, 4 Feb 2025 10:34:42 +0100 Subject: [PATCH 5/7] changes based on comments #3623 --- ...29155205.php => Version20250204083053.php} | 4 +-- src/Entity/Partner.php | 1 + src/Entity/PopNotification.php | 33 +++++++------------ 3 files changed, 15 insertions(+), 23 deletions(-) rename migrations/{Version20250129155205.php => Version20250204083053.php} (63%) diff --git a/migrations/Version20250129155205.php b/migrations/Version20250204083053.php similarity index 63% rename from migrations/Version20250129155205.php rename to migrations/Version20250204083053.php index 59969c1b4..be6933cd6 100644 --- a/migrations/Version20250129155205.php +++ b/migrations/Version20250204083053.php @@ -7,7 +7,7 @@ use Doctrine\DBAL\Schema\Schema; use Doctrine\Migrations\AbstractMigration; -final class Version20250129155205 extends AbstractMigration +final class Version20250204083053 extends AbstractMigration { public function getDescription(): string { @@ -16,7 +16,7 @@ public function getDescription(): string public function up(Schema $schema): void { - $this->addSql('CREATE TABLE pop_notification (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, created_at DATETIME NOT NULL COMMENT \'(DC2Type:datetime_immutable)\', params JSON NOT NULL, INDEX IDX_257F9F96A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); + $this->addSql('CREATE TABLE pop_notification (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, params JSON NOT NULL, created_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', updated_at DATETIME DEFAULT NULL COMMENT \'(DC2Type:datetime_immutable)\', INDEX IDX_257F9F96A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB'); $this->addSql('ALTER TABLE pop_notification ADD CONSTRAINT FK_257F9F96A76ED395 FOREIGN KEY (user_id) REFERENCES user (id)'); } diff --git a/src/Entity/Partner.php b/src/Entity/Partner.php index c3d2d0aae..53b5764c5 100644 --- a/src/Entity/Partner.php +++ b/src/Entity/Partner.php @@ -17,6 +17,7 @@ use Symfony\Component\Validator\Constraints as Assert; #[ORM\Entity(repositoryClass: PartnerRepository::class)] +#[ORM\HasLifecycleCallbacks()] #[UniqueEntity( fields: ['email', 'territory', 'isArchive'], message: 'L\'e-mail générique existe déjà pour ce territoire. Veuillez saisir un autre e-mail partenaire.', diff --git a/src/Entity/PopNotification.php b/src/Entity/PopNotification.php index fadd59ee1..89bdcf50c 100644 --- a/src/Entity/PopNotification.php +++ b/src/Entity/PopNotification.php @@ -2,12 +2,18 @@ namespace App\Entity; +use App\Entity\Behaviour\EntityHistoryInterface; +use App\Entity\Behaviour\TimestampableTrait; +use App\Entity\Enum\HistoryEntryEvent; use App\Repository\PopNotificationRepository; use Doctrine\ORM\Mapping as ORM; #[ORM\Entity(repositoryClass: PopNotificationRepository::class)] -class PopNotification +#[ORM\HasLifecycleCallbacks()] +class PopNotification implements EntityHistoryInterface { + use TimestampableTrait; + #[ORM\Id] #[ORM\GeneratedValue] #[ORM\Column] @@ -17,17 +23,9 @@ class PopNotification #[ORM\JoinColumn(nullable: false)] private ?User $user = null; - #[ORM\Column] - private ?\DateTimeImmutable $createdAt = null; - #[ORM\Column] private array $params = []; - public function __construct() - { - $this->createdAt = new \DateTimeImmutable(); - } - public function getId(): ?int { return $this->id; @@ -45,18 +43,6 @@ public function setUser(?User $user): static return $this; } - public function getCreatedAt(): ?\DateTimeImmutable - { - return $this->createdAt; - } - - public function setCreatedAt(\DateTimeImmutable $createdAt): static - { - $this->createdAt = $createdAt; - - return $this; - } - public function getParams(): array { return $this->params; @@ -68,4 +54,9 @@ public function setParams(array $params): static return $this; } + + public function getHistoryRegisteredEvent(): array + { + return [HistoryEntryEvent::CREATE, HistoryEntryEvent::UPDATE, HistoryEntryEvent::DELETE]; + } } From 971e416b8bc790f6f05c658a7e214f99d973aaa4 Mon Sep 17 00:00:00 2001 From: numew Date: Tue, 4 Feb 2025 16:03:50 +0100 Subject: [PATCH 6/7] changes based on comments #3623 --- templates/back/profil/index.html.twig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/templates/back/profil/index.html.twig b/templates/back/profil/index.html.twig index 52ab18978..669482d17 100644 --- a/templates/back/profil/index.html.twig +++ b/templates/back/profil/index.html.twig @@ -46,9 +46,16 @@ {{ user_avatar_or_placeholder(app.user, 74) }}
{{ app.user.prenom ~' '~app.user.nom }} - {% for partner in app.user.partners %} - {{ partner.nom}} - {% endfor %} + {% if app.user.partners|length > 1 %} +

Mes partenaires

+
    + {% for partner in app.user.partners %} +
  • {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • + {% endfor %} +
      + {% elseif app.user.partners|length == 1 %} + {{ app.user.partners.first.nom }} + {% endif %}
From 13365f5871acb28a16b041ff705e59d0e787b664 Mon Sep 17 00:00:00 2001 From: numew Date: Fri, 7 Feb 2025 10:08:04 +0100 Subject: [PATCH 7/7] change based on comments #3623 --- templates/back/pop-notification/index.html.twig | 12 ++++++------ templates/back/profil/index.html.twig | 9 ++++++++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/templates/back/pop-notification/index.html.twig b/templates/back/pop-notification/index.html.twig index 16a91f221..d659bd7a1 100644 --- a/templates/back/pop-notification/index.html.twig +++ b/templates/back/pop-notification/index.html.twig @@ -17,7 +17,7 @@ Votre compte a été ajouté :
    {% for partner in addedPartners %} -
  • au partenaire {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • +
  • au partenaire {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • {% endfor %}
{% endif %} @@ -25,24 +25,24 @@ Votre compte a été retiré :
    {% for partner in removedPartners %} -
  • du partenaire {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • +
  • du partenaire {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • {% endfor %}
{% endif %} Désormais,
- 1. Vous avez accès aux signalements de : + 1. Vous avez accès aux signalements :
    {% for partner in user.partners %} -
  • {{partner.nom}} - {{partner.territory.zip}} - {{partner.territory.name}}
  • +
  • du partenaire {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • {% endfor %}
{% set nb = 2 %} {% if removedPartners|length %} - {{nb}}. Vous n'avez plus accès aux signalements de : + {{nb}}. Vous n'avez plus accès aux signalements :
    {% for partner in removedPartners %} -
  • {{partner.nom}} - {{partner.territory.zip}} - {{partner.territory.name}}
  • +
  • du partenaire {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • {% endfor %}
{% set nb = nb + 1 %} diff --git a/templates/back/profil/index.html.twig b/templates/back/profil/index.html.twig index 669482d17..99a5b3c60 100644 --- a/templates/back/profil/index.html.twig +++ b/templates/back/profil/index.html.twig @@ -52,7 +52,14 @@ {% for partner in app.user.partners %}
  • {{partner.nom}} du territoire {{partner.territory.zip}} - {{partner.territory.name}}
  • {% endfor %} -
      +
    +
    +

    + Vous ne pouvez pas modifier vos partenaires vous-même. +
    + Si vous souhaitez modifier vos partenaires, contactez vos responsables de territoire ! +

    +
    {% elseif app.user.partners|length == 1 %} {{ app.user.partners.first.nom }} {% endif %}