From 23528e7a5ca9fe9d723da54727150c23d44497a5 Mon Sep 17 00:00:00 2001 From: Marc Ducobu Date: Tue, 15 Jun 2021 11:53:19 +0200 Subject: [PATCH] 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(); + } + } +}