xref: /webtrees/app/Http/RequestHandlers/MergeRecordsPage.php (revision d11be7027e34e3121be11cc025421873364403f9)
15bbfbb82SGreg Roach<?php
25bbfbb82SGreg Roach
35bbfbb82SGreg Roach/**
45bbfbb82SGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 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
1589f7189bSGreg 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;
269d28ed8bSGreg Roachuse Fisharebest\Webtrees\Location;
275bbfbb82SGreg Roachuse Fisharebest\Webtrees\Media;
285bbfbb82SGreg Roachuse Fisharebest\Webtrees\Note;
296b9cb339SGreg Roachuse Fisharebest\Webtrees\Registry;
305bbfbb82SGreg Roachuse Fisharebest\Webtrees\Repository;
315bbfbb82SGreg Roachuse Fisharebest\Webtrees\Source;
3270fa8906SGreg Roachuse Fisharebest\Webtrees\Submitter;
33b55cbc6bSGreg Roachuse Fisharebest\Webtrees\Validator;
345bbfbb82SGreg Roachuse Psr\Http\Message\ResponseInterface;
355bbfbb82SGreg Roachuse Psr\Http\Message\ServerRequestInterface;
365bbfbb82SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
375bbfbb82SGreg Roach
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
58b55cbc6bSGreg Roach        $tree  = Validator::attributes($request)->tree();
59748dbe15SGreg Roach        $xref1 = Validator::queryParams($request)->isXref()->string('xref1', '');
60748dbe15SGreg Roach        $xref2 = Validator::queryParams($request)->isXref()->string('xref2', '');
615bbfbb82SGreg Roach
626b9cb339SGreg Roach        $record1 = Registry::gedcomRecordFactory()->make($xref1, $tree);
636b9cb339SGreg Roach        $record2 = Registry::gedcomRecordFactory()->make($xref2, $tree);
645bbfbb82SGreg Roach
655bbfbb82SGreg Roach        $title = I18N::translate('Merge records') . ' — ' . e($tree->title());
665bbfbb82SGreg Roach
675bbfbb82SGreg Roach        return $this->viewResponse('admin/merge-records-step-1', [
685bbfbb82SGreg Roach            'individual1' => $record1 instanceof Individual ? $record1 : null,
695bbfbb82SGreg Roach            'individual2' => $record2 instanceof Individual ? $record2 : null,
705bbfbb82SGreg Roach            'family1'     => $record1 instanceof Family ? $record1 : null,
715bbfbb82SGreg Roach            'family2'     => $record2 instanceof Family ? $record2 : null,
725bbfbb82SGreg Roach            'source1'     => $record1 instanceof Source ? $record1 : null,
735bbfbb82SGreg Roach            'source2'     => $record2 instanceof Source ? $record2 : null,
745bbfbb82SGreg Roach            'repository1' => $record1 instanceof Repository ? $record1 : null,
755bbfbb82SGreg Roach            'repository2' => $record2 instanceof Repository ? $record2 : null,
765bbfbb82SGreg Roach            'media1'      => $record1 instanceof Media ? $record1 : null,
775bbfbb82SGreg Roach            'media2'      => $record2 instanceof Media ? $record2 : null,
785bbfbb82SGreg Roach            'note1'       => $record1 instanceof Note ? $record1 : null,
795bbfbb82SGreg Roach            'note2'       => $record2 instanceof Note ? $record2 : null,
8070fa8906SGreg Roach            'submitter1'  => $record1 instanceof Submitter ? $record1 : null,
8170fa8906SGreg Roach            'submitter2'  => $record2 instanceof Submitter ? $record2 : null,
829d28ed8bSGreg Roach            'location1'   => $record1 instanceof Location ? $record1 : null,
839d28ed8bSGreg Roach            'location2'   => $record2 instanceof Location ? $record2 : null,
845bbfbb82SGreg Roach            'title'       => $title,
855bbfbb82SGreg Roach            'tree'        => $tree,
865bbfbb82SGreg Roach        ]);
875bbfbb82SGreg Roach    }
885bbfbb82SGreg Roach}
89