xref: /webtrees/app/Census/CensusColumnGivenNameInitial.php (revision d11be7027e34e3121be11cc025421873364403f9)
1f3fa6d90SGreg Roach<?php
23976b470SGreg Roach
3f3fa6d90SGreg Roach/**
4f3fa6d90SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
6f3fa6d90SGreg Roach * This program is free software: you can redistribute it and/or modify
7f3fa6d90SGreg Roach * it under the terms of the GNU General Public License as published by
8f3fa6d90SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9f3fa6d90SGreg Roach * (at your option) any later version.
10f3fa6d90SGreg Roach * This program is distributed in the hope that it will be useful,
11f3fa6d90SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12f3fa6d90SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13f3fa6d90SGreg Roach * GNU General Public License for more details.
14f3fa6d90SGreg 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/>.
16f3fa6d90SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
1915d603e7SGreg Roach
20f3fa6d90SGreg Roachnamespace Fisharebest\Webtrees\Census;
21f3fa6d90SGreg Roach
22f3fa6d90SGreg Roachuse Fisharebest\Webtrees\Individual;
23f3fa6d90SGreg Roach
24f3fa6d90SGreg Roach/**
25f3fa6d90SGreg Roach * The individual's full name.
26f3fa6d90SGreg Roach */
27c1010edaSGreg Roachclass CensusColumnGivenNameInitial extends AbstractCensusColumn implements CensusColumnInterface
28c1010edaSGreg Roach{
29f3fa6d90SGreg Roach    /**
30f3fa6d90SGreg Roach     * Generate the likely value of this census column, based on available information.
31f3fa6d90SGreg Roach     *
32f3fa6d90SGreg Roach     * @param Individual $individual
3315d603e7SGreg Roach     * @param Individual $head
34f3fa6d90SGreg Roach     *
35f3fa6d90SGreg Roach     * @return string
36f3fa6d90SGreg Roach     */
378f53f488SRico Sonntag    public function generate(Individual $individual, Individual $head): string
38c1010edaSGreg Roach    {
39f3fa6d90SGreg Roach        foreach ($individual->getAllNames() as $name) {
40f3fa6d90SGreg Roach            $given = $name['givn'];
417e47eb99SGreg Roach            $space_pos = strpos($given, ' ');
427e47eb99SGreg Roach
437e47eb99SGreg Roach            if ($space_pos === false) {
44f3fa6d90SGreg Roach                return $given;
45f3fa6d90SGreg Roach            }
46b2ce94c6SRico Sonntag
477e47eb99SGreg Roach            return substr($given, 0, $space_pos + 2);
48f3fa6d90SGreg Roach        }
49f3fa6d90SGreg Roach
50f3fa6d90SGreg Roach        return '';
51f3fa6d90SGreg Roach    }
52f3fa6d90SGreg Roach}
53