1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* webtrees: online genealogy |
5
|
|
|
* Copyright (C) 2021 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
|
|
|
|
18
|
|
|
declare(strict_types=1); |
19
|
|
|
|
20
|
|
|
namespace Fisharebest\Webtrees\Http\RequestHandlers; |
21
|
|
|
|
22
|
|
|
use Fisharebest\Webtrees\Auth; |
23
|
|
|
use Fisharebest\Webtrees\Family; |
24
|
|
|
use Fisharebest\Webtrees\Header; |
25
|
|
|
use Fisharebest\Webtrees\Http\ViewResponseTrait; |
26
|
|
|
use Fisharebest\Webtrees\Individual; |
27
|
|
|
use Fisharebest\Webtrees\Location; |
28
|
|
|
use Fisharebest\Webtrees\Media; |
29
|
|
|
use Fisharebest\Webtrees\Note; |
30
|
|
|
use Fisharebest\Webtrees\Registry; |
31
|
|
|
use Fisharebest\Webtrees\Repository; |
32
|
|
|
use Fisharebest\Webtrees\Services\ClipboardService; |
33
|
|
|
use Fisharebest\Webtrees\Services\LinkedRecordService; |
34
|
|
|
use Fisharebest\Webtrees\Source; |
35
|
|
|
use Fisharebest\Webtrees\Submission; |
36
|
|
|
use Fisharebest\Webtrees\Submitter; |
37
|
|
|
use Fisharebest\Webtrees\Validator; |
38
|
|
|
use Illuminate\Support\Collection; |
39
|
|
|
use Psr\Http\Message\ResponseInterface; |
40
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
41
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Display non-standard genealogy records. |
45
|
|
|
*/ |
46
|
|
|
class GedcomRecordPage implements RequestHandlerInterface |
47
|
|
|
{ |
48
|
|
|
use ViewResponseTrait; |
49
|
|
|
|
50
|
|
|
// These standard genealogy record types have their own pages. |
51
|
|
|
private const STANDARD_RECORDS = [ |
52
|
|
|
Family::class, |
53
|
|
|
Header::class, |
54
|
|
|
Individual::class, |
55
|
|
|
Location::class, |
56
|
|
|
Media::class, |
57
|
|
|
Note::class, |
58
|
|
|
Repository::class, |
59
|
|
|
Source::class, |
60
|
|
|
Submission::class, |
61
|
|
|
Submitter::class, |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
private ClipboardService $clipboard_service; |
65
|
|
|
|
66
|
|
|
private LinkedRecordService $linked_record_service; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @param ClipboardService $clipboard_service |
70
|
|
|
* @param LinkedRecordService $linked_record_service |
71
|
|
|
*/ |
72
|
|
|
public function __construct(ClipboardService $clipboard_service, LinkedRecordService $linked_record_service) |
73
|
|
|
{ |
74
|
|
|
$this->clipboard_service = $clipboard_service; |
75
|
|
|
$this->linked_record_service = $linked_record_service; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Show a gedcom record's page. |
80
|
|
|
* |
81
|
|
|
* @param ServerRequestInterface $request |
82
|
|
|
* |
83
|
|
|
* @return ResponseInterface |
84
|
|
|
*/ |
85
|
|
|
public function handle(ServerRequestInterface $request): ResponseInterface |
86
|
|
|
{ |
87
|
|
|
$tree = Validator::attributes($request)->tree(); |
88
|
|
|
$xref = Validator::attributes($request)->isXref()->string('xref'); |
89
|
|
|
$record = Registry::gedcomRecordFactory()->make($xref, $tree); |
90
|
|
|
$record = Auth::checkRecordAccess($record); |
91
|
|
|
|
92
|
|
|
// Standard genealogy records have their own pages. |
93
|
|
|
if ($record->xref() !== $xref || in_array(get_class($record), self::STANDARD_RECORDS, true)) { |
94
|
|
|
return Registry::responseFactory()->redirectUrl($record->url()); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$linked_families = $this->linked_record_service->linkedFamilies($record); |
98
|
|
|
$linked_individuals = $this->linked_record_service->linkedIndividuals($record); |
99
|
|
|
$linked_locations = $this->linked_record_service->linkedLocations($record); |
100
|
|
|
$linked_media = $this->linked_record_service->linkedMedia($record); |
101
|
|
|
$linked_notes = $this->linked_record_service->linkedNotes($record); |
102
|
|
|
$linked_repositories = $this->linked_record_service->linkedRepositories($record); |
103
|
|
|
$linked_sources = $this->linked_record_service->linkedSources($record); |
104
|
|
|
$linked_submitters = $this->linked_record_service->linkedSubmitters($record); |
105
|
|
|
|
106
|
|
|
return $this->viewResponse('record-page', [ |
107
|
|
|
'clipboard_facts' => $this->clipboard_service->pastableFacts($record), |
108
|
|
|
'linked_families' => $linked_families->isEmpty() ? null : $linked_families, |
109
|
|
|
'linked_individuals' => $linked_individuals->isEmpty() ? null : $linked_individuals, |
110
|
|
|
'linked_locations' => $linked_locations->isEmpty() ? null : $linked_locations, |
111
|
|
|
'linked_media_objects' => $linked_media->isEmpty() ? null : $linked_media, |
112
|
|
|
'linked_notes' => $linked_notes->isEmpty() ? null : $linked_notes, |
113
|
|
|
'linked_repositories' => $linked_repositories->isEmpty() ? null : $linked_repositories, |
114
|
|
|
'linked_sources' => $linked_sources->isEmpty() ? null : $linked_sources, |
115
|
|
|
'linked_submitters' => $linked_submitters->isEmpty() ? null : $linked_submitters, |
116
|
|
|
'record' => $record, |
117
|
|
|
'title' => $record->fullName(), |
118
|
|
|
'tree' => $tree, |
119
|
|
|
]); |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
|