|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* webtrees: online genealogy |
|
4
|
|
|
* Copyright (C) 2018 webtrees development team |
|
5
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
6
|
|
|
* it under the terms of the GNU General Public License as published by |
|
7
|
|
|
* the Free Software Foundation, either version 3 of the License, or |
|
8
|
|
|
* (at your option) any later version. |
|
9
|
|
|
* This program is distributed in the hope that it will be useful, |
|
10
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12
|
|
|
* GNU General Public License for more details. |
|
13
|
|
|
* You should have received a copy of the GNU General Public License |
|
14
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
15
|
|
|
*/ |
|
16
|
|
|
declare(strict_types=1); |
|
17
|
|
|
|
|
18
|
|
|
namespace Fisharebest\Webtrees\Http\Controllers; |
|
19
|
|
|
|
|
20
|
|
|
use Fisharebest\Webtrees\I18N; |
|
21
|
|
|
use Fisharebest\Webtrees\Individual; |
|
22
|
|
|
use Fisharebest\Webtrees\Tree; |
|
23
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
24
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
25
|
|
|
use Symfony\Component\HttpFoundation\Response; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Controller for edit forms and responses. |
|
29
|
|
|
*/ |
|
30
|
|
|
class EditIndividualController extends BaseController { |
|
31
|
|
|
/** |
|
32
|
|
|
* @param Request $request |
|
33
|
|
|
* |
|
34
|
|
|
* @return Response |
|
35
|
|
|
*/ |
|
36
|
|
|
public function reorderMedia(Request $request): Response { |
|
37
|
|
|
/** @var Tree $tree */ |
|
38
|
|
|
$tree = $request->attributes->get('tree'); |
|
39
|
|
|
$xref = $request->get('xref'); |
|
40
|
|
|
$individual = Individual::getInstance($xref, $tree); |
|
41
|
|
|
|
|
42
|
|
|
if ($individual === null) { |
|
43
|
|
|
return $this->individualNotFound(); |
|
44
|
|
|
} elseif (!$individual->canEdit()) { |
|
45
|
|
|
return $this->individualNotAllowed(); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
$title = $individual->getFullName() . ' — ' . I18N::translate('Re-order media'); |
|
49
|
|
|
|
|
50
|
|
|
return $this->viewResponse('edit/reorder-media', [ |
|
51
|
|
|
'title' => $title, |
|
52
|
|
|
'individual' => $individual, |
|
53
|
|
|
]); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param Request $request |
|
58
|
|
|
* |
|
59
|
|
|
* @return Response |
|
60
|
|
|
*/ |
|
61
|
|
|
public function reorderMediaAction(Request $request): Response { |
|
62
|
|
|
/** @var Tree $tree */ |
|
63
|
|
|
$tree = $request->attributes->get('tree'); |
|
64
|
|
|
$xref = $request->get('xref'); |
|
65
|
|
|
$order = (array) $request->get('order', []); |
|
66
|
|
|
$individual = Individual::getInstance($xref, $tree); |
|
67
|
|
|
|
|
68
|
|
|
if ($individual === null) { |
|
69
|
|
|
return $this->individualNotFound(); |
|
70
|
|
|
} elseif (!$individual->canEdit()) { |
|
71
|
|
|
return $this->individualNotAllowed(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$dummy_facts = ['0 @' . $individual->getXref() . '@ INDI']; |
|
75
|
|
|
$sort_facts = []; |
|
76
|
|
|
$keep_facts = []; |
|
77
|
|
|
|
|
78
|
|
|
// Split facts into OBJE and other |
|
79
|
|
|
foreach ($individual->getFacts() as $fact) { |
|
80
|
|
|
if ($fact->getTag() === 'OBJE') { |
|
81
|
|
|
$sort_facts[$fact->getFactId()] = $fact->getGedcom(); |
|
82
|
|
|
} else { |
|
83
|
|
|
$keep_facts[] = $fact->getGedcom(); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
// Sort the facts |
|
88
|
|
|
uksort($sort_facts, function ($x, $y) use ($order) { |
|
89
|
|
|
return array_search($x, $order) - array_search($y, $order); |
|
90
|
|
|
}); |
|
91
|
|
|
|
|
92
|
|
|
// Merge the facts |
|
93
|
|
|
$gedcom = implode("\n", array_merge($dummy_facts, $sort_facts, $keep_facts)); |
|
94
|
|
|
|
|
95
|
|
|
$individual->updateRecord($gedcom, false); |
|
96
|
|
|
|
|
97
|
|
|
return new RedirectResponse($individual->url()); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* @param Request $request |
|
102
|
|
|
* |
|
103
|
|
|
* @return Response |
|
104
|
|
|
*/ |
|
105
|
|
|
public function reorderNames(Request $request): Response { |
|
106
|
|
|
/** @var Tree $tree */ |
|
107
|
|
|
$tree = $request->attributes->get('tree'); |
|
108
|
|
|
$xref = $request->get('xref'); |
|
109
|
|
|
$individual = Individual::getInstance($xref, $tree); |
|
110
|
|
|
|
|
111
|
|
|
if ($individual === null) { |
|
112
|
|
|
return $this->individualNotFound(); |
|
113
|
|
|
} elseif (!$individual->canEdit()) { |
|
114
|
|
|
return $this->individualNotAllowed(); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$title = $individual->getFullName() . ' — ' . I18N::translate('Re-order names'); |
|
118
|
|
|
|
|
119
|
|
|
return $this->viewResponse('edit/reorder-names', [ |
|
120
|
|
|
'title' => $title, |
|
121
|
|
|
'individual' => $individual, |
|
122
|
|
|
]); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* @param Request $request |
|
127
|
|
|
* |
|
128
|
|
|
* @return Response |
|
129
|
|
|
*/ |
|
130
|
|
|
public function reorderNamesAction(Request $request): Response { |
|
131
|
|
|
/** @var Tree $tree */ |
|
132
|
|
|
$tree = $request->attributes->get('tree'); |
|
133
|
|
|
$xref = $request->get('xref'); |
|
134
|
|
|
$order = (array) $request->get('order', []); |
|
135
|
|
|
$individual = Individual::getInstance($xref, $tree); |
|
136
|
|
|
|
|
137
|
|
|
if ($individual === null) { |
|
138
|
|
|
return $this->individualNotFound(); |
|
139
|
|
|
} elseif (!$individual->canEdit()) { |
|
140
|
|
|
return $this->individualNotAllowed(); |
|
141
|
|
|
} |
|
142
|
|
|
|
|
143
|
|
|
$dummy_facts = ['0 @' . $individual->getXref() . '@ INDI']; |
|
144
|
|
|
$sort_facts = []; |
|
145
|
|
|
$keep_facts = []; |
|
146
|
|
|
|
|
147
|
|
|
// Split facts into NAME and other |
|
148
|
|
|
foreach ($individual->getFacts() as $fact) { |
|
149
|
|
|
if ($fact->getTag() === 'NAME') { |
|
150
|
|
|
$sort_facts[$fact->getFactId()] = $fact->getGedcom(); |
|
151
|
|
|
} else { |
|
152
|
|
|
$keep_facts[] = $fact->getGedcom(); |
|
153
|
|
|
} |
|
154
|
|
|
} |
|
155
|
|
|
|
|
156
|
|
|
// Sort the facts |
|
157
|
|
|
uksort($sort_facts, function ($x, $y) use ($order) { |
|
158
|
|
|
return array_search($x, $order) - array_search($y, $order); |
|
159
|
|
|
}); |
|
160
|
|
|
|
|
161
|
|
|
// Merge the facts |
|
162
|
|
|
$gedcom = implode("\n", array_merge($dummy_facts, $sort_facts, $keep_facts)); |
|
163
|
|
|
|
|
164
|
|
|
$individual->updateRecord($gedcom, false); |
|
165
|
|
|
|
|
166
|
|
|
return new RedirectResponse($individual->url()); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* @param Request $request |
|
171
|
|
|
* |
|
172
|
|
|
* @return Response |
|
173
|
|
|
*/ |
|
174
|
|
|
public function reorderSpouses(Request $request): Response { |
|
175
|
|
|
/** @var Tree $tree */ |
|
176
|
|
|
$tree = $request->attributes->get('tree'); |
|
177
|
|
|
$xref = $request->get('xref'); |
|
178
|
|
|
$individual = Individual::getInstance($xref, $tree); |
|
179
|
|
|
|
|
180
|
|
|
if ($individual === null) { |
|
181
|
|
|
return $this->individualNotFound(); |
|
182
|
|
|
} elseif (!$individual->canEdit()) { |
|
183
|
|
|
return $this->individualNotAllowed(); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
$title = $individual->getFullName() . ' — ' . I18N::translate('Re-order families'); |
|
187
|
|
|
|
|
188
|
|
|
return $this->viewResponse('edit/reorder-spouses', [ |
|
189
|
|
|
'title' => $title, |
|
190
|
|
|
'individual' => $individual, |
|
191
|
|
|
]); |
|
192
|
|
|
} |
|
193
|
|
|
|
|
194
|
|
|
/** |
|
195
|
|
|
* @param Request $request |
|
196
|
|
|
* |
|
197
|
|
|
* @return Response |
|
198
|
|
|
*/ |
|
199
|
|
|
public function reorderSpousesAction(Request $request): Response { |
|
200
|
|
|
/** @var Tree $tree */ |
|
201
|
|
|
$tree = $request->attributes->get('tree'); |
|
202
|
|
|
$xref = $request->get('xref'); |
|
203
|
|
|
$order = (array) $request->get('order', []); |
|
204
|
|
|
$individual = Individual::getInstance($xref, $tree); |
|
205
|
|
|
|
|
206
|
|
|
if ($individual === null) { |
|
207
|
|
|
return $this->individualNotFound(); |
|
208
|
|
|
} elseif (!$individual->canEdit()) { |
|
209
|
|
|
return $this->individualNotAllowed(); |
|
210
|
|
|
} |
|
211
|
|
|
|
|
212
|
|
|
$dummy_facts = ['0 @' . $individual->getXref() . '@ INDI']; |
|
213
|
|
|
$sort_facts = []; |
|
214
|
|
|
$keep_facts = []; |
|
215
|
|
|
|
|
216
|
|
|
// Split facts into FAMS and other |
|
217
|
|
|
foreach ($individual->getFacts() as $fact) { |
|
218
|
|
|
if ($fact->getTag() === 'FAMS') { |
|
219
|
|
|
$sort_facts[$fact->getFactId()] = $fact->getGedcom(); |
|
220
|
|
|
} else { |
|
221
|
|
|
$keep_facts[] = $fact->getGedcom(); |
|
222
|
|
|
} |
|
223
|
|
|
} |
|
224
|
|
|
|
|
225
|
|
|
// Sort the facts |
|
226
|
|
|
uksort($sort_facts, function ($x, $y) use ($order) { |
|
227
|
|
|
return array_search($x, $order) - array_search($y, $order); |
|
228
|
|
|
}); |
|
229
|
|
|
|
|
230
|
|
|
// Merge the facts |
|
231
|
|
|
$gedcom = implode("\n", array_merge($dummy_facts, $sort_facts, $keep_facts)); |
|
232
|
|
|
|
|
233
|
|
|
$individual->updateRecord($gedcom, false); |
|
234
|
|
|
|
|
235
|
|
|
return new RedirectResponse($individual->url()); |
|
236
|
|
|
} |
|
237
|
|
|
} |
|
238
|
|
|
|