mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 21:34:25 +00:00
Adding MaritalStatus in db
This commit is contained in:
parent
31e734f2c7
commit
3f9f58030c
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'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
82
Entity/MaritalStatus.php
Normal file
82
Entity/MaritalStatus.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* Copyright (C) 2014-2015, 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\Entity;
|
||||
|
||||
/**
|
||||
* MaritalStatus
|
||||
*/
|
||||
class MaritalStatus
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $id;
|
||||
|
||||
/**
|
||||
* @var string array
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set id
|
||||
*
|
||||
* @param string $id
|
||||
* @return MaritalStatus
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name
|
||||
*
|
||||
* @param string array $name
|
||||
* @return MaritalStatus
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get name
|
||||
*
|
||||
* @return string array
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
}
|
@ -46,10 +46,10 @@ class Person implements HasCenterInterface {
|
||||
/** @var string The person's place of birth */
|
||||
private $placeOfBirth = '';
|
||||
|
||||
/** @var \CL\Chill\MainBundle\Entity\Country The person's country of birth */
|
||||
/** @var \Chill\MainBundle\Entity\Country The person's country of birth */
|
||||
private $countryOfBirth;
|
||||
|
||||
/** @var \CL\Chill\MainBundle\Entity\Country The person's nationality */
|
||||
/** @var \Chill\MainBundle\Entity\Country The person's nationality */
|
||||
private $nationality;
|
||||
|
||||
/** @var string The person's gender */
|
||||
@ -58,7 +58,8 @@ class Person implements HasCenterInterface {
|
||||
const MALE_GENDER = 'man';
|
||||
const FEMALE_GENDER = 'woman';
|
||||
|
||||
//TO-ADD : maritalStatus
|
||||
/** @var \Chill\PersonBundle\Entity\MaritalStatus The marital status of the person */
|
||||
private $maritalStatus;
|
||||
|
||||
//TO-ADD : address
|
||||
|
||||
@ -395,6 +396,29 @@ class Person implements HasCenterInterface {
|
||||
return $this->memo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set maritalStatus
|
||||
*
|
||||
* @param \Chill\PersonBundle\Entity\MaritalStatus $maritalStatus
|
||||
* @return Person
|
||||
*/
|
||||
public function setMaritalStatus($maritalStatus)
|
||||
{
|
||||
$this->maritalStatus = $maritalStatus;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get maritalStatus
|
||||
*
|
||||
* @return \Chill\PersonBundle\Entity\MaritalStatus
|
||||
*/
|
||||
public function getMaritalStatus()
|
||||
{
|
||||
return $this->maritalStatus;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set email
|
||||
*
|
||||
|
11
Resources/config/doctrine/MaritalStatus.orm.yml
Normal file
11
Resources/config/doctrine/MaritalStatus.orm.yml
Normal file
@ -0,0 +1,11 @@
|
||||
Chill\PersonBundle\Entity\MaritalStatus:
|
||||
table: marital_status
|
||||
type: entity
|
||||
id:
|
||||
id:
|
||||
type: string
|
||||
length: 7
|
||||
fields:
|
||||
name:
|
||||
type: json_array
|
||||
lifecycleCallbacks: { }
|
@ -53,6 +53,8 @@ Chill\PersonBundle\Entity\Person:
|
||||
center:
|
||||
targetEntity: Chill\MainBundle\Entity\Center
|
||||
nullable: false
|
||||
maritalStatus:
|
||||
targetEntity: Chill\PersonBundle\Entity\maritalStatus
|
||||
oneToMany:
|
||||
accompanyingPeriods:
|
||||
targetEntity: AccompanyingPeriod
|
||||
|
63
Resources/migrations/Version20150812110708.php
Normal file
63
Resources/migrations/Version20150812110708.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?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 Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration;
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Migration for adding maritalstatus to person
|
||||
*/
|
||||
class Version20150812110708 extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function up(Schema $schema)
|
||||
{
|
||||
$this->abortIf(
|
||||
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
|
||||
'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('CREATE TABLE marital_status (
|
||||
id character varying(10) NOT NULL,
|
||||
name json NOT NULL,
|
||||
CONSTRAINT marital_status_pkey PRIMARY KEY (id));');
|
||||
$this->addSql('ALTER TABLE person ADD COLUMN maritalstatus_id character varying(10)');
|
||||
$this->addSql('ALTER TABLE person ADD CONSTRAINT fk_person_marital_status FOREIGN KEY (maritalstatus_id) REFERENCES marital_status (id) MATCH SIMPLE ON UPDATE NO ACTION ON DELETE NO ACTION');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Schema $schema
|
||||
*/
|
||||
public function down(Schema $schema)
|
||||
{
|
||||
$this->abortIf(
|
||||
$this->connection->getDatabasePlatform()->getName() != 'postgresql',
|
||||
'Migration can only be executed safely on \'postgresql\'.');
|
||||
|
||||
$this->addSql('ALTER TABLE person DROP CONSTRAINT fk_person_marital_status;');
|
||||
$this->addSql('ALTER TABLE person DROP COLUMN maritalstatus_id;');
|
||||
$this->addSql('DROP TABLE marital_status;');
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user