1*6fd01894SGreg Roach<?php 2*6fd01894SGreg Roach 3*6fd01894SGreg Roach/** 4*6fd01894SGreg Roach * webtrees: online genealogy 5*6fd01894SGreg Roach * Copyright (C) 2020 webtrees development team 6*6fd01894SGreg Roach * This program is free software: you can redistribute it and/or modify 7*6fd01894SGreg Roach * it under the terms of the GNU General Public License as published by 8*6fd01894SGreg Roach * the Free Software Foundation, either version 3 of the License, or 9*6fd01894SGreg Roach * (at your option) any later version. 10*6fd01894SGreg Roach * This program is distributed in the hope that it will be useful, 11*6fd01894SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of 12*6fd01894SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*6fd01894SGreg Roach * GNU General Public License for more details. 14*6fd01894SGreg Roach * You should have received a copy of the GNU General Public License 15*6fd01894SGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*6fd01894SGreg Roach */ 17*6fd01894SGreg Roach 18*6fd01894SGreg Roachdeclare(strict_types=1); 19*6fd01894SGreg Roach 20*6fd01894SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers; 21*6fd01894SGreg Roach 22*6fd01894SGreg Roachuse Fisharebest\Webtrees\Factory; 23*6fd01894SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait; 24*6fd01894SGreg Roachuse Fisharebest\Webtrees\I18N; 25*6fd01894SGreg Roachuse Fisharebest\Webtrees\Services\AdminService; 26*6fd01894SGreg Roachuse Fisharebest\Webtrees\Tree; 27*6fd01894SGreg Roachuse Psr\Http\Message\ResponseInterface; 28*6fd01894SGreg Roachuse Psr\Http\Message\ServerRequestInterface; 29*6fd01894SGreg Roachuse Psr\Http\Server\RequestHandlerInterface; 30*6fd01894SGreg Roach 31*6fd01894SGreg Roachuse function assert; 32*6fd01894SGreg Roachuse function e; 33*6fd01894SGreg Roach 34*6fd01894SGreg Roach/** 35*6fd01894SGreg Roach * Import a GEDCOM file into a tree. 36*6fd01894SGreg Roach */ 37*6fd01894SGreg Roachclass ImportGedcomPage implements RequestHandlerInterface 38*6fd01894SGreg Roach{ 39*6fd01894SGreg Roach use ViewResponseTrait; 40*6fd01894SGreg Roach 41*6fd01894SGreg Roach /** @var AdminService */ 42*6fd01894SGreg Roach private $admin_service; 43*6fd01894SGreg Roach 44*6fd01894SGreg Roach /** 45*6fd01894SGreg Roach * @param AdminService $admin_service 46*6fd01894SGreg Roach */ 47*6fd01894SGreg Roach public function __construct(AdminService $admin_service) 48*6fd01894SGreg Roach { 49*6fd01894SGreg Roach $this->admin_service = $admin_service; 50*6fd01894SGreg Roach } 51*6fd01894SGreg Roach 52*6fd01894SGreg Roach /** 53*6fd01894SGreg Roach * @param ServerRequestInterface $request 54*6fd01894SGreg Roach * 55*6fd01894SGreg Roach * @return ResponseInterface 56*6fd01894SGreg Roach */ 57*6fd01894SGreg Roach public function handle(ServerRequestInterface $request): ResponseInterface 58*6fd01894SGreg Roach { 59*6fd01894SGreg Roach $this->layout = 'layouts/administration'; 60*6fd01894SGreg Roach 61*6fd01894SGreg Roach $tree = $request->getAttribute('tree'); 62*6fd01894SGreg Roach assert($tree instanceof Tree); 63*6fd01894SGreg Roach 64*6fd01894SGreg Roach $data_filesystem = Factory::filesystem()->data(); 65*6fd01894SGreg Roach $data_folder = Factory::filesystem()->dataName(); 66*6fd01894SGreg Roach 67*6fd01894SGreg Roach $default_gedcom_file = $tree->getPreference('gedcom_filename'); 68*6fd01894SGreg Roach $gedcom_media_path = $tree->getPreference('GEDCOM_MEDIA_PATH'); 69*6fd01894SGreg Roach $gedcom_files = $this->admin_service->gedcomFiles($data_filesystem); 70*6fd01894SGreg Roach 71*6fd01894SGreg Roach $title = I18N::translate('Import a GEDCOM file') . ' — ' . e($tree->title()); 72*6fd01894SGreg Roach 73*6fd01894SGreg Roach return $this->viewResponse('admin/trees-import', [ 74*6fd01894SGreg Roach 'data_folder' => $data_folder, 75*6fd01894SGreg Roach 'default_gedcom_file' => $default_gedcom_file, 76*6fd01894SGreg Roach 'gedcom_files' => $gedcom_files, 77*6fd01894SGreg Roach 'gedcom_media_path' => $gedcom_media_path, 78*6fd01894SGreg Roach 'title' => $title, 79*6fd01894SGreg Roach 'tree' => $tree, 80*6fd01894SGreg Roach ]); 81*6fd01894SGreg Roach } 82*6fd01894SGreg Roach} 83