xref: /webtrees/app/Elements/Census.php (revision 77b47e31e3b68d0ac4acc5d29d0b7357ff450342)
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        'NOTE' => '0:M',
41        'OBJE' => '0:M',
42        'SOUR' => '0:M',
43        'RESN' => '0:1',
44    ];
45
46    /**
47     * An edit control for this data.
48     *
49     * @param string $id
50     * @param string $name
51     * @param string $value
52     * @param Tree   $tree
53     *
54     * @return string
55     */
56    public function edit(string $id, string $name, string $value, Tree $tree): string
57    {
58        $html = $this->editHidden($id, $name, $value) . view('modules/GEDFact_assistant/select-census', [
59            'census_places' => Censuses::censusPlaces(I18N::languageTag()),
60        ]);
61
62        $xref=app(ServerRequestInterface::class)->getAttribute('xref', '');
63
64        $census_assistant = app(ModuleService::class)->findByInterface(CensusAssistantModule::class)->first();
65        $record           = Registry::individualFactory()->make($xref, $tree);
66
67        if ($census_assistant instanceof CensusAssistantModule && $record instanceof Individual) {
68            $html .= $census_assistant->createCensusAssistant($record);
69        }
70
71        return $html;
72    }
73}
74