@@ -30,58 +30,58 @@ |
||
30 | 30 | */ |
31 | 31 | class ModulesHooksAction extends AbstractModuleComponentAction |
32 | 32 | { |
33 | - protected HookService $hook_service; |
|
33 | + protected HookService $hook_service; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor for ModulesHooksAction Request Handler |
|
37 | - * |
|
38 | - * @param ModuleService $module_service |
|
39 | - * @param TreeService $tree_service |
|
40 | - * @param HookService $hook_service |
|
41 | - */ |
|
42 | - public function __construct(ModuleService $module_service, TreeService $tree_service, HookService $hook_service) |
|
43 | - { |
|
44 | - parent::__construct($module_service, $tree_service); |
|
45 | - $this->hook_service = $hook_service; |
|
46 | - } |
|
35 | + /** |
|
36 | + * Constructor for ModulesHooksAction Request Handler |
|
37 | + * |
|
38 | + * @param ModuleService $module_service |
|
39 | + * @param TreeService $tree_service |
|
40 | + * @param HookService $hook_service |
|
41 | + */ |
|
42 | + public function __construct(ModuleService $module_service, TreeService $tree_service, HookService $hook_service) |
|
43 | + { |
|
44 | + parent::__construct($module_service, $tree_service); |
|
45 | + $this->hook_service = $hook_service; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
51 | - */ |
|
52 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
53 | - { |
|
54 | - $hook_name = Validator::attributes($request)->string('hook_name', ''); |
|
55 | - $hook_collector = $this->hook_service->find($hook_name, true); |
|
56 | - if ($hook_collector === null) { |
|
57 | - FlashMessages::addMessage(I18N::translate('The hook with name “%s” does not exist.', $hook_name), 'danger'); |
|
58 | - return redirect(AdminConfigPage::class); |
|
59 | - } |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
51 | + */ |
|
52 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
53 | + { |
|
54 | + $hook_name = Validator::attributes($request)->string('hook_name', ''); |
|
55 | + $hook_collector = $this->hook_service->find($hook_name, true); |
|
56 | + if ($hook_collector === null) { |
|
57 | + FlashMessages::addMessage(I18N::translate('The hook with name “%s” does not exist.', $hook_name), 'danger'); |
|
58 | + return redirect(AdminConfigPage::class); |
|
59 | + } |
|
60 | 60 | |
61 | - foreach ($hook_collector->hooks() as $hook) { |
|
62 | - $this->updateStatus(get_class($hook->module()), $request); |
|
63 | - } |
|
61 | + foreach ($hook_collector->hooks() as $hook) { |
|
62 | + $this->updateStatus(get_class($hook->module()), $request); |
|
63 | + } |
|
64 | 64 | |
65 | - $this->updateHookOrder($hook_collector, $request); |
|
65 | + $this->updateHookOrder($hook_collector, $request); |
|
66 | 66 | |
67 | - FlashMessages::addMessage(I18N::translate('The hook preferences have been updated.'), 'success'); |
|
67 | + FlashMessages::addMessage(I18N::translate('The hook preferences have been updated.'), 'success'); |
|
68 | 68 | |
69 | - return redirect(route(ModulesHooksPage::class, ['hook_name' => $hook_name])); |
|
70 | - } |
|
69 | + return redirect(route(ModulesHooksPage::class, ['hook_name' => $hook_name])); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Update the order of modules for a hook interface. |
|
74 | - * |
|
75 | - * @param HookCollectorInterface $hook_collector |
|
76 | - * @param ServerRequestInterface $request |
|
77 | - */ |
|
78 | - protected function updateHookOrder(HookCollectorInterface $hook_collector, ServerRequestInterface $request): void |
|
79 | - { |
|
80 | - $order = Validator::parsedBody($request)->array('order'); |
|
81 | - $order = array_flip($order); |
|
72 | + /** |
|
73 | + * Update the order of modules for a hook interface. |
|
74 | + * |
|
75 | + * @param HookCollectorInterface $hook_collector |
|
76 | + * @param ServerRequestInterface $request |
|
77 | + */ |
|
78 | + protected function updateHookOrder(HookCollectorInterface $hook_collector, ServerRequestInterface $request): void |
|
79 | + { |
|
80 | + $order = Validator::parsedBody($request)->array('order'); |
|
81 | + $order = array_flip($order); |
|
82 | 82 | |
83 | - foreach ($hook_collector->hooks() as $hook) { |
|
84 | - $this->hook_service->updateOrder($hook_collector, $hook->module(), $order[$hook->module()->name()] ?? 0); |
|
85 | - } |
|
86 | - } |
|
83 | + foreach ($hook_collector->hooks() as $hook) { |
|
84 | + $this->hook_service->updateOrder($hook_collector, $hook->module(), $order[$hook->module()->name()] ?? 0); |
|
85 | + } |
|
86 | + } |
|
87 | 87 | } |
@@ -29,44 +29,44 @@ |
||
29 | 29 | */ |
30 | 30 | class ModulesHooksPage implements RequestHandlerInterface |
31 | 31 | { |
32 | - use ViewResponseTrait; |
|
32 | + use ViewResponseTrait; |
|
33 | 33 | |
34 | - protected HookService $hook_service; |
|
34 | + protected HookService $hook_service; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for ModulesHooksPage request handler |
|
38 | - * |
|
39 | - * @param HookService $hook_service |
|
40 | - */ |
|
41 | - public function __construct(HookService $hook_service) |
|
42 | - { |
|
43 | - $this->hook_service = $hook_service; |
|
44 | - } |
|
36 | + /** |
|
37 | + * Constructor for ModulesHooksPage request handler |
|
38 | + * |
|
39 | + * @param HookService $hook_service |
|
40 | + */ |
|
41 | + public function __construct(HookService $hook_service) |
|
42 | + { |
|
43 | + $this->hook_service = $hook_service; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | - */ |
|
50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | - { |
|
52 | - $this->layout = 'layouts/administration'; |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | + */ |
|
50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | + { |
|
52 | + $this->layout = 'layouts/administration'; |
|
53 | 53 | |
54 | - $hook_name = Validator::attributes($request)->string('hook_name', ''); |
|
55 | - $hook = $this->hook_service->find($hook_name, true); |
|
56 | - if ($hook === null) { |
|
57 | - throw new HttpNotFoundException(I18N::translate('The hook with name “%s” does not exist.', $hook_name)); |
|
58 | - } |
|
54 | + $hook_name = Validator::attributes($request)->string('hook_name', ''); |
|
55 | + $hook = $this->hook_service->find($hook_name, true); |
|
56 | + if ($hook === null) { |
|
57 | + throw new HttpNotFoundException(I18N::translate('The hook with name “%s” does not exist.', $hook_name)); |
|
58 | + } |
|
59 | 59 | |
60 | - $modules = $hook->hooks() |
|
61 | - ->sortKeys() |
|
62 | - ->mapWithKeys(fn(HookInterface $hook) => [$hook->module()->name() => $hook->module()]); |
|
60 | + $modules = $hook->hooks() |
|
61 | + ->sortKeys() |
|
62 | + ->mapWithKeys(fn(HookInterface $hook) => [$hook->module()->name() => $hook->module()]); |
|
63 | 63 | |
64 | - return $this->viewResponse('admin/components', [ |
|
65 | - 'description' => $hook->description(), |
|
66 | - 'modules' => $modules, |
|
67 | - 'title' => $hook->title(), |
|
68 | - 'uses_access' => false, |
|
69 | - 'uses_sorting' => true |
|
70 | - ]); |
|
71 | - } |
|
64 | + return $this->viewResponse('admin/components', [ |
|
65 | + 'description' => $hook->description(), |
|
66 | + 'modules' => $modules, |
|
67 | + 'title' => $hook->title(), |
|
68 | + 'uses_access' => false, |
|
69 | + 'uses_sorting' => true |
|
70 | + ]); |
|
71 | + } |
|
72 | 72 | } |
@@ -30,101 +30,101 @@ |
||
30 | 30 | */ |
31 | 31 | class HookService implements HookServiceInterface |
32 | 32 | { |
33 | - private ModuleService $module_service; |
|
33 | + private ModuleService $module_service; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor for HookService |
|
37 | - * |
|
38 | - * @param ModuleService $module_service |
|
39 | - */ |
|
40 | - public function __construct(ModuleService $module_service) |
|
41 | - { |
|
42 | - $this->module_service = $module_service; |
|
43 | - } |
|
35 | + /** |
|
36 | + * Constructor for HookService |
|
37 | + * |
|
38 | + * @param ModuleService $module_service |
|
39 | + */ |
|
40 | + public function __construct(ModuleService $module_service) |
|
41 | + { |
|
42 | + $this->module_service = $module_service; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookServiceInterface::use() |
|
48 | - */ |
|
49 | - public function use(string $hook_interface): ?HookCollectorInterface |
|
50 | - { |
|
51 | - return $this->all()->get($hook_interface); |
|
52 | - } |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookServiceInterface::use() |
|
48 | + */ |
|
49 | + public function use(string $hook_interface): ?HookCollectorInterface |
|
50 | + { |
|
51 | + return $this->all()->get($hook_interface); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Find a hook collector by its name, with or without the disabled ones. |
|
57 | - * |
|
58 | - * @param string $hook_name |
|
59 | - * @return HookCollectorInterface|null |
|
60 | - */ |
|
61 | - public function find(string $hook_name, bool $include_disabled = false): ?HookCollectorInterface |
|
62 | - { |
|
63 | - return $this->all($include_disabled) |
|
64 | - ->first(fn(HookCollectorInterface $hook_collector) => $hook_collector->name() === $hook_name); |
|
65 | - } |
|
55 | + /** |
|
56 | + * Find a hook collector by its name, with or without the disabled ones. |
|
57 | + * |
|
58 | + * @param string $hook_name |
|
59 | + * @return HookCollectorInterface|null |
|
60 | + */ |
|
61 | + public function find(string $hook_name, bool $include_disabled = false): ?HookCollectorInterface |
|
62 | + { |
|
63 | + return $this->all($include_disabled) |
|
64 | + ->first(fn(HookCollectorInterface $hook_collector) => $hook_collector->name() === $hook_name); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Get all hook collectors subscribed by modules, with hooks ordered, with or without the disabled ones. |
|
69 | - * |
|
70 | - * @param bool $include_disabled |
|
71 | - * @return Collection<string, HookCollectorInterface> |
|
72 | - */ |
|
73 | - public function all(bool $include_disabled = false): Collection |
|
74 | - { |
|
75 | - return Registry::cache()->array()->remember('all-hooks', function () use ($include_disabled): Collection { |
|
76 | - $hooks_info = DB::table('maj_hook_order') |
|
77 | - ->get() |
|
78 | - ->groupBy(['majho_hook_name', 'majho_module_name']); |
|
67 | + /** |
|
68 | + * Get all hook collectors subscribed by modules, with hooks ordered, with or without the disabled ones. |
|
69 | + * |
|
70 | + * @param bool $include_disabled |
|
71 | + * @return Collection<string, HookCollectorInterface> |
|
72 | + */ |
|
73 | + public function all(bool $include_disabled = false): Collection |
|
74 | + { |
|
75 | + return Registry::cache()->array()->remember('all-hooks', function () use ($include_disabled): Collection { |
|
76 | + $hooks_info = DB::table('maj_hook_order') |
|
77 | + ->get() |
|
78 | + ->groupBy(['majho_hook_name', 'majho_module_name']); |
|
79 | 79 | |
80 | - $hooks = $this->module_service |
|
81 | - ->findByInterface(ModuleHookSubscriberInterface::class, $include_disabled) |
|
82 | - ->flatMap(fn(ModuleHookSubscriberInterface $module) => $module->listSubscribedHooks()); |
|
80 | + $hooks = $this->module_service |
|
81 | + ->findByInterface(ModuleHookSubscriberInterface::class, $include_disabled) |
|
82 | + ->flatMap(fn(ModuleHookSubscriberInterface $module) => $module->listSubscribedHooks()); |
|
83 | 83 | |
84 | - $hook_collectors = collect(); |
|
85 | - $hook_instances = collect(); |
|
86 | - foreach ($hooks as $hook) { |
|
87 | - if (!($hook instanceof HookInterface)) { |
|
88 | - continue; |
|
89 | - } |
|
90 | - if ($hook instanceof HookCollectorInterface) { |
|
91 | - $hook_collectors->put($hook->hookInterface(), $hook); |
|
92 | - } else { |
|
93 | - $hook_instances->add($hook); |
|
94 | - } |
|
95 | - } |
|
84 | + $hook_collectors = collect(); |
|
85 | + $hook_instances = collect(); |
|
86 | + foreach ($hooks as $hook) { |
|
87 | + if (!($hook instanceof HookInterface)) { |
|
88 | + continue; |
|
89 | + } |
|
90 | + if ($hook instanceof HookCollectorInterface) { |
|
91 | + $hook_collectors->put($hook->hookInterface(), $hook); |
|
92 | + } else { |
|
93 | + $hook_instances->add($hook); |
|
94 | + } |
|
95 | + } |
|
96 | 96 | |
97 | - foreach ($hook_collectors as $hook_interface => $hook_collector) { |
|
98 | - $hook_info = $hooks_info->get($hook_collector->name()) ?? collect(); |
|
99 | - foreach ( |
|
100 | - $hook_instances->filter( |
|
101 | - fn(HookInterface $hook): bool => $hook instanceof $hook_interface |
|
102 | - ) as $hook_instance |
|
103 | - ) { |
|
104 | - $hook_module_info = $hook_info->get($hook_instance->module()->name(), collect())->first(); |
|
105 | - $hook_order = $hook_module_info instanceof stdClass ? (int) $hook_module_info->majho_hook_order : 0; |
|
106 | - $hook_collector->register($hook_instance, $hook_order); |
|
107 | - } |
|
108 | - } |
|
109 | - return $hook_collectors; |
|
110 | - }); |
|
111 | - } |
|
97 | + foreach ($hook_collectors as $hook_interface => $hook_collector) { |
|
98 | + $hook_info = $hooks_info->get($hook_collector->name()) ?? collect(); |
|
99 | + foreach ( |
|
100 | + $hook_instances->filter( |
|
101 | + fn(HookInterface $hook): bool => $hook instanceof $hook_interface |
|
102 | + ) as $hook_instance |
|
103 | + ) { |
|
104 | + $hook_module_info = $hook_info->get($hook_instance->module()->name(), collect())->first(); |
|
105 | + $hook_order = $hook_module_info instanceof stdClass ? (int) $hook_module_info->majho_hook_order : 0; |
|
106 | + $hook_collector->register($hook_instance, $hook_order); |
|
107 | + } |
|
108 | + } |
|
109 | + return $hook_collectors; |
|
110 | + }); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Update the order of the modules implementing a hook in the database. |
|
115 | - * |
|
116 | - * @param HookCollectorInterface $hook_collector |
|
117 | - * @param ModuleInterface $module |
|
118 | - * @param int $order |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function updateOrder(HookCollectorInterface $hook_collector, ModuleInterface $module, int $order): int |
|
122 | - { |
|
123 | - return DB::table('maj_hook_order') |
|
124 | - ->upsert([ |
|
125 | - 'majho_module_name' => $module->name(), |
|
126 | - 'majho_hook_name' => $hook_collector->name(), |
|
127 | - 'majho_hook_order' => $order |
|
128 | - ], ['majho_module_name', 'majho_hook_name'], ['majho_hook_order']); |
|
129 | - } |
|
113 | + /** |
|
114 | + * Update the order of the modules implementing a hook in the database. |
|
115 | + * |
|
116 | + * @param HookCollectorInterface $hook_collector |
|
117 | + * @param ModuleInterface $module |
|
118 | + * @param int $order |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function updateOrder(HookCollectorInterface $hook_collector, ModuleInterface $module, int $order): int |
|
122 | + { |
|
123 | + return DB::table('maj_hook_order') |
|
124 | + ->upsert([ |
|
125 | + 'majho_module_name' => $module->name(), |
|
126 | + 'majho_hook_name' => $hook_collector->name(), |
|
127 | + 'majho_hook_order' => $order |
|
128 | + ], ['majho_module_name', 'majho_hook_name'], ['majho_hook_order']); |
|
129 | + } |
|
130 | 130 | } |
@@ -32,64 +32,64 @@ |
||
32 | 32 | */ |
33 | 33 | class MatomoStats implements RequestHandlerInterface |
34 | 34 | { |
35 | - use ViewResponseTrait; |
|
35 | + use ViewResponseTrait; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var WelcomeBlockModule|null $module |
|
39 | - */ |
|
40 | - private $module; |
|
37 | + /** |
|
38 | + * @var WelcomeBlockModule|null $module |
|
39 | + */ |
|
40 | + private $module; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var MatomoStatsService $matomo_service |
|
44 | - */ |
|
45 | - private $matomo_service; |
|
42 | + /** |
|
43 | + * @var MatomoStatsService $matomo_service |
|
44 | + */ |
|
45 | + private $matomo_service; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Constructor for MatomoStats request handler |
|
49 | - * @param ModuleService $module_service |
|
50 | - * @param MatomoStatsService $matomo_service |
|
51 | - */ |
|
52 | - public function __construct( |
|
53 | - ModuleService $module_service, |
|
54 | - MatomoStatsService $matomo_service |
|
55 | - ) { |
|
56 | - $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first(); |
|
57 | - $this->matomo_service = $matomo_service; |
|
58 | - } |
|
47 | + /** |
|
48 | + * Constructor for MatomoStats request handler |
|
49 | + * @param ModuleService $module_service |
|
50 | + * @param MatomoStatsService $matomo_service |
|
51 | + */ |
|
52 | + public function __construct( |
|
53 | + ModuleService $module_service, |
|
54 | + MatomoStatsService $matomo_service |
|
55 | + ) { |
|
56 | + $this->module = $module_service->findByInterface(WelcomeBlockModule::class)->first(); |
|
57 | + $this->matomo_service = $matomo_service; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
63 | - */ |
|
64 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
65 | - { |
|
66 | - $this->layout = 'layouts/ajax'; |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
63 | + */ |
|
64 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
65 | + { |
|
66 | + $this->layout = 'layouts/ajax'; |
|
67 | 67 | |
68 | - if ($this->module === null) { |
|
69 | - return $this->viewResponse('errors/unhandled-exception', [ |
|
70 | - 'error' => 'The attached module could not be found.' |
|
71 | - ], StatusCodeInterface::STATUS_NOT_FOUND); |
|
72 | - } |
|
68 | + if ($this->module === null) { |
|
69 | + return $this->viewResponse('errors/unhandled-exception', [ |
|
70 | + 'error' => 'The attached module could not be found.' |
|
71 | + ], StatusCodeInterface::STATUS_NOT_FOUND); |
|
72 | + } |
|
73 | 73 | |
74 | - $block_id = Validator::attributes($request)->integer('block_id', -1); |
|
75 | - $nb_visits_year = $nb_visits_today = null; |
|
74 | + $block_id = Validator::attributes($request)->integer('block_id', -1); |
|
75 | + $nb_visits_year = $nb_visits_today = null; |
|
76 | 76 | |
77 | - try { |
|
78 | - if ($block_id !== -1 && $this->module->isMatomoEnabled($block_id)) { |
|
79 | - $nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0; |
|
80 | - $nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0) |
|
81 | - + $nb_visits_today; |
|
82 | - } |
|
83 | - } catch (Throwable $ex) { |
|
84 | - return $this->viewResponse('errors/unhandled-exception', [ |
|
85 | - 'error' => I18N::translate('Error while retrieving Matomo statistics: ') . |
|
86 | - (Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details')) |
|
87 | - ], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); |
|
88 | - } |
|
77 | + try { |
|
78 | + if ($block_id !== -1 && $this->module->isMatomoEnabled($block_id)) { |
|
79 | + $nb_visits_today = $this->matomo_service->visitsToday($this->module, $block_id) ?? 0; |
|
80 | + $nb_visits_year = ($this->matomo_service->visitsThisYear($this->module, $block_id) ?? 0) |
|
81 | + + $nb_visits_today; |
|
82 | + } |
|
83 | + } catch (Throwable $ex) { |
|
84 | + return $this->viewResponse('errors/unhandled-exception', [ |
|
85 | + 'error' => I18N::translate('Error while retrieving Matomo statistics: ') . |
|
86 | + (Auth::isAdmin() ? $ex->getMessage() : I18N::translate('Log in as admin for error details')) |
|
87 | + ], StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); |
|
88 | + } |
|
89 | 89 | |
90 | - return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
91 | - 'visits_year' => $nb_visits_year, |
|
92 | - 'visits_today' => $nb_visits_today |
|
93 | - ]); |
|
94 | - } |
|
90 | + return $this->viewResponse($this->module->name() . '::matomo-stats', [ |
|
91 | + 'visits_year' => $nb_visits_year, |
|
92 | + 'visits_today' => $nb_visits_today |
|
93 | + ]); |
|
94 | + } |
|
95 | 95 | } |
@@ -34,163 +34,163 @@ |
||
34 | 34 | */ |
35 | 35 | class WelcomeBlockModule extends AbstractModule implements ModuleMyArtJaubInterface, ModuleBlockInterface |
36 | 36 | { |
37 | - use ModuleMyArtJaubTrait; |
|
38 | - use ModuleBlockTrait; |
|
39 | - |
|
40 | - /** |
|
41 | - * {@inheritDoc} |
|
42 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
43 | - */ |
|
44 | - public function title(): string |
|
45 | - { |
|
46 | - return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * {@inheritDoc} |
|
51 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
52 | - */ |
|
53 | - public function description(): string |
|
54 | - { |
|
55 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
56 | - 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.'); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
62 | - */ |
|
63 | - public function loadRoutes(Map $router): void |
|
64 | - { |
|
65 | - $router->attach('', '', static function (Map $router): void { |
|
66 | - |
|
67 | - $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
68 | - $router->tokens(['block_id' => '\d+']); |
|
69 | - $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
70 | - }); |
|
71 | - }); |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * {@inheritDoc} |
|
76 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
77 | - */ |
|
78 | - public function customModuleVersion(): string |
|
79 | - { |
|
80 | - return '2.1.1-v.1'; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * {@inheritDoc} |
|
85 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
86 | - * |
|
87 | - * @param mixed[] $config |
|
88 | - */ |
|
89 | - public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
90 | - { |
|
91 | - $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
92 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
93 | - |
|
94 | - $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
95 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
96 | - |
|
97 | - $content = view($this->name() . '::block-embed', [ |
|
98 | - 'block_id' => $block_id, |
|
99 | - 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
100 | - 'fab_login_block_view' => $fab_login_block_view, |
|
101 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
102 | - 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
103 | - ]); |
|
104 | - |
|
105 | - if ($context !== self::CONTEXT_EMBED) { |
|
106 | - return view('modules/block-template', [ |
|
107 | - 'block' => Str::kebab($this->name()), |
|
108 | - 'id' => $block_id, |
|
109 | - 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
110 | - 'title' => e($tree->title()), |
|
111 | - 'content' => $content, |
|
112 | - ]); |
|
113 | - } |
|
114 | - |
|
115 | - return $content; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * {@inheritDoc} |
|
120 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
121 | - */ |
|
122 | - public function isTreeBlock(): bool |
|
123 | - { |
|
124 | - return true; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * {@inheritDoc} |
|
129 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
130 | - */ |
|
131 | - public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
132 | - { |
|
133 | - return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * {@inheritDoc} |
|
138 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
139 | - */ |
|
140 | - public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
141 | - { |
|
142 | - $matomo_enabled = Validator::parsedBody($request)->string('matomo_enabled', '') == 'yes'; |
|
143 | - $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
144 | - if (!$matomo_enabled) { |
|
145 | - return; |
|
146 | - } |
|
147 | - |
|
148 | - $matomo_url = trim(Validator::parsedBody($request)->string('matomo_url', '')); |
|
149 | - if (filter_var($matomo_url, FILTER_VALIDATE_URL) === false) { |
|
150 | - FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
151 | - return; |
|
152 | - } |
|
153 | - |
|
154 | - $matomo_siteid = Validator::parsedBody($request)->integer('matomo_siteid', -1); |
|
155 | - if ($matomo_siteid === -1) { |
|
156 | - FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
157 | - return; |
|
158 | - } |
|
159 | - |
|
160 | - $matomo_token = trim(Validator::parsedBody($request)->string('matomo_token', '')); |
|
161 | - |
|
162 | - $this |
|
163 | - ->setBlockSetting($block_id, 'matomo_url', $matomo_url) |
|
164 | - ->setBlockSetting($block_id, 'matomo_token', $matomo_token) |
|
165 | - ->setBlockSetting($block_id, 'matomo_siteid', (string) $matomo_siteid); |
|
166 | - |
|
167 | - Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
172 | - * |
|
173 | - * @param int $block_id |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public function isMatomoEnabled(int $block_id): bool |
|
177 | - { |
|
178 | - return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
183 | - * |
|
184 | - * @param int $block_id |
|
185 | - * @return array<string, mixed> |
|
186 | - */ |
|
187 | - public function matomoSettings(int $block_id): array |
|
188 | - { |
|
189 | - return [ |
|
190 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
191 | - 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
192 | - 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
193 | - 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
194 | - ]; |
|
195 | - } |
|
37 | + use ModuleMyArtJaubTrait; |
|
38 | + use ModuleBlockTrait; |
|
39 | + |
|
40 | + /** |
|
41 | + * {@inheritDoc} |
|
42 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
43 | + */ |
|
44 | + public function title(): string |
|
45 | + { |
|
46 | + return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
52 | + */ |
|
53 | + public function description(): string |
|
54 | + { |
|
55 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
56 | + 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.'); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
62 | + */ |
|
63 | + public function loadRoutes(Map $router): void |
|
64 | + { |
|
65 | + $router->attach('', '', static function (Map $router): void { |
|
66 | + |
|
67 | + $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
68 | + $router->tokens(['block_id' => '\d+']); |
|
69 | + $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
70 | + }); |
|
71 | + }); |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * {@inheritDoc} |
|
76 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
77 | + */ |
|
78 | + public function customModuleVersion(): string |
|
79 | + { |
|
80 | + return '2.1.1-v.1'; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * {@inheritDoc} |
|
85 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
86 | + * |
|
87 | + * @param mixed[] $config |
|
88 | + */ |
|
89 | + public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
90 | + { |
|
91 | + $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
92 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
93 | + |
|
94 | + $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
95 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
96 | + |
|
97 | + $content = view($this->name() . '::block-embed', [ |
|
98 | + 'block_id' => $block_id, |
|
99 | + 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
100 | + 'fab_login_block_view' => $fab_login_block_view, |
|
101 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
102 | + 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
103 | + ]); |
|
104 | + |
|
105 | + if ($context !== self::CONTEXT_EMBED) { |
|
106 | + return view('modules/block-template', [ |
|
107 | + 'block' => Str::kebab($this->name()), |
|
108 | + 'id' => $block_id, |
|
109 | + 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
110 | + 'title' => e($tree->title()), |
|
111 | + 'content' => $content, |
|
112 | + ]); |
|
113 | + } |
|
114 | + |
|
115 | + return $content; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * {@inheritDoc} |
|
120 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
121 | + */ |
|
122 | + public function isTreeBlock(): bool |
|
123 | + { |
|
124 | + return true; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * {@inheritDoc} |
|
129 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
130 | + */ |
|
131 | + public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
132 | + { |
|
133 | + return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * {@inheritDoc} |
|
138 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
139 | + */ |
|
140 | + public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
141 | + { |
|
142 | + $matomo_enabled = Validator::parsedBody($request)->string('matomo_enabled', '') == 'yes'; |
|
143 | + $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
144 | + if (!$matomo_enabled) { |
|
145 | + return; |
|
146 | + } |
|
147 | + |
|
148 | + $matomo_url = trim(Validator::parsedBody($request)->string('matomo_url', '')); |
|
149 | + if (filter_var($matomo_url, FILTER_VALIDATE_URL) === false) { |
|
150 | + FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
151 | + return; |
|
152 | + } |
|
153 | + |
|
154 | + $matomo_siteid = Validator::parsedBody($request)->integer('matomo_siteid', -1); |
|
155 | + if ($matomo_siteid === -1) { |
|
156 | + FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
157 | + return; |
|
158 | + } |
|
159 | + |
|
160 | + $matomo_token = trim(Validator::parsedBody($request)->string('matomo_token', '')); |
|
161 | + |
|
162 | + $this |
|
163 | + ->setBlockSetting($block_id, 'matomo_url', $matomo_url) |
|
164 | + ->setBlockSetting($block_id, 'matomo_token', $matomo_token) |
|
165 | + ->setBlockSetting($block_id, 'matomo_siteid', (string) $matomo_siteid); |
|
166 | + |
|
167 | + Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
172 | + * |
|
173 | + * @param int $block_id |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public function isMatomoEnabled(int $block_id): bool |
|
177 | + { |
|
178 | + return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
183 | + * |
|
184 | + * @param int $block_id |
|
185 | + * @return array<string, mixed> |
|
186 | + */ |
|
187 | + public function matomoSettings(int $block_id): array |
|
188 | + { |
|
189 | + return [ |
|
190 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
191 | + 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
192 | + 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
193 | + 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
194 | + ]; |
|
195 | + } |
|
196 | 196 | } |
@@ -28,93 +28,93 @@ |
||
28 | 28 | */ |
29 | 29 | class MatomoStatsService |
30 | 30 | { |
31 | - /** |
|
32 | - * Returns the number of visits for the current year (up to the day before). |
|
33 | - * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
34 | - * |
|
35 | - * @param WelcomeBlockModule $module |
|
36 | - * @param int $block_id |
|
37 | - * @return int|NULL |
|
38 | - */ |
|
39 | - public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
40 | - { |
|
41 | - return Registry::cache()->file()->remember( |
|
42 | - $module->name() . '-matomovisits-yearly-' . $block_id, |
|
43 | - function () use ($module, $block_id): ?int { |
|
44 | - $visits_year = $this->visits($module, $block_id, 'year'); |
|
45 | - if ($visits_year === null) { |
|
46 | - return null; |
|
47 | - } |
|
48 | - $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
31 | + /** |
|
32 | + * Returns the number of visits for the current year (up to the day before). |
|
33 | + * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
34 | + * |
|
35 | + * @param WelcomeBlockModule $module |
|
36 | + * @param int $block_id |
|
37 | + * @return int|NULL |
|
38 | + */ |
|
39 | + public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
40 | + { |
|
41 | + return Registry::cache()->file()->remember( |
|
42 | + $module->name() . '-matomovisits-yearly-' . $block_id, |
|
43 | + function () use ($module, $block_id): ?int { |
|
44 | + $visits_year = $this->visits($module, $block_id, 'year'); |
|
45 | + if ($visits_year === null) { |
|
46 | + return null; |
|
47 | + } |
|
48 | + $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
49 | 49 | |
50 | - return $visits_year - $visits_today; |
|
51 | - }, |
|
52 | - Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
53 | - ); |
|
54 | - } |
|
50 | + return $visits_year - $visits_today; |
|
51 | + }, |
|
52 | + Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Returns the number of visits for the current day. |
|
58 | - * |
|
59 | - * @param WelcomeBlockModule $module |
|
60 | - * @param int $block_id |
|
61 | - * @return int|NULL |
|
62 | - */ |
|
63 | - public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
64 | - { |
|
65 | - return Registry::cache()->array()->remember( |
|
66 | - $module->name() . '-matomovisits-daily-' . $block_id, |
|
67 | - function () use ($module, $block_id): ?int { |
|
68 | - return $this->visits($module, $block_id, 'day'); |
|
69 | - } |
|
70 | - ); |
|
71 | - } |
|
56 | + /** |
|
57 | + * Returns the number of visits for the current day. |
|
58 | + * |
|
59 | + * @param WelcomeBlockModule $module |
|
60 | + * @param int $block_id |
|
61 | + * @return int|NULL |
|
62 | + */ |
|
63 | + public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
64 | + { |
|
65 | + return Registry::cache()->array()->remember( |
|
66 | + $module->name() . '-matomovisits-daily-' . $block_id, |
|
67 | + function () use ($module, $block_id): ?int { |
|
68 | + return $this->visits($module, $block_id, 'day'); |
|
69 | + } |
|
70 | + ); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Invoke the Matomo API to retrieve the number of visits over a period. |
|
75 | - * |
|
76 | - * @param WelcomeBlockModule $module |
|
77 | - * @param int $block_id |
|
78 | - * @param string $period |
|
79 | - * @return int|NULL |
|
80 | - */ |
|
81 | - protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
82 | - { |
|
83 | - $settings = $module->matomoSettings($block_id); |
|
73 | + /** |
|
74 | + * Invoke the Matomo API to retrieve the number of visits over a period. |
|
75 | + * |
|
76 | + * @param WelcomeBlockModule $module |
|
77 | + * @param int $block_id |
|
78 | + * @param string $period |
|
79 | + * @return int|NULL |
|
80 | + */ |
|
81 | + protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
82 | + { |
|
83 | + $settings = $module->matomoSettings($block_id); |
|
84 | 84 | |
85 | - if ( |
|
86 | - $settings['matomo_enabled'] === true |
|
87 | - && mb_strlen($settings['matomo_url']) > 0 |
|
88 | - && mb_strlen($settings['matomo_token']) > 0 |
|
89 | - && $settings['matomo_siteid'] > 0 |
|
90 | - ) { |
|
91 | - try { |
|
92 | - $http_client = new Client([ |
|
93 | - RequestOptions::TIMEOUT => 30 |
|
94 | - ]); |
|
85 | + if ( |
|
86 | + $settings['matomo_enabled'] === true |
|
87 | + && mb_strlen($settings['matomo_url']) > 0 |
|
88 | + && mb_strlen($settings['matomo_token']) > 0 |
|
89 | + && $settings['matomo_siteid'] > 0 |
|
90 | + ) { |
|
91 | + try { |
|
92 | + $http_client = new Client([ |
|
93 | + RequestOptions::TIMEOUT => 30 |
|
94 | + ]); |
|
95 | 95 | |
96 | - $response = $http_client->get($settings['matomo_url'], [ |
|
97 | - 'query' => [ |
|
98 | - 'module' => 'API', |
|
99 | - 'method' => 'VisitsSummary.getVisits', |
|
100 | - 'idSite' => $settings['matomo_siteid'], |
|
101 | - 'period' => $period, |
|
102 | - 'date' => 'today', |
|
103 | - 'token_auth' => $settings['matomo_token'], |
|
104 | - 'format' => 'json' |
|
105 | - ] |
|
106 | - ]); |
|
96 | + $response = $http_client->get($settings['matomo_url'], [ |
|
97 | + 'query' => [ |
|
98 | + 'module' => 'API', |
|
99 | + 'method' => 'VisitsSummary.getVisits', |
|
100 | + 'idSite' => $settings['matomo_siteid'], |
|
101 | + 'period' => $period, |
|
102 | + 'date' => 'today', |
|
103 | + 'token_auth' => $settings['matomo_token'], |
|
104 | + 'format' => 'json' |
|
105 | + ] |
|
106 | + ]); |
|
107 | 107 | |
108 | - if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
109 | - $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
110 | - if ($result !== null) { |
|
111 | - return (int)$result; |
|
112 | - } |
|
113 | - } |
|
114 | - } catch (GuzzleException $ex) { |
|
115 | - } |
|
116 | - } |
|
108 | + if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
109 | + $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
110 | + if ($result !== null) { |
|
111 | + return (int)$result; |
|
112 | + } |
|
113 | + } |
|
114 | + } catch (GuzzleException $ex) { |
|
115 | + } |
|
116 | + } |
|
117 | 117 | |
118 | - return null; |
|
119 | - } |
|
118 | + return null; |
|
119 | + } |
|
120 | 120 | } |
@@ -32,67 +32,67 @@ |
||
32 | 32 | */ |
33 | 33 | class LineagesPage implements RequestHandlerInterface |
34 | 34 | { |
35 | - use ViewResponseTrait; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var PatronymicLineageModule|null $module |
|
39 | - */ |
|
40 | - private $module; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var IndividualListModule|null $indilist_module |
|
44 | - */ |
|
45 | - private $indilist_module; |
|
46 | - |
|
47 | - /** |
|
48 | - * Constructor for LineagesPage Request handler |
|
49 | - * |
|
50 | - * @param ModuleService $module_service |
|
51 | - */ |
|
52 | - public function __construct(ModuleService $module_service) |
|
53 | - { |
|
54 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
55 | - $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | - */ |
|
62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | - { |
|
64 | - if ($this->module === null) { |
|
65 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
66 | - } |
|
67 | - |
|
68 | - if ($this->indilist_module === null) { |
|
69 | - throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
70 | - } |
|
71 | - |
|
72 | - $tree = Validator::attributes($request)->tree(); |
|
73 | - $surname = Validator::attributes($request)->string('$surname', ''); |
|
74 | - |
|
75 | - $initial = mb_substr($surname, 0, 1); |
|
76 | - $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
77 | - ->reject(function (int $count, string $initial): bool { |
|
78 | - |
|
79 | - return $initial === '@' || $initial === ','; |
|
80 | - }); |
|
81 | - |
|
82 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
83 | - |
|
84 | - $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
85 | - |
|
86 | - return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
87 | - 'title' => $title, |
|
88 | - 'module' => $this->module, |
|
89 | - 'tree' => $tree, |
|
90 | - 'initials_list' => $initials_list, |
|
91 | - 'initial' => $initial, |
|
92 | - 'show_all' => 'no', |
|
93 | - 'surname' => $surname, |
|
94 | - 'lineages' => $lineages, |
|
95 | - 'nb_lineages' => $lineages !== null ? $lineages->count() : 0 |
|
96 | - ]); |
|
97 | - } |
|
35 | + use ViewResponseTrait; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var PatronymicLineageModule|null $module |
|
39 | + */ |
|
40 | + private $module; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var IndividualListModule|null $indilist_module |
|
44 | + */ |
|
45 | + private $indilist_module; |
|
46 | + |
|
47 | + /** |
|
48 | + * Constructor for LineagesPage Request handler |
|
49 | + * |
|
50 | + * @param ModuleService $module_service |
|
51 | + */ |
|
52 | + public function __construct(ModuleService $module_service) |
|
53 | + { |
|
54 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
55 | + $this->indilist_module = $module_service->findByInterface(IndividualListModule::class)->first(); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | + */ |
|
62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | + { |
|
64 | + if ($this->module === null) { |
|
65 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
66 | + } |
|
67 | + |
|
68 | + if ($this->indilist_module === null) { |
|
69 | + throw new HttpNotFoundException(I18N::translate('There is no module to handle individual lists.')); |
|
70 | + } |
|
71 | + |
|
72 | + $tree = Validator::attributes($request)->tree(); |
|
73 | + $surname = Validator::attributes($request)->string('$surname', ''); |
|
74 | + |
|
75 | + $initial = mb_substr($surname, 0, 1); |
|
76 | + $initials_list = collect($this->indilist_module->surnameAlpha($tree, false, false, I18N::locale())) |
|
77 | + ->reject(function (int $count, string $initial): bool { |
|
78 | + |
|
79 | + return $initial === '@' || $initial === ','; |
|
80 | + }); |
|
81 | + |
|
82 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $surname; |
|
83 | + |
|
84 | + $lineages = app()->make(LineageBuilder::class, ['surname' => $surname])->buildLineages(); |
|
85 | + |
|
86 | + return $this->viewResponse($this->module->name() . '::lineages-page', [ |
|
87 | + 'title' => $title, |
|
88 | + 'module' => $this->module, |
|
89 | + 'tree' => $tree, |
|
90 | + 'initials_list' => $initials_list, |
|
91 | + 'initial' => $initial, |
|
92 | + 'show_all' => 'no', |
|
93 | + 'surname' => $surname, |
|
94 | + 'lineages' => $lineages, |
|
95 | + 'nb_lineages' => $lineages !== null ? $lineages->count() : 0 |
|
96 | + ]); |
|
97 | + } |
|
98 | 98 | } |
@@ -31,59 +31,59 @@ |
||
31 | 31 | */ |
32 | 32 | class SurnamesList implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
34 | + use ViewResponseTrait; |
|
35 | 35 | |
36 | - private ?PatronymicLineageModule $module; |
|
36 | + private ?PatronymicLineageModule $module; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor for SurnamesList Request Handler |
|
40 | - * |
|
41 | - * @param ModuleService $module_service |
|
42 | - */ |
|
43 | - public function __construct(ModuleService $module_service) |
|
44 | - { |
|
45 | - $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
46 | - } |
|
38 | + /** |
|
39 | + * Constructor for SurnamesList Request Handler |
|
40 | + * |
|
41 | + * @param ModuleService $module_service |
|
42 | + */ |
|
43 | + public function __construct(ModuleService $module_service) |
|
44 | + { |
|
45 | + $this->module = $module_service->findByInterface(PatronymicLineageModule::class)->first(); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
51 | - */ |
|
52 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
53 | - { |
|
54 | - if ($this->module === null) { |
|
55 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
56 | - } |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
51 | + */ |
|
52 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
53 | + { |
|
54 | + if ($this->module === null) { |
|
55 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
56 | + } |
|
57 | 57 | |
58 | - $tree = Validator::attributes($request)->tree(); |
|
59 | - $initial = Validator::attributes($request)->string('alpha', ''); |
|
58 | + $tree = Validator::attributes($request)->tree(); |
|
59 | + $initial = Validator::attributes($request)->string('alpha', ''); |
|
60 | 60 | |
61 | - $initials_list = collect($this->module->surnameAlpha($tree, false, false, I18N::locale())) |
|
62 | - ->reject(function (int $count, string $initial): bool { |
|
63 | - return $initial === '@' || $initial === ','; |
|
64 | - }); |
|
61 | + $initials_list = collect($this->module->surnameAlpha($tree, false, false, I18N::locale())) |
|
62 | + ->reject(function (int $count, string $initial): bool { |
|
63 | + return $initial === '@' || $initial === ','; |
|
64 | + }); |
|
65 | 65 | |
66 | - $show_all = Validator::queryParams($request)->string('show_all', 'no'); |
|
66 | + $show_all = Validator::queryParams($request)->string('show_all', 'no'); |
|
67 | 67 | |
68 | - if ($show_all === 'yes') { |
|
69 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
70 | - $surnames = $this->module->surnames($tree, '', '', false, false, I18N::locale()); |
|
71 | - } elseif (mb_strlen($initial) == 1) { |
|
72 | - $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
73 | - $surnames = $this->module->surnames($tree, '', $initial, false, false, I18N::locale()); |
|
74 | - } else { |
|
75 | - $title = I18N::translate('Patronymic Lineages'); |
|
76 | - $surnames = []; |
|
77 | - } |
|
68 | + if ($show_all === 'yes') { |
|
69 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . I18N::translate('All'); |
|
70 | + $surnames = $this->module->surnames($tree, '', '', false, false, I18N::locale()); |
|
71 | + } elseif (mb_strlen($initial) == 1) { |
|
72 | + $title = I18N::translate('Patronymic Lineages') . ' — ' . $initial; |
|
73 | + $surnames = $this->module->surnames($tree, '', $initial, false, false, I18N::locale()); |
|
74 | + } else { |
|
75 | + $title = I18N::translate('Patronymic Lineages'); |
|
76 | + $surnames = []; |
|
77 | + } |
|
78 | 78 | |
79 | - return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
80 | - 'title' => $title, |
|
81 | - 'module' => $this->module, |
|
82 | - 'tree' => $tree, |
|
83 | - 'initials_list' => $initials_list, |
|
84 | - 'initial' => $initial, |
|
85 | - 'show_all' => $show_all, |
|
86 | - 'surnames' => $surnames |
|
87 | - ]); |
|
88 | - } |
|
79 | + return $this->viewResponse($this->module->name() . '::surnames-page', [ |
|
80 | + 'title' => $title, |
|
81 | + 'module' => $this->module, |
|
82 | + 'tree' => $tree, |
|
83 | + 'initials_list' => $initials_list, |
|
84 | + 'initial' => $initial, |
|
85 | + 'show_all' => $show_all, |
|
86 | + 'surnames' => $surnames |
|
87 | + ]); |
|
88 | + } |
|
89 | 89 | } |
@@ -36,139 +36,139 @@ |
||
36 | 36 | * Display lineages of people with the same surname. |
37 | 37 | */ |
38 | 38 | class PatronymicLineageModule extends IndividualListModule implements |
39 | - ModuleMyArtJaubInterface, |
|
40 | - ModuleListInterface, |
|
41 | - ModuleGlobalInterface |
|
39 | + ModuleMyArtJaubInterface, |
|
40 | + ModuleListInterface, |
|
41 | + ModuleGlobalInterface |
|
42 | 42 | { |
43 | - use ModuleMyArtJaubTrait; |
|
44 | - use ModuleListTrait; |
|
45 | - use ModuleGlobalTrait; |
|
46 | - |
|
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
50 | - */ |
|
51 | - public function title(): string |
|
52 | - { |
|
53 | - return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages'); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
59 | - */ |
|
60 | - public function description(): string |
|
61 | - { |
|
62 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
63 | - return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.'); |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * {@inheritDoc} |
|
68 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
69 | - */ |
|
70 | - public function loadRoutes(Map $router): void |
|
71 | - { |
|
72 | - $router->attach('', '', static function (Map $router): void { |
|
73 | - |
|
74 | - $router->attach('', '/module-maj/lineages', static function (Map $router): void { |
|
75 | - |
|
76 | - $router->attach('', '/Page', static function (Map $router): void { |
|
77 | - |
|
78 | - $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
|
79 | - $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
|
80 | - }); |
|
81 | - }); |
|
82 | - }); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * {@inheritDoc} |
|
87 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
88 | - */ |
|
89 | - public function customModuleVersion(): string |
|
90 | - { |
|
91 | - return '2.0.11-v.1'; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * {@inheritDoc} |
|
96 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
97 | - * |
|
98 | - * @param array<bool|int|string|array<mixed>|null> $parameters |
|
99 | - */ |
|
100 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
101 | - { |
|
102 | - $surname = $parameters['surname'] ?? ''; |
|
103 | - |
|
104 | - $xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
|
105 | - if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) { |
|
106 | - $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
|
107 | - } |
|
108 | - |
|
109 | - if ($surname !== '') { |
|
110 | - return route(LineagesPage::class, [ |
|
111 | - 'tree' => $tree->name(), |
|
112 | - 'surname' => $surname |
|
113 | - ] + $parameters); |
|
114 | - } |
|
115 | - return route(SurnamesList::class, [ |
|
116 | - 'tree' => $tree->name() |
|
117 | - ] + $parameters); |
|
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * {@inheritDoc} |
|
122 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
123 | - */ |
|
124 | - public function listMenuClass(): string |
|
125 | - { |
|
126 | - return 'menu-maj-patrolineage'; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * {@inheritDoc} |
|
131 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
132 | - */ |
|
133 | - public function headContent(): string |
|
134 | - { |
|
135 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * {@inheritDoc} |
|
140 | - * @see \Fisharebest\Webtrees\Module\IndividualListModule::individuals() |
|
141 | - * |
|
142 | - * Implemented to set the visibility to public. |
|
143 | - * This should probably be in a service, but this hack allows for reuse of mainstream code. |
|
144 | - */ |
|
145 | - public function individuals( |
|
146 | - Tree $tree, |
|
147 | - string $surn, |
|
148 | - string $salpha, |
|
149 | - string $galpha, |
|
150 | - bool $marnm, |
|
151 | - bool $fams, |
|
152 | - LocaleInterface $locale |
|
153 | - ): Collection { |
|
154 | - return parent::individuals($tree, $surn, $salpha, $galpha, $marnm, $fams, $locale); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * {@inheritDoc} |
|
159 | - * @see \Fisharebest\Webtrees\Module\IndividualListModule::surnames() |
|
160 | - * |
|
161 | - * Implemented to set the visibility to public. |
|
162 | - * This should probably be in a service, but this hack allows for reuse of mainstream code. |
|
163 | - */ |
|
164 | - public function surnames( |
|
165 | - Tree $tree, |
|
166 | - string $surn, |
|
167 | - string $salpha, |
|
168 | - bool $marnm, |
|
169 | - bool $fams, |
|
170 | - LocaleInterface $locale |
|
171 | - ): array { |
|
172 | - return parent::surnames($tree, $surn, $salpha, $marnm, $fams, $locale); |
|
173 | - } |
|
43 | + use ModuleMyArtJaubTrait; |
|
44 | + use ModuleListTrait; |
|
45 | + use ModuleGlobalTrait; |
|
46 | + |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
50 | + */ |
|
51 | + public function title(): string |
|
52 | + { |
|
53 | + return /* I18N: Name of the “Patronymic lineage” module */ I18N::translate('Patronymic Lineages'); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
59 | + */ |
|
60 | + public function description(): string |
|
61 | + { |
|
62 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
63 | + return /* I18N: Description of the “Patronymic lineage” module */ I18N::translate('Display lineages of people holding the same surname.'); |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * {@inheritDoc} |
|
68 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
69 | + */ |
|
70 | + public function loadRoutes(Map $router): void |
|
71 | + { |
|
72 | + $router->attach('', '', static function (Map $router): void { |
|
73 | + |
|
74 | + $router->attach('', '/module-maj/lineages', static function (Map $router): void { |
|
75 | + |
|
76 | + $router->attach('', '/Page', static function (Map $router): void { |
|
77 | + |
|
78 | + $router->get(SurnamesList::class, '/{tree}/list{/alpha}', SurnamesList::class); |
|
79 | + $router->get(LineagesPage::class, '/{tree}/lineage/{surname}', LineagesPage::class); |
|
80 | + }); |
|
81 | + }); |
|
82 | + }); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * {@inheritDoc} |
|
87 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
88 | + */ |
|
89 | + public function customModuleVersion(): string |
|
90 | + { |
|
91 | + return '2.0.11-v.1'; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * {@inheritDoc} |
|
96 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
97 | + * |
|
98 | + * @param array<bool|int|string|array<mixed>|null> $parameters |
|
99 | + */ |
|
100 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
101 | + { |
|
102 | + $surname = $parameters['surname'] ?? ''; |
|
103 | + |
|
104 | + $xref = app(ServerRequestInterface::class)->getAttribute('xref', ''); |
|
105 | + if ($xref !== '' && ($individual = Registry::individualFactory()->make($xref, $tree)) !== null) { |
|
106 | + $surname = $individual->getAllNames()[$individual->getPrimaryName()]['surname']; |
|
107 | + } |
|
108 | + |
|
109 | + if ($surname !== '') { |
|
110 | + return route(LineagesPage::class, [ |
|
111 | + 'tree' => $tree->name(), |
|
112 | + 'surname' => $surname |
|
113 | + ] + $parameters); |
|
114 | + } |
|
115 | + return route(SurnamesList::class, [ |
|
116 | + 'tree' => $tree->name() |
|
117 | + ] + $parameters); |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * {@inheritDoc} |
|
122 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
123 | + */ |
|
124 | + public function listMenuClass(): string |
|
125 | + { |
|
126 | + return 'menu-maj-patrolineage'; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * {@inheritDoc} |
|
131 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
132 | + */ |
|
133 | + public function headContent(): string |
|
134 | + { |
|
135 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * {@inheritDoc} |
|
140 | + * @see \Fisharebest\Webtrees\Module\IndividualListModule::individuals() |
|
141 | + * |
|
142 | + * Implemented to set the visibility to public. |
|
143 | + * This should probably be in a service, but this hack allows for reuse of mainstream code. |
|
144 | + */ |
|
145 | + public function individuals( |
|
146 | + Tree $tree, |
|
147 | + string $surn, |
|
148 | + string $salpha, |
|
149 | + string $galpha, |
|
150 | + bool $marnm, |
|
151 | + bool $fams, |
|
152 | + LocaleInterface $locale |
|
153 | + ): Collection { |
|
154 | + return parent::individuals($tree, $surn, $salpha, $galpha, $marnm, $fams, $locale); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * {@inheritDoc} |
|
159 | + * @see \Fisharebest\Webtrees\Module\IndividualListModule::surnames() |
|
160 | + * |
|
161 | + * Implemented to set the visibility to public. |
|
162 | + * This should probably be in a service, but this hack allows for reuse of mainstream code. |
|
163 | + */ |
|
164 | + public function surnames( |
|
165 | + Tree $tree, |
|
166 | + string $surn, |
|
167 | + string $salpha, |
|
168 | + bool $marnm, |
|
169 | + bool $fams, |
|
170 | + LocaleInterface $locale |
|
171 | + ): array { |
|
172 | + return parent::surnames($tree, $surn, $salpha, $marnm, $fams, $locale); |
|
173 | + } |
|
174 | 174 | } |