-
Notifications
You must be signed in to change notification settings - Fork 4
/
module.php
602 lines (548 loc) · 21.6 KB
/
module.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
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
<?php
namespace Vytux\WebtreesModules\VytuxCousins;
/*
* webtrees - vytux_cousins tab based on simpl_cousins
*
* Copyright (C) 2013 Vytautas Krivickas and vytux.com. All rights reserved.
*
* Copyright (C) 2013 Nigel Osborne and kiwtrees.net. All rights reserved.
*
* webtrees: Web based Family History software
* Copyright (C) 2013 webtrees development team.
*
* Derived from PhpGedView
* Copyright (C) 2002 to 2010 PGV Development Team. All rights reserved.
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
use Fisharebest\Webtrees\Fact;
use Fisharebest\Webtrees\Gedcom;
use Fisharebest\Webtrees\I18N;
use Fisharebest\Webtrees\Individual;
use Fisharebest\Webtrees\Family;
use Fisharebest\Webtrees\Auth;
use Fisharebest\Webtrees\Registry;
use Fisharebest\Webtrees\Elements\PedigreeLinkageType;
use Fisharebest\Webtrees\Contracts\UserInterface;
use Fisharebest\Webtrees\Module\AbstractModule;
use Fisharebest\Webtrees\Module\ModuleCustomInterface;
use Fisharebest\Webtrees\Module\ModuleCustomTrait;
use Fisharebest\Webtrees\Module\ModuleTabInterface;
use Fisharebest\Webtrees\Module\ModuleTabTrait;
use Fisharebest\Webtrees\Tree;
use Fisharebest\Webtrees\View;
use Fisharebest\Localization\Translation;
use Psr\Http\Message\ResponseInterface;
/**
* vytux_cousins module
*/
class VytuxCousinsTabModule extends AbstractModule implements ModuleTabInterface, ModuleCustomInterface
{
use ModuleCustomTrait;
use ModuleTabTrait;
/**
* How should this module be identified in the control panel, etc.?
*
* @return string
*/
public function title(): string
{
return /* I18N: Name of a module/tab on the individual page. */ I18N::translate('Cousins');
}
/**
* A sentence describing what this module does.
*
* @return string
*/
public function description(): string
{
return /* I18N: Description of the "Facts and events" module */ I18N::translate('A tab showing cousins of an individual.');
}
/**
* The person or organisation who created this module.
*
* @return string
*/
public function customModuleAuthorName(): string
{
return 'Vytautas Krivickas';
}
/**
* The version of this module.
*
* @return string
*/
public function customModuleVersion(): string
{
return '2.1.1';
}
/**
* A URL that will provide the latest version of this module.
*
* @return string
*/
public function customModuleLatestVersionUrl(): string
{
return 'https://raw.githubusercontent.com/vytux-com/vytux_cousins/master/latest.txt';
}
/**
* Where to get support for this module. Perhaps a github respository?
*
* @return string
*/
public function customModuleSupportUrl(): string
{
return 'https://github.com/vytux-com/vytux_cousins/';
}
/**
* The default position for this tab. It can be changed in the control panel.
*
* @return int
*/
public function defaultTabOrder(): int
{
return 10;
}
/**
* Is this tab empty? If so, we don't always need to display it.
*
* @param Individual $individual
*
* @return bool
*/
public function hasTabContent(Individual $individual): bool
{
return true;
}
/**
* A greyed out tab has no actual content, but may perhaps have
* options to create content.
*
* @param Individual $individual
*
* @return bool
*/
public function isGrayedOut(Individual $individual): bool
{
return false;
}
private function getCousins(Individual $individual): object
{
$cousinsObj = (object)[];
$cousinsObj->self = $individual;
$cousinsObj->fathersCousinCount = 0;
$cousinsObj->mothersCousinCount = 0;
$cousinsObj->allCousinCount = 0;
$cousinsObj->fatherCousins = [];
$cousinsObj->motherCousins = [];
if ($individual->childFamilies()->first()) {
$cousinsObj->father = $individual->childFamilies()->first()->husband();
if (($cousinsObj->father) && ($cousinsObj->father->childFamilies()->first())) {
foreach ($cousinsObj->father->childFamilies()->first()->children() as $sibling) {
if ($sibling !== $cousinsObj->father) {
foreach ($sibling->spouseFamilies() as $fam) {
foreach ($fam->children() as $child) {
$cousinsObj->fatherCousins[] = $child;
$cousinsObj->fathersCousinCount++;
}
}
}
}
}
$cousinsObj->mother = $individual->childFamilies()->first()->wife();
if (($cousinsObj->mother) && ($cousinsObj->mother->childFamilies()->first())) {
foreach ($cousinsObj->mother->childFamilies()->first()->children() as $sibling) {
if ($sibling !== $cousinsObj->mother) {
foreach ($sibling->spouseFamilies() as $fam) {
foreach ($fam->children() as $child) {
$cousinsObj->motherCousins[] = $child;
$cousinsObj->mothersCousinCount++;
}
}
}
}
}
$cousinsObj->allCousinCount = sizeof(array_unique(array_merge($cousinsObj->fatherCousins, $cousinsObj->motherCousins)));
}
return $cousinsObj;
}
/**
* Where does this module store its resources
*
* @return string
*/
public function resourcesFolder(): string
{
return __DIR__ . '/resources/';
}
/**
* A label for a parental family group
*
* @param Individual $individual
*
* @return string
*/
public function getChildLabel(Individual $individual): string
{
$fact = $individual->facts(['FAMC'])->first();
if ($fact instanceof Fact) {
$pedi = $fact->attribute('PEDI');
} else {
$pedi = '';
}
if ($pedi !== '' && $pedi !== PedigreeLinkageType::VALUE_BIRTH) {
$pedigree = Registry::elementFactory()->make('INDI:FAMC:PEDI')->value($pedi, $individual->tree());
} else {
$pedigree = Registry::elementFactory()->make('INDI:FAMC:PEDI')->value('', $individual->tree());
}
return $pedigree;
}
/**
* @return ResponseInterface
*/
function getCssAction(): ResponseInterface
{
return response(
file_get_contents($this->resourcesFolder() . 'css/vytux_cousins.css'),
200,
['content-type' => 'text/css']
);
}
/** {@inheritdoc} */
public function getTabContent(Individual $individual): string
{
return view(
$this->name() . '::tab',
[
'cousins_obj' => $this->getCousins($individual),
'cousins_css' => route('module', ['module' => $this->name(), 'action' => 'Css']),
'module_obj' => $this,
]
);
}
/** {@inheritdoc} */
public function canLoadAjax(): bool
{
return false;
}
/**
* Constructor.
*/
public function __construct()
{
// IMPORTANT - the constructor is called on *all* modules, even ones that are disabled.
// It is also called before the webtrees framework is initialised, and so other components
// will not yet exist.
}
/**
* Boostrap.
*
* @param UserInterface $user A user (or visitor) object.
* @param Tree|null $tree Note that $tree can be null (if all trees are private).
*/
public function boot(): void
{
// Here is also a good place to register any views (templates) used by the module.
// This command allows the module to use: view($this->name() . '::', 'fish')
// to access the file ./resources/views/fish.phtml
View::registerNamespace($this->name(), __DIR__ . '/resources/views/');
}
/**
* Additional/updated translations.
*
* @param string $language
*
* @return string[]
*/
public function customTranslations(string $language): array
{
// Here we are using an array for translations.
// If you had .MO files, you could use them with:
// return (new Translation('path/to/file.mo'))->asArray();
switch ($language) {
case 'da':
return $this->danishTranslations();
case 'fi':
return $this->finnishTranslations();
case 'fr':
case 'fr-CA':
return $this->frenchTranslations();
case 'he':
return $this->hebrewTranslations();
case 'lt':
return $this->lithuanianTranslations();
case 'nb':
return $this->norwegianBokmålTranslations();
case 'nl':
return $this->dutchTranslations();
case 'nn':
return $this->norwegianNynorskTranslations();
case 'sv':
return $this->swedishTranslations();
case 'cs':
return $this->czechTranslations();
case 'de':
return $this->germanTranslations();
case 'ru':
return $this->russianTranslations();
case 'zh-Hans':
return $this->hansTranslations();
case 'zh-Hant':
return $this->hantTranslations();
default:
return [];
}
}
/**
* @return array
*/
protected function lithuanianTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Pusbroliai / Pusseserės',
'A tab showing cousins of an individual.' => 'Lapas rodantis asmens pusbrolius ir pusseseres.',
'No family available' => 'Šeima nerasta',
'Father\'s family (%s)' => 'Tėvo šeima (%s)',
'Mother\'s family (%s)' => 'Motinos šeima (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s turi %1$d įrašyta pirmos eilės pusbrolį/pusseserę'
. I18N::PLURAL . '%2$s turi %1$d įrašytus pirmos eilės pusbrolius/pusseseres'
. I18N::PLURAL . '%2$s turi %1$d įrašytų pirmos eilės pusbrolių/pusseserių',
];
}
/**
* @return array
*/
protected function germanTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Cousins und Cousinen',
'A tab showing cousins of an individual.' => 'Ein Reiter, der Cousins und Cousinen der Person anzeigt.',
'No family available' => 'Es gibt keine Familie',
'Father\'s family (%s)' => 'Väterlicherseits (%s)',
'Mother\'s family (%s)' => 'Mütterlicherseits (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s hat einen Cousin oder eine Cousine ersten Grades'
. I18N::PLURAL . '%2$s hat %1$d Cousins oder Cousinen ersten Grades',
];
}
/**
* @return array
*/
protected function danishTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Fætre og kusiner',
'A tab showing cousins of an individual.' => 'En fane der viser en persons fætre og kusiner.',
'No family available' => 'Ingen familie tilgængelig',
'Father\'s family (%s)' => 'Fars familie (%s)',
'Mother\'s family (%s)' => 'Mors familie (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s har %1$d registreret fætter eller kusine'
. I18N::PLURAL . '%2$s har %1$d registrerede fætre eller kusiner',
];
}
/**
* @return array
*/
protected function frenchTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Cousins',
'A tab showing cousins of an individual.' => 'Onglet montrant les cousins d\'un individu.',
'No family available' => 'Pas de famille disponible',
'Father\'s family (%s)' => 'Famille paternelle (%s)',
'Mother\'s family (%s)' => 'Famille maternelle (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s a %1$d cousin germain connu'
. I18N::PLURAL . '%2$s a %1$d cousins germains connus',
];
}
/**
* @return array
*/
protected function finnishTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Serkut',
'A tab showing cousins of an individual.' => 'Välilehti joka näyttää henkilön serkut.',
'No family available' => 'Perhe puuttuu',
'Father\'s family (%s)' => 'Isän perhe (%s)',
'Mother\'s family (%s)' => 'Äidin perhe (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s:llä on %1$d serkku sivustolla'
. I18N::PLURAL . '%2$s:lla on %1$d serkkua sivustolla',
];
}
/**
* @return array
*/
protected function hebrewTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'בני דודים',
'A tab showing cousins of an individual.' => 'חוצץ המראה בני דוד של אדם.',
'No family available' => 'משפחה חסרה',
'Father\'s family (%s)' => 'משפחת האב (%s)',
'Mother\'s family (%s)' => 'משפחת האם (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => 'ל%2$s יש בן דוד אחד מדרגה ראשונה'
. I18N::PLURAL . 'ל%2$s יש %1$d בני דודים מדרגה ראשונה',
];
}
/**
* @return array
*/
protected function norwegianBokmålTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Søskenbarn',
'A tab showing cousins of an individual.' => 'Fane som viser en persons søskenbarn.',
'No family available' => 'Ingen familie tilgjengelig',
'Father\'s family (%s)' => 'Fars familie (%s)',
'Mother\'s family (%s)' => 'Mors familie (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s har %1$d registrert søskenbarn'
. I18N::PLURAL . '%2$s har %1$d registrerte søskenbarn',
];
}
/**
* @return array
*/
protected function norwegianNynorskTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Syskenbarn',
'A tab showing cousins of an individual.' => 'Fane som syner ein person sine syskenbarn.',
'No family available' => 'Ingen familie tilgjengeleg',
'Father\'s family (%s)' => 'Fars familie (%s)',
'Mother\'s family (%s)' => 'Mors familie (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s har %1$d registrert syskenbarn'
. I18N::PLURAL . '%2$s har %1$d registrerte syskenbarn',
];
}
/**
* @return array
*/
protected function dutchTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Neven en nichten',
'A tab showing cousins of an individual.' => 'Tab laat volle neven en nichten van deze persoon zien.',
'No family available' => 'Geen familie gevonden',
'Father\'s family (%s)' => 'Vader\'s familie (%s)',
'Mother\'s family (%s)' => 'Moeder\'s familie (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s heeft %1$d volle neef of nicht'
. I18N::PLURAL . '%2$s heeft %1$d volle neven en nichten',
];
}
/**
* @return array
*/
protected function swedishTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Kusiner',
'A tab showing cousins of an individual.' => 'En flik som visar en persons kusiner.',
'No family available' => 'Familj saknas',
'Father\'s family (%s)' => 'Faderns familj (%s)',
'Mother\'s family (%s)' => 'Moderns familj (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s har %1$d registrerad kusin'
. I18N::PLURAL . '%2$s har %1$d registrerade kusiner',
];
}
/**
* @return array
*/
protected function czechTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => 'Bratranci',
'A tab showing cousins of an individual.' => 'Panel zobrazující bratrance osoby.',
'No family available' => 'Rodina chybí',
'Father\'s family (%s)' => 'Otcova rodina (%s)',
'Mother\'s family (%s)' => 'Matčina rodina (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s má %1$d bratrance'
. I18N::PLURAL . '%2$s má %1$d bratrance'
. I18N::PLURAL . '%2$s má %1$d bratranců',
];
}
/**
* @return array
*/
protected function russianTranslations(): array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => '🇺🇦 Двоюродные братья и сёстры 🇺🇦',
'A tab showing cousins of an individual.' => 'Вкладка с двоюродными братьями и сёстрами человека.',
'No family available' => 'Нет доступных семей',
'Father\'s family (%s)' => 'По отцу (%s)',
'Mother\'s family (%s)' => 'По матери (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s имеет %1$d двоюродного брата или сестру записанным'
. I18N::PLURAL . '%2$s имеет %1$d двоюродных братьев или сестёр записанными'
. I18N::PLURAL . '%2$s имеет %1$d двоюродных братьев или сестёр записанными',
];
}
/**
* @return array
*/
protected function hansTranslations() : array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => '表亲',
'A tab showing cousins of an individual.' => '显示个人表亲的标签。',
'No family available' => '没有堂表亲记录',
'Father\'s family (%s)' => '父亲的家庭 (%s)',
'Mother\'s family (%s)' => '母亲的家庭 (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s有%1$d个第一代堂表亲',
];
}
/**
* @return array
*/
protected function hantTranslations() : array
{
// Note the special characters used in plural and context-sensitive translations.
return [
'Cousins' => '表親',
'A tab showing cousins of an individual.' => '显示个人堂表親的标签。',
'No family available' => '没有堂表親记录',
'Father\'s family (%s)' => '父親的家庭 (%s)',
'Mother\'s family (%s)' => '母親的家庭 (%s)',
'%2$s has %1$d first cousin recorded'
. I18N::PLURAL . '%2$s has %1$d first cousins recorded' => '%2$s 有 %1$d 個第一代堂表親',
];
}
};
return new VytuxCousinsTabModule;