-
Notifications
You must be signed in to change notification settings - Fork 9
/
ExtendedFamily.php
378 lines (352 loc) · 16.3 KB
/
ExtendedFamily.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<?php
/*
* webtrees - extended family part
*
* Copyright (C) 2021 Hermann Hartenthaler. All rights reserved.
*
* webtrees: online genealogy / web based family history software
* Copyright (C) 2021 webtrees development team.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; If not, see <https://www.gnu.org/licenses/>.
*/
/*
* tbd: offene Punkte
* ------------------
* Performance: testen von Variante A und B (letztere muss erst noch fertig implementiert werden)
*
* Familiengruppe Urgroßeltern: Unterscheidung bei den Eltern eines Stiefelternteils nach Eltern und Stiefeltern
* Familiengruppe Neffen und Nichten: 2-stufig: erst Geschwister als P bzw. Partner als P, dann Eltern wie gehabt
* Familiengruppe Cousins: wenn sie zur Vater- und Mutterfamilie gehören, werden sie falsch zugeordnet (bei P Seudo: C2)
* Familiengruppe Schwäger und Schwägerinnen: Ergänzen der vollbürtigen Geschwister um halbbürtige und Stiefgeschwister
* Familiengruppe Partner: Problem mit Zusammenfassung, falls Geschlecht der Partner oder Geschlecht der Partner von
* Partner gemischt sein sollte
* Familiengruppe Partnerketten: grafische Anzeige statt Textketten
* Familiengruppe Partnerketten: von Ge. geht keine Partnerkette aus, aber sie ist Mitglied in der Partnerkette
* von Di. zu Ga., d.h. dies als zweite Information ergänzen
* Familiengruppe Geschwister: eventuell statt Label eigene Kategorie für Adoptiv- und Pflegekinder bzw. Stillmutter
*
* generelle Familienkennzeichen: statt "Eltern" immer "Ehe/Partnerschaft" verwenden
* Label für biologische Vorfahren und Nachkommen mit SOSA-Nummer bzw. d'Aboville
* Label für diverse Personen unter Nutzung der Funktion getRelationshipName(),
* basierend auf den Vesta-Modulen oder eigenen Funktionen:
* Schwäger: Partner der Geschwister
* Schwippschwäger: Rechts = Partner der Schwäger (Ehemann, Ex-, Partner)
* Schwiegerkinder: Partnerin/Ehefrau
* Biologische Eltern, falls selbst adoptiert
* Partner: (Ehefrau, Ehemann, Partner)
* Angeheiratete Onkel und Tanten: generell (Ehefrau/Ehemann, Partner/Partnerin)
* Label für Stiefkinder: etwa bei meinen Neffen Fabian, Felix, Jason und Sam
* Label für Partner: neu einbauen (Ehemann/Ehefrau/Partner/Partnerin/Verlobter/Verlobte/Ex-...)
* Label für Eltern: biologische Eltern, Stiefeltern, Adoptiveltern, Pflegeeltern
* Label oder Gruppe bei Onkel/Tante: Halbonkel/-tante = Halbbruder/-schwester eines biologischen Elternteils
*
* Code: eventuell Verwendung der bestehenden Funktionen "_individuals" zum Aufbau von Familienteilen verwenden,
* statt es jedes Mal vom Probanden aus komplett neu zu gestalten
*
* Test: Übersetzung bei den Partnern testen bei diversen Fällen mit gemischtem Geschlecht
* Test: wie verhält es sich, wenn eine Person als Kind zu zwei Familien gehört (bei P Seudo: C2)
* Test: Stiefcousins (siehe Onkel Walter)
* Test: Schwagerehe (etwa Levirat oder Sororat)
*
* andere Verwandtschaftssysteme: eventuell auch andere Verwandtschaftssysteme als nur das Eskimo-System implementieren
* andere Verwandtschaftssysteme: Onkel als Vater- oder Mutterbruder ausweisen für Übersetzung (Label?);
* Tante als Vater- oder Mutterschwester ausweisen für Übersetzung (Label?);
* andere Verwandtschaftssysteme: Brüder und Schwestern als jüngere oder ältere Geschwister ausweisen für Übersetzung
* (in Bezug auf Proband) (Label?)
*/
namespace Hartenthaler\Webtrees\Module\ExtendedFamily;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Session;
use Illuminate\Support\Collection;
use function explode;
use function count;
/**
* class ExtendedFamily
*
* data and methods for extended family
*/
class ExtendedFamily
{
// ------------ definition of data structures (they have to be public so that they can be accessed in tab.phtml)
/**
* @var $config object
* ->showFilterOptions bool
* ->filterOptions array<int,string>
* ->showSummary bool
* ->showEmptyBlock int [0,1,2]
* ->countPartnerChainsToTotal bool
* ->showShortName bool
* ->showLabels bool
* ->useCompactDesign bool
* ->useClippingsCart bool
* ->shownFamilyParts[] array<string,object>
* ->name string
* ->enabled bool
* ->showParameters bool
* ->familyPartParameters array of array
* ->showThumbnail bool
* ->sizeThumbnailW int (in pixel)
* ->sizeThumbnailH int (in pixel)
*/
public object $config;
/**
* @var $proband object
* ->indi Individual
* ->niceName string
* ->labels array<int,string>
*/
public object $proband;
/**
* @var $filters array<string,object> (index is filterOption)
* ->efp object
* ->summary object
* ->allCount int sum of the members of all family parts without proband
* ->allCountUnique int unique members of all family parts including proband
* allCountUnique depends on countPartnerChainsToTotal
* ->summaryMessageEmptyBlocks array<int,string>
* ... specific data structures for each extended family part
*/
public array $filters;
// ------------ definition of methods
/**
* Extended Family constructor
*
* @param Individual $proband the proband for whom the extended family members are searched
* @param object $config configuration parameters for this extended family
*/
public function __construct(Individual $proband, object $config)
{
$this->constructConfig($config);
$this->constructProband($proband);
$this->constructFiltersExtendedFamilyParts();
}
/**
* construct object containing configuration information based on module parameters
*
* @param object $config configuration parameters
*/
protected function constructConfig(object $config)
{
$this->config = $config;
}
/**
* construct object containing information related to the proband
*
* @param Individual $proband
*/
protected function constructProband(Individual $proband)
{
$this->proband = (object)[];
$this->proband->indi = $proband;
$this->proband->niceName = ProbandName::findNiceName($proband, $this->config->showShortName);
$this->proband->labels = ExtendedFamilySupport::generateChildLabels($proband);
}
/**
* construct array of extended family parts for all combinations of filter options
*/
private function constructFiltersExtendedFamilyParts()
{
$variant ='A'; // tbd test and compare performance of both variants
// A: build up each filter variant from scratch
// B: build for filter option 'all', then copy and reduce/filter this
if ($variant == 'A') {
$this->filters = [];
foreach ($this->config->filterOptions as $filterOption) {
//if ($filterOption == 'F') {
$extfamObj = (object)[];
$extfamObj->efp = (object)[];
$extfamObj->efp->summary = (object)[];
$extfamObj->efp->summary->allCount = 0;
foreach ($this->config->shownFamilyParts as $efp => $element) {
if ($element->enabled) {
$efpO = ExtendedFamilyPartFactory::create(ucfirst($efp), $this->proband->indi, $filterOption);
$extfamObj->efp->$efp = $efpO->getEfpObject();
$extfamObj->efp->summary->allCount += $extfamObj->efp->$efp->allCount;
}
}
$extfamObj->efp->summary->summaryMessageEmptyBlocks = $this->summaryMessageEmptyBlocks($extfamObj);
$extfamObj->efp->summary->allCountUnique = $this->collectAllIndividuals($extfamObj)->count();
$this->filters[$filterOption] = $extfamObj;
//}
}
} else {
// build up structure for 'all'
$extfamObj = (object)[];
$extfamObj->efp = (object)[];
$extfamObj->efp->summary = (object)[];
$extfamObj->efp->summary->allCount = 0;
foreach ($this->config->shownFamilyParts as $efp => $element) {
if ($element->enabled) {
$efpO = ExtendedFamilyPartFactory::create(ucfirst($efp), $this->proband->indi, 'all');
$extfamObj->efp->$efp = $efpO->getEfpObject();
$extfamObj->efp->summary->allCount += $extfamObj->efp->$efp->allCount;
}
}
$extfamObj->efp->summary->summaryMessageEmptyBlocks = $this->summaryMessageEmptyBlocks($extfamObj);
$extfamObj->efp->summary->allCountUnique = $this->collectAllIndividuals($extfamObj)->count();
$this->filters['all'] = $extfamObj;
// clone and reduce/filter this filtered object
foreach ($this->config->filterOptions as $filterOption) {
if ($filterOption !== 'all') {
$this->filters[$filterOption] = clone $this->filters['all'];
// using __clone to filter and add counters
// sum up ->efp->summary->allCount
// replace ->summaryMessageEmptyBlocks
}
}
}
// tbd remove
if ($this->config->useClippingsCart) {
//$this->addExtendedFamilyToClippingsCart($this->collectAllIndividuals($this->filters['all']), $this->collectAllFamilies($this->filters['all']));
}
}
/**
* generate list of empty family parts (blocks) (needed for showEmptyBlock == 1)
*
* @param object $extendedFamily
* @return array<int,string>
*/
private function summaryMessageEmptyBlocks(object $extendedFamily): array
{
$emptyBlocks = [];
foreach ($extendedFamily->efp as $propName => $propValue) {
if ($propName !== 'summary' &&
$extendedFamily->efp->$propName->allCount == 0) {
$emptyBlocks[] = $propName;
}
}
return $emptyBlocks;
}
/**
* collect all members of the extended family (individuals)
* including the proband, maybe excluding the additional members of the partner chains
*
* @param object $extendedFamily
* @return Collection
*/
public function collectAllIndividuals(object $extendedFamily): Collection
{
$collection = collect([$this->proband->indi]); // add proband to the extended family
foreach ($extendedFamily->efp as $propName => $propValue) {
if ($propName == 'partner_chains' && $this->config->countPartnerChainsToTotal) {
// we include the additional members of partner chains only if the option is set
$collection = $collection->concat($propValue->collectionIndividuals);
} elseif ($propName !== 'summary') {
foreach ($propValue->groups as $group) {
foreach ($group->members as $individual) {
$collection->add($individual);
}
}
}
}
return $collection->unique(function ($item) {
return $item->xref();
});
}
/**
* collect all families of the extended family
* maybe excluding the additional families of the partner chains
*
* @param object $extendedFamily
* @return Collection
*/
public function collectAllFamilies(object $extendedFamily): Collection
{
$collection = new Collection();
foreach ($extendedFamily->efp as $propName => $propValue) {
if ($propName == 'partner_chains' && $this->config->countPartnerChainsToTotal) {
// we include the additional families of partner chains only if the option is set
$collection = $collection->concat($propValue->collectionFamilies);
} elseif ($propName !== 'summary') {
foreach ($propValue->groups as $group) {
return $collection; // tbd
foreach ($group->members as $family) {
$collection->add($family);
}
}
}
}
return $collection;
}
/**
* add all members of the extended family (individuals and their families) to the webtrees clippings cart
*
* @param Collection $individuals
* @param Collection $families
*/
public function addExtendedFamilyToClippingsCart(Collection $individuals, Collection $families = null): void
{
$individuals->each(function($item, $key) {
$this->addIndividualToCart($item);
});
if ($families) {
$families->each(function($item, $key) {
$this->addFamilyToCart($item);
});
}
}
/**
* add an individual and all linked other records to the clippings cart
*
* @param Individual $individual
*/
protected function addIndividualToCart(Individual $individual): void
{
if ($individual->canShow()) {
$cart = Session::get('cart');
$cart = is_array($cart) ? $cart : [];
$tree = $individual->tree()->name();
$xref = $individual->xref();
if (($cart[$tree][$xref] ?? false) === false) {
$cart[$tree][$xref] = true;
Session::put('cart', $cart);
/* add all linked records to the clippings cart
$this->addLocationLinksToCart($individual);
$this->addMediaLinksToCart($individual);
$this->addNoteLinksToCart($individual);
$this->addSourceLinksToCart($individual);
*/
}
}
}
/**
* add a family and the spouses and all linked other records to the clippings cart
*
* @param Family $family
*/
protected function addFamilyToCart(Family $family): void
{
$cart = Session::get('cart');
$cart = is_array($cart) ? $cart : [];
$tree = $family->tree()->name();
$xref = $family->xref();
if (($cart[$tree][$xref] ?? false) === false) {
$cart[$tree][$xref] = true;
Session::put('cart', $cart);
//echo "<br>**** added family $xref to clippings cart ****";
foreach ($family->spouses() as $spouse) {
$this->addIndividualToCart($spouse);
}
/* add all linked records to the clippings cart
$this->addLocationLinksToCart($family);
$this->addMediaLinksToCart($family);
$this->addNoteLinksToCart($family);
$this->addSourceLinksToCart($family);
$this->addSubmitterLinksToCart($family);
*/
}
}
}