xref: /webtrees/app/Http/RequestHandlers/SubmitterPage.php (revision fdfa4a42b488cb6df3ddfb1ec5ad61cd51f2cf51)
1<?php
2
3/**
4 * webtrees: online genealogy
5 * Copyright (C) 2022 webtrees development team
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
18declare(strict_types=1);
19
20namespace Fisharebest\Webtrees\Http\RequestHandlers;
21
22use Fig\Http\Message\StatusCodeInterface;
23use Fisharebest\Webtrees\Auth;
24use Fisharebest\Webtrees\Http\ViewResponseTrait;
25use Fisharebest\Webtrees\Registry;
26use Fisharebest\Webtrees\Services\ClipboardService;
27use Fisharebest\Webtrees\Services\LinkedRecordService;
28use Fisharebest\Webtrees\Validator;
29use Illuminate\Support\Collection;
30use Psr\Http\Message\ResponseInterface;
31use Psr\Http\Message\ServerRequestInterface;
32use Psr\Http\Server\RequestHandlerInterface;
33
34use function redirect;
35
36/**
37 * Show a submitter's page.
38 */
39class SubmitterPage implements RequestHandlerInterface
40{
41    use ViewResponseTrait;
42
43    private ClipboardService $clipboard_service;
44
45    private LinkedRecordService $linked_record_service;
46
47    /**
48     * @param ClipboardService $clipboard_service
49     * @param LinkedRecordService $linked_record_service
50     */
51    public function __construct(ClipboardService $clipboard_service, LinkedRecordService $linked_record_service)
52    {
53        $this->clipboard_service     = $clipboard_service;
54        $this->linked_record_service = $linked_record_service;
55    }
56
57    /**
58     * @param ServerRequestInterface $request
59     *
60     * @return ResponseInterface
61     */
62    public function handle(ServerRequestInterface $request): ResponseInterface
63    {
64        $tree   = Validator::attributes($request)->tree();
65        $xref   = Validator::attributes($request)->isXref()->string('xref');
66        $slug   = Validator::attributes($request)->string('slug', '');
67        $record = Registry::submitterFactory()->make($xref, $tree);
68        $record = Auth::checkSubmitterAccess($record, false);
69
70        // Redirect to correct xref/slug
71        if ($record->xref() !== $xref || Registry::slugFactory()->make($record) !== $slug) {
72            return redirect($record->url(), StatusCodeInterface::STATUS_MOVED_PERMANENTLY);
73        }
74
75        return $this->viewResponse('record-page', [
76            'clipboard_facts'      => $this->clipboard_service->pastableFacts($record),
77            'linked_families'      => $this->linked_record_service->linkedFamilies($record),
78            'linked_individuals'   => $this->linked_record_service->linkedIndividuals($record),
79            'linked_locations'     => null,
80            'linked_media_objects' => null,
81            'linked_notes'         => null,
82            'linked_repositories'  => null,
83            'linked_sources'       => null,
84            'linked_submitters'    => null,
85            'meta_description'     => '',
86            'meta_robots'          => 'index,follow',
87            'record'               => $record,
88            'title'                => $record->fullName(),
89            'tree'                 => $tree,
90        ]);
91    }
92}
93