@@ -30,155 +30,155 @@ |
||
30 | 30 | */ |
31 | 31 | class MapAdapterDataService |
32 | 32 | { |
33 | - private MapDefinitionsService $mapdefinition_service; |
|
33 | + private MapDefinitionsService $mapdefinition_service; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor for MapAdapterDataService |
|
37 | - * |
|
38 | - * @param MapDefinitionsService $mapdefinition_service |
|
39 | - */ |
|
40 | - public function __construct(MapDefinitionsService $mapdefinition_service) |
|
41 | - { |
|
42 | - $this->mapdefinition_service = $mapdefinition_service; |
|
43 | - } |
|
35 | + /** |
|
36 | + * Constructor for MapAdapterDataService |
|
37 | + * |
|
38 | + * @param MapDefinitionsService $mapdefinition_service |
|
39 | + */ |
|
40 | + public function __construct(MapDefinitionsService $mapdefinition_service) |
|
41 | + { |
|
42 | + $this->mapdefinition_service = $mapdefinition_service; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Find a GeoAnalysisMapAdapter by ID |
|
47 | - * |
|
48 | - * @param int $id |
|
49 | - * @return GeoAnalysisMapAdapter|NULL |
|
50 | - */ |
|
51 | - public function find(int $id): ?GeoAnalysisMapAdapter |
|
52 | - { |
|
53 | - return DB::table('maj_geodisp_mapviews') |
|
54 | - ->select('maj_geodisp_mapviews.*') |
|
55 | - ->where('majgm_id', '=', $id) |
|
56 | - ->get() |
|
57 | - ->map($this->mapAdapterMapper()) |
|
58 | - ->first(); |
|
59 | - } |
|
45 | + /** |
|
46 | + * Find a GeoAnalysisMapAdapter by ID |
|
47 | + * |
|
48 | + * @param int $id |
|
49 | + * @return GeoAnalysisMapAdapter|NULL |
|
50 | + */ |
|
51 | + public function find(int $id): ?GeoAnalysisMapAdapter |
|
52 | + { |
|
53 | + return DB::table('maj_geodisp_mapviews') |
|
54 | + ->select('maj_geodisp_mapviews.*') |
|
55 | + ->where('majgm_id', '=', $id) |
|
56 | + ->get() |
|
57 | + ->map($this->mapAdapterMapper()) |
|
58 | + ->first(); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
63 | - * |
|
64 | - * @param GeoAnalysisMap $map_view |
|
65 | - * @return Collection<GeoAnalysisMapAdapter> |
|
66 | - */ |
|
67 | - public function allForView(GeoAnalysisMap $map_view): Collection |
|
68 | - { |
|
69 | - return DB::table('maj_geodisp_mapviews') |
|
70 | - ->select('maj_geodisp_mapviews.*') |
|
71 | - ->where('majgm_majgv_id', '=', $map_view->id()) |
|
72 | - ->get() |
|
73 | - ->map($this->mapAdapterMapper()) |
|
74 | - ->filter(); |
|
75 | - } |
|
61 | + /** |
|
62 | + * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
63 | + * |
|
64 | + * @param GeoAnalysisMap $map_view |
|
65 | + * @return Collection<GeoAnalysisMapAdapter> |
|
66 | + */ |
|
67 | + public function allForView(GeoAnalysisMap $map_view): Collection |
|
68 | + { |
|
69 | + return DB::table('maj_geodisp_mapviews') |
|
70 | + ->select('maj_geodisp_mapviews.*') |
|
71 | + ->where('majgm_majgv_id', '=', $map_view->id()) |
|
72 | + ->get() |
|
73 | + ->map($this->mapAdapterMapper()) |
|
74 | + ->filter(); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Insert a GeoAnalysisMapAdapter in the database. |
|
79 | - * |
|
80 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
81 | - * @return int |
|
82 | - */ |
|
83 | - public function insertGetId(GeoAnalysisMapAdapter $map_adapter): int |
|
84 | - { |
|
85 | - return DB::table('maj_geodisp_mapviews') |
|
86 | - ->insertGetId([ |
|
87 | - 'majgm_majgv_id' => $map_adapter->geoAnalysisViewId(), |
|
88 | - 'majgm_map_id' => $map_adapter->map()->id(), |
|
89 | - 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
90 | - 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
91 | - 'majgm_config' => json_encode($map_adapter->viewConfig()->mapperConfig()) |
|
92 | - ]); |
|
93 | - } |
|
77 | + /** |
|
78 | + * Insert a GeoAnalysisMapAdapter in the database. |
|
79 | + * |
|
80 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
81 | + * @return int |
|
82 | + */ |
|
83 | + public function insertGetId(GeoAnalysisMapAdapter $map_adapter): int |
|
84 | + { |
|
85 | + return DB::table('maj_geodisp_mapviews') |
|
86 | + ->insertGetId([ |
|
87 | + 'majgm_majgv_id' => $map_adapter->geoAnalysisViewId(), |
|
88 | + 'majgm_map_id' => $map_adapter->map()->id(), |
|
89 | + 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
90 | + 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
91 | + 'majgm_config' => json_encode($map_adapter->viewConfig()->mapperConfig()) |
|
92 | + ]); |
|
93 | + } |
|
94 | 94 | |
95 | - /** |
|
96 | - * Update a GeoAnalysisMapAdapter in the database. |
|
97 | - * |
|
98 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
99 | - * @return int |
|
100 | - */ |
|
101 | - public function update(GeoAnalysisMapAdapter $map_adapter): int |
|
102 | - { |
|
103 | - return DB::table('maj_geodisp_mapviews') |
|
104 | - ->where('majgm_id', '=', $map_adapter->id()) |
|
105 | - ->update([ |
|
106 | - 'majgm_map_id' => $map_adapter->map()->id(), |
|
107 | - 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
108 | - 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
109 | - 'majgm_config' => json_encode($map_adapter->placeMapper()->config()) |
|
110 | - ]); |
|
111 | - } |
|
95 | + /** |
|
96 | + * Update a GeoAnalysisMapAdapter in the database. |
|
97 | + * |
|
98 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
99 | + * @return int |
|
100 | + */ |
|
101 | + public function update(GeoAnalysisMapAdapter $map_adapter): int |
|
102 | + { |
|
103 | + return DB::table('maj_geodisp_mapviews') |
|
104 | + ->where('majgm_id', '=', $map_adapter->id()) |
|
105 | + ->update([ |
|
106 | + 'majgm_map_id' => $map_adapter->map()->id(), |
|
107 | + 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
108 | + 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
109 | + 'majgm_config' => json_encode($map_adapter->placeMapper()->config()) |
|
110 | + ]); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Delete a GeoAnalysisMapAdapter from the database. |
|
115 | - * |
|
116 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
117 | - * @return int |
|
118 | - */ |
|
119 | - public function delete(GeoAnalysisMapAdapter $map_adapter): int |
|
120 | - { |
|
121 | - return DB::table('maj_geodisp_mapviews') |
|
122 | - ->where('majgm_id', '=', $map_adapter->id()) |
|
123 | - ->delete(); |
|
124 | - } |
|
113 | + /** |
|
114 | + * Delete a GeoAnalysisMapAdapter from the database. |
|
115 | + * |
|
116 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
117 | + * @return int |
|
118 | + */ |
|
119 | + public function delete(GeoAnalysisMapAdapter $map_adapter): int |
|
120 | + { |
|
121 | + return DB::table('maj_geodisp_mapviews') |
|
122 | + ->where('majgm_id', '=', $map_adapter->id()) |
|
123 | + ->delete(); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
128 | - * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
129 | - * or if the types do not match with the ones expected. |
|
130 | - * |
|
131 | - * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
132 | - */ |
|
133 | - private function mapAdapterMapper(): Closure |
|
134 | - { |
|
135 | - return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
136 | - if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
137 | - return null; |
|
138 | - } |
|
139 | - try { |
|
140 | - $mapper = app($row->majgm_mapper); |
|
141 | - if (!($mapper instanceof PlaceMapperInterface)) { |
|
142 | - return null; |
|
143 | - } |
|
126 | + /** |
|
127 | + * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
128 | + * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
129 | + * or if the types do not match with the ones expected. |
|
130 | + * |
|
131 | + * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
132 | + */ |
|
133 | + private function mapAdapterMapper(): Closure |
|
134 | + { |
|
135 | + return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
136 | + if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
137 | + return null; |
|
138 | + } |
|
139 | + try { |
|
140 | + $mapper = app($row->majgm_mapper); |
|
141 | + if (!($mapper instanceof PlaceMapperInterface)) { |
|
142 | + return null; |
|
143 | + } |
|
144 | 144 | |
145 | - return new GeoAnalysisMapAdapter( |
|
146 | - (int) $row->majgm_id, |
|
147 | - (int) $row->majgm_majgv_id, |
|
148 | - $map, |
|
149 | - app($row->majgm_mapper), |
|
150 | - new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
151 | - ); |
|
152 | - } catch (BindingResolutionException $ex) { |
|
153 | - return null; |
|
154 | - } |
|
155 | - }; |
|
156 | - } |
|
145 | + return new GeoAnalysisMapAdapter( |
|
146 | + (int) $row->majgm_id, |
|
147 | + (int) $row->majgm_majgv_id, |
|
148 | + $map, |
|
149 | + app($row->majgm_mapper), |
|
150 | + new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
151 | + ); |
|
152 | + } catch (BindingResolutionException $ex) { |
|
153 | + return null; |
|
154 | + } |
|
155 | + }; |
|
156 | + } |
|
157 | 157 | |
158 | - /** |
|
159 | - * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
160 | - * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
161 | - * through the Laravel container or if the type do not match with the one expected. |
|
162 | - * |
|
163 | - * @param string $json_config |
|
164 | - * @return PlaceMapperConfigInterface|NULL |
|
165 | - */ |
|
166 | - private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
167 | - { |
|
168 | - $config = $json_config === null ? [] : json_decode($json_config, true); |
|
169 | - $class = $config['class'] ?? null; |
|
170 | - $json_mapper_config = $config['config'] ?? null; |
|
171 | - if ($class === null || $json_mapper_config === null) { |
|
172 | - return null; |
|
173 | - } |
|
174 | - try { |
|
175 | - $mapper_config = app($class); |
|
176 | - if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
177 | - return null; |
|
178 | - } |
|
179 | - return $mapper_config->jsonDeserialize($json_mapper_config); |
|
180 | - } catch (BindingResolutionException $ex) { |
|
181 | - return null; |
|
182 | - } |
|
183 | - } |
|
158 | + /** |
|
159 | + * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
160 | + * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
161 | + * through the Laravel container or if the type do not match with the one expected. |
|
162 | + * |
|
163 | + * @param string $json_config |
|
164 | + * @return PlaceMapperConfigInterface|NULL |
|
165 | + */ |
|
166 | + private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
167 | + { |
|
168 | + $config = $json_config === null ? [] : json_decode($json_config, true); |
|
169 | + $class = $config['class'] ?? null; |
|
170 | + $json_mapper_config = $config['config'] ?? null; |
|
171 | + if ($class === null || $json_mapper_config === null) { |
|
172 | + return null; |
|
173 | + } |
|
174 | + try { |
|
175 | + $mapper_config = app($class); |
|
176 | + if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
177 | + return null; |
|
178 | + } |
|
179 | + return $mapper_config->jsonDeserialize($json_mapper_config); |
|
180 | + } catch (BindingResolutionException $ex) { |
|
181 | + return null; |
|
182 | + } |
|
183 | + } |
|
184 | 184 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | private function mapAdapterMapper(): Closure |
134 | 134 | { |
135 | - return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
135 | + return function(stdClass $row): ?GeoAnalysisMapAdapter { |
|
136 | 136 | if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
137 | 137 | return null; |
138 | 138 | } |
@@ -143,8 +143,8 @@ discard block |
||
143 | 143 | } |
144 | 144 | |
145 | 145 | return new GeoAnalysisMapAdapter( |
146 | - (int) $row->majgm_id, |
|
147 | - (int) $row->majgm_majgv_id, |
|
146 | + (int)$row->majgm_id, |
|
147 | + (int)$row->majgm_majgv_id, |
|
148 | 148 | $map, |
149 | 149 | app($row->majgm_mapper), |
150 | 150 | new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
@@ -25,38 +25,38 @@ |
||
25 | 25 | */ |
26 | 26 | class GeoAnalysisService |
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 | - * Get all available geographical dispersion analyses. |
|
42 | - * |
|
43 | - * {@internal The list is generated based on the modules exposing ModuleGeoAnalysisProviderInterface |
|
44 | - * |
|
45 | - * @param bool $include_disabled |
|
46 | - * @return Collection |
|
47 | - */ |
|
48 | - public function all(bool $include_disabled = false): Collection |
|
49 | - { |
|
50 | - return $this->module_service |
|
51 | - ->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
|
52 | - ->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
|
53 | - ->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
|
54 | - try { |
|
55 | - $analysis = app($analysis_class); |
|
56 | - return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
|
57 | - } catch (BindingResolutionException $ex) { |
|
58 | - return null; |
|
59 | - } |
|
60 | - })->filter(); |
|
61 | - } |
|
40 | + /** |
|
41 | + * Get all available geographical dispersion analyses. |
|
42 | + * |
|
43 | + * {@internal The list is generated based on the modules exposing ModuleGeoAnalysisProviderInterface |
|
44 | + * |
|
45 | + * @param bool $include_disabled |
|
46 | + * @return Collection |
|
47 | + */ |
|
48 | + public function all(bool $include_disabled = false): Collection |
|
49 | + { |
|
50 | + return $this->module_service |
|
51 | + ->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
|
52 | + ->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
|
53 | + ->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
|
54 | + try { |
|
55 | + $analysis = app($analysis_class); |
|
56 | + return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
|
57 | + } catch (BindingResolutionException $ex) { |
|
58 | + return null; |
|
59 | + } |
|
60 | + })->filter(); |
|
61 | + } |
|
62 | 62 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | return $this->module_service |
51 | 51 | ->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
52 | 52 | ->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
53 | - ->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
|
53 | + ->map(static function(string $analysis_class): ?GeoAnalysisInterface { |
|
54 | 54 | try { |
55 | 55 | $analysis = app($analysis_class); |
56 | 56 | return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
@@ -25,39 +25,39 @@ |
||
25 | 25 | */ |
26 | 26 | class PlaceMapperService |
27 | 27 | { |
28 | - private ModuleService $module_service; |
|
28 | + private ModuleService $module_service; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor for PlaceMapperService |
|
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 PlaceMapperService |
|
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 | - * Get all place mappers available. |
|
42 | - * |
|
43 | - * {@internal The list is generated based on the modules exposing ModulePlaceMapperProviderInterface} |
|
44 | - * |
|
45 | - * @param bool $include_disabled |
|
46 | - * @return Collection |
|
47 | - */ |
|
48 | - public function all(bool $include_disabled = false): Collection |
|
49 | - { |
|
50 | - return $this->module_service |
|
51 | - ->findByInterface(ModulePlaceMapperProviderInterface::class, $include_disabled) |
|
52 | - ->flatMap(fn(ModulePlaceMapperProviderInterface $module) => $module->listPlaceMappers()) |
|
53 | - ->map(static function (string $mapper_class): ?PlaceMapperInterface { |
|
54 | - try { |
|
55 | - $mapper = app($mapper_class); |
|
56 | - return $mapper instanceof PlaceMapperInterface ? $mapper : null; |
|
57 | - } catch (BindingResolutionException $ex) { |
|
58 | - return null; |
|
59 | - } |
|
60 | - })->filter(); |
|
61 | - ; |
|
62 | - } |
|
40 | + /** |
|
41 | + * Get all place mappers available. |
|
42 | + * |
|
43 | + * {@internal The list is generated based on the modules exposing ModulePlaceMapperProviderInterface} |
|
44 | + * |
|
45 | + * @param bool $include_disabled |
|
46 | + * @return Collection |
|
47 | + */ |
|
48 | + public function all(bool $include_disabled = false): Collection |
|
49 | + { |
|
50 | + return $this->module_service |
|
51 | + ->findByInterface(ModulePlaceMapperProviderInterface::class, $include_disabled) |
|
52 | + ->flatMap(fn(ModulePlaceMapperProviderInterface $module) => $module->listPlaceMappers()) |
|
53 | + ->map(static function (string $mapper_class): ?PlaceMapperInterface { |
|
54 | + try { |
|
55 | + $mapper = app($mapper_class); |
|
56 | + return $mapper instanceof PlaceMapperInterface ? $mapper : null; |
|
57 | + } catch (BindingResolutionException $ex) { |
|
58 | + return null; |
|
59 | + } |
|
60 | + })->filter(); |
|
61 | + ; |
|
62 | + } |
|
63 | 63 | } |
@@ -50,7 +50,7 @@ |
||
50 | 50 | return $this->module_service |
51 | 51 | ->findByInterface(ModulePlaceMapperProviderInterface::class, $include_disabled) |
52 | 52 | ->flatMap(fn(ModulePlaceMapperProviderInterface $module) => $module->listPlaceMappers()) |
53 | - ->map(static function (string $mapper_class): ?PlaceMapperInterface { |
|
53 | + ->map(static function(string $mapper_class): ?PlaceMapperInterface { |
|
54 | 54 | try { |
55 | 55 | $mapper = app($mapper_class); |
56 | 56 | return $mapper instanceof PlaceMapperInterface ? $mapper : null; |
@@ -26,55 +26,55 @@ |
||
26 | 26 | */ |
27 | 27 | class AllEventsByTypeGeoAnalysis implements GeoAnalysisInterface |
28 | 28 | { |
29 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
29 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor for AllEventsByTypeGeoAnalysis |
|
33 | - * |
|
34 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
35 | - */ |
|
36 | - public function __construct(GeoAnalysisDataService $geoanalysis_data_service) |
|
37 | - { |
|
38 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
39 | - } |
|
31 | + /** |
|
32 | + * Constructor for AllEventsByTypeGeoAnalysis |
|
33 | + * |
|
34 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
35 | + */ |
|
36 | + public function __construct(GeoAnalysisDataService $geoanalysis_data_service) |
|
37 | + { |
|
38 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritDoc} |
|
43 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
44 | - */ |
|
45 | - public function title(): string |
|
46 | - { |
|
47 | - return I18N::translate('All events places by event type'); |
|
48 | - } |
|
41 | + /** |
|
42 | + * {@inheritDoc} |
|
43 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
44 | + */ |
|
45 | + public function title(): string |
|
46 | + { |
|
47 | + return I18N::translate('All events places by event type'); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
53 | - */ |
|
54 | - public function itemsDescription(): callable |
|
55 | - { |
|
56 | - return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
57 | - } |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
53 | + */ |
|
54 | + public function itemsDescription(): callable |
|
55 | + { |
|
56 | + return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
62 | - */ |
|
63 | - public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
64 | - { |
|
65 | - $results = new GeoAnalysisResults(); |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
62 | + */ |
|
63 | + public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
64 | + { |
|
65 | + $results = new GeoAnalysisResults(); |
|
66 | 66 | |
67 | - foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
68 | - foreach ($record->facts([]) as $fact) { |
|
69 | - $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
70 | - if ($place->isUnknown()) { |
|
71 | - continue; |
|
72 | - } |
|
73 | - $results->addPlace($place); |
|
74 | - $results->addPlaceInCategory($fact->label(), 0, $place); |
|
75 | - } |
|
76 | - } |
|
67 | + foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
68 | + foreach ($record->facts([]) as $fact) { |
|
69 | + $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
70 | + if ($place->isUnknown()) { |
|
71 | + continue; |
|
72 | + } |
|
73 | + $results->addPlace($place); |
|
74 | + $results->addPlaceInCategory($fact->label(), 0, $place); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - return $results; |
|
79 | - } |
|
78 | + return $results; |
|
79 | + } |
|
80 | 80 | } |
@@ -28,66 +28,66 @@ |
||
28 | 28 | */ |
29 | 29 | class AllEventsByCenturyGeoAnalysis implements GeoAnalysisInterface |
30 | 30 | { |
31 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
32 | - private CenturyService $century_service; |
|
31 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
32 | + private CenturyService $century_service; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor for AllEventsByCenturyGeoAnalysis |
|
36 | - * |
|
37 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
38 | - * @param CenturyService $century_service |
|
39 | - */ |
|
40 | - public function __construct(GeoAnalysisDataService $geoanalysis_data_service, CenturyService $century_service) |
|
41 | - { |
|
42 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
43 | - $this->century_service = $century_service; |
|
44 | - } |
|
34 | + /** |
|
35 | + * Constructor for AllEventsByCenturyGeoAnalysis |
|
36 | + * |
|
37 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
38 | + * @param CenturyService $century_service |
|
39 | + */ |
|
40 | + public function __construct(GeoAnalysisDataService $geoanalysis_data_service, CenturyService $century_service) |
|
41 | + { |
|
42 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
43 | + $this->century_service = $century_service; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
49 | - */ |
|
50 | - public function title(): string |
|
51 | - { |
|
52 | - return I18N::translate('All events places by century'); |
|
53 | - } |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
49 | + */ |
|
50 | + public function title(): string |
|
51 | + { |
|
52 | + return I18N::translate('All events places by century'); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
58 | - */ |
|
59 | - public function itemsDescription(): callable |
|
60 | - { |
|
61 | - return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
62 | - } |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
58 | + */ |
|
59 | + public function itemsDescription(): callable |
|
60 | + { |
|
61 | + return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
67 | - */ |
|
68 | - public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
69 | - { |
|
70 | - $results = new GeoAnalysisResults(); |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
67 | + */ |
|
68 | + public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
69 | + { |
|
70 | + $results = new GeoAnalysisResults(); |
|
71 | 71 | |
72 | - foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
73 | - foreach ($record->facts([]) as $fact) { |
|
74 | - $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
75 | - if ($place->isUnknown()) { |
|
76 | - continue; |
|
77 | - } |
|
78 | - $results->addPlace($place); |
|
79 | - $date = $fact->date(); |
|
80 | - if ($date->isOK()) { |
|
81 | - $century = intdiv($date->gregorianYear(), 100); |
|
82 | - $results->addPlaceInCategory( |
|
83 | - I18N::translate('%s century', $this->century_service->centuryName($century)), |
|
84 | - $century, |
|
85 | - $place |
|
86 | - ); |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
72 | + foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
73 | + foreach ($record->facts([]) as $fact) { |
|
74 | + $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
75 | + if ($place->isUnknown()) { |
|
76 | + continue; |
|
77 | + } |
|
78 | + $results->addPlace($place); |
|
79 | + $date = $fact->date(); |
|
80 | + if ($date->isOK()) { |
|
81 | + $century = intdiv($date->gregorianYear(), 100); |
|
82 | + $results->addPlaceInCategory( |
|
83 | + I18N::translate('%s century', $this->century_service->centuryName($century)), |
|
84 | + $century, |
|
85 | + $place |
|
86 | + ); |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - return $results; |
|
92 | - } |
|
91 | + return $results; |
|
92 | + } |
|
93 | 93 | } |
@@ -24,23 +24,23 @@ |
||
24 | 24 | */ |
25 | 25 | class SimplePlaceMapper implements PlaceMapperInterface |
26 | 26 | { |
27 | - use PlaceMapperTrait; |
|
27 | + use PlaceMapperTrait; |
|
28 | 28 | |
29 | - /** |
|
30 | - * {@inheritDoc} |
|
31 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
32 | - */ |
|
33 | - public function title(): string |
|
34 | - { |
|
35 | - return I18N::translate('Mapping on place name'); |
|
36 | - } |
|
29 | + /** |
|
30 | + * {@inheritDoc} |
|
31 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
32 | + */ |
|
33 | + public function title(): string |
|
34 | + { |
|
35 | + return I18N::translate('Mapping on place name'); |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * {@inheritDoc} |
|
40 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
41 | - */ |
|
42 | - public function map(Place $place, string $feature_property): ?string |
|
43 | - { |
|
44 | - return $place->firstParts(1)->first(); |
|
45 | - } |
|
38 | + /** |
|
39 | + * {@inheritDoc} |
|
40 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
41 | + */ |
|
42 | + public function map(Place $place, string $feature_property): ?string |
|
43 | + { |
|
44 | + return $place->firstParts(1)->first(); |
|
45 | + } |
|
46 | 46 | } |
@@ -28,110 +28,110 @@ |
||
28 | 28 | */ |
29 | 29 | class FilteredTopPlaceMapperConfig extends GenericPlaceMapperConfig |
30 | 30 | { |
31 | - private TreeService $tree_service; |
|
31 | + private TreeService $tree_service; |
|
32 | 32 | |
33 | - /** |
|
34 | - * FilteredTopPlaceMapperConfig |
|
35 | - * |
|
36 | - * @param TreeService $tree_service |
|
37 | - */ |
|
38 | - public function __construct(TreeService $tree_service) |
|
39 | - { |
|
40 | - $this->tree_service = $tree_service; |
|
41 | - } |
|
33 | + /** |
|
34 | + * FilteredTopPlaceMapperConfig |
|
35 | + * |
|
36 | + * @param TreeService $tree_service |
|
37 | + */ |
|
38 | + public function __construct(TreeService $tree_service) |
|
39 | + { |
|
40 | + $this->tree_service = $tree_service; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Get the configured Top Places to filter on |
|
45 | - * |
|
46 | - * @return Collection<Place> |
|
47 | - */ |
|
48 | - public function topPlaces(): Collection |
|
49 | - { |
|
50 | - return collect($this->get('topPlaces', [])) |
|
51 | - ->filter( |
|
52 | - /** @psalm-suppress MissingClosureParamType */ |
|
53 | - fn($item): bool => $item instanceof Place |
|
54 | - ); |
|
55 | - } |
|
43 | + /** |
|
44 | + * Get the configured Top Places to filter on |
|
45 | + * |
|
46 | + * @return Collection<Place> |
|
47 | + */ |
|
48 | + public function topPlaces(): Collection |
|
49 | + { |
|
50 | + return collect($this->get('topPlaces', [])) |
|
51 | + ->filter( |
|
52 | + /** @psalm-suppress MissingClosureParamType */ |
|
53 | + fn($item): bool => $item instanceof Place |
|
54 | + ); |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonSerializeConfig() |
|
60 | - */ |
|
61 | - public function jsonSerializeConfig() |
|
62 | - { |
|
63 | - return [ |
|
64 | - 'topPlaces' => $this->topPlaces() |
|
65 | - ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
66 | - ->toArray() |
|
67 | - ]; |
|
68 | - } |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonSerializeConfig() |
|
60 | + */ |
|
61 | + public function jsonSerializeConfig() |
|
62 | + { |
|
63 | + return [ |
|
64 | + 'topPlaces' => $this->topPlaces() |
|
65 | + ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
66 | + ->toArray() |
|
67 | + ]; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * {@inheritDoc} |
|
72 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonDeserialize() |
|
73 | - */ |
|
74 | - public function jsonDeserialize($config): self |
|
75 | - { |
|
76 | - if (is_string($config)) { |
|
77 | - return $this->jsonDeserialize(json_decode($config)); |
|
78 | - } |
|
79 | - if (is_array($config)) { |
|
80 | - $this->setConfig([ |
|
81 | - 'topPlaces' => collect($config['topPlaces'] ?? []) |
|
82 | - ->filter( |
|
83 | - /** @psalm-suppress MissingClosureParamType */ |
|
84 | - fn($item): bool => is_array($item) && count($item) == 2 |
|
85 | - )->map(function (array $item): ?Place { |
|
86 | - try { |
|
87 | - return new Place($item[1], $this->tree_service->find($item[0])); |
|
88 | - } catch (RuntimeException $ex) { |
|
89 | - return null; |
|
90 | - } |
|
91 | - }) |
|
92 | - ->filter() |
|
93 | - ->toArray() |
|
94 | - ]); |
|
95 | - } |
|
96 | - return $this; |
|
97 | - } |
|
70 | + /** |
|
71 | + * {@inheritDoc} |
|
72 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonDeserialize() |
|
73 | + */ |
|
74 | + public function jsonDeserialize($config): self |
|
75 | + { |
|
76 | + if (is_string($config)) { |
|
77 | + return $this->jsonDeserialize(json_decode($config)); |
|
78 | + } |
|
79 | + if (is_array($config)) { |
|
80 | + $this->setConfig([ |
|
81 | + 'topPlaces' => collect($config['topPlaces'] ?? []) |
|
82 | + ->filter( |
|
83 | + /** @psalm-suppress MissingClosureParamType */ |
|
84 | + fn($item): bool => is_array($item) && count($item) == 2 |
|
85 | + )->map(function (array $item): ?Place { |
|
86 | + try { |
|
87 | + return new Place($item[1], $this->tree_service->find($item[0])); |
|
88 | + } catch (RuntimeException $ex) { |
|
89 | + return null; |
|
90 | + } |
|
91 | + }) |
|
92 | + ->filter() |
|
93 | + ->toArray() |
|
94 | + ]); |
|
95 | + } |
|
96 | + return $this; |
|
97 | + } |
|
98 | 98 | |
99 | - /** |
|
100 | - * {@inheritDoc} |
|
101 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::configContent() |
|
102 | - */ |
|
103 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
104 | - { |
|
105 | - return view($module->name() . '::mappers/filtered-top-config', [ |
|
106 | - 'tree' => $tree, |
|
107 | - 'top_places' => $this->topPlaces() |
|
108 | - ]); |
|
109 | - } |
|
99 | + /** |
|
100 | + * {@inheritDoc} |
|
101 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::configContent() |
|
102 | + */ |
|
103 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
104 | + { |
|
105 | + return view($module->name() . '::mappers/filtered-top-config', [ |
|
106 | + 'tree' => $tree, |
|
107 | + 'top_places' => $this->topPlaces() |
|
108 | + ]); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * {@inheritDoc} |
|
113 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::withConfigUpdate() |
|
114 | - */ |
|
115 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
116 | - { |
|
117 | - $tree = $request->getAttribute('tree'); |
|
118 | - if (!($tree instanceof Tree)) { |
|
119 | - return $this; |
|
120 | - } |
|
111 | + /** |
|
112 | + * {@inheritDoc} |
|
113 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::withConfigUpdate() |
|
114 | + */ |
|
115 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
116 | + { |
|
117 | + $tree = $request->getAttribute('tree'); |
|
118 | + if (!($tree instanceof Tree)) { |
|
119 | + return $this; |
|
120 | + } |
|
121 | 121 | |
122 | - $params = (array) $request->getParsedBody(); |
|
122 | + $params = (array) $request->getParsedBody(); |
|
123 | 123 | |
124 | - $top_places = $params['mapper_filt_top_places'] ?? []; |
|
125 | - if (is_array($top_places)) { |
|
126 | - $config = ['topPlaces' => []]; |
|
127 | - foreach ($top_places as $top_place_id) { |
|
128 | - $place = Place::find((int) $top_place_id, $tree); |
|
129 | - if (mb_strlen($place->gedcomName()) > 0) { |
|
130 | - $config['topPlaces'][] = $place; |
|
131 | - } |
|
132 | - } |
|
133 | - $this->setConfig($config); |
|
134 | - } |
|
135 | - return $this; |
|
136 | - } |
|
124 | + $top_places = $params['mapper_filt_top_places'] ?? []; |
|
125 | + if (is_array($top_places)) { |
|
126 | + $config = ['topPlaces' => []]; |
|
127 | + foreach ($top_places as $top_place_id) { |
|
128 | + $place = Place::find((int) $top_place_id, $tree); |
|
129 | + if (mb_strlen($place->gedcomName()) > 0) { |
|
130 | + $config['topPlaces'][] = $place; |
|
131 | + } |
|
132 | + } |
|
133 | + $this->setConfig($config); |
|
134 | + } |
|
135 | + return $this; |
|
136 | + } |
|
137 | 137 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | return [ |
64 | 64 | 'topPlaces' => $this->topPlaces() |
65 | - ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
65 | + ->map(fn(Place $place): array => [$place->tree()->id(), $place->gedcomName()]) |
|
66 | 66 | ->toArray() |
67 | 67 | ]; |
68 | 68 | } |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ->filter( |
83 | 83 | /** @psalm-suppress MissingClosureParamType */ |
84 | 84 | fn($item): bool => is_array($item) && count($item) == 2 |
85 | - )->map(function (array $item): ?Place { |
|
85 | + )->map(function(array $item): ?Place { |
|
86 | 86 | try { |
87 | 87 | return new Place($item[1], $this->tree_service->find($item[0])); |
88 | 88 | } catch (RuntimeException $ex) { |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function configContent(ModuleInterface $module, Tree $tree): string |
104 | 104 | { |
105 | - return view($module->name() . '::mappers/filtered-top-config', [ |
|
105 | + return view($module->name().'::mappers/filtered-top-config', [ |
|
106 | 106 | 'tree' => $tree, |
107 | 107 | 'top_places' => $this->topPlaces() |
108 | 108 | ]); |
@@ -119,13 +119,13 @@ discard block |
||
119 | 119 | return $this; |
120 | 120 | } |
121 | 121 | |
122 | - $params = (array) $request->getParsedBody(); |
|
122 | + $params = (array)$request->getParsedBody(); |
|
123 | 123 | |
124 | 124 | $top_places = $params['mapper_filt_top_places'] ?? []; |
125 | 125 | if (is_array($top_places)) { |
126 | 126 | $config = ['topPlaces' => []]; |
127 | 127 | foreach ($top_places as $top_place_id) { |
128 | - $place = Place::find((int) $top_place_id, $tree); |
|
128 | + $place = Place::find((int)$top_place_id, $tree); |
|
129 | 129 | if (mb_strlen($place->gedcomName()) > 0) { |
130 | 130 | $config['topPlaces'][] = $place; |
131 | 131 | } |
@@ -28,51 +28,51 @@ |
||
28 | 28 | */ |
29 | 29 | class SimpleTopFilteredPlaceMapper extends SimplePlaceMapper implements PlaceMapperInterface |
30 | 30 | { |
31 | - use TopFilteredPlaceMapperTrait; |
|
31 | + use TopFilteredPlaceMapperTrait; |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title() |
|
36 | - */ |
|
37 | - public function title(): string |
|
38 | - { |
|
39 | - return I18N::translate('Mapping on place name with filter'); |
|
40 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title() |
|
36 | + */ |
|
37 | + public function title(): string |
|
38 | + { |
|
39 | + return I18N::translate('Mapping on place name with filter'); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritDoc} |
|
44 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
45 | - */ |
|
46 | - public function boot(): void |
|
47 | - { |
|
48 | - parent::boot(); |
|
49 | - $top_places = $this->config()->get('topPlaces'); |
|
50 | - if (is_array($top_places)) { |
|
51 | - $this->setTopPlaces($top_places); |
|
52 | - } |
|
53 | - } |
|
42 | + /** |
|
43 | + * {@inheritDoc} |
|
44 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
45 | + */ |
|
46 | + public function boot(): void |
|
47 | + { |
|
48 | + parent::boot(); |
|
49 | + $top_places = $this->config()->get('topPlaces'); |
|
50 | + if (is_array($top_places)) { |
|
51 | + $this->setTopPlaces($top_places); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
58 | - */ |
|
59 | - public function config(): PlaceMapperConfigInterface |
|
60 | - { |
|
61 | - if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) { |
|
62 | - $this->setConfig(app(FilteredTopPlaceMapperConfig::class)); |
|
63 | - } |
|
64 | - return parent::config(); |
|
65 | - } |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
58 | + */ |
|
59 | + public function config(): PlaceMapperConfigInterface |
|
60 | + { |
|
61 | + if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) { |
|
62 | + $this->setConfig(app(FilteredTopPlaceMapperConfig::class)); |
|
63 | + } |
|
64 | + return parent::config(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inheritDoc} |
|
69 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map() |
|
70 | - */ |
|
71 | - public function map(Place $place, string $feature_property): ?string |
|
72 | - { |
|
73 | - if (!$this->belongsToTopLevels($place)) { |
|
74 | - return null; |
|
75 | - } |
|
76 | - return parent::map($place, $feature_property); |
|
77 | - } |
|
67 | + /** |
|
68 | + * {@inheritDoc} |
|
69 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map() |
|
70 | + */ |
|
71 | + public function map(Place $place, string $feature_property): ?string |
|
72 | + { |
|
73 | + if (!$this->belongsToTopLevels($place)) { |
|
74 | + return null; |
|
75 | + } |
|
76 | + return parent::map($place, $feature_property); |
|
77 | + } |
|
78 | 78 | } |
@@ -36,183 +36,183 @@ |
||
36 | 36 | */ |
37 | 37 | class CoordinatesPlaceMapper implements PlaceMapperInterface |
38 | 38 | { |
39 | - use PlaceMapperTrait; |
|
40 | - |
|
41 | - private ?string $cache_key = null; |
|
42 | - |
|
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
46 | - */ |
|
47 | - public function title(): string |
|
48 | - { |
|
49 | - return I18N::translate('Mapping on place coordinates'); |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * |
|
55 | - * {@internal The Place is associated to a Point only. |
|
56 | - * PlaceLocation can calculate a BoundingBox. |
|
57 | - * Using a BoundingBox could make the mapping more complex and potentially arbitary. |
|
58 | - * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents. |
|
59 | - * This could create the unwanted side effect of a very large area to consider} |
|
60 | - * |
|
61 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
62 | - */ |
|
63 | - public function map(Place $place, string $feature_property): ?string |
|
64 | - { |
|
65 | - $location = new PlaceLocation($place->gedcomName()); |
|
66 | - $longitude = $location->longitude(); |
|
67 | - $latitude = $location->latitude(); |
|
68 | - if ($longitude === null || $latitude === null) { |
|
69 | - return null; |
|
70 | - } |
|
71 | - |
|
72 | - $features_index = $this->featuresIndex(); |
|
73 | - if ($features_index === null) { |
|
74 | - return null; |
|
75 | - } |
|
76 | - |
|
77 | - $place_point = Point::xy($longitude, $latitude, $features_index['SRID']); |
|
78 | - $grid_box = $this->getGridCell( |
|
79 | - $place_point, |
|
80 | - $features_index['map_NE'], |
|
81 | - $features_index['map_SW'], |
|
82 | - $features_index['nb_columns'] |
|
83 | - ); |
|
84 | - if ($grid_box === null || !$this->setGeometryEngine()) { |
|
85 | - return null; |
|
86 | - } |
|
87 | - $features = $features_index['grid'][$grid_box[0]][$grid_box[1]]; |
|
88 | - foreach ($features as $feature) { |
|
89 | - $geometry = $feature->getGeometry(); |
|
90 | - if ($place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) { |
|
91 | - return $feature->getProperty($feature_property); |
|
92 | - } |
|
93 | - } |
|
94 | - return null; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Return the XY coordinates in a bounded grid of the cell containing a specific point. |
|
99 | - * |
|
100 | - * @param Point $point Point to find |
|
101 | - * @param Point $grid_NE North-East point of the bounded grid |
|
102 | - * @param Point $grid_SW South-West point fo the bounded grid |
|
103 | - * @param int $grid_columns Number of columns/rows in the grid |
|
104 | - * @return array|NULL |
|
105 | - */ |
|
106 | - protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array |
|
107 | - { |
|
108 | - list($x, $y) = $point->toArray(); |
|
109 | - list($x_max, $y_max) = $grid_NE->toArray(); |
|
110 | - list($x_min, $y_min) = $grid_SW->toArray(); |
|
111 | - |
|
112 | - $x_step = ($x_max - $x_min) / $grid_columns; |
|
113 | - $y_step = ($y_max - $y_min) / $grid_columns; |
|
114 | - |
|
115 | - if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) { |
|
116 | - return [ |
|
117 | - $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step), |
|
118 | - $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step) |
|
119 | - ]; |
|
120 | - } |
|
121 | - return null; |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Get an indexed array of the features of the map. |
|
126 | - * |
|
127 | - * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell. |
|
128 | - * The grid is computed once for each map, and cached.} |
|
129 | - * |
|
130 | - * @return array|NULL |
|
131 | - */ |
|
132 | - protected function featuresIndex(): ?array |
|
133 | - { |
|
134 | - $cacheKey = $this->cacheKey(); |
|
135 | - if ($cacheKey === null) { |
|
136 | - return null; |
|
137 | - } |
|
138 | - return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
139 | - $map_def = $this->data('map'); |
|
140 | - if ( |
|
141 | - !$this->setGeometryEngine() |
|
142 | - || $map_def === null |
|
143 | - || !($map_def instanceof MapDefinitionInterface) |
|
144 | - ) { |
|
145 | - return null; |
|
146 | - } |
|
147 | - $bounding_boxes = []; |
|
148 | - $map_bounding_box = new BoundingBox(); |
|
149 | - $srid = 0; |
|
150 | - foreach ($map_def->features() as $feature) { |
|
151 | - $geometry = $feature->getGeometry(); |
|
152 | - if ($geometry === null) { |
|
153 | - continue; |
|
154 | - } |
|
155 | - $srid = $geometry->SRID(); |
|
156 | - $bounding_box = $geometry->getBoundingBox(); |
|
157 | - $bounding_boxes[] = [$feature, $bounding_box]; |
|
158 | - $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
159 | - } |
|
160 | - $grid_columns = count($bounding_boxes); |
|
161 | - $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
162 | - $map_NE = $map_bounding_box->getNorthEast(); |
|
163 | - $map_SW = $map_bounding_box->getSouthWest(); |
|
164 | - foreach ($bounding_boxes as $item) { |
|
165 | - $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
166 | - $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
167 | - for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
168 | - for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
169 | - $grid[$i][$j][] = $item[0]; |
|
170 | - } |
|
171 | - } |
|
172 | - } |
|
173 | - return [ |
|
174 | - 'grid' => $grid, |
|
175 | - 'nb_columns' => $grid_columns, |
|
176 | - 'map_NE' => $map_NE, |
|
177 | - 'map_SW' => $map_SW, |
|
178 | - 'SRID' => $srid |
|
179 | - ]; |
|
180 | - }); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Set the Brick Geo Engine to use the database for geospatial computations. |
|
185 | - * The engine is set only if it has not been set beforehand. |
|
186 | - * |
|
187 | - * @return bool |
|
188 | - */ |
|
189 | - protected function setGeometryEngine(): bool |
|
190 | - { |
|
191 | - try { |
|
192 | - if (!GeometryEngineRegistry::has()) { |
|
193 | - GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo())); |
|
194 | - } |
|
195 | - $point = Point::xy(1, 1); |
|
196 | - return $point->equals($point); |
|
197 | - } catch (Throwable $ex) { |
|
198 | - } |
|
199 | - return false; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Get the key to cache the indexed grid of features. |
|
204 | - * |
|
205 | - * @return string|NULL |
|
206 | - */ |
|
207 | - protected function cacheKey(): ?string |
|
208 | - { |
|
209 | - if ($this->cache_key === null) { |
|
210 | - $map_def = $this->data('map'); |
|
211 | - if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
212 | - return null; |
|
213 | - } |
|
214 | - return spl_object_id($this) . '-map-' . $map_def->id(); |
|
215 | - } |
|
216 | - return $this->cache_key; |
|
217 | - } |
|
39 | + use PlaceMapperTrait; |
|
40 | + |
|
41 | + private ?string $cache_key = null; |
|
42 | + |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
46 | + */ |
|
47 | + public function title(): string |
|
48 | + { |
|
49 | + return I18N::translate('Mapping on place coordinates'); |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * |
|
55 | + * {@internal The Place is associated to a Point only. |
|
56 | + * PlaceLocation can calculate a BoundingBox. |
|
57 | + * Using a BoundingBox could make the mapping more complex and potentially arbitary. |
|
58 | + * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents. |
|
59 | + * This could create the unwanted side effect of a very large area to consider} |
|
60 | + * |
|
61 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
62 | + */ |
|
63 | + public function map(Place $place, string $feature_property): ?string |
|
64 | + { |
|
65 | + $location = new PlaceLocation($place->gedcomName()); |
|
66 | + $longitude = $location->longitude(); |
|
67 | + $latitude = $location->latitude(); |
|
68 | + if ($longitude === null || $latitude === null) { |
|
69 | + return null; |
|
70 | + } |
|
71 | + |
|
72 | + $features_index = $this->featuresIndex(); |
|
73 | + if ($features_index === null) { |
|
74 | + return null; |
|
75 | + } |
|
76 | + |
|
77 | + $place_point = Point::xy($longitude, $latitude, $features_index['SRID']); |
|
78 | + $grid_box = $this->getGridCell( |
|
79 | + $place_point, |
|
80 | + $features_index['map_NE'], |
|
81 | + $features_index['map_SW'], |
|
82 | + $features_index['nb_columns'] |
|
83 | + ); |
|
84 | + if ($grid_box === null || !$this->setGeometryEngine()) { |
|
85 | + return null; |
|
86 | + } |
|
87 | + $features = $features_index['grid'][$grid_box[0]][$grid_box[1]]; |
|
88 | + foreach ($features as $feature) { |
|
89 | + $geometry = $feature->getGeometry(); |
|
90 | + if ($place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) { |
|
91 | + return $feature->getProperty($feature_property); |
|
92 | + } |
|
93 | + } |
|
94 | + return null; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Return the XY coordinates in a bounded grid of the cell containing a specific point. |
|
99 | + * |
|
100 | + * @param Point $point Point to find |
|
101 | + * @param Point $grid_NE North-East point of the bounded grid |
|
102 | + * @param Point $grid_SW South-West point fo the bounded grid |
|
103 | + * @param int $grid_columns Number of columns/rows in the grid |
|
104 | + * @return array|NULL |
|
105 | + */ |
|
106 | + protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array |
|
107 | + { |
|
108 | + list($x, $y) = $point->toArray(); |
|
109 | + list($x_max, $y_max) = $grid_NE->toArray(); |
|
110 | + list($x_min, $y_min) = $grid_SW->toArray(); |
|
111 | + |
|
112 | + $x_step = ($x_max - $x_min) / $grid_columns; |
|
113 | + $y_step = ($y_max - $y_min) / $grid_columns; |
|
114 | + |
|
115 | + if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) { |
|
116 | + return [ |
|
117 | + $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step), |
|
118 | + $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step) |
|
119 | + ]; |
|
120 | + } |
|
121 | + return null; |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Get an indexed array of the features of the map. |
|
126 | + * |
|
127 | + * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell. |
|
128 | + * The grid is computed once for each map, and cached.} |
|
129 | + * |
|
130 | + * @return array|NULL |
|
131 | + */ |
|
132 | + protected function featuresIndex(): ?array |
|
133 | + { |
|
134 | + $cacheKey = $this->cacheKey(); |
|
135 | + if ($cacheKey === null) { |
|
136 | + return null; |
|
137 | + } |
|
138 | + return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
139 | + $map_def = $this->data('map'); |
|
140 | + if ( |
|
141 | + !$this->setGeometryEngine() |
|
142 | + || $map_def === null |
|
143 | + || !($map_def instanceof MapDefinitionInterface) |
|
144 | + ) { |
|
145 | + return null; |
|
146 | + } |
|
147 | + $bounding_boxes = []; |
|
148 | + $map_bounding_box = new BoundingBox(); |
|
149 | + $srid = 0; |
|
150 | + foreach ($map_def->features() as $feature) { |
|
151 | + $geometry = $feature->getGeometry(); |
|
152 | + if ($geometry === null) { |
|
153 | + continue; |
|
154 | + } |
|
155 | + $srid = $geometry->SRID(); |
|
156 | + $bounding_box = $geometry->getBoundingBox(); |
|
157 | + $bounding_boxes[] = [$feature, $bounding_box]; |
|
158 | + $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
159 | + } |
|
160 | + $grid_columns = count($bounding_boxes); |
|
161 | + $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
162 | + $map_NE = $map_bounding_box->getNorthEast(); |
|
163 | + $map_SW = $map_bounding_box->getSouthWest(); |
|
164 | + foreach ($bounding_boxes as $item) { |
|
165 | + $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
166 | + $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
167 | + for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
168 | + for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
169 | + $grid[$i][$j][] = $item[0]; |
|
170 | + } |
|
171 | + } |
|
172 | + } |
|
173 | + return [ |
|
174 | + 'grid' => $grid, |
|
175 | + 'nb_columns' => $grid_columns, |
|
176 | + 'map_NE' => $map_NE, |
|
177 | + 'map_SW' => $map_SW, |
|
178 | + 'SRID' => $srid |
|
179 | + ]; |
|
180 | + }); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Set the Brick Geo Engine to use the database for geospatial computations. |
|
185 | + * The engine is set only if it has not been set beforehand. |
|
186 | + * |
|
187 | + * @return bool |
|
188 | + */ |
|
189 | + protected function setGeometryEngine(): bool |
|
190 | + { |
|
191 | + try { |
|
192 | + if (!GeometryEngineRegistry::has()) { |
|
193 | + GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo())); |
|
194 | + } |
|
195 | + $point = Point::xy(1, 1); |
|
196 | + return $point->equals($point); |
|
197 | + } catch (Throwable $ex) { |
|
198 | + } |
|
199 | + return false; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Get the key to cache the indexed grid of features. |
|
204 | + * |
|
205 | + * @return string|NULL |
|
206 | + */ |
|
207 | + protected function cacheKey(): ?string |
|
208 | + { |
|
209 | + if ($this->cache_key === null) { |
|
210 | + $map_def = $this->data('map'); |
|
211 | + if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
212 | + return null; |
|
213 | + } |
|
214 | + return spl_object_id($this) . '-map-' . $map_def->id(); |
|
215 | + } |
|
216 | + return $this->cache_key; |
|
217 | + } |
|
218 | 218 | } |