xref: /webtrees/app/Http/RequestHandlers/MergeRecordsPage.php (revision 89f7189b61a494347591c99bdb92afb7d8b66e1b)
15bbfbb82SGreg Roach<?php
25bbfbb82SGreg Roach
35bbfbb82SGreg Roach/**
45bbfbb82SGreg Roach * webtrees: online genealogy
5*89f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
65bbfbb82SGreg Roach * This program is free software: you can redistribute it and/or modify
75bbfbb82SGreg Roach * it under the terms of the GNU General Public License as published by
85bbfbb82SGreg Roach * the Free Software Foundation, either version 3 of the License, or
95bbfbb82SGreg Roach * (at your option) any later version.
105bbfbb82SGreg Roach * This program is distributed in the hope that it will be useful,
115bbfbb82SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
125bbfbb82SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135bbfbb82SGreg Roach * GNU General Public License for more details.
145bbfbb82SGreg Roach * You should have received a copy of the GNU General Public License
15*89f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
165bbfbb82SGreg Roach */
175bbfbb82SGreg Roach
185bbfbb82SGreg Roachdeclare(strict_types=1);
195bbfbb82SGreg Roach
205bbfbb82SGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
215bbfbb82SGreg Roach
225bbfbb82SGreg Roachuse Fisharebest\Webtrees\Family;
235bbfbb82SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait;
245bbfbb82SGreg Roachuse Fisharebest\Webtrees\I18N;
255bbfbb82SGreg Roachuse Fisharebest\Webtrees\Individual;
265bbfbb82SGreg Roachuse Fisharebest\Webtrees\Media;
275bbfbb82SGreg Roachuse Fisharebest\Webtrees\Note;
286b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry;
295bbfbb82SGreg Roachuse Fisharebest\Webtrees\Repository;
305bbfbb82SGreg Roachuse Fisharebest\Webtrees\Source;
3170fa8906SGreg Roachuse Fisharebest\Webtrees\Submitter;
325bbfbb82SGreg Roachuse Fisharebest\Webtrees\Tree;
335bbfbb82SGreg Roachuse Psr\Http\Message\ResponseInterface;
345bbfbb82SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
355bbfbb82SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
365bbfbb82SGreg Roach
375bbfbb82SGreg Roachuse function assert;
385bbfbb82SGreg Roachuse function e;
395bbfbb82SGreg Roach
405bbfbb82SGreg Roach/**
415bbfbb82SGreg Roach * Merge records
425bbfbb82SGreg Roach */
435bbfbb82SGreg Roachclass MergeRecordsPage implements RequestHandlerInterface
445bbfbb82SGreg Roach{
455bbfbb82SGreg Roach    use ViewResponseTrait;
465bbfbb82SGreg Roach
475bbfbb82SGreg Roach    /**
485bbfbb82SGreg Roach     * Merge two genealogy records.
495bbfbb82SGreg Roach     *
505bbfbb82SGreg Roach     * @param ServerRequestInterface $request
515bbfbb82SGreg Roach     *
525bbfbb82SGreg Roach     * @return ResponseInterface
535bbfbb82SGreg Roach     */
545bbfbb82SGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
555bbfbb82SGreg Roach    {
565bbfbb82SGreg Roach        $this->layout = 'layouts/administration';
575bbfbb82SGreg Roach
585bbfbb82SGreg Roach        $tree = $request->getAttribute('tree');
595bbfbb82SGreg Roach        assert($tree instanceof Tree);
605bbfbb82SGreg Roach
615bbfbb82SGreg Roach        $xref1 = $request->getQueryParams()['xref1'] ?? '';
625bbfbb82SGreg Roach        $xref2 = $request->getQueryParams()['xref2'] ?? '';
635bbfbb82SGreg Roach
646b9cb339SGreg Roach        $record1 = Registry::gedcomRecordFactory()->make($xref1, $tree);
656b9cb339SGreg Roach        $record2 = Registry::gedcomRecordFactory()->make($xref2, $tree);
665bbfbb82SGreg Roach
675bbfbb82SGreg Roach        $title = I18N::translate('Merge records') . ' — ' . e($tree->title());
685bbfbb82SGreg Roach
695bbfbb82SGreg Roach        return $this->viewResponse('admin/merge-records-step-1', [
705bbfbb82SGreg Roach            'individual1' => $record1 instanceof Individual ? $record1 : null,
715bbfbb82SGreg Roach            'individual2' => $record2 instanceof Individual ? $record2 : null,
725bbfbb82SGreg Roach            'family1'     => $record1 instanceof Family ? $record1 : null,
735bbfbb82SGreg Roach            'family2'     => $record2 instanceof Family ? $record2 : null,
745bbfbb82SGreg Roach            'source1'     => $record1 instanceof Source ? $record1 : null,
755bbfbb82SGreg Roach            'source2'     => $record2 instanceof Source ? $record2 : null,
765bbfbb82SGreg Roach            'repository1' => $record1 instanceof Repository ? $record1 : null,
775bbfbb82SGreg Roach            'repository2' => $record2 instanceof Repository ? $record2 : null,
785bbfbb82SGreg Roach            'media1'      => $record1 instanceof Media ? $record1 : null,
795bbfbb82SGreg Roach            'media2'      => $record2 instanceof Media ? $record2 : null,
805bbfbb82SGreg Roach            'note1'       => $record1 instanceof Note ? $record1 : null,
815bbfbb82SGreg Roach            'note2'       => $record2 instanceof Note ? $record2 : null,
8270fa8906SGreg Roach            'submitter1'  => $record1 instanceof Submitter ? $record1 : null,
8370fa8906SGreg Roach            'submitter2'  => $record2 instanceof Submitter ? $record2 : null,
845bbfbb82SGreg Roach            'title'       => $title,
855bbfbb82SGreg Roach            'tree'        => $tree,
865bbfbb82SGreg Roach        ]);
875bbfbb82SGreg Roach    }
885bbfbb82SGreg Roach}
89