xref: /webtrees/app/Elements/Census.php (revision d1da5ba430762bd82a5d57bc40552492431d11ee)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2021 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Elements;
21
22use Fisharebest\Webtrees\Census\Census as Censuses;
23use Fisharebest\Webtrees\I18N;
24use Fisharebest\Webtrees\Individual;
25use Fisharebest\Webtrees\Module\CensusAssistantModule;
26use Fisharebest\Webtrees\Registry;
27use Fisharebest\Webtrees\Services\ModuleService;
28use Fisharebest\Webtrees\Tree;
29use Psr\Http\Message\ServerRequestInterface;
30
31/**
32 * Census
33 */
34class Census extends AbstractElement
35{
36    protected const SUBTAGS = [
37        'DATE' => '0:1',
38        'AGE'  => '0:1',
39        'PLAC' => '0:1',
40        'ADDR' => '0:1',
41        'NOTE' => '0:M',
42        'OBJE' => '0:M',
43        'SOUR' => '0:M',
44        'RESN' => '0:1',
45    ];
46
47    /**
48     * An edit control for this data.
49     *
50     * @param string $id
51     * @param string $name
52     * @param string $value
53     * @param Tree   $tree
54     *
55     * @return string
56     */
57    public function edit(string $id, string $name, string $value, Tree $tree): string
58    {
59        $html = $this->editHidden($id, $name, $value);
60
61        $html .= view('modules/GEDFact_assistant/select-census', [
62            'census_places' => Censuses::censusPlaces(I18N::languageTag()),
63        ]);
64
65        $xref = app(ServerRequestInterface::class)->getAttribute('xref', '');
66
67        $census_assistant = app(ModuleService::class)->findByInterface(CensusAssistantModule::class)->first();
68        $record           = Registry::individualFactory()->make($xref, $tree);
69
70        if ($census_assistant instanceof CensusAssistantModule && $record instanceof Individual) {
71            $html .= $census_assistant->createCensusAssistant($record);
72        }
73
74        return $html;
75    }
76}
77