xref: /webtrees/app/Census/CensusColumnReligion.php (revision d11be7027e34e3121be11cc025421873364403f9)
14c219c47SGreg Roach<?php
23976b470SGreg Roach
34c219c47SGreg Roach/**
44c219c47SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
64c219c47SGreg Roach * This program is free software: you can redistribute it and/or modify
74c219c47SGreg Roach * it under the terms of the GNU General Public License as published by
84c219c47SGreg Roach * the Free Software Foundation, either version 3 of the License, or
94c219c47SGreg Roach * (at your option) any later version.
104c219c47SGreg Roach * This program is distributed in the hope that it will be useful,
114c219c47SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
124c219c47SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
134c219c47SGreg Roach * GNU General Public License for more details.
144c219c47SGreg 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/>.
164c219c47SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
1915d603e7SGreg Roach
204c219c47SGreg Roachnamespace Fisharebest\Webtrees\Census;
214c219c47SGreg Roach
22cacefda1SGreg Roachuse Fisharebest\Webtrees\Fact;
234c219c47SGreg Roachuse Fisharebest\Webtrees\Individual;
244c219c47SGreg Roach
254c219c47SGreg Roach/**
264c219c47SGreg Roach * The individual's religion.
274c219c47SGreg Roach */
28c1010edaSGreg Roachclass CensusColumnReligion extends AbstractCensusColumn implements CensusColumnInterface
29c1010edaSGreg Roach{
304c219c47SGreg Roach    /**
314c219c47SGreg Roach     * Generate the likely value of this census column, based on available information.
324c219c47SGreg Roach     *
334c219c47SGreg Roach     * @param Individual $individual
3415d603e7SGreg Roach     * @param Individual $head
354c219c47SGreg Roach     *
364c219c47SGreg Roach     * @return string
374c219c47SGreg Roach     */
388f53f488SRico Sonntag    public function generate(Individual $individual, Individual $head): string
39c1010edaSGreg Roach    {
4040d5e854SGreg Roach        $reli_fact = $individual->facts(['RELI'])->first();
4140d5e854SGreg Roach        if ($reli_fact instanceof Fact) {
4240d5e854SGreg Roach            return $reli_fact->value();
43cacefda1SGreg Roach        }
44cacefda1SGreg Roach
45cacefda1SGreg Roach        foreach ($individual->facts() as $fact) {
46cacefda1SGreg Roach            if ($fact->attribute('RELI') !== '') {
47cacefda1SGreg Roach                return $fact->attribute('RELI');
48cacefda1SGreg Roach            }
49cacefda1SGreg Roach        }
50cacefda1SGreg Roach
514c219c47SGreg Roach        return '';
524c219c47SGreg Roach    }
534c219c47SGreg Roach}
54