xref: /webtrees/app/Http/RequestHandlers/RenumberTreePage.php (revision 6fd01894a78d321fac365dd0291a2fc52129fa03)
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\Http\ViewResponseTrait;
23*6fd01894SGreg Roachuse Fisharebest\Webtrees\I18N;
24*6fd01894SGreg Roachuse Fisharebest\Webtrees\Services\AdminService;
25*6fd01894SGreg Roachuse Fisharebest\Webtrees\Services\TreeService;
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 * Renumber the XREFs in a family tree.
36*6fd01894SGreg Roach */
37*6fd01894SGreg Roachclass RenumberTreePage 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        $xrefs = $this->admin_service->duplicateXrefs($tree);
65*6fd01894SGreg Roach
66*6fd01894SGreg Roach        /* I18N: Renumber the records in a family tree */
67*6fd01894SGreg Roach        $title = I18N::translate('Renumber family tree') . ' — ' . e($tree->title());
68*6fd01894SGreg Roach
69*6fd01894SGreg Roach        return $this->viewResponse('admin/trees-renumber', [
70*6fd01894SGreg Roach            'title' => $title,
71*6fd01894SGreg Roach            'tree'  => $tree,
72*6fd01894SGreg Roach            'xrefs' => $xrefs,
73*6fd01894SGreg Roach        ]);
74*6fd01894SGreg Roach    }
75*6fd01894SGreg Roach}
76