xref: /webtrees/app/Census/CensusColumnBornForeignParts.php (revision 3976b4703df669696105ed6b024b96d433c8fbdb)
1db7d25eeSGreg Roach<?php
2*3976b470SGreg Roach
3db7d25eeSGreg Roach/**
4db7d25eeSGreg Roach * webtrees: online genealogy
58fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
6db7d25eeSGreg Roach * This program is free software: you can redistribute it and/or modify
7db7d25eeSGreg Roach * it under the terms of the GNU General Public License as published by
8db7d25eeSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9db7d25eeSGreg Roach * (at your option) any later version.
10db7d25eeSGreg Roach * This program is distributed in the hope that it will be useful,
11db7d25eeSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12db7d25eeSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13db7d25eeSGreg Roach * GNU General Public License for more details.
14db7d25eeSGreg Roach * You should have received a copy of the GNU General Public License
15db7d25eeSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16db7d25eeSGreg Roach */
17e7f56f2aSGreg Roachdeclare(strict_types=1);
1815d603e7SGreg Roach
19db7d25eeSGreg Roachnamespace Fisharebest\Webtrees\Census;
20db7d25eeSGreg Roach
21db7d25eeSGreg Roachuse Fisharebest\Webtrees\Individual;
22db7d25eeSGreg Roach
23db7d25eeSGreg Roach/**
24db7d25eeSGreg Roach * Was the individual born in "foreign parts".
25db7d25eeSGreg Roach */
26c1010edaSGreg Roachclass CensusColumnBornForeignParts extends AbstractCensusColumn implements CensusColumnInterface
27c1010edaSGreg Roach{
28db7d25eeSGreg Roach    /**
29db7d25eeSGreg Roach     * Generate the likely value of this census column, based on available information.
30db7d25eeSGreg Roach     *
31db7d25eeSGreg Roach     * @param Individual $individual
3215d603e7SGreg Roach     * @param Individual $head
33db7d25eeSGreg Roach     *
34db7d25eeSGreg Roach     * @return string
35db7d25eeSGreg Roach     */
365a62e0a6SGreg Roach    public function generate(Individual $individual, Individual $head): string
37c1010edaSGreg Roach    {
38392561bbSGreg Roach        $birth_place  = (string) $individual->getBirthPlace()->lastParts(1)->first();
39ef21b467SGreg Roach        $census_place = $this->place();
40db7d25eeSGreg Roach
41db7d25eeSGreg Roach        if ($birth_place === 'Wales') {
42db7d25eeSGreg Roach            $birth_place = 'England';
43db7d25eeSGreg Roach        }
44db7d25eeSGreg Roach
45db7d25eeSGreg Roach        if ($census_place === 'Wales') {
46db7d25eeSGreg Roach            $census_place = 'England';
47db7d25eeSGreg Roach        }
48db7d25eeSGreg Roach
49b164ca57SGreg Roach        if ($birth_place === $census_place || $birth_place === '') {
50db7d25eeSGreg Roach            return '';
51db7d25eeSGreg Roach        }
52b2ce94c6SRico Sonntag
53b2ce94c6SRico Sonntag        if ($birth_place === 'England' || $birth_place === 'Scotland' || $birth_place === 'Ireland') {
54b2ce94c6SRico Sonntag            return substr($birth_place, 0, 1);
55b2ce94c6SRico Sonntag        }
56b2ce94c6SRico Sonntag
57b2ce94c6SRico Sonntag        return 'F';
58db7d25eeSGreg Roach    }
59db7d25eeSGreg Roach}
60