diff --git a/DataFixtures/ORM/LoadMaritalStatus.php b/DataFixtures/ORM/LoadMaritalStatus.php
new file mode 100644
index 000000000..7369d677b
--- /dev/null
+++ b/DataFixtures/ORM/LoadMaritalStatus.php
@@ -0,0 +1,66 @@
+
+ *
+ * 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 .
+ */
+
+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
+ */
+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();
+ }
+}
diff --git a/DataFixtures/ORM/LoadPeople.php b/DataFixtures/ORM/LoadPeople.php
index e607078ad..fedff5a4d 100644
--- a/DataFixtures/ORM/LoadPeople.php
+++ b/DataFixtures/ORM/LoadPeople.php
@@ -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'
)
);
}
diff --git a/Entity/MaritalStatus.php b/Entity/MaritalStatus.php
new file mode 100644
index 000000000..83bad2cbf
--- /dev/null
+++ b/Entity/MaritalStatus.php
@@ -0,0 +1,82 @@
+
+ *
+ * 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 .
+ */
+
+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;
+ }
+}
diff --git a/Entity/Person.php b/Entity/Person.php
index e34c4adee..2ce0986a1 100644
--- a/Entity/Person.php
+++ b/Entity/Person.php
@@ -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
*
diff --git a/Resources/config/doctrine/MaritalStatus.orm.yml b/Resources/config/doctrine/MaritalStatus.orm.yml
new file mode 100644
index 000000000..112463c43
--- /dev/null
+++ b/Resources/config/doctrine/MaritalStatus.orm.yml
@@ -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: { }
\ No newline at end of file
diff --git a/Resources/config/doctrine/Person.orm.yml b/Resources/config/doctrine/Person.orm.yml
index 73de33a38..e51644ecc 100644
--- a/Resources/config/doctrine/Person.orm.yml
+++ b/Resources/config/doctrine/Person.orm.yml
@@ -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
diff --git a/Resources/migrations/Version20150812110708.php b/Resources/migrations/Version20150812110708.php
new file mode 100644
index 000000000..b7dc7729f
--- /dev/null
+++ b/Resources/migrations/Version20150812110708.php
@@ -0,0 +1,63 @@
+,
+ *
+ * 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 .
+ */
+
+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;');
+ }
+}