Adding some features to load for notifications)

This commit is contained in:
Marc Ducobu 2021-06-15 11:53:19 +02:00
parent a258905c59
commit 23528e7a5c
3 changed files with 85 additions and 1 deletions

View File

@ -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();
}

View File

@ -0,0 +1,39 @@
<?php
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 Chill\ActivityBundle\Entity\Activity;
use Chill\MainBundle\DataFixtures\ORM\LoadAbstractNotificationsTrait;
/**
* Load notififications into database
*/
class LoadActivityNotifications extends AbstractFixture implements OrderedFixtureInterface
{
use LoadAbstractNotificationsTrait;
public function getOrder() {
return 16500;
}
public $notifs = [
[
'message' => 'Hello !',
'entityClass' => Activity::class,
'entityRef' => 'activity_gerard depardieu',
'sender' => 'center a_social',
'addressees' => [
'center a_administrative',
'center a_direction',
'multi_center'
],
]
];
}

View File

@ -0,0 +1,41 @@
<?php
namespace Chill\MainBundle\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;
/**
* Load notififications into database
*/
trait LoadAbstractNotificationsTrait
{
public function load(ObjectManager $manager)
{
foreach ($this->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();
}
}
}