xref: /webtrees/app/Census/CensusColumnAgeMarried.php (revision d11be7027e34e3121be11cc025421873364403f9)
181d1be7aSGreg Roach<?php
23976b470SGreg Roach
381d1be7aSGreg Roach/**
481d1be7aSGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
681d1be7aSGreg Roach * This program is free software: you can redistribute it and/or modify
781d1be7aSGreg Roach * it under the terms of the GNU General Public License as published by
881d1be7aSGreg Roach * the Free Software Foundation, either version 3 of the License, or
981d1be7aSGreg Roach * (at your option) any later version.
1081d1be7aSGreg Roach * This program is distributed in the hope that it will be useful,
1181d1be7aSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1281d1be7aSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1381d1be7aSGreg Roach * GNU General Public License for more details.
1481d1be7aSGreg 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/>.
1681d1be7aSGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
1915d603e7SGreg Roach
2081d1be7aSGreg Roachnamespace Fisharebest\Webtrees\Census;
2181d1be7aSGreg Roach
22054771e9SGreg Roachuse Fisharebest\Webtrees\Age;
23054771e9SGreg Roachuse Fisharebest\Webtrees\I18N;
2481d1be7aSGreg Roachuse Fisharebest\Webtrees\Individual;
2581d1be7aSGreg Roach
2681d1be7aSGreg Roach/**
2781d1be7aSGreg Roach * At what age did the individual marry.
2881d1be7aSGreg Roach */
29c1010edaSGreg Roachclass CensusColumnAgeMarried extends AbstractCensusColumn implements CensusColumnInterface
30c1010edaSGreg Roach{
3181d1be7aSGreg Roach    /**
3281d1be7aSGreg Roach     * Generate the likely value of this census column, based on available information.
3381d1be7aSGreg Roach     *
3481d1be7aSGreg Roach     * @param Individual $individual
3515d603e7SGreg Roach     * @param Individual $head
3681d1be7aSGreg Roach     *
3781d1be7aSGreg Roach     * @return string
3881d1be7aSGreg Roach     */
398f53f488SRico Sonntag    public function generate(Individual $individual, Individual $head): string
40c1010edaSGreg Roach    {
4181d1be7aSGreg Roach        if ($individual->getBirthDate()->isOK()) {
4239ca88baSGreg Roach            foreach ($individual->spouseFamilies() as $family) {
438d0ebef0SGreg Roach                foreach ($family->facts(['MARR'], true) as $fact) {
442decada7SGreg Roach                    if ($fact->date()->isOK()) {
45054771e9SGreg Roach                        $age = new Age($individual->getBirthDate(), $fact->date());
46054771e9SGreg Roach
47054771e9SGreg Roach                        return I18N::number($age->ageYears());
4881d1be7aSGreg Roach                    }
4981d1be7aSGreg Roach                }
5081d1be7aSGreg Roach            }
5181d1be7aSGreg Roach        }
5281d1be7aSGreg Roach
5381d1be7aSGreg Roach        return '';
5481d1be7aSGreg Roach    }
5581d1be7aSGreg Roach}
56