1<?php 2/** 3 * webtrees: online genealogy 4 * Copyright (C) 2015 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 * Definitions for a census column 23 */ 24class AbstractCensusColumn { 25 /** @var CensusInterface */ 26 private $census; 27 28 /** @var string */ 29 private $abbr; 30 31 /** @var string */ 32 private $title; 33 34 /** 35 * Create a column for a census 36 * 37 * @param CensusInterface $census - The census to which this column forms part. 38 * @param string $abbr - The abbrievated on-screen name "BiC" 39 * @param string $title - The full column heading "Born in the county" 40 */ 41 public function __construct(CensusInterface $census, $abbr, $title) { 42 $this->census = $census; 43 $this->abbr = $abbr; 44 $this->title = $title; 45 } 46 47 /** 48 * A short version of the column's name. 49 * 50 * @return string 51 */ 52 public function abbreviation() { 53 return $this->abbr; 54 } 55 56 /** 57 * Extract the country (last part) of a place name. 58 * 59 * @param string $place - e.g. "London, England" 60 * 61 * @return string - e.g. "England" 62 */ 63 protected function country($place) { 64 $place = explode(', ', $place); 65 66 return end($place); 67 } 68 69 /** 70 * When did this census occur 71 * 72 * @return Date 73 */ 74 public function date() { 75 return new Date($this->census->censusDate()); 76 } 77 78 /** 79 * Find the father of an individual 80 * 81 * @return Individual $individual 82 */ 83 public function father(Individual $individual) { 84 $family = $individual->getPrimaryChildFamily(); 85 86 if ($family) { 87 return $family->getHusband(); 88 } else { 89 return null; 90 } 91 } 92 93 /** 94 * Find the mother of an individual 95 * 96 * @return Individual $individual 97 */ 98 public function mother(Individual $individual) { 99 $family = $individual->getPrimaryChildFamily(); 100 101 if ($family) { 102 return $family->getWife(); 103 } else { 104 return null; 105 } 106 } 107 108 /** 109 * Remove the country of a place name, where it is the same as the census place 110 * 111 * @param string $place - e.g. "London, England" 112 * 113 * @return string - e.g. "London" (for census of England) and "London, England" elsewhere 114 */ 115 protected function notCountry($place) { 116 $parts = explode(', ', $place); 117 118 if (end($parts) === $this->place()) { 119 return implode(', ', array_slice($parts, 0, -1)); 120 } else { 121 return $place; 122 } 123 } 124 125 /** 126 * Where did this census occur 127 * 128 * @return string 129 */ 130 public function place() { 131 return $this->census->censusPlace(); 132 } 133 134 /** 135 * The full version of the column's name. 136 * 137 * @return string 138 */ 139 public function title() { 140 return $this->title; 141 } 142} 143