xref: /webtrees/app/Census/CensusColumnSurnameGivenNameInitial.php (revision 5a62e0a61f2bcd84378fc14765f7f86c18865ba7)
1f3fa6d90SGreg Roach<?php
2f3fa6d90SGreg Roach/**
3f3fa6d90SGreg Roach * webtrees: online genealogy
41062a142SGreg Roach * Copyright (C) 2018 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 */
1615d603e7SGreg Roach
17f3fa6d90SGreg Roachnamespace Fisharebest\Webtrees\Census;
18f3fa6d90SGreg Roach
19f3fa6d90SGreg Roachuse Fisharebest\Webtrees\Individual;
20f3fa6d90SGreg Roach
21f3fa6d90SGreg Roach/**
22f3fa6d90SGreg Roach * The individual's full name.
23f3fa6d90SGreg Roach */
24c1010edaSGreg Roachclass CensusColumnSurnameGivenNameInitial extends CensusColumnFullName
25c1010edaSGreg Roach{
26f3fa6d90SGreg Roach    /**
27f3fa6d90SGreg Roach     * Generate the likely value of this census column, based on available information.
28f3fa6d90SGreg Roach     *
29f3fa6d90SGreg Roach     * @param Individual $individual
3015d603e7SGreg Roach     * @param Individual $head
31f3fa6d90SGreg Roach     *
32f3fa6d90SGreg Roach     * @return string
33f3fa6d90SGreg Roach     */
34*5a62e0a6SGreg Roach    public function generate(Individual $individual, Individual $head): string
35c1010edaSGreg Roach    {
3609db5ef8SGreg Roach        $name  = $this->nameAtCensusDate($individual, $this->date());
37f3fa6d90SGreg Roach        $given = $name['givn'];
38f3fa6d90SGreg Roach        if (strpos($given, ' ') === false) {
395105fb59SGreg Roach            return $name['surname'] . ', ' . $given;
40f3fa6d90SGreg Roach        } else {
415105fb59SGreg Roach            return $name['surname'] . ', ' . substr($given, 0, strpos($given, ' ') + 2);
42f3fa6d90SGreg Roach        }
43f3fa6d90SGreg Roach    }
44f3fa6d90SGreg Roach}
45