100225b98SGreg Roach<?php 200225b98SGreg Roach/** 300225b98SGreg Roach * webtrees: online genealogy 4*1062a142SGreg Roach * Copyright (C) 2018 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 */ 1615d603e7SGreg Roach 1700225b98SGreg Roachnamespace Fisharebest\Webtrees\Census; 1800225b98SGreg Roach 1900225b98SGreg Roachuse Fisharebest\Webtrees\Date; 2000225b98SGreg Roachuse Fisharebest\Webtrees\Individual; 2100225b98SGreg Roach 2200225b98SGreg Roach/** 2300225b98SGreg Roach * Marital status. 2400225b98SGreg Roach */ 2500225b98SGreg Roachabstract class AbstractCensusColumnCondition extends AbstractCensusColumn implements CensusColumnInterface { 260a921d1eSGreg Roach /* Text to display for married males */ 2700225b98SGreg Roach protected $husband = ''; 280a921d1eSGreg Roach 290a921d1eSGreg Roach /* Text to display for married females */ 3000225b98SGreg Roach protected $wife = ''; 3100225b98SGreg Roach 320a921d1eSGreg Roach /* Text to display for unmarried males */ 3300225b98SGreg Roach protected $bachelor = ''; 340a921d1eSGreg Roach 350a921d1eSGreg Roach /* Text to display for unmarried females */ 3600225b98SGreg Roach protected $spinster = ''; 3700225b98SGreg Roach 380a921d1eSGreg Roach /* Text to display for male children */ 3900225b98SGreg Roach protected $boy = ''; 400a921d1eSGreg Roach 410a921d1eSGreg Roach /* Text to display for female children */ 4200225b98SGreg Roach protected $girl = ''; 4300225b98SGreg Roach 440a921d1eSGreg Roach /* Text to display for divorced males */ 4500225b98SGreg Roach protected $divorce = ''; 460a921d1eSGreg Roach 470a921d1eSGreg Roach /* Text to display for divorced females */ 4800225b98SGreg Roach protected $divorcee = ''; 4900225b98SGreg Roach 500a921d1eSGreg Roach /* Text to display for widowed males */ 5100225b98SGreg Roach protected $widower = ''; 520a921d1eSGreg Roach 530a921d1eSGreg Roach /* Text to display for widowed females */ 5400225b98SGreg Roach protected $widow = ''; 5500225b98SGreg Roach 5600225b98SGreg Roach /* At what age is this individual recorded as an adult */ 5700225b98SGreg Roach protected $age_adult = 15; 5800225b98SGreg Roach 5900225b98SGreg Roach /** 6000225b98SGreg Roach * Generate the likely value of this census column, based on available information. 6100225b98SGreg Roach * 6200225b98SGreg Roach * @param Individual $individual 6315d603e7SGreg Roach * @param Individual $head 6400225b98SGreg Roach * 6500225b98SGreg Roach * @return string 6600225b98SGreg Roach */ 6700225b98SGreg Roach public function generate(Individual $individual, Individual $head = null) { 6800225b98SGreg Roach $family = $this->spouseFamily($individual); 6900225b98SGreg Roach $sex = $individual->getSex(); 7000225b98SGreg Roach 712a6fda60SGreg Roach if ($family === null || count($family->getFacts('MARR')) === 0) { 7200225b98SGreg Roach if ($this->isChild($individual)) { 7300225b98SGreg Roach return $this->conditionChild($sex); 7400225b98SGreg Roach } else { 7500225b98SGreg Roach return $this->conditionSingle($sex); 7600225b98SGreg Roach } 7700225b98SGreg Roach } elseif (count($family->getFacts('DIV')) > 0) { 7800225b98SGreg Roach return $this->conditionDivorced($sex); 7900225b98SGreg Roach } else { 80e76c0cf0SGreg Roach $spouse = $family->getSpouse($individual); 81e76c0cf0SGreg Roach if ($spouse instanceof Individual && $this->isDead($spouse)) { 82e76c0cf0SGreg Roach return $this->conditionWidowed($sex); 83e76c0cf0SGreg Roach } else { 8400225b98SGreg Roach return $this->conditionMarried($sex); 8500225b98SGreg Roach } 8600225b98SGreg Roach } 87e76c0cf0SGreg Roach } 8800225b98SGreg Roach 8900225b98SGreg Roach /** 9015d603e7SGreg Roach * Is the individual a child. 9115d603e7SGreg Roach * 9215d603e7SGreg Roach * @param Individual $individual 9315d603e7SGreg Roach * 9415d603e7SGreg Roach * @return bool 9515d603e7SGreg Roach */ 9615d603e7SGreg Roach private function isChild(Individual $individual) { 9715d603e7SGreg Roach $age = (int) Date::getAge($individual->getEstimatedBirthDate(), $this->date(), 0); 9815d603e7SGreg Roach 9915d603e7SGreg Roach return $age < $this->age_adult; 10015d603e7SGreg Roach } 10115d603e7SGreg Roach 10215d603e7SGreg Roach /** 10300225b98SGreg Roach * How is this condition written in a census column. 10400225b98SGreg Roach * 10507902ed6SScrutinizer Auto-Fixer * @param string $sex 10600225b98SGreg Roach * 10700225b98SGreg Roach * @return string 10800225b98SGreg Roach */ 10900225b98SGreg Roach private function conditionChild($sex) { 11000225b98SGreg Roach if ($sex === 'F') { 11100225b98SGreg Roach return $this->girl; 11200225b98SGreg Roach } else { 11300225b98SGreg Roach return $this->boy; 11400225b98SGreg Roach } 11500225b98SGreg Roach } 11600225b98SGreg Roach 11700225b98SGreg Roach /** 11800225b98SGreg Roach * How is this condition written in a census column. 11900225b98SGreg Roach * 12007902ed6SScrutinizer Auto-Fixer * @param string $sex 12100225b98SGreg Roach * 12200225b98SGreg Roach * @return string 12300225b98SGreg Roach */ 12400225b98SGreg Roach private function conditionSingle($sex) { 12500225b98SGreg Roach if ($sex === 'F') { 12600225b98SGreg Roach return $this->spinster; 12700225b98SGreg Roach } else { 12800225b98SGreg Roach return $this->bachelor; 12900225b98SGreg Roach } 13000225b98SGreg Roach } 13100225b98SGreg Roach 13200225b98SGreg Roach /** 133e76c0cf0SGreg Roach * How is this condition written in a census column. 134e76c0cf0SGreg Roach * 13507902ed6SScrutinizer Auto-Fixer * @param string $sex 136e76c0cf0SGreg Roach * 137e76c0cf0SGreg Roach * @return string 138e76c0cf0SGreg Roach */ 13915d603e7SGreg Roach private function conditionDivorced($sex) { 140e76c0cf0SGreg Roach if ($sex === 'F') { 14115d603e7SGreg Roach return $this->divorcee; 142e76c0cf0SGreg Roach } else { 14315d603e7SGreg Roach return $this->divorce; 144e76c0cf0SGreg Roach } 145e76c0cf0SGreg Roach } 146e76c0cf0SGreg Roach 147e76c0cf0SGreg Roach /** 148e76c0cf0SGreg Roach * Is the individual dead. 149e76c0cf0SGreg Roach * 150e76c0cf0SGreg Roach * @param Individual $individual 151e76c0cf0SGreg Roach * 152e76c0cf0SGreg Roach * @return bool 153e76c0cf0SGreg Roach */ 154e76c0cf0SGreg Roach private function isDead(Individual $individual) { 155fef3019cSGreg Roach return $individual->getDeathDate()->isOK() && Date::compare($individual->getDeathDate(), $this->date()) < 0; 156e76c0cf0SGreg Roach } 15715d603e7SGreg Roach 15815d603e7SGreg Roach /** 15915d603e7SGreg Roach * How is this condition written in a census column. 16015d603e7SGreg Roach * 16115d603e7SGreg Roach * @param string $sex 16215d603e7SGreg Roach * 16315d603e7SGreg Roach * @return string 16415d603e7SGreg Roach */ 16515d603e7SGreg Roach private function conditionWidowed($sex) { 16615d603e7SGreg Roach if ($sex === 'F') { 16715d603e7SGreg Roach return $this->widow; 16815d603e7SGreg Roach } else { 16915d603e7SGreg Roach return $this->widower; 17015d603e7SGreg Roach } 17115d603e7SGreg Roach } 17215d603e7SGreg Roach 17315d603e7SGreg Roach /** 17415d603e7SGreg Roach * How is this condition written in a census column. 17515d603e7SGreg Roach * 17615d603e7SGreg Roach * @param string $sex 17715d603e7SGreg Roach * 17815d603e7SGreg Roach * @return string 17915d603e7SGreg Roach */ 18015d603e7SGreg Roach private function conditionMarried($sex) { 18115d603e7SGreg Roach if ($sex === 'F') { 18215d603e7SGreg Roach return $this->wife; 18315d603e7SGreg Roach } else { 18415d603e7SGreg Roach return $this->husband; 18515d603e7SGreg Roach } 18615d603e7SGreg Roach } 18700225b98SGreg Roach} 188