@@ -32,79 +32,79 @@ |
||
32 | 32 | */ |
33 | 33 | class GeoAnalysisViewListData implements RequestHandlerInterface |
34 | 34 | { |
35 | - private ?GeoDispersionModule $module; |
|
36 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
37 | - private DatatablesService $datatables_service; |
|
35 | + private ?GeoDispersionModule $module; |
|
36 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
37 | + private DatatablesService $datatables_service; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor for GeoAnalysisViewListData Request Handler |
|
41 | - * |
|
42 | - * @param ModuleService $module_service |
|
43 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
44 | - * @param DatatablesService $datatables_service |
|
45 | - */ |
|
46 | - public function __construct( |
|
47 | - ModuleService $module_service, |
|
48 | - GeoAnalysisViewDataService $geoview_data_service, |
|
49 | - DatatablesService $datatables_service |
|
50 | - ) { |
|
51 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
52 | - $this->geoview_data_service = $geoview_data_service; |
|
53 | - $this->datatables_service = $datatables_service; |
|
54 | - } |
|
39 | + /** |
|
40 | + * Constructor for GeoAnalysisViewListData Request Handler |
|
41 | + * |
|
42 | + * @param ModuleService $module_service |
|
43 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
44 | + * @param DatatablesService $datatables_service |
|
45 | + */ |
|
46 | + public function __construct( |
|
47 | + ModuleService $module_service, |
|
48 | + GeoAnalysisViewDataService $geoview_data_service, |
|
49 | + DatatablesService $datatables_service |
|
50 | + ) { |
|
51 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
52 | + $this->geoview_data_service = $geoview_data_service; |
|
53 | + $this->datatables_service = $datatables_service; |
|
54 | + } |
|
55 | 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 | - } |
|
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 | 65 | |
66 | - $tree = $request->getAttribute('tree'); |
|
67 | - assert($tree instanceof Tree); |
|
66 | + $tree = $request->getAttribute('tree'); |
|
67 | + assert($tree instanceof Tree); |
|
68 | 68 | |
69 | - $module = $this->module; |
|
70 | - $module_name = $this->module->name(); |
|
71 | - return response(['data' => $this->geoview_data_service->all($tree, true) |
|
72 | - ->map(fn(AbstractGeoAnalysisView $view) => [ |
|
73 | - 'edit' => view($module_name . '::admin/view-table-options', [ |
|
74 | - 'view_id' => $view->id(), |
|
75 | - 'view_enabled' => $view->isEnabled(), |
|
76 | - 'view_edit_route' => route(GeoAnalysisViewEditPage::class, [ |
|
77 | - 'tree' => $tree->name(), |
|
78 | - 'view_id' => $view->id() |
|
79 | - ]), |
|
80 | - 'view_delete_route' => route(GeoAnalysisViewDeleteAction::class, [ |
|
81 | - 'tree' => $tree->name(), |
|
82 | - 'view_id' => $view->id() |
|
83 | - ]), |
|
84 | - 'view_status_route' => route(GeoAnalysisViewStatusAction::class, [ |
|
85 | - 'tree' => $tree->name(), |
|
86 | - 'view_id' => $view->id(), |
|
87 | - 'enable' => $view->isEnabled() ? 0 : 1 |
|
88 | - ]), |
|
89 | - ]), |
|
90 | - 'enabled' => [ |
|
91 | - 'display' => view($module_name . '::components/yes-no-icons', ['yes' => $view->isEnabled()]), |
|
92 | - 'raw' => $view->isEnabled() ? 0 : 1 |
|
93 | - ], |
|
94 | - 'type' => $view->icon($module), |
|
95 | - 'description' => [ |
|
96 | - 'display' => '<span dir="auto">' . e($view->description()) . '</span>', |
|
97 | - 'raw' => e($view->description()) |
|
98 | - ], |
|
99 | - 'analysis' => [ |
|
100 | - 'display' => '<span dir="auto">' . e($view->analysis()->title()) . '</span>', |
|
101 | - 'raw' => e($view->analysis()->title()) |
|
102 | - ], |
|
103 | - 'place_depth' => [ |
|
104 | - 'display' => I18N::number($view->placesDepth()), |
|
105 | - 'raw' => $view->placesDepth() |
|
106 | - ] |
|
107 | - ]) |
|
108 | - ]); |
|
109 | - } |
|
69 | + $module = $this->module; |
|
70 | + $module_name = $this->module->name(); |
|
71 | + return response(['data' => $this->geoview_data_service->all($tree, true) |
|
72 | + ->map(fn(AbstractGeoAnalysisView $view) => [ |
|
73 | + 'edit' => view($module_name . '::admin/view-table-options', [ |
|
74 | + 'view_id' => $view->id(), |
|
75 | + 'view_enabled' => $view->isEnabled(), |
|
76 | + 'view_edit_route' => route(GeoAnalysisViewEditPage::class, [ |
|
77 | + 'tree' => $tree->name(), |
|
78 | + 'view_id' => $view->id() |
|
79 | + ]), |
|
80 | + 'view_delete_route' => route(GeoAnalysisViewDeleteAction::class, [ |
|
81 | + 'tree' => $tree->name(), |
|
82 | + 'view_id' => $view->id() |
|
83 | + ]), |
|
84 | + 'view_status_route' => route(GeoAnalysisViewStatusAction::class, [ |
|
85 | + 'tree' => $tree->name(), |
|
86 | + 'view_id' => $view->id(), |
|
87 | + 'enable' => $view->isEnabled() ? 0 : 1 |
|
88 | + ]), |
|
89 | + ]), |
|
90 | + 'enabled' => [ |
|
91 | + 'display' => view($module_name . '::components/yes-no-icons', ['yes' => $view->isEnabled()]), |
|
92 | + 'raw' => $view->isEnabled() ? 0 : 1 |
|
93 | + ], |
|
94 | + 'type' => $view->icon($module), |
|
95 | + 'description' => [ |
|
96 | + 'display' => '<span dir="auto">' . e($view->description()) . '</span>', |
|
97 | + 'raw' => e($view->description()) |
|
98 | + ], |
|
99 | + 'analysis' => [ |
|
100 | + 'display' => '<span dir="auto">' . e($view->analysis()->title()) . '</span>', |
|
101 | + 'raw' => e($view->analysis()->title()) |
|
102 | + ], |
|
103 | + 'place_depth' => [ |
|
104 | + 'display' => I18N::number($view->placesDepth()), |
|
105 | + 'raw' => $view->placesDepth() |
|
106 | + ] |
|
107 | + ]) |
|
108 | + ]); |
|
109 | + } |
|
110 | 110 | } |
@@ -29,48 +29,48 @@ |
||
29 | 29 | */ |
30 | 30 | class MapFeaturePropertyData implements RequestHandlerInterface |
31 | 31 | { |
32 | - private MapDefinitionsService $map_definition_service; |
|
32 | + private MapDefinitionsService $map_definition_service; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor for MapFeaturePropertyData Request Handler |
|
36 | - * |
|
37 | - * @param MapDefinitionsService $map_definition_service |
|
38 | - */ |
|
39 | - public function __construct( |
|
40 | - MapDefinitionsService $map_definition_service |
|
41 | - ) { |
|
42 | - $this->map_definition_service = $map_definition_service; |
|
43 | - } |
|
34 | + /** |
|
35 | + * Constructor for MapFeaturePropertyData Request Handler |
|
36 | + * |
|
37 | + * @param MapDefinitionsService $map_definition_service |
|
38 | + */ |
|
39 | + public function __construct( |
|
40 | + MapDefinitionsService $map_definition_service |
|
41 | + ) { |
|
42 | + $this->map_definition_service = $map_definition_service; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
48 | - */ |
|
49 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
50 | - { |
|
51 | - $map_id = $request->getQueryParams()['map_id'] ?? $request->getAttribute('map_id') ?? ''; |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
48 | + */ |
|
49 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
50 | + { |
|
51 | + $map_id = $request->getQueryParams()['map_id'] ?? $request->getAttribute('map_id') ?? ''; |
|
52 | 52 | |
53 | - return response(Registry::cache()->file()->remember( |
|
54 | - 'map-properties-' . $map_id, |
|
55 | - function () use ($map_id): array { |
|
56 | - $map = $this->map_definition_service->find($map_id); |
|
57 | - if ($map === null) { |
|
58 | - throw new HttpNotFoundException(I18N::translate('The map could not be found.')); |
|
59 | - } |
|
53 | + return response(Registry::cache()->file()->remember( |
|
54 | + 'map-properties-' . $map_id, |
|
55 | + function () use ($map_id): array { |
|
56 | + $map = $this->map_definition_service->find($map_id); |
|
57 | + if ($map === null) { |
|
58 | + throw new HttpNotFoundException(I18N::translate('The map could not be found.')); |
|
59 | + } |
|
60 | 60 | |
61 | - $features = []; |
|
62 | - collect($map->features()) |
|
63 | - ->map(fn(Feature $feature): ?stdClass => $feature->getProperties()) |
|
64 | - ->filter() |
|
65 | - ->map(fn(stdClass $properties): array => array_keys(get_object_vars($properties))) |
|
66 | - ->each(function (array $properties) use (&$features): void { |
|
67 | - $features = count($features) === 0 ? $properties : array_intersect($features, $properties); |
|
68 | - }); |
|
61 | + $features = []; |
|
62 | + collect($map->features()) |
|
63 | + ->map(fn(Feature $feature): ?stdClass => $feature->getProperties()) |
|
64 | + ->filter() |
|
65 | + ->map(fn(stdClass $properties): array => array_keys(get_object_vars($properties))) |
|
66 | + ->each(function (array $properties) use (&$features): void { |
|
67 | + $features = count($features) === 0 ? $properties : array_intersect($features, $properties); |
|
68 | + }); |
|
69 | 69 | |
70 | - usort($features, I18N::comparator()); |
|
71 | - return $features; |
|
72 | - }, |
|
73 | - 86400000 |
|
74 | - )); |
|
75 | - } |
|
70 | + usort($features, I18N::comparator()); |
|
71 | + return $features; |
|
72 | + }, |
|
73 | + 86400000 |
|
74 | + )); |
|
75 | + } |
|
76 | 76 | } |
@@ -34,88 +34,88 @@ |
||
34 | 34 | */ |
35 | 35 | class MapAdapterEditAction implements RequestHandlerInterface |
36 | 36 | { |
37 | - private ?GeoDispersionModule $module; |
|
38 | - private MapAdapterDataService $mapadapter_data_service; |
|
39 | - private MapDefinitionsService $map_definition_service; |
|
37 | + private ?GeoDispersionModule $module; |
|
38 | + private MapAdapterDataService $mapadapter_data_service; |
|
39 | + private MapDefinitionsService $map_definition_service; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor for MapAdapterEditAction Request Handler |
|
43 | - * |
|
44 | - * @param ModuleService $module_service |
|
45 | - * @param MapAdapterDataService $mapadapter_data_service |
|
46 | - * @param MapDefinitionsService $map_definition_service |
|
47 | - */ |
|
48 | - public function __construct( |
|
49 | - ModuleService $module_service, |
|
50 | - MapAdapterDataService $mapadapter_data_service, |
|
51 | - MapDefinitionsService $map_definition_service |
|
52 | - ) { |
|
53 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
54 | - $this->mapadapter_data_service = $mapadapter_data_service; |
|
55 | - $this->map_definition_service = $map_definition_service; |
|
56 | - } |
|
41 | + /** |
|
42 | + * Constructor for MapAdapterEditAction Request Handler |
|
43 | + * |
|
44 | + * @param ModuleService $module_service |
|
45 | + * @param MapAdapterDataService $mapadapter_data_service |
|
46 | + * @param MapDefinitionsService $map_definition_service |
|
47 | + */ |
|
48 | + public function __construct( |
|
49 | + ModuleService $module_service, |
|
50 | + MapAdapterDataService $mapadapter_data_service, |
|
51 | + MapDefinitionsService $map_definition_service |
|
52 | + ) { |
|
53 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
54 | + $this->mapadapter_data_service = $mapadapter_data_service; |
|
55 | + $this->map_definition_service = $map_definition_service; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | - */ |
|
62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | - { |
|
64 | - $tree = $request->getAttribute('tree'); |
|
65 | - assert($tree instanceof Tree); |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | + */ |
|
62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | + { |
|
64 | + $tree = $request->getAttribute('tree'); |
|
65 | + assert($tree instanceof Tree); |
|
66 | 66 | |
67 | - if ($this->module === null) { |
|
68 | - FlashMessages::addMessage( |
|
69 | - I18N::translate('The attached module could not be found.'), |
|
70 | - 'danger' |
|
71 | - ); |
|
72 | - return redirect(route(AdminConfigPage::class, ['tree' => $tree])); |
|
73 | - } |
|
67 | + if ($this->module === null) { |
|
68 | + FlashMessages::addMessage( |
|
69 | + I18N::translate('The attached module could not be found.'), |
|
70 | + 'danger' |
|
71 | + ); |
|
72 | + return redirect(route(AdminConfigPage::class, ['tree' => $tree])); |
|
73 | + } |
|
74 | 74 | |
75 | - $adapter_id = (int) $request->getAttribute('adapter_id'); |
|
76 | - $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
|
75 | + $adapter_id = (int) $request->getAttribute('adapter_id'); |
|
76 | + $map_adapter = $this->mapadapter_data_service->find($adapter_id); |
|
77 | 77 | |
78 | - $params = (array) $request->getParsedBody(); |
|
78 | + $params = (array) $request->getParsedBody(); |
|
79 | 79 | |
80 | - $map = $this->map_definition_service->find($params['map_adapter_map'] ?? ''); |
|
81 | - $mapping_property = $params['map_adapter_property_selected'] ?? ''; |
|
80 | + $map = $this->map_definition_service->find($params['map_adapter_map'] ?? ''); |
|
81 | + $mapping_property = $params['map_adapter_property_selected'] ?? ''; |
|
82 | 82 | |
83 | - $mapper = null; |
|
84 | - try { |
|
85 | - $mapper = app($params['map_adapter_mapper'] ?? ''); |
|
86 | - } catch (BindingResolutionException $ex) { |
|
87 | - } |
|
83 | + $mapper = null; |
|
84 | + try { |
|
85 | + $mapper = app($params['map_adapter_mapper'] ?? ''); |
|
86 | + } catch (BindingResolutionException $ex) { |
|
87 | + } |
|
88 | 88 | |
89 | - if ($map_adapter === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
|
90 | - FlashMessages::addMessage( |
|
91 | - I18N::translate('The parameters for the map configuration are not valid.'), |
|
92 | - 'danger' |
|
93 | - ); |
|
94 | - return redirect(route(AdminConfigPage::class, ['tree' => $tree])); |
|
95 | - } |
|
89 | + if ($map_adapter === null || $map === null || $mapper === null || !($mapper instanceof PlaceMapperInterface)) { |
|
90 | + FlashMessages::addMessage( |
|
91 | + I18N::translate('The parameters for the map configuration are not valid.'), |
|
92 | + 'danger' |
|
93 | + ); |
|
94 | + return redirect(route(AdminConfigPage::class, ['tree' => $tree])); |
|
95 | + } |
|
96 | 96 | |
97 | - $mapper->setConfig($mapper->config()->withConfigUpdate($request)); |
|
98 | - $new_map_adapter = $map_adapter->with($map, $mapper, $mapping_property); |
|
99 | - try { |
|
100 | - $this->mapadapter_data_service->update($new_map_adapter); |
|
101 | - FlashMessages::addMessage( |
|
102 | - I18N::translate('The map configuration has been successfully updated.'), |
|
103 | - 'success' |
|
104 | - ); |
|
105 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
106 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.'); |
|
107 | - } catch (Throwable $ex) { |
|
108 | - FlashMessages::addMessage( |
|
109 | - I18N::translate('An error occured while updating the map configuration.'), |
|
110 | - 'danger' |
|
111 | - ); |
|
112 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
113 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating Map Adapter “' . $map_adapter->id() . '”: ' . $ex->getMessage()); |
|
114 | - } |
|
97 | + $mapper->setConfig($mapper->config()->withConfigUpdate($request)); |
|
98 | + $new_map_adapter = $map_adapter->with($map, $mapper, $mapping_property); |
|
99 | + try { |
|
100 | + $this->mapadapter_data_service->update($new_map_adapter); |
|
101 | + FlashMessages::addMessage( |
|
102 | + I18N::translate('The map configuration has been successfully updated.'), |
|
103 | + 'success' |
|
104 | + ); |
|
105 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
106 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been updated.'); |
|
107 | + } catch (Throwable $ex) { |
|
108 | + FlashMessages::addMessage( |
|
109 | + I18N::translate('An error occured while updating the map configuration.'), |
|
110 | + 'danger' |
|
111 | + ); |
|
112 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
113 | + Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating Map Adapter “' . $map_adapter->id() . '”: ' . $ex->getMessage()); |
|
114 | + } |
|
115 | 115 | |
116 | - return redirect(route(GeoAnalysisViewEditPage::class, [ |
|
117 | - 'tree' => $tree->name(), |
|
118 | - 'view_id' => $map_adapter->geoAnalysisViewId() |
|
119 | - ])); |
|
120 | - } |
|
116 | + return redirect(route(GeoAnalysisViewEditPage::class, [ |
|
117 | + 'tree' => $tree->name(), |
|
118 | + 'view_id' => $map_adapter->geoAnalysisViewId() |
|
119 | + ])); |
|
120 | + } |
|
121 | 121 | } |
@@ -21,51 +21,51 @@ |
||
21 | 21 | |
22 | 22 | class GeoAnalysisTable extends AbstractGeoAnalysisView |
23 | 23 | { |
24 | - /** |
|
25 | - * {@inheritDoc} |
|
26 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::type() |
|
27 | - */ |
|
28 | - public function type(): string |
|
29 | - { |
|
30 | - return I18N::translateContext('GEODISPERSION', 'Table'); |
|
31 | - } |
|
24 | + /** |
|
25 | + * {@inheritDoc} |
|
26 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::type() |
|
27 | + */ |
|
28 | + public function type(): string |
|
29 | + { |
|
30 | + return I18N::translateContext('GEODISPERSION', 'Table'); |
|
31 | + } |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
36 | - */ |
|
37 | - public function icon(ModuleInterface $module): string |
|
38 | - { |
|
39 | - return view($module->name() . '::icons/view-table', ['type' => $this->type()]); |
|
40 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
36 | + */ |
|
37 | + public function icon(ModuleInterface $module): string |
|
38 | + { |
|
39 | + return view($module->name() . '::icons/view-table', ['type' => $this->type()]); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritDoc} |
|
44 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent() |
|
45 | - */ |
|
46 | - public function globalSettingsContent(ModuleInterface $module): string |
|
47 | - { |
|
48 | - return ''; |
|
49 | - } |
|
42 | + /** |
|
43 | + * {@inheritDoc} |
|
44 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent() |
|
45 | + */ |
|
46 | + public function globalSettingsContent(ModuleInterface $module): string |
|
47 | + { |
|
48 | + return ''; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * {@inheritDoc} |
|
53 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate() |
|
54 | - * @return $this |
|
55 | - */ |
|
56 | - public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
|
57 | - { |
|
58 | - return $this; |
|
59 | - } |
|
51 | + /** |
|
52 | + * {@inheritDoc} |
|
53 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate() |
|
54 | + * @return $this |
|
55 | + */ |
|
56 | + public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
|
57 | + { |
|
58 | + return $this; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * {@inheritDoc} |
|
63 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
64 | - */ |
|
65 | - public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string |
|
66 | - { |
|
67 | - return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [ |
|
68 | - 'result' => $result |
|
69 | - ]); |
|
70 | - } |
|
61 | + /** |
|
62 | + * {@inheritDoc} |
|
63 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
64 | + */ |
|
65 | + public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string |
|
66 | + { |
|
67 | + return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [ |
|
68 | + 'result' => $result |
|
69 | + ]); |
|
70 | + } |
|
71 | 71 | } |
@@ -29,128 +29,128 @@ |
||
29 | 29 | */ |
30 | 30 | class GeoAnalysisMap extends AbstractGeoAnalysisView |
31 | 31 | { |
32 | - private ?MapColorsConfig $colors_config = null; |
|
33 | - |
|
34 | - public function type(): string |
|
35 | - { |
|
36 | - return I18N::translateContext('GEODISPERSION', 'Map'); |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
42 | - */ |
|
43 | - public function icon(ModuleInterface $module): string |
|
44 | - { |
|
45 | - return view($module->name() . '::icons/view-map', ['type' => $this->type()]); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent() |
|
51 | - */ |
|
52 | - public function globalSettingsContent(ModuleInterface $module): string |
|
53 | - { |
|
54 | - return view($module->name() . '::admin/view-edit-map', [ |
|
55 | - 'module_name' => $module->name(), |
|
56 | - 'view' => $this, |
|
57 | - 'colors' => $this->colors(), |
|
58 | - 'map_adapters' => app(MapAdapterDataService::class)->allForView($this, true) |
|
59 | - ]); |
|
60 | - } |
|
61 | - |
|
62 | - /** |
|
63 | - * {@inheritDoc} |
|
64 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate() |
|
65 | - * @return static |
|
66 | - */ |
|
67 | - public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
|
68 | - { |
|
69 | - $params = (array) $request->getParsedBody(); |
|
70 | - |
|
71 | - $default_color = $params['view_map_color_default'] ?? ''; |
|
72 | - $stroke_color = $params['view_map_color_stroke'] ?? ''; |
|
73 | - $maxvalue_color = $params['view_map_color_maxvalue'] ?? ''; |
|
74 | - $hover_color = $params['view_map_color_hover'] ?? ''; |
|
75 | - |
|
76 | - try { |
|
77 | - return $this->withColors(new MapColorsConfig( |
|
78 | - Hex::fromString($default_color), |
|
79 | - Hex::fromString($stroke_color), |
|
80 | - Hex::fromString($maxvalue_color), |
|
81 | - Hex::fromString($hover_color) |
|
82 | - )); |
|
83 | - } catch (InvalidColorValue $ex) { |
|
84 | - } |
|
85 | - |
|
86 | - return $this; |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * {@inheritDoc} |
|
91 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
92 | - */ |
|
93 | - public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string |
|
94 | - { |
|
95 | - $map_adapters = app(MapAdapterDataService::class)->allForView($this); |
|
96 | - |
|
97 | - $adapter_result = null; |
|
98 | - foreach ($map_adapters as $map_adapter) { |
|
99 | - $adapter_result_tmp = $map_adapter->convert($result); |
|
100 | - $adapter_result = $adapter_result === null ? |
|
101 | - $adapter_result_tmp : |
|
102 | - $adapter_result->merge($adapter_result_tmp); |
|
103 | - } |
|
104 | - |
|
105 | - if ($adapter_result === null) { |
|
106 | - return view($module->name() . '::errors/tab-error', [ |
|
107 | - 'message' => I18N::translate('The map could not be loaded.'), |
|
108 | - ]); |
|
109 | - } |
|
110 | - |
|
111 | - //phpcs:disable Generic.Files.LineLength.TooLong |
|
112 | - $basemap_provider = [ |
|
113 | - 'url' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
|
114 | - 'options' => [ |
|
115 | - 'attribution' => '<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap</a> contributors', |
|
116 | - 'max_zoom' => 19 |
|
117 | - ] |
|
118 | - ]; |
|
119 | - //phpcs:enable |
|
120 | - |
|
121 | - return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [ |
|
122 | - 'result' => $adapter_result->geoAnalysisResult(), |
|
123 | - 'features' => $adapter_result->features(), |
|
124 | - 'colors' => $this->colors(), |
|
125 | - 'basemap_provider' => $basemap_provider |
|
126 | - ]); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Get the color scheme configuration for the map view |
|
131 | - * |
|
132 | - * @return MapColorsConfig |
|
133 | - */ |
|
134 | - public function colors(): MapColorsConfig |
|
135 | - { |
|
136 | - return $this->colors_config ?? new MapColorsConfig( |
|
137 | - new Rgb(245, 245, 245), |
|
138 | - new Rgb(213, 213, 213), |
|
139 | - new Rgb(4, 147, 171), |
|
140 | - new Rgb(255, 102, 0) |
|
141 | - ); |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Returns a map view with a new color scheme configuration |
|
146 | - * |
|
147 | - * @param MapColorsConfig $config |
|
148 | - * @return static |
|
149 | - */ |
|
150 | - public function withColors(?MapColorsConfig $config): self |
|
151 | - { |
|
152 | - $new = clone $this; |
|
153 | - $new->colors_config = $config; |
|
154 | - return $new; |
|
155 | - } |
|
32 | + private ?MapColorsConfig $colors_config = null; |
|
33 | + |
|
34 | + public function type(): string |
|
35 | + { |
|
36 | + return I18N::translateContext('GEODISPERSION', 'Map'); |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
42 | + */ |
|
43 | + public function icon(ModuleInterface $module): string |
|
44 | + { |
|
45 | + return view($module->name() . '::icons/view-map', ['type' => $this->type()]); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent() |
|
51 | + */ |
|
52 | + public function globalSettingsContent(ModuleInterface $module): string |
|
53 | + { |
|
54 | + return view($module->name() . '::admin/view-edit-map', [ |
|
55 | + 'module_name' => $module->name(), |
|
56 | + 'view' => $this, |
|
57 | + 'colors' => $this->colors(), |
|
58 | + 'map_adapters' => app(MapAdapterDataService::class)->allForView($this, true) |
|
59 | + ]); |
|
60 | + } |
|
61 | + |
|
62 | + /** |
|
63 | + * {@inheritDoc} |
|
64 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate() |
|
65 | + * @return static |
|
66 | + */ |
|
67 | + public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
|
68 | + { |
|
69 | + $params = (array) $request->getParsedBody(); |
|
70 | + |
|
71 | + $default_color = $params['view_map_color_default'] ?? ''; |
|
72 | + $stroke_color = $params['view_map_color_stroke'] ?? ''; |
|
73 | + $maxvalue_color = $params['view_map_color_maxvalue'] ?? ''; |
|
74 | + $hover_color = $params['view_map_color_hover'] ?? ''; |
|
75 | + |
|
76 | + try { |
|
77 | + return $this->withColors(new MapColorsConfig( |
|
78 | + Hex::fromString($default_color), |
|
79 | + Hex::fromString($stroke_color), |
|
80 | + Hex::fromString($maxvalue_color), |
|
81 | + Hex::fromString($hover_color) |
|
82 | + )); |
|
83 | + } catch (InvalidColorValue $ex) { |
|
84 | + } |
|
85 | + |
|
86 | + return $this; |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * {@inheritDoc} |
|
91 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
92 | + */ |
|
93 | + public function globalTabContent(ModuleInterface $module, GeoAnalysisResult $result, array $params): string |
|
94 | + { |
|
95 | + $map_adapters = app(MapAdapterDataService::class)->allForView($this); |
|
96 | + |
|
97 | + $adapter_result = null; |
|
98 | + foreach ($map_adapters as $map_adapter) { |
|
99 | + $adapter_result_tmp = $map_adapter->convert($result); |
|
100 | + $adapter_result = $adapter_result === null ? |
|
101 | + $adapter_result_tmp : |
|
102 | + $adapter_result->merge($adapter_result_tmp); |
|
103 | + } |
|
104 | + |
|
105 | + if ($adapter_result === null) { |
|
106 | + return view($module->name() . '::errors/tab-error', [ |
|
107 | + 'message' => I18N::translate('The map could not be loaded.'), |
|
108 | + ]); |
|
109 | + } |
|
110 | + |
|
111 | + //phpcs:disable Generic.Files.LineLength.TooLong |
|
112 | + $basemap_provider = [ |
|
113 | + 'url' => 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', |
|
114 | + 'options' => [ |
|
115 | + 'attribution' => '<a href="https://www.openstreetmap.org/copyright">© OpenStreetMap</a> contributors', |
|
116 | + 'max_zoom' => 19 |
|
117 | + ] |
|
118 | + ]; |
|
119 | + //phpcs:enable |
|
120 | + |
|
121 | + return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [ |
|
122 | + 'result' => $adapter_result->geoAnalysisResult(), |
|
123 | + 'features' => $adapter_result->features(), |
|
124 | + 'colors' => $this->colors(), |
|
125 | + 'basemap_provider' => $basemap_provider |
|
126 | + ]); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Get the color scheme configuration for the map view |
|
131 | + * |
|
132 | + * @return MapColorsConfig |
|
133 | + */ |
|
134 | + public function colors(): MapColorsConfig |
|
135 | + { |
|
136 | + return $this->colors_config ?? new MapColorsConfig( |
|
137 | + new Rgb(245, 245, 245), |
|
138 | + new Rgb(213, 213, 213), |
|
139 | + new Rgb(4, 147, 171), |
|
140 | + new Rgb(255, 102, 0) |
|
141 | + ); |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Returns a map view with a new color scheme configuration |
|
146 | + * |
|
147 | + * @param MapColorsConfig $config |
|
148 | + * @return static |
|
149 | + */ |
|
150 | + public function withColors(?MapColorsConfig $config): self |
|
151 | + { |
|
152 | + $new = clone $this; |
|
153 | + $new->colors_config = $config; |
|
154 | + return $new; |
|
155 | + } |
|
156 | 156 | } |
@@ -24,35 +24,35 @@ |
||
24 | 24 | class Migration1 implements MigrationInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritDoc} |
|
29 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
30 | - */ |
|
31 | - public function upgrade(): void |
|
32 | - { |
|
33 | - DB::schema()->create('maj_geodisp_views', static function (Blueprint $table): void { |
|
34 | - $table->integer('majgv_id')->autoIncrement(); |
|
35 | - $table->integer('majgv_gedcom_id')->index(); |
|
36 | - $table->string('majgv_view_class', 255); |
|
37 | - $table->enum('majgv_status', ['enabled', 'disabled'])->default('enabled'); |
|
38 | - $table->string('majgv_descr', 248); |
|
39 | - $table->string('majgv_analysis', 255); |
|
40 | - $table->tinyInteger('majgv_place_depth')->default(1); |
|
41 | - $table->tinyInteger('majgv_top_places')->default(0); |
|
42 | - $table->json('majgv_colors')->nullable(); |
|
43 | - |
|
44 | - $table->foreign('majgv_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); |
|
45 | - }); |
|
46 | - |
|
47 | - DB::schema()->create('maj_geodisp_mapviews', static function (Blueprint $table): void { |
|
48 | - $table->integer('majgm_id')->autoIncrement(); |
|
49 | - $table->integer('majgm_majgv_id')->index(); |
|
50 | - $table->string('majgm_map_id', 127); |
|
51 | - $table->string('majgm_mapper', 255); |
|
52 | - $table->string('majgm_feature_prop', 31); |
|
53 | - $table->json('majgm_config')->nullable(); |
|
54 | - |
|
55 | - $table->foreign('majgm_majgv_id')->references('majgv_id')->on('maj_geodisp_views')->onDelete('cascade'); |
|
56 | - }); |
|
57 | - } |
|
27 | + /** |
|
28 | + * {@inheritDoc} |
|
29 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
30 | + */ |
|
31 | + public function upgrade(): void |
|
32 | + { |
|
33 | + DB::schema()->create('maj_geodisp_views', static function (Blueprint $table): void { |
|
34 | + $table->integer('majgv_id')->autoIncrement(); |
|
35 | + $table->integer('majgv_gedcom_id')->index(); |
|
36 | + $table->string('majgv_view_class', 255); |
|
37 | + $table->enum('majgv_status', ['enabled', 'disabled'])->default('enabled'); |
|
38 | + $table->string('majgv_descr', 248); |
|
39 | + $table->string('majgv_analysis', 255); |
|
40 | + $table->tinyInteger('majgv_place_depth')->default(1); |
|
41 | + $table->tinyInteger('majgv_top_places')->default(0); |
|
42 | + $table->json('majgv_colors')->nullable(); |
|
43 | + |
|
44 | + $table->foreign('majgv_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); |
|
45 | + }); |
|
46 | + |
|
47 | + DB::schema()->create('maj_geodisp_mapviews', static function (Blueprint $table): void { |
|
48 | + $table->integer('majgm_id')->autoIncrement(); |
|
49 | + $table->integer('majgm_majgv_id')->index(); |
|
50 | + $table->string('majgm_map_id', 127); |
|
51 | + $table->string('majgm_mapper', 255); |
|
52 | + $table->string('majgm_feature_prop', 31); |
|
53 | + $table->json('majgm_config')->nullable(); |
|
54 | + |
|
55 | + $table->foreign('majgm_majgv_id')->references('majgv_id')->on('maj_geodisp_views')->onDelete('cascade'); |
|
56 | + }); |
|
57 | + } |
|
58 | 58 | } |
@@ -22,12 +22,12 @@ |
||
22 | 22 | class Migration0 implements MigrationInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritDoc} |
|
27 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | - */ |
|
29 | - public function upgrade(): void |
|
30 | - { |
|
31 | - // This migration has been superseded by migration 1. |
|
32 | - } |
|
25 | + /** |
|
26 | + * {@inheritDoc} |
|
27 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | + */ |
|
29 | + public function upgrade(): void |
|
30 | + { |
|
31 | + // This migration has been superseded by migration 1. |
|
32 | + } |
|
33 | 33 | } |
@@ -25,46 +25,46 @@ |
||
25 | 25 | */ |
26 | 26 | class MapDefinitionsService |
27 | 27 | { |
28 | - private ModuleService $module_service; |
|
28 | + private ModuleService $module_service; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor for MapDefinitionsService |
|
32 | - * |
|
33 | - * @param ModuleService $module_service |
|
34 | - */ |
|
35 | - public function __construct(ModuleService $module_service) |
|
36 | - { |
|
37 | - $this->module_service = $module_service; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Constructor for MapDefinitionsService |
|
32 | + * |
|
33 | + * @param ModuleService $module_service |
|
34 | + */ |
|
35 | + public function __construct(ModuleService $module_service) |
|
36 | + { |
|
37 | + $this->module_service = $module_service; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * Find a map definition by ID. |
|
42 | - * |
|
43 | - * @param string $id |
|
44 | - * @return MapDefinitionInterface|NULL |
|
45 | - */ |
|
46 | - public function find(string $id): ?MapDefinitionInterface |
|
47 | - { |
|
48 | - return $this->all()->get($id); |
|
49 | - } |
|
40 | + /** |
|
41 | + * Find a map definition by ID. |
|
42 | + * |
|
43 | + * @param string $id |
|
44 | + * @return MapDefinitionInterface|NULL |
|
45 | + */ |
|
46 | + public function find(string $id): ?MapDefinitionInterface |
|
47 | + { |
|
48 | + return $this->all()->get($id); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Get all map definitions available. |
|
53 | - * |
|
54 | - * {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface, |
|
55 | - * and the result is cached} |
|
56 | - * |
|
57 | - * @param bool $include_disabled |
|
58 | - * @return Collection<string, MapDefinitionInterface> |
|
59 | - */ |
|
60 | - public function all(bool $include_disabled = false): Collection |
|
61 | - { |
|
62 | - return Registry::cache()->array()->remember( |
|
63 | - 'maj-geodisp-maps-all', |
|
64 | - fn() => $this->module_service |
|
65 | - ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
66 | - ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
67 | - ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]) |
|
68 | - ); |
|
69 | - } |
|
51 | + /** |
|
52 | + * Get all map definitions available. |
|
53 | + * |
|
54 | + * {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface, |
|
55 | + * and the result is cached} |
|
56 | + * |
|
57 | + * @param bool $include_disabled |
|
58 | + * @return Collection<string, MapDefinitionInterface> |
|
59 | + */ |
|
60 | + public function all(bool $include_disabled = false): Collection |
|
61 | + { |
|
62 | + return Registry::cache()->array()->remember( |
|
63 | + 'maj-geodisp-maps-all', |
|
64 | + fn() => $this->module_service |
|
65 | + ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
66 | + ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
67 | + ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]) |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | } |
@@ -32,186 +32,186 @@ |
||
32 | 32 | */ |
33 | 33 | class GeoAnalysisViewDataService |
34 | 34 | { |
35 | - /** |
|
36 | - * Find a Geographical dispersion analysis view by ID |
|
37 | - * |
|
38 | - * @param Tree $tree |
|
39 | - * @param int $id |
|
40 | - * @return AbstractGeoAnalysisView|NULL |
|
41 | - */ |
|
42 | - public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView |
|
43 | - { |
|
44 | - return $this->all($tree, $include_disabled) |
|
45 | - ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Get all Geographical dispersion analysis views, with or without the disabled ones. |
|
50 | - * |
|
51 | - * {@internal It would ignore any view for which the class could not be loaded by the container} |
|
52 | - * |
|
53 | - * @param Tree $tree |
|
54 | - * @param bool $include_disabled |
|
55 | - * @return Collection<AbstractGeoAnalysisView> |
|
56 | - */ |
|
57 | - public function all(Tree $tree, bool $include_disabled = false): Collection |
|
58 | - { |
|
59 | - return Registry::cache()->array()->remember( |
|
60 | - 'all-geodispersion-views', |
|
61 | - function () use ($tree, $include_disabled): Collection { |
|
62 | - return DB::table('maj_geodisp_views') |
|
63 | - ->select('maj_geodisp_views.*') |
|
64 | - ->where('majgv_gedcom_id', '=', $tree->id()) |
|
65 | - ->get() |
|
66 | - ->map($this->viewMapper($tree)) |
|
67 | - ->filter() |
|
68 | - ->filter($this->enabledFilter($include_disabled)); |
|
69 | - } |
|
70 | - ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Insert a geographical dispersion analysis view object in the database. |
|
75 | - * |
|
76 | - * @param AbstractGeoAnalysisView $view |
|
77 | - * @return int |
|
78 | - */ |
|
79 | - public function insertGetId(AbstractGeoAnalysisView $view): int |
|
80 | - { |
|
81 | - return DB::table('maj_geodisp_views') |
|
82 | - ->insertGetId([ |
|
83 | - 'majgv_gedcom_id' => $view->tree()->id(), |
|
84 | - 'majgv_view_class' => get_class($view), |
|
85 | - 'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled', |
|
86 | - 'majgv_descr' => mb_substr($view->description(), 0, 248), |
|
87 | - 'majgv_analysis' => get_class($view->analysis()), |
|
88 | - 'majgv_place_depth' => $view->placesDepth() |
|
89 | - ]); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Update a geographical dispersion analysis view object in the database. |
|
94 | - * |
|
95 | - * @param AbstractGeoAnalysisView $view |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function update(AbstractGeoAnalysisView $view): int |
|
99 | - { |
|
100 | - return DB::table('maj_geodisp_views') |
|
101 | - ->where('majgv_id', '=', $view->id()) |
|
102 | - ->update([ |
|
103 | - 'majgv_gedcom_id' => $view->tree()->id(), |
|
104 | - 'majgv_view_class' => get_class($view), |
|
105 | - 'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled', |
|
106 | - 'majgv_descr' => mb_substr($view->description(), 0, 248), |
|
107 | - 'majgv_analysis' => get_class($view->analysis()), |
|
108 | - 'majgv_place_depth' => $view->placesDepth(), |
|
109 | - 'majgv_top_places' => $view->numberTopPlaces(), |
|
110 | - 'majgv_colors' => $view instanceof GeoAnalysisMap ? json_encode($view->colors()) : null |
|
111 | - ]); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Update the status of a geographical dispersion analysis view object in the database. |
|
116 | - * |
|
117 | - * @param AbstractGeoAnalysisView $view |
|
118 | - * @param bool $status |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function updateStatus(AbstractGeoAnalysisView $view, bool $status): int |
|
122 | - { |
|
123 | - return DB::table('maj_geodisp_views') |
|
124 | - ->where('majgv_id', '=', $view->id()) |
|
125 | - ->update(['majgv_status' => $status ? 'enabled' : 'disabled']); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Delete a geographical dispersion analysis view object from the database. |
|
130 | - * |
|
131 | - * @param AbstractGeoAnalysisView $view |
|
132 | - * @return int |
|
133 | - */ |
|
134 | - public function delete(AbstractGeoAnalysisView $view): int |
|
135 | - { |
|
136 | - return DB::table('maj_geodisp_views') |
|
137 | - ->where('majgv_id', '=', $view->id()) |
|
138 | - ->delete(); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Get the closure to create a AbstractGeoAnalysisView object from a row in the database. |
|
143 | - * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
144 | - * or if the types do not match with the ones expected. |
|
145 | - * |
|
146 | - * @param Tree $tree |
|
147 | - * @return Closure(\stdClass $row):?AbstractGeoAnalysisView |
|
148 | - */ |
|
149 | - private function viewMapper(Tree $tree): Closure |
|
150 | - { |
|
151 | - return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
152 | - try { |
|
153 | - $geoanalysis = app($row->majgv_analysis); |
|
154 | - if (!($geoanalysis instanceof GeoAnalysisInterface)) { |
|
155 | - return null; |
|
156 | - } |
|
157 | - |
|
158 | - $view = app()->makeWith($row->majgv_view_class, [ |
|
159 | - 'id' => (int) $row->majgv_id, |
|
160 | - 'tree' => $tree, |
|
161 | - 'enabled' => $row->majgv_status === 'enabled', |
|
162 | - 'description' => $row->majgv_descr, |
|
163 | - 'geoanalysis' => $geoanalysis, |
|
164 | - 'depth' => (int) $row->majgv_place_depth, |
|
165 | - 'detailed_top_places' => (int) $row->majgv_top_places |
|
166 | - ]); |
|
167 | - |
|
168 | - if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) { |
|
169 | - $view = $view->withColors($this->colorsDecoder($row->majgv_colors)); |
|
170 | - } |
|
171 | - |
|
172 | - return $view instanceof AbstractGeoAnalysisView ? $view : null; |
|
173 | - } catch (BindingResolutionException $ex) { |
|
174 | - return null; |
|
175 | - } |
|
176 | - }; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Create a MapColorsConfig object from a JSON column value. |
|
181 | - * Returns null if the JSON string is invalid, or if the colors are not valid. |
|
182 | - * |
|
183 | - * @param string $colors_config |
|
184 | - * @return MapColorsConfig|NULL |
|
185 | - */ |
|
186 | - private function colorsDecoder(string $colors_config): ?MapColorsConfig |
|
187 | - { |
|
188 | - $colors = json_decode($colors_config, true); |
|
189 | - if (!is_array($colors) && count($colors) !== 4) { |
|
190 | - return null; |
|
191 | - } |
|
192 | - try { |
|
193 | - return new MapColorsConfig( |
|
194 | - \Spatie\Color\Factory::fromString($colors['default'] ?? ''), |
|
195 | - \Spatie\Color\Factory::fromString($colors['stroke'] ?? ''), |
|
196 | - \Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''), |
|
197 | - \Spatie\Color\Factory::fromString($colors['hover'] ?? '') |
|
198 | - ); |
|
199 | - } catch (InvalidColorValue $ex) { |
|
200 | - return null; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Get a closure to filter views by enabled/disabled status |
|
206 | - * |
|
207 | - * @param bool $include_disabled |
|
208 | - * |
|
209 | - * @return Closure(AbstractGeoAnalysisView $view):bool |
|
210 | - */ |
|
211 | - private function enabledFilter(bool $include_disabled): Closure |
|
212 | - { |
|
213 | - return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
214 | - return $include_disabled || $view->isEnabled(); |
|
215 | - }; |
|
216 | - } |
|
35 | + /** |
|
36 | + * Find a Geographical dispersion analysis view by ID |
|
37 | + * |
|
38 | + * @param Tree $tree |
|
39 | + * @param int $id |
|
40 | + * @return AbstractGeoAnalysisView|NULL |
|
41 | + */ |
|
42 | + public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView |
|
43 | + { |
|
44 | + return $this->all($tree, $include_disabled) |
|
45 | + ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Get all Geographical dispersion analysis views, with or without the disabled ones. |
|
50 | + * |
|
51 | + * {@internal It would ignore any view for which the class could not be loaded by the container} |
|
52 | + * |
|
53 | + * @param Tree $tree |
|
54 | + * @param bool $include_disabled |
|
55 | + * @return Collection<AbstractGeoAnalysisView> |
|
56 | + */ |
|
57 | + public function all(Tree $tree, bool $include_disabled = false): Collection |
|
58 | + { |
|
59 | + return Registry::cache()->array()->remember( |
|
60 | + 'all-geodispersion-views', |
|
61 | + function () use ($tree, $include_disabled): Collection { |
|
62 | + return DB::table('maj_geodisp_views') |
|
63 | + ->select('maj_geodisp_views.*') |
|
64 | + ->where('majgv_gedcom_id', '=', $tree->id()) |
|
65 | + ->get() |
|
66 | + ->map($this->viewMapper($tree)) |
|
67 | + ->filter() |
|
68 | + ->filter($this->enabledFilter($include_disabled)); |
|
69 | + } |
|
70 | + ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Insert a geographical dispersion analysis view object in the database. |
|
75 | + * |
|
76 | + * @param AbstractGeoAnalysisView $view |
|
77 | + * @return int |
|
78 | + */ |
|
79 | + public function insertGetId(AbstractGeoAnalysisView $view): int |
|
80 | + { |
|
81 | + return DB::table('maj_geodisp_views') |
|
82 | + ->insertGetId([ |
|
83 | + 'majgv_gedcom_id' => $view->tree()->id(), |
|
84 | + 'majgv_view_class' => get_class($view), |
|
85 | + 'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled', |
|
86 | + 'majgv_descr' => mb_substr($view->description(), 0, 248), |
|
87 | + 'majgv_analysis' => get_class($view->analysis()), |
|
88 | + 'majgv_place_depth' => $view->placesDepth() |
|
89 | + ]); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Update a geographical dispersion analysis view object in the database. |
|
94 | + * |
|
95 | + * @param AbstractGeoAnalysisView $view |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function update(AbstractGeoAnalysisView $view): int |
|
99 | + { |
|
100 | + return DB::table('maj_geodisp_views') |
|
101 | + ->where('majgv_id', '=', $view->id()) |
|
102 | + ->update([ |
|
103 | + 'majgv_gedcom_id' => $view->tree()->id(), |
|
104 | + 'majgv_view_class' => get_class($view), |
|
105 | + 'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled', |
|
106 | + 'majgv_descr' => mb_substr($view->description(), 0, 248), |
|
107 | + 'majgv_analysis' => get_class($view->analysis()), |
|
108 | + 'majgv_place_depth' => $view->placesDepth(), |
|
109 | + 'majgv_top_places' => $view->numberTopPlaces(), |
|
110 | + 'majgv_colors' => $view instanceof GeoAnalysisMap ? json_encode($view->colors()) : null |
|
111 | + ]); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Update the status of a geographical dispersion analysis view object in the database. |
|
116 | + * |
|
117 | + * @param AbstractGeoAnalysisView $view |
|
118 | + * @param bool $status |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function updateStatus(AbstractGeoAnalysisView $view, bool $status): int |
|
122 | + { |
|
123 | + return DB::table('maj_geodisp_views') |
|
124 | + ->where('majgv_id', '=', $view->id()) |
|
125 | + ->update(['majgv_status' => $status ? 'enabled' : 'disabled']); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Delete a geographical dispersion analysis view object from the database. |
|
130 | + * |
|
131 | + * @param AbstractGeoAnalysisView $view |
|
132 | + * @return int |
|
133 | + */ |
|
134 | + public function delete(AbstractGeoAnalysisView $view): int |
|
135 | + { |
|
136 | + return DB::table('maj_geodisp_views') |
|
137 | + ->where('majgv_id', '=', $view->id()) |
|
138 | + ->delete(); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Get the closure to create a AbstractGeoAnalysisView object from a row in the database. |
|
143 | + * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
144 | + * or if the types do not match with the ones expected. |
|
145 | + * |
|
146 | + * @param Tree $tree |
|
147 | + * @return Closure(\stdClass $row):?AbstractGeoAnalysisView |
|
148 | + */ |
|
149 | + private function viewMapper(Tree $tree): Closure |
|
150 | + { |
|
151 | + return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
152 | + try { |
|
153 | + $geoanalysis = app($row->majgv_analysis); |
|
154 | + if (!($geoanalysis instanceof GeoAnalysisInterface)) { |
|
155 | + return null; |
|
156 | + } |
|
157 | + |
|
158 | + $view = app()->makeWith($row->majgv_view_class, [ |
|
159 | + 'id' => (int) $row->majgv_id, |
|
160 | + 'tree' => $tree, |
|
161 | + 'enabled' => $row->majgv_status === 'enabled', |
|
162 | + 'description' => $row->majgv_descr, |
|
163 | + 'geoanalysis' => $geoanalysis, |
|
164 | + 'depth' => (int) $row->majgv_place_depth, |
|
165 | + 'detailed_top_places' => (int) $row->majgv_top_places |
|
166 | + ]); |
|
167 | + |
|
168 | + if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) { |
|
169 | + $view = $view->withColors($this->colorsDecoder($row->majgv_colors)); |
|
170 | + } |
|
171 | + |
|
172 | + return $view instanceof AbstractGeoAnalysisView ? $view : null; |
|
173 | + } catch (BindingResolutionException $ex) { |
|
174 | + return null; |
|
175 | + } |
|
176 | + }; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Create a MapColorsConfig object from a JSON column value. |
|
181 | + * Returns null if the JSON string is invalid, or if the colors are not valid. |
|
182 | + * |
|
183 | + * @param string $colors_config |
|
184 | + * @return MapColorsConfig|NULL |
|
185 | + */ |
|
186 | + private function colorsDecoder(string $colors_config): ?MapColorsConfig |
|
187 | + { |
|
188 | + $colors = json_decode($colors_config, true); |
|
189 | + if (!is_array($colors) && count($colors) !== 4) { |
|
190 | + return null; |
|
191 | + } |
|
192 | + try { |
|
193 | + return new MapColorsConfig( |
|
194 | + \Spatie\Color\Factory::fromString($colors['default'] ?? ''), |
|
195 | + \Spatie\Color\Factory::fromString($colors['stroke'] ?? ''), |
|
196 | + \Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''), |
|
197 | + \Spatie\Color\Factory::fromString($colors['hover'] ?? '') |
|
198 | + ); |
|
199 | + } catch (InvalidColorValue $ex) { |
|
200 | + return null; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Get a closure to filter views by enabled/disabled status |
|
206 | + * |
|
207 | + * @param bool $include_disabled |
|
208 | + * |
|
209 | + * @return Closure(AbstractGeoAnalysisView $view):bool |
|
210 | + */ |
|
211 | + private function enabledFilter(bool $include_disabled): Closure |
|
212 | + { |
|
213 | + return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
214 | + return $include_disabled || $view->isEnabled(); |
|
215 | + }; |
|
216 | + } |
|
217 | 217 | } |