xref: /webtrees/app/Http/RequestHandlers/CreateTreePage.php (revision e93a8df2f8d797005750082cc3766c0e80799688)
15afbc57aSGreg Roach<?php
25afbc57aSGreg Roach
35afbc57aSGreg Roach/**
45afbc57aSGreg Roach * webtrees: online genealogy
5*d11be702SGreg Roach * Copyright (C) 2023 webtrees development team
65afbc57aSGreg Roach * This program is free software: you can redistribute it and/or modify
75afbc57aSGreg Roach * it under the terms of the GNU General Public License as published by
85afbc57aSGreg Roach * the Free Software Foundation, either version 3 of the License, or
95afbc57aSGreg Roach * (at your option) any later version.
105afbc57aSGreg Roach * This program is distributed in the hope that it will be useful,
115afbc57aSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
125afbc57aSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
135afbc57aSGreg Roach * GNU General Public License for more details.
145afbc57aSGreg 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/>.
165afbc57aSGreg Roach */
17fcfa147eSGreg Roach
185afbc57aSGreg Roachdeclare(strict_types=1);
195afbc57aSGreg Roach
205afbc57aSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
215afbc57aSGreg Roach
2298b7e8b3SGreg Roachuse Fisharebest\Webtrees\Http\ViewResponseTrait;
235afbc57aSGreg Roachuse Fisharebest\Webtrees\I18N;
245afbc57aSGreg Roachuse Fisharebest\Webtrees\Services\TreeService;
25748dbe15SGreg Roachuse Fisharebest\Webtrees\Validator;
265afbc57aSGreg Roachuse Psr\Http\Message\ResponseInterface;
275afbc57aSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
2898b7e8b3SGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
295afbc57aSGreg Roach
305afbc57aSGreg Roach/**
315afbc57aSGreg Roach * Show a form to create a new tree.
325afbc57aSGreg Roach */
3398b7e8b3SGreg Roachclass CreateTreePage implements RequestHandlerInterface
345afbc57aSGreg Roach{
3598b7e8b3SGreg Roach    use ViewResponseTrait;
3698b7e8b3SGreg Roach
37c4943cffSGreg Roach    private TreeService $tree_service;
385afbc57aSGreg Roach
395afbc57aSGreg Roach    /**
405afbc57aSGreg Roach     * @param TreeService $tree_service
415afbc57aSGreg Roach     */
425afbc57aSGreg Roach    public function __construct(TreeService $tree_service)
435afbc57aSGreg Roach    {
445afbc57aSGreg Roach        $this->tree_service = $tree_service;
455afbc57aSGreg Roach    }
465afbc57aSGreg Roach
475afbc57aSGreg Roach    /**
485afbc57aSGreg Roach     * @param ServerRequestInterface $request
495afbc57aSGreg Roach     *
505afbc57aSGreg Roach     * @return ResponseInterface
515afbc57aSGreg Roach     */
525afbc57aSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
535afbc57aSGreg Roach    {
545afbc57aSGreg Roach        $this->layout = 'layouts/administration';
555afbc57aSGreg Roach
565afbc57aSGreg Roach        $title      = I18N::translate('Create a family tree');
57748dbe15SGreg Roach        $tree_name  = Validator::queryParams($request)->string('name', $this->tree_service->uniqueTreeName());
58748dbe15SGreg Roach        $tree_title = Validator::queryParams($request)->string('title', I18N::translate('My family tree'));
595afbc57aSGreg Roach
605afbc57aSGreg Roach        return $this->viewResponse('admin/trees-create', [
615afbc57aSGreg Roach            'title'      => $title,
625afbc57aSGreg Roach            'tree_name'  => $tree_name,
635afbc57aSGreg Roach            'tree_title' => $tree_title,
645afbc57aSGreg Roach        ]);
655afbc57aSGreg Roach    }
665afbc57aSGreg Roach}
67