mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-20 14:43:49 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,25 +1,35 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\Helper;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use function array_pop;
|
||||
use function random_int;
|
||||
|
||||
trait PersonRandomHelper
|
||||
{
|
||||
private array $randPersons = [];
|
||||
private ?int $countPersons = null;
|
||||
|
||||
private array $randPersons = [];
|
||||
|
||||
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()
|
||||
;
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
if ([] === $this->randPersons) {
|
||||
@@ -28,13 +38,11 @@ trait PersonRandomHelper
|
||||
->select('p')
|
||||
->from(Person::class, 'p')
|
||||
->getQuery()
|
||||
->setFirstResult(\random_int(0, $this->countPersons - $fetchBy))
|
||||
->setFirstResult(random_int(0, $this->countPersons - $fetchBy))
|
||||
->setMaxResults($fetchBy)
|
||||
->getResult()
|
||||
;
|
||||
->getResult();
|
||||
}
|
||||
|
||||
return \array_pop($this->randPersons);
|
||||
return array_pop($this->randPersons);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,9 +1,17 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\Helper;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use function random_int;
|
||||
|
||||
trait RandomPersonHelperTrait
|
||||
{
|
||||
@@ -13,23 +21,20 @@ trait RandomPersonHelperTrait
|
||||
{
|
||||
$qb = $em->createQueryBuilder();
|
||||
$qb
|
||||
->from(Person::class, 'p')
|
||||
;
|
||||
->from(Person::class, 'p');
|
||||
|
||||
if (null === $this->nbOfPersons) {
|
||||
$this->nbOfPersons = $qb
|
||||
->select('COUNT(p)')
|
||||
->getQuery()
|
||||
->getSingleScalarResult()
|
||||
;
|
||||
->getSingleScalarResult();
|
||||
}
|
||||
|
||||
return $qb
|
||||
->select('p')
|
||||
->setMaxResults(1)
|
||||
->setFirstResult(\random_int(0, $this->nbOfPersons))
|
||||
->setFirstResult(random_int(0, $this->nbOfPersons))
|
||||
->getQuery()
|
||||
->getSingleResult()
|
||||
;
|
||||
->getSingleResult();
|
||||
}
|
||||
}
|
||||
|
@@ -1,89 +1,68 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\ClosingMotive;
|
||||
|
||||
/**
|
||||
* Load closing motives into database
|
||||
*
|
||||
* @author Julien Fastré <julien arobase fastre point info>
|
||||
* Load closing motives into database.
|
||||
*/
|
||||
class LoadAccompanyingPeriodClosingMotive extends AbstractFixture
|
||||
implements OrderedFixtureInterface
|
||||
class LoadAccompanyingPeriodClosingMotive extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
|
||||
public function getOrder() {
|
||||
public static $closingMotives = [
|
||||
'nothing_to_do' => [
|
||||
'name' => [
|
||||
'fr' => 'Plus rien à faire',
|
||||
'en' => 'Nothing to do',
|
||||
'nl' => 'nieks meer te doen',
|
||||
],
|
||||
],
|
||||
'did_not_come_back' => [
|
||||
'name' => [
|
||||
'fr' => "N'est plus revenu",
|
||||
'en' => "Did'nt come back",
|
||||
'nl' => 'Niet teruggekomen',
|
||||
],
|
||||
],
|
||||
'no_more_money' => [
|
||||
'active' => false,
|
||||
'name' => [
|
||||
'fr' => "Plus d'argent",
|
||||
'en' => 'No more money',
|
||||
'nl' => 'Geen geld',
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
public static $references = [];
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 9500;
|
||||
}
|
||||
|
||||
public static $closingMotives = array(
|
||||
'nothing_to_do' => array(
|
||||
'name' => array(
|
||||
'fr' => 'Plus rien à faire',
|
||||
'en' => 'Nothing to do',
|
||||
'nl' => 'nieks meer te doen'
|
||||
)
|
||||
),
|
||||
'did_not_come_back' => array(
|
||||
'name' => array(
|
||||
'fr' => "N'est plus revenu",
|
||||
'en' => "Did'nt come back",
|
||||
'nl' => "Niet teruggekomen"
|
||||
)
|
||||
),
|
||||
'no_more_money' => array(
|
||||
'active' => false,
|
||||
'name' => array(
|
||||
'fr' => "Plus d'argent",
|
||||
'en' => "No more money",
|
||||
'nl' => "Geen geld"
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
public static $references = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (static::$closingMotives as $ref => $new) {
|
||||
$motive = new ClosingMotive();
|
||||
$motive->setName($new['name'])
|
||||
->setActive((isset($new['active']) ? $new['active'] : true))
|
||||
;
|
||||
|
||||
->setActive(($new['active'] ?? true));
|
||||
|
||||
$manager->persist($motive);
|
||||
$this->addReference($ref, $motive);
|
||||
echo "Adding ClosingMotive $ref\n";
|
||||
echo "Adding ClosingMotive {$ref}\n";
|
||||
}
|
||||
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@@ -1,14 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadAbstractNotificationsTrait;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadAbstractNotificationsTrait;
|
||||
|
||||
/**
|
||||
* Load notififications into database
|
||||
* Load notififications into database.
|
||||
*/
|
||||
class LoadAccompanyingPeriodNotifications extends AbstractFixture implements DependentFixtureInterface
|
||||
{
|
||||
@@ -24,20 +31,20 @@ class LoadAccompanyingPeriodNotifications extends AbstractFixture implements Dep
|
||||
'center a_social',
|
||||
'center a_administrative',
|
||||
'center a_direction',
|
||||
'multi_center'
|
||||
'multi_center',
|
||||
],
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
protected function getEntityRef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
LoadPeople::class,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getEntityRef()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
@@ -1,52 +1,36 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014-2015, Champs Libres Cooperative SCRLFS,
|
||||
* <http://www.champs-libres.coop>, <info@champs-libres.coop>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod\Origin;
|
||||
|
||||
/**
|
||||
* Description of LoadAccompanyingPeriodOrigin
|
||||
*
|
||||
* @author Champs-Libres Coop
|
||||
* Description of LoadAccompanyingPeriodOrigin.
|
||||
*/
|
||||
class LoadAccompanyingPeriodOrigin extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
|
||||
public const ACCOMPANYING_PERIOD_ORIGIN = 'accompanying_period_origin';
|
||||
|
||||
public static $references = [];
|
||||
|
||||
private $phoneCall = ['en' => 'phone call', 'fr' => 'appel téléphonique'];
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 9000;
|
||||
}
|
||||
|
||||
private $phoneCall = ['en' => 'phone call', 'fr' => 'appel téléphonique'];
|
||||
|
||||
public static $references = array();
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$o = new Origin();
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
@@ -8,24 +15,22 @@ use Chill\PersonBundle\Entity\SocialWork\SocialAction;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Repository\AccompanyingPeriodRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\EvaluationRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\SocialActionRepository;
|
||||
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\PersonBundle\DataFixtures\ORM\LoadPeople;
|
||||
use function array_pop;
|
||||
use function array_rand;
|
||||
|
||||
class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture implements \Doctrine\Common\DataFixtures\DependentFixtureInterface
|
||||
{
|
||||
private AccompanyingPeriodRepository $periodRepository;
|
||||
private EvaluationRepository $evaluationRepository;
|
||||
|
||||
/**
|
||||
* @var Evaluation[]|array
|
||||
* @var array|Evaluation[]
|
||||
*/
|
||||
private array $cacheEvaluations = [];
|
||||
|
||||
/**
|
||||
* @param AccompanyingPeriodRepository $periodRepository
|
||||
*/
|
||||
private EvaluationRepository $evaluationRepository;
|
||||
|
||||
private AccompanyingPeriodRepository $periodRepository;
|
||||
|
||||
public function __construct(
|
||||
AccompanyingPeriodRepository $periodRepository,
|
||||
EvaluationRepository $evaluationRepository
|
||||
@@ -34,16 +39,83 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
|
||||
$this->evaluationRepository = $evaluationRepository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
LoadPeople::class
|
||||
LoadPeople::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
// load all the period which are confirmed
|
||||
$periods = $this->periodRepository
|
||||
->findBy(['step' => AccompanyingPeriod::STEP_CONFIRMED]);
|
||||
|
||||
$i = 0;
|
||||
|
||||
while (null !== $period = array_pop($periods)) {
|
||||
/** @var AccompanyingPeriod $period */
|
||||
++$i;
|
||||
|
||||
if (0 === $i % 15) {
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
if (0 === $period->getSocialIssues()->count()) {
|
||||
continue;
|
||||
}
|
||||
$work = new AccompanyingPeriod\AccompanyingPeriodWork();
|
||||
$action = $this->getRandomAction($period->getSocialIssues()->first());
|
||||
|
||||
if (null !== $action) {
|
||||
$work
|
||||
->setAccompanyingPeriod($period)
|
||||
->setSocialAction($action)
|
||||
->setStartDate(new DateTimeImmutable('today'))
|
||||
->addPerson($period->getPersons()->first())
|
||||
->setCreatedAt(new DateTimeImmutable())
|
||||
->setCreatedBy($this->getReference('center a_social'))
|
||||
->setUpdatedAt(new DateTimeImmutable())
|
||||
->setUpdatedBy($this->getReference('center a_social'));
|
||||
$manager->persist($work);
|
||||
|
||||
if ($action->getEvaluations()->count() > 0) {
|
||||
$ev = $action->getEvaluations()->first();
|
||||
$evaluation = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation();
|
||||
$evaluation->setAccompanyingPeriodWork($work)
|
||||
->setEvaluation($ev);
|
||||
$manager->persist($evaluation);
|
||||
}
|
||||
}
|
||||
|
||||
// 1 of 10, force an evaluation
|
||||
if (0 === $i % 10) {
|
||||
$evaluation = $this->getRandomEvaluation();
|
||||
$action = $evaluation->getSocialAction();
|
||||
$issue = $action->getIssue();
|
||||
|
||||
$period->addSocialIssue($issue);
|
||||
$work
|
||||
->setAccompanyingPeriod($period)
|
||||
->setSocialAction($action)
|
||||
->setStartDate(new DateTimeImmutable('today'))
|
||||
->addPerson($period->getPersons()->first())
|
||||
->setCreatedAt(new DateTimeImmutable())
|
||||
->setCreatedBy($this->getReference('center a_social'))
|
||||
->setUpdatedAt(new DateTimeImmutable())
|
||||
->setUpdatedBy($this->getReference('center a_social'));
|
||||
$manager->persist($work);
|
||||
$ev = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation();
|
||||
$ev->setAccompanyingPeriodWork($work)
|
||||
->setEvaluation($evaluation);
|
||||
$manager->persist($ev);
|
||||
}
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private function getRandomAction(SocialIssue $socialIssue): ?SocialAction
|
||||
{
|
||||
$actions = $socialIssue->getRecursiveSocialActions()->toArray();
|
||||
@@ -52,89 +124,16 @@ class LoadAccompanyingPeriodWork extends \Doctrine\Bundle\FixturesBundle\Fixture
|
||||
return null;
|
||||
}
|
||||
|
||||
return $actions[\array_rand($actions)];
|
||||
return $actions[array_rand($actions)];
|
||||
}
|
||||
|
||||
private function getRandomEvaluation(): Evaluation
|
||||
{
|
||||
if (0 === count($this->cacheEvaluations)) {
|
||||
$this->cacheEvaluations = $this->evaluationRepository
|
||||
->findAll();
|
||||
}
|
||||
|
||||
return $this->cacheEvaluations[\array_rand($this->cacheEvaluations)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
// load all the period which are confirmed
|
||||
$periods = $this->periodRepository
|
||||
->findBy(['step' => AccompanyingPeriod::STEP_CONFIRMED])
|
||||
;
|
||||
|
||||
$i = 0;
|
||||
while (null !== $period = \array_pop($periods)) {
|
||||
/** @var AccompanyingPeriod $period */
|
||||
$i++;
|
||||
if (0 === $i % 15) {
|
||||
$manager->flush();
|
||||
}
|
||||
if (0 === $period->getSocialIssues()->count()) {
|
||||
continue;
|
||||
}
|
||||
$work = new AccompanyingPeriod\AccompanyingPeriodWork();
|
||||
$action = $this->getRandomAction($period->getSocialIssues()->first());
|
||||
|
||||
if (null !== $action) {
|
||||
$work
|
||||
->setAccompanyingPeriod($period)
|
||||
->setSocialAction($action)
|
||||
->setStartDate(new \DateTimeImmutable('today'))
|
||||
->addPerson($period->getPersons()->first())
|
||||
->setCreatedAt(new \DateTimeImmutable())
|
||||
->setCreatedBy($this->getReference('center a_social'))
|
||||
->setUpdatedAt(new \DateTimeImmutable())
|
||||
->setUpdatedBy($this->getReference('center a_social'));
|
||||
$manager->persist($work);
|
||||
|
||||
if ($action->getEvaluations()->count() > 0) {
|
||||
$ev = $action->getEvaluations()->first();
|
||||
$evaluation = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation();
|
||||
$evaluation->setAccompanyingPeriodWork($work)
|
||||
->setEvaluation($ev);
|
||||
$manager->persist($evaluation);
|
||||
}
|
||||
}
|
||||
|
||||
// 1 of 10, force an evaluation
|
||||
if (0 === $i % 10) {
|
||||
$evaluation = $this->getRandomEvaluation();
|
||||
$action = $evaluation->getSocialAction();
|
||||
$issue = $action->getIssue();
|
||||
|
||||
$period->addSocialIssue($issue);
|
||||
$work
|
||||
->setAccompanyingPeriod($period)
|
||||
->setSocialAction($action)
|
||||
->setStartDate(new \DateTimeImmutable('today'))
|
||||
->addPerson($period->getPersons()->first())
|
||||
->setCreatedAt(new \DateTimeImmutable())
|
||||
->setCreatedBy($this->getReference('center a_social'))
|
||||
->setUpdatedAt(new \DateTimeImmutable())
|
||||
->setUpdatedBy($this->getReference('center a_social'))
|
||||
;
|
||||
$manager->persist($work);
|
||||
$ev = new AccompanyingPeriod\AccompanyingPeriodWorkEvaluation();
|
||||
$ev->setAccompanyingPeriodWork($work)
|
||||
->setEvaluation($evaluation);
|
||||
$manager->persist($ev);
|
||||
}
|
||||
|
||||
if (0 === count($this->cacheEvaluations)) {
|
||||
$this->cacheEvaluations = $this->evaluationRepository
|
||||
->findAll();
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
return $this->cacheEvaluations[array_rand($this->cacheEvaluations)];
|
||||
}
|
||||
}
|
||||
|
@@ -1,78 +1,61 @@
|
||||
<?php
|
||||
/*
|
||||
* Copyright (C) 2017 Champs Libres Cooperative <info@champs-libres.coop>
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice;
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldText;
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldTitle;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
|
||||
use Chill\MainBundle\Templating\TranslatableStringHelper;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use RuntimeException;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomField;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup;
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldTitle;
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldText;
|
||||
use Chill\CustomFieldsBundle\CustomFields\CustomFieldChoice;
|
||||
use Chill\CustomFieldsBundle\Entity\CustomFieldsDefaultGroup;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Symfony\Contracts\Translation\TranslatorInterface;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
*/
|
||||
class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterface,
|
||||
class LoadCustomFields extends AbstractFixture implements
|
||||
OrderedFixtureInterface,
|
||||
ContainerAwareInterface
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var ContainerInterface
|
||||
*/
|
||||
private $container;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @var CustomField
|
||||
*/
|
||||
private $customFieldText;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var CustomField
|
||||
*/
|
||||
private $customFieldChoice;
|
||||
|
||||
|
||||
/**
|
||||
* @var CustomField
|
||||
*/
|
||||
private $customFieldText;
|
||||
|
||||
/**
|
||||
* @var TranslatableStringHelper
|
||||
*/
|
||||
private $translatableStringHelper;
|
||||
|
||||
|
||||
/**
|
||||
* @var TranslatorInterface
|
||||
*/
|
||||
private $translator;
|
||||
|
||||
|
||||
/**
|
||||
* LoadCustomFields constructor.
|
||||
*
|
||||
* @param TranslatableStringHelper $translatableStringHelper
|
||||
* @param TranslatorInterface $translator
|
||||
*/
|
||||
public function __construct(
|
||||
TranslatableStringHelper $translatableStringHelper,
|
||||
@@ -81,21 +64,12 @@ class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterfac
|
||||
$this->translatableStringHelper = $translatableStringHelper;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
|
||||
//put your code here
|
||||
public function getOrder()
|
||||
{
|
||||
return 10003;
|
||||
}
|
||||
|
||||
public function setContainer(ContainerInterface $container = null)
|
||||
{
|
||||
if ($container === null) {
|
||||
throw new \RuntimeException("The given container should not be null");
|
||||
}
|
||||
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
@@ -103,45 +77,16 @@ class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterfac
|
||||
$this->loadData($manager);
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private function loadData(ObjectManager $manager)
|
||||
|
||||
public function setContainer(?ContainerInterface $container = null)
|
||||
{
|
||||
$personIds = $this->container->get('doctrine.orm.entity_manager')
|
||||
->createQuery("SELECT person.id FROM ChillPersonBundle:Person person")
|
||||
->getScalarResult();
|
||||
|
||||
// get possible values for cfGroup
|
||||
$choices = array_map(
|
||||
function($a) { return $a["slug"]; },
|
||||
$this->customFieldChoice->getOptions()["choices"]
|
||||
);
|
||||
// create faker
|
||||
$faker = \Faker\Factory::create('fr_FR');
|
||||
// select a set of people and add data
|
||||
foreach ($personIds as $id) {
|
||||
// add info on 1 person on 2
|
||||
if (rand(0,1) === 1) {
|
||||
/* @var $person Person */
|
||||
$person = $manager->getRepository(Person::class)->find($id);
|
||||
$person->setCFData(array(
|
||||
"remarques" => $this->createCustomFieldText()
|
||||
->serialize($faker->text(rand(150, 250)), $this->customFieldText),
|
||||
"document-d-identite" => $this->createCustomFieldChoice()
|
||||
->serialize(array($choices[array_rand($choices)]), $this->customFieldChoice)
|
||||
));
|
||||
}
|
||||
if (null === $container) {
|
||||
throw new RuntimeException('The given container should not be null');
|
||||
}
|
||||
|
||||
$this->container = $container;
|
||||
}
|
||||
|
||||
private function createCustomFieldText()
|
||||
{
|
||||
return new CustomFieldText(
|
||||
$this->container->get('request_stack'),
|
||||
$this->container->get('templating'),
|
||||
$this->translatableStringHelper
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function createCustomFieldChoice()
|
||||
{
|
||||
return new CustomFieldChoice(
|
||||
@@ -150,80 +95,113 @@ class LoadCustomFields extends AbstractFixture implements OrderedFixtureInterfac
|
||||
$this->translatableStringHelper
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function createCustomFieldText()
|
||||
{
|
||||
return new CustomFieldText(
|
||||
$this->container->get('request_stack'),
|
||||
$this->container->get('templating'),
|
||||
$this->translatableStringHelper
|
||||
);
|
||||
}
|
||||
|
||||
private function loadData(ObjectManager $manager)
|
||||
{
|
||||
$personIds = $this->container->get('doctrine.orm.entity_manager')
|
||||
->createQuery('SELECT person.id FROM ChillPersonBundle:Person person')
|
||||
->getScalarResult();
|
||||
|
||||
// get possible values for cfGroup
|
||||
$choices = array_map(
|
||||
function ($a) { return $a['slug']; },
|
||||
$this->customFieldChoice->getOptions()['choices']
|
||||
);
|
||||
// create faker
|
||||
$faker = \Faker\Factory::create('fr_FR');
|
||||
// select a set of people and add data
|
||||
foreach ($personIds as $id) {
|
||||
// add info on 1 person on 2
|
||||
if (rand(0, 1) === 1) {
|
||||
/* @var $person Person */
|
||||
$person = $manager->getRepository(Person::class)->find($id);
|
||||
$person->setCFData([
|
||||
'remarques' => $this->createCustomFieldText()
|
||||
->serialize($faker->text(rand(150, 250)), $this->customFieldText),
|
||||
'document-d-identite' => $this->createCustomFieldChoice()
|
||||
->serialize([$choices[array_rand($choices)]], $this->customFieldChoice),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function loadFields(ObjectManager $manager)
|
||||
{
|
||||
$cfGroup = (new CustomFieldsGroup())
|
||||
->setEntity(Person::class)
|
||||
->setName(array("fr" => "Données"))
|
||||
;
|
||||
->setName(['fr' => 'Données']);
|
||||
$manager->persist($cfGroup);
|
||||
|
||||
|
||||
// make this group default for Person::class
|
||||
$manager->persist(
|
||||
(new CustomFieldsDefaultGroup())
|
||||
->setCustomFieldsGroup($cfGroup)
|
||||
->setEntity(Person::class)
|
||||
);
|
||||
|
||||
);
|
||||
|
||||
// create title field
|
||||
$customField0 = (new CustomField())
|
||||
->setActive(true)
|
||||
->setName(array("fr" => "Données personnalisées"))
|
||||
->setSlug("personal-data")
|
||||
->setName(['fr' => 'Données personnalisées'])
|
||||
->setSlug('personal-data')
|
||||
->setOrdering(10)
|
||||
->setType('title')
|
||||
->setOptions(array(CustomFieldTitle::TYPE => CustomFieldTitle::TYPE_TITLE))
|
||||
->setCustomFieldsGroup($cfGroup)
|
||||
;
|
||||
->setOptions([CustomFieldTitle::TYPE => CustomFieldTitle::TYPE_TITLE])
|
||||
->setCustomFieldsGroup($cfGroup);
|
||||
$manager->persist($customField0);
|
||||
|
||||
|
||||
// create text field
|
||||
$this->customFieldText = (new CustomField())
|
||||
->setActive(true)
|
||||
->setName(array("fr" => "Remarques"))
|
||||
->setSlug("remarques")
|
||||
->setName(['fr' => 'Remarques'])
|
||||
->setSlug('remarques')
|
||||
->setOrdering(20)
|
||||
->setType('text')
|
||||
->setOptions(array('maxLength' => 5000))
|
||||
->setCustomFieldsGroup($cfGroup)
|
||||
;
|
||||
->setOptions(['maxLength' => 5000])
|
||||
->setCustomFieldsGroup($cfGroup);
|
||||
$manager->persist($this->customFieldText);
|
||||
|
||||
|
||||
// create choice field
|
||||
$this->customFieldChoice = (new CustomField())
|
||||
->setActive(true)
|
||||
->setName(array("fr" => "Document d'identité"))
|
||||
->setSlug("document-d-identite")
|
||||
->setName(['fr' => "Document d'identité"])
|
||||
->setSlug('document-d-identite')
|
||||
->setOrdering(30)
|
||||
->setType('choice')
|
||||
->setCustomFieldsGroup($cfGroup)
|
||||
->setOptions(array(
|
||||
"multiple" => true,
|
||||
"other" => false,
|
||||
"expanded" => true,
|
||||
"active" => true,
|
||||
"slug" => "document-d-identite",
|
||||
"choices" => array(
|
||||
array(
|
||||
"name" => array("fr" => "Carte d'identité"),
|
||||
"active" => true,
|
||||
"slug" => "carte-d-identite"
|
||||
),
|
||||
array(
|
||||
"name" => array("fr" => "Passeport"),
|
||||
"active" => true,
|
||||
"slug" => "passeport"
|
||||
),
|
||||
array(
|
||||
"name" => array("fr" => "Titre de séjour"),
|
||||
"active" => true,
|
||||
"slug" => "passeport"
|
||||
)
|
||||
)
|
||||
))
|
||||
;
|
||||
->setOptions([
|
||||
'multiple' => true,
|
||||
'other' => false,
|
||||
'expanded' => true,
|
||||
'active' => true,
|
||||
'slug' => 'document-d-identite',
|
||||
'choices' => [
|
||||
[
|
||||
'name' => ['fr' => "Carte d'identité"],
|
||||
'active' => true,
|
||||
'slug' => 'carte-d-identite',
|
||||
],
|
||||
[
|
||||
'name' => ['fr' => 'Passeport'],
|
||||
'active' => true,
|
||||
'slug' => 'passeport',
|
||||
],
|
||||
[
|
||||
'name' => ['fr' => 'Titre de séjour'],
|
||||
'active' => true,
|
||||
'slug' => 'passeport',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$manager->persist($this->customFieldChoice);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,31 +1,45 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
use Chill\PersonBundle\Entity\Household\Household;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Household\MembersEditorFactory;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||
use Nelmio\Alice\Loader\NativeLoader;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
||||
use function array_pop;
|
||||
use function array_rand;
|
||||
use function random_int;
|
||||
use function shuffle;
|
||||
|
||||
class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
private const NUMBER_OF_HOUSEHOLD = 10;
|
||||
|
||||
private MembersEditorFactory $editorFactory;
|
||||
|
||||
private EntityManagerInterface $em;
|
||||
|
||||
private NativeLoader $loader;
|
||||
|
||||
private CONST NUMBER_OF_HOUSEHOLD = 10;
|
||||
|
||||
private array $personIds;
|
||||
|
||||
public function __construct(MembersEditorFactory $editorFactory, EntityManagerInterface $em)
|
||||
@@ -35,6 +49,14 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
$this->loader = new NativeLoader();
|
||||
}
|
||||
|
||||
public function getDependencies()
|
||||
{
|
||||
return [
|
||||
LoadPeople::class,
|
||||
LoadHouseholdPosition::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
// generate two times the participation. This will lead to
|
||||
@@ -45,87 +67,44 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
|
||||
$this->generateHousehold(
|
||||
$manager,
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
|
||||
DateTimeImmutable::createFromFormat('Y-m-d', '2010-01-01')
|
||||
);
|
||||
|
||||
$this->preparePersonIds();
|
||||
|
||||
$this->generateHousehold(
|
||||
$manager,
|
||||
\DateTimeImmutable::createFromFormat('Y-m-d', '2015-01-01')
|
||||
DateTimeImmutable::createFromFormat('Y-m-d', '2015-01-01')
|
||||
);
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
private function generateHousehold(ObjectManager $manager, \DateTimeImmutable $startDate)
|
||||
private function addAddressToHousehold(Household $household, DateTimeImmutable $date, ObjectManager $manager)
|
||||
{
|
||||
for ($i=0; $i < self::NUMBER_OF_HOUSEHOLD; $i++) {
|
||||
$household = new Household();
|
||||
$manager->persist($household);
|
||||
|
||||
$this->addAddressToHousehold($household, clone $startDate, $manager);
|
||||
|
||||
$movement = $this->editorFactory->createEditor($household);
|
||||
|
||||
// load adults
|
||||
$k = 0;
|
||||
foreach ($this->getRandomPersons(1, 3) as $person) {
|
||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::ADULT);
|
||||
|
||||
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||
$k++;
|
||||
}
|
||||
|
||||
// load children
|
||||
foreach ($this->getRandomPersons(0, 3) as $person) {
|
||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::CHILD);
|
||||
|
||||
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||
$k++;
|
||||
}
|
||||
|
||||
// load children out
|
||||
foreach ($this->getRandomPersons(0, 2) as $person) {
|
||||
$date = $startDate->add(new \DateInterval('P'.\random_int(1, 200).'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::CHILD_OUT);
|
||||
|
||||
$movement->addMovement($date, $person, $position, $k === 0, "self generated");
|
||||
$k++;
|
||||
}
|
||||
|
||||
foreach ($movement->getPersistable() as $obj) {
|
||||
$manager->persist($obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function addAddressToHousehold(Household $household, \DateTimeImmutable $date, ObjectManager $manager)
|
||||
{
|
||||
if (\random_int(0, 10) > 8) {
|
||||
if (random_int(0, 10) > 8) {
|
||||
// 20% of household without address
|
||||
return;
|
||||
}
|
||||
|
||||
$nb = \random_int(1, 6);
|
||||
$nb = random_int(1, 6);
|
||||
|
||||
$i = 0;
|
||||
|
||||
while ($i < $nb) {
|
||||
$address = $this->createAddress();
|
||||
$address->setValidFrom(\DateTime::createFromImmutable($date));
|
||||
$address->setValidFrom(DateTime::createFromImmutable($date));
|
||||
|
||||
if (\random_int(0, 20) < 1) {
|
||||
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
|
||||
$address->setValidTo(\DateTime::createFromImmutable($date));
|
||||
if (random_int(0, 20) < 1) {
|
||||
$date = $date->add(new DateInterval('P' . random_int(8, 52) . 'W'));
|
||||
$address->setValidTo(DateTime::createFromImmutable($date));
|
||||
}
|
||||
|
||||
$household->addAddress($address);
|
||||
$manager->persist($address);
|
||||
|
||||
$date = $date->add(new \DateInterval('P'.\random_int(8, 52).'W'));
|
||||
$i++;
|
||||
$date = $date->add(new DateInterval('P' . random_int(8, 52) . 'W'));
|
||||
++$i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,54 +115,92 @@ class LoadHousehold extends Fixture implements DependentFixtureInterface
|
||||
'address1' => [
|
||||
'street' => '<fr_FR:streetName()>',
|
||||
'streetNumber' => '<fr_FR:buildingNumber()>',
|
||||
'postCode' => $this->getPostalCode()
|
||||
]
|
||||
]
|
||||
'postCode' => $this->getPostalCode(),
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
return $objectSet->getObjects()['address1'];
|
||||
}
|
||||
|
||||
private function getPostalCode(): PostalCode
|
||||
private function generateHousehold(ObjectManager $manager, DateTimeImmutable $startDate)
|
||||
{
|
||||
$ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)];
|
||||
for ($i = 0; self::NUMBER_OF_HOUSEHOLD > $i; ++$i) {
|
||||
$household = new Household();
|
||||
$manager->persist($household);
|
||||
|
||||
return $this->getReference($ref);
|
||||
$this->addAddressToHousehold($household, clone $startDate, $manager);
|
||||
|
||||
$movement = $this->editorFactory->createEditor($household);
|
||||
|
||||
// load adults
|
||||
$k = 0;
|
||||
|
||||
foreach ($this->getRandomPersons(1, 3) as $person) {
|
||||
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::ADULT);
|
||||
|
||||
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
||||
++$k;
|
||||
}
|
||||
|
||||
// load children
|
||||
foreach ($this->getRandomPersons(0, 3) as $person) {
|
||||
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::CHILD);
|
||||
|
||||
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
||||
++$k;
|
||||
}
|
||||
|
||||
// load children out
|
||||
foreach ($this->getRandomPersons(0, 2) as $person) {
|
||||
$date = $startDate->add(new DateInterval('P' . random_int(1, 200) . 'W'));
|
||||
$position = $this->getReference(LoadHouseholdPosition::CHILD_OUT);
|
||||
|
||||
$movement->addMovement($date, $person, $position, 0 === $k, 'self generated');
|
||||
++$k;
|
||||
}
|
||||
|
||||
foreach ($movement->getPersistable() as $obj) {
|
||||
$manager->persist($obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function preparePersonIds()
|
||||
private function getPostalCode(): PostalCode
|
||||
{
|
||||
// @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();
|
||||
$ref = LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)];
|
||||
|
||||
\shuffle($this->personIds);
|
||||
return $this->getReference($ref);
|
||||
}
|
||||
|
||||
private function getRandomPersons(int $min, int $max): array
|
||||
{
|
||||
$persons = [];
|
||||
|
||||
$nb = \random_int($min, $max);
|
||||
$nb = random_int($min, $max);
|
||||
|
||||
for ($i=0; $i < $nb; $i++) {
|
||||
$personId = \array_pop($this->personIds)['id'];
|
||||
for ($i = 0; $i < $nb; ++$i) {
|
||||
$personId = array_pop($this->personIds)['id'];
|
||||
$persons[] = $this->em->getRepository(Person::class)->find($personId);
|
||||
}
|
||||
|
||||
return $persons;
|
||||
}
|
||||
|
||||
public function getDependencies()
|
||||
private function preparePersonIds()
|
||||
{
|
||||
return [
|
||||
LoadPeople::class,
|
||||
LoadHouseholdPosition::class
|
||||
];
|
||||
// @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();
|
||||
|
||||
shuffle($this->personIds);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\Household\Position;
|
||||
@@ -8,26 +15,27 @@ use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class LoadHouseholdPosition extends Fixture
|
||||
{
|
||||
const POSITIONS_DATA = [
|
||||
["Adulte", true, true, 1.0, self::ADULT ],
|
||||
["Enfant", true, false, 2.0, self::CHILD ],
|
||||
["Enfant hors ménage", false, false, 3.0, self::CHILD_OUT ]
|
||||
];
|
||||
public const ADULT = 'position_adulte';
|
||||
|
||||
const ADULT = "position_adulte";
|
||||
const CHILD = "position_enfant";
|
||||
const CHILD_OUT = "position_enfant_hors";
|
||||
public const CHILD = 'position_enfant';
|
||||
|
||||
public const CHILD_OUT = 'position_enfant_hors';
|
||||
|
||||
public const POSITIONS_DATA = [
|
||||
['Adulte', true, true, 1.0, self::ADULT],
|
||||
['Enfant', true, false, 2.0, self::CHILD],
|
||||
['Enfant hors ménage', false, false, 3.0, self::CHILD_OUT],
|
||||
];
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (self::POSITIONS_DATA as list($name, $share, $allowHolder,
|
||||
$ordering, $ref)) {
|
||||
foreach (self::POSITIONS_DATA as [$name, $share, $allowHolder,
|
||||
$ordering, $ref]) {
|
||||
$position = (new Position())
|
||||
->setLabel([ "fr" => $name ])
|
||||
->setLabel(['fr' => $name])
|
||||
->setAllowHolder($allowHolder)
|
||||
->setShareHousehold($share)
|
||||
->setOrdering($ordering)
|
||||
;
|
||||
->setOrdering($ordering);
|
||||
|
||||
$manager->persist($position);
|
||||
$this->addReference($ref, $position);
|
||||
|
@@ -1,66 +1,52 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\PersonBundle\Entity\MaritalStatus;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\PersonBundle\Entity\MaritalStatus;
|
||||
|
||||
/**
|
||||
* Load marital status into database
|
||||
*
|
||||
* @author Marc Ducobu <marc@champs-libres.coop>
|
||||
* Load marital status into database.
|
||||
*/
|
||||
class LoadMaritalStatus extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
private $maritalStatuses = [
|
||||
['id' => 'single', 'name' =>['en' => 'single', 'fr' => 'célibataire']],
|
||||
['id' => 'married', 'name' =>['en' => 'married', 'fr' => 'marié(e)']],
|
||||
['id' => 'widow', 'name' =>['en' => 'widow', 'fr' => 'veuf – veuve ']],
|
||||
['id' => 'separat', 'name' =>['en' => 'separated', 'fr' => 'séparé(e)']],
|
||||
['id' => 'divorce', 'name' =>['en' => 'divorced', 'fr' => 'divorcé(e)']],
|
||||
['id' => 'legalco', 'name' =>['en' => 'legal cohabitant', 'fr' => 'cohabitant(e) légal(e)']],
|
||||
['id' => 'unknown', 'name' =>['en' => 'unknown', 'fr' => 'indéterminé']]
|
||||
['id' => 'single', 'name' => ['en' => 'single', 'fr' => 'célibataire']],
|
||||
['id' => 'married', 'name' => ['en' => 'married', 'fr' => 'marié(e)']],
|
||||
['id' => 'widow', 'name' => ['en' => 'widow', 'fr' => 'veuf – veuve ']],
|
||||
['id' => 'separat', 'name' => ['en' => 'separated', 'fr' => 'séparé(e)']],
|
||||
['id' => 'divorce', 'name' => ['en' => 'divorced', 'fr' => 'divorcé(e)']],
|
||||
['id' => 'legalco', 'name' => ['en' => 'legal cohabitant', 'fr' => 'cohabitant(e) légal(e)']],
|
||||
['id' => 'unknown', 'name' => ['en' => 'unknown', 'fr' => 'indéterminé']],
|
||||
];
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 9999;
|
||||
}
|
||||
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
echo "loading maritalStatuses... \n";
|
||||
|
||||
foreach ($this->maritalStatuses as $ms) {
|
||||
echo $ms['name']['en'].' ';
|
||||
echo $ms['name']['en'] . ' ';
|
||||
$new_ms = new MaritalStatus();
|
||||
$new_ms->setId($ms['id']);
|
||||
$new_ms->setName($ms['name']);
|
||||
$this->addReference('ms_'.$ms['id'], $new_ms);
|
||||
$this->addReference('ms_' . $ms['id'], $new_ms);
|
||||
$manager->persist($new_ms);
|
||||
}
|
||||
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
||||
|
@@ -1,26 +1,17 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
||||
use Chill\MainBundle\Doctrine\Model\Point;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Entity\Center;
|
||||
use Chill\MainBundle\Entity\Country;
|
||||
use Chill\MainBundle\Entity\PostalCode;
|
||||
@@ -32,386 +23,91 @@ use Chill\MainBundle\Repository\ScopeRepository;
|
||||
use Chill\MainBundle\Repository\UserRepository;
|
||||
use Chill\PersonBundle\Entity\AccompanyingPeriod;
|
||||
use Chill\PersonBundle\Entity\MaritalStatus;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\SocialWork\SocialIssue;
|
||||
use Chill\PersonBundle\Repository\MaritalStatusRepository;
|
||||
use Chill\ThirdPartyBundle\Entity\ThirdParty;
|
||||
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use DateTimeImmutable;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Exception;
|
||||
use Faker\Factory;
|
||||
use Faker\Generator;
|
||||
use Nelmio\Alice\Faker\GeneratorFactory;
|
||||
use Nelmio\Alice\Loader\NativeLoader;
|
||||
use Nelmio\Alice\ObjectSet;
|
||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
|
||||
use Chill\MainBundle\Entity\Address;
|
||||
use Chill\MainBundle\Doctrine\Model\Point;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Workflow\Workflow;
|
||||
use Chill\PersonBundle\Repository\SocialWork\SocialIssueRepository;
|
||||
use function random_int;
|
||||
use function ucfirst;
|
||||
|
||||
/**
|
||||
* Load people into database
|
||||
*
|
||||
* Load people into database.
|
||||
*/
|
||||
class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
|
||||
{
|
||||
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
||||
|
||||
protected Generator $faker;
|
||||
|
||||
protected Registry $workflowRegistry;
|
||||
|
||||
protected SocialIssueRepository $socialIssueRepository;
|
||||
|
||||
protected CountryRepository $countryRepository;
|
||||
|
||||
protected NativeLoader $loader;
|
||||
public const PERSON = 'person';
|
||||
|
||||
/**
|
||||
* @var array|SocialIssue[]
|
||||
* @var array|Center[]
|
||||
*/
|
||||
protected array $cacheSocialIssues = [];
|
||||
protected array $cacheCenters = [];
|
||||
|
||||
/**
|
||||
* @var array|Country[]
|
||||
*/
|
||||
protected array $cacheCountries = [];
|
||||
|
||||
/**
|
||||
* @var array|Center[]
|
||||
*/
|
||||
protected array $cacheCenters = [];
|
||||
|
||||
protected CenterRepository $centerRepository;
|
||||
|
||||
/**
|
||||
* @var array|MaritalStatus[]
|
||||
*/
|
||||
protected array $cacheMaritalStatuses = [];
|
||||
|
||||
protected MaritalStatusRepository $maritalStatusRepository;
|
||||
|
||||
/**
|
||||
* @var array|Scope[]
|
||||
*/
|
||||
protected array $cacheScopes = [];
|
||||
|
||||
/**
|
||||
* @var array|SocialIssue[]
|
||||
*/
|
||||
protected array $cacheSocialIssues = [];
|
||||
|
||||
/**
|
||||
* @var array|User[]
|
||||
*/
|
||||
protected array $cacheUsers = [];
|
||||
|
||||
protected CenterRepository $centerRepository;
|
||||
|
||||
protected CountryRepository $countryRepository;
|
||||
|
||||
protected Generator $faker;
|
||||
|
||||
protected NativeLoader $loader;
|
||||
|
||||
protected MaritalStatusRepository $maritalStatusRepository;
|
||||
|
||||
protected ScopeRepository $scopeRepository;
|
||||
|
||||
/** @var array|User[] */
|
||||
protected array $cacheUsers = [];
|
||||
protected SocialIssueRepository $socialIssueRepository;
|
||||
|
||||
protected UserRepository $userRepository;
|
||||
|
||||
public const PERSON = 'person';
|
||||
protected Registry $workflowRegistry;
|
||||
|
||||
public function __construct(
|
||||
Registry $workflowRegistry,
|
||||
SocialIssueRepository $socialIssueRepository,
|
||||
CenterRepository $centerRepository,
|
||||
CountryRepository $countryRepository,
|
||||
MaritalStatusRepository $maritalStatusRepository,
|
||||
ScopeRepository $scopeRepository,
|
||||
UserRepository $userRepository
|
||||
) {
|
||||
$this->faker = Factory::create('fr_FR');
|
||||
$this->faker->addProvider($this);
|
||||
$this->workflowRegistry = $workflowRegistry;
|
||||
$this->socialIssueRepository = $socialIssueRepository;
|
||||
$this->centerRepository = $centerRepository;
|
||||
$this->countryRepository = $countryRepository;
|
||||
$this->maritalStatusRepository = $maritalStatusRepository;
|
||||
$this->loader = new NativeLoader($this->faker);
|
||||
$this->scopeRepository = $scopeRepository;
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
private $genders = [Person::MALE_GENDER, Person::FEMALE_GENDER, Person::BOTH_GENDER];
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 10000;
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$this->loadExpectedPeople($manager);
|
||||
$this->loadRandPeople($manager);
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
public function loadExpectedPeople(ObjectManager $manager)
|
||||
{
|
||||
echo "loading expected people...\n";
|
||||
|
||||
|
||||
foreach ($this->peoples as $personDef) {
|
||||
$person = $this->createExpectedPerson($personDef);
|
||||
$this->addAPerson($person, $manager);
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadRandPeople(ObjectManager $manager)
|
||||
{
|
||||
echo "loading rand people...\n";
|
||||
$persons = $this->createRandPerson()->getObjects();
|
||||
|
||||
foreach ($persons as $person) {
|
||||
$this->addAPerson($person, $manager);
|
||||
}
|
||||
}
|
||||
|
||||
private function createRandPerson(): ObjectSet
|
||||
{
|
||||
return $this->loader->loadData([
|
||||
Person::class => [
|
||||
'persons{1..300}' => [
|
||||
'firstName' => '<firstname()>',
|
||||
'lastName' => '<lastname()>',
|
||||
'gender' => '<getRandomGender()>',
|
||||
'nationality' => '<getRandomCountry()>',
|
||||
'center' => '<getRandomCenter()>',
|
||||
'maritalStatus' => '<getRandomMaritalStatus()>',
|
||||
'birthdate' => '<dateTimeBetween("-75 years", "-1 tears")>',
|
||||
'placeOfBirth' => '<city()>',
|
||||
'email' => '<freeEmail()>',
|
||||
'countryOfBirth' => '<getRandomCountry(80)>',
|
||||
]
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
private function createExpectedPerson($default): Person
|
||||
{
|
||||
$person = $this->loader->loadData([
|
||||
Person::class => [
|
||||
"person" => [
|
||||
'firstName' => $default['firstName'] ?? '<firstname()>',
|
||||
'lastName' => $default['lastName'] ?? '<lastname()>',
|
||||
'gender' => '<getRandomGender()>',
|
||||
'nationality' => '<getRandomCountry()>',
|
||||
'center' => '<getRandomCenter()>',
|
||||
'maritalStatus' => '<getRandomMaritalStatus()>',
|
||||
'birthdate' => '<dateTimeBetween("-75 years", "-1 tears")>',
|
||||
'placeOfBirth' => '<city()>',
|
||||
'email' => '<freeEmail()>',
|
||||
'countryOfBirth' => '<getRandomCountry(80)>',
|
||||
],
|
||||
]
|
||||
])->getObjects()['person'];
|
||||
|
||||
// force some values
|
||||
foreach ($default as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'birthdate':
|
||||
$person->setBirthdate(new \DateTime($value));
|
||||
break;
|
||||
case 'center':
|
||||
$person->setCenter($this->centerRepository
|
||||
->findOneBy(['name' => $value]));
|
||||
break;
|
||||
case 'countryOfBirth':
|
||||
case 'nationality':
|
||||
$country = $this->countryRepository
|
||||
->findOneBy(['countryCode' => $value]);
|
||||
$person->{'set'.\ucfirst($key)}($country);
|
||||
break;
|
||||
case 'maritalStatus':
|
||||
$person->setMaritalStatus($this->maritalStatusRepository
|
||||
->find($value));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new person from array data
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function addAPerson(Person $person, ObjectManager $manager)
|
||||
{
|
||||
$accompanyingPeriod = new AccompanyingPeriod(
|
||||
(new \DateTime())
|
||||
->sub(
|
||||
new \DateInterval('P' . \random_int(0, 180) . 'D')
|
||||
)
|
||||
);
|
||||
$accompanyingPeriod->setCreatedBy($this->getRandomUser())
|
||||
->setCreatedAt(new \DateTimeImmutable('now'));
|
||||
$person->addAccompanyingPeriod($accompanyingPeriod);
|
||||
$accompanyingPeriod->addSocialIssue($this->getRandomSocialIssue());
|
||||
|
||||
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);
|
||||
$workflow->apply($accompanyingPeriod, 'confirm');
|
||||
}
|
||||
|
||||
$manager->persist($person);
|
||||
$manager->persist($accompanyingPeriod);
|
||||
echo "add person'".$person->__toString()."'\n";
|
||||
|
||||
$this->addReference(self::PERSON.$person->getId(), $person);
|
||||
}
|
||||
|
||||
private function getRandomUser(): User
|
||||
{
|
||||
if (0 === count($this->cacheUsers)) {
|
||||
$this->cacheUsers = $this->userRepository->findAll();
|
||||
}
|
||||
|
||||
return $this->cacheUsers[\array_rand($this->cacheUsers)];
|
||||
}
|
||||
|
||||
private function createAddress(): Address
|
||||
{
|
||||
$objectSet = $this->loader->loadData([
|
||||
Address::class => [
|
||||
'address' => [
|
||||
'street' => '<fr_FR:streetName()>',
|
||||
'streetNumber' => '<fr_FR:buildingNumber()>',
|
||||
'validFrom' => '<dateTimeBetween(\'-1 year\', \'now\')>',
|
||||
'postCode' => $this->getPostalCode()
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
return $objectSet->getObjects()['address'];
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function getRandomSocialIssue(): SocialIssue
|
||||
{
|
||||
if (0 === count($this->cacheSocialIssues)) {
|
||||
$this->cacheSocialIssues = $this->socialIssueRepository->findAll();
|
||||
}
|
||||
|
||||
return $this->cacheSocialIssues[\array_rand($this->cacheSocialIssues)];
|
||||
}
|
||||
|
||||
private function getPostalCode(): PostalCode
|
||||
{
|
||||
$ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)];
|
||||
|
||||
return $this->getReference($ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a random point
|
||||
*
|
||||
* @return Point
|
||||
*/
|
||||
private function getRandomPoint()
|
||||
{
|
||||
$lonBrussels = 4.35243;
|
||||
$latBrussels = 50.84676;
|
||||
$lon = $lonBrussels + 0.01 * rand(-5, 5);
|
||||
$lat = $latBrussels + 0.01 * rand(-5, 5);
|
||||
return Point::fromLonLat($lon, $lat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a random address
|
||||
*
|
||||
* @return Address
|
||||
*/
|
||||
private function getRandomAddress()
|
||||
{
|
||||
return (new Address())
|
||||
->setStreetAddress1($this->faker->streetAddress)
|
||||
->setStreetAddress2(
|
||||
rand(0,9) > 5 ? $this->faker->streetAddress : ''
|
||||
)
|
||||
->setPoint(
|
||||
rand(0,9) > 5 ? $this->getRandomPoint() : NULL
|
||||
)
|
||||
->setPostcode($this->getReference(
|
||||
LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)]
|
||||
))
|
||||
->setValidFrom($this->faker->dateTimeBetween('-5 years'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
* @return Center
|
||||
*/
|
||||
public function getRandomCenter(): Center
|
||||
{
|
||||
if (0 === count($this->cacheCenters)) {
|
||||
$this->cacheCenters = $this->centerRepository->findAll();
|
||||
}
|
||||
|
||||
return $this->cacheCenters[\array_rand($this->cacheCenters)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
* @param int $nullPercentage
|
||||
* @return Country|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getRandomCountry(int $nullPercentage = 20): ?Country
|
||||
{
|
||||
if (0 === count($this->cacheCountries)) {
|
||||
$this->cacheCountries = $this->countryRepository->findAll();
|
||||
}
|
||||
|
||||
if ($nullPercentage < \random_int(0, 100)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $this->cacheCountries [\array_rand($this->cacheCountries)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
* @return string
|
||||
*/
|
||||
public function getRandomGender(): string
|
||||
{
|
||||
return $this->genders[array_rand($this->genders)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
* @param int $nullPercentage
|
||||
* @return MaritalStatus|null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getRandomMaritalStatus(int $nullPercentage = 50): ?MaritalStatus
|
||||
{
|
||||
if (0 === count($this->cacheMaritalStatuses)) {
|
||||
$this->cacheMaritalStatuses = $this->maritalStatusRepository->findAll();
|
||||
}
|
||||
|
||||
if ($nullPercentage < \random_int(0, 100)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $this->cacheMaritalStatuses[array_rand($this->cacheMaritalStatuses)];
|
||||
}
|
||||
|
||||
private $genders = array(Person::MALE_GENDER, Person::FEMALE_GENDER, Person::BOTH_GENDER);
|
||||
|
||||
private $peoples = array(
|
||||
array(
|
||||
'lastName' => "Depardieu",
|
||||
'firstName' => "Gérard",
|
||||
'birthdate' => "1948-12-27",
|
||||
'placeOfBirth' => "Châteauroux",
|
||||
private $peoples = [
|
||||
[
|
||||
'lastName' => 'Depardieu',
|
||||
'firstName' => 'Gérard',
|
||||
'birthdate' => '1948-12-27',
|
||||
'placeOfBirth' => 'Châteauroux',
|
||||
'nationality' => 'RU',
|
||||
'gender' => Person::MALE_GENDER,
|
||||
'center' => 'Center A',
|
||||
@@ -420,73 +116,73 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
'from' => '2015-02-01',
|
||||
'to' => '2015-10-30',
|
||||
'remark' => 'oops',
|
||||
],[
|
||||
], [
|
||||
'from' => '2017-06-01',
|
||||
'to' => '2018-03-30',
|
||||
'remark' => 'argg',
|
||||
],[
|
||||
], [
|
||||
'from' => '2019-01-01',
|
||||
'to' => '2019-12-31',
|
||||
'remark' => 'blob',
|
||||
]
|
||||
]
|
||||
),
|
||||
array(
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
//to have a person with same firstname as Gérard Depardieu
|
||||
'lastName' => "Depardieu",
|
||||
'firstName' => "Jean",
|
||||
'birthdate' => "1960-10-12",
|
||||
'lastName' => 'Depardieu',
|
||||
'firstName' => 'Jean',
|
||||
'birthdate' => '1960-10-12',
|
||||
'countryOfBirth' => 'FR',
|
||||
'nationality' => 'FR',
|
||||
'center' => 'Center A',
|
||||
'maritalStatus' => 'ms_divorce'
|
||||
),
|
||||
array(
|
||||
'maritalStatus' => 'ms_divorce',
|
||||
],
|
||||
[
|
||||
//to have a person with same birthdate of Gérard Depardieu
|
||||
'lastName' => 'Van Snick',
|
||||
'firstName' => 'Bart',
|
||||
'birthdate' => '1948-12-27',
|
||||
'center' => 'Center A',
|
||||
'maritalStatus' => 'ms_legalco'
|
||||
),
|
||||
array(
|
||||
'maritalStatus' => 'ms_legalco',
|
||||
],
|
||||
[
|
||||
//to have a woman with Depardieu as FirstName
|
||||
'lastName' => 'Depardieu',
|
||||
'firstName' => 'Charline',
|
||||
'gender' => Person::FEMALE_GENDER,
|
||||
'center' => 'Center A',
|
||||
'maritalStatus' => 'ms_legalco'
|
||||
),
|
||||
array(
|
||||
'maritalStatus' => 'ms_legalco',
|
||||
],
|
||||
[
|
||||
//to have a special character in lastName
|
||||
'lastName' => 'Manço',
|
||||
'firstName' => 'Étienne',
|
||||
'center' => 'Center A',
|
||||
'maritalStatus' => 'ms_unknown'
|
||||
),
|
||||
array(
|
||||
'maritalStatus' => 'ms_unknown',
|
||||
],
|
||||
[
|
||||
//to have true duplicate person
|
||||
'lastName' => "Depardieu",
|
||||
'firstName' => "Jean",
|
||||
'birthdate' => "1960-10-12",
|
||||
'lastName' => 'Depardieu',
|
||||
'firstName' => 'Jean',
|
||||
'birthdate' => '1960-10-12',
|
||||
'countryOfBirth' => 'FR',
|
||||
'nationality' => 'FR',
|
||||
'center' => 'Center A',
|
||||
'maritalStatus' => 'ms_divorce'
|
||||
),
|
||||
array(
|
||||
'maritalStatus' => 'ms_divorce',
|
||||
],
|
||||
[
|
||||
//to have false duplicate person
|
||||
'lastName' => "Depardieu",
|
||||
'firstName' => "Jeanne",
|
||||
'birthdate' => "1966-11-13",
|
||||
'lastName' => 'Depardieu',
|
||||
'firstName' => 'Jeanne',
|
||||
'birthdate' => '1966-11-13',
|
||||
'countryOfBirth' => 'FR',
|
||||
'nationality' => 'FR',
|
||||
'center' => 'Center A',
|
||||
'maritalStatus' => 'ms_legalco'
|
||||
),
|
||||
'maritalStatus' => 'ms_legalco',
|
||||
],
|
||||
[
|
||||
'lastName' => 'Diallo',
|
||||
'firstName' => "Fatoumata Binta"
|
||||
'firstName' => 'Fatoumata Binta',
|
||||
],
|
||||
[
|
||||
'lastName' => 'Diallo',
|
||||
@@ -510,7 +206,7 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
],
|
||||
[
|
||||
'lastName' => 'Bah',
|
||||
'firstName' => "Fatoumata Binta"
|
||||
'firstName' => 'Fatoumata Binta',
|
||||
],
|
||||
[
|
||||
'lastName' => 'Bah',
|
||||
@@ -540,24 +236,320 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
'lastName' => 'Gaillot',
|
||||
'firstName' => 'Adèle',
|
||||
],
|
||||
);
|
||||
];
|
||||
|
||||
/*
|
||||
private function addAccompanyingPeriods(Person $person, array $periods, ObjectManager $manager)
|
||||
public function __construct(
|
||||
Registry $workflowRegistry,
|
||||
SocialIssueRepository $socialIssueRepository,
|
||||
CenterRepository $centerRepository,
|
||||
CountryRepository $countryRepository,
|
||||
MaritalStatusRepository $maritalStatusRepository,
|
||||
ScopeRepository $scopeRepository,
|
||||
UserRepository $userRepository
|
||||
) {
|
||||
$this->faker = Factory::create('fr_FR');
|
||||
$this->faker->addProvider($this);
|
||||
$this->workflowRegistry = $workflowRegistry;
|
||||
$this->socialIssueRepository = $socialIssueRepository;
|
||||
$this->centerRepository = $centerRepository;
|
||||
$this->countryRepository = $countryRepository;
|
||||
$this->maritalStatusRepository = $maritalStatusRepository;
|
||||
$this->loader = new NativeLoader($this->faker);
|
||||
$this->scopeRepository = $scopeRepository;
|
||||
$this->userRepository = $userRepository;
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
foreach ($periods as $period) {
|
||||
return 10000;
|
||||
}
|
||||
|
||||
echo "adding new past Accompanying Period..\n";
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
*/
|
||||
public function getRandomCenter(): Center
|
||||
{
|
||||
if (0 === count($this->cacheCenters)) {
|
||||
$this->cacheCenters = $this->centerRepository->findAll();
|
||||
}
|
||||
|
||||
/** @var AccompanyingPeriod $accompanyingPeriod
|
||||
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime($period['from']));
|
||||
$accompanyingPeriod
|
||||
->setClosingDate(new \DateTime($period['to']))
|
||||
->setRemark($period['remark'])
|
||||
;
|
||||
return $this->cacheCenters[\array_rand($this->cacheCenters)];
|
||||
}
|
||||
|
||||
$person->addAccompanyingPeriod($accompanyingPeriod);
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRandomCountry(int $nullPercentage = 20): ?Country
|
||||
{
|
||||
if (0 === count($this->cacheCountries)) {
|
||||
$this->cacheCountries = $this->countryRepository->findAll();
|
||||
}
|
||||
|
||||
if (random_int(0, 100) > $nullPercentage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->cacheCountries[\array_rand($this->cacheCountries)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
*/
|
||||
public function getRandomGender(): string
|
||||
{
|
||||
return $this->genders[array_rand($this->genders)];
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal This method is public and called by faker as a custom generator
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getRandomMaritalStatus(int $nullPercentage = 50): ?MaritalStatus
|
||||
{
|
||||
if (0 === count($this->cacheMaritalStatuses)) {
|
||||
$this->cacheMaritalStatuses = $this->maritalStatusRepository->findAll();
|
||||
}
|
||||
|
||||
if (random_int(0, 100) > $nullPercentage) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->cacheMaritalStatuses[array_rand($this->cacheMaritalStatuses)];
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
$this->loadExpectedPeople($manager);
|
||||
$this->loadRandPeople($manager);
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
public function loadExpectedPeople(ObjectManager $manager)
|
||||
{
|
||||
echo "loading expected people...\n";
|
||||
|
||||
foreach ($this->peoples as $personDef) {
|
||||
$person = $this->createExpectedPerson($personDef);
|
||||
$this->addAPerson($person, $manager);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
protected function loadRandPeople(ObjectManager $manager)
|
||||
{
|
||||
echo "loading rand people...\n";
|
||||
$persons = $this->createRandPerson()->getObjects();
|
||||
|
||||
foreach ($persons as $person) {
|
||||
$this->addAPerson($person, $manager);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* create a new person from array data.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
private function addAPerson(Person $person, ObjectManager $manager)
|
||||
{
|
||||
$accompanyingPeriod = new AccompanyingPeriod(
|
||||
(new DateTime())
|
||||
->sub(
|
||||
new DateInterval('P' . random_int(0, 180) . 'D')
|
||||
)
|
||||
);
|
||||
$accompanyingPeriod->setCreatedBy($this->getRandomUser())
|
||||
->setCreatedAt(new DateTimeImmutable('now'));
|
||||
$person->addAccompanyingPeriod($accompanyingPeriod);
|
||||
$accompanyingPeriod->addSocialIssue($this->getRandomSocialIssue());
|
||||
|
||||
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);
|
||||
$workflow->apply($accompanyingPeriod, 'confirm');
|
||||
}
|
||||
|
||||
$manager->persist($person);
|
||||
$manager->persist($accompanyingPeriod);
|
||||
echo "add person'" . $person->__toString() . "'\n";
|
||||
|
||||
$this->addReference(self::PERSON . $person->getId(), $person);
|
||||
}
|
||||
|
||||
private function createAddress(): Address
|
||||
{
|
||||
$objectSet = $this->loader->loadData([
|
||||
Address::class => [
|
||||
'address' => [
|
||||
'street' => '<fr_FR:streetName()>',
|
||||
'streetNumber' => '<fr_FR:buildingNumber()>',
|
||||
'validFrom' => '<dateTimeBetween(\'-1 year\', \'now\')>',
|
||||
'postCode' => $this->getPostalCode(),
|
||||
],
|
||||
],
|
||||
]);
|
||||
|
||||
return $objectSet->getObjects()['address'];
|
||||
}
|
||||
|
||||
private function createExpectedPerson($default): Person
|
||||
{
|
||||
$person = $this->loader->loadData([
|
||||
Person::class => [
|
||||
'person' => [
|
||||
'firstName' => $default['firstName'] ?? '<firstname()>',
|
||||
'lastName' => $default['lastName'] ?? '<lastname()>',
|
||||
'gender' => '<getRandomGender()>',
|
||||
'nationality' => '<getRandomCountry()>',
|
||||
'center' => '<getRandomCenter()>',
|
||||
'maritalStatus' => '<getRandomMaritalStatus()>',
|
||||
'birthdate' => '<dateTimeBetween("-75 years", "-1 tears")>',
|
||||
'placeOfBirth' => '<city()>',
|
||||
'email' => '<freeEmail()>',
|
||||
'countryOfBirth' => '<getRandomCountry(80)>',
|
||||
],
|
||||
],
|
||||
])->getObjects()['person'];
|
||||
|
||||
// force some values
|
||||
foreach ($default as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'birthdate':
|
||||
$person->setBirthdate(new DateTime($value));
|
||||
|
||||
break;
|
||||
|
||||
case 'center':
|
||||
$person->setCenter($this->centerRepository
|
||||
->findOneBy(['name' => $value]));
|
||||
|
||||
break;
|
||||
|
||||
case 'countryOfBirth':
|
||||
case 'nationality':
|
||||
$country = $this->countryRepository
|
||||
->findOneBy(['countryCode' => $value]);
|
||||
$person->{'set' . ucfirst($key)}($country);
|
||||
|
||||
break;
|
||||
|
||||
case 'maritalStatus':
|
||||
$person->setMaritalStatus($this->maritalStatusRepository
|
||||
->find($value));
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
private function createRandPerson(): ObjectSet
|
||||
{
|
||||
return $this->loader->loadData([
|
||||
Person::class => [
|
||||
'persons{1..300}' => [
|
||||
'firstName' => '<firstname()>',
|
||||
'lastName' => '<lastname()>',
|
||||
'gender' => '<getRandomGender()>',
|
||||
'nationality' => '<getRandomCountry()>',
|
||||
'center' => '<getRandomCenter()>',
|
||||
'maritalStatus' => '<getRandomMaritalStatus()>',
|
||||
'birthdate' => '<dateTimeBetween("-75 years", "-1 tears")>',
|
||||
'placeOfBirth' => '<city()>',
|
||||
'email' => '<freeEmail()>',
|
||||
'countryOfBirth' => '<getRandomCountry(80)>',
|
||||
],
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
private function getPostalCode(): PostalCode
|
||||
{
|
||||
$ref = LoadPostalCodes::$refs[\array_rand(LoadPostalCodes::$refs)];
|
||||
|
||||
return $this->getReference($ref);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a random address.
|
||||
*
|
||||
* @return Address
|
||||
*/
|
||||
private function getRandomAddress()
|
||||
{
|
||||
return (new Address())
|
||||
->setStreetAddress1($this->faker->streetAddress)
|
||||
->setStreetAddress2(
|
||||
rand(0, 9) > 5 ? $this->faker->streetAddress : ''
|
||||
)
|
||||
->setPoint(
|
||||
rand(0, 9) > 5 ? $this->getRandomPoint() : null
|
||||
)
|
||||
->setPostcode($this->getReference(
|
||||
LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)]
|
||||
))
|
||||
->setValidFrom($this->faker->dateTimeBetween('-5 years'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a random point.
|
||||
*
|
||||
* @return Point
|
||||
*/
|
||||
private function getRandomPoint()
|
||||
{
|
||||
$lonBrussels = 4.35243;
|
||||
$latBrussels = 50.84676;
|
||||
$lon = $lonBrussels + 0.01 * rand(-5, 5);
|
||||
$lat = $latBrussels + 0.01 * rand(-5, 5);
|
||||
|
||||
return Point::fromLonLat($lon, $lat);
|
||||
}
|
||||
|
||||
private function getRandomSocialIssue(): SocialIssue
|
||||
{
|
||||
if (0 === count($this->cacheSocialIssues)) {
|
||||
$this->cacheSocialIssues = $this->socialIssueRepository->findAll();
|
||||
}
|
||||
|
||||
return $this->cacheSocialIssues[\array_rand($this->cacheSocialIssues)];
|
||||
}
|
||||
|
||||
private function getRandomUser(): User
|
||||
{
|
||||
if (0 === count($this->cacheUsers)) {
|
||||
$this->cacheUsers = $this->userRepository->findAll();
|
||||
}
|
||||
|
||||
return $this->cacheUsers[\array_rand($this->cacheUsers)];
|
||||
}
|
||||
|
||||
/*
|
||||
private function addAccompanyingPeriods(Person $person, array $periods, ObjectManager $manager)
|
||||
{
|
||||
foreach ($periods as $period) {
|
||||
|
||||
echo "adding new past Accompanying Period..\n";
|
||||
|
||||
/** @var AccompanyingPeriod $accompanyingPeriod
|
||||
$accompanyingPeriod = new AccompanyingPeriod(new \DateTime($period['from']));
|
||||
$accompanyingPeriod
|
||||
->setClosingDate(new \DateTime($period['to']))
|
||||
->setRemark($period['remark'])
|
||||
;
|
||||
|
||||
$person->addAccompanyingPeriod($accompanyingPeriod);
|
||||
}
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
@@ -1,37 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (C) 2015 Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
|
||||
use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadPermissionsGroup;
|
||||
use Chill\MainBundle\Entity\RoleScope;
|
||||
use Chill\PersonBundle\Security\Authorization\PersonVoter;
|
||||
use Chill\PersonBundle\Security\Authorization\AccompanyingPeriodVoter;
|
||||
|
||||
/**
|
||||
* Add a role CHILL_PERSON_UPDATE & CHILL_PERSON_CREATE for all groups except administrative,
|
||||
* and a role CHILL_PERSON_SEE for administrative
|
||||
*
|
||||
* @author Julien Fastré <julien.fastre@champs-libres.coop>
|
||||
* and a role CHILL_PERSON_SEE for administrative.
|
||||
*/
|
||||
class LoadPersonACL extends AbstractFixture implements OrderedFixtureInterface
|
||||
{
|
||||
@@ -40,7 +28,6 @@ class LoadPersonACL extends AbstractFixture implements OrderedFixtureInterface
|
||||
return 9600;
|
||||
}
|
||||
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
|
||||
@@ -60,13 +47,13 @@ class LoadPersonACL extends AbstractFixture implements OrderedFixtureInterface
|
||||
);
|
||||
|
||||
$roleScopeUpdate = (new RoleScope())
|
||||
->setRole('CHILL_PERSON_UPDATE')
|
||||
->setScope(null);
|
||||
->setRole('CHILL_PERSON_UPDATE')
|
||||
->setScope(null);
|
||||
$permissionsGroup->addRoleScope($roleScopeUpdate);
|
||||
|
||||
$roleScopeCreate = (new RoleScope())
|
||||
->setRole('CHILL_PERSON_CREATE')
|
||||
->setScope(null);
|
||||
->setRole('CHILL_PERSON_CREATE')
|
||||
->setScope(null);
|
||||
$permissionsGroup->addRoleScope($roleScopeCreate);
|
||||
|
||||
$roleScopeDuplicate = (new RoleScope())
|
||||
@@ -75,13 +62,13 @@ class LoadPersonACL extends AbstractFixture implements OrderedFixtureInterface
|
||||
$permissionsGroup->addRoleScope($roleScopeDuplicate);
|
||||
|
||||
$roleScopeList = (new RoleScope())
|
||||
->setRole(PersonVoter::LISTS)
|
||||
->setScope(null);
|
||||
->setRole(PersonVoter::LISTS)
|
||||
->setScope(null);
|
||||
$permissionsGroup->addRoleScope($roleScopeList);
|
||||
|
||||
$roleScopeStats = (new RoleScope())
|
||||
->setRole(PersonVoter::STATS)
|
||||
->setScope(null);
|
||||
->setRole(PersonVoter::STATS)
|
||||
->setScope(null);
|
||||
$permissionsGroup->addRoleScope($roleScopeStats);
|
||||
|
||||
$manager->persist($roleScopeUpdate);
|
||||
@@ -89,19 +76,19 @@ class LoadPersonACL extends AbstractFixture implements OrderedFixtureInterface
|
||||
$manager->persist($roleScopeDuplicate);
|
||||
|
||||
break;
|
||||
|
||||
case 'administrative':
|
||||
printf("Adding CHILL_PERSON_SEE to %s permission group \n", $permissionsGroup->getName());
|
||||
$roleScopeSee = (new RoleScope())
|
||||
->setRole('CHILL_PERSON_SEE')
|
||||
->setScope(null);
|
||||
->setRole('CHILL_PERSON_SEE')
|
||||
->setScope(null);
|
||||
$permissionsGroup->addRoleScope($roleScopeSee);
|
||||
$manager->persist($roleScopeSee);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
@@ -10,8 +18,9 @@ use Doctrine\Persistence\ObjectManager;
|
||||
|
||||
class LoadRelations extends Fixture implements FixtureGroupInterface
|
||||
{
|
||||
public const RELATION_KEY = 'relations';
|
||||
public const RELATIONS = [
|
||||
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']],
|
||||
@@ -38,17 +47,16 @@ class LoadRelations extends Fixture implements FixtureGroupInterface
|
||||
|
||||
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";
|
||||
foreach (self::RELATIONS as $key => $value) {
|
||||
echo '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);
|
||||
$this->addReference(self::RELATION_KEY . $key, $relation);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -1,4 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
@@ -6,15 +14,17 @@ namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use Chill\PersonBundle\DataFixtures\Helper\PersonRandomHelper;
|
||||
use Chill\PersonBundle\Entity\Relationships\Relationship;
|
||||
use DateTimeImmutable;
|
||||
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)
|
||||
@@ -26,26 +36,25 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
|
||||
{
|
||||
return [
|
||||
LoadPeople::class,
|
||||
LoadRelations::class
|
||||
LoadRelations::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function load(ObjectManager $manager)
|
||||
{
|
||||
for ($i = 0; $i < 15; $i++) {
|
||||
for ($i = 0; 15 > $i; ++$i) {
|
||||
$user = $this->getRandomUser();
|
||||
$date = new \DateTimeImmutable();
|
||||
$date = new DateTimeImmutable();
|
||||
$relationship = (new Relationship())
|
||||
->setFromPerson($this->getRandomPerson($this->em))
|
||||
->setToPerson($this->getRandomPerson($this->em))
|
||||
->setRelation($this->getReference(LoadRelations::RELATION_KEY.
|
||||
->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)
|
||||
;
|
||||
->setUpdatedAt($date);
|
||||
$manager->persist($relationship);
|
||||
}
|
||||
|
||||
@@ -55,6 +64,7 @@ class LoadRelationships extends Fixture implements DependentFixtureInterface
|
||||
private function getRandomUser(): User
|
||||
{
|
||||
$userRef = array_rand(LoadUsers::$refs);
|
||||
|
||||
return $this->getReference($userRef);
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,12 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Chill\PersonBundle\DataFixtures\ORM;
|
||||
@@ -8,7 +15,9 @@ use Chill\PersonBundle\Service\Import\SocialWorkMetadata;
|
||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
||||
use Doctrine\Persistence\ObjectManager;
|
||||
use Exception;
|
||||
use League\Csv\Reader;
|
||||
use Throwable;
|
||||
|
||||
class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface
|
||||
{
|
||||
@@ -19,21 +28,21 @@ class LoadSocialWorkMetadata extends Fixture implements OrderedFixtureInterface
|
||||
$this->importer = $importer;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$csv->setDelimiter(";");
|
||||
|
||||
$this->importer->import($csv);
|
||||
}
|
||||
|
||||
public function getOrder()
|
||||
{
|
||||
return 9500;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$csv->setDelimiter(';');
|
||||
|
||||
$this->importer->import($csv);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user