xref: /webtrees/app/Http/RequestHandlers/SearchGeneralAction.php (revision 058ba7243339e0f2f5f84aa0f772e56ee5252797)
1f5402f3dSGreg Roach<?php
2f5402f3dSGreg Roach
3f5402f3dSGreg Roach/**
4f5402f3dSGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
6f5402f3dSGreg Roach * This program is free software: you can redistribute it and/or modify
7f5402f3dSGreg Roach * it under the terms of the GNU General Public License as published by
8f5402f3dSGreg Roach * the Free Software Foundation, either version 3 of the License, or
9f5402f3dSGreg Roach * (at your option) any later version.
10f5402f3dSGreg Roach * This program is distributed in the hope that it will be useful,
11f5402f3dSGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12f5402f3dSGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13f5402f3dSGreg Roach * GNU General Public License for more details.
14f5402f3dSGreg 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/>.
16f5402f3dSGreg Roach */
17f5402f3dSGreg Roach
18f5402f3dSGreg Roachdeclare(strict_types=1);
19f5402f3dSGreg Roach
20f5402f3dSGreg Roachnamespace Fisharebest\Webtrees\Http\RequestHandlers;
21f5402f3dSGreg Roach
22f5402f3dSGreg Roachuse Fisharebest\Webtrees\Tree;
23f5402f3dSGreg Roachuse Psr\Http\Message\ResponseInterface;
24f5402f3dSGreg Roachuse Psr\Http\Message\ServerRequestInterface;
25f5402f3dSGreg Roachuse Psr\Http\Server\RequestHandlerInterface;
26f5402f3dSGreg Roach
27f5402f3dSGreg Roachuse function assert;
28f5402f3dSGreg Roach
29f5402f3dSGreg Roach/**
30f5402f3dSGreg Roach * Search for genealogy data
31f5402f3dSGreg Roach */
32f5402f3dSGreg Roachclass SearchGeneralAction implements RequestHandlerInterface
33f5402f3dSGreg Roach{
34f5402f3dSGreg Roach    /**
35f5402f3dSGreg Roach     * The standard search.
36f5402f3dSGreg Roach     *
37f5402f3dSGreg Roach     * @param ServerRequestInterface $request
38f5402f3dSGreg Roach     *
39f5402f3dSGreg Roach     * @return ResponseInterface
40f5402f3dSGreg Roach     */
41f5402f3dSGreg Roach    public function handle(ServerRequestInterface $request): ResponseInterface
42f5402f3dSGreg Roach    {
43f5402f3dSGreg Roach        $tree = $request->getAttribute('tree');
4475964c75SGreg Roach        assert($tree instanceof Tree);
45f5402f3dSGreg Roach
46b46c87bdSGreg Roach        $params = (array) $request->getParsedBody();
47f5402f3dSGreg Roach
48f5402f3dSGreg Roach        return redirect(route(SearchGeneralPage::class, [
49f5402f3dSGreg Roach            'query'               => $params['query'] ?? '',
50f5402f3dSGreg Roach            'search_families'     => (bool) ($params['search_families'] ?? false),
51*058ba724SGreg Roach            'search_individuals'  => (bool) ($params['search_individuals'] ?? false),
52*058ba724SGreg Roach            'search_locations'    => (bool) ($params['search_locations'] ?? false),
53*058ba724SGreg Roach            'search_notes'        => (bool) ($params['search_notes'] ?? false),
54f5402f3dSGreg Roach            'search_repositories' => (bool) ($params['search_repositories'] ?? false),
55f5402f3dSGreg Roach            'search_sources'      => (bool) ($params['search_sources'] ?? false),
56f5402f3dSGreg Roach            'search_trees'        => $params['search_trees'] ?? [],
57f5402f3dSGreg Roach            'tree'                => $tree->name(),
58f5402f3dSGreg Roach        ]));
59f5402f3dSGreg Roach    }
60f5402f3dSGreg Roach}
61