14ccf2a72SGreg Roach<?php 24ccf2a72SGreg Roach/** 34ccf2a72SGreg Roach * webtrees: online genealogy 44ccf2a72SGreg Roach * Copyright (C) 2015 webtrees development team 54ccf2a72SGreg Roach * This program is free software: you can redistribute it and/or modify 64ccf2a72SGreg Roach * it under the terms of the GNU General Public License as published by 74ccf2a72SGreg Roach * the Free Software Foundation, either version 3 of the License, or 84ccf2a72SGreg Roach * (at your option) any later version. 94ccf2a72SGreg Roach * This program is distributed in the hope that it will be useful, 104ccf2a72SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 114ccf2a72SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 124ccf2a72SGreg Roach * GNU General Public License for more details. 134ccf2a72SGreg Roach * You should have received a copy of the GNU General Public License 144ccf2a72SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 154ccf2a72SGreg Roach */ 164ccf2a72SGreg Roachnamespace Fisharebest\Webtrees\Census; 174ccf2a72SGreg Roach 184ccf2a72SGreg Roachuse Fisharebest\Webtrees\Date; 19*40150762SGreg Roachuse Fisharebest\Webtrees\Individual; 204ccf2a72SGreg Roach 214ccf2a72SGreg Roach/** 224ccf2a72SGreg Roach * Definitions for a census column 234ccf2a72SGreg Roach */ 244ccf2a72SGreg Roachclass AbstractCensusColumn { 25ef21b467SGreg Roach /** @var CensusInterface */ 26ef21b467SGreg Roach private $census; 27ef21b467SGreg Roach 28ef21b467SGreg Roach /** @var string */ 29ef21b467SGreg Roach private $abbr; 30ef21b467SGreg Roach 31ef21b467SGreg Roach /** @var string */ 32ef21b467SGreg Roach private $title; 334ccf2a72SGreg Roach 344ccf2a72SGreg Roach /** 35db7d25eeSGreg Roach * Create a column for a census 364ccf2a72SGreg Roach * 37ef21b467SGreg Roach * @param CensusInterface $census - The census to which this column forms part. 38ef21b467SGreg Roach * @param string $abbr - The abbrievated on-screen name "BiC" 39ef21b467SGreg Roach * @param string $title - The full column heading "Born in the county" 404ccf2a72SGreg Roach */ 41ef21b467SGreg Roach public function __construct(CensusInterface $census, $abbr, $title) { 42db7d25eeSGreg Roach $this->census = $census; 43ef21b467SGreg Roach $this->abbr = $abbr; 44ef21b467SGreg Roach $this->title = $title; 45ef21b467SGreg Roach } 46ef21b467SGreg Roach 47ef21b467SGreg Roach /** 48ef21b467SGreg Roach * A short version of the column's name. 49ef21b467SGreg Roach * 50ef21b467SGreg Roach * @return string 51ef21b467SGreg Roach */ 52ef21b467SGreg Roach public function abbreviation() { 53ef21b467SGreg Roach return $this->abbr; 54db7d25eeSGreg Roach } 55db7d25eeSGreg Roach 56db7d25eeSGreg Roach /** 57*40150762SGreg Roach * Extract the country (last part) of a place name. 58*40150762SGreg Roach * 59*40150762SGreg Roach * @param string $place - e.g. "London, England" 60*40150762SGreg Roach * 61*40150762SGreg Roach * @return string - e.g. "England" 62*40150762SGreg Roach */ 63*40150762SGreg Roach protected function country($place) { 64*40150762SGreg Roach $place = explode(', ', $place); 65*40150762SGreg Roach 66*40150762SGreg Roach return end($place); 67*40150762SGreg Roach } 68*40150762SGreg Roach 69*40150762SGreg Roach /** 70db7d25eeSGreg Roach * When did this census occur 71db7d25eeSGreg Roach * 72db7d25eeSGreg Roach * @return Date 73db7d25eeSGreg Roach */ 74db7d25eeSGreg Roach public function date() { 75db7d25eeSGreg Roach return new Date($this->census->censusDate()); 76db7d25eeSGreg Roach } 77db7d25eeSGreg Roach 78db7d25eeSGreg Roach /** 79*40150762SGreg Roach * Find the father of an individual 80*40150762SGreg Roach * 81*40150762SGreg Roach * @return Individual|null $individual 82*40150762SGreg Roach */ 83*40150762SGreg Roach public function father(Individual $individual) { 84*40150762SGreg Roach $family = $individual->getPrimaryChildFamily(); 85*40150762SGreg Roach 86*40150762SGreg Roach if ($family) { 87*40150762SGreg Roach return $family->getHusband(); 88*40150762SGreg Roach } else { 89*40150762SGreg Roach return null; 90*40150762SGreg Roach } 91*40150762SGreg Roach } 92*40150762SGreg Roach 93*40150762SGreg Roach /** 94*40150762SGreg Roach * Find the mother of an individual 95*40150762SGreg Roach * 96*40150762SGreg Roach * @return Individual|null $individual 97*40150762SGreg Roach */ 98*40150762SGreg Roach public function mother(Individual $individual) { 99*40150762SGreg Roach $family = $individual->getPrimaryChildFamily(); 100*40150762SGreg Roach 101*40150762SGreg Roach if ($family) { 102*40150762SGreg Roach return $family->getWife(); 103*40150762SGreg Roach } else { 104*40150762SGreg Roach return null; 105*40150762SGreg Roach } 106*40150762SGreg Roach } 107*40150762SGreg Roach 108*40150762SGreg Roach /** 109db7d25eeSGreg Roach * Where did this census occur 110db7d25eeSGreg Roach * 111ef21b467SGreg Roach * @return string 112db7d25eeSGreg Roach */ 113db7d25eeSGreg Roach public function place() { 114db7d25eeSGreg Roach return $this->census->censusPlace(); 1154ccf2a72SGreg Roach } 116ef21b467SGreg Roach 117ef21b467SGreg Roach /** 118ef21b467SGreg Roach * The full version of the column's name. 119ef21b467SGreg Roach * 120ef21b467SGreg Roach * @return string 121ef21b467SGreg Roach */ 122ef21b467SGreg Roach public function title() { 123ef21b467SGreg Roach return $this->title; 124ef21b467SGreg Roach } 1254ccf2a72SGreg Roach} 126