xref: /webtrees/app/Http/RequestHandlers/MergeRecordsPage.php (revision 8634febf6487fcb3ee7b59e88f828071a22cba22)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2023 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\Http\RequestHandlers;
21
22use Fisharebest\Webtrees\Family;
23use Fisharebest\Webtrees\Http\ViewResponseTrait;
24use Fisharebest\Webtrees\I18N;
25use Fisharebest\Webtrees\Individual;
26use Fisharebest\Webtrees\Location;
27use Fisharebest\Webtrees\Media;
28use Fisharebest\Webtrees\Note;
29use Fisharebest\Webtrees\Registry;
30use Fisharebest\Webtrees\Repository;
31use Fisharebest\Webtrees\Source;
32use Fisharebest\Webtrees\Submitter;
33use Fisharebest\Webtrees\Validator;
34use Psr\Http\Message\ResponseInterface;
35use Psr\Http\Message\ServerRequestInterface;
36use Psr\Http\Server\RequestHandlerInterface;
37
38use function e;
39
40/**
41 * Merge records
42 */
43class MergeRecordsPage implements RequestHandlerInterface
44{
45    use ViewResponseTrait;
46
47    /**
48     * Merge two genealogy records.
49     *
50     * @param ServerRequestInterface $request
51     *
52     * @return ResponseInterface
53     */
54    public function handle(ServerRequestInterface $request): ResponseInterface
55    {
56        $this->layout = 'layouts/administration';
57
58        $tree  = Validator::attributes($request)->tree();
59        $xref1 = Validator::queryParams($request)->isXref()->string('xref1', '');
60        $xref2 = Validator::queryParams($request)->isXref()->string('xref2', '');
61
62        $record1 = Registry::gedcomRecordFactory()->make($xref1, $tree);
63        $record2 = Registry::gedcomRecordFactory()->make($xref2, $tree);
64
65        $title = I18N::translate('Merge records') . ' — ' . e($tree->title());
66
67        return $this->viewResponse('admin/merge-records-step-1', [
68            'individual1' => $record1 instanceof Individual ? $record1 : null,
69            'individual2' => $record2 instanceof Individual ? $record2 : null,
70            'family1'     => $record1 instanceof Family ? $record1 : null,
71            'family2'     => $record2 instanceof Family ? $record2 : null,
72            'source1'     => $record1 instanceof Source ? $record1 : null,
73            'source2'     => $record2 instanceof Source ? $record2 : null,
74            'repository1' => $record1 instanceof Repository ? $record1 : null,
75            'repository2' => $record2 instanceof Repository ? $record2 : null,
76            'media1'      => $record1 instanceof Media ? $record1 : null,
77            'media2'      => $record2 instanceof Media ? $record2 : null,
78            'note1'       => $record1 instanceof Note ? $record1 : null,
79            'note2'       => $record2 instanceof Note ? $record2 : null,
80            'submitter1'  => $record1 instanceof Submitter ? $record1 : null,
81            'submitter2'  => $record2 instanceof Submitter ? $record2 : null,
82            'location1'   => $record1 instanceof Location ? $record1 : null,
83            'location2'   => $record2 instanceof Location ? $record2 : null,
84            'title'       => $title,
85            'tree'        => $tree,
86        ]);
87    }
88}
89