From 3ec212df93f868150d4193844bd749af52405864 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 9 Jun 2021 14:54:36 +0200 Subject: [PATCH 01/14] Creation of Notification Entity --- .../ChillMainBundle/Entity/Notification.php | 182 ++++++++++++++++++ .../Repository/NotificationRepository.php | 39 ++++ 2 files changed, 221 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/Entity/Notification.php create mode 100644 src/Bundle/ChillMainBundle/Repository/NotificationRepository.php diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php new file mode 100644 index 000000000..fd0a2acb8 --- /dev/null +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -0,0 +1,182 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\MainBundle\Entity; + +use App\Repository\Chill\MainBundle\Entity\NotificationRepository; +use Chill\MainBundle\Entity\User; +use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\Common\Collections\Collection; +use Doctrine\ORM\Mapping as ORM; + +/** + * @ORM\Entity(repositoryClass=NotificationRepository::class) + */ +class Notification +{ + /** + * @ORM\Id + * @ORM\GeneratedValue + * @ORM\Column(type="integer") + */ + private $id; + + /** + * @ORM\Column(type="text") + */ + private $message; + + /** + * @ORM\Column(type="datetime_immutable") + */ + private $date; + + /** + * @ORM\ManyToOne(targetEntity=User::class) + * @ORM\JoinColumn(nullable=false) + */ + private $sender; + + /** + * @ORM\ManyToMany(targetEntity=User::class) + * @ORM\JoinTable(name="chill_main_notification_addresses_user") + */ + private $addressees; + + /** + * @ORM\Column(type="string", length=255) + */ + private $relatedEntityClass; + + /** + * @ORM\Column(type="integer") + */ + private $relatedEntityId; + + /** + * @ORM\Column(type="boolean") + */ + private $read; + + public function __construct() + { + $this->addressees = new ArrayCollection(); + } + + public function getId(): ?int + { + return $this->id; + } + + public function getMessage(): ?string + { + return $this->message; + } + + public function setMessage(string $message): self + { + $this->message = $message; + + return $this; + } + + public function getDate(): ?\DateTimeImmutable + { + return $this->date; + } + + public function setDate(\DateTimeImmutable $date): self + { + $this->date = $date; + + return $this; + } + + public function getSender(): ?User + { + return $this->sender; + } + + public function setSender(?User $sender): self + { + $this->sender = $sender; + + return $this; + } + + /** + * @return Collection|User[] + */ + public function getAddressees(): Collection + { + return $this->addressees; + } + + public function addAddressee(User $addressee): self + { + if (!$this->addressees->contains($addressee)) { + $this->addressees[] = $addressee; + } + + return $this; + } + + public function removeAddressee(User $addressee): self + { + $this->addressees->removeElement($addressee); + + return $this; + } + + public function getRelatedEntityClass(): ?string + { + return $this->relatedEntityClass; + } + + public function setRelatedEntityClass(string $relatedEntityClass): self + { + $this->relatedEntityClass = $relatedEntityClass; + + return $this; + } + + public function getRelatedEntityId(): ?int + { + return $this->relatedEntityId; + } + + public function setRelatedEntityId(int $relatedEntityId): self + { + $this->relatedEntityId = $relatedEntityId; + + return $this; + } + + public function getRead(): ?bool + { + return $this->read; + } + + public function setRead(bool $read): self + { + $this->read = $read; + + return $this; + } +} diff --git a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php new file mode 100644 index 000000000..04d6def1b --- /dev/null +++ b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php @@ -0,0 +1,39 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Chill\MainBundle\Repository; + +use Chill\MainBundle\Entity\Notification; +use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; +use Doctrine\Persistence\ManagerRegistry; + +/** + * @method Notification|null find($id, $lockMode = null, $lockVersion = null) + * @method Notification|null findOneBy(array $criteria, array $orderBy = null) + * @method Notification[] findAll() + * @method Notification[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) + */ +class NotificationRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Notification::class); + } + +} From 916209e402df07e39e969b17f7fb202778dc0a7e Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 10 Jun 2021 15:11:03 +0200 Subject: [PATCH 02/14] Fix remarks MR - notif --- src/Bundle/ChillMainBundle/Entity/Notification.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index fd0a2acb8..76a4b1e4c 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -27,6 +27,7 @@ use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass=NotificationRepository::class) + * @ORM\Table(name="chill_main_notification") */ class Notification { @@ -70,7 +71,7 @@ class Notification private $relatedEntityId; /** - * @ORM\Column(type="boolean") + * @ORM\Column(type="json") */ private $read; @@ -168,12 +169,12 @@ class Notification return $this; } - public function getRead(): ?bool + public function getRead(): array { return $this->read; } - public function setRead(bool $read): self + public function setRead(array $read): self { $this->read = $read; From 84913553e831e61de8c05990be15f3d09dbaa505 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Thu, 10 Jun 2021 15:11:36 +0200 Subject: [PATCH 03/14] NotificationRepo as a service --- .../config/services/repositories.yaml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/config/services/repositories.yaml diff --git a/src/Bundle/ChillMainBundle/config/services/repositories.yaml b/src/Bundle/ChillMainBundle/config/services/repositories.yaml new file mode 100644 index 000000000..18fd70df8 --- /dev/null +++ b/src/Bundle/ChillMainBundle/config/services/repositories.yaml @@ -0,0 +1,42 @@ +services: + chill.main.countries_repository: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine.orm.entity_manager", getRepository] + arguments: + - "Chill\\MainBundle\\Entity\\Country" + + chill.main.user_repository: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine.orm.entity_manager", getRepository] + arguments: + - "Chill\\MainBundle\\Entity\\User" + + chill.main.scope_repository: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine.orm.entity_manager", getRepository] + arguments: + - "Chill\\MainBundle\\Entity\\Scope" + + chill.main.postalcode_repository: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine.orm.entity_manager", getRepository] + arguments: + - "Chill\\MainBundle\\Entity\\PostalCode" + + Chill\MainBundle\Repository\PostalCodeRepository: '@chill.main.postalcode_repository' + + chill.main.center_repository: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine.orm.entity_manager", getRepository] + arguments: + - "Chill\\MainBundle\\Entity\\Center" + + Chill\MainBundle\Repository\CenterRepository: '@chill.main.center_repository' + + chill.main.notification_repository: + class: Doctrine\ORM\EntityRepository + factory: ["@doctrine.orm.entity_manager", getRepository] + arguments: + - "Chill\\MainBundle\\Entity\\Notification" + + Chill\MainBundle\Repository\NotificationRepository: '@chill.main.notification_repository' From a258905c599b993eb76a0ee7daa3d5c4b86cf6f9 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 15 Jun 2021 11:23:43 +0200 Subject: [PATCH 04/14] Add unique constraint (class, id) to notifications --- src/Bundle/ChillMainBundle/Entity/Notification.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index 76a4b1e4c..51ea0e39f 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -27,7 +27,12 @@ use Doctrine\ORM\Mapping as ORM; /** * @ORM\Entity(repositoryClass=NotificationRepository::class) - * @ORM\Table(name="chill_main_notification") + * @ORM\Table( + * name="chill_main_notification", + * uniqueConstraints={ + * @ORM\UniqueConstraint(columns={"relatedEntityClass", "relatedEntityId"}) + * } + * ) */ class Notification { From 23528e7a5ca9fe9d723da54727150c23d44497a5 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 15 Jun 2021 11:53:19 +0200 Subject: [PATCH 05/14] Adding some features to load for notifications) --- .../DataFixtures/ORM/LoadActivity.php | 6 ++- .../ORM/LoadActivityNotifications.php | 39 ++++++++++++++++++ .../ORM/LoadAbstractNotificationsTrait.php | 41 +++++++++++++++++++ 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php create mode 100644 src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAbstractNotificationsTrait.php diff --git a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivity.php b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivity.php index de1ea97c2..ce32143f5 100644 --- a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivity.php +++ b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivity.php @@ -138,11 +138,15 @@ class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, C foreach($persons as $person) { $activityNbr = rand(0,3); + $ref = 'activity_'.$person->getFullnameCanonical(); + for($i = 0; $i < $activityNbr; $i ++) { - print "Creating an activity type for : ".$person."\n"; + print "Creating an activity type for : ".$person." (ref: ".$ref.") \n"; $activity = $this->newRandomActivity($person); $manager->persist($activity); } + + $this->setReference($ref, $activity); } $manager->flush(); } diff --git a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php new file mode 100644 index 000000000..588b2b7e1 --- /dev/null +++ b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php @@ -0,0 +1,39 @@ + 'Hello !', + 'entityClass' => Activity::class, + 'entityRef' => 'activity_gerard depardieu', + 'sender' => 'center a_social', + 'addressees' => [ + 'center a_administrative', + 'center a_direction', + 'multi_center' + ], + ] + ]; + + +} diff --git a/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAbstractNotificationsTrait.php b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAbstractNotificationsTrait.php new file mode 100644 index 000000000..071f67497 --- /dev/null +++ b/src/Bundle/ChillMainBundle/DataFixtures/ORM/LoadAbstractNotificationsTrait.php @@ -0,0 +1,41 @@ +notifs as $notif) { + $entityId = $this->getReference($notif['entityRef'])->getId(); + + print('Adding notification for '.$notif['entityClass'].'(entity id:'.$entityId.")\n"); + + $newNotif = (new Notification()) + ->setMessage($notif['message']) + ->setSender($this->getReference($notif['sender'])) + ->setRelatedEntityClass($notif['entityClass']) + ->setRelatedEntityId($entityId) + ->setDate(new \DateTimeImmutable('now')) + ->setRead([]) + ; + + foreach ($notif['addressees'] as $addressee) { + $newNotif->addAddressee($this->getReference($addressee)); + } + + $manager->persist($newNotif); + + $manager->flush(); + } + } +} From cf8b9ec172e4e6987900780eabec03c4136b784f Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 15 Jun 2021 11:54:00 +0200 Subject: [PATCH 06/14] Migration for notifications --- .../migrations/Version20210610140248.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20210610140248.php diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210610140248.php b/src/Bundle/ChillMainBundle/migrations/Version20210610140248.php new file mode 100644 index 000000000..a0b239d31 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20210610140248.php @@ -0,0 +1,42 @@ +addSql('CREATE SEQUENCE chill_main_notification_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); + $this->addSql('CREATE TABLE chill_main_notification (id INT NOT NULL, sender_id INT NOT NULL, message TEXT NOT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, relatedEntityClass VARCHAR(255) NOT NULL, relatedEntityId INT NOT NULL, read JSON NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE INDEX IDX_5BDC8067F624B39D ON chill_main_notification (sender_id)'); + $this->addSql('CREATE UNIQUE INDEX UNIQ_5BDC8067567988B4440F6072 ON chill_main_notification (relatedEntityClass, relatedEntityId)'); + $this->addSql('COMMENT ON COLUMN chill_main_notification.date IS \'(DC2Type:datetime_immutable)\''); + $this->addSql('CREATE TABLE chill_main_notification_addresses_user (notification_id INT NOT NULL, user_id INT NOT NULL, PRIMARY KEY(notification_id, user_id))'); + $this->addSql('CREATE INDEX IDX_E52C5D2BEF1A9D84 ON chill_main_notification_addresses_user (notification_id)'); + $this->addSql('CREATE INDEX IDX_E52C5D2BA76ED395 ON chill_main_notification_addresses_user (user_id)'); + $this->addSql('ALTER TABLE chill_main_notification ADD CONSTRAINT FK_5BDC8067F624B39D FOREIGN KEY (sender_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_main_notification_addresses_user ADD CONSTRAINT FK_E52C5D2BEF1A9D84 FOREIGN KEY (notification_id) REFERENCES chill_main_notification (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('ALTER TABLE chill_main_notification_addresses_user ADD CONSTRAINT FK_E52C5D2BA76ED395 FOREIGN KEY (user_id) REFERENCES users (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_notification_addresses_user DROP CONSTRAINT FK_E52C5D2BEF1A9D84'); + $this->addSql('DROP SEQUENCE chill_main_notification_id_seq CASCADE'); + $this->addSql('DROP TABLE chill_main_notification'); + $this->addSql('DROP TABLE chill_main_notification_addresses_user'); + } +} From 86d764c09719be66d91c0ad9130bf501a31860d2 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 15 Jun 2021 14:48:33 +0200 Subject: [PATCH 07/14] Using JSONB for storage in db for attendees in Notifications --- src/Bundle/ChillMainBundle/migrations/Version20210610140248.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210610140248.php b/src/Bundle/ChillMainBundle/migrations/Version20210610140248.php index a0b239d31..d54ff4634 100644 --- a/src/Bundle/ChillMainBundle/migrations/Version20210610140248.php +++ b/src/Bundle/ChillMainBundle/migrations/Version20210610140248.php @@ -20,7 +20,7 @@ final class Version20210610140248 extends AbstractMigration public function up(Schema $schema): void { $this->addSql('CREATE SEQUENCE chill_main_notification_id_seq INCREMENT BY 1 MINVALUE 1 START 1'); - $this->addSql('CREATE TABLE chill_main_notification (id INT NOT NULL, sender_id INT NOT NULL, message TEXT NOT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, relatedEntityClass VARCHAR(255) NOT NULL, relatedEntityId INT NOT NULL, read JSON NOT NULL, PRIMARY KEY(id))'); + $this->addSql('CREATE TABLE chill_main_notification (id INT NOT NULL, sender_id INT NOT NULL, message TEXT NOT NULL, date TIMESTAMP(0) WITHOUT TIME ZONE NOT NULL, relatedEntityClass VARCHAR(255) NOT NULL, relatedEntityId INT NOT NULL, read JSONB NOT NULL, PRIMARY KEY(id))'); $this->addSql('CREATE INDEX IDX_5BDC8067F624B39D ON chill_main_notification (sender_id)'); $this->addSql('CREATE UNIQUE INDEX UNIQ_5BDC8067567988B4440F6072 ON chill_main_notification (relatedEntityClass, relatedEntityId)'); $this->addSql('COMMENT ON COLUMN chill_main_notification.date IS \'(DC2Type:datetime_immutable)\''); From db545f9fe62371282a9ddb67724f534db0700bac Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 15 Jun 2021 14:49:17 +0200 Subject: [PATCH 08/14] Adding typehinting for Entity/Notif --- .../ChillMainBundle/Entity/Notification.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index 51ea0e39f..3854525b8 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -41,44 +41,44 @@ class Notification * @ORM\GeneratedValue * @ORM\Column(type="integer") */ - private $id; + private int $id; /** * @ORM\Column(type="text") */ - private $message; + private string $message; /** * @ORM\Column(type="datetime_immutable") */ - private $date; + private \DateTimeImmutable $date; /** * @ORM\ManyToOne(targetEntity=User::class) * @ORM\JoinColumn(nullable=false) */ - private $sender; + private User $sender; /** * @ORM\ManyToMany(targetEntity=User::class) * @ORM\JoinTable(name="chill_main_notification_addresses_user") */ - private $addressees; + private Collection $addressees; /** * @ORM\Column(type="string", length=255) */ - private $relatedEntityClass; + private string $relatedEntityClass; /** * @ORM\Column(type="integer") */ - private $relatedEntityId; + private int $relatedEntityId; /** * @ORM\Column(type="json") */ - private $read; + private array $read; public function __construct() { From 49d022ef55eb011b60b8f86969a56ec1b0041c65 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 15 Jun 2021 18:57:56 +0200 Subject: [PATCH 09/14] NotificationRepository as a service --- .../ChillMainBundle/Entity/Notification.php | 3 +- .../Repository/NotificationRepository.php | 49 ++++++++++++++----- .../config/services/repositories.yaml | 8 --- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/src/Bundle/ChillMainBundle/Entity/Notification.php b/src/Bundle/ChillMainBundle/Entity/Notification.php index 3854525b8..092445c9b 100644 --- a/src/Bundle/ChillMainBundle/Entity/Notification.php +++ b/src/Bundle/ChillMainBundle/Entity/Notification.php @@ -19,14 +19,13 @@ namespace Chill\MainBundle\Entity; -use App\Repository\Chill\MainBundle\Entity\NotificationRepository; use Chill\MainBundle\Entity\User; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; /** - * @ORM\Entity(repositoryClass=NotificationRepository::class) + * @ORM\Entity * @ORM\Table( * name="chill_main_notification", * uniqueConstraints={ diff --git a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php index 04d6def1b..844459f8b 100644 --- a/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php +++ b/src/Bundle/ChillMainBundle/Repository/NotificationRepository.php @@ -20,20 +20,47 @@ namespace Chill\MainBundle\Repository; use Chill\MainBundle\Entity\Notification; -use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; -use Doctrine\Persistence\ManagerRegistry; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\EntityRepository; +use Doctrine\Persistence\ObjectRepository; -/** - * @method Notification|null find($id, $lockMode = null, $lockVersion = null) - * @method Notification|null findOneBy(array $criteria, array $orderBy = null) - * @method Notification[] findAll() - * @method Notification[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) - */ -class NotificationRepository extends ServiceEntityRepository +final class NotificationRepository implements ObjectRepository { - public function __construct(ManagerRegistry $registry) + private EntityRepository $repository; + + public function __construct(EntityManagerInterface $entityManager) { - parent::__construct($registry, Notification::class); + $this->repository = $entityManager->getRepository(Notification::class); + } + + public function find($id, $lockMode = null, $lockVersion = null): ?Notification + { + return $this->repository->find($id, $lockMode, $lockVersion); + } + + public function findOneBy(array $criteria, array $orderBy = null): ?Notification + { + return $this->repository->findOneBy($criteria, $orderBy); + } + + /** + * @return Notification[] + */ + public function findAll(): array + { + return $this->repository->findAll(); + } + + /** + * @return Notification[] + */ + public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array + { + return $this->repository->findBy($criteria, $orderBy, $limit, $offset); + } + + public function getClassName() { + return Notification::class; } } diff --git a/src/Bundle/ChillMainBundle/config/services/repositories.yaml b/src/Bundle/ChillMainBundle/config/services/repositories.yaml index 18fd70df8..551a2f705 100644 --- a/src/Bundle/ChillMainBundle/config/services/repositories.yaml +++ b/src/Bundle/ChillMainBundle/config/services/repositories.yaml @@ -32,11 +32,3 @@ services: - "Chill\\MainBundle\\Entity\\Center" Chill\MainBundle\Repository\CenterRepository: '@chill.main.center_repository' - - chill.main.notification_repository: - class: Doctrine\ORM\EntityRepository - factory: ["@doctrine.orm.entity_manager", getRepository] - arguments: - - "Chill\\MainBundle\\Entity\\Notification" - - Chill\MainBundle\Repository\NotificationRepository: '@chill.main.notification_repository' From 06daf35e964dbd2f7ce5e146e21f507354a36c9c Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 16 Jun 2021 14:39:02 +0200 Subject: [PATCH 10/14] addresses: edit address for person --- .../Resources/public/scss/chillmain.scss | 13 +++++- .../Resources/public/vuejs/Address/App.vue | 18 ++++---- .../Resources/public/vuejs/Address/js/i18n.js | 2 + .../public/vuejs/Address/store/index.js | 6 +-- .../public/vuejs/_components/AddAddress.vue | 31 +++++++------ .../_components/AddAddress/AddressMore.vue | 35 +++++++++++---- .../AddAddress/AddressSelection.vue | 2 +- .../_components/AddAddress/CitySelection.vue | 4 +- .../AddAddress/CountrySelection.vue | 7 ++- .../public/vuejs/_components/ShowAddress.vue | 44 +++++++++++++++++++ .../Normalizer/AddressNormalizer.php | 5 +++ .../Controller/PersonAddressController.php | 4 +- .../Resources/views/Address/edit.html.twig | 2 +- .../translations/messages.fr.yml | 1 + 14 files changed, 132 insertions(+), 42 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/ShowAddress.vue diff --git a/src/Bundle/ChillMainBundle/Resources/public/scss/chillmain.scss b/src/Bundle/ChillMainBundle/Resources/public/scss/chillmain.scss index f101b78ca..9f0ebd190 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/scss/chillmain.scss +++ b/src/Bundle/ChillMainBundle/Resources/public/scss/chillmain.scss @@ -244,6 +244,9 @@ div.address_form { display: flex; flex-direction: column; flex-grow: 1; + div.custom-address, div.custom-postcode { + padding: 12px; + } } div.address_form__select__map { @@ -251,11 +254,19 @@ div.address_form { div#address_map { height:400px; width:400px; + input { + border: 1px solid #999; + } } } } div.address_form__more { - + & > div { + display: flex; + & > label { + width: 30%; + } + } } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue index 37dd6aba4..c0d3271ef 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/App.vue @@ -8,16 +8,12 @@ @addNewAddress="addNewAddress"> +
-
- {{ address.text }} -
-
- {{ address.postcode.name }} -
-
- {{ address.country.name }} -
+ +
@@ -49,11 +45,13 @@ diff --git a/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php b/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php index 9cebddfa0..362ed7b26 100644 --- a/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php +++ b/src/Bundle/ChillMainBundle/Serializer/Normalizer/AddressNormalizer.php @@ -15,9 +15,14 @@ class AddressNormalizer implements NormalizerAwareInterface, NormalizerInterface { $data['address_id'] = $address->getId(); $data['text'] = $address->getStreet().', '.$address->getStreetNumber(); + $data['street'] = $address->getStreet(); + $data['streetNumber'] = $address->getStreetNumber(); $data['postcode']['name'] = $address->getPostCode()->getName(); + $data['postcode']['code'] = $address->getPostCode()->getCode(); $data['country']['name'] = $address->getPostCode()->getCountry()->getName(); + $data['country']['code'] = $address->getPostCode()->getCountry()->getCountryCode(); $data['floor'] = $address->getFloor(); + $data['corridor'] = $address->getCorridor(); $data['steps'] = $address->getSteps(); $data['flat'] = $address->getBuildingName(); $data['buildingName'] = $address->getFlat(); diff --git a/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php b/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php index f68e1ee9b..5dc6fea46 100644 --- a/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php +++ b/src/Bundle/ChillPersonBundle/Controller/PersonAddressController.php @@ -45,7 +45,7 @@ class PersonAddressController extends AbstractController * @var ValidatorInterface */ protected $validator; - + /** * PersonAddressController constructor. * @@ -55,7 +55,7 @@ class PersonAddressController extends AbstractController { $this->validator = $validator; } - + public function listAction($person_id) { $person = $this->getDoctrine()->getManager() diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Address/edit.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Address/edit.html.twig index 238afb473..ffdfaea86 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Address/edit.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Address/edit.html.twig @@ -18,7 +18,7 @@ {% set activeRouteKey = '' %} -{% block title 'Update address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) %} +{% block title 'Modify address for %name%'|trans({ '%name%': person.firstName ~ ' ' ~ person.lastName } ) %} {% block personcontent %} diff --git a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml index 28ec07798..a1e353f89 100644 --- a/src/Bundle/ChillPersonBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillPersonBundle/translations/messages.fr.yml @@ -185,6 +185,7 @@ Pick a person: Choisir une personne No address given: Pas d'adresse renseignée The address has been successfully updated: L'adresse a été mise à jour avec succès Update address for %name%: Mettre à jour une adresse pour %name% +Modify address for %name%: Modifier une adresse pour %name% Addresses'history for %name%: Historique des adresses de %name% Addresses'history: Historique des adresses New address for %name% : Nouvelle adresse pour %name% From 801af209a164f5171e022b32e6e69e2f66ce2430 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 16 Jun 2021 14:54:33 +0200 Subject: [PATCH 11/14] Revert "NotificationRepo as a service" This reverts commit 84913553e831e61de8c05990be15f3d09dbaa505. --- .../config/services/repositories.yaml | 34 ------------------- 1 file changed, 34 deletions(-) delete mode 100644 src/Bundle/ChillMainBundle/config/services/repositories.yaml diff --git a/src/Bundle/ChillMainBundle/config/services/repositories.yaml b/src/Bundle/ChillMainBundle/config/services/repositories.yaml deleted file mode 100644 index 551a2f705..000000000 --- a/src/Bundle/ChillMainBundle/config/services/repositories.yaml +++ /dev/null @@ -1,34 +0,0 @@ -services: - chill.main.countries_repository: - class: Doctrine\ORM\EntityRepository - factory: ["@doctrine.orm.entity_manager", getRepository] - arguments: - - "Chill\\MainBundle\\Entity\\Country" - - chill.main.user_repository: - class: Doctrine\ORM\EntityRepository - factory: ["@doctrine.orm.entity_manager", getRepository] - arguments: - - "Chill\\MainBundle\\Entity\\User" - - chill.main.scope_repository: - class: Doctrine\ORM\EntityRepository - factory: ["@doctrine.orm.entity_manager", getRepository] - arguments: - - "Chill\\MainBundle\\Entity\\Scope" - - chill.main.postalcode_repository: - class: Doctrine\ORM\EntityRepository - factory: ["@doctrine.orm.entity_manager", getRepository] - arguments: - - "Chill\\MainBundle\\Entity\\PostalCode" - - Chill\MainBundle\Repository\PostalCodeRepository: '@chill.main.postalcode_repository' - - chill.main.center_repository: - class: Doctrine\ORM\EntityRepository - factory: ["@doctrine.orm.entity_manager", getRepository] - arguments: - - "Chill\\MainBundle\\Entity\\Center" - - Chill\MainBundle\Repository\CenterRepository: '@chill.main.center_repository' From 5b72eeb1474adb578a3043f2ca0cf4f8e5806700 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 16 Jun 2021 15:05:32 +0200 Subject: [PATCH 12/14] addresses: edit address for household (WIP) --- .../Controller/HouseholdController.php | 23 ++++++++++++++++ .../public/vuejs/HouseholdAddress/App.vue | 13 +++++----- .../views/Household/address_edit.html.twig | 26 +++++++++++++++++++ .../views/Household/addresses.html.twig | 2 ++ 4 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 src/Bundle/ChillPersonBundle/Resources/views/Household/address_edit.html.twig diff --git a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php index d7e69439d..6a4a4be34 100644 --- a/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php +++ b/src/Bundle/ChillPersonBundle/Controller/HouseholdController.php @@ -2,6 +2,7 @@ namespace Chill\PersonBundle\Controller; +use Chill\MainBundle\Entity\Address; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -97,4 +98,26 @@ class HouseholdController extends AbstractController ] ); } + + /** + * @Route( + * "/{household_id}/address/edit", + * name="chill_person_household_address_edit", + * methods={"GET", "HEAD", "POST"} + * ) + * @ParamConverter("household", options={"id" = "household_id"}) + */ + public function addressEdit(Request $request, Household $household) + { + // TODO ACL + //$address = $this->findAddressById($household, $address_id); //TODO + + + return $this->render('@ChillPerson/Household/address_edit.html.twig', + [ + 'household' => $household, + //'address' => $address, + ] + ); + } } diff --git a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/App.vue b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/App.vue index 0c989c310..e42564738 100644 --- a/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/App.vue +++ b/src/Bundle/ChillPersonBundle/Resources/public/vuejs/HouseholdAddress/App.vue @@ -8,12 +8,10 @@
-
- {{ newAddress.text }} -
-
- {{ newAddress.postcode.name }} -
+ +
@@ -45,14 +43,17 @@ + {{ encore_entry_script_tags('household_address') }} + {% endblock %} + +{% endblock %} diff --git a/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig b/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig index db682e6b1..fcc21765b 100644 --- a/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig +++ b/src/Bundle/ChillPersonBundle/Resources/views/Household/addresses.html.twig @@ -54,8 +54,10 @@ ({{ address.postCode.country.name|localize_translatable_string }})
{% endif %} + {% endif %} + From 1cfc29caf7fdd9bda4c224a221fa2637e1338ea3 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Wed, 16 Jun 2021 15:32:59 +0200 Subject: [PATCH 13/14] LoadNotifications using DependentFixtureInterface --- .../ORM/LoadActivityNotifications.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php index 588b2b7e1..7835a0db4 100644 --- a/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php +++ b/src/Bundle/ChillActivityBundle/DataFixtures/ORM/LoadActivityNotifications.php @@ -3,24 +3,18 @@ namespace Chill\ActivityBundle\DataFixtures\ORM; use Doctrine\Common\DataFixtures\AbstractFixture; -use Doctrine\Common\DataFixtures\OrderedFixtureInterface; -use Doctrine\Persistence\ObjectManager; -use Symfony\Component\Intl\Intl; -use Chill\MainBundle\Entity\Notification; +use Doctrine\Common\DataFixtures\DependentFixtureInterface; use Chill\ActivityBundle\Entity\Activity; use Chill\MainBundle\DataFixtures\ORM\LoadAbstractNotificationsTrait; +use Chill\ActivityBundle\DataFixtures\ORM\LoadActivity; /** * Load notififications into database */ -class LoadActivityNotifications extends AbstractFixture implements OrderedFixtureInterface +class LoadActivityNotifications extends AbstractFixture implements DependentFixtureInterface { use LoadAbstractNotificationsTrait; - public function getOrder() { - return 16500; - } - public $notifs = [ [ 'message' => 'Hello !', @@ -35,5 +29,10 @@ class LoadActivityNotifications extends AbstractFixture implements OrderedFixtur ] ]; - + public function getDependencies() + { + return [ + LoadActivity::class, + ]; + } } From e2633a2a790569e1da68e7b8146cba3cfef11483 Mon Sep 17 00:00:00 2001 From: nobohan Date: Wed, 16 Jun 2021 16:20:37 +0200 Subject: [PATCH 14/14] addresses: filter out postal code introduced by user --- .../ChillMainBundle/Entity/PostalCode.php | 33 +++++++++++++++++++ .../public/vuejs/Address/store/index.js | 10 ++++-- .../public/vuejs/_components/AddAddress.vue | 4 +-- .../migrations/Version20210616134328.php | 29 ++++++++++++++++ 4 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/Bundle/ChillMainBundle/migrations/Version20210616134328.php diff --git a/src/Bundle/ChillMainBundle/Entity/PostalCode.php b/src/Bundle/ChillMainBundle/Entity/PostalCode.php index 26d75a532..01d03ed52 100644 --- a/src/Bundle/ChillMainBundle/Entity/PostalCode.php +++ b/src/Bundle/ChillMainBundle/Entity/PostalCode.php @@ -54,6 +54,13 @@ class PostalCode */ private $country; + /** + * @var integer + * + * @ORM\Column(name="origin", type="integer", nullable=true) + * @groups({"write", "read"}) + */ + private $origin = 0; /** * Get id @@ -65,6 +72,32 @@ class PostalCode return $this->id; } + + /** + * Set origin + * + * @param int $origin + * + * @return PostalCode + */ + public function setOrigin($origin) + { + $this->origin = $origin; + + return $this; + } + + /** + * Get origin + * + * @return int + */ + public function getOrigin() + { + return $this->origin; + } + + /** * Set name * diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js index 9aeea6f01..acbf4dcbb 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/store/index.js @@ -45,10 +45,12 @@ const store = createStore({ console.log('@A addAddress payload', payload); if('newPostalCode' in payload){ - postPostalCode(payload.newPostalCode) + let postalCodeBody = payload.newPostalCode; + postalCodeBody = Object.assign(postalCodeBody, {'origin': 3}); + postPostalCode(postalCodeBody) .then(postalCode => { let body = payload; - body.postcode = {'id': postalCode.id }, + body.postcode = {'id': postalCode.id}, postAddress(body) .then(address => new Promise((resolve, reject) => { commit('addAddress', address); @@ -95,7 +97,9 @@ const store = createStore({ console.log('@A updateAddress payload', payload); if('newPostalCode' in payload.newAddress){ // TODO change the condition because it writes new postal code in edit mode now: !writeNewPostalCode - postPostalCode(payload.newAddress.newPostalCode) + let postalCodeBody = payload.newAddress.newPostalCode; + postalCodeBody = Object.assign(postalCodeBody, {'origin': 3}); + postPostalCode(postalCodeBody) .then(postalCode => { let body = payload.newAddress; body.postcode = {'id': postalCode.id }, diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue index 57422d044..3417a2d0d 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/_components/AddAddress.vue @@ -181,8 +181,8 @@ export default { getCities(country) { console.log('getCities for', country.name); fetchCities(country).then(cities => new Promise((resolve, reject) => { - this.address.loaded.cities = cities.results; - resolve() + this.address.loaded.cities = cities.results.filter(c => c.origin !== 3); // filter out user-defined cities + resolve(); })) .catch((error) => { this.errorMsg.push(error.message); diff --git a/src/Bundle/ChillMainBundle/migrations/Version20210616134328.php b/src/Bundle/ChillMainBundle/migrations/Version20210616134328.php new file mode 100644 index 000000000..c54f0a183 --- /dev/null +++ b/src/Bundle/ChillMainBundle/migrations/Version20210616134328.php @@ -0,0 +1,29 @@ +addSql('ALTER TABLE chill_main_postal_code ADD origin INT DEFAULT NULL'); + } + + public function down(Schema $schema): void + { + $this->addSql('ALTER TABLE chill_main_postal_code DROP origin'); + } +}