@@ -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 | } |
@@ -21,102 +21,102 @@ |
||
21 | 21 | */ |
22 | 22 | class PlacesReferenceTableService |
23 | 23 | { |
24 | - /** |
|
25 | - * Mapping format placeholder tags => table column names |
|
26 | - * @var array<string, string> |
|
27 | - */ |
|
28 | - private const COLUMN_MAPPING = [ |
|
29 | - 'name' => 'majgr_place_name', |
|
30 | - 'id' => 'majgr_place_admin_id', |
|
31 | - 'zip' => 'majgr_place_zip', |
|
32 | - 'gov' => 'majgr_place_gov_id', |
|
33 | - 'mls' => 'majgr_place_mls_id' |
|
34 | - ]; |
|
24 | + /** |
|
25 | + * Mapping format placeholder tags => table column names |
|
26 | + * @var array<string, string> |
|
27 | + */ |
|
28 | + private const COLUMN_MAPPING = [ |
|
29 | + 'name' => 'majgr_place_name', |
|
30 | + 'id' => 'majgr_place_admin_id', |
|
31 | + 'zip' => 'majgr_place_zip', |
|
32 | + 'gov' => 'majgr_place_gov_id', |
|
33 | + 'mls' => 'majgr_place_mls_id' |
|
34 | + ]; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get the formatted target mapping value of a place defined by a source format. |
|
38 | - * |
|
39 | - * @param string $source |
|
40 | - * @param string $source_format |
|
41 | - * @param string $target_format |
|
42 | - * @return string|NULL |
|
43 | - */ |
|
44 | - public function targetId(string $source, string $source_format, string $target_format): ?string |
|
45 | - { |
|
46 | - // Extract parts for the WHERE clause |
|
47 | - $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format); |
|
48 | - $source_parts = preg_split('/[{}]/i', $source_format); |
|
49 | - if ($source_parts === false) { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $source_parts = array_map(function (string $part): string { |
|
53 | - if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
|
54 | - return $this->columnName($column_id[1]); |
|
55 | - } |
|
56 | - return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
|
57 | - }, array_filter($source_parts)); |
|
58 | - $source_parts[] = "'%'"; |
|
59 | - $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
36 | + /** |
|
37 | + * Get the formatted target mapping value of a place defined by a source format. |
|
38 | + * |
|
39 | + * @param string $source |
|
40 | + * @param string $source_format |
|
41 | + * @param string $target_format |
|
42 | + * @return string|NULL |
|
43 | + */ |
|
44 | + public function targetId(string $source, string $source_format, string $target_format): ?string |
|
45 | + { |
|
46 | + // Extract parts for the WHERE clause |
|
47 | + $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format); |
|
48 | + $source_parts = preg_split('/[{}]/i', $source_format); |
|
49 | + if ($source_parts === false) { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $source_parts = array_map(function (string $part): string { |
|
53 | + if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
|
54 | + return $this->columnName($column_id[1]); |
|
55 | + } |
|
56 | + return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
|
57 | + }, array_filter($source_parts)); |
|
58 | + $source_parts[] = "'%'"; |
|
59 | + $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
60 | 60 | |
61 | - // Extract columns used in target |
|
62 | - $columns = []; |
|
63 | - if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) { |
|
64 | - $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1]))); |
|
65 | - } |
|
61 | + // Extract columns used in target |
|
62 | + $columns = []; |
|
63 | + if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) { |
|
64 | + $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1]))); |
|
65 | + } |
|
66 | 66 | |
67 | - // Get the mapping |
|
68 | - $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
|
69 | - ->select($columns) |
|
70 | - ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
71 | - ->get(); |
|
67 | + // Get the mapping |
|
68 | + $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
|
69 | + ->select($columns) |
|
70 | + ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
71 | + ->get(); |
|
72 | 72 | |
73 | - // Format the output ID |
|
74 | - if ($rows->count() === 0) { |
|
75 | - return null; |
|
76 | - } |
|
73 | + // Format the output ID |
|
74 | + if ($rows->count() === 0) { |
|
75 | + return null; |
|
76 | + } |
|
77 | 77 | |
78 | - $mapping = (array) $rows->first(); |
|
79 | - if (count($columns_select) === 0) { |
|
80 | - return $target_format; |
|
81 | - } |
|
78 | + $mapping = (array) $rows->first(); |
|
79 | + if (count($columns_select) === 0) { |
|
80 | + return $target_format; |
|
81 | + } |
|
82 | 82 | |
83 | - return str_replace( |
|
84 | - array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
85 | - array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
|
86 | - $target_format |
|
87 | - ); |
|
88 | - } |
|
83 | + return str_replace( |
|
84 | + array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
85 | + array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
|
86 | + $target_format |
|
87 | + ); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Get the column name for a format placeholder tag |
|
92 | - * |
|
93 | - * @param string $placeholder |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - private function columnName(string $placeholder): string |
|
97 | - { |
|
98 | - return self::COLUMN_MAPPING[$placeholder] ?? ''; |
|
99 | - } |
|
90 | + /** |
|
91 | + * Get the column name for a format placeholder tag |
|
92 | + * |
|
93 | + * @param string $placeholder |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + private function columnName(string $placeholder): string |
|
97 | + { |
|
98 | + return self::COLUMN_MAPPING[$placeholder] ?? ''; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the placeholder tag for a column_name |
|
103 | - * |
|
104 | - * @param string $column_name |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - private function tagName(string $column_name): string |
|
108 | - { |
|
109 | - return array_flip(self::COLUMN_MAPPING)[$column_name] ?? ''; |
|
110 | - } |
|
101 | + /** |
|
102 | + * Get the placeholder tag for a column_name |
|
103 | + * |
|
104 | + * @param string $column_name |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + private function tagName(string $column_name): string |
|
108 | + { |
|
109 | + return array_flip(self::COLUMN_MAPPING)[$column_name] ?? ''; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Sanitize string for use in a SQL query. |
|
114 | - * |
|
115 | - * @param string $string |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - private function sanitizeString(string $string): string |
|
119 | - { |
|
120 | - return DB::connection()->getPdo()->quote($string); |
|
121 | - } |
|
112 | + /** |
|
113 | + * Sanitize string for use in a SQL query. |
|
114 | + * |
|
115 | + * @param string $string |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + private function sanitizeString(string $string): string |
|
119 | + { |
|
120 | + return DB::connection()->getPdo()->quote($string); |
|
121 | + } |
|
122 | 122 | } |
@@ -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,114 +28,114 @@ |
||
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 | - * @param mixed $config |
|
75 | - * @return $this |
|
76 | - */ |
|
77 | - public function jsonDeserialize($config): self |
|
78 | - { |
|
79 | - if (is_string($config)) { |
|
80 | - return $this->jsonDeserialize(json_decode($config)); |
|
81 | - } |
|
82 | - if (is_array($config)) { |
|
83 | - $this->setConfig([ |
|
84 | - 'topPlaces' => collect($config['topPlaces'] ?? []) |
|
85 | - ->filter( |
|
86 | - /** @psalm-suppress MissingClosureParamType */ |
|
87 | - fn($item): bool => is_array($item) && count($item) == 2 |
|
88 | - )->map(function (array $item): ?Place { |
|
89 | - try { |
|
90 | - return new Place($item[1], $this->tree_service->find($item[0])); |
|
91 | - } catch (RuntimeException $ex) { |
|
92 | - return null; |
|
93 | - } |
|
94 | - }) |
|
95 | - ->filter() |
|
96 | - ->toArray() |
|
97 | - ]); |
|
98 | - } |
|
99 | - return $this; |
|
100 | - } |
|
70 | + /** |
|
71 | + * {@inheritDoc} |
|
72 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonDeserialize() |
|
73 | + * |
|
74 | + * @param mixed $config |
|
75 | + * @return $this |
|
76 | + */ |
|
77 | + public function jsonDeserialize($config): self |
|
78 | + { |
|
79 | + if (is_string($config)) { |
|
80 | + return $this->jsonDeserialize(json_decode($config)); |
|
81 | + } |
|
82 | + if (is_array($config)) { |
|
83 | + $this->setConfig([ |
|
84 | + 'topPlaces' => collect($config['topPlaces'] ?? []) |
|
85 | + ->filter( |
|
86 | + /** @psalm-suppress MissingClosureParamType */ |
|
87 | + fn($item): bool => is_array($item) && count($item) == 2 |
|
88 | + )->map(function (array $item): ?Place { |
|
89 | + try { |
|
90 | + return new Place($item[1], $this->tree_service->find($item[0])); |
|
91 | + } catch (RuntimeException $ex) { |
|
92 | + return null; |
|
93 | + } |
|
94 | + }) |
|
95 | + ->filter() |
|
96 | + ->toArray() |
|
97 | + ]); |
|
98 | + } |
|
99 | + return $this; |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * {@inheritDoc} |
|
104 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::configContent() |
|
105 | - */ |
|
106 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
107 | - { |
|
108 | - return view($module->name() . '::mappers/filtered-top-config', [ |
|
109 | - 'tree' => $tree, |
|
110 | - 'top_places' => $this->topPlaces() |
|
111 | - ]); |
|
112 | - } |
|
102 | + /** |
|
103 | + * {@inheritDoc} |
|
104 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::configContent() |
|
105 | + */ |
|
106 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
107 | + { |
|
108 | + return view($module->name() . '::mappers/filtered-top-config', [ |
|
109 | + 'tree' => $tree, |
|
110 | + 'top_places' => $this->topPlaces() |
|
111 | + ]); |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * {@inheritDoc} |
|
116 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::withConfigUpdate() |
|
117 | - * @return $this |
|
118 | - */ |
|
119 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
120 | - { |
|
121 | - $tree = $request->getAttribute('tree'); |
|
122 | - if (!($tree instanceof Tree)) { |
|
123 | - return $this; |
|
124 | - } |
|
114 | + /** |
|
115 | + * {@inheritDoc} |
|
116 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::withConfigUpdate() |
|
117 | + * @return $this |
|
118 | + */ |
|
119 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
120 | + { |
|
121 | + $tree = $request->getAttribute('tree'); |
|
122 | + if (!($tree instanceof Tree)) { |
|
123 | + return $this; |
|
124 | + } |
|
125 | 125 | |
126 | - $params = (array) $request->getParsedBody(); |
|
126 | + $params = (array) $request->getParsedBody(); |
|
127 | 127 | |
128 | - $top_places = $params['mapper_filt_top_places'] ?? []; |
|
129 | - if (is_array($top_places)) { |
|
130 | - $config = ['topPlaces' => []]; |
|
131 | - foreach ($top_places as $top_place_id) { |
|
132 | - $place = Place::find((int) $top_place_id, $tree); |
|
133 | - if (mb_strlen($place->gedcomName()) > 0) { |
|
134 | - $config['topPlaces'][] = $place; |
|
135 | - } |
|
136 | - } |
|
137 | - $this->setConfig($config); |
|
138 | - } |
|
139 | - return $this; |
|
140 | - } |
|
128 | + $top_places = $params['mapper_filt_top_places'] ?? []; |
|
129 | + if (is_array($top_places)) { |
|
130 | + $config = ['topPlaces' => []]; |
|
131 | + foreach ($top_places as $top_place_id) { |
|
132 | + $place = Place::find((int) $top_place_id, $tree); |
|
133 | + if (mb_strlen($place->gedcomName()) > 0) { |
|
134 | + $config['topPlaces'][] = $place; |
|
135 | + } |
|
136 | + } |
|
137 | + $this->setConfig($config); |
|
138 | + } |
|
139 | + return $this; |
|
140 | + } |
|
141 | 141 | } |
@@ -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 | } |
@@ -22,81 +22,81 @@ |
||
22 | 22 | */ |
23 | 23 | class MapFeatureAnalysisData |
24 | 24 | { |
25 | - private string $id; |
|
26 | - private int $count; |
|
27 | - private bool $in_map; |
|
28 | - /** |
|
29 | - * @var Collection<GeoAnalysisPlace> $places |
|
30 | - */ |
|
31 | - private Collection $places; |
|
25 | + private string $id; |
|
26 | + private int $count; |
|
27 | + private bool $in_map; |
|
28 | + /** |
|
29 | + * @var Collection<GeoAnalysisPlace> $places |
|
30 | + */ |
|
31 | + private Collection $places; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor for MapFeatureAnalysisData |
|
35 | - * |
|
36 | - * @param string $id |
|
37 | - */ |
|
38 | - public function __construct(string $id) |
|
39 | - { |
|
40 | - $this->id = $id; |
|
41 | - $this->count = 0; |
|
42 | - $this->places = new Collection(); |
|
43 | - $this->in_map = false; |
|
44 | - } |
|
33 | + /** |
|
34 | + * Constructor for MapFeatureAnalysisData |
|
35 | + * |
|
36 | + * @param string $id |
|
37 | + */ |
|
38 | + public function __construct(string $id) |
|
39 | + { |
|
40 | + $this->id = $id; |
|
41 | + $this->count = 0; |
|
42 | + $this->places = new Collection(); |
|
43 | + $this->in_map = false; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the list of places mapped to the feature |
|
48 | - * |
|
49 | - * @return Collection<GeoAnalysisPlace> |
|
50 | - */ |
|
51 | - public function places(): Collection |
|
52 | - { |
|
53 | - return $this->places; |
|
54 | - } |
|
46 | + /** |
|
47 | + * Get the list of places mapped to the feature |
|
48 | + * |
|
49 | + * @return Collection<GeoAnalysisPlace> |
|
50 | + */ |
|
51 | + public function places(): Collection |
|
52 | + { |
|
53 | + return $this->places; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get the count of analysis items occurring in the feature |
|
58 | - * |
|
59 | - * @return int |
|
60 | - */ |
|
61 | - public function count(): int |
|
62 | - { |
|
63 | - return $this->count; |
|
64 | - } |
|
56 | + /** |
|
57 | + * Get the count of analysis items occurring in the feature |
|
58 | + * |
|
59 | + * @return int |
|
60 | + */ |
|
61 | + public function count(): int |
|
62 | + { |
|
63 | + return $this->count; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Check whether the feature exist in the target map |
|
68 | - * |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - public function existsInMap(): bool |
|
72 | - { |
|
73 | - return $this->in_map; |
|
74 | - } |
|
66 | + /** |
|
67 | + * Check whether the feature exist in the target map |
|
68 | + * |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + public function existsInMap(): bool |
|
72 | + { |
|
73 | + return $this->in_map; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Confirm that the feature exist in the target map |
|
78 | - * |
|
79 | - * @return $this |
|
80 | - */ |
|
81 | - public function tagAsExisting(): self |
|
82 | - { |
|
83 | - $this->in_map = true; |
|
84 | - return $this; |
|
85 | - } |
|
76 | + /** |
|
77 | + * Confirm that the feature exist in the target map |
|
78 | + * |
|
79 | + * @return $this |
|
80 | + */ |
|
81 | + public function tagAsExisting(): self |
|
82 | + { |
|
83 | + $this->in_map = true; |
|
84 | + return $this; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Add a GeoAnalysisPlace to the feature |
|
89 | - * |
|
90 | - * @param GeoAnalysisPlace $place |
|
91 | - * @param int $count |
|
92 | - * @return $this |
|
93 | - */ |
|
94 | - public function add(GeoAnalysisPlace $place, int $count): self |
|
95 | - { |
|
96 | - if (!$place->isExcluded()) { |
|
97 | - $this->places->add($place); |
|
98 | - $this->count += $count; |
|
99 | - } |
|
100 | - return $this; |
|
101 | - } |
|
87 | + /** |
|
88 | + * Add a GeoAnalysisPlace to the feature |
|
89 | + * |
|
90 | + * @param GeoAnalysisPlace $place |
|
91 | + * @param int $count |
|
92 | + * @return $this |
|
93 | + */ |
|
94 | + public function add(GeoAnalysisPlace $place, int $count): self |
|
95 | + { |
|
96 | + if (!$place->isExcluded()) { |
|
97 | + $this->places->add($place); |
|
98 | + $this->count += $count; |
|
99 | + } |
|
100 | + return $this; |
|
101 | + } |
|
102 | 102 | } |