xref: /webtrees/app/Http/RequestHandlers/CreateTreePage.php (revision 5afbc57a5c33b9caec67458db57f44e54a90f745)
1*5afbc57aSGreg Roach<?php
2*5afbc57aSGreg Roach
3*5afbc57aSGreg Roach/**
4*5afbc57aSGreg Roach * webtrees: online genealogy
5*5afbc57aSGreg Roach * Copyright (C) 2019 webtrees development team
6*5afbc57aSGreg Roach * This program is free software: you can redistribute it and/or modify
7*5afbc57aSGreg Roach * it under the terms of the GNU General Public License as published by
8*5afbc57aSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9*5afbc57aSGreg Roach * (at your option) any later version.
10*5afbc57aSGreg Roach * This program is distributed in the hope that it will be useful,
11*5afbc57aSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12*5afbc57aSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13*5afbc57aSGreg Roach * GNU General Public License for more details.
14*5afbc57aSGreg Roach * You should have received a copy of the GNU General Public License
15*5afbc57aSGreg Roach * along with this program. If not, see <http://www.gnu.org/licenses/>.
16*5afbc57aSGreg Roach */
17*5afbc57aSGreg Roachdeclare(strict_types=1);
18*5afbc57aSGreg Roach
19*5afbc57aSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
20*5afbc57aSGreg Roach
21*5afbc57aSGreg Roachuse Fisharebest\Webtrees\Http\Controllers\AbstractBaseController;
22*5afbc57aSGreg Roachuse Fisharebest\Webtrees\I18N;
23*5afbc57aSGreg Roachuse Fisharebest\Webtrees\Services\TreeService;
24*5afbc57aSGreg Roachuse Psr\Http\Message\ResponseInterface;
25*5afbc57aSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
26*5afbc57aSGreg Roach
27*5afbc57aSGreg Roach/**
28*5afbc57aSGreg Roach * Show a form to create a new tree.
29*5afbc57aSGreg Roach */
30*5afbc57aSGreg Roachclass CreateTreePage extends AbstractBaseController
31*5afbc57aSGreg Roach{
32*5afbc57aSGreg Roach    /** @var TreeService */
33*5afbc57aSGreg Roach    private $tree_service;
34*5afbc57aSGreg Roach
35*5afbc57aSGreg Roach    /**
36*5afbc57aSGreg Roach     * CreateTreePage constructor.
37*5afbc57aSGreg Roach     *
38*5afbc57aSGreg Roach     * @param TreeService $tree_service
39*5afbc57aSGreg Roach     */
40*5afbc57aSGreg Roach    public function __construct(TreeService $tree_service)
41*5afbc57aSGreg Roach    {
42*5afbc57aSGreg Roach        $this->tree_service = $tree_service;
43*5afbc57aSGreg Roach    }
44*5afbc57aSGreg Roach
45*5afbc57aSGreg Roach    /**
46*5afbc57aSGreg Roach     * @param ServerRequestInterface $request
47*5afbc57aSGreg Roach     *
48*5afbc57aSGreg Roach     * @return ResponseInterface
49*5afbc57aSGreg Roach     */
50*5afbc57aSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
51*5afbc57aSGreg Roach    {
52*5afbc57aSGreg Roach        $this->layout = 'layouts/administration';
53*5afbc57aSGreg Roach
54*5afbc57aSGreg Roach        $title      = I18N::translate('Create a family tree');
55*5afbc57aSGreg Roach        $tree_name  = $request->getQueryParams()['name'] ?? $this->tree_service->uniqueTreeName();
56*5afbc57aSGreg Roach        $tree_title = $request->getQueryParams()['title'] ?? I18N::translate('My family tree');
57*5afbc57aSGreg Roach
58*5afbc57aSGreg Roach        return $this->viewResponse('admin/trees-create', [
59*5afbc57aSGreg Roach            'title'      => $title,
60*5afbc57aSGreg Roach            'tree_name'  => $tree_name,
61*5afbc57aSGreg Roach            'tree_title' => $tree_title,
62*5afbc57aSGreg Roach        ]);
63*5afbc57aSGreg Roach    }
64*5afbc57aSGreg Roach}
65