Total Complexity | 96 |
Total Lines | 831 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like IndividualFactsService often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use IndividualFactsService, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | class IndividualFactsService |
||
39 | { |
||
40 | private LinkedRecordService $linked_record_service; |
||
41 | |||
42 | private ModuleService $module_service; |
||
43 | |||
44 | /** |
||
45 | * @param LinkedRecordService $linked_record_service |
||
46 | * @param ModuleService $module_service |
||
47 | */ |
||
48 | public function __construct( |
||
49 | LinkedRecordService $linked_record_service, |
||
50 | ModuleService $module_service |
||
51 | ) { |
||
52 | $this->linked_record_service = $linked_record_service; |
||
53 | $this->module_service = $module_service; |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * The individuals own facts, such as birth and death. |
||
58 | * |
||
59 | * @param Individual $individual |
||
60 | * @param Collection<int,string> $exclude_facts |
||
61 | * |
||
62 | * @return Collection<int,Fact> |
||
63 | */ |
||
64 | public function individualFacts(Individual $individual, Collection $exclude_facts): Collection |
||
65 | { |
||
66 | return $individual->facts() |
||
67 | ->filter(fn (Fact $fact): bool => !$exclude_facts->contains($fact->tag())); |
||
68 | } |
||
69 | |||
70 | /** |
||
71 | * The individuals own family facts, such as marriage and divorce. |
||
72 | * |
||
73 | * @param Individual $individual |
||
74 | * @param Collection<int,string> $exclude_facts |
||
75 | * |
||
76 | * @return Collection<int,Fact> |
||
77 | */ |
||
78 | public function familyFacts(Individual $individual, Collection $exclude_facts): Collection |
||
79 | { |
||
80 | return $individual->spouseFamilies() |
||
81 | ->map(fn (Family $family): Collection => $family->facts()) |
||
82 | ->flatten() |
||
83 | ->filter(fn (Fact $fact): bool => !$exclude_facts->contains($fact->tag())); |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * Get the events of associates. |
||
88 | * |
||
89 | * @param Individual $individual |
||
90 | * |
||
91 | * @return Collection<int,Fact> |
||
92 | */ |
||
93 | public function associateFacts(Individual $individual): Collection |
||
94 | { |
||
95 | $facts = []; |
||
96 | |||
97 | $asso1 = $this->linked_record_service->linkedIndividuals($individual, 'ASSO'); |
||
98 | $asso2 = $this->linked_record_service->linkedIndividuals($individual, '_ASSO'); |
||
99 | $asso3 = $this->linked_record_service->linkedFamilies($individual, 'ASSO'); |
||
100 | $asso4 = $this->linked_record_service->linkedFamilies($individual, '_ASSO'); |
||
101 | |||
102 | $associates = $asso1->merge($asso2)->merge($asso3)->merge($asso4); |
||
103 | |||
104 | foreach ($associates as $associate) { |
||
105 | foreach ($associate->facts() as $fact) { |
||
106 | if (preg_match('/\n\d _?ASSO @' . $individual->xref() . '@/', $fact->gedcom())) { |
||
107 | // Extract the important details from the fact |
||
108 | $factrec = explode("\n", $fact->gedcom(), 2)[0]; |
||
109 | if (preg_match('/\n2 DATE .*/', $fact->gedcom(), $match)) { |
||
110 | $factrec .= $match[0]; |
||
111 | } |
||
112 | if (preg_match('/\n2 PLAC .*/', $fact->gedcom(), $match)) { |
||
113 | $factrec .= $match[0]; |
||
114 | } |
||
115 | if ($associate instanceof Family) { |
||
116 | foreach ($associate->spouses() as $spouse) { |
||
117 | $factrec .= "\n2 _ASSO @" . $spouse->xref() . '@'; |
||
118 | } |
||
119 | } else { |
||
120 | $factrec .= "\n2 _ASSO @" . $associate->xref() . '@'; |
||
121 | } |
||
122 | $facts[] = new Fact($factrec, $associate, 'asso'); |
||
123 | } |
||
124 | } |
||
125 | } |
||
126 | |||
127 | return new Collection($facts); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * Get the events of close relatives. |
||
132 | * |
||
133 | * @param Individual $individual |
||
134 | * |
||
135 | * @return Collection<int,Fact> |
||
136 | */ |
||
137 | public function relativeFacts(Individual $individual): Collection |
||
138 | { |
||
139 | // Only include events of close relatives that are between birth and death |
||
140 | $min_date = $individual->getEstimatedBirthDate(); |
||
141 | $max_date = $individual->getEstimatedDeathDate(); |
||
142 | |||
143 | $parent_facts = $this->parentFacts($individual, 1, $min_date, $max_date); |
||
144 | |||
145 | $spouse_facts = $individual->spouseFamilies() |
||
146 | ->filter(fn (Family $family): bool => $family->spouse($individual) instanceof Individual) |
||
147 | ->map(fn (Family $family): Collection => $this->spouseFacts($individual, $family->spouse($individual), $min_date, $max_date)) |
||
|
|||
148 | ->flatten(); |
||
149 | |||
150 | $child_facts = $individual->spouseFamilies() |
||
151 | ->map(fn (Family $family): Collection => $this->childFacts($individual, $family, '_CHIL', '', $min_date, $max_date)) |
||
152 | ->flatten(); |
||
153 | |||
154 | return $parent_facts |
||
155 | ->merge($child_facts) |
||
156 | ->merge($spouse_facts) |
||
157 | ->unique(); |
||
158 | } |
||
159 | |||
160 | /** |
||
161 | * Get any historical events. |
||
162 | * |
||
163 | * @param Individual $individual |
||
164 | * |
||
165 | * @return Collection<int,Fact> |
||
166 | */ |
||
167 | public function historicFacts(Individual $individual): Collection |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * Get the events of children and grandchildren. |
||
178 | * |
||
179 | * @param Individual $person |
||
180 | * @param Family $family |
||
181 | * @param string $option |
||
182 | * @param string $relation |
||
183 | * @param Date $min_date |
||
184 | * @param Date $max_date |
||
185 | * |
||
186 | * @return Collection<int,Fact> |
||
187 | */ |
||
188 | private function childFacts(Individual $person, Family $family, string $option, string $relation, Date $min_date, Date $max_date): Collection |
||
189 | { |
||
190 | $SHOW_RELATIVES_EVENTS = $person->tree()->getPreference('SHOW_RELATIVES_EVENTS'); |
||
191 | |||
192 | $birth_of_a_child = [ |
||
193 | 'INDI:BIRT' => [ |
||
194 | 'M' => I18N::translate('Birth of a son'), |
||
195 | 'F' => I18N::translate('Birth of a daughter'), |
||
196 | 'U' => I18N::translate('Birth of a child'), |
||
197 | ], |
||
198 | 'INDI:CHR' => [ |
||
199 | 'M' => I18N::translate('Christening of a son'), |
||
200 | 'F' => I18N::translate('Christening of a daughter'), |
||
201 | 'U' => I18N::translate('Christening of a child'), |
||
202 | ], |
||
203 | 'INDI:BAPM' => [ |
||
204 | 'M' => I18N::translate('Baptism of a son'), |
||
205 | 'F' => I18N::translate('Baptism of a daughter'), |
||
206 | 'U' => I18N::translate('Baptism of a child'), |
||
207 | ], |
||
208 | 'INDI:ADOP' => [ |
||
209 | 'M' => I18N::translate('Adoption of a son'), |
||
210 | 'F' => I18N::translate('Adoption of a daughter'), |
||
211 | 'U' => I18N::translate('Adoption of a child'), |
||
212 | ], |
||
213 | ]; |
||
214 | |||
215 | $birth_of_a_sibling = [ |
||
216 | 'INDI:BIRT' => [ |
||
217 | 'M' => I18N::translate('Birth of a brother'), |
||
218 | 'F' => I18N::translate('Birth of a sister'), |
||
219 | 'U' => I18N::translate('Birth of a sibling'), |
||
220 | ], |
||
221 | 'INDI:CHR' => [ |
||
222 | 'M' => I18N::translate('Christening of a brother'), |
||
223 | 'F' => I18N::translate('Christening of a sister'), |
||
224 | 'U' => I18N::translate('Christening of a sibling'), |
||
225 | ], |
||
226 | 'INDI:BAPM' => [ |
||
227 | 'M' => I18N::translate('Baptism of a brother'), |
||
228 | 'F' => I18N::translate('Baptism of a sister'), |
||
229 | 'U' => I18N::translate('Baptism of a sibling'), |
||
230 | ], |
||
231 | 'INDI:ADOP' => [ |
||
232 | 'M' => I18N::translate('Adoption of a brother'), |
||
233 | 'F' => I18N::translate('Adoption of a sister'), |
||
234 | 'U' => I18N::translate('Adoption of a sibling'), |
||
235 | ], |
||
236 | ]; |
||
237 | |||
238 | $birth_of_a_half_sibling = [ |
||
239 | 'INDI:BIRT' => [ |
||
240 | 'M' => I18N::translate('Birth of a half-brother'), |
||
241 | 'F' => I18N::translate('Birth of a half-sister'), |
||
242 | 'U' => I18N::translate('Birth of a half-sibling'), |
||
243 | ], |
||
244 | 'INDI:CHR' => [ |
||
245 | 'M' => I18N::translate('Christening of a half-brother'), |
||
246 | 'F' => I18N::translate('Christening of a half-sister'), |
||
247 | 'U' => I18N::translate('Christening of a half-sibling'), |
||
248 | ], |
||
249 | 'INDI:BAPM' => [ |
||
250 | 'M' => I18N::translate('Baptism of a half-brother'), |
||
251 | 'F' => I18N::translate('Baptism of a half-sister'), |
||
252 | 'U' => I18N::translate('Baptism of a half-sibling'), |
||
253 | ], |
||
254 | 'INDI:ADOP' => [ |
||
255 | 'M' => I18N::translate('Adoption of a half-brother'), |
||
256 | 'F' => I18N::translate('Adoption of a half-sister'), |
||
257 | 'U' => I18N::translate('Adoption of a half-sibling'), |
||
258 | ], |
||
259 | ]; |
||
260 | |||
261 | $birth_of_a_grandchild = [ |
||
262 | 'INDI:BIRT' => [ |
||
263 | 'M' => I18N::translate('Birth of a grandson'), |
||
264 | 'F' => I18N::translate('Birth of a granddaughter'), |
||
265 | 'U' => I18N::translate('Birth of a grandchild'), |
||
266 | ], |
||
267 | 'INDI:CHR' => [ |
||
268 | 'M' => I18N::translate('Christening of a grandson'), |
||
269 | 'F' => I18N::translate('Christening of a granddaughter'), |
||
270 | 'U' => I18N::translate('Christening of a grandchild'), |
||
271 | ], |
||
272 | 'INDI:BAPM' => [ |
||
273 | 'M' => I18N::translate('Baptism of a grandson'), |
||
274 | 'F' => I18N::translate('Baptism of a granddaughter'), |
||
275 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
276 | ], |
||
277 | 'INDI:ADOP' => [ |
||
278 | 'M' => I18N::translate('Adoption of a grandson'), |
||
279 | 'F' => I18N::translate('Adoption of a granddaughter'), |
||
280 | 'U' => I18N::translate('Adoption of a grandchild'), |
||
281 | ], |
||
282 | ]; |
||
283 | |||
284 | $birth_of_a_grandchild1 = [ |
||
285 | 'INDI:BIRT' => [ |
||
286 | 'M' => I18N::translateContext('daughter’s son', 'Birth of a grandson'), |
||
287 | 'F' => I18N::translateContext('daughter’s daughter', 'Birth of a granddaughter'), |
||
288 | 'U' => I18N::translate('Birth of a grandchild'), |
||
289 | ], |
||
290 | 'INDI:CHR' => [ |
||
291 | 'M' => I18N::translateContext('daughter’s son', 'Christening of a grandson'), |
||
292 | 'F' => I18N::translateContext('daughter’s daughter', 'Christening of a granddaughter'), |
||
293 | 'U' => I18N::translate('Christening of a grandchild'), |
||
294 | ], |
||
295 | 'INDI:BAPM' => [ |
||
296 | 'M' => I18N::translateContext('daughter’s son', 'Baptism of a grandson'), |
||
297 | 'F' => I18N::translateContext('daughter’s daughter', 'Baptism of a granddaughter'), |
||
298 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
299 | ], |
||
300 | 'INDI:ADOP' => [ |
||
301 | 'M' => I18N::translateContext('daughter’s son', 'Adoption of a grandson'), |
||
302 | 'F' => I18N::translateContext('daughter’s daughter', 'Adoption of a granddaughter'), |
||
303 | 'U' => I18N::translate('Adoption of a grandchild'), |
||
304 | ], |
||
305 | ]; |
||
306 | |||
307 | $birth_of_a_grandchild2 = [ |
||
308 | 'INDI:BIRT' => [ |
||
309 | 'M' => I18N::translateContext('son’s son', 'Birth of a grandson'), |
||
310 | 'F' => I18N::translateContext('son’s daughter', 'Birth of a granddaughter'), |
||
311 | 'U' => I18N::translate('Birth of a grandchild'), |
||
312 | ], |
||
313 | 'INDI:CHR' => [ |
||
314 | 'M' => I18N::translateContext('son’s son', 'Christening of a grandson'), |
||
315 | 'F' => I18N::translateContext('son’s daughter', 'Christening of a granddaughter'), |
||
316 | 'U' => I18N::translate('Christening of a grandchild'), |
||
317 | ], |
||
318 | 'INDI:BAPM' => [ |
||
319 | 'M' => I18N::translateContext('son’s son', 'Baptism of a grandson'), |
||
320 | 'F' => I18N::translateContext('son’s daughter', 'Baptism of a granddaughter'), |
||
321 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
322 | ], |
||
323 | 'INDI:ADOP' => [ |
||
324 | 'M' => I18N::translateContext('son’s son', 'Adoption of a grandson'), |
||
325 | 'F' => I18N::translateContext('son’s daughter', 'Adoption of a granddaughter'), |
||
326 | 'U' => I18N::translate('Adoption of a grandchild'), |
||
327 | ], |
||
328 | ]; |
||
329 | |||
330 | $death_of_a_child = [ |
||
331 | 'INDI:DEAT' => [ |
||
332 | 'M' => I18N::translate('Death of a son'), |
||
333 | 'F' => I18N::translate('Death of a daughter'), |
||
334 | 'U' => I18N::translate('Death of a child'), |
||
335 | ], |
||
336 | 'INDI:BURI' => [ |
||
337 | 'M' => I18N::translate('Burial of a son'), |
||
338 | 'F' => I18N::translate('Burial of a daughter'), |
||
339 | 'U' => I18N::translate('Burial of a child'), |
||
340 | ], |
||
341 | 'INDI:CREM' => [ |
||
342 | 'M' => I18N::translate('Cremation of a son'), |
||
343 | 'F' => I18N::translate('Cremation of a daughter'), |
||
344 | 'U' => I18N::translate('Cremation of a child'), |
||
345 | ], |
||
346 | ]; |
||
347 | |||
348 | $death_of_a_sibling = [ |
||
349 | 'INDI:DEAT' => [ |
||
350 | 'M' => I18N::translate('Death of a brother'), |
||
351 | 'F' => I18N::translate('Death of a sister'), |
||
352 | 'U' => I18N::translate('Death of a sibling'), |
||
353 | ], |
||
354 | 'INDI:BURI' => [ |
||
355 | 'M' => I18N::translate('Burial of a brother'), |
||
356 | 'F' => I18N::translate('Burial of a sister'), |
||
357 | 'U' => I18N::translate('Burial of a sibling'), |
||
358 | ], |
||
359 | 'INDI:CREM' => [ |
||
360 | 'M' => I18N::translate('Cremation of a brother'), |
||
361 | 'F' => I18N::translate('Cremation of a sister'), |
||
362 | 'U' => I18N::translate('Cremation of a sibling'), |
||
363 | ], |
||
364 | ]; |
||
365 | |||
366 | $death_of_a_half_sibling = [ |
||
367 | 'INDI:DEAT' => [ |
||
368 | 'M' => I18N::translate('Death of a half-brother'), |
||
369 | 'F' => I18N::translate('Death of a half-sister'), |
||
370 | 'U' => I18N::translate('Death of a half-sibling'), |
||
371 | ], |
||
372 | 'INDI:BURI' => [ |
||
373 | 'M' => I18N::translate('Burial of a half-brother'), |
||
374 | 'F' => I18N::translate('Burial of a half-sister'), |
||
375 | 'U' => I18N::translate('Burial of a half-sibling'), |
||
376 | ], |
||
377 | 'INDI:CREM' => [ |
||
378 | 'M' => I18N::translate('Cremation of a half-brother'), |
||
379 | 'F' => I18N::translate('Cremation of a half-sister'), |
||
380 | 'U' => I18N::translate('Cremation of a half-sibling'), |
||
381 | ], |
||
382 | ]; |
||
383 | |||
384 | $death_of_a_grandchild = [ |
||
385 | 'INDI:DEAT' => [ |
||
386 | 'M' => I18N::translate('Death of a grandson'), |
||
387 | 'F' => I18N::translate('Death of a granddaughter'), |
||
388 | 'U' => I18N::translate('Death of a grandchild'), |
||
389 | ], |
||
390 | 'INDI:BURI' => [ |
||
391 | 'M' => I18N::translate('Burial of a grandson'), |
||
392 | 'F' => I18N::translate('Burial of a granddaughter'), |
||
393 | 'U' => I18N::translate('Burial of a grandchild'), |
||
394 | ], |
||
395 | 'INDI:CREM' => [ |
||
396 | 'M' => I18N::translate('Cremation of a grandson'), |
||
397 | 'F' => I18N::translate('Cremation of a granddaughter'), |
||
398 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
399 | ], |
||
400 | ]; |
||
401 | |||
402 | $death_of_a_grandchild1 = [ |
||
403 | 'INDI:DEAT' => [ |
||
404 | 'M' => I18N::translateContext('daughter’s son', 'Death of a grandson'), |
||
405 | 'F' => I18N::translateContext('daughter’s daughter', 'Death of a granddaughter'), |
||
406 | 'U' => I18N::translate('Death of a grandchild'), |
||
407 | ], |
||
408 | 'INDI:BURI' => [ |
||
409 | 'M' => I18N::translateContext('daughter’s son', 'Burial of a grandson'), |
||
410 | 'F' => I18N::translateContext('daughter’s daughter', 'Burial of a granddaughter'), |
||
411 | 'U' => I18N::translate('Burial of a grandchild'), |
||
412 | ], |
||
413 | 'INDI:CREM' => [ |
||
414 | 'M' => I18N::translateContext('daughter’s son', 'Cremation of a grandson'), |
||
415 | 'F' => I18N::translateContext('daughter’s daughter', 'Cremation of a granddaughter'), |
||
416 | 'U' => I18N::translate('Baptism of a grandchild'), |
||
417 | ], |
||
418 | ]; |
||
419 | |||
420 | $death_of_a_grandchild2 = [ |
||
421 | 'INDI:DEAT' => [ |
||
422 | 'M' => I18N::translateContext('son’s son', 'Death of a grandson'), |
||
423 | 'F' => I18N::translateContext('son’s daughter', 'Death of a granddaughter'), |
||
424 | 'U' => I18N::translate('Death of a grandchild'), |
||
425 | ], |
||
426 | 'INDI:BURI' => [ |
||
427 | 'M' => I18N::translateContext('son’s son', 'Burial of a grandson'), |
||
428 | 'F' => I18N::translateContext('son’s daughter', 'Burial of a granddaughter'), |
||
429 | 'U' => I18N::translate('Burial of a grandchild'), |
||
430 | ], |
||
431 | 'INDI:CREM' => [ |
||
432 | 'M' => I18N::translateContext('son’s son', 'Cremation of a grandson'), |
||
433 | 'F' => I18N::translateContext('son’s daughter', 'Cremation of a granddaughter'), |
||
434 | 'U' => I18N::translate('Cremation of a grandchild'), |
||
435 | ], |
||
436 | ]; |
||
437 | |||
438 | $marriage_of_a_child = [ |
||
439 | 'M' => I18N::translate('Marriage of a son'), |
||
440 | 'F' => I18N::translate('Marriage of a daughter'), |
||
441 | 'U' => I18N::translate('Marriage of a child'), |
||
442 | ]; |
||
443 | |||
444 | $marriage_of_a_grandchild = [ |
||
445 | 'M' => I18N::translate('Marriage of a grandson'), |
||
446 | 'F' => I18N::translate('Marriage of a granddaughter'), |
||
447 | 'U' => I18N::translate('Marriage of a grandchild'), |
||
448 | ]; |
||
449 | |||
450 | $marriage_of_a_grandchild1 = [ |
||
451 | 'M' => I18N::translateContext('daughter’s son', 'Marriage of a grandson'), |
||
452 | 'F' => I18N::translateContext('daughter’s daughter', 'Marriage of a granddaughter'), |
||
453 | 'U' => I18N::translate('Marriage of a grandchild'), |
||
454 | ]; |
||
455 | |||
456 | $marriage_of_a_grandchild2 = [ |
||
457 | 'M' => I18N::translateContext('son’s son', 'Marriage of a grandson'), |
||
458 | 'F' => I18N::translateContext('son’s daughter', 'Marriage of a granddaughter'), |
||
459 | 'U' => I18N::translate('Marriage of a grandchild'), |
||
460 | ]; |
||
461 | |||
462 | $marriage_of_a_sibling = [ |
||
463 | 'M' => I18N::translate('Marriage of a brother'), |
||
464 | 'F' => I18N::translate('Marriage of a sister'), |
||
465 | 'U' => I18N::translate('Marriage of a sibling'), |
||
466 | ]; |
||
467 | |||
468 | $marriage_of_a_half_sibling = [ |
||
469 | 'M' => I18N::translate('Marriage of a half-brother'), |
||
470 | 'F' => I18N::translate('Marriage of a half-sister'), |
||
471 | 'U' => I18N::translate('Marriage of a half-sibling'), |
||
472 | ]; |
||
473 | |||
474 | $facts = new Collection(); |
||
475 | |||
476 | // Deal with recursion. |
||
477 | if ($option === '_CHIL') { |
||
478 | // Add grandchildren |
||
479 | foreach ($family->children() as $child) { |
||
480 | foreach ($child->spouseFamilies() as $cfamily) { |
||
481 | switch ($child->sex()) { |
||
482 | case 'M': |
||
483 | foreach ($this->childFacts($person, $cfamily, '_GCHI', 'son', $min_date, $max_date) as $fact) { |
||
484 | $facts[] = $fact; |
||
485 | } |
||
486 | break; |
||
487 | case 'F': |
||
488 | foreach ($this->childFacts($person, $cfamily, '_GCHI', 'dau', $min_date, $max_date) as $fact) { |
||
489 | $facts[] = $fact; |
||
490 | } |
||
491 | break; |
||
492 | default: |
||
493 | foreach ($this->childFacts($person, $cfamily, '_GCHI', 'chi', $min_date, $max_date) as $fact) { |
||
494 | $facts[] = $fact; |
||
495 | } |
||
496 | break; |
||
497 | } |
||
498 | } |
||
499 | } |
||
500 | } |
||
501 | |||
502 | // For each child in the family |
||
503 | foreach ($family->children() as $child) { |
||
504 | if ($child->xref() === $person->xref()) { |
||
505 | // We are not our own sibling! |
||
506 | continue; |
||
507 | } |
||
508 | // add child’s birth |
||
509 | if (str_contains($SHOW_RELATIVES_EVENTS, '_BIRT' . str_replace('_HSIB', '_SIBL', $option))) { |
||
510 | foreach ($child->facts(['BIRT', 'CHR', 'BAPM', 'ADOP']) as $fact) { |
||
511 | // Always show _BIRT_CHIL, even if the dates are not known |
||
512 | if ($option === '_CHIL' || $this->includeFact($fact, $min_date, $max_date)) { |
||
513 | switch ($option) { |
||
514 | case '_GCHI': |
||
515 | switch ($relation) { |
||
516 | case 'dau': |
||
517 | $facts[] = $this->convertEvent($fact, $birth_of_a_grandchild1[$fact->tag()], $fact->record()->sex()); |
||
518 | break; |
||
519 | case 'son': |
||
520 | $facts[] = $this->convertEvent($fact, $birth_of_a_grandchild2[$fact->tag()], $fact->record()->sex()); |
||
521 | break; |
||
522 | case 'chil': |
||
523 | $facts[] = $this->convertEvent($fact, $birth_of_a_grandchild[$fact->tag()], $fact->record()->sex()); |
||
524 | break; |
||
525 | } |
||
526 | break; |
||
527 | case '_SIBL': |
||
528 | $facts[] = $this->convertEvent($fact, $birth_of_a_sibling[$fact->tag()], $fact->record()->sex()); |
||
529 | break; |
||
530 | case '_HSIB': |
||
531 | $facts[] = $this->convertEvent($fact, $birth_of_a_half_sibling[$fact->tag()], $fact->record()->sex()); |
||
532 | break; |
||
533 | case '_CHIL': |
||
534 | $facts[] = $this->convertEvent($fact, $birth_of_a_child[$fact->tag()], $fact->record()->sex()); |
||
535 | break; |
||
536 | } |
||
537 | } |
||
538 | } |
||
539 | } |
||
540 | // add child’s death |
||
541 | if (str_contains($SHOW_RELATIVES_EVENTS, '_DEAT' . str_replace('_HSIB', '_SIBL', $option))) { |
||
542 | foreach ($child->facts(['DEAT', 'BURI', 'CREM']) as $fact) { |
||
543 | if ($this->includeFact($fact, $min_date, $max_date)) { |
||
544 | switch ($option) { |
||
545 | case '_GCHI': |
||
546 | switch ($relation) { |
||
547 | case 'dau': |
||
548 | $facts[] = $this->convertEvent($fact, $death_of_a_grandchild1[$fact->tag()], $fact->record()->sex()); |
||
549 | break; |
||
550 | case 'son': |
||
551 | $facts[] = $this->convertEvent($fact, $death_of_a_grandchild2[$fact->tag()], $fact->record()->sex()); |
||
552 | break; |
||
553 | case 'chi': |
||
554 | $facts[] = $this->convertEvent($fact, $death_of_a_grandchild[$fact->tag()], $fact->record()->sex()); |
||
555 | break; |
||
556 | } |
||
557 | break; |
||
558 | case '_SIBL': |
||
559 | $facts[] = $this->convertEvent($fact, $death_of_a_sibling[$fact->tag()], $fact->record()->sex()); |
||
560 | break; |
||
561 | case '_HSIB': |
||
562 | $facts[] = $this->convertEvent($fact, $death_of_a_half_sibling[$fact->tag()], $fact->record()->sex()); |
||
563 | break; |
||
564 | case '_CHIL': |
||
565 | $facts[] = $this->convertEvent($fact, $death_of_a_child[$fact->tag()], $fact->record()->sex()); |
||
566 | break; |
||
567 | } |
||
568 | } |
||
569 | } |
||
570 | } |
||
571 | |||
572 | // add child’s marriage |
||
573 | if (str_contains($SHOW_RELATIVES_EVENTS, '_MARR' . str_replace('_HSIB', '_SIBL', $option))) { |
||
574 | foreach ($child->spouseFamilies() as $sfamily) { |
||
575 | foreach ($sfamily->facts(['MARR']) as $fact) { |
||
576 | if ($this->includeFact($fact, $min_date, $max_date)) { |
||
577 | switch ($option) { |
||
578 | case '_GCHI': |
||
579 | switch ($relation) { |
||
580 | case 'dau': |
||
581 | $facts[] = $this->convertEvent($fact, $marriage_of_a_grandchild1, $child->sex()); |
||
582 | break; |
||
583 | case 'son': |
||
584 | $facts[] = $this->convertEvent($fact, $marriage_of_a_grandchild2, $child->sex()); |
||
585 | break; |
||
586 | case 'chi': |
||
587 | $facts[] = $this->convertEvent($fact, $marriage_of_a_grandchild, $child->sex()); |
||
588 | break; |
||
589 | } |
||
590 | break; |
||
591 | case '_SIBL': |
||
592 | $facts[] = $this->convertEvent($fact, $marriage_of_a_sibling, $child->sex()); |
||
593 | break; |
||
594 | case '_HSIB': |
||
595 | $facts[] = $this->convertEvent($fact, $marriage_of_a_half_sibling, $child->sex()); |
||
596 | break; |
||
597 | case '_CHIL': |
||
598 | $facts[] = $this->convertEvent($fact, $marriage_of_a_child, $child->sex()); |
||
599 | break; |
||
600 | } |
||
601 | } |
||
602 | } |
||
603 | } |
||
604 | } |
||
605 | } |
||
606 | |||
607 | return $facts; |
||
608 | } |
||
609 | |||
610 | /** |
||
611 | * Get the events of parents and grandparents. |
||
612 | * |
||
613 | * @param Individual $person |
||
614 | * @param int $sosa |
||
615 | * @param Date $min_date |
||
616 | * @param Date $max_date |
||
617 | * |
||
618 | * @return Collection<int,Fact> |
||
619 | */ |
||
620 | private function parentFacts(Individual $person, int $sosa, Date $min_date, Date $max_date): Collection |
||
778 | } |
||
779 | |||
780 | /** |
||
781 | * Spouse facts that are shown on an individual’s page. |
||
782 | * |
||
783 | * @param Individual $individual Show events that occurred during the lifetime of this individual |
||
784 | * @param Individual $spouse Show events of this individual |
||
785 | * @param Date $min_date |
||
786 | * @param Date $max_date |
||
787 | * |
||
788 | * @return Collection<int,Fact> |
||
789 | */ |
||
790 | private function spouseFacts(Individual $individual, Individual $spouse, Date $min_date, Date $max_date): Collection |
||
791 | { |
||
792 | $SHOW_RELATIVES_EVENTS = $individual->tree()->getPreference('SHOW_RELATIVES_EVENTS'); |
||
793 | |||
794 | $death_of_a_spouse = [ |
||
795 | 'INDI:DEAT' => [ |
||
796 | 'M' => I18N::translate('Death of a husband'), |
||
797 | 'F' => I18N::translate('Death of a wife'), |
||
798 | 'U' => I18N::translate('Death of a spouse'), |
||
799 | ], |
||
800 | 'INDI:BURI' => [ |
||
801 | 'M' => I18N::translate('Burial of a husband'), |
||
802 | 'F' => I18N::translate('Burial of a wife'), |
||
803 | 'U' => I18N::translate('Burial of a spouse'), |
||
804 | ], |
||
805 | 'INDI:CREM' => [ |
||
806 | 'M' => I18N::translate('Cremation of a husband'), |
||
807 | 'F' => I18N::translate('Cremation of a wife'), |
||
808 | 'U' => I18N::translate('Cremation of a spouse'), |
||
809 | ], |
||
810 | ]; |
||
811 | |||
812 | $facts = new Collection(); |
||
813 | |||
814 | if (str_contains($SHOW_RELATIVES_EVENTS, '_DEAT_SPOU')) { |
||
815 | foreach ($spouse->facts(['DEAT', 'BURI', 'CREM']) as $fact) { |
||
816 | if ($this->includeFact($fact, $min_date, $max_date)) { |
||
817 | $facts[] = $this->convertEvent($fact, $death_of_a_spouse[$fact->tag()], $fact->record()->sex()); |
||
818 | } |
||
819 | } |
||
820 | } |
||
821 | |||
822 | return $facts; |
||
823 | } |
||
824 | |||
825 | /** |
||
826 | * Does a relative event occur within a date range (i.e. the individual's lifetime)? |
||
827 | * |
||
828 | * @param Fact $fact |
||
829 | * @param Date $min_date |
||
830 | * @param Date $max_date |
||
831 | * |
||
832 | * @return bool |
||
833 | */ |
||
834 | private function includeFact(Fact $fact, Date $min_date, Date $max_date): bool |
||
839 | } |
||
840 | |||
841 | /** |
||
842 | * Convert an event into a special "event of a close relative". |
||
843 | * |
||
844 | * @param Fact $fact |
||
845 | * @param array<string> $types |
||
846 | * @param string $sex |
||
847 | * |
||
848 | * @return Fact |
||
849 | */ |
||
850 | private function convertEvent(Fact $fact, array $types, string $sex): Fact |
||
869 | } |
||
870 | } |
||
871 |