100225b98SGreg Roach<?php 200225b98SGreg Roach/** 300225b98SGreg Roach * webtrees: online genealogy 4*8fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team 500225b98SGreg Roach * This program is free software: you can redistribute it and/or modify 600225b98SGreg Roach * it under the terms of the GNU General Public License as published by 700225b98SGreg Roach * the Free Software Foundation, either version 3 of the License, or 800225b98SGreg Roach * (at your option) any later version. 900225b98SGreg Roach * This program is distributed in the hope that it will be useful, 1000225b98SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 1100225b98SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1200225b98SGreg Roach * GNU General Public License for more details. 1300225b98SGreg Roach * You should have received a copy of the GNU General Public License 1400225b98SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 1500225b98SGreg Roach */ 16e7f56f2aSGreg Roachdeclare(strict_types=1); 1715d603e7SGreg Roach 1800225b98SGreg Roachnamespace Fisharebest\Webtrees\Census; 1900225b98SGreg Roach 2000225b98SGreg Roachuse Fisharebest\Webtrees\Date; 2100225b98SGreg Roachuse Fisharebest\Webtrees\Individual; 2200225b98SGreg Roach 2300225b98SGreg Roach/** 2400225b98SGreg Roach * Marital status. 2500225b98SGreg Roach */ 26c1010edaSGreg Roachabstract class AbstractCensusColumnCondition extends AbstractCensusColumn implements CensusColumnInterface 27c1010edaSGreg Roach{ 28cfe766afSGreg Roach /** @var string Text to display for married males */ 2900225b98SGreg Roach protected $husband = ''; 300a921d1eSGreg Roach 31cfe766afSGreg Roach /** @var string Text to display for married females */ 3200225b98SGreg Roach protected $wife = ''; 3300225b98SGreg Roach 34cfe766afSGreg Roach /** @var string Text to display for unmarried males */ 3500225b98SGreg Roach protected $bachelor = ''; 360a921d1eSGreg Roach 37cfe766afSGreg Roach /** @var string Text to display for unmarried females */ 3800225b98SGreg Roach protected $spinster = ''; 3900225b98SGreg Roach 40cfe766afSGreg Roach /** @var string Text to display for male children */ 4100225b98SGreg Roach protected $boy = ''; 420a921d1eSGreg Roach 43cfe766afSGreg Roach /** @var string Text to display for female children */ 4400225b98SGreg Roach protected $girl = ''; 4500225b98SGreg Roach 46cfe766afSGreg Roach /** @var string Text to display for divorced males */ 4700225b98SGreg Roach protected $divorce = ''; 480a921d1eSGreg Roach 49cfe766afSGreg Roach /** @var string Text to display for divorced females */ 5000225b98SGreg Roach protected $divorcee = ''; 5100225b98SGreg Roach 52cfe766afSGreg Roach /** @var string Text to display for widowed males */ 5300225b98SGreg Roach protected $widower = ''; 540a921d1eSGreg Roach 55cfe766afSGreg Roach /** @var string Text to display for widowed females */ 5600225b98SGreg Roach protected $widow = ''; 5700225b98SGreg Roach 58cfe766afSGreg Roach /** @var int At what age is this individual recorded as an adult */ 5900225b98SGreg Roach protected $age_adult = 15; 6000225b98SGreg Roach 6100225b98SGreg Roach /** 6200225b98SGreg Roach * Generate the likely value of this census column, based on available information. 6300225b98SGreg Roach * 6400225b98SGreg Roach * @param Individual $individual 6515d603e7SGreg Roach * @param Individual $head 6600225b98SGreg Roach * 6700225b98SGreg Roach * @return string 6800225b98SGreg Roach */ 695a62e0a6SGreg Roach public function generate(Individual $individual, Individual $head): string 70c1010edaSGreg Roach { 7100225b98SGreg Roach $family = $this->spouseFamily($individual); 7200225b98SGreg Roach $sex = $individual->getSex(); 7300225b98SGreg Roach 748d0ebef0SGreg Roach if ($family === null || count($family->facts(['MARR'])) === 0) { 7500225b98SGreg Roach if ($this->isChild($individual)) { 7600225b98SGreg Roach return $this->conditionChild($sex); 77b2ce94c6SRico Sonntag } 78b2ce94c6SRico Sonntag 7900225b98SGreg Roach return $this->conditionSingle($sex); 8000225b98SGreg Roach } 81b2ce94c6SRico Sonntag 828d0ebef0SGreg Roach if (count($family->facts(['DIV'])) > 0) { 8300225b98SGreg Roach return $this->conditionDivorced($sex); 84b2ce94c6SRico Sonntag } 85b2ce94c6SRico Sonntag 86e76c0cf0SGreg Roach $spouse = $family->getSpouse($individual); 87e76c0cf0SGreg Roach if ($spouse instanceof Individual && $this->isDead($spouse)) { 88e76c0cf0SGreg Roach return $this->conditionWidowed($sex); 89b2ce94c6SRico Sonntag } 90b2ce94c6SRico Sonntag 9100225b98SGreg Roach return $this->conditionMarried($sex); 9200225b98SGreg Roach } 9300225b98SGreg Roach 9400225b98SGreg Roach /** 9515d603e7SGreg Roach * Is the individual a child. 9615d603e7SGreg Roach * 9715d603e7SGreg Roach * @param Individual $individual 9815d603e7SGreg Roach * 9915d603e7SGreg Roach * @return bool 10015d603e7SGreg Roach */ 1018f53f488SRico Sonntag private function isChild(Individual $individual): bool 102c1010edaSGreg Roach { 1038fe32d0dSGreg Roach $age = Date::getAgeYears($individual->getEstimatedBirthDate(), $this->date()); 10415d603e7SGreg Roach 10515d603e7SGreg Roach return $age < $this->age_adult; 10615d603e7SGreg Roach } 10715d603e7SGreg Roach 10815d603e7SGreg Roach /** 10900225b98SGreg Roach * How is this condition written in a census column. 11000225b98SGreg Roach * 11107902ed6SScrutinizer Auto-Fixer * @param string $sex 11200225b98SGreg Roach * 11300225b98SGreg Roach * @return string 11400225b98SGreg Roach */ 115c1010edaSGreg Roach private function conditionChild($sex) 116c1010edaSGreg Roach { 11700225b98SGreg Roach if ($sex === 'F') { 11800225b98SGreg Roach return $this->girl; 11900225b98SGreg Roach } 120b2ce94c6SRico Sonntag 121b2ce94c6SRico Sonntag return $this->boy; 12200225b98SGreg Roach } 12300225b98SGreg Roach 12400225b98SGreg Roach /** 12500225b98SGreg Roach * How is this condition written in a census column. 12600225b98SGreg Roach * 12707902ed6SScrutinizer Auto-Fixer * @param string $sex 12800225b98SGreg Roach * 12900225b98SGreg Roach * @return string 13000225b98SGreg Roach */ 131c1010edaSGreg Roach private function conditionSingle($sex) 132c1010edaSGreg Roach { 13300225b98SGreg Roach if ($sex === 'F') { 13400225b98SGreg Roach return $this->spinster; 13500225b98SGreg Roach } 136b2ce94c6SRico Sonntag 137b2ce94c6SRico Sonntag return $this->bachelor; 13800225b98SGreg Roach } 13900225b98SGreg Roach 14000225b98SGreg Roach /** 141e76c0cf0SGreg Roach * How is this condition written in a census column. 142e76c0cf0SGreg Roach * 14307902ed6SScrutinizer Auto-Fixer * @param string $sex 144e76c0cf0SGreg Roach * 145e76c0cf0SGreg Roach * @return string 146e76c0cf0SGreg Roach */ 147c1010edaSGreg Roach private function conditionDivorced($sex) 148c1010edaSGreg Roach { 149e76c0cf0SGreg Roach if ($sex === 'F') { 15015d603e7SGreg Roach return $this->divorcee; 151e76c0cf0SGreg Roach } 152b2ce94c6SRico Sonntag 153b2ce94c6SRico Sonntag return $this->divorce; 154e76c0cf0SGreg Roach } 155e76c0cf0SGreg Roach 156e76c0cf0SGreg Roach /** 157e76c0cf0SGreg Roach * Is the individual dead. 158e76c0cf0SGreg Roach * 159e76c0cf0SGreg Roach * @param Individual $individual 160e76c0cf0SGreg Roach * 161e76c0cf0SGreg Roach * @return bool 162e76c0cf0SGreg Roach */ 1638f53f488SRico Sonntag private function isDead(Individual $individual): bool 164c1010edaSGreg Roach { 165fef3019cSGreg Roach return $individual->getDeathDate()->isOK() && Date::compare($individual->getDeathDate(), $this->date()) < 0; 166e76c0cf0SGreg Roach } 16715d603e7SGreg Roach 16815d603e7SGreg Roach /** 16915d603e7SGreg Roach * How is this condition written in a census column. 17015d603e7SGreg Roach * 17115d603e7SGreg Roach * @param string $sex 17215d603e7SGreg Roach * 17315d603e7SGreg Roach * @return string 17415d603e7SGreg Roach */ 175c1010edaSGreg Roach private function conditionWidowed($sex) 176c1010edaSGreg Roach { 17715d603e7SGreg Roach if ($sex === 'F') { 17815d603e7SGreg Roach return $this->widow; 17915d603e7SGreg Roach } 180b2ce94c6SRico Sonntag 181b2ce94c6SRico Sonntag return $this->widower; 18215d603e7SGreg Roach } 18315d603e7SGreg Roach 18415d603e7SGreg Roach /** 18515d603e7SGreg Roach * How is this condition written in a census column. 18615d603e7SGreg Roach * 18715d603e7SGreg Roach * @param string $sex 18815d603e7SGreg Roach * 18915d603e7SGreg Roach * @return string 19015d603e7SGreg Roach */ 191c1010edaSGreg Roach private function conditionMarried($sex) 192c1010edaSGreg Roach { 19315d603e7SGreg Roach if ($sex === 'F') { 19415d603e7SGreg Roach return $this->wife; 19515d603e7SGreg Roach } 196b2ce94c6SRico Sonntag 197b2ce94c6SRico Sonntag return $this->husband; 19815d603e7SGreg Roach } 19900225b98SGreg Roach} 200