1ef21b467SGreg Roach<?php 23976b470SGreg Roach 3ef21b467SGreg Roach/** 4ef21b467SGreg Roach * webtrees: online genealogy 5d11be702SGreg Roach * Copyright (C) 2023 webtrees development team 6ef21b467SGreg Roach * This program is free software: you can redistribute it and/or modify 7ef21b467SGreg Roach * it under the terms of the GNU General Public License as published by 8ef21b467SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9ef21b467SGreg Roach * (at your option) any later version. 10ef21b467SGreg Roach * This program is distributed in the hope that it will be useful, 11ef21b467SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12ef21b467SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13ef21b467SGreg Roach * GNU General Public License for more details. 14ef21b467SGreg Roach * You should have received a copy of the GNU General Public License 1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>. 16ef21b467SGreg Roach */ 17fcfa147eSGreg Roach 18e7f56f2aSGreg Roachdeclare(strict_types=1); 1915d603e7SGreg Roach 20ef21b467SGreg Roachnamespace Fisharebest\Webtrees\Census; 21ef21b467SGreg Roach 2240150762SGreg Roachuse Fisharebest\Webtrees\Date; 23ef21b467SGreg Roachuse Fisharebest\Webtrees\Individual; 24ef21b467SGreg Roach 25ef21b467SGreg Roach/** 26ef21b467SGreg Roach * The nationality of the individual. 27ef21b467SGreg Roach */ 28c1010edaSGreg Roachclass CensusColumnNationality extends AbstractCensusColumn implements CensusColumnInterface 29c1010edaSGreg Roach{ 3088ca476bSGreg Roach // Convert a country name to a nationality 31e364afe4SGreg Roach private const NATIONALITIES = [ 3252f14e58SGreg Roach 'England' => 'British', 3352f14e58SGreg Roach 'Scotland' => 'British', 3452f14e58SGreg Roach 'Wales' => 'British', 3552f14e58SGreg Roach 'Deutschland' => 'Deutsch', 36*f71a4582Smanf0001 'Canada' => 'Canadian', 3713abd6f3SGreg Roach ]; 3852f14e58SGreg Roach 39ef21b467SGreg Roach /** 40ef21b467SGreg Roach * Generate the likely value of this census column, based on available information. 41ef21b467SGreg Roach * 42ef21b467SGreg Roach * @param Individual $individual 4315d603e7SGreg Roach * @param Individual $head 44ef21b467SGreg Roach * 45ef21b467SGreg Roach * @return string 46ef21b467SGreg Roach */ 475a62e0a6SGreg Roach public function generate(Individual $individual, Individual $head): string 48c1010edaSGreg Roach { 49392561bbSGreg Roach $place = $individual->getBirthPlace()->gedcomName(); 50ef21b467SGreg Roach 5152f14e58SGreg Roach // No birthplace? Assume born in the same country. 5252f14e58SGreg Roach if ($place === '') { 5352f14e58SGreg Roach $place = $this->place(); 5452f14e58SGreg Roach } 5552f14e58SGreg Roach 56ef21b467SGreg Roach // Did we emigrate or naturalise? 578d0ebef0SGreg Roach foreach ($individual->facts(['IMMI', 'EMIG', 'NATU'], true) as $fact) { 582decada7SGreg Roach if (Date::compare($fact->date(), $this->date()) <= 0) { 59392561bbSGreg Roach $place = $fact->place()->gedcomName(); 60ef21b467SGreg Roach } 61ef21b467SGreg Roach } 62ef21b467SGreg Roach 6352f14e58SGreg Roach $place = $this->lastPartOfPlace($place); 64ef21b467SGreg Roach 65e364afe4SGreg Roach return self::NATIONALITIES[$place] ?? $place; 66ef21b467SGreg Roach } 67ef21b467SGreg Roach} 68