summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Census/AbstractCensusColumn.php34
-rw-r--r--app/Census/CensusColumnCondition.php14
-rw-r--r--app/Census/CensusColumnConditionDanish.php17
-rw-r--r--app/Census/CensusColumnDateOfBirth.php35
-rw-r--r--app/Census/CensusOfDenmark1901.php2
-rw-r--r--app/Census/CensusOfDenmark1906.php2
-rw-r--r--app/Census/CensusOfDenmark1911.php2
-rw-r--r--app/Census/CensusOfDenmark1916.php2
-rw-r--r--app/Census/CensusOfDenmark1921.php2
-rw-r--r--app/Census/CensusOfDenmark1925.php2
-rw-r--r--app/Census/CensusOfDenmark1930.php2
-rw-r--r--app/Census/CensusOfDenmark1940.php2
-rw-r--r--app/Census/CensusOfDenmark1950.php2
-rw-r--r--tests/app/Census/CensusColumnConditionDanishTest.php2
-rw-r--r--tests/app/Census/CensusColumnDateOfBirthTest.php50
15 files changed, 153 insertions, 17 deletions
diff --git a/app/Census/AbstractCensusColumn.php b/app/Census/AbstractCensusColumn.php
index a1c8c5c93d..26afd7046b 100644
--- a/app/Census/AbstractCensusColumn.php
+++ b/app/Census/AbstractCensusColumn.php
@@ -16,6 +16,7 @@
namespace Fisharebest\Webtrees\Census;
use Fisharebest\Webtrees\Date;
+use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Individual;
/**
@@ -78,7 +79,9 @@ class AbstractCensusColumn {
/**
* Find the father of an individual
*
- * @return Individual $individual
+ * @param Individual $individual
+ *
+ * @return Individual|null
*/
public function father(Individual $individual) {
$family = $individual->getPrimaryChildFamily();
@@ -93,7 +96,9 @@ class AbstractCensusColumn {
/**
* Find the mother of an individual
*
- * @return Individual $individual
+ * @param Individual $individual
+ *
+ * @return Individual|null
*/
public function mother(Individual $individual) {
$family = $individual->getPrimaryChildFamily();
@@ -132,6 +137,31 @@ class AbstractCensusColumn {
}
/**
+ * Find the current spouse family of an individual
+ *
+ * @param Individual $individual
+ *
+ * @return Family|null
+ */
+ public function spouseFamily(Individual $individual) {
+ // Exclude families that were created after this census date
+ $families = array();
+ foreach ($individual->getSpouseFamilies() as $family) {
+ if (Date::compare($family->getMarriageDate(), $this->date()) <= 0) {
+ $families[] = $family;
+ }
+ }
+
+ if (empty($families)) {
+ return null;
+ } else {
+ usort($families, function(Family $x, Family $y) { return Date::compare($x->getMarriageDate(), $y->getMarriageDate()); });
+
+ return end($families);
+ }
+ }
+
+ /**
* The full version of the column's name.
*
* @return string
diff --git a/app/Census/CensusColumnCondition.php b/app/Census/CensusColumnCondition.php
index 9f756e8168..46d05315b8 100644
--- a/app/Census/CensusColumnCondition.php
+++ b/app/Census/CensusColumnCondition.php
@@ -29,6 +29,18 @@ class CensusColumnCondition extends AbstractCensusColumn implements CensusColumn
* @return string
*/
public function generate(Individual $individual) {
- return '';
+ $family = $this->spouseFamily($individual);
+
+ if ($family === null) {
+ return 'Unm'; // unmarried
+ } else {
+ if (empty($family->getFacts('_NMR'))) {
+ return 'Unm'; // unmarried
+ } elseif (empty($family->getFacts('DIV'))) {
+ return 'Div'; // divorced
+ } else {
+ return 'Mar'; // married
+ }
+ }
}
}
diff --git a/app/Census/CensusColumnConditionDanish.php b/app/Census/CensusColumnConditionDanish.php
index e387d91fbc..7523c31af8 100644
--- a/app/Census/CensusColumnConditionDanish.php
+++ b/app/Census/CensusColumnConditionDanish.php
@@ -29,9 +29,18 @@ class CensusColumnConditionDanish extends AbstractCensusColumn implements Census
* @return string
*/
public function generate(Individual $individual) {
- // G = married
- // U = unmarried
- // S = separated or divorced
- return '';
+ $family = $this->spouseFamily($individual);
+
+ if ($family === null) {
+ return 'Ugift'; // unmarried
+ } else {
+ if (empty($family->getFacts('_NMR'))) {
+ return 'Ugift'; // unmarried
+ } elseif (empty($family->getFacts('DIV'))) {
+ return 'Ugift'; // unmarried
+ } else {
+ return 'Gift'; // married
+ }
+ }
}
}
diff --git a/app/Census/CensusColumnDateOfBirth.php b/app/Census/CensusColumnDateOfBirth.php
new file mode 100644
index 0000000000..6ed1bf332a
--- /dev/null
+++ b/app/Census/CensusColumnDateOfBirth.php
@@ -0,0 +1,35 @@
+<?php
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2015 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+namespace Fisharebest\Webtrees\Census;
+
+use Fisharebest\Webtrees\Date;
+use Fisharebest\Webtrees\Individual;
+
+/**
+ * The individual's date of birth.
+ */
+class CensusColumnDateOfBirth extends AbstractCensusColumn implements CensusColumnInterface {
+ /**
+ * Generate the likely value of this census column, based on available information.
+ *
+ * @param Individual $individual
+ *
+ * @return string
+ */
+ public function generate(Individual $individual) {
+ return $individual->getEstimatedBirthDate()->display(false, null, false);
+ }
+}
diff --git a/app/Census/CensusOfDenmark1901.php b/app/Census/CensusOfDenmark1901.php
index 3bddf915de..342b702f87 100644
--- a/app/Census/CensusOfDenmark1901.php
+++ b/app/Census/CensusOfDenmark1901.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1901 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/app/Census/CensusOfDenmark1906.php b/app/Census/CensusOfDenmark1906.php
index 50e2454453..0bcaa2be95 100644
--- a/app/Census/CensusOfDenmark1906.php
+++ b/app/Census/CensusOfDenmark1906.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1906 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/app/Census/CensusOfDenmark1911.php b/app/Census/CensusOfDenmark1911.php
index b7bebc4b83..51e7ae76c6 100644
--- a/app/Census/CensusOfDenmark1911.php
+++ b/app/Census/CensusOfDenmark1911.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1911 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/app/Census/CensusOfDenmark1916.php b/app/Census/CensusOfDenmark1916.php
index 089af5c730..0b6bd5ce9b 100644
--- a/app/Census/CensusOfDenmark1916.php
+++ b/app/Census/CensusOfDenmark1916.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1916 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/app/Census/CensusOfDenmark1921.php b/app/Census/CensusOfDenmark1921.php
index 3a1e428ee5..f44f7b2708 100644
--- a/app/Census/CensusOfDenmark1921.php
+++ b/app/Census/CensusOfDenmark1921.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1921 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/app/Census/CensusOfDenmark1925.php b/app/Census/CensusOfDenmark1925.php
index cf3c2e98b8..8739867199 100644
--- a/app/Census/CensusOfDenmark1925.php
+++ b/app/Census/CensusOfDenmark1925.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1925 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/app/Census/CensusOfDenmark1930.php b/app/Census/CensusOfDenmark1930.php
index 2215a4dc9e..8b7676878c 100644
--- a/app/Census/CensusOfDenmark1930.php
+++ b/app/Census/CensusOfDenmark1930.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1930 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/app/Census/CensusOfDenmark1940.php b/app/Census/CensusOfDenmark1940.php
index 738dfbf727..bee9422315 100644
--- a/app/Census/CensusOfDenmark1940.php
+++ b/app/Census/CensusOfDenmark1940.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1940 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/app/Census/CensusOfDenmark1950.php b/app/Census/CensusOfDenmark1950.php
index 4c74ccea06..373b354cc0 100644
--- a/app/Census/CensusOfDenmark1950.php
+++ b/app/Census/CensusOfDenmark1950.php
@@ -38,7 +38,7 @@ class CensusOfDenmark1950 extends CensusOfDenmark implements CensusInterface {
public function columns() {
return array(
new CensusColumnFullName($this, 'TBC', 'To be confirmed'),
- new CensusColumnAge($this, 'TBC', 'To be confirmed'),
+ new CensusColumnDateOfBirth($this, 'TBC', 'To be confirmed'),
new CensusColumnSexMF($this, 'TBC', 'To be confirmed'),
new CensusColumnCondition($this, 'TBC', 'To be confirmed'),
new CensusColumnRelationToHead($this, 'TBC', 'To be confirmed'),
diff --git a/tests/app/Census/CensusColumnConditionDanishTest.php b/tests/app/Census/CensusColumnConditionDanishTest.php
index 6b7e7c6bce..c7163481a7 100644
--- a/tests/app/Census/CensusColumnConditionDanishTest.php
+++ b/tests/app/Census/CensusColumnConditionDanishTest.php
@@ -41,7 +41,7 @@ class CensusColumnConditionDanishTest extends \PHPUnit_Framework_TestCase {
$census = Mockery::mock(CensusInterface::class);
- $column = new CensusColumnCondition($census, '', '');
+ $column = new CensusColumnConditionDnish($census, '', '');
$this->assertSame('', $column->generate($individual));
}
diff --git a/tests/app/Census/CensusColumnDateOfBirthTest.php b/tests/app/Census/CensusColumnDateOfBirthTest.php
new file mode 100644
index 0000000000..dfc75a0e78
--- /dev/null
+++ b/tests/app/Census/CensusColumnDateOfBirthTest.php
@@ -0,0 +1,50 @@
+<?php
+
+/**
+ * webtrees: online genealogy
+ * Copyright (C) 2015 webtrees development team
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU 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 General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+namespace Fisharebest\Webtrees\Census;
+
+use Fisharebest\Webtrees\Date;
+use Fisharebest\Webtrees\Individual;
+use Mockery;
+
+/**
+ * Test harness for the class CensusColumnAge
+ */
+class CensusColumnDateOfBirthTest extends \PHPUnit_Framework_TestCase {
+ /**
+ * Delete mock objects
+ */
+ public function tearDown() {
+ Mockery::close();
+ }
+
+ /**
+ * @covers Fisharebest\Webtrees\Census\CensusColumnAge
+ * @covers Fisharebest\Webtrees\Census\AbstractCensusColumn
+ */
+ public function testGenerateColumn() {
+ $individual = Mockery::mock(Individual::class);
+ $individual->shouldReceive('getEstimatedBirthDate')->andReturn(new Date('01 JAN 1800'));
+
+ $census = Mockery::mock(CensusInterface::class);
+ $census->shouldReceive('censusDate')->andReturn('30 JUN 1832');
+
+ $column = new CensusColumnDateOfBirth($census, '', '');
+
+ $this->assertSame('32', $column->generate($individual));
+ }
+}