mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-28 18:43:49 +00:00
Adding MaritalStatus in db
This commit is contained in:
66
DataFixtures/ORM/LoadMaritalStatus.php
Normal file
66
DataFixtures/ORM/LoadMaritalStatus.php
Normal 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\Common\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();
|
||||
}
|
||||
}
|
@@ -119,7 +119,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
'LastName' => $lastName,
|
||||
'Gender' => $sex,
|
||||
'Nationality' => (rand(0,100) > 50) ? NULL: 'BE',
|
||||
'center' => (rand(0,1) == 0) ? 'centerA': 'centerB'
|
||||
'center' => (rand(0,1) == 0) ? 'centerA': 'centerB',
|
||||
'maritalStatus' => $this->maritalStatusRef[array_rand($this->maritalStatusRef)]
|
||||
);
|
||||
|
||||
$this->addAPerson($this->fillWithDefault($person), $manager);
|
||||
@@ -148,12 +149,10 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
private function addAPerson(array $person, ObjectManager $manager)
|
||||
{
|
||||
$p = new Person();
|
||||
|
||||
|
||||
foreach ($person as $key => $value) {
|
||||
switch ($key) {
|
||||
case 'CountryOfBirth':
|
||||
$value = $this->getCountry($value);
|
||||
break;
|
||||
case 'Nationality':
|
||||
$value = $this->getCountry($value);
|
||||
break;
|
||||
@@ -161,8 +160,9 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
$value = new \DateTime($value);
|
||||
break;
|
||||
case 'center':
|
||||
case 'maritalStatus':
|
||||
$value = $this->getReference($value);
|
||||
break;
|
||||
break;
|
||||
}
|
||||
call_user_func(array($p, 'set'.$key), $value);
|
||||
}
|
||||
@@ -180,11 +180,14 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
->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",
|
||||
"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",
|
||||
@@ -213,7 +216,8 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
'Gender' => Person::MALE_GENDER,
|
||||
'CountryOfBirth' => 'FR',
|
||||
'Nationality' => 'RU',
|
||||
'center' => 'centerA'
|
||||
'center' => 'centerA',
|
||||
'maritalStatus' => 'ms_divorce'
|
||||
),
|
||||
array(
|
||||
//to have a person with same firstname as Gérard Depardieu
|
||||
@@ -222,27 +226,31 @@ class LoadPeople extends AbstractFixture implements OrderedFixtureInterface, Con
|
||||
'Birthdate' => "1960-10-12",
|
||||
'CountryOfBirth' => 'FR',
|
||||
'Nationality' => 'FR',
|
||||
'center' => 'centerA'
|
||||
'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'
|
||||
'center' => 'centerA',
|
||||
'maritalStatus' => 'ms_legalco'
|
||||
),
|
||||
array(
|
||||
//to have a woman with Depardieu as FirstName
|
||||
'FirstName' => 'Depardieu',
|
||||
'LastName' => 'Charline',
|
||||
'Gender' => Person::FEMALE_GENDER,
|
||||
'center' => 'centerA'
|
||||
'center' => 'centerA',
|
||||
'maritalStatus' => 'ms_legalco'
|
||||
),
|
||||
array(
|
||||
//to have a special character in lastName
|
||||
'FirstName' => 'Manço',
|
||||
'LastName' => 'Étienne',
|
||||
'center' => 'centerA'
|
||||
'center' => 'centerA',
|
||||
'maritalStatus' => 'ms_unknown'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user