fix folder name

This commit is contained in:
2021-03-18 13:37:13 +01:00
parent a2f6773f5a
commit eaa0ad925f
1578 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
<?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/>.
*/
namespace Chill\PersonBundle\DataFixtures\ORM;
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>
*/
class LoadAccompanyingPeriodClosingMotive extends AbstractFixture
implements OrderedFixtureInterface
{
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)
{
foreach (static::$closingMotives as $ref => $new) {
$motive = new ClosingMotive();
$motive->setName($new['name'])
->setActive((isset($new['active']) ? $new['active'] : true))
;
$manager->persist($motive);
$this->addReference($ref, $motive);
echo "Adding ClosingMotive $ref\n";
}
$manager->flush();
}
}

View File

@@ -0,0 +1,229 @@
<?php
/*
* Copyright (C) 2017 Champs Libres Cooperative <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/>.
*/
namespace Chill\PersonBundle\DataFixtures\ORM;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
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,
ContainerAwareInterface
{
/**
*
* @var ContainerInterface
*/
private $container;
/**
*
* @var CustomField
*/
private $customFieldText;
/**
*
* @var CustomField
*/
private $customFieldChoice;
/**
* @var TranslatableStringHelper
*/
private $translatableStringHelper;
/**
* @var TranslatorInterface
*/
private $translator;
/**
* LoadCustomFields constructor.
*
* @param TranslatableStringHelper $translatableStringHelper
* @param TranslatorInterface $translator
*/
public function __construct(
TranslatableStringHelper $translatableStringHelper,
TranslatorInterface $translator
) {
$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)
{
$this->loadFields($manager);
$this->loadData($manager);
$manager->flush();
}
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(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)
));
}
}
}
private function createCustomFieldText()
{
return new CustomFieldText(
$this->container->get('request_stack'),
$this->container->get('templating'),
$this->translatableStringHelper
);
}
private function createCustomFieldChoice()
{
return new CustomFieldChoice(
$this->translator,
$this->container->get('templating'),
$this->translatableStringHelper
);
}
private function loadFields(ObjectManager $manager)
{
$cfGroup = (new CustomFieldsGroup())
->setEntity(Person::class)
->setName(array("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")
->setOrdering(10)
->setType('title')
->setOptions(array(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")
->setOrdering(20)
->setType('text')
->setOptions(array('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")
->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"
)
)
))
;
$manager->persist($this->customFieldChoice);
}
}

View File

@@ -0,0 +1,66 @@
<?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/>.
*/
namespace Chill\PersonBundle\DataFixtures\ORM;
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>
*/
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é']]
];
public function getOrder()
{
return 9999;
}
public function load(ObjectManager $manager)
{
echo "loading maritalStatuses... \n";
foreach ($this->maritalStatuses as $ms) {
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);
$manager->persist($new_ms);
}
$manager->flush();
}
}

View File

@@ -0,0 +1,326 @@
<?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/>.
*/
namespace Chill\PersonBundle\DataFixtures\ORM;
use Doctrine\Common\DataFixtures\AbstractFixture;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Chill\PersonBundle\Entity\Person;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
use Chill\MainBundle\Entity\Address;
/**
* Load people into database
*
* @author Julien Fastré <julien arobase fastre point info>
* @author Marc Ducobu <marc@champs-libres.coop>
*/
class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
protected $faker;
public function __construct()
{
$this->faker = \Faker\Factory::create('fr_FR');
}
public function prepare()
{
//prepare days, month, years
$y = 1950;
do {
$this->years[] = $y;
$y = $y +1;
} while ($y >= 1990);
$m = 1;
do {
$this->month[] = $m;
$m = $m +1;
} while ($m >= 12);
$d = 1;
do {
$this->day[] = $d;
$d = $d + 1;
} while ($d <= 28);
}
public function getOrder()
{
return 10000;
}
public function load(ObjectManager $manager)
{
$this->loadRandPeople($manager);
$this->loadExpectedPeople($manager);
$manager->flush();
}
public function loadExpectedPeople(ObjectManager $manager)
{
echo "loading expected people...\n";
foreach ($this->peoples as $person) {
$this->addAPerson($this->fillWithDefault($person), $manager);
}
}
public function loadRandPeople(ObjectManager $manager)
{
echo "loading rand people...\n";
$this->prepare();
$chooseLastNameOrTri = array('tri', 'tri', 'name', 'tri');
$i = 0;
do {
$i++;
$sex = $this->genders[array_rand($this->genders)];
if ($chooseLastNameOrTri[array_rand($chooseLastNameOrTri)] === 'tri' ) {
$length = rand(2, 3);
$lastName = '';
for ($j = 0; $j <= $length; $j++) {
$lastName .= $this->lastNamesTrigrams[array_rand($this->lastNamesTrigrams)];
}
$lastName = ucfirst($lastName);
} else {
$lastName = $this->lastNames[array_rand($this->lastNames)];
}
if ($sex === Person::MALE_GENDER) {
$firstName = $this->firstNamesMale[array_rand($this->firstNamesMale)];
} else {
$firstName = $this->firstNamesFemale[array_rand($this->firstNamesFemale)];
}
// add an address on 80% of the created people
if (rand(0,100) < 80) {
$address = $this->getRandomAddress();
// on 30% of those person, add multiple addresses
if (rand(0,10) < 4) {
$address = array(
$address,
$this->getRandomAddress()
);
}
} else {
$address = null;
}
$person = array(
'FirstName' => $firstName,
'LastName' => $lastName,
'Gender' => $sex,
'Nationality' => (rand(0,100) > 50) ? NULL: 'BE',
'center' => (rand(0,1) == 0) ? 'centerA': 'centerB',
'Address' => $address,
'maritalStatus' => $this->maritalStatusRef[array_rand($this->maritalStatusRef)]
);
$this->addAPerson($this->fillWithDefault($person), $manager);
} while ($i <= 100);
}
/**
* fill a person array with default value
*
* @param string[] $specific
*/
private function fillWithDefault(array $specific)
{
return array_merge(array(
'Birthdate' => "1960-10-12",
'PlaceOfBirth' => "Ottignies Louvain-La-Neuve",
'Gender' => Person::MALE_GENDER,
'Email' => "Email d'un ami: roger@tt.com",
'CountryOfBirth' => 'BE',
'Nationality' => 'BE',
'CFData' => array(),
'Address' => null
), $specific);
}
/**
* create a new person from array data
*
* @param array $person
* @param ObjectManager $manager
* @throws \Exception
*/
private function addAPerson(array $person, ObjectManager $manager)
{
$p = new Person();
foreach ($person as $key => $value) {
switch ($key) {
case 'CountryOfBirth':
case 'Nationality':
$value = $this->getCountry($value);
break;
case 'Birthdate':
$value = new \DateTime($value);
break;
case 'center':
case 'maritalStatus':
$value = $this->getReference($value);
break;
}
//try to add the data using the setSomething function,
// if not possible, fallback to addSomething function
if (method_exists($p, 'set'.$key)) {
call_user_func(array($p, 'set'.$key), $value);
} elseif (method_exists($p, 'add'.$key)) {
// if we have a "addSomething", we may have multiple items to add
// so, we set the value in an array if it is not an array, and
// will call the function addSomething multiple times
if (!is_array($value)) {
$value = array($value);
}
foreach($value as $v) {
if ($v !== NULL) {
call_user_func(array($p, 'add'.$key), $v);
}
}
}
}
$manager->persist($p);
echo "add person'".$p->__toString()."'\n";
}
/**
* Creata a random address
*
* @return Address
*/
private function getRandomAddress()
{
return (new Address())
->setStreetAddress1($this->faker->streetAddress)
->setStreetAddress2(
rand(0,9) > 5 ? $this->faker->streetAddress : ''
)
->setPostcode($this->getReference(
LoadPostalCodes::$refs[array_rand(LoadPostalCodes::$refs)]
))
->setValidFrom($this->faker->dateTimeBetween('-5 years'))
;
}
private function getCountry($countryCode)
{
if ($countryCode === NULL) {
return NULL;
}
return $this->container->get('doctrine.orm.entity_manager')
->getRepository('ChillMainBundle:Country')
->findOneByCountryCode($countryCode);
}
private $maritalStatusRef = ['ms_single', 'ms_married', 'ms_widow', 'ms_separat',
'ms_divorce', 'ms_legalco', 'ms_unknown'];
private $firstNamesMale = array("Jean", "Mohamed", "Alfred", "Robert",
"Compère", "Jean-de-Dieu",
"Charles", "Pierre", "Luc", "Mathieu", "Alain", "Etienne", "Eric",
"Corentin", "Gaston", "Spirou", "Fantasio", "Mahmadou", "Mohamidou",
"Vursuv" );
private $firstNamesFemale = array("Svedana", "Sevlatina","Irène", "Marcelle",
"Corentine", "Alfonsine","Caroline","Solange","Gostine", "Fatoumata",
"Groseille", "Chana", "Oxana", "Ivana");
private $lastNames = array("Diallo", "Bah", "Gaillot");
private $lastNamesTrigrams = array("fas", "tré", "hu", 'blart', 'van', 'der', 'lin', 'den',
'ta', 'mi', 'gna', 'bol', 'sac', 'ré', 'jo', 'du', 'pont', 'cas', 'tor', 'rob', 'al',
'ma', 'gone', 'car',"fu", "ka", "lot", "no", "va", "du", "bu", "su",
"lo", 'to', "cho", "car", 'mo','zu', 'qi', 'mu');
private $genders = array(Person::MALE_GENDER, Person::FEMALE_GENDER);
private $years = array();
private $month = array();
private $day = array();
private $peoples = array(
array(
'FirstName' => "Depardieu",
'LastName' => "Gérard",
'Birthdate' => "1948-12-27",
'PlaceOfBirth' => "Châteauroux",
'Gender' => Person::MALE_GENDER,
'CountryOfBirth' => 'FR',
'Nationality' => 'RU',
'center' => 'centerA',
'maritalStatus' => 'ms_divorce'
),
array(
//to have a person with same firstname as Gérard Depardieu
'FirstName' => "Depardieu",
'LastName' => "Jean",
'Birthdate' => "1960-10-12",
'CountryOfBirth' => 'FR',
'Nationality' => 'FR',
'center' => 'centerA',
'maritalStatus' => 'ms_divorce'
),
array(
//to have a person with same birthdate of Gérard Depardieu
'FirstName' => 'Van Snick',
'LastName' => 'Bart',
'Birthdate' => '1948-12-27',
'center' => 'centerA',
'maritalStatus' => 'ms_legalco'
),
array(
//to have a woman with Depardieu as FirstName
'FirstName' => 'Depardieu',
'LastName' => 'Charline',
'Gender' => Person::FEMALE_GENDER,
'center' => 'centerA',
'maritalStatus' => 'ms_legalco'
),
array(
//to have a special character in lastName
'FirstName' => 'Manço',
'LastName' => 'Étienne',
'center' => 'centerA',
'maritalStatus' => 'ms_unknown'
)
);
}

View File

@@ -0,0 +1,87 @@
<?php
/*
* Copyright (C) 2015 Julien Fastré <julien.fastre@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/>.
*/
namespace Chill\PersonBundle\DataFixtures\ORM;
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;
/**
* 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>
*/
class LoadPersonACL extends AbstractFixture implements OrderedFixtureInterface
{
public function getOrder()
{
return 9600;
}
public function load(ObjectManager $manager)
{
foreach (LoadPermissionsGroup::$refs as $permissionsGroupRef) {
$permissionsGroup = $this->getReference($permissionsGroupRef);
//create permission group
switch ($permissionsGroup->getName()) {
case 'social':
case 'direction':
printf("Adding CHILL_PERSON_UPDATE & CHILL_PERSON_CREATE to %s permission group \n", $permissionsGroup->getName());
$roleScopeUpdate = (new RoleScope())
->setRole('CHILL_PERSON_UPDATE')
->setScope(null);
$permissionsGroup->addRoleScope($roleScopeUpdate);
$roleScopeCreate = (new RoleScope())
->setRole('CHILL_PERSON_CREATE')
->setScope(null);
$permissionsGroup->addRoleScope($roleScopeCreate);
$roleScopeList = (new RoleScope())
->setRole(PersonVoter::LISTS)
->setScope(null);
$permissionsGroup->addRoleScope($roleScopeList);
$roleScopeStats = (new RoleScope())
->setRole(PersonVoter::STATS)
->setScope(null);
$permissionsGroup->addRoleScope($roleScopeStats);
$manager->persist($roleScopeUpdate);
$manager->persist($roleScopeCreate);
break;
case 'administrative':
printf("Adding CHILL_PERSON_SEE to %s permission group \n", $permissionsGroup->getName());
$roleScopeSee = (new RoleScope())
->setRole('CHILL_PERSON_SEE')
->setScope(null);
$permissionsGroup->addRoleScope($roleScopeSee);
$manager->persist($roleScopeSee);
break;
}
}
$manager->flush();
}
}