xref: /webtrees/app/Census/CensusColumnAgeMarried.php (revision 39ca88ba08cefcfcaf891abfcf748f9c808eb326)
181d1be7aSGreg Roach<?php
281d1be7aSGreg Roach/**
381d1be7aSGreg Roach * webtrees: online genealogy
48fcd0d32SGreg Roach * Copyright (C) 2019 webtrees development team
581d1be7aSGreg Roach * This program is free software: you can redistribute it and/or modify
681d1be7aSGreg Roach * it under the terms of the GNU General Public License as published by
781d1be7aSGreg Roach * the Free Software Foundation, either version 3 of the License, or
881d1be7aSGreg Roach * (at your option) any later version.
981d1be7aSGreg Roach * This program is distributed in the hope that it will be useful,
1081d1be7aSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
1181d1be7aSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1281d1be7aSGreg Roach * GNU General Public License for more details.
1381d1be7aSGreg Roach * You should have received a copy of the GNU General Public License
1481d1be7aSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
1581d1be7aSGreg Roach */
16e7f56f2aSGreg Roachdeclare(strict_types=1);
1715d603e7SGreg Roach
1881d1be7aSGreg Roachnamespace Fisharebest\Webtrees\Census;
1981d1be7aSGreg Roach
2081d1be7aSGreg Roachuse Fisharebest\Webtrees\Date;
2181d1be7aSGreg Roachuse Fisharebest\Webtrees\Individual;
2281d1be7aSGreg Roach
2381d1be7aSGreg Roach/**
2481d1be7aSGreg Roach * At what age did the individual marry.
2581d1be7aSGreg Roach */
26c1010edaSGreg Roachclass CensusColumnAgeMarried extends AbstractCensusColumn implements CensusColumnInterface
27c1010edaSGreg Roach{
2881d1be7aSGreg Roach    /**
2981d1be7aSGreg Roach     * Generate the likely value of this census column, based on available information.
3081d1be7aSGreg Roach     *
3181d1be7aSGreg Roach     * @param Individual $individual
3215d603e7SGreg Roach     * @param Individual $head
3381d1be7aSGreg Roach     *
3481d1be7aSGreg Roach     * @return string
3581d1be7aSGreg Roach     */
368f53f488SRico Sonntag    public function generate(Individual $individual, Individual $head): string
37c1010edaSGreg Roach    {
3881d1be7aSGreg Roach        if ($individual->getBirthDate()->isOK()) {
39*39ca88baSGreg Roach            foreach ($individual->spouseFamilies() as $family) {
408d0ebef0SGreg Roach                foreach ($family->facts(['MARR'], true) as $fact) {
412decada7SGreg Roach                    if ($fact->date()->isOK()) {
422decada7SGreg Roach                        return (string) Date::getAgeYears($individual->getBirthDate(), $fact->date());
4381d1be7aSGreg Roach                    }
4481d1be7aSGreg Roach                }
4581d1be7aSGreg Roach            }
4681d1be7aSGreg Roach        }
4781d1be7aSGreg Roach
4881d1be7aSGreg Roach        return '';
4981d1be7aSGreg Roach    }
5081d1be7aSGreg Roach}
51