@@ -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 | } |
@@ -31,69 +31,69 @@ |
||
31 | 31 | */ |
32 | 32 | class LineagesPage implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var PatronymicLineageModule $module |
|
38 | - */ |
|
39 | - private $module; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var IndividualListModule $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 ($count, $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 $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var IndividualListModule $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 ($count, $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 ($count, $initial): bool { |
|
78 | + ->reject(function($count, $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 $module |
|
37 | - */ |
|
38 | - private $module; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var IndividualListModule $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 ($count, $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 $module |
|
37 | + */ |
|
38 | + private $module; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var IndividualListModule $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 ($count, $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 ($count, $initial): bool { |
|
75 | + ->reject(function($count, $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, |
@@ -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 | } |
@@ -34,100 +34,100 @@ |
||
34 | 34 | * Display lineages of people with the same surname. |
35 | 35 | */ |
36 | 36 | class PatronymicLineageModule extends AbstractModule 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 | } |
@@ -27,50 +27,50 @@ |
||
27 | 27 | */ |
28 | 28 | class MatomoStats implements RequestHandlerInterface |
29 | 29 | { |
30 | - use ViewResponseTrait; |
|
30 | + use ViewResponseTrait; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @var WelcomeBlockModule |
|
34 | - */ |
|
35 | - private $module; |
|
32 | + /** |
|
33 | + * @var WelcomeBlockModule |
|
34 | + */ |
|
35 | + private $module; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var MatomoStatsService $matomo_service |
|
39 | - */ |
|
40 | - private $matomo_service; |
|
37 | + /** |
|
38 | + * @var MatomoStatsService $matomo_service |
|
39 | + */ |
|
40 | + private $matomo_service; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor for MatomoStats request handler |
|
44 | - * @param ModuleService $module_service |
|
45 | - * @param MatomoStatsService $matomo_service |
|
46 | - */ |
|
47 | - public function __construct( |
|
48 | - ModuleService $module_service, |
|
49 | - MatomoStatsService $matomo_service |
|
50 | - ) { |
|
51 | - $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first(); |
|
52 | - $this->matomo_service = $matomo_service; |
|
53 | - } |
|
42 | + /** |
|
43 | + * Constructor for MatomoStats request handler |
|
44 | + * @param ModuleService $module_service |
|
45 | + * @param MatomoStatsService $matomo_service |
|
46 | + */ |
|
47 | + public function __construct( |
|
48 | + ModuleService $module_service, |
|
49 | + MatomoStatsService $matomo_service |
|
50 | + ) { |
|
51 | + $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first(); |
|
52 | + $this->matomo_service = $matomo_service; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
58 | - */ |
|
59 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
60 | - { |
|
61 | - $this->layout = 'layouts/ajax'; |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
58 | + */ |
|
59 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
60 | + { |
|
61 | + $this->layout = 'layouts/ajax'; |
|
62 | 62 | |
63 | - $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT); |
|
64 | - $nb_visits_year = $nb_visits_today = null; |
|
63 | + $block_id = filter_var($request->getAttribute('block_id'), FILTER_VALIDATE_INT); |
|
64 | + $nb_visits_year = $nb_visits_today = null; |
|
65 | 65 | |
66 | - if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) { |
|
67 | - $nb_visits_today = (int) $this->matomo_service->visitsToday($this->module, $block_id); |
|
68 | - $nb_visits_year = (int) $this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today; |
|
69 | - } |
|
66 | + if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) { |
|
67 | + $nb_visits_today = (int) $this->matomo_service->visitsToday($this->module, $block_id); |
|
68 | + $nb_visits_year = (int) $this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today; |
|
69 | + } |
|
70 | 70 | |
71 | - return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
72 | - 'visits_year' => $nb_visits_year, |
|
73 | - 'visits_today' => $nb_visits_today |
|
74 | - ]); |
|
75 | - } |
|
71 | + return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
72 | + 'visits_year' => $nb_visits_year, |
|
73 | + 'visits_today' => $nb_visits_today |
|
74 | + ]); |
|
75 | + } |
|
76 | 76 | } |
@@ -64,11 +64,11 @@ |
||
64 | 64 | $nb_visits_year = $nb_visits_today = null; |
65 | 65 | |
66 | 66 | if ($block_id !== false && $this->module->isMatomoEnabled($block_id)) { |
67 | - $nb_visits_today = (int) $this->matomo_service->visitsToday($this->module, $block_id); |
|
68 | - $nb_visits_year = (int) $this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today; |
|
67 | + $nb_visits_today = (int)$this->matomo_service->visitsToday($this->module, $block_id); |
|
68 | + $nb_visits_year = (int)$this->matomo_service->visitsThisYear($this->module, $block_id) + $nb_visits_today; |
|
69 | 69 | } |
70 | 70 | |
71 | - return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
71 | + return $this->viewResponse($this->module->name().'::matomo-stats', [ |
|
72 | 72 | 'visits_year' => $nb_visits_year, |
73 | 73 | 'visits_today' => $nb_visits_today |
74 | 74 | ]); |
@@ -57,9 +57,9 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function loadRoutes(Map $router): void |
59 | 59 | { |
60 | - $router->attach('', '', static function (Map $router): void { |
|
60 | + $router->attach('', '', static function(Map $router): void { |
|
61 | 61 | |
62 | - $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
62 | + $router->attach('', '/module-maj/welcomeblock/{block_id}', static function(Map $router): void { |
|
63 | 63 | |
64 | 64 | $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
65 | 65 | }); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
88 | 88 | ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
89 | 89 | |
90 | - $content = view($this->name() . '::block-embed', [ |
|
90 | + $content = view($this->name().'::block-embed', [ |
|
91 | 91 | 'block_id' => $block_id, |
92 | 92 | 'fab_welcome_block_view' => $fab_welcome_block_view, |
93 | 93 | 'fab_login_block_view' => $fab_login_block_view, |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | */ |
123 | 123 | public function editBlockConfiguration(Tree $tree, int $block_id): string |
124 | 124 | { |
125 | - return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
125 | + return view($this->name().'::config', $this->matomoSettings($block_id)); |
|
126 | 126 | } |
127 | 127 | |
128 | 128 | /** |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | */ |
132 | 132 | public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
133 | 133 | { |
134 | - $params = (array) $request->getParsedBody(); |
|
134 | + $params = (array)$request->getParsedBody(); |
|
135 | 135 | |
136 | 136 | $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
137 | 137 | $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
155 | 155 | ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
156 | 156 | |
157 | - app('cache.files')->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
157 | + app('cache.files')->forget($this->name().'-matomovisits-yearly-'.$block_id); |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | /** |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
181 | 181 | 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
182 | 182 | 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
183 | - 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
183 | + 'matomo_siteid' => (int)$this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
184 | 184 | ]; |
185 | 185 | } |
186 | 186 | } |
@@ -32,158 +32,158 @@ |
||
32 | 32 | */ |
33 | 33 | class WelcomeBlockModule extends AbstractModule implements ModuleMyArtJaubInterface, ModuleBlockInterface |
34 | 34 | { |
35 | - use ModuleMyArtJaubTrait; |
|
36 | - use ModuleBlockTrait; |
|
37 | - |
|
38 | - /** |
|
39 | - * {@inheritDoc} |
|
40 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
41 | - */ |
|
42 | - public function title(): string |
|
43 | - { |
|
44 | - return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
50 | - */ |
|
51 | - public function description(): string |
|
52 | - { |
|
53 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
54 | - return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
60 | - */ |
|
61 | - public function loadRoutes(Map $router): void |
|
62 | - { |
|
63 | - $router->attach('', '', static function (Map $router): void { |
|
64 | - |
|
65 | - $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
66 | - |
|
67 | - $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
68 | - }); |
|
69 | - }); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * {@inheritDoc} |
|
74 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
75 | - */ |
|
76 | - public function customModuleVersion(): string |
|
77 | - { |
|
78 | - return '2.0.11-v.1'; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * {@inheritDoc} |
|
83 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
84 | - */ |
|
85 | - public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
86 | - { |
|
87 | - $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
88 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
89 | - |
|
90 | - $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
91 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
92 | - |
|
93 | - $content = view($this->name() . '::block-embed', [ |
|
94 | - 'block_id' => $block_id, |
|
95 | - 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
96 | - 'fab_login_block_view' => $fab_login_block_view, |
|
97 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id) |
|
98 | - ]); |
|
99 | - |
|
100 | - if ($context !== self::CONTEXT_EMBED) { |
|
101 | - return view('modules/block-template', [ |
|
102 | - 'block' => Str::kebab($this->name()), |
|
103 | - 'id' => $block_id, |
|
104 | - 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
105 | - 'title' => $tree->title(), |
|
106 | - 'content' => $content, |
|
107 | - ]); |
|
108 | - } |
|
109 | - |
|
110 | - return $content; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * {@inheritDoc} |
|
115 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
116 | - */ |
|
117 | - public function isTreeBlock(): bool |
|
118 | - { |
|
119 | - return true; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * {@inheritDoc} |
|
124 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
125 | - */ |
|
126 | - public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
127 | - { |
|
128 | - return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
129 | - } |
|
130 | - |
|
131 | - /** |
|
132 | - * {@inheritDoc} |
|
133 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
134 | - */ |
|
135 | - public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
136 | - { |
|
137 | - $params = (array) $request->getParsedBody(); |
|
138 | - |
|
139 | - $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
|
140 | - $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
141 | - if (!$matomo_enabled) { |
|
142 | - return; |
|
143 | - } |
|
144 | - |
|
145 | - if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) { |
|
146 | - FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
147 | - return; |
|
148 | - } |
|
149 | - |
|
150 | - if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) { |
|
151 | - FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
152 | - return; |
|
153 | - } |
|
154 | - |
|
155 | - $this |
|
156 | - ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url'])) |
|
157 | - ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
|
158 | - ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
|
159 | - |
|
160 | - app('cache.files')->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
165 | - * |
|
166 | - * @param int $block_id |
|
167 | - * @return bool |
|
168 | - */ |
|
169 | - public function isMatomoEnabled(int $block_id): bool |
|
170 | - { |
|
171 | - return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
176 | - * |
|
177 | - * @param int $block_id |
|
178 | - * @return array<string, mixed> |
|
179 | - */ |
|
180 | - public function matomoSettings(int $block_id): array |
|
181 | - { |
|
182 | - return [ |
|
183 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
184 | - 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
185 | - 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
186 | - 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
187 | - ]; |
|
188 | - } |
|
35 | + use ModuleMyArtJaubTrait; |
|
36 | + use ModuleBlockTrait; |
|
37 | + |
|
38 | + /** |
|
39 | + * {@inheritDoc} |
|
40 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
41 | + */ |
|
42 | + public function title(): string |
|
43 | + { |
|
44 | + return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
50 | + */ |
|
51 | + public function description(): string |
|
52 | + { |
|
53 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
54 | + return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
60 | + */ |
|
61 | + public function loadRoutes(Map $router): void |
|
62 | + { |
|
63 | + $router->attach('', '', static function (Map $router): void { |
|
64 | + |
|
65 | + $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
66 | + |
|
67 | + $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
68 | + }); |
|
69 | + }); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * {@inheritDoc} |
|
74 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
75 | + */ |
|
76 | + public function customModuleVersion(): string |
|
77 | + { |
|
78 | + return '2.0.11-v.1'; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * {@inheritDoc} |
|
83 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
84 | + */ |
|
85 | + public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
86 | + { |
|
87 | + $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
88 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
89 | + |
|
90 | + $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
91 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
92 | + |
|
93 | + $content = view($this->name() . '::block-embed', [ |
|
94 | + 'block_id' => $block_id, |
|
95 | + 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
96 | + 'fab_login_block_view' => $fab_login_block_view, |
|
97 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id) |
|
98 | + ]); |
|
99 | + |
|
100 | + if ($context !== self::CONTEXT_EMBED) { |
|
101 | + return view('modules/block-template', [ |
|
102 | + 'block' => Str::kebab($this->name()), |
|
103 | + 'id' => $block_id, |
|
104 | + 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
105 | + 'title' => $tree->title(), |
|
106 | + 'content' => $content, |
|
107 | + ]); |
|
108 | + } |
|
109 | + |
|
110 | + return $content; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * {@inheritDoc} |
|
115 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
116 | + */ |
|
117 | + public function isTreeBlock(): bool |
|
118 | + { |
|
119 | + return true; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * {@inheritDoc} |
|
124 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
125 | + */ |
|
126 | + public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
127 | + { |
|
128 | + return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
129 | + } |
|
130 | + |
|
131 | + /** |
|
132 | + * {@inheritDoc} |
|
133 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
134 | + */ |
|
135 | + public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
136 | + { |
|
137 | + $params = (array) $request->getParsedBody(); |
|
138 | + |
|
139 | + $matomo_enabled = $params['matomo_enabled'] == 'yes'; |
|
140 | + $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
141 | + if (!$matomo_enabled) { |
|
142 | + return; |
|
143 | + } |
|
144 | + |
|
145 | + if (filter_var($params['matomo_url'], FILTER_VALIDATE_URL) === false) { |
|
146 | + FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
147 | + return; |
|
148 | + } |
|
149 | + |
|
150 | + if (filter_var($params['matomo_siteid'], FILTER_VALIDATE_INT) === false) { |
|
151 | + FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
152 | + return; |
|
153 | + } |
|
154 | + |
|
155 | + $this |
|
156 | + ->setBlockSetting($block_id, 'matomo_url', trim($params['matomo_url'])) |
|
157 | + ->setBlockSetting($block_id, 'matomo_token', trim($params['matomo_token'])) |
|
158 | + ->setBlockSetting($block_id, 'matomo_siteid', $params['matomo_siteid']); |
|
159 | + |
|
160 | + app('cache.files')->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
165 | + * |
|
166 | + * @param int $block_id |
|
167 | + * @return bool |
|
168 | + */ |
|
169 | + public function isMatomoEnabled(int $block_id): bool |
|
170 | + { |
|
171 | + return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
176 | + * |
|
177 | + * @param int $block_id |
|
178 | + * @return array<string, mixed> |
|
179 | + */ |
|
180 | + public function matomoSettings(int $block_id): array |
|
181 | + { |
|
182 | + return [ |
|
183 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
184 | + 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
185 | + 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
186 | + 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
187 | + ]; |
|
188 | + } |
|
189 | 189 | } |
@@ -30,95 +30,95 @@ |
||
30 | 30 | class MatomoStatsService |
31 | 31 | { |
32 | 32 | |
33 | - /** |
|
34 | - * Returns the number of visits for the current year (up to the day before). |
|
35 | - * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
36 | - * |
|
37 | - * @param WelcomeBlockModule $module |
|
38 | - * @param int $block_id |
|
39 | - * @return int|NULL |
|
40 | - */ |
|
41 | - public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
42 | - { |
|
43 | - $cache = Registry::cache()->file(); |
|
33 | + /** |
|
34 | + * Returns the number of visits for the current year (up to the day before). |
|
35 | + * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
36 | + * |
|
37 | + * @param WelcomeBlockModule $module |
|
38 | + * @param int $block_id |
|
39 | + * @return int|NULL |
|
40 | + */ |
|
41 | + public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
42 | + { |
|
43 | + $cache = Registry::cache()->file(); |
|
44 | 44 | |
45 | - return $cache->remember( |
|
46 | - $module->name() . '-matomovisits-yearly-' . $block_id, |
|
47 | - function () use ($module, $block_id): ?int { |
|
48 | - $visits_year = $this->visits($module, $block_id, 'year'); |
|
49 | - if ($visits_year === null) { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
45 | + return $cache->remember( |
|
46 | + $module->name() . '-matomovisits-yearly-' . $block_id, |
|
47 | + function () use ($module, $block_id): ?int { |
|
48 | + $visits_year = $this->visits($module, $block_id, 'year'); |
|
49 | + if ($visits_year === null) { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
53 | 53 | |
54 | - return $visits_year - $visits_today; |
|
55 | - }, |
|
56 | - Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
57 | - ); |
|
58 | - } |
|
54 | + return $visits_year - $visits_today; |
|
55 | + }, |
|
56 | + Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
57 | + ); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Returns the number of visits for the current day. |
|
62 | - * |
|
63 | - * @param WelcomeBlockModule $module |
|
64 | - * @param int $block_id |
|
65 | - * @return int|NULL |
|
66 | - */ |
|
67 | - public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
68 | - { |
|
69 | - return app('cache.array')->remember( |
|
70 | - $module->name() . '-matomovisits-daily-' . $block_id, |
|
71 | - function () use ($module, $block_id): ?int { |
|
72 | - return $this->visits($module, $block_id, 'day'); |
|
73 | - } |
|
74 | - ); |
|
75 | - } |
|
60 | + /** |
|
61 | + * Returns the number of visits for the current day. |
|
62 | + * |
|
63 | + * @param WelcomeBlockModule $module |
|
64 | + * @param int $block_id |
|
65 | + * @return int|NULL |
|
66 | + */ |
|
67 | + public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
68 | + { |
|
69 | + return app('cache.array')->remember( |
|
70 | + $module->name() . '-matomovisits-daily-' . $block_id, |
|
71 | + function () use ($module, $block_id): ?int { |
|
72 | + return $this->visits($module, $block_id, 'day'); |
|
73 | + } |
|
74 | + ); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Invoke the Matomo API to retrieve the number of visits over a period. |
|
79 | - * |
|
80 | - * @param WelcomeBlockModule $module |
|
81 | - * @param int $block_id |
|
82 | - * @param string $period |
|
83 | - * @return int|NULL |
|
84 | - */ |
|
85 | - protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
86 | - { |
|
87 | - $settings = $module->matomoSettings($block_id); |
|
77 | + /** |
|
78 | + * Invoke the Matomo API to retrieve the number of visits over a period. |
|
79 | + * |
|
80 | + * @param WelcomeBlockModule $module |
|
81 | + * @param int $block_id |
|
82 | + * @param string $period |
|
83 | + * @return int|NULL |
|
84 | + */ |
|
85 | + protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
86 | + { |
|
87 | + $settings = $module->matomoSettings($block_id); |
|
88 | 88 | |
89 | - if ( |
|
90 | - $settings['matomo_enabled'] === true |
|
91 | - && mb_strlen($settings['matomo_url']) > 0 |
|
92 | - && mb_strlen($settings['matomo_token']) > 0 |
|
93 | - && $settings['matomo_siteid'] > 0 |
|
94 | - ) { |
|
95 | - try { |
|
96 | - $http_client = new Client([ |
|
97 | - RequestOptions::TIMEOUT => 30 |
|
98 | - ]); |
|
89 | + if ( |
|
90 | + $settings['matomo_enabled'] === true |
|
91 | + && mb_strlen($settings['matomo_url']) > 0 |
|
92 | + && mb_strlen($settings['matomo_token']) > 0 |
|
93 | + && $settings['matomo_siteid'] > 0 |
|
94 | + ) { |
|
95 | + try { |
|
96 | + $http_client = new Client([ |
|
97 | + RequestOptions::TIMEOUT => 30 |
|
98 | + ]); |
|
99 | 99 | |
100 | - $response = $http_client->get($settings['matomo_url'], [ |
|
101 | - 'query' => [ |
|
102 | - 'module' => 'API', |
|
103 | - 'method' => 'VisitsSummary.getVisits', |
|
104 | - 'idSite' => $settings['matomo_siteid'], |
|
105 | - 'period' => $period, |
|
106 | - 'date' => 'today', |
|
107 | - 'token_auth' => $settings['matomo_token'], |
|
108 | - 'format' => 'json' |
|
109 | - ] |
|
110 | - ]); |
|
100 | + $response = $http_client->get($settings['matomo_url'], [ |
|
101 | + 'query' => [ |
|
102 | + 'module' => 'API', |
|
103 | + 'method' => 'VisitsSummary.getVisits', |
|
104 | + 'idSite' => $settings['matomo_siteid'], |
|
105 | + 'period' => $period, |
|
106 | + 'date' => 'today', |
|
107 | + 'token_auth' => $settings['matomo_token'], |
|
108 | + 'format' => 'json' |
|
109 | + ] |
|
110 | + ]); |
|
111 | 111 | |
112 | - if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
113 | - $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
114 | - if ($result !== null) { |
|
115 | - return (int)$result; |
|
116 | - } |
|
117 | - } |
|
118 | - } catch (RequestException $ex) { |
|
119 | - } |
|
120 | - } |
|
112 | + if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
113 | + $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
114 | + if ($result !== null) { |
|
115 | + return (int)$result; |
|
116 | + } |
|
117 | + } |
|
118 | + } catch (RequestException $ex) { |
|
119 | + } |
|
120 | + } |
|
121 | 121 | |
122 | - return null; |
|
123 | - } |
|
122 | + return null; |
|
123 | + } |
|
124 | 124 | } |
@@ -43,13 +43,13 @@ discard block |
||
43 | 43 | $cache = Registry::cache()->file(); |
44 | 44 | |
45 | 45 | return $cache->remember( |
46 | - $module->name() . '-matomovisits-yearly-' . $block_id, |
|
47 | - function () use ($module, $block_id): ?int { |
|
46 | + $module->name().'-matomovisits-yearly-'.$block_id, |
|
47 | + function() use ($module, $block_id): ?int { |
|
48 | 48 | $visits_year = $this->visits($module, $block_id, 'year'); |
49 | 49 | if ($visits_year === null) { |
50 | 50 | return null; |
51 | 51 | } |
52 | - $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
52 | + $visits_today = (int)$this->visits($module, $block_id, 'day'); |
|
53 | 53 | |
54 | 54 | return $visits_year - $visits_today; |
55 | 55 | }, |
@@ -67,8 +67,8 @@ discard block |
||
67 | 67 | public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
68 | 68 | { |
69 | 69 | return app('cache.array')->remember( |
70 | - $module->name() . '-matomovisits-daily-' . $block_id, |
|
71 | - function () use ($module, $block_id): ?int { |
|
70 | + $module->name().'-matomovisits-daily-'.$block_id, |
|
71 | + function() use ($module, $block_id) : ?int { |
|
72 | 72 | return $this->visits($module, $block_id, 'day'); |
73 | 73 | } |
74 | 74 | ); |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | ]); |
111 | 111 | |
112 | 112 | if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
113 | - $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
113 | + $result = json_decode((string)$response->getBody(), true)['value'] ?? null; |
|
114 | 114 | if ($result !== null) { |
115 | 115 | return (int)$result; |
116 | 116 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | //How to update the database schema for this module |
52 | 52 | private const SCHEMA_TARGET_VERSION = 2; |
53 | 53 | private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
54 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
54 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema'; |
|
55 | 55 | |
56 | 56 | /** |
57 | 57 | * {@inheritDoc} |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public function loadRoutes(Map $router): void |
93 | 93 | { |
94 | - $router->attach('', '', static function (Map $router): void { |
|
94 | + $router->attach('', '', static function(Map $router): void { |
|
95 | 95 | |
96 | - $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
96 | + $router->attach('', '/module-maj/admintasks', static function(Map $router): void { |
|
97 | 97 | |
98 | - $router->attach('', '/admin', static function (Map $router): void { |
|
98 | + $router->attach('', '/admin', static function(Map $router): void { |
|
99 | 99 | |
100 | 100 | $router->extras([ |
101 | 101 | 'middleware' => [ |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | ]); |
105 | 105 | $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
106 | 106 | |
107 | - $router->attach('', '/tasks', static function (Map $router): void { |
|
107 | + $router->attach('', '/tasks', static function(Map $router): void { |
|
108 | 108 | |
109 | 109 | $router->get(TasksList::class, '', TasksList::class); |
110 | 110 | $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | */ |
147 | 147 | public function bodyContent(): string |
148 | 148 | { |
149 | - return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
149 | + return view($this->name().'::snippet', ['url' => route(TaskTrigger::class)]); |
|
150 | 150 | } |
151 | 151 | |
152 | 152 | /** |
@@ -41,126 +41,126 @@ |
||
41 | 41 | * Allow for tasks to be run on a (nearly-)regular schedule |
42 | 42 | */ |
43 | 43 | class AdminTasksModule extends AbstractModule implements |
44 | - ModuleMyArtJaubInterface, |
|
45 | - ModuleConfigInterface, |
|
46 | - ModuleGlobalInterface, |
|
47 | - ModuleTasksProviderInterface |
|
44 | + ModuleMyArtJaubInterface, |
|
45 | + ModuleConfigInterface, |
|
46 | + ModuleGlobalInterface, |
|
47 | + ModuleTasksProviderInterface |
|
48 | 48 | { |
49 | - use ModuleMyArtJaubTrait { |
|
50 | - boot as traitBoot; |
|
51 | - } |
|
52 | - use ModuleConfigTrait; |
|
53 | - use ModuleGlobalTrait; |
|
54 | - |
|
55 | - //How to update the database schema for this module |
|
56 | - private const SCHEMA_TARGET_VERSION = 2; |
|
57 | - private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
|
58 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | - */ |
|
64 | - public function title(): string |
|
65 | - { |
|
66 | - return I18N::translate('Administration Tasks'); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | - */ |
|
73 | - public function description(): string |
|
74 | - { |
|
75 | - return I18N::translate('Manage and run nearly-scheduled administration tasks.'); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * {@inheritDoc} |
|
80 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
81 | - */ |
|
82 | - public function boot(): void |
|
83 | - { |
|
84 | - $this->traitBoot(); |
|
85 | - app(MigrationService::class)->updateSchema( |
|
86 | - self::SCHEMA_MIGRATION_PREFIX, |
|
87 | - self::SCHEMA_SETTING_NAME, |
|
88 | - self::SCHEMA_TARGET_VERSION |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * {@inheritDoc} |
|
94 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
95 | - */ |
|
96 | - public function loadRoutes(Map $router): void |
|
97 | - { |
|
98 | - $router->attach('', '', static function (Map $router): void { |
|
99 | - |
|
100 | - $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
101 | - |
|
102 | - $router->attach('', '/admin', static function (Map $router): void { |
|
103 | - |
|
104 | - $router->extras([ |
|
105 | - 'middleware' => [ |
|
106 | - AuthAdministrator::class, |
|
107 | - ], |
|
108 | - ]); |
|
109 | - $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
110 | - |
|
111 | - $router->attach('', '/tasks', static function (Map $router): void { |
|
112 | - |
|
113 | - $router->get(TasksList::class, '', TasksList::class); |
|
114 | - $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
115 | - $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
116 | - $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
117 | - }); |
|
118 | - }); |
|
119 | - |
|
120 | - $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
121 | - ->allows(RequestMethodInterface::METHOD_POST); |
|
122 | - |
|
123 | - $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
124 | - ->extras(['middleware' => [AuthAdministrator::class]]); |
|
125 | - }); |
|
126 | - }); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * {@inheritDoc} |
|
131 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
132 | - */ |
|
133 | - public function customModuleVersion(): string |
|
134 | - { |
|
135 | - return '2.0.11-v.1'; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * {@inheritDoc} |
|
140 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
141 | - */ |
|
142 | - public function getConfigLink(): string |
|
143 | - { |
|
144 | - return route(AdminConfigPage::class); |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * {@inheritDoc} |
|
149 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
150 | - */ |
|
151 | - public function bodyContent(): string |
|
152 | - { |
|
153 | - return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * {@inheritDoc} |
|
158 | - * @see \MyArtJaub\Webtrees\Module\AdminTasks\Contracts\ModuleTasksProviderInterface::listTasks() |
|
159 | - */ |
|
160 | - public function listTasks(): array |
|
161 | - { |
|
162 | - return [ |
|
163 | - 'maj-healthcheck' => HealthCheckEmailTask::class |
|
164 | - ]; |
|
165 | - } |
|
49 | + use ModuleMyArtJaubTrait { |
|
50 | + boot as traitBoot; |
|
51 | + } |
|
52 | + use ModuleConfigTrait; |
|
53 | + use ModuleGlobalTrait; |
|
54 | + |
|
55 | + //How to update the database schema for this module |
|
56 | + private const SCHEMA_TARGET_VERSION = 2; |
|
57 | + private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
|
58 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | + */ |
|
64 | + public function title(): string |
|
65 | + { |
|
66 | + return I18N::translate('Administration Tasks'); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | + */ |
|
73 | + public function description(): string |
|
74 | + { |
|
75 | + return I18N::translate('Manage and run nearly-scheduled administration tasks.'); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * {@inheritDoc} |
|
80 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
81 | + */ |
|
82 | + public function boot(): void |
|
83 | + { |
|
84 | + $this->traitBoot(); |
|
85 | + app(MigrationService::class)->updateSchema( |
|
86 | + self::SCHEMA_MIGRATION_PREFIX, |
|
87 | + self::SCHEMA_SETTING_NAME, |
|
88 | + self::SCHEMA_TARGET_VERSION |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * {@inheritDoc} |
|
94 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
95 | + */ |
|
96 | + public function loadRoutes(Map $router): void |
|
97 | + { |
|
98 | + $router->attach('', '', static function (Map $router): void { |
|
99 | + |
|
100 | + $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
101 | + |
|
102 | + $router->attach('', '/admin', static function (Map $router): void { |
|
103 | + |
|
104 | + $router->extras([ |
|
105 | + 'middleware' => [ |
|
106 | + AuthAdministrator::class, |
|
107 | + ], |
|
108 | + ]); |
|
109 | + $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
110 | + |
|
111 | + $router->attach('', '/tasks', static function (Map $router): void { |
|
112 | + |
|
113 | + $router->get(TasksList::class, '', TasksList::class); |
|
114 | + $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
115 | + $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
116 | + $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
117 | + }); |
|
118 | + }); |
|
119 | + |
|
120 | + $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
121 | + ->allows(RequestMethodInterface::METHOD_POST); |
|
122 | + |
|
123 | + $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
124 | + ->extras(['middleware' => [AuthAdministrator::class]]); |
|
125 | + }); |
|
126 | + }); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * {@inheritDoc} |
|
131 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
132 | + */ |
|
133 | + public function customModuleVersion(): string |
|
134 | + { |
|
135 | + return '2.0.11-v.1'; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * {@inheritDoc} |
|
140 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
141 | + */ |
|
142 | + public function getConfigLink(): string |
|
143 | + { |
|
144 | + return route(AdminConfigPage::class); |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * {@inheritDoc} |
|
149 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
150 | + */ |
|
151 | + public function bodyContent(): string |
|
152 | + { |
|
153 | + return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * {@inheritDoc} |
|
158 | + * @see \MyArtJaub\Webtrees\Module\AdminTasks\Contracts\ModuleTasksProviderInterface::listTasks() |
|
159 | + */ |
|
160 | + public function listTasks(): array |
|
161 | + { |
|
162 | + return [ |
|
163 | + 'maj-healthcheck' => HealthCheckEmailTask::class |
|
164 | + ]; |
|
165 | + } |
|
166 | 166 | } |
@@ -25,290 +25,290 @@ |
||
25 | 25 | class TaskSchedule |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Task Schedule ID |
|
30 | - * @var int $id |
|
31 | - */ |
|
32 | - private $id; |
|
33 | - |
|
34 | - /** |
|
35 | - * Task schedule status |
|
36 | - * @var bool $enabled |
|
37 | - */ |
|
38 | - private $enabled; |
|
39 | - |
|
40 | - /** |
|
41 | - * ID of the task attached to schedule |
|
42 | - * @var string $task_id |
|
43 | - */ |
|
44 | - private $task_id; |
|
45 | - |
|
46 | - /** |
|
47 | - * Last updated date |
|
48 | - * @var Carbon $last_run |
|
49 | - */ |
|
50 | - private $last_run; |
|
51 | - |
|
52 | - /** |
|
53 | - * Last run result |
|
54 | - * @var bool $last_result |
|
55 | - */ |
|
56 | - private $last_result; |
|
57 | - |
|
58 | - /** |
|
59 | - * Task run frequency |
|
60 | - * @var CarbonInterval $frequency |
|
61 | - */ |
|
62 | - private $frequency; |
|
63 | - |
|
64 | - /** |
|
65 | - * Task remaining runs |
|
66 | - * @var int $nb_occurrences |
|
67 | - */ |
|
68 | - private $nb_occurrences; |
|
69 | - |
|
70 | - /** |
|
71 | - * Current running status of the task |
|
72 | - * @var bool $is_running |
|
73 | - */ |
|
74 | - private $is_running; |
|
75 | - |
|
76 | - /** |
|
77 | - * Constructor for TaskSchedule |
|
78 | - * |
|
79 | - * @param int $id Schedule ID |
|
80 | - * @param string $task_id Task ID |
|
81 | - * @param bool $enabled Is the schedule enabled |
|
82 | - * @param Carbon $last_run Last successful run date/time |
|
83 | - * @param bool $last_result Result of the last run |
|
84 | - * @param CarbonInterval $frequency Schedule frequency |
|
85 | - * @param int $nb_occurrences Number of remaining occurrences to be run |
|
86 | - * @param bool $is_running Is the task currently running |
|
87 | - */ |
|
88 | - public function __construct( |
|
89 | - int $id, |
|
90 | - string $task_id, |
|
91 | - bool $enabled, |
|
92 | - Carbon $last_run, |
|
93 | - bool $last_result, |
|
94 | - CarbonInterval $frequency, |
|
95 | - int $nb_occurrences, |
|
96 | - bool $is_running |
|
97 | - ) { |
|
98 | - $this->id = $id; |
|
99 | - $this->task_id = $task_id; |
|
100 | - $this->enabled = $enabled; |
|
101 | - $this->last_run = $last_run; |
|
102 | - $this->last_result = $last_result; |
|
103 | - $this->frequency = $frequency; |
|
104 | - $this->nb_occurrences = $nb_occurrences; |
|
105 | - $this->is_running = $is_running; |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Get the schedule ID. |
|
110 | - * |
|
111 | - * @return int |
|
112 | - */ |
|
113 | - public function id(): int |
|
114 | - { |
|
115 | - return $this->id; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Get the task ID. |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function taskId(): string |
|
124 | - { |
|
125 | - return $this->task_id; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Returns whether the schedule is enabled |
|
130 | - * |
|
131 | - * @return bool |
|
132 | - */ |
|
133 | - public function isEnabled(): bool |
|
134 | - { |
|
135 | - return $this->enabled; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Enable the schedule |
|
140 | - * |
|
141 | - * @return self |
|
142 | - */ |
|
143 | - public function enable(): self |
|
144 | - { |
|
145 | - $this->enabled = true; |
|
146 | - return $this; |
|
147 | - } |
|
148 | - |
|
149 | - /** |
|
150 | - * Disable the schedule |
|
151 | - * |
|
152 | - * @return self |
|
153 | - */ |
|
154 | - public function disable(): self |
|
155 | - { |
|
156 | - $this->enabled = false; |
|
157 | - return $this; |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * Get the frequency of the schedule |
|
162 | - * |
|
163 | - * @return CarbonInterval |
|
164 | - */ |
|
165 | - public function frequency(): CarbonInterval |
|
166 | - { |
|
167 | - return $this->frequency; |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Set the frequency of the schedule |
|
172 | - * |
|
173 | - * @param CarbonInterval $frequency |
|
174 | - * @return self |
|
175 | - */ |
|
176 | - public function setFrequency(CarbonInterval $frequency): self |
|
177 | - { |
|
178 | - $this->frequency = $frequency; |
|
179 | - return $this; |
|
180 | - } |
|
181 | - |
|
182 | - /** |
|
183 | - * Get the date/time of the last successful run. |
|
184 | - * |
|
185 | - * @return Carbon |
|
186 | - */ |
|
187 | - public function lastRunTime(): Carbon |
|
188 | - { |
|
189 | - return $this->last_run; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Set the last successful run date/time |
|
194 | - * |
|
195 | - * @param Carbon $last_run |
|
196 | - * @return self |
|
197 | - */ |
|
198 | - public function setLastRunTime(Carbon $last_run): self |
|
199 | - { |
|
200 | - $this->last_run = $last_run; |
|
201 | - return $this; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Returns whether the last run was successful |
|
206 | - * |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - public function wasLastRunSuccess(): bool |
|
210 | - { |
|
211 | - return $this->last_result; |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * Set the last run result |
|
216 | - * |
|
217 | - * @param bool $last_result |
|
218 | - * @return self |
|
219 | - */ |
|
220 | - public function setLastResult(bool $last_result): self |
|
221 | - { |
|
222 | - $this->last_result = $last_result; |
|
223 | - return $this; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Get the number of remaining of occurrences of task runs. |
|
228 | - * Returns 0 if the tasks must be run indefinitely. |
|
229 | - * |
|
230 | - * @return int |
|
231 | - */ |
|
232 | - public function remainingOccurences(): int |
|
233 | - { |
|
234 | - return $this->nb_occurrences; |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Decrements the number of remaining occurences by 1. |
|
239 | - * The task will be disabled when the number reaches 0. |
|
240 | - * |
|
241 | - * @return self |
|
242 | - */ |
|
243 | - public function decrementRemainingOccurences(): self |
|
244 | - { |
|
245 | - if ($this->nb_occurrences > 0) { |
|
246 | - $this->nb_occurrences--; |
|
247 | - if ($this->nb_occurrences == 0) { |
|
248 | - $this->disable(); |
|
249 | - } |
|
250 | - } |
|
251 | - return $this; |
|
252 | - } |
|
253 | - |
|
254 | - /** |
|
255 | - * Set the number of remaining occurences of task runs. |
|
256 | - * |
|
257 | - * @param int $nb_occurrences |
|
258 | - * @return self |
|
259 | - */ |
|
260 | - public function setRemainingOccurences(int $nb_occurrences): self |
|
261 | - { |
|
262 | - $this->nb_occurrences = $nb_occurrences; |
|
263 | - return $this; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Returns whether the task is running |
|
268 | - * @return bool |
|
269 | - */ |
|
270 | - public function isRunning(): bool |
|
271 | - { |
|
272 | - return $this->is_running; |
|
273 | - } |
|
274 | - |
|
275 | - /** |
|
276 | - * Informs the schedule that the task is going to run |
|
277 | - * |
|
278 | - * @return self |
|
279 | - */ |
|
280 | - public function startRunning(): self |
|
281 | - { |
|
282 | - $this->is_running = true; |
|
283 | - return $this; |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Informs the schedule that the task has stopped running. |
|
288 | - * @return self |
|
289 | - */ |
|
290 | - public function stopRunning(): self |
|
291 | - { |
|
292 | - $this->is_running = false; |
|
293 | - return $this; |
|
294 | - } |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns the schedule details as an associate array |
|
298 | - * |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function toArray(): array |
|
302 | - { |
|
303 | - return [ |
|
304 | - 'id' => $this->id, |
|
305 | - 'task_id' => $this->task_id, |
|
306 | - 'enabled' => $this->enabled, |
|
307 | - 'last_run' => $this->last_run, |
|
308 | - 'last_result' => $this->last_result, |
|
309 | - 'frequency' => $this->frequency, |
|
310 | - 'nb_occurrences' => $this->nb_occurrences, |
|
311 | - 'is_running' => $this->is_running |
|
312 | - ]; |
|
313 | - } |
|
28 | + /** |
|
29 | + * Task Schedule ID |
|
30 | + * @var int $id |
|
31 | + */ |
|
32 | + private $id; |
|
33 | + |
|
34 | + /** |
|
35 | + * Task schedule status |
|
36 | + * @var bool $enabled |
|
37 | + */ |
|
38 | + private $enabled; |
|
39 | + |
|
40 | + /** |
|
41 | + * ID of the task attached to schedule |
|
42 | + * @var string $task_id |
|
43 | + */ |
|
44 | + private $task_id; |
|
45 | + |
|
46 | + /** |
|
47 | + * Last updated date |
|
48 | + * @var Carbon $last_run |
|
49 | + */ |
|
50 | + private $last_run; |
|
51 | + |
|
52 | + /** |
|
53 | + * Last run result |
|
54 | + * @var bool $last_result |
|
55 | + */ |
|
56 | + private $last_result; |
|
57 | + |
|
58 | + /** |
|
59 | + * Task run frequency |
|
60 | + * @var CarbonInterval $frequency |
|
61 | + */ |
|
62 | + private $frequency; |
|
63 | + |
|
64 | + /** |
|
65 | + * Task remaining runs |
|
66 | + * @var int $nb_occurrences |
|
67 | + */ |
|
68 | + private $nb_occurrences; |
|
69 | + |
|
70 | + /** |
|
71 | + * Current running status of the task |
|
72 | + * @var bool $is_running |
|
73 | + */ |
|
74 | + private $is_running; |
|
75 | + |
|
76 | + /** |
|
77 | + * Constructor for TaskSchedule |
|
78 | + * |
|
79 | + * @param int $id Schedule ID |
|
80 | + * @param string $task_id Task ID |
|
81 | + * @param bool $enabled Is the schedule enabled |
|
82 | + * @param Carbon $last_run Last successful run date/time |
|
83 | + * @param bool $last_result Result of the last run |
|
84 | + * @param CarbonInterval $frequency Schedule frequency |
|
85 | + * @param int $nb_occurrences Number of remaining occurrences to be run |
|
86 | + * @param bool $is_running Is the task currently running |
|
87 | + */ |
|
88 | + public function __construct( |
|
89 | + int $id, |
|
90 | + string $task_id, |
|
91 | + bool $enabled, |
|
92 | + Carbon $last_run, |
|
93 | + bool $last_result, |
|
94 | + CarbonInterval $frequency, |
|
95 | + int $nb_occurrences, |
|
96 | + bool $is_running |
|
97 | + ) { |
|
98 | + $this->id = $id; |
|
99 | + $this->task_id = $task_id; |
|
100 | + $this->enabled = $enabled; |
|
101 | + $this->last_run = $last_run; |
|
102 | + $this->last_result = $last_result; |
|
103 | + $this->frequency = $frequency; |
|
104 | + $this->nb_occurrences = $nb_occurrences; |
|
105 | + $this->is_running = $is_running; |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Get the schedule ID. |
|
110 | + * |
|
111 | + * @return int |
|
112 | + */ |
|
113 | + public function id(): int |
|
114 | + { |
|
115 | + return $this->id; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Get the task ID. |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function taskId(): string |
|
124 | + { |
|
125 | + return $this->task_id; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Returns whether the schedule is enabled |
|
130 | + * |
|
131 | + * @return bool |
|
132 | + */ |
|
133 | + public function isEnabled(): bool |
|
134 | + { |
|
135 | + return $this->enabled; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Enable the schedule |
|
140 | + * |
|
141 | + * @return self |
|
142 | + */ |
|
143 | + public function enable(): self |
|
144 | + { |
|
145 | + $this->enabled = true; |
|
146 | + return $this; |
|
147 | + } |
|
148 | + |
|
149 | + /** |
|
150 | + * Disable the schedule |
|
151 | + * |
|
152 | + * @return self |
|
153 | + */ |
|
154 | + public function disable(): self |
|
155 | + { |
|
156 | + $this->enabled = false; |
|
157 | + return $this; |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * Get the frequency of the schedule |
|
162 | + * |
|
163 | + * @return CarbonInterval |
|
164 | + */ |
|
165 | + public function frequency(): CarbonInterval |
|
166 | + { |
|
167 | + return $this->frequency; |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Set the frequency of the schedule |
|
172 | + * |
|
173 | + * @param CarbonInterval $frequency |
|
174 | + * @return self |
|
175 | + */ |
|
176 | + public function setFrequency(CarbonInterval $frequency): self |
|
177 | + { |
|
178 | + $this->frequency = $frequency; |
|
179 | + return $this; |
|
180 | + } |
|
181 | + |
|
182 | + /** |
|
183 | + * Get the date/time of the last successful run. |
|
184 | + * |
|
185 | + * @return Carbon |
|
186 | + */ |
|
187 | + public function lastRunTime(): Carbon |
|
188 | + { |
|
189 | + return $this->last_run; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Set the last successful run date/time |
|
194 | + * |
|
195 | + * @param Carbon $last_run |
|
196 | + * @return self |
|
197 | + */ |
|
198 | + public function setLastRunTime(Carbon $last_run): self |
|
199 | + { |
|
200 | + $this->last_run = $last_run; |
|
201 | + return $this; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Returns whether the last run was successful |
|
206 | + * |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + public function wasLastRunSuccess(): bool |
|
210 | + { |
|
211 | + return $this->last_result; |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * Set the last run result |
|
216 | + * |
|
217 | + * @param bool $last_result |
|
218 | + * @return self |
|
219 | + */ |
|
220 | + public function setLastResult(bool $last_result): self |
|
221 | + { |
|
222 | + $this->last_result = $last_result; |
|
223 | + return $this; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Get the number of remaining of occurrences of task runs. |
|
228 | + * Returns 0 if the tasks must be run indefinitely. |
|
229 | + * |
|
230 | + * @return int |
|
231 | + */ |
|
232 | + public function remainingOccurences(): int |
|
233 | + { |
|
234 | + return $this->nb_occurrences; |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Decrements the number of remaining occurences by 1. |
|
239 | + * The task will be disabled when the number reaches 0. |
|
240 | + * |
|
241 | + * @return self |
|
242 | + */ |
|
243 | + public function decrementRemainingOccurences(): self |
|
244 | + { |
|
245 | + if ($this->nb_occurrences > 0) { |
|
246 | + $this->nb_occurrences--; |
|
247 | + if ($this->nb_occurrences == 0) { |
|
248 | + $this->disable(); |
|
249 | + } |
|
250 | + } |
|
251 | + return $this; |
|
252 | + } |
|
253 | + |
|
254 | + /** |
|
255 | + * Set the number of remaining occurences of task runs. |
|
256 | + * |
|
257 | + * @param int $nb_occurrences |
|
258 | + * @return self |
|
259 | + */ |
|
260 | + public function setRemainingOccurences(int $nb_occurrences): self |
|
261 | + { |
|
262 | + $this->nb_occurrences = $nb_occurrences; |
|
263 | + return $this; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Returns whether the task is running |
|
268 | + * @return bool |
|
269 | + */ |
|
270 | + public function isRunning(): bool |
|
271 | + { |
|
272 | + return $this->is_running; |
|
273 | + } |
|
274 | + |
|
275 | + /** |
|
276 | + * Informs the schedule that the task is going to run |
|
277 | + * |
|
278 | + * @return self |
|
279 | + */ |
|
280 | + public function startRunning(): self |
|
281 | + { |
|
282 | + $this->is_running = true; |
|
283 | + return $this; |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Informs the schedule that the task has stopped running. |
|
288 | + * @return self |
|
289 | + */ |
|
290 | + public function stopRunning(): self |
|
291 | + { |
|
292 | + $this->is_running = false; |
|
293 | + return $this; |
|
294 | + } |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns the schedule details as an associate array |
|
298 | + * |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function toArray(): array |
|
302 | + { |
|
303 | + return [ |
|
304 | + 'id' => $this->id, |
|
305 | + 'task_id' => $this->task_id, |
|
306 | + 'enabled' => $this->enabled, |
|
307 | + 'last_run' => $this->last_run, |
|
308 | + 'last_result' => $this->last_result, |
|
309 | + 'frequency' => $this->frequency, |
|
310 | + 'nb_occurrences' => $this->nb_occurrences, |
|
311 | + 'is_running' => $this->is_running |
|
312 | + ]; |
|
313 | + } |
|
314 | 314 | } |