mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
Merge remote-tracking branch 'origin/master' into doc/authorizaton-documentation-update
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\Helper;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
|
||||
trait PersonRandomHelper
|
||||
{
|
||||
private array $randPersons = [];
|
||||
private ?int $countPersons = null;
|
||||
|
||||
protected function getRandomPerson(EntityManagerInterface $em): Person
|
||||
{
|
||||
$fetchBy = 5;
|
||||
if (null === $this->countPersons) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$this->countPersons = $qb->select('count(p)')
|
||||
->from(Person::class, 'p')
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
}
|
||||
|
||||
if ([] === $this->randPersons) {
|
||||
$qb = $em->createQueryBuilder();
|
||||
$this->randPersons = $qb
|
||||
->select('p')
|
||||
->from(Person::class, 'p')
|
||||
->getQuery()
|
||||
->setFirstResult(\random_int(0, $this->countPersons - $fetchBy))
|
||||
->setMaxResults($fetchBy)
|
||||
->getResult()
|
||||
;
|
||||
}
|
||||
|
||||
return \array_pop($this->randPersons);
|
||||
}
|
||||
|
||||
}
|
@@ -40,7 +40,7 @@ class LoadAccompanyingPeriodOrigin extends AbstractFixture implements OrderedFix
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 10005;
|
||||
return 9000;
|
||||
}
|
||||
|
||||
private $phoneCall = ['en' => 'phone call', 'fr' => 'appel téléphonique'];
|
||||
|
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
@@ -24,6 +26,8 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
|
||||
private CONST NUMBER_OF_HOUSEHOLD = 10;
|
||||
|
||||
private array $personIds;
|
||||
|
||||
public function __construct(MembersEditorFactory $editorFactory, EntityManagerInterface $em)
|
||||
{
|
||||
$this->editorFactory = $editorFactory;
|
||||
@@ -149,30 +153,30 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
|
||||
private function preparePersonIds()
|
||||
{
|
||||
// @TODO: Remove this and make this service stateless
|
||||
$this->personIds = $this->em
|
||||
->createQuery('SELECT p.id FROM '.Person::class.' p '.
|
||||
'JOIN p.center c '.
|
||||
'WHERE c.name = :center '
|
||||
)
|
||||
->setParameter('center', 'Center A')
|
||||
->getScalarResult()
|
||||
;
|
||||
->getScalarResult();
|
||||
|
||||
\shuffle($this->personIds);
|
||||
}
|
||||
|
||||
private function getRandomPersons(int $min, int $max)
|
||||
private function getRandomPersons(int $min, int $max): array
|
||||
{
|
||||
$persons = [];
|
||||
|
||||
$nb = \random_int($min, $max);
|
||||
|
||||
for ($i=0; $i < $nb; $i++) {
|
||||
$personId = \array_pop($this->personIds)['id'];
|
||||
$persons[] = $this->em->getRepository(Person::class)
|
||||
->find($personId)
|
||||
;
|
||||
$persons[] = $this->em->getRepository(Person::class)->find($personId);
|
||||
}
|
||||
|
||||
return $persons ?? [];
|
||||
return $persons;
|
||||
}
|
||||
|
||||
public function getDependencies()
|
||||
|
@@ -10,8 +10,8 @@ class LoadHouseholdPosition extends Fixture
|
||||
{
|
||||
const POSITIONS_DATA = [
|
||||
["Adulte", true, true, 1.0, self::ADULT ],
|
||||
["Enfants", true, false, 2.0, self::CHILD ],
|
||||
["Enfants hors ménage", false, false, 3.0, self::CHILD_OUT ]
|
||||
["Enfant", true, false, 2.0, self::CHILD ],
|
||||
["Enfant hors ménage", false, false, 3.0, self::CHILD_OUT ]
|
||||
];
|
||||
|
||||
const ADULT = "position_adulte";
|
||||
|
@@ -106,6 +106,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
|
||||
protected UserRepository $userRepository;
|
||||
|
||||
public const PERSON = 'person';
|
||||
|
||||
public function __construct(
|
||||
Registry $workflowRegistry,
|
||||
SocialIssueRepository $socialIssueRepository,
|
||||
@@ -247,7 +249,9 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
if (\random_int(0, 10) > 3) {
|
||||
// always add social scope:
|
||||
$accompanyingPeriod->addScope($this->getReference('scope_social'));
|
||||
|
||||
$origin = $this->getReference(LoadAccompanyingPeriodOrigin::ACCOMPANYING_PERIOD_ORIGIN);
|
||||
$accompanyingPeriod->setOrigin($origin);
|
||||
$accompanyingPeriod->setIntensity('regular');
|
||||
$accompanyingPeriod->setAddressLocation($this->createAddress());
|
||||
$manager->persist($accompanyingPeriod->getAddressLocation());
|
||||
$workflow = $this->workflowRegistry->get($accompanyingPeriod);
|
||||
@@ -257,6 +261,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
$manager->persist($person);
|
||||
$manager->persist($accompanyingPeriod);
|
||||
echo "add person'".$person->__toString()."'\n";
|
||||
|
||||
$this->addReference(self::PERSON.$person->getId(), $person);
|
||||
}
|
||||
|
||||
private function getRandomUser(): User
|
||||
|
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\Relationships\Relation;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class LoadRelations extends Fixture implements FixtureGroupInterface
|
||||
{
|
||||
public const RELATION_KEY = 'relations';
|
||||
public const RELATIONS = [
|
||||
['title' => ['fr' => 'Mère'], 'reverseTitle' => ['fr' => 'Fille']],
|
||||
['title' => ['fr' => 'Mère'], 'reverseTitle' => ['fr' => 'Fils']],
|
||||
['title' => ['fr' => 'Père'], 'reverseTitle' => ['fr' => 'Fille']],
|
||||
['title' => ['fr' => 'Père'], 'reverseTitle' => ['fr' => 'Fils']],
|
||||
|
||||
['title' => ['fr' => 'Frère'], 'reverseTitle' => ['fr' => 'Frère']],
|
||||
['title' => ['fr' => 'Soeur'], 'reverseTitle' => ['fr' => 'Soeur']],
|
||||
['title' => ['fr' => 'Frère'], 'reverseTitle' => ['fr' => 'Soeur']],
|
||||
|
||||
['title' => ['fr' => 'Demi-frère'], 'reverseTitle' => ['fr' => 'Demi-frère']],
|
||||
['title' => ['fr' => 'Demi-soeur'], 'reverseTitle' => ['fr' => 'Demi-soeur']],
|
||||
['title' => ['fr' => 'Demi-frère'], 'reverseTitle' => ['fr' => 'Demi-soeur']],
|
||||
|
||||
['title' => ['fr' => 'Oncle'], 'reverseTitle' => ['fr' => 'Neveu']],
|
||||
['title' => ['fr' => 'Oncle'], 'reverseTitle' => ['fr' => 'Nièce']],
|
||||
['title' => ['fr' => 'Tante'], 'reverseTitle' => ['fr' => 'Neveu']],
|
||||
['title' => ['fr' => 'Tante'], 'reverseTitle' => ['fr' => 'Nièce']],
|
||||
];
|
||||
|
||||
public static function getGroups(): array
|
||||
{
|
||||
return ['person_relations'];
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (self::RELATIONS as $key => $value){
|
||||
print "Creating a new relation type: relation" . $value['title']['fr'] . "reverse relation: " . $value['reverseTitle']['fr'] . "\n";
|
||||
$relation = new Relation();
|
||||
$relation->setTitle($value['title'])
|
||||
->setReverseTitle($value['reverseTitle']);
|
||||
$manager->persist($relation);
|
||||
|
||||
$this->addReference(self::RELATION_KEY.$key, $relation);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||
|
||||
class LoadRelationships extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
use PersonRandomHelper;
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
public function __construct(EntityManagerInterface $em)
|
||||
{
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
LoadPeople::class,
|
||||
LoadRelations::class
|
||||
];
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
for ($i = 0; $i < 15; $i++) {
|
||||
$user = $this->getRandomUser();
|
||||
$date = new \DateTimeImmutable();
|
||||
$relationship = (new Relationship())
|
||||
->setFromPerson($this->getRandomPerson($this->em))
|
||||
->setToPerson($this->getRandomPerson($this->em))
|
||||
->setRelation($this->getReference(LoadRelations::RELATION_KEY.
|
||||
\random_int(0, count(LoadRelations::RELATIONS) - 1)))
|
||||
->setReverse((bool) random_int(0, 1))
|
||||
->setCreatedBy($user)
|
||||
->setUpdatedBy($user)
|
||||
->setCreatedAt($date)
|
||||
->setUpdatedAt($date)
|
||||
;
|
||||
$manager->persist($relationship);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private function getRandomUser(): User
|
||||
{
|
||||
$userRef = array_rand(LoadUsers::$refs);
|
||||
return $this->getReference($userRef);
|
||||
}
|
||||
}
|
@@ -1,32 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Service\Import\SocialWorkMetadata;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use League\Csv\Reader;
|
||||
|
||||
class LoadSocialWorkMetadata extends \Doctrine\Bundle\FixturesBundle\Fixture implements \Doctrine\Common\DataFixtures\OrderedFixtureInterface
|
||||
class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface
|
||||
{
|
||||
private SocialWorkMetadata $importer;
|
||||
|
||||
/**
|
||||
* @param SocialWorkMetadata $importer
|
||||
*/
|
||||
public function __construct(SocialWorkMetadata $importer)
|
||||
{
|
||||
$this->importer = $importer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
try {
|
||||
$csv = Reader::createFromPath(__DIR__.'/data/social_work_metadata.csv');
|
||||
} catch (Throwable $e) {
|
||||
throw new Exception('Error while loading CSV.',0, $e);
|
||||
} catch (\Throwable $e) {
|
||||
throw new \Exception('Error while loading CSV.',0, $e);
|
||||
}
|
||||
|
||||
$csv->setDelimiter(";");
|
||||
@@ -34,9 +32,6 @@ class LoadSocialWorkMetadata extends \Doctrine\Bundle\FixturesBundle\Fixture imp
|
||||
$this->importer->import($csv);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getOrder()
|
||||
{
|
||||
return 9500;
|
||||
|
Reference in New Issue
Block a user