1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
5
|
|
|
* |
6
|
|
|
* @package MyArtJaub\Webtrees |
7
|
|
|
* @subpackage PatronymicLineage |
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
9
|
|
|
* @copyright Copyright (c) 2009-2022, Jonathan Jaubart |
10
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
declare(strict_types=1); |
14
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Module\PatronymicLineage; |
16
|
|
|
|
17
|
|
|
use Aura\Router\Map; |
18
|
|
|
use Fisharebest\Localization\Locale\LocaleInterface; |
19
|
|
|
use Fisharebest\Webtrees\I18N; |
20
|
|
|
use Fisharebest\Webtrees\Registry; |
21
|
|
|
use Fisharebest\Webtrees\Tree; |
22
|
|
|
use Fisharebest\Webtrees\Module\IndividualListModule; |
23
|
|
|
use Fisharebest\Webtrees\Module\ModuleGlobalInterface; |
24
|
|
|
use Fisharebest\Webtrees\Module\ModuleGlobalTrait; |
25
|
|
|
use Fisharebest\Webtrees\Module\ModuleListInterface; |
26
|
|
|
use Fisharebest\Webtrees\Module\ModuleListTrait; |
27
|
|
|
use Illuminate\Support\Collection; |
28
|
|
|
use MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface; |
29
|
|
|
use MyArtJaub\Webtrees\Module\ModuleMyArtJaubTrait; |
30
|
|
|
use MyArtJaub\Webtrees\Module\PatronymicLineage\Http\RequestHandlers\LineagesPage; |
31
|
|
|
use MyArtJaub\Webtrees\Module\PatronymicLineage\Http\RequestHandlers\SurnamesList; |
32
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Patronymic Lineage Module. |
36
|
|
|
* Display lineages of people with the same surname. |
37
|
|
|
*/ |
38
|
|
|
class PatronymicLineageModule extends IndividualListModule implements |
39
|
|
|
ModuleMyArtJaubInterface, |
40
|
|
|
ModuleListInterface, |
41
|
|
|
ModuleGlobalInterface |
42
|
|
|
{ |
43
|
|
|
use ModuleMyArtJaubTrait; |
44
|
|
|
use ModuleListTrait; |
45
|
|
|
use ModuleGlobalTrait; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritDoc} |
49
|
|
|
* @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
50
|
|
|
*/ |
51
|
|
|
public function title(): string |
52
|
|
|
{ |
53
|
|
|
return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages'); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* {@inheritDoc} |
58
|
|
|
* @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
59
|
|
|
*/ |
60
|
|
|
public function description(): string |
61
|
|
|
{ |
62
|
|
|
//phpcs:ignore Generic.Files.LineLength.TooLong |
63
|
|
|
return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.'); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* {@inheritDoc} |
68
|
|
|
* @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
69
|
|
|
*/ |
70
|
|
|
public function loadRoutes(Map $router): void |
71
|
|
|
{ |
72
|
|
|
$router->attach('', '', static function (Map $router): void { |
73
|
|
|
|
74
|
|
|
$router->attach('', '/module-maj/lineages', static function (Map $router): void { |
75
|
|
|
|
76
|
|
|
$router->attach('', '/Page', static function (Map $router): void { |
77
|
|
|
|
78
|
|
|
$router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
79
|
|
|
$router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
80
|
|
|
}); |
81
|
|
|
}); |
82
|
|
|
}); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* {@inheritDoc} |
87
|
|
|
* @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
88
|
|
|
*/ |
89
|
|
|
public function customModuleVersion(): string |
90
|
|
|
{ |
91
|
|
|
return '2.0.11-v.1'; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* {@inheritDoc} |
96
|
|
|
* @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
97
|
|
|
* |
98
|
|
|
* @param array<bool|int|string|array<mixed>|null> $parameters |
99
|
|
|
*/ |
100
|
|
|
public function listUrl(Tree $tree, array $parameters = []): string |
101
|
|
|
{ |
102
|
|
|
$surname = $parameters['surname'] ?? ''; |
103
|
|
|
|
104
|
|
|
$xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
105
|
|
|
if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) { |
106
|
|
|
$surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
if ($surname !== '') { |
110
|
|
|
return route(LineagesPage::class, [ |
111
|
|
|
'tree' => $tree->name(), |
112
|
|
|
'surname' => $surname |
113
|
|
|
] + $parameters); |
114
|
|
|
} |
115
|
|
|
return route(SurnamesList::class, [ |
116
|
|
|
'tree' => $tree->name() |
117
|
|
|
] + $parameters); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* {@inheritDoc} |
122
|
|
|
* @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
123
|
|
|
*/ |
124
|
|
|
public function listMenuClass(): string |
125
|
|
|
{ |
126
|
|
|
return 'menu-maj-patrolineage'; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* {@inheritDoc} |
131
|
|
|
* @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
132
|
|
|
*/ |
133
|
|
|
public function headContent(): string |
134
|
|
|
{ |
135
|
|
|
return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* {@inheritDoc} |
140
|
|
|
* @see \Fisharebest\Webtrees\Module\IndividualListModule::individuals() |
141
|
|
|
* |
142
|
|
|
* Implemented to set the visibility to public. |
143
|
|
|
* This should probably be in a service, but this hack allows for reuse of mainstream code. |
144
|
|
|
*/ |
145
|
|
|
public function individuals( |
146
|
|
|
Tree $tree, |
147
|
|
|
string $surn, |
148
|
|
|
string $salpha, |
149
|
|
|
string $galpha, |
150
|
|
|
bool $marnm, |
151
|
|
|
bool $fams, |
152
|
|
|
LocaleInterface $locale |
153
|
|
|
): Collection { |
154
|
|
|
return parent::individuals($tree, $surn, $salpha, $galpha, $marnm, $fams, $locale); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* {@inheritDoc} |
159
|
|
|
* @see \Fisharebest\Webtrees\Module\IndividualListModule::surnames() |
160
|
|
|
* |
161
|
|
|
* Implemented to set the visibility to public. |
162
|
|
|
* This should probably be in a service, but this hack allows for reuse of mainstream code. |
163
|
|
|
*/ |
164
|
|
|
public function surnames( |
165
|
|
|
Tree $tree, |
166
|
|
|
string $surn, |
167
|
|
|
string $salpha, |
168
|
|
|
bool $marnm, |
169
|
|
|
bool $fams, |
170
|
|
|
LocaleInterface $locale |
171
|
|
|
): array { |
172
|
|
|
return parent::surnames($tree, $surn, $salpha, $marnm, $fams, $locale); |
173
|
|
|
} |
174
|
|
|
} |
175
|
|
|
|