xref: /webtrees/app/Census/CensusColumnGivenNameInitial.php (revision 7e47eb99e7f64684fec0c690af016448225d6c05)
1f3fa6d90SGreg Roach<?php
2f3fa6d90SGreg Roach/**
3f3fa6d90SGreg Roach * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
5f3fa6d90SGreg Roach * This program is free software: you can redistribute it and/or modify
6f3fa6d90SGreg Roach * it under the terms of the GNU General Public License as published by
7f3fa6d90SGreg Roach * the Free Software Foundation, either version 3 of the License, or
8f3fa6d90SGreg Roach * (at your option) any later version.
9f3fa6d90SGreg Roach * This program is distributed in the hope that it will be useful,
10f3fa6d90SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
11f3fa6d90SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12f3fa6d90SGreg Roach * GNU General Public License for more details.
13f3fa6d90SGreg Roach * You should have received a copy of the GNU General Public License
14f3fa6d90SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
15f3fa6d90SGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
1715d603e7SGreg Roach
18f3fa6d90SGreg Roachnamespace Fisharebest\Webtrees\Census;
19f3fa6d90SGreg Roach
20f3fa6d90SGreg Roachuse Fisharebest\Webtrees\Individual;
21f3fa6d90SGreg Roach
22f3fa6d90SGreg Roach/**
23f3fa6d90SGreg Roach * The individual's full name.
24f3fa6d90SGreg Roach */
25c1010edaSGreg Roachclass CensusColumnGivenNameInitial extends AbstractCensusColumn implements CensusColumnInterface
26c1010edaSGreg Roach{
27f3fa6d90SGreg Roach    /**
28f3fa6d90SGreg Roach     * Generate the likely value of this census column, based on available information.
29f3fa6d90SGreg Roach     *
30f3fa6d90SGreg Roach     * @param Individual $individual
3115d603e7SGreg Roach     * @param Individual $head
32f3fa6d90SGreg Roach     *
33f3fa6d90SGreg Roach     * @return string
34f3fa6d90SGreg Roach     */
358f53f488SRico Sonntag    public function generate(Individual $individual, Individual $head): string
36c1010edaSGreg Roach    {
37f3fa6d90SGreg Roach        foreach ($individual->getAllNames() as $name) {
38f3fa6d90SGreg Roach            $given = $name['givn'];
39*7e47eb99SGreg Roach            $space_pos = strpos($given, ' ');
40*7e47eb99SGreg Roach
41*7e47eb99SGreg Roach            if ($space_pos === false) {
42f3fa6d90SGreg Roach                return $given;
43f3fa6d90SGreg Roach            }
44b2ce94c6SRico Sonntag
45*7e47eb99SGreg Roach            return substr($given, 0, $space_pos + 2);
46f3fa6d90SGreg Roach        }
47f3fa6d90SGreg Roach
48f3fa6d90SGreg Roach        return '';
49f3fa6d90SGreg Roach    }
50f3fa6d90SGreg Roach}
51