1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2016 webtrees development team 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16namespace Fisharebest\Webtrees\Census; 17 18use Fisharebest\Webtrees\Date; 19use Fisharebest\Webtrees\Individual; 20 21/** 22 * Marital status. 23 */ 24abstract class AbstractCensusColumnCondition extends AbstractCensusColumn implements CensusColumnInterface { 25 /* Text to display for married individuals */ 26 protected $husband = ''; 27 protected $wife = ''; 28 29 /* Text to display for unmarried individuals */ 30 protected $bachelor = ''; 31 protected $spinster = ''; 32 33 /* Text to display for children */ 34 protected $boy = ''; 35 protected $girl = ''; 36 37 /* Text to display for divorced individuals */ 38 protected $divorce = ''; 39 protected $divorcee = ''; 40 41 /* Text to display for widowed individuals (not yet implemented) */ 42 protected $widower = ''; 43 protected $widow = ''; 44 45 /* At what age is this individual recorded as an adult */ 46 protected $age_adult = 15; 47 48 /** 49 * Generate the likely value of this census column, based on available information. 50 * 51 * @param Individual $individual 52 * @param Individual|null $head 53 * 54 * @return string 55 */ 56 public function generate(Individual $individual, Individual $head = null) { 57 $family = $this->spouseFamily($individual); 58 $sex = $individual->getSex(); 59 60 if ($family === null || count($family->getFacts('_NMR')) > 0) { 61 if ($this->isChild($individual)) { 62 return $this->conditionChild($sex); 63 } else { 64 return $this->conditionSingle($sex); 65 } 66 } elseif (count($family->getFacts('DIV')) > 0) { 67 return $this->conditionDivorced($sex); 68 } else { 69 return $this->conditionMarried($sex); 70 } 71 } 72 73 /** 74 * How is this condition written in a census column. 75 * 76 * @param $sex 77 * 78 * @return string 79 */ 80 private function conditionChild($sex) { 81 if ($sex === 'F') { 82 return $this->girl; 83 } else { 84 return $this->boy; 85 } 86 } 87 88 /** 89 * How is this condition written in a census column. 90 * 91 * @param $sex 92 * 93 * @return string 94 */ 95 private function conditionDivorced($sex) { 96 if ($sex === 'F') { 97 return $this->divorcee; 98 } else { 99 return $this->divorce; 100 } 101 } 102 103 /** 104 * How is this condition written in a census column. 105 * 106 * @param $sex 107 * 108 * @return string 109 */ 110 private function conditionMarried($sex) { 111 if ($sex === 'F') { 112 return $this->wife; 113 } else { 114 return $this->husband; 115 } 116 } 117 118 /** 119 * How is this condition written in a census column. 120 * 121 * @param $sex 122 * 123 * @return string 124 */ 125 private function conditionSingle($sex) { 126 if ($sex === 'F') { 127 return $this->spinster; 128 } else { 129 return $this->bachelor; 130 } 131 } 132 133 /** 134 * Is the individual a child. 135 * 136 * @param Individual $individual 137 * 138 * @return bool 139 */ 140 private function isChild(Individual $individual) { 141 $age = (int) Date::getAge($individual->getEstimatedBirthDate(), $this->date(), 0); 142 143 return $age < $this->age_adult; 144 } 145} 146