@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -31,64 +31,64 @@ |
||
31 | 31 | */ |
32 | 32 | class MatomoStats implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
34 | + use ViewResponseTrait; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var WelcomeBlockModule|null $module |
|
38 | - */ |
|
39 | - private $module; |
|
36 | + /** |
|
37 | + * @var WelcomeBlockModule|null $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var MatomoStatsService $matomo_service |
|
43 | - */ |
|
44 | - private $matomo_service; |
|
41 | + /** |
|
42 | + * @var MatomoStatsService $matomo_service |
|
43 | + */ |
|
44 | + private $matomo_service; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Constructor for MatomoStats request handler |
|
48 | - * @param ModuleService $module_service |
|
49 | - * @param MatomoStatsService $matomo_service |
|
50 | - */ |
|
51 | - public function __construct( |
|
52 | - ModuleService $module_service, |
|
53 | - MatomoStatsService $matomo_service |
|
54 | - ) { |
|
55 | - $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first(); |
|
56 | - $this->matomo_service = $matomo_service; |
|
57 | - } |
|
46 | + /** |
|
47 | + * Constructor for MatomoStats request handler |
|
48 | + * @param ModuleService $module_service |
|
49 | + * @param MatomoStatsService $matomo_service |
|
50 | + */ |
|
51 | + public function __construct( |
|
52 | + ModuleService $module_service, |
|
53 | + MatomoStatsService $matomo_service |
|
54 | + ) { |
|
55 | + $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first(); |
|
56 | + $this->matomo_service = $matomo_service; |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
62 | - */ |
|
63 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
64 | - { |
|
65 | - $this->layout = 'layouts/ajax'; |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
62 | + */ |
|
63 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
64 | + { |
|
65 | + $this->layout = 'layouts/ajax'; |
|
66 | 66 | |
67 | - if ($this->module === null) { |
|
68 | - return $this->viewResponse('errors/unhandled-exception', [ |
|
69 | - 'error' => 'The attached module could not be found.' |
|
70 | - ], StatusCodeInterface::STATUS_NOT_FOUND); |
|
71 | - } |
|
67 | + if ($this->module === null) { |
|
68 | + return $this->viewResponse('errors/unhandled-exception', [ |
|
69 | + 'error' => 'The attached module could not be found.' |
|
70 | + ], StatusCodeInterface::STATUS_NOT_FOUND); |
|
71 | + } |
|
72 | 72 | |
73 | - $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT); |
|
74 | - $nb_visits_year = $nb_visits_today = null; |
|
73 | + $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT); |
|
74 | + $nb_visits_year = $nb_visits_today = null; |
|
75 | 75 | |
76 | - try { |
|
77 | - if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) { |
|
78 | - $nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0; |
|
79 | - $nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0) |
|
80 | - + $nb_visits_today; |
|
81 | - } |
|
82 | - } catch (Throwable $ex) { |
|
83 | - return $this->viewResponse('errors/unhandled-exception', [ |
|
84 | - 'error' => I18N::translate('Error while retrieving Matomo statistics: ') . |
|
85 | - (Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details')) |
|
86 | - ], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); |
|
87 | - } |
|
76 | + try { |
|
77 | + if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) { |
|
78 | + $nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0; |
|
79 | + $nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0) |
|
80 | + + $nb_visits_today; |
|
81 | + } |
|
82 | + } catch (Throwable $ex) { |
|
83 | + return $this->viewResponse('errors/unhandled-exception', [ |
|
84 | + 'error' => I18N::translate('Error while retrieving Matomo statistics: ') . |
|
85 | + (Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details')) |
|
86 | + ], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); |
|
87 | + } |
|
88 | 88 | |
89 | - return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
90 | - 'visits_year' => $nb_visits_year, |
|
91 | - 'visits_today' => $nb_visits_today |
|
92 | - ]); |
|
93 | - } |
|
89 | + return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
90 | + 'visits_year' => $nb_visits_year, |
|
91 | + 'visits_today' => $nb_visits_today |
|
92 | + ]); |
|
93 | + } |
|
94 | 94 | } |
@@ -29,93 +29,93 @@ |
||
29 | 29 | class MatomoStatsService |
30 | 30 | { |
31 | 31 | |
32 | - /** |
|
33 | - * Returns the number of visits for the current year (up to the day before). |
|
34 | - * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
35 | - * |
|
36 | - * @param WelcomeBlockModule $module |
|
37 | - * @param int $block_id |
|
38 | - * @return int|NULL |
|
39 | - */ |
|
40 | - public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
41 | - { |
|
42 | - return Registry::cache()->file()->remember( |
|
43 | - $module->name() . '-matomovisits-yearly-' . $block_id, |
|
44 | - function () use ($module, $block_id): ?int { |
|
45 | - $visits_year = $this->visits($module, $block_id, 'year'); |
|
46 | - if ($visits_year === null) { |
|
47 | - return null; |
|
48 | - } |
|
49 | - $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
32 | + /** |
|
33 | + * Returns the number of visits for the current year (up to the day before). |
|
34 | + * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
35 | + * |
|
36 | + * @param WelcomeBlockModule $module |
|
37 | + * @param int $block_id |
|
38 | + * @return int|NULL |
|
39 | + */ |
|
40 | + public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
41 | + { |
|
42 | + return Registry::cache()->file()->remember( |
|
43 | + $module->name() . '-matomovisits-yearly-' . $block_id, |
|
44 | + function () use ($module, $block_id): ?int { |
|
45 | + $visits_year = $this->visits($module, $block_id, 'year'); |
|
46 | + if ($visits_year === null) { |
|
47 | + return null; |
|
48 | + } |
|
49 | + $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
50 | 50 | |
51 | - return $visits_year - $visits_today; |
|
52 | - }, |
|
53 | - Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
54 | - ); |
|
55 | - } |
|
51 | + return $visits_year - $visits_today; |
|
52 | + }, |
|
53 | + Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
54 | + ); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * Returns the number of visits for the current day. |
|
59 | - * |
|
60 | - * @param WelcomeBlockModule $module |
|
61 | - * @param int $block_id |
|
62 | - * @return int|NULL |
|
63 | - */ |
|
64 | - public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
65 | - { |
|
66 | - return Registry::cache()->array()->remember( |
|
67 | - $module->name() . '-matomovisits-daily-' . $block_id, |
|
68 | - function () use ($module, $block_id): ?int { |
|
69 | - return $this->visits($module, $block_id, 'day'); |
|
70 | - } |
|
71 | - ); |
|
72 | - } |
|
57 | + /** |
|
58 | + * Returns the number of visits for the current day. |
|
59 | + * |
|
60 | + * @param WelcomeBlockModule $module |
|
61 | + * @param int $block_id |
|
62 | + * @return int|NULL |
|
63 | + */ |
|
64 | + public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
65 | + { |
|
66 | + return Registry::cache()->array()->remember( |
|
67 | + $module->name() . '-matomovisits-daily-' . $block_id, |
|
68 | + function () use ($module, $block_id): ?int { |
|
69 | + return $this->visits($module, $block_id, 'day'); |
|
70 | + } |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Invoke the Matomo API to retrieve the number of visits over a period. |
|
76 | - * |
|
77 | - * @param WelcomeBlockModule $module |
|
78 | - * @param int $block_id |
|
79 | - * @param string $period |
|
80 | - * @return int|NULL |
|
81 | - */ |
|
82 | - protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
83 | - { |
|
84 | - $settings = $module->matomoSettings($block_id); |
|
74 | + /** |
|
75 | + * Invoke the Matomo API to retrieve the number of visits over a period. |
|
76 | + * |
|
77 | + * @param WelcomeBlockModule $module |
|
78 | + * @param int $block_id |
|
79 | + * @param string $period |
|
80 | + * @return int|NULL |
|
81 | + */ |
|
82 | + protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
83 | + { |
|
84 | + $settings = $module->matomoSettings($block_id); |
|
85 | 85 | |
86 | - if ( |
|
87 | - $settings['matomo_enabled'] === true |
|
88 | - && mb_strlen($settings['matomo_url']) > 0 |
|
89 | - && mb_strlen($settings['matomo_token']) > 0 |
|
90 | - && $settings['matomo_siteid'] > 0 |
|
91 | - ) { |
|
92 | - try { |
|
93 | - $http_client = new Client([ |
|
94 | - RequestOptions::TIMEOUT => 30 |
|
95 | - ]); |
|
86 | + if ( |
|
87 | + $settings['matomo_enabled'] === true |
|
88 | + && mb_strlen($settings['matomo_url']) > 0 |
|
89 | + && mb_strlen($settings['matomo_token']) > 0 |
|
90 | + && $settings['matomo_siteid'] > 0 |
|
91 | + ) { |
|
92 | + try { |
|
93 | + $http_client = new Client([ |
|
94 | + RequestOptions::TIMEOUT => 30 |
|
95 | + ]); |
|
96 | 96 | |
97 | - $response = $http_client->get($settings['matomo_url'], [ |
|
98 | - 'query' => [ |
|
99 | - 'module' => 'API', |
|
100 | - 'method' => 'VisitsSummary.getVisits', |
|
101 | - 'idSite' => $settings['matomo_siteid'], |
|
102 | - 'period' => $period, |
|
103 | - 'date' => 'today', |
|
104 | - 'token_auth' => $settings['matomo_token'], |
|
105 | - 'format' => 'json' |
|
106 | - ] |
|
107 | - ]); |
|
97 | + $response = $http_client->get($settings['matomo_url'], [ |
|
98 | + 'query' => [ |
|
99 | + 'module' => 'API', |
|
100 | + 'method' => 'VisitsSummary.getVisits', |
|
101 | + 'idSite' => $settings['matomo_siteid'], |
|
102 | + 'period' => $period, |
|
103 | + 'date' => 'today', |
|
104 | + 'token_auth' => $settings['matomo_token'], |
|
105 | + 'format' => 'json' |
|
106 | + ] |
|
107 | + ]); |
|
108 | 108 | |
109 | - if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
110 | - $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
111 | - if ($result !== null) { |
|
112 | - return (int)$result; |
|
113 | - } |
|
114 | - } |
|
115 | - } catch (RequestException $ex) { |
|
116 | - } |
|
117 | - } |
|
109 | + if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
110 | + $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
111 | + if ($result !== null) { |
|
112 | + return (int)$result; |
|
113 | + } |
|
114 | + } |
|
115 | + } catch (RequestException $ex) { |
|
116 | + } |
|
117 | + } |
|
118 | 118 | |
119 | - return null; |
|
120 | - } |
|
119 | + return null; |
|
120 | + } |
|
121 | 121 | } |