@@ -19,25 +19,25 @@ |
||
19 | 19 | */ |
20 | 20 | interface TaskInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Display name of the task |
|
24 | - * |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function name(): string; |
|
22 | + /** |
|
23 | + * Display name of the task |
|
24 | + * |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function name(): string; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Return the default frequency for the execution of the task, in minutes. |
|
31 | - * |
|
32 | - * @return int Frequency for the execution of the task |
|
33 | - */ |
|
34 | - public function defaultFrequency(): int; |
|
29 | + /** |
|
30 | + * Return the default frequency for the execution of the task, in minutes. |
|
31 | + * |
|
32 | + * @return int Frequency for the execution of the task |
|
33 | + */ |
|
34 | + public function defaultFrequency(): int; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Run the task's actions, and return whether the execution has been successful. |
|
38 | - * |
|
39 | - * @param TaskSchedule $task_schedule |
|
40 | - * @return bool Has the execution been a success |
|
41 | - */ |
|
42 | - public function run(TaskSchedule $task_schedule): bool; |
|
36 | + /** |
|
37 | + * Run the task's actions, and return whether the execution has been successful. |
|
38 | + * |
|
39 | + * @param TaskSchedule $task_schedule |
|
40 | + * @return bool Has the execution been a success |
|
41 | + */ |
|
42 | + public function run(TaskSchedule $task_schedule): bool; |
|
43 | 43 | } |
@@ -22,20 +22,20 @@ |
||
22 | 22 | interface ConfigurableTaskInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * Returns the HTML code to display the specific task configuration. |
|
27 | - * |
|
28 | - * @param ServerRequestInterface $request |
|
29 | - * @return string HTML code |
|
30 | - */ |
|
31 | - public function configView(ServerRequestInterface $request): string; |
|
25 | + /** |
|
26 | + * Returns the HTML code to display the specific task configuration. |
|
27 | + * |
|
28 | + * @param ServerRequestInterface $request |
|
29 | + * @return string HTML code |
|
30 | + */ |
|
31 | + public function configView(ServerRequestInterface $request): string; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Update the specific configuration of the task. |
|
35 | - * |
|
36 | - * @param ServerRequestInterface $request |
|
37 | - * @param TaskSchedule $task_schedule |
|
38 | - * @return bool Result of the update |
|
39 | - */ |
|
40 | - public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool; |
|
33 | + /** |
|
34 | + * Update the specific configuration of the task. |
|
35 | + * |
|
36 | + * @param ServerRequestInterface $request |
|
37 | + * @param TaskSchedule $task_schedule |
|
38 | + * @return bool Result of the update |
|
39 | + */ |
|
40 | + public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool; |
|
41 | 41 | } |
@@ -20,11 +20,11 @@ |
||
20 | 20 | interface ModuleTasksProviderInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * List tasks provided by the module as an associative array. |
|
25 | - * They keys are used as task IDs for storage and reference. |
|
26 | - * |
|
27 | - * @return array<string, string> List of tasks |
|
28 | - */ |
|
29 | - public function listTasks(): array; |
|
23 | + /** |
|
24 | + * List tasks provided by the module as an associative array. |
|
25 | + * They keys are used as task IDs for storage and reference. |
|
26 | + * |
|
27 | + * @return array<string, string> List of tasks |
|
28 | + */ |
|
29 | + public function listTasks(): array; |
|
30 | 30 | } |
@@ -34,100 +34,100 @@ |
||
34 | 34 | * Display lineages of people with the same surname. |
35 | 35 | */ |
36 | 36 | class PatronymicLineageModule extends IndividualListModule implements |
37 | - ModuleMyArtJaubInterface, |
|
38 | - ModuleListInterface, |
|
39 | - ModuleGlobalInterface |
|
37 | + ModuleMyArtJaubInterface, |
|
38 | + ModuleListInterface, |
|
39 | + ModuleGlobalInterface |
|
40 | 40 | { |
41 | - use ModuleMyArtJaubTrait; |
|
42 | - use ModuleListTrait; |
|
43 | - use ModuleGlobalTrait; |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
48 | - */ |
|
49 | - public function title(): string |
|
50 | - { |
|
51 | - return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages'); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
57 | - */ |
|
58 | - public function description(): string |
|
59 | - { |
|
60 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
61 | - return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.'); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
67 | - */ |
|
68 | - public function loadRoutes(Map $router): void |
|
69 | - { |
|
70 | - $router->attach('', '', static function (Map $router): void { |
|
71 | - |
|
72 | - $router->attach('', '/module-maj/lineages', static function (Map $router): void { |
|
73 | - |
|
74 | - $router->attach('', '/Page', static function (Map $router): void { |
|
75 | - |
|
76 | - $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
|
77 | - $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
|
78 | - }); |
|
79 | - }); |
|
80 | - }); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * {@inheritDoc} |
|
85 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
86 | - */ |
|
87 | - public function customModuleVersion(): string |
|
88 | - { |
|
89 | - return '2.0.11-v.1'; |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * {@inheritDoc} |
|
94 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
95 | - */ |
|
96 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
97 | - { |
|
98 | - $surname = $parameters['surname'] ?? ''; |
|
99 | - |
|
100 | - $xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
|
101 | - if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) { |
|
102 | - $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
|
103 | - } |
|
104 | - |
|
105 | - if ($surname !== '') { |
|
106 | - return route(LineagesPage::class, [ |
|
107 | - 'tree' => $tree->name(), |
|
108 | - 'surname' => $surname |
|
109 | - ] + $parameters); |
|
110 | - } |
|
111 | - return route(SurnamesList::class, [ |
|
112 | - 'tree' => $tree->name() |
|
113 | - ] + $parameters); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * {@inheritDoc} |
|
118 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
119 | - */ |
|
120 | - public function listMenuClass(): string |
|
121 | - { |
|
122 | - return 'menu-maj-patrolineage'; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * {@inheritDoc} |
|
127 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
128 | - */ |
|
129 | - public function headContent(): string |
|
130 | - { |
|
131 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
132 | - } |
|
41 | + use ModuleMyArtJaubTrait; |
|
42 | + use ModuleListTrait; |
|
43 | + use ModuleGlobalTrait; |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
48 | + */ |
|
49 | + public function title(): string |
|
50 | + { |
|
51 | + return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages'); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
57 | + */ |
|
58 | + public function description(): string |
|
59 | + { |
|
60 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
61 | + return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.'); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
67 | + */ |
|
68 | + public function loadRoutes(Map $router): void |
|
69 | + { |
|
70 | + $router->attach('', '', static function (Map $router): void { |
|
71 | + |
|
72 | + $router->attach('', '/module-maj/lineages', static function (Map $router): void { |
|
73 | + |
|
74 | + $router->attach('', '/Page', static function (Map $router): void { |
|
75 | + |
|
76 | + $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
|
77 | + $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
|
78 | + }); |
|
79 | + }); |
|
80 | + }); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * {@inheritDoc} |
|
85 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
86 | + */ |
|
87 | + public function customModuleVersion(): string |
|
88 | + { |
|
89 | + return '2.0.11-v.1'; |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * {@inheritDoc} |
|
94 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
95 | + */ |
|
96 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
97 | + { |
|
98 | + $surname = $parameters['surname'] ?? ''; |
|
99 | + |
|
100 | + $xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
|
101 | + if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) { |
|
102 | + $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
|
103 | + } |
|
104 | + |
|
105 | + if ($surname !== '') { |
|
106 | + return route(LineagesPage::class, [ |
|
107 | + 'tree' => $tree->name(), |
|
108 | + 'surname' => $surname |
|
109 | + ] + $parameters); |
|
110 | + } |
|
111 | + return route(SurnamesList::class, [ |
|
112 | + 'tree' => $tree->name() |
|
113 | + ] + $parameters); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * {@inheritDoc} |
|
118 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
119 | + */ |
|
120 | + public function listMenuClass(): string |
|
121 | + { |
|
122 | + return 'menu-maj-patrolineage'; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * {@inheritDoc} |
|
127 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
128 | + */ |
|
129 | + public function headContent(): string |
|
130 | + { |
|
131 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
132 | + } |
|
133 | 133 | } |
@@ -61,11 +61,11 @@ discard block |
||
61 | 61 | */ |
62 | 62 | public function loadRoutes(Map $router): void |
63 | 63 | { |
64 | - $router->attach('', '', static function (Map $router): void { |
|
64 | + $router->attach('', '', static function(Map $router): void { |
|
65 | 65 | |
66 | - $router->attach('', '/module-maj/lineages', static function (Map $router): void { |
|
66 | + $router->attach('', '/module-maj/lineages', static function(Map $router): void { |
|
67 | 67 | |
68 | - $router->attach('', '/Page', static function (Map $router): void { |
|
68 | + $router->attach('', '/Page', static function(Map $router): void { |
|
69 | 69 | |
70 | 70 | $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
71 | 71 | $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
@@ -122,6 +122,6 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function headContent(): string |
124 | 124 | { |
125 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
125 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
126 | 126 | } |
127 | 127 | } |
@@ -31,69 +31,69 @@ |
||
31 | 31 | */ |
32 | 32 | class LineagesPage implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var PatronymicLineageModule|null $module |
|
38 | - */ |
|
39 | - private $module; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var IndividualListModule|null $indilist_module |
|
43 | - */ |
|
44 | - private $indilist_module; |
|
45 | - |
|
46 | - /** |
|
47 | - * Constructor for LineagesPage Request handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - */ |
|
51 | - public function __construct(ModuleService $module_service) |
|
52 | - { |
|
53 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
54 | - $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
60 | - */ |
|
61 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
62 | - { |
|
63 | - if ($this->module === null) { |
|
64 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
65 | - } |
|
66 | - |
|
67 | - if ($this->indilist_module === null) { |
|
68 | - throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
69 | - } |
|
70 | - |
|
71 | - $tree = $request->getAttribute('tree'); |
|
72 | - assert($tree instanceof Tree); |
|
73 | - |
|
74 | - $surname = $request->getAttribute('surname'); |
|
75 | - |
|
76 | - $initial = mb_substr($surname, 0, 1); |
|
77 | - $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
78 | - ->reject(function (int $count, string $initial): bool { |
|
79 | - |
|
80 | - return $initial === '@' || $initial === ','; |
|
81 | - }); |
|
82 | - |
|
83 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
84 | - |
|
85 | - $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
86 | - |
|
87 | - return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
88 | - 'title' => $title, |
|
89 | - 'module' => $this->module, |
|
90 | - 'tree' => $tree, |
|
91 | - 'initials_list' => $initials_list, |
|
92 | - 'initial' => $initial, |
|
93 | - 'show_all' => 'no', |
|
94 | - 'surname' => $surname, |
|
95 | - 'lineages' => $lineages, |
|
96 | - 'nb_lineages' => $lineages !== null ? $lineages->count() : 0 |
|
97 | - ]); |
|
98 | - } |
|
34 | + use ViewResponseTrait; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var PatronymicLineageModule|null $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var IndividualListModule|null $indilist_module |
|
43 | + */ |
|
44 | + private $indilist_module; |
|
45 | + |
|
46 | + /** |
|
47 | + * Constructor for LineagesPage Request handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + */ |
|
51 | + public function __construct(ModuleService $module_service) |
|
52 | + { |
|
53 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
54 | + $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
60 | + */ |
|
61 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
62 | + { |
|
63 | + if ($this->module === null) { |
|
64 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
65 | + } |
|
66 | + |
|
67 | + if ($this->indilist_module === null) { |
|
68 | + throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
69 | + } |
|
70 | + |
|
71 | + $tree = $request->getAttribute('tree'); |
|
72 | + assert($tree instanceof Tree); |
|
73 | + |
|
74 | + $surname = $request->getAttribute('surname'); |
|
75 | + |
|
76 | + $initial = mb_substr($surname, 0, 1); |
|
77 | + $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
78 | + ->reject(function (int $count, string $initial): bool { |
|
79 | + |
|
80 | + return $initial === '@' || $initial === ','; |
|
81 | + }); |
|
82 | + |
|
83 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
84 | + |
|
85 | + $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
86 | + |
|
87 | + return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
88 | + 'title' => $title, |
|
89 | + 'module' => $this->module, |
|
90 | + 'tree' => $tree, |
|
91 | + 'initials_list' => $initials_list, |
|
92 | + 'initial' => $initial, |
|
93 | + 'show_all' => 'no', |
|
94 | + 'surname' => $surname, |
|
95 | + 'lineages' => $lineages, |
|
96 | + 'nb_lineages' => $lineages !== null ? $lineages->count() : 0 |
|
97 | + ]); |
|
98 | + } |
|
99 | 99 | } |
@@ -75,16 +75,16 @@ |
||
75 | 75 | |
76 | 76 | $initial = mb_substr($surname, 0, 1); |
77 | 77 | $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
78 | - ->reject(function (int $count, string $initial): bool { |
|
78 | + ->reject(function(int $count, string $initial): bool { |
|
79 | 79 | |
80 | 80 | return $initial === '@' || $initial === ','; |
81 | 81 | }); |
82 | 82 | |
83 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
83 | + $title = I18N::translate('Patronymic Lineages').' — '.$surname; |
|
84 | 84 | |
85 | 85 | $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
86 | 86 | |
87 | - return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
87 | + return $this->viewResponse($this->module->name().'::lineages-page', [ |
|
88 | 88 | 'title' => $title, |
89 | 89 | 'module' => $this->module, |
90 | 90 | 'tree' => $tree, |
@@ -30,74 +30,74 @@ |
||
30 | 30 | */ |
31 | 31 | class SurnamesList implements RequestHandlerInterface |
32 | 32 | { |
33 | - use ViewResponseTrait; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var PatronymicLineageModule|null $module |
|
37 | - */ |
|
38 | - private $module; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var IndividualListModule|null $indilist_module |
|
42 | - */ |
|
43 | - private $indilist_module; |
|
44 | - |
|
45 | - /** |
|
46 | - * Constructor for SurnamesList Request Handler |
|
47 | - * |
|
48 | - * @param ModuleService $module_service |
|
49 | - */ |
|
50 | - public function __construct(ModuleService $module_service) |
|
51 | - { |
|
52 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
53 | - $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | - */ |
|
60 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | - { |
|
62 | - if ($this->module === null) { |
|
63 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | - } |
|
65 | - |
|
66 | - if ($this->indilist_module === null) { |
|
67 | - throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
68 | - } |
|
69 | - |
|
70 | - $tree = $request->getAttribute('tree'); |
|
71 | - assert($tree instanceof Tree); |
|
72 | - |
|
73 | - $initial = $request->getAttribute('alpha'); |
|
74 | - $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
75 | - ->reject(function (int $count, string $initial): bool { |
|
76 | - |
|
77 | - return $initial === '@' || $initial === ','; |
|
78 | - }); |
|
79 | - |
|
80 | - $show_all = $request->getQueryParams()['show_all'] ?? 'no'; |
|
81 | - |
|
82 | - if ($show_all === 'yes') { |
|
83 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
84 | - $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale()); |
|
85 | - } elseif ($initial !== null && mb_strlen($initial) == 1) { |
|
86 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
87 | - $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale()); |
|
88 | - } else { |
|
89 | - $title = I18N::translate('Patronymic Lineages'); |
|
90 | - $surnames = []; |
|
91 | - } |
|
92 | - |
|
93 | - return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
94 | - 'title' => $title, |
|
95 | - 'module' => $this->module, |
|
96 | - 'tree' => $tree, |
|
97 | - 'initials_list' => $initials_list, |
|
98 | - 'initial' => $initial, |
|
99 | - 'show_all' => $show_all, |
|
100 | - 'surnames' => $surnames |
|
101 | - ]); |
|
102 | - } |
|
33 | + use ViewResponseTrait; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var PatronymicLineageModule|null $module |
|
37 | + */ |
|
38 | + private $module; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var IndividualListModule|null $indilist_module |
|
42 | + */ |
|
43 | + private $indilist_module; |
|
44 | + |
|
45 | + /** |
|
46 | + * Constructor for SurnamesList Request Handler |
|
47 | + * |
|
48 | + * @param ModuleService $module_service |
|
49 | + */ |
|
50 | + public function __construct(ModuleService $module_service) |
|
51 | + { |
|
52 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
53 | + $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | + */ |
|
60 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | + { |
|
62 | + if ($this->module === null) { |
|
63 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | + } |
|
65 | + |
|
66 | + if ($this->indilist_module === null) { |
|
67 | + throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
68 | + } |
|
69 | + |
|
70 | + $tree = $request->getAttribute('tree'); |
|
71 | + assert($tree instanceof Tree); |
|
72 | + |
|
73 | + $initial = $request->getAttribute('alpha'); |
|
74 | + $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
75 | + ->reject(function (int $count, string $initial): bool { |
|
76 | + |
|
77 | + return $initial === '@' || $initial === ','; |
|
78 | + }); |
|
79 | + |
|
80 | + $show_all = $request->getQueryParams()['show_all'] ?? 'no'; |
|
81 | + |
|
82 | + if ($show_all === 'yes') { |
|
83 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
84 | + $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale()); |
|
85 | + } elseif ($initial !== null && mb_strlen($initial) == 1) { |
|
86 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
87 | + $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale()); |
|
88 | + } else { |
|
89 | + $title = I18N::translate('Patronymic Lineages'); |
|
90 | + $surnames = []; |
|
91 | + } |
|
92 | + |
|
93 | + return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
94 | + 'title' => $title, |
|
95 | + 'module' => $this->module, |
|
96 | + 'tree' => $tree, |
|
97 | + 'initials_list' => $initials_list, |
|
98 | + 'initial' => $initial, |
|
99 | + 'show_all' => $show_all, |
|
100 | + 'surnames' => $surnames |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | |
73 | 73 | $initial = $request->getAttribute('alpha'); |
74 | 74 | $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
75 | - ->reject(function (int $count, string $initial): bool { |
|
75 | + ->reject(function(int $count, string $initial): bool { |
|
76 | 76 | |
77 | 77 | return $initial === '@' || $initial === ','; |
78 | 78 | }); |
@@ -80,17 +80,17 @@ discard block |
||
80 | 80 | $show_all = $request->getQueryParams()['show_all'] ?? 'no'; |
81 | 81 | |
82 | 82 | if ($show_all === 'yes') { |
83 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
83 | + $title = I18N::translate('Patronymic Lineages').' — '.I18N::translate('All'); |
|
84 | 84 | $surnames = $this->indilist_module->surnames($tree, '', '', false, false, I18N::locale()); |
85 | 85 | } elseif ($initial !== null && mb_strlen($initial) == 1) { |
86 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
86 | + $title = I18N::translate('Patronymic Lineages').' — '.$initial; |
|
87 | 87 | $surnames = $this->indilist_module->surnames($tree, '', $initial, false, false, I18N::locale()); |
88 | 88 | } else { |
89 | - $title = I18N::translate('Patronymic Lineages'); |
|
89 | + $title = I18N::translate('Patronymic Lineages'); |
|
90 | 90 | $surnames = []; |
91 | 91 | } |
92 | 92 | |
93 | - return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
93 | + return $this->viewResponse($this->module->name().'::surnames-page', [ |
|
94 | 94 | 'title' => $title, |
95 | 95 | 'module' => $this->module, |
96 | 96 | 'tree' => $tree, |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | public function addFamily(Family $fams): object |
69 | 69 | { |
70 | 70 | if (!$this->linked_fams->has($fams->xref())) { |
71 | - $this->linked_fams->put($fams->xref(), (object) [ |
|
71 | + $this->linked_fams->put($fams->xref(), (object)[ |
|
72 | 72 | 'family' => $fams, |
73 | 73 | 'children' => new Collection() |
74 | 74 | ]); |
@@ -135,6 +135,6 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function hasFollowUpSurname(): bool |
137 | 137 | { |
138 | - return mb_strlen($this->followUpSurname()) > 0 ; |
|
138 | + return mb_strlen($this->followUpSurname()) > 0; |
|
139 | 139 | } |
140 | 140 | } |
@@ -25,106 +25,106 @@ |
||
25 | 25 | class LineageNode |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var Collection<string, stdClass> $linked_fams Spouse families linked to the node |
|
30 | - */ |
|
31 | - private Collection $linked_fams; |
|
28 | + /** |
|
29 | + * @var Collection<string, stdClass> $linked_fams Spouse families linked to the node |
|
30 | + */ |
|
31 | + private Collection $linked_fams; |
|
32 | 32 | |
33 | - private ?Individual $node_indi; |
|
34 | - private LineageRootNode $root_node; |
|
35 | - private ?string $alt_surname; |
|
33 | + private ?Individual $node_indi; |
|
34 | + private LineageRootNode $root_node; |
|
35 | + private ?string $alt_surname; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for Lineage node |
|
39 | - * |
|
40 | - * @param Individual $node_indi Main individual |
|
41 | - * @param LineageRootNode $root_node Node of the lineage root |
|
42 | - * @param null|string $alt_surname Follow-up surname |
|
43 | - */ |
|
44 | - public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null) |
|
45 | - { |
|
46 | - $this->node_indi = $node_indi; |
|
47 | - $this->root_node = $root_node; |
|
48 | - $this->alt_surname = $alt_surname; |
|
49 | - $this->linked_fams = new Collection(); |
|
50 | - } |
|
37 | + /** |
|
38 | + * Constructor for Lineage node |
|
39 | + * |
|
40 | + * @param Individual $node_indi Main individual |
|
41 | + * @param LineageRootNode $root_node Node of the lineage root |
|
42 | + * @param null|string $alt_surname Follow-up surname |
|
43 | + */ |
|
44 | + public function __construct(?Individual $node_indi = null, LineageRootNode $root_node, $alt_surname = null) |
|
45 | + { |
|
46 | + $this->node_indi = $node_indi; |
|
47 | + $this->root_node = $root_node; |
|
48 | + $this->alt_surname = $alt_surname; |
|
49 | + $this->linked_fams = new Collection(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Add a spouse family to the node |
|
54 | - * |
|
55 | - * @param Family $fams |
|
56 | - * @return stdClass |
|
57 | - */ |
|
58 | - public function addFamily(Family $fams): object |
|
59 | - { |
|
60 | - if (!$this->linked_fams->has($fams->xref())) { |
|
61 | - $this->linked_fams->put($fams->xref(), (object) [ |
|
62 | - 'family' => $fams, |
|
63 | - 'children' => new Collection() |
|
64 | - ]); |
|
65 | - } |
|
66 | - return $this->linked_fams->get($fams->xref()); |
|
67 | - } |
|
52 | + /** |
|
53 | + * Add a spouse family to the node |
|
54 | + * |
|
55 | + * @param Family $fams |
|
56 | + * @return stdClass |
|
57 | + */ |
|
58 | + public function addFamily(Family $fams): object |
|
59 | + { |
|
60 | + if (!$this->linked_fams->has($fams->xref())) { |
|
61 | + $this->linked_fams->put($fams->xref(), (object) [ |
|
62 | + 'family' => $fams, |
|
63 | + 'children' => new Collection() |
|
64 | + ]); |
|
65 | + } |
|
66 | + return $this->linked_fams->get($fams->xref()); |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Add a child LineageNode to the node |
|
71 | - * |
|
72 | - * @param Family $fams |
|
73 | - * @param LineageNode $child |
|
74 | - */ |
|
75 | - public function addChild(Family $fams, LineageNode $child = null): void |
|
76 | - { |
|
77 | - $this->addFamily($fams)->children->push($child); |
|
78 | - $this->root_node->incrementChildNodes(); |
|
79 | - } |
|
69 | + /** |
|
70 | + * Add a child LineageNode to the node |
|
71 | + * |
|
72 | + * @param Family $fams |
|
73 | + * @param LineageNode $child |
|
74 | + */ |
|
75 | + public function addChild(Family $fams, LineageNode $child = null): void |
|
76 | + { |
|
77 | + $this->addFamily($fams)->children->push($child); |
|
78 | + $this->root_node->incrementChildNodes(); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Returns the node individual |
|
83 | - * |
|
84 | - * @return Individual|NULL |
|
85 | - */ |
|
86 | - public function individual(): ?Individual |
|
87 | - { |
|
88 | - return $this->node_indi; |
|
89 | - } |
|
81 | + /** |
|
82 | + * Returns the node individual |
|
83 | + * |
|
84 | + * @return Individual|NULL |
|
85 | + */ |
|
86 | + public function individual(): ?Individual |
|
87 | + { |
|
88 | + return $this->node_indi; |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Returns the lineage root node individual |
|
93 | - * |
|
94 | - * @return LineageRootNode |
|
95 | - */ |
|
96 | - public function rootNode(): LineageRootNode |
|
97 | - { |
|
98 | - return $this->root_node; |
|
99 | - } |
|
91 | + /** |
|
92 | + * Returns the lineage root node individual |
|
93 | + * |
|
94 | + * @return LineageRootNode |
|
95 | + */ |
|
96 | + public function rootNode(): LineageRootNode |
|
97 | + { |
|
98 | + return $this->root_node; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Returns the spouse families linked to the node |
|
103 | - * |
|
104 | - * @return Collection<string, \stdClass> |
|
105 | - */ |
|
106 | - public function families(): Collection |
|
107 | - { |
|
108 | - return $this->linked_fams; |
|
109 | - } |
|
101 | + /** |
|
102 | + * Returns the spouse families linked to the node |
|
103 | + * |
|
104 | + * @return Collection<string, \stdClass> |
|
105 | + */ |
|
106 | + public function families(): Collection |
|
107 | + { |
|
108 | + return $this->linked_fams; |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Returns the follow-up surname |
|
113 | - * |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function followUpSurname(): string |
|
117 | - { |
|
118 | - return $this->alt_surname ?? ''; |
|
119 | - } |
|
111 | + /** |
|
112 | + * Returns the follow-up surname |
|
113 | + * |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function followUpSurname(): string |
|
117 | + { |
|
118 | + return $this->alt_surname ?? ''; |
|
119 | + } |
|
120 | 120 | |
121 | - /** |
|
122 | - * Indicates whether the node has a follow up surname |
|
123 | - * |
|
124 | - * @return boolean |
|
125 | - */ |
|
126 | - public function hasFollowUpSurname(): bool |
|
127 | - { |
|
128 | - return mb_strlen($this->followUpSurname()) > 0 ; |
|
129 | - } |
|
121 | + /** |
|
122 | + * Indicates whether the node has a follow up surname |
|
123 | + * |
|
124 | + * @return boolean |
|
125 | + */ |
|
126 | + public function hasFollowUpSurname(): bool |
|
127 | + { |
|
128 | + return mb_strlen($this->followUpSurname()) > 0 ; |
|
129 | + } |
|
130 | 130 | } |
@@ -24,68 +24,68 @@ |
||
24 | 24 | class LineageRootNode extends LineageNode |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var Collection<string, int> $places Places for the lineage node |
|
29 | - */ |
|
30 | - private $places; |
|
27 | + /** |
|
28 | + * @var Collection<string, int> $places Places for the lineage node |
|
29 | + */ |
|
30 | + private $places; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var int $nb_children Number of node childs |
|
34 | - */ |
|
35 | - private $nb_children; |
|
32 | + /** |
|
33 | + * @var int $nb_children Number of node childs |
|
34 | + */ |
|
35 | + private $nb_children; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for LineageRootNode |
|
39 | - * |
|
40 | - * @param Individual|null $node_indi |
|
41 | - */ |
|
42 | - public function __construct(?Individual $node_indi = null) |
|
43 | - { |
|
44 | - parent::__construct($node_indi, $this); |
|
45 | - $this->places = new Collection(); |
|
46 | - $this->nb_children = 0; |
|
47 | - } |
|
37 | + /** |
|
38 | + * Constructor for LineageRootNode |
|
39 | + * |
|
40 | + * @param Individual|null $node_indi |
|
41 | + */ |
|
42 | + public function __construct(?Individual $node_indi = null) |
|
43 | + { |
|
44 | + parent::__construct($node_indi, $this); |
|
45 | + $this->places = new Collection(); |
|
46 | + $this->nb_children = 0; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * Adds a place to the list of lineage's place |
|
51 | - * |
|
52 | - * @param Place $place |
|
53 | - */ |
|
54 | - public function addPlace(Place $place): void |
|
55 | - { |
|
56 | - $place_name = $place->gedcomName(); |
|
57 | - if (mb_strlen($place_name) > 0) { |
|
58 | - $this->places->put($place_name, $this->places->get($place_name, 0) + 1); |
|
59 | - } |
|
60 | - } |
|
49 | + /** |
|
50 | + * Adds a place to the list of lineage's place |
|
51 | + * |
|
52 | + * @param Place $place |
|
53 | + */ |
|
54 | + public function addPlace(Place $place): void |
|
55 | + { |
|
56 | + $place_name = $place->gedcomName(); |
|
57 | + if (mb_strlen($place_name) > 0) { |
|
58 | + $this->places->put($place_name, $this->places->get($place_name, 0) + 1); |
|
59 | + } |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Returns the number of child nodes. |
|
64 | - * This number is more to be used as indication rather than an accurate one. |
|
65 | - * |
|
66 | - * @return int |
|
67 | - */ |
|
68 | - public function numberChildNodes(): int |
|
69 | - { |
|
70 | - return $this->nb_children; |
|
71 | - } |
|
62 | + /** |
|
63 | + * Returns the number of child nodes. |
|
64 | + * This number is more to be used as indication rather than an accurate one. |
|
65 | + * |
|
66 | + * @return int |
|
67 | + */ |
|
68 | + public function numberChildNodes(): int |
|
69 | + { |
|
70 | + return $this->nb_children; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Increments the number of child nodes by one |
|
75 | - * |
|
76 | - */ |
|
77 | - public function incrementChildNodes(): void |
|
78 | - { |
|
79 | - $this->nb_children++; |
|
80 | - } |
|
73 | + /** |
|
74 | + * Increments the number of child nodes by one |
|
75 | + * |
|
76 | + */ |
|
77 | + public function incrementChildNodes(): void |
|
78 | + { |
|
79 | + $this->nb_children++; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Returns the list of place for the lineage |
|
84 | - * |
|
85 | - * @return Collection<string, int> |
|
86 | - */ |
|
87 | - public function places(): Collection |
|
88 | - { |
|
89 | - return $this->places; |
|
90 | - } |
|
82 | + /** |
|
83 | + * Returns the list of place for the lineage |
|
84 | + * |
|
85 | + * @return Collection<string, int> |
|
86 | + */ |
|
87 | + public function places(): Collection |
|
88 | + { |
|
89 | + return $this->places; |
|
90 | + } |
|
91 | 91 | } |
@@ -107,7 +107,7 @@ |
||
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
110 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
110 | + return $root_lineages->sort(function(LineageRootNode $a, LineageRootNode $b) { |
|
111 | 111 | |
112 | 112 | if ($a->numberChildNodes() == $b->numberChildNodes()) { |
113 | 113 | return 0; |
@@ -28,210 +28,210 @@ |
||
28 | 28 | */ |
29 | 29 | class LineageBuilder |
30 | 30 | { |
31 | - private string $surname; |
|
32 | - private Tree $tree; |
|
33 | - private ?IndividualListModule $indilist_module; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var Collection<string, bool> $used_indis Individuals already processed |
|
37 | - */ |
|
38 | - private Collection $used_indis; |
|
39 | - |
|
40 | - /** |
|
41 | - * Constructor for Lineage Builder |
|
42 | - * |
|
43 | - * @param string $surname Reference surname |
|
44 | - * @param Tree $tree Gedcom tree |
|
45 | - */ |
|
46 | - public function __construct($surname, Tree $tree, IndividualListModule $indilist_module) |
|
47 | - { |
|
48 | - $this->surname = $surname; |
|
49 | - $this->tree = $tree; |
|
50 | - $this->indilist_module = $indilist_module; |
|
51 | - $this->used_indis = new Collection(); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Build all patronymic lineages for the reference surname. |
|
56 | - * |
|
57 | - * @return Collection<LineageRootNode>|NULL List of root patronymic lineages |
|
58 | - */ |
|
59 | - public function buildLineages(): ?Collection |
|
60 | - { |
|
61 | - if ($this->indilist_module === null) { |
|
62 | - return null; |
|
63 | - } |
|
64 | - |
|
65 | - $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale()); |
|
66 | - //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality |
|
67 | - if (count($indis) == 0) { |
|
68 | - return null; |
|
69 | - } |
|
70 | - |
|
71 | - $root_lineages = new Collection(); |
|
72 | - |
|
73 | - foreach ($indis as $indi) { |
|
74 | - /** @var Individual $indi */ |
|
75 | - if ($this->used_indis->get($indi->xref(), false) === false) { |
|
76 | - $indi_first = $this->getLineageRootIndividual($indi); |
|
77 | - if ($indi_first !== null) { |
|
78 | - // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
79 | - $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
80 | - } |
|
81 | - if ($indi_first === null) { |
|
82 | - continue; |
|
83 | - } |
|
84 | - $this->used_indis->put($indi_first->xref(), true); |
|
85 | - if ($indi_first->canShow()) { |
|
86 | - //Check if the root individual has brothers and sisters, without parents |
|
87 | - $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
88 | - if ($indi_first_child_family !== null) { |
|
89 | - $root_node = new LineageRootNode(null); |
|
90 | - $root_node->addFamily($indi_first_child_family); |
|
91 | - } else { |
|
92 | - $root_node = new LineageRootNode($indi_first); |
|
93 | - } |
|
94 | - $root_node = $this->buildLineage($root_node); |
|
95 | - $root_lineages->add($root_node); |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
101 | - |
|
102 | - if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
103 | - return 0; |
|
104 | - } |
|
105 | - return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
106 | - }); |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Retrieve the root individual, from any individual, by recursion. |
|
111 | - * The Root individual is the individual without a father, or without a mother holding the same name. |
|
112 | - * |
|
113 | - * @param Individual $indi |
|
114 | - * @return Individual|NULL Root individual |
|
115 | - */ |
|
116 | - private function getLineageRootIndividual(Individual $indi): ?Individual |
|
117 | - { |
|
118 | - $child_families = $indi->childFamilies(); |
|
119 | - if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
120 | - return null; |
|
121 | - } |
|
122 | - |
|
123 | - foreach ($child_families as $child_family) { |
|
124 | - /** @var Family $child_family */ |
|
125 | - $child_family->husband(); |
|
126 | - if (($husb = $child_family->husband()) !== null) { |
|
127 | - if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
128 | - return $indi; |
|
129 | - } |
|
130 | - return $this->getLineageRootIndividual($husb); |
|
131 | - } elseif (($wife = $child_family->wife()) !== null) { |
|
132 | - if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
133 | - $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
134 | - $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
135 | - if ( |
|
136 | - $indi->canShowName() |
|
137 | - && $wife->canShowName() |
|
138 | - && I18N::comparator()($indi_surname, $wife_surname) == 0 |
|
139 | - ) { |
|
140 | - return $this->getLineageRootIndividual($wife); |
|
141 | - } |
|
142 | - } |
|
143 | - return $indi; |
|
144 | - } |
|
145 | - } |
|
146 | - return $indi; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Computes descendent Lineage from a node. |
|
151 | - * Uses recursion to build the lineage tree |
|
152 | - * |
|
153 | - * @param LineageNode $node |
|
154 | - * @return LineageNode Computed lineage |
|
155 | - */ |
|
156 | - private function buildLineage(LineageNode $node): LineageNode |
|
157 | - { |
|
158 | - $indi_surname = ''; |
|
159 | - |
|
160 | - $indi_node = $node->individual(); |
|
161 | - if ($indi_node !== null) { |
|
162 | - if ($node->families()->count() == 0) { |
|
163 | - foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
164 | - $node->addFamily($spouse_family); |
|
165 | - } |
|
166 | - } |
|
167 | - |
|
168 | - $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
169 | - $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
170 | - |
|
171 | - //Tag the individual as used |
|
172 | - $this->used_indis->put($indi_node->xref(), true); |
|
173 | - } |
|
174 | - |
|
175 | - foreach ($node->families() as $family_node) { |
|
176 | - /** @var Family $spouse_family */ |
|
177 | - $spouse_family = $family_node->family; |
|
178 | - $spouse_surname = ''; |
|
179 | - $spouse = null; |
|
180 | - if ( |
|
181 | - $indi_node !== null && |
|
182 | - ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
183 | - ) { |
|
184 | - $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
185 | - } |
|
186 | - |
|
187 | - $nb_children = $nb_natural = 0; |
|
188 | - |
|
189 | - foreach ($spouse_family->children() as $child) { |
|
190 | - if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
191 | - $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
192 | - |
|
193 | - $nb_children++; |
|
194 | - if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
195 | - //Print only lineages of children with the same surname as their mother |
|
196 | - //(supposing they are natural children) |
|
197 | - /** @psalm-suppress RedundantCondition */ |
|
198 | - if ( |
|
199 | - $spouse === null || |
|
200 | - ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0) |
|
201 | - ) { |
|
202 | - if (I18N::comparator()($child_surname, $indi_surname) == 0) { |
|
203 | - $nb_natural++; |
|
204 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
205 | - $node_child = $this->buildLineage($node_child); |
|
206 | - $node->addChild($spouse_family, $node_child); |
|
207 | - } |
|
208 | - } |
|
209 | - } else { //If the root individual is the father |
|
210 | - $nb_natural++; |
|
211 | - //Print if the children does not bear the same name as his mother |
|
212 | - //(and different from his father) |
|
213 | - if ( |
|
214 | - mb_strlen($child_surname) == 0 || |
|
215 | - mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
216 | - I18N::comparator()($child_surname, $indi_surname) == 0 || |
|
217 | - I18N::comparator()($child_surname, $spouse_surname) != 0 |
|
218 | - ) { |
|
219 | - $node_child = new LineageNode($child, $node->rootNode()); |
|
220 | - $node_child = $this->buildLineage($node_child); |
|
221 | - } else { |
|
222 | - $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
223 | - } |
|
224 | - $node->addChild($spouse_family, $node_child); |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - //Do not print other children |
|
230 | - if (($nb_children - $nb_natural) > 0) { |
|
231 | - $node->addChild($spouse_family, null); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - return $node; |
|
236 | - } |
|
31 | + private string $surname; |
|
32 | + private Tree $tree; |
|
33 | + private ?IndividualListModule $indilist_module; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var Collection<string, bool> $used_indis Individuals already processed |
|
37 | + */ |
|
38 | + private Collection $used_indis; |
|
39 | + |
|
40 | + /** |
|
41 | + * Constructor for Lineage Builder |
|
42 | + * |
|
43 | + * @param string $surname Reference surname |
|
44 | + * @param Tree $tree Gedcom tree |
|
45 | + */ |
|
46 | + public function __construct($surname, Tree $tree, IndividualListModule $indilist_module) |
|
47 | + { |
|
48 | + $this->surname = $surname; |
|
49 | + $this->tree = $tree; |
|
50 | + $this->indilist_module = $indilist_module; |
|
51 | + $this->used_indis = new Collection(); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Build all patronymic lineages for the reference surname. |
|
56 | + * |
|
57 | + * @return Collection<LineageRootNode>|NULL List of root patronymic lineages |
|
58 | + */ |
|
59 | + public function buildLineages(): ?Collection |
|
60 | + { |
|
61 | + if ($this->indilist_module === null) { |
|
62 | + return null; |
|
63 | + } |
|
64 | + |
|
65 | + $indis = $this->indilist_module->individuals($this->tree, $this->surname, '', '', false, false, I18N::locale()); |
|
66 | + //Warning - the IndividualListModule returns a clone of individuals objects. Cannot be used for object equality |
|
67 | + if (count($indis) == 0) { |
|
68 | + return null; |
|
69 | + } |
|
70 | + |
|
71 | + $root_lineages = new Collection(); |
|
72 | + |
|
73 | + foreach ($indis as $indi) { |
|
74 | + /** @var Individual $indi */ |
|
75 | + if ($this->used_indis->get($indi->xref(), false) === false) { |
|
76 | + $indi_first = $this->getLineageRootIndividual($indi); |
|
77 | + if ($indi_first !== null) { |
|
78 | + // The root lineage needs to be recreated from the Factory, to retrieve the proper object |
|
79 | + $indi_first = Registry::individualFactory()->make($indi_first->xref(), $this->tree); |
|
80 | + } |
|
81 | + if ($indi_first === null) { |
|
82 | + continue; |
|
83 | + } |
|
84 | + $this->used_indis->put($indi_first->xref(), true); |
|
85 | + if ($indi_first->canShow()) { |
|
86 | + //Check if the root individual has brothers and sisters, without parents |
|
87 | + $indi_first_child_family = $indi_first->childFamilies()->first(); |
|
88 | + if ($indi_first_child_family !== null) { |
|
89 | + $root_node = new LineageRootNode(null); |
|
90 | + $root_node->addFamily($indi_first_child_family); |
|
91 | + } else { |
|
92 | + $root_node = new LineageRootNode($indi_first); |
|
93 | + } |
|
94 | + $root_node = $this->buildLineage($root_node); |
|
95 | + $root_lineages->add($root_node); |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + return $root_lineages->sort(function (LineageRootNode $a, LineageRootNode $b) { |
|
101 | + |
|
102 | + if ($a->numberChildNodes() == $b->numberChildNodes()) { |
|
103 | + return 0; |
|
104 | + } |
|
105 | + return ($a->numberChildNodes() > $b->numberChildNodes()) ? -1 : 1; |
|
106 | + }); |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Retrieve the root individual, from any individual, by recursion. |
|
111 | + * The Root individual is the individual without a father, or without a mother holding the same name. |
|
112 | + * |
|
113 | + * @param Individual $indi |
|
114 | + * @return Individual|NULL Root individual |
|
115 | + */ |
|
116 | + private function getLineageRootIndividual(Individual $indi): ?Individual |
|
117 | + { |
|
118 | + $child_families = $indi->childFamilies(); |
|
119 | + if ($this->used_indis->get($indi->xref(), false) !== false) { |
|
120 | + return null; |
|
121 | + } |
|
122 | + |
|
123 | + foreach ($child_families as $child_family) { |
|
124 | + /** @var Family $child_family */ |
|
125 | + $child_family->husband(); |
|
126 | + if (($husb = $child_family->husband()) !== null) { |
|
127 | + if ($husb->isPendingAddition() && $husb->privatizeGedcom(Auth::PRIV_HIDE) == '') { |
|
128 | + return $indi; |
|
129 | + } |
|
130 | + return $this->getLineageRootIndividual($husb); |
|
131 | + } elseif (($wife = $child_family->wife()) !== null) { |
|
132 | + if (!($wife->isPendingAddition() && $wife->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
133 | + $indi_surname = $indi->getAllNames()[$indi->getPrimaryName()]['surname']; |
|
134 | + $wife_surname = $wife->getAllNames()[$wife->getPrimaryName()]['surname']; |
|
135 | + if ( |
|
136 | + $indi->canShowName() |
|
137 | + && $wife->canShowName() |
|
138 | + && I18N::comparator()($indi_surname, $wife_surname) == 0 |
|
139 | + ) { |
|
140 | + return $this->getLineageRootIndividual($wife); |
|
141 | + } |
|
142 | + } |
|
143 | + return $indi; |
|
144 | + } |
|
145 | + } |
|
146 | + return $indi; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Computes descendent Lineage from a node. |
|
151 | + * Uses recursion to build the lineage tree |
|
152 | + * |
|
153 | + * @param LineageNode $node |
|
154 | + * @return LineageNode Computed lineage |
|
155 | + */ |
|
156 | + private function buildLineage(LineageNode $node): LineageNode |
|
157 | + { |
|
158 | + $indi_surname = ''; |
|
159 | + |
|
160 | + $indi_node = $node->individual(); |
|
161 | + if ($indi_node !== null) { |
|
162 | + if ($node->families()->count() == 0) { |
|
163 | + foreach ($indi_node->spouseFamilies() as $spouse_family) { |
|
164 | + $node->addFamily($spouse_family); |
|
165 | + } |
|
166 | + } |
|
167 | + |
|
168 | + $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
|
169 | + $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
|
170 | + |
|
171 | + //Tag the individual as used |
|
172 | + $this->used_indis->put($indi_node->xref(), true); |
|
173 | + } |
|
174 | + |
|
175 | + foreach ($node->families() as $family_node) { |
|
176 | + /** @var Family $spouse_family */ |
|
177 | + $spouse_family = $family_node->family; |
|
178 | + $spouse_surname = ''; |
|
179 | + $spouse = null; |
|
180 | + if ( |
|
181 | + $indi_node !== null && |
|
182 | + ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
|
183 | + ) { |
|
184 | + $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
|
185 | + } |
|
186 | + |
|
187 | + $nb_children = $nb_natural = 0; |
|
188 | + |
|
189 | + foreach ($spouse_family->children() as $child) { |
|
190 | + if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) == '')) { |
|
191 | + $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
|
192 | + |
|
193 | + $nb_children++; |
|
194 | + if ($indi_node !== null && $indi_node->sex() == 'F') { //If the root individual is the mother |
|
195 | + //Print only lineages of children with the same surname as their mother |
|
196 | + //(supposing they are natural children) |
|
197 | + /** @psalm-suppress RedundantCondition */ |
|
198 | + if ( |
|
199 | + $spouse === null || |
|
200 | + ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0) |
|
201 | + ) { |
|
202 | + if (I18N::comparator()($child_surname, $indi_surname) == 0) { |
|
203 | + $nb_natural++; |
|
204 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
205 | + $node_child = $this->buildLineage($node_child); |
|
206 | + $node->addChild($spouse_family, $node_child); |
|
207 | + } |
|
208 | + } |
|
209 | + } else { //If the root individual is the father |
|
210 | + $nb_natural++; |
|
211 | + //Print if the children does not bear the same name as his mother |
|
212 | + //(and different from his father) |
|
213 | + if ( |
|
214 | + mb_strlen($child_surname) == 0 || |
|
215 | + mb_strlen($indi_surname) == 0 || mb_strlen($spouse_surname) == 0 || |
|
216 | + I18N::comparator()($child_surname, $indi_surname) == 0 || |
|
217 | + I18N::comparator()($child_surname, $spouse_surname) != 0 |
|
218 | + ) { |
|
219 | + $node_child = new LineageNode($child, $node->rootNode()); |
|
220 | + $node_child = $this->buildLineage($node_child); |
|
221 | + } else { |
|
222 | + $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
|
223 | + } |
|
224 | + $node->addChild($spouse_family, $node_child); |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + //Do not print other children |
|
230 | + if (($nb_children - $nb_natural) > 0) { |
|
231 | + $node->addChild($spouse_family, null); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + return $node; |
|
236 | + } |
|
237 | 237 | } |