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 Fisharebest\Webtrees\Validator; 30use Psr\Http\Message\ServerRequestInterface; 31 32use function app; 33use function assert; 34 35/** 36 * Census 37 */ 38class Census extends AbstractElement 39{ 40 protected const SUBTAGS = [ 41 'DATE' => '0:1', 42 'AGE' => '0:1', 43 'PLAC' => '0:1', 44 'ADDR' => '0:1', 45 'NOTE' => '0:M', 46 'OBJE' => '0:M', 47 'SOUR' => '0:M', 48 'RESN' => '0:1', 49 ]; 50 51 /** 52 * An edit control for this data. 53 * 54 * @param string $id 55 * @param string $name 56 * @param string $value 57 * @param Tree $tree 58 * 59 * @return string 60 */ 61 public function edit(string $id, string $name, string $value, Tree $tree): string 62 { 63 $html = $this->editHidden($id, $name, $value); 64 65 $html .= view('modules/GEDFact_assistant/select-census', [ 66 'census_places' => Censuses::censusPlaces(I18N::languageTag()), 67 ]); 68 69 $request = app(ServerRequestInterface::class); 70 assert($request instanceof ServerRequestInterface); 71 72 $xref = Validator::attributes($request)->isXref()->string('xref', ''); 73 74 $module_service = app(ModuleService::class); 75 assert($module_service instanceof ModuleService); 76 77 $census_assistant = $module_service->findByInterface(CensusAssistantModule::class)->first(); 78 $record = Registry::individualFactory()->make($xref, $tree); 79 80 if ($census_assistant instanceof CensusAssistantModule && $record instanceof Individual) { 81 $html .= $census_assistant->createCensusAssistant($record); 82 } 83 84 return $html; 85 } 86} 87