mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Adding some features to load for notifications)
This commit is contained in:
parent
a258905c59
commit
23528e7a5c
@ -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();
|
||||
}
|
||||
|
@ -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'
|
||||
],
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user