@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | foreach ($existing_views as $old_view) { |
93 | 93 | try { |
94 | - $tree = $tree_service->find((int) $old_view->majgd_file); |
|
94 | + $tree = $tree_service->find((int)$old_view->majgd_file); |
|
95 | 95 | } catch (RuntimeException $ex) { |
96 | 96 | continue; |
97 | 97 | } |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | $old_view->majgd_status === 'enabled', |
135 | 135 | $old_view->majgd_descr, |
136 | 136 | app(SosaByGenerationGeoAnalysis::class), |
137 | - (int) $old_view->majgd_sublevel, |
|
138 | - (int) $old_view->majgd_detailsgen |
|
137 | + (int)$old_view->majgd_sublevel, |
|
138 | + (int)$old_view->majgd_detailsgen |
|
139 | 139 | ); |
140 | 140 | |
141 | 141 | return $geoview_data_service->insertGetId($new_view) > 0; |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | $old_view->majgd_status === 'enabled', |
166 | 166 | $old_view->majgd_descr, |
167 | 167 | app(SosaByGenerationGeoAnalysis::class), |
168 | - (int) $old_view->majgd_sublevel, |
|
169 | - (int) $old_view->majgd_detailsgen |
|
168 | + (int)$old_view->majgd_sublevel, |
|
169 | + (int)$old_view->majgd_detailsgen |
|
170 | 170 | ); |
171 | 171 | |
172 | 172 | $view_id = $geoview_data_service->insertGetId($new_view); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | private function mapIdsFromOld(string $map_xml): array |
204 | 204 | { |
205 | 205 | $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? []; |
206 | - return is_array($mapping) ? $mapping : [ $mapping ]; |
|
206 | + return is_array($mapping) ? $mapping : [$mapping]; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -39,219 +39,219 @@ |
||
39 | 39 | */ |
40 | 40 | class Migration2 implements MigrationInterface |
41 | 41 | { |
42 | - /** |
|
43 | - * Mapping from old map definitions to new ones |
|
44 | - * @var array<string,mixed> MAPS_XML_MAPPING |
|
45 | - */ |
|
46 | - private const MAPS_XML_MAPPING = [ |
|
47 | - 'aubracmargeridebycommunes.xml' => 'fr-area-aubrac-lot-margeride-planeze-communes', |
|
48 | - 'calvadosbycommunes.xml' => 'fr-dpt-14-communes', |
|
49 | - 'cantalbycommunes.xml' => 'fr-dpt-15-communes', |
|
50 | - 'cotesdarmorbycommunes.xml' => 'fr-dpt-22-communes', |
|
51 | - 'essonnebycommunes.xml' => 'fr-dpt-91-communes', |
|
52 | - 'eurebycommunes.xml' => 'fr-dpt-27-communes', |
|
53 | - 'eureetloirbycommunes.xml' => 'fr-dpt-28-communes', |
|
54 | - 'francebydepartements.xml' => 'fr-metropole-departements', |
|
55 | - 'francebyregions1970.xml' => 'fr-metropole-regions-1970', |
|
56 | - 'francebyregions2016.xml' => 'fr-metropole-regions-2016', |
|
57 | - 'hauteloirebycommunes.xml' => 'fr-dpt-43-communes', |
|
58 | - 'illeetvilainebycommunes.xml' => 'fr-dpt-35-communes', |
|
59 | - 'loiretbycommunes.xml' => 'fr-dpt-45-communes', |
|
60 | - 'lozerebycodepostaux.xml' => 'fr-dpt-48-codespostaux', |
|
61 | - 'lozerebycommunes.xml' => 'fr-dpt-48-communes', |
|
62 | - 'mayennebycommunes.xml' => 'fr-dpt-53-communes', |
|
63 | - 'oisebycommunes.xml' => 'fr-dpt-60-communes', |
|
64 | - 'ornebycommunes.xml' => 'fr-dpt-61-communes', |
|
65 | - 'puydedomebycommunes.xml' => 'fr-dpt-63-communes', |
|
66 | - 'sarthebycommunes.xml' => 'fr-dpt-72-communes', |
|
67 | - 'seinemaritimebycommunes.xml' => 'fr-dpt-76-communes', |
|
68 | - 'seinesommeoisebycommunes.xml' => ['fr-dpt-60-communes', 'fr-dpt-76-communes', 'fr-dpt-80-communes'], |
|
69 | - 'valdoisebycommunes.xml' => 'fr-dpt-95-communes', |
|
70 | - 'yvelinesbycommunes.xml' => 'fr-dpt-78-communes' |
|
71 | - ]; |
|
42 | + /** |
|
43 | + * Mapping from old map definitions to new ones |
|
44 | + * @var array<string,mixed> MAPS_XML_MAPPING |
|
45 | + */ |
|
46 | + private const MAPS_XML_MAPPING = [ |
|
47 | + 'aubracmargeridebycommunes.xml' => 'fr-area-aubrac-lot-margeride-planeze-communes', |
|
48 | + 'calvadosbycommunes.xml' => 'fr-dpt-14-communes', |
|
49 | + 'cantalbycommunes.xml' => 'fr-dpt-15-communes', |
|
50 | + 'cotesdarmorbycommunes.xml' => 'fr-dpt-22-communes', |
|
51 | + 'essonnebycommunes.xml' => 'fr-dpt-91-communes', |
|
52 | + 'eurebycommunes.xml' => 'fr-dpt-27-communes', |
|
53 | + 'eureetloirbycommunes.xml' => 'fr-dpt-28-communes', |
|
54 | + 'francebydepartements.xml' => 'fr-metropole-departements', |
|
55 | + 'francebyregions1970.xml' => 'fr-metropole-regions-1970', |
|
56 | + 'francebyregions2016.xml' => 'fr-metropole-regions-2016', |
|
57 | + 'hauteloirebycommunes.xml' => 'fr-dpt-43-communes', |
|
58 | + 'illeetvilainebycommunes.xml' => 'fr-dpt-35-communes', |
|
59 | + 'loiretbycommunes.xml' => 'fr-dpt-45-communes', |
|
60 | + 'lozerebycodepostaux.xml' => 'fr-dpt-48-codespostaux', |
|
61 | + 'lozerebycommunes.xml' => 'fr-dpt-48-communes', |
|
62 | + 'mayennebycommunes.xml' => 'fr-dpt-53-communes', |
|
63 | + 'oisebycommunes.xml' => 'fr-dpt-60-communes', |
|
64 | + 'ornebycommunes.xml' => 'fr-dpt-61-communes', |
|
65 | + 'puydedomebycommunes.xml' => 'fr-dpt-63-communes', |
|
66 | + 'sarthebycommunes.xml' => 'fr-dpt-72-communes', |
|
67 | + 'seinemaritimebycommunes.xml' => 'fr-dpt-76-communes', |
|
68 | + 'seinesommeoisebycommunes.xml' => ['fr-dpt-60-communes', 'fr-dpt-76-communes', 'fr-dpt-80-communes'], |
|
69 | + 'valdoisebycommunes.xml' => 'fr-dpt-95-communes', |
|
70 | + 'yvelinesbycommunes.xml' => 'fr-dpt-78-communes' |
|
71 | + ]; |
|
72 | 72 | |
73 | - /** |
|
74 | - * {@inheritDoc} |
|
75 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
76 | - */ |
|
77 | - public function upgrade(): void |
|
78 | - { |
|
79 | - if (!DB::schema()->hasTable('maj_geodispersion')) { |
|
80 | - return; |
|
81 | - } |
|
73 | + /** |
|
74 | + * {@inheritDoc} |
|
75 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
76 | + */ |
|
77 | + public function upgrade(): void |
|
78 | + { |
|
79 | + if (!DB::schema()->hasTable('maj_geodispersion')) { |
|
80 | + return; |
|
81 | + } |
|
82 | 82 | |
83 | - /** @var TreeService $tree_service */ |
|
84 | - $tree_service = app(TreeService::class); |
|
85 | - /** @var GeoAnalysisViewDataService $geoview_data_service */ |
|
86 | - $geoview_data_service = app(GeoAnalysisViewDataService::class); |
|
83 | + /** @var TreeService $tree_service */ |
|
84 | + $tree_service = app(TreeService::class); |
|
85 | + /** @var GeoAnalysisViewDataService $geoview_data_service */ |
|
86 | + $geoview_data_service = app(GeoAnalysisViewDataService::class); |
|
87 | 87 | |
88 | - $existing_views = DB::table('maj_geodispersion') |
|
89 | - ->select() |
|
90 | - ->get(); |
|
88 | + $existing_views = DB::table('maj_geodispersion') |
|
89 | + ->select() |
|
90 | + ->get(); |
|
91 | 91 | |
92 | - foreach ($existing_views as $old_view) { |
|
93 | - try { |
|
94 | - $tree = $tree_service->find((int) $old_view->majgd_file); |
|
95 | - } catch (RuntimeException $ex) { |
|
96 | - continue; |
|
97 | - } |
|
92 | + foreach ($existing_views as $old_view) { |
|
93 | + try { |
|
94 | + $tree = $tree_service->find((int) $old_view->majgd_file); |
|
95 | + } catch (RuntimeException $ex) { |
|
96 | + continue; |
|
97 | + } |
|
98 | 98 | |
99 | - if ($old_view->majgd_map === null) { |
|
100 | - $this->migrateGeoAnalysisTable($old_view, $tree, $geoview_data_service); |
|
101 | - } else { |
|
102 | - DB::connection()->beginTransaction(); |
|
103 | - if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) { |
|
104 | - DB::connection()->commit(); |
|
105 | - } else { |
|
106 | - DB::connection()->rollBack(); |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
99 | + if ($old_view->majgd_map === null) { |
|
100 | + $this->migrateGeoAnalysisTable($old_view, $tree, $geoview_data_service); |
|
101 | + } else { |
|
102 | + DB::connection()->beginTransaction(); |
|
103 | + if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) { |
|
104 | + DB::connection()->commit(); |
|
105 | + } else { |
|
106 | + DB::connection()->rollBack(); |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - $in_transaction = DB::connection()->getPdo()->inTransaction(); |
|
111 | + $in_transaction = DB::connection()->getPdo()->inTransaction(); |
|
112 | 112 | |
113 | - DB::schema()->drop('maj_geodispersion'); |
|
113 | + DB::schema()->drop('maj_geodispersion'); |
|
114 | 114 | |
115 | - if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) { |
|
116 | - DB::connection()->beginTransaction(); |
|
117 | - } |
|
115 | + if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) { |
|
116 | + DB::connection()->beginTransaction(); |
|
117 | + } |
|
118 | 118 | |
119 | - FlashMessages::addMessage(I18N::translate( |
|
120 | - 'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.' |
|
121 | - )); |
|
122 | - } |
|
119 | + FlashMessages::addMessage(I18N::translate( |
|
120 | + 'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.' |
|
121 | + )); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Create a Table geographical analysis view from a migrated item. |
|
126 | - * |
|
127 | - * @param stdClass $old_view |
|
128 | - * @param Tree $tree |
|
129 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - private function migrateGeoAnalysisTable( |
|
133 | - stdClass $old_view, |
|
134 | - Tree $tree, |
|
135 | - GeoAnalysisViewDataService $geoview_data_service |
|
136 | - ): bool { |
|
137 | - $new_view = new GeoAnalysisTable( |
|
138 | - 0, |
|
139 | - $tree, |
|
140 | - $old_view->majgd_status === 'enabled', |
|
141 | - $old_view->majgd_descr, |
|
142 | - app(SosaByGenerationGeoAnalysis::class), |
|
143 | - (int) $old_view->majgd_sublevel, |
|
144 | - (int) $old_view->majgd_detailsgen |
|
145 | - ); |
|
124 | + /** |
|
125 | + * Create a Table geographical analysis view from a migrated item. |
|
126 | + * |
|
127 | + * @param stdClass $old_view |
|
128 | + * @param Tree $tree |
|
129 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + private function migrateGeoAnalysisTable( |
|
133 | + stdClass $old_view, |
|
134 | + Tree $tree, |
|
135 | + GeoAnalysisViewDataService $geoview_data_service |
|
136 | + ): bool { |
|
137 | + $new_view = new GeoAnalysisTable( |
|
138 | + 0, |
|
139 | + $tree, |
|
140 | + $old_view->majgd_status === 'enabled', |
|
141 | + $old_view->majgd_descr, |
|
142 | + app(SosaByGenerationGeoAnalysis::class), |
|
143 | + (int) $old_view->majgd_sublevel, |
|
144 | + (int) $old_view->majgd_detailsgen |
|
145 | + ); |
|
146 | 146 | |
147 | - return $geoview_data_service->insertGetId($new_view) > 0; |
|
148 | - } |
|
147 | + return $geoview_data_service->insertGetId($new_view) > 0; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Create a Map geographical analysis view from a migrated item. |
|
152 | - * |
|
153 | - * @param stdClass $old_view |
|
154 | - * @param Tree $tree |
|
155 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
156 | - * @return bool |
|
157 | - */ |
|
158 | - private function migrateGeoAnalysisMap( |
|
159 | - stdClass $old_view, |
|
160 | - Tree $tree, |
|
161 | - GeoAnalysisViewDataService $geoview_data_service |
|
162 | - ): bool { |
|
163 | - /** @var MapDefinitionsService $map_definition_service */ |
|
164 | - $map_definition_service = app(MapDefinitionsService::class); |
|
165 | - /** @var MapAdapterDataService $mapadapter_data_service */ |
|
166 | - $mapadapter_data_service = app(MapAdapterDataService::class); |
|
150 | + /** |
|
151 | + * Create a Map geographical analysis view from a migrated item. |
|
152 | + * |
|
153 | + * @param stdClass $old_view |
|
154 | + * @param Tree $tree |
|
155 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | + private function migrateGeoAnalysisMap( |
|
159 | + stdClass $old_view, |
|
160 | + Tree $tree, |
|
161 | + GeoAnalysisViewDataService $geoview_data_service |
|
162 | + ): bool { |
|
163 | + /** @var MapDefinitionsService $map_definition_service */ |
|
164 | + $map_definition_service = app(MapDefinitionsService::class); |
|
165 | + /** @var MapAdapterDataService $mapadapter_data_service */ |
|
166 | + $mapadapter_data_service = app(MapAdapterDataService::class); |
|
167 | 167 | |
168 | - $new_view = new GeoAnalysisMap( |
|
169 | - 0, |
|
170 | - $tree, |
|
171 | - $old_view->majgd_status === 'enabled', |
|
172 | - $old_view->majgd_descr, |
|
173 | - app(SosaByGenerationGeoAnalysis::class), |
|
174 | - (int) $old_view->majgd_sublevel, |
|
175 | - (int) $old_view->majgd_detailsgen |
|
176 | - ); |
|
168 | + $new_view = new GeoAnalysisMap( |
|
169 | + 0, |
|
170 | + $tree, |
|
171 | + $old_view->majgd_status === 'enabled', |
|
172 | + $old_view->majgd_descr, |
|
173 | + app(SosaByGenerationGeoAnalysis::class), |
|
174 | + (int) $old_view->majgd_sublevel, |
|
175 | + (int) $old_view->majgd_detailsgen |
|
176 | + ); |
|
177 | 177 | |
178 | - $view_id = $geoview_data_service->insertGetId($new_view); |
|
179 | - if ($view_id === 0) { |
|
180 | - return false; |
|
181 | - } |
|
182 | - $new_view = $new_view->withId($view_id); |
|
178 | + $view_id = $geoview_data_service->insertGetId($new_view); |
|
179 | + if ($view_id === 0) { |
|
180 | + return false; |
|
181 | + } |
|
182 | + $new_view = $new_view->withId($view_id); |
|
183 | 183 | |
184 | - $colors = $new_view->colors(); |
|
185 | - foreach ($this->mapIdsFromOld($old_view->majgd_map) as $new_map_id) { |
|
186 | - $map = $map_definition_service->find($new_map_id); |
|
187 | - if ($map === null) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - $colors = $this->colorsFromMap($new_map_id); |
|
184 | + $colors = $new_view->colors(); |
|
185 | + foreach ($this->mapIdsFromOld($old_view->majgd_map) as $new_map_id) { |
|
186 | + $map = $map_definition_service->find($new_map_id); |
|
187 | + if ($map === null) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + $colors = $this->colorsFromMap($new_map_id); |
|
191 | 191 | |
192 | - /** @var SimplePlaceMapper $mapper */ |
|
193 | - $mapper = app(SimplePlaceMapper::class); |
|
194 | - $mapview_config = new MapViewConfig($this->mappingPropertyForMap($new_map_id), $mapper->config()); |
|
195 | - $map_adapter = new GeoAnalysisMapAdapter(0, $view_id, $map, $mapper, $mapview_config); |
|
192 | + /** @var SimplePlaceMapper $mapper */ |
|
193 | + $mapper = app(SimplePlaceMapper::class); |
|
194 | + $mapview_config = new MapViewConfig($this->mappingPropertyForMap($new_map_id), $mapper->config()); |
|
195 | + $map_adapter = new GeoAnalysisMapAdapter(0, $view_id, $map, $mapper, $mapview_config); |
|
196 | 196 | |
197 | - $mapadapter_data_service->insertGetId($map_adapter); |
|
198 | - } |
|
197 | + $mapadapter_data_service->insertGetId($map_adapter); |
|
198 | + } |
|
199 | 199 | |
200 | - return $geoview_data_service->update($new_view->withColors($colors)) > 0; |
|
201 | - } |
|
200 | + return $geoview_data_service->update($new_view->withColors($colors)) > 0; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Get all new map definitions IDs representing an old map definition |
|
205 | - * |
|
206 | - * @param string $map_xml |
|
207 | - * @return string[] |
|
208 | - */ |
|
209 | - private function mapIdsFromOld(string $map_xml): array |
|
210 | - { |
|
211 | - $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? []; |
|
212 | - return is_array($mapping) ? $mapping : [ $mapping ]; |
|
213 | - } |
|
203 | + /** |
|
204 | + * Get all new map definitions IDs representing an old map definition |
|
205 | + * |
|
206 | + * @param string $map_xml |
|
207 | + * @return string[] |
|
208 | + */ |
|
209 | + private function mapIdsFromOld(string $map_xml): array |
|
210 | + { |
|
211 | + $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? []; |
|
212 | + return is_array($mapping) ? $mapping : [ $mapping ]; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Get the mapping property to be used for the migrated map adapter |
|
217 | - * |
|
218 | - * @param string $map_id |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - private function mappingPropertyForMap(string $map_id): string |
|
222 | - { |
|
223 | - switch ($map_id) { |
|
224 | - case 'fr-metropole-regions-1970': |
|
225 | - case 'fr-metropole-regions-2016': |
|
226 | - return 'region_insee_libelle'; |
|
227 | - case 'fr-metropole-departements': |
|
228 | - return 'dpt_insee_libelle'; |
|
229 | - case 'fr-dpt-48-codespostaux': |
|
230 | - return 'code_postal'; |
|
231 | - default: |
|
232 | - return 'commune_insee_libelle'; |
|
233 | - } |
|
234 | - } |
|
215 | + /** |
|
216 | + * Get the mapping property to be used for the migrated map adapter |
|
217 | + * |
|
218 | + * @param string $map_id |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + private function mappingPropertyForMap(string $map_id): string |
|
222 | + { |
|
223 | + switch ($map_id) { |
|
224 | + case 'fr-metropole-regions-1970': |
|
225 | + case 'fr-metropole-regions-2016': |
|
226 | + return 'region_insee_libelle'; |
|
227 | + case 'fr-metropole-departements': |
|
228 | + return 'dpt_insee_libelle'; |
|
229 | + case 'fr-dpt-48-codespostaux': |
|
230 | + return 'code_postal'; |
|
231 | + default: |
|
232 | + return 'commune_insee_libelle'; |
|
233 | + } |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Get the color configuration to be used for the migrated map view |
|
238 | - * |
|
239 | - * @param string $map_id |
|
240 | - * @return MapColorsConfig |
|
241 | - */ |
|
242 | - private function colorsFromMap(string $map_id): MapColorsConfig |
|
243 | - { |
|
244 | - $default = Hex::fromString('#f5f5f5'); |
|
245 | - $stroke = Hex::fromString('#d5d5d5'); |
|
246 | - $hover = Hex::fromString('#ff6600'); |
|
236 | + /** |
|
237 | + * Get the color configuration to be used for the migrated map view |
|
238 | + * |
|
239 | + * @param string $map_id |
|
240 | + * @return MapColorsConfig |
|
241 | + */ |
|
242 | + private function colorsFromMap(string $map_id): MapColorsConfig |
|
243 | + { |
|
244 | + $default = Hex::fromString('#f5f5f5'); |
|
245 | + $stroke = Hex::fromString('#d5d5d5'); |
|
246 | + $hover = Hex::fromString('#ff6600'); |
|
247 | 247 | |
248 | - switch ($map_id) { |
|
249 | - case 'fr-metropole-departements': |
|
250 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover); |
|
251 | - case 'fr-dpt-48-codespostaux': |
|
252 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover); |
|
253 | - default: |
|
254 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover); |
|
255 | - } |
|
256 | - } |
|
248 | + switch ($map_id) { |
|
249 | + case 'fr-metropole-departements': |
|
250 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover); |
|
251 | + case 'fr-dpt-48-codespostaux': |
|
252 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover); |
|
253 | + default: |
|
254 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover); |
|
255 | + } |
|
256 | + } |
|
257 | 257 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView |
43 | 43 | { |
44 | 44 | return $this->all($tree, $include_disabled) |
45 | - ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id); |
|
45 | + ->first(fn(AbstractGeoAnalysisView $view) : bool => $view->id() === $id); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | return Registry::cache()->array()->remember( |
60 | 60 | 'all-geodispersion-views', |
61 | - function () use ($tree, $include_disabled): Collection { |
|
61 | + function() use ($tree, $include_disabled): Collection { |
|
62 | 62 | return DB::table('maj_geodisp_views') |
63 | 63 | ->select('maj_geodisp_views.*') |
64 | 64 | ->where('majgv_gedcom_id', '=', $tree->id()) |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | private function viewMapper(Tree $tree): Closure |
150 | 150 | { |
151 | - return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
151 | + return function(stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
152 | 152 | try { |
153 | 153 | $geoanalysis = app($row->majgv_analysis); |
154 | 154 | if (!($geoanalysis instanceof GeoAnalysisInterface)) { |
@@ -156,13 +156,13 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | $view = app()->makeWith($row->majgv_view_class, [ |
159 | - 'id' => (int) $row->majgv_id, |
|
159 | + 'id' => (int)$row->majgv_id, |
|
160 | 160 | 'tree' => $tree, |
161 | 161 | 'enabled' => $row->majgv_status === 'enabled', |
162 | 162 | 'description' => $row->majgv_descr, |
163 | 163 | 'geoanalysis' => $geoanalysis, |
164 | - 'depth' => (int) $row->majgv_place_depth, |
|
165 | - 'detailed_top_places' => (int) $row->majgv_top_places |
|
164 | + 'depth' => (int)$row->majgv_place_depth, |
|
165 | + 'detailed_top_places' => (int)$row->majgv_top_places |
|
166 | 166 | ]); |
167 | 167 | |
168 | 168 | if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) { |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | private function enabledFilter(bool $include_disabled): Closure |
212 | 212 | { |
213 | - return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
213 | + return function(AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
214 | 214 | return $include_disabled || $view->isEnabled(); |
215 | 215 | }; |
216 | 216 | } |
@@ -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 | } |
@@ -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)) |
@@ -31,171 +31,171 @@ |
||
31 | 31 | */ |
32 | 32 | class MapAdapterDataService |
33 | 33 | { |
34 | - private MapDefinitionsService $mapdefinition_service; |
|
34 | + private MapDefinitionsService $mapdefinition_service; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for MapAdapterDataService |
|
38 | - * |
|
39 | - * @param MapDefinitionsService $mapdefinition_service |
|
40 | - */ |
|
41 | - public function __construct(MapDefinitionsService $mapdefinition_service) |
|
42 | - { |
|
43 | - $this->mapdefinition_service = $mapdefinition_service; |
|
44 | - } |
|
36 | + /** |
|
37 | + * Constructor for MapAdapterDataService |
|
38 | + * |
|
39 | + * @param MapDefinitionsService $mapdefinition_service |
|
40 | + */ |
|
41 | + public function __construct(MapDefinitionsService $mapdefinition_service) |
|
42 | + { |
|
43 | + $this->mapdefinition_service = $mapdefinition_service; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Find a GeoAnalysisMapAdapter by ID |
|
48 | - * |
|
49 | - * @param int $id |
|
50 | - * @return GeoAnalysisMapAdapter|NULL |
|
51 | - */ |
|
52 | - public function find(int $id): ?GeoAnalysisMapAdapter |
|
53 | - { |
|
54 | - return DB::table('maj_geodisp_mapviews') |
|
55 | - ->select('maj_geodisp_mapviews.*') |
|
56 | - ->where('majgm_id', '=', $id) |
|
57 | - ->get() |
|
58 | - ->map($this->mapAdapterMapper()) |
|
59 | - ->first(); |
|
60 | - } |
|
46 | + /** |
|
47 | + * Find a GeoAnalysisMapAdapter by ID |
|
48 | + * |
|
49 | + * @param int $id |
|
50 | + * @return GeoAnalysisMapAdapter|NULL |
|
51 | + */ |
|
52 | + public function find(int $id): ?GeoAnalysisMapAdapter |
|
53 | + { |
|
54 | + return DB::table('maj_geodisp_mapviews') |
|
55 | + ->select('maj_geodisp_mapviews.*') |
|
56 | + ->where('majgm_id', '=', $id) |
|
57 | + ->get() |
|
58 | + ->map($this->mapAdapterMapper()) |
|
59 | + ->first(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
64 | - * |
|
65 | - * @param GeoAnalysisMap $map_view |
|
66 | - * @param bool $show_invalid |
|
67 | - * @return Collection<GeoAnalysisMapAdapter|null> |
|
68 | - */ |
|
69 | - public function allForView(GeoAnalysisMap $map_view, bool $show_invalid = false): Collection |
|
70 | - { |
|
71 | - $map_adapters = DB::table('maj_geodisp_mapviews') |
|
72 | - ->select('maj_geodisp_mapviews.*') |
|
73 | - ->where('majgm_majgv_id', '=', $map_view->id()) |
|
74 | - ->get() |
|
75 | - ->map($this->mapAdapterMapper()); |
|
76 | - return $show_invalid ? $map_adapters : $map_adapters->filter(); |
|
77 | - } |
|
62 | + /** |
|
63 | + * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
64 | + * |
|
65 | + * @param GeoAnalysisMap $map_view |
|
66 | + * @param bool $show_invalid |
|
67 | + * @return Collection<GeoAnalysisMapAdapter|null> |
|
68 | + */ |
|
69 | + public function allForView(GeoAnalysisMap $map_view, bool $show_invalid = false): Collection |
|
70 | + { |
|
71 | + $map_adapters = DB::table('maj_geodisp_mapviews') |
|
72 | + ->select('maj_geodisp_mapviews.*') |
|
73 | + ->where('majgm_majgv_id', '=', $map_view->id()) |
|
74 | + ->get() |
|
75 | + ->map($this->mapAdapterMapper()); |
|
76 | + return $show_invalid ? $map_adapters : $map_adapters->filter(); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Insert a GeoAnalysisMapAdapter in the database. |
|
81 | - * |
|
82 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
83 | - * @return int |
|
84 | - */ |
|
85 | - public function insertGetId(GeoAnalysisMapAdapter $map_adapter): int |
|
86 | - { |
|
87 | - return DB::table('maj_geodisp_mapviews') |
|
88 | - ->insertGetId([ |
|
89 | - 'majgm_majgv_id' => $map_adapter->geoAnalysisViewId(), |
|
90 | - 'majgm_map_id' => $map_adapter->map()->id(), |
|
91 | - 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
92 | - 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
93 | - 'majgm_config' => json_encode($map_adapter->viewConfig()->mapperConfig()) |
|
94 | - ]); |
|
95 | - } |
|
79 | + /** |
|
80 | + * Insert a GeoAnalysisMapAdapter in the database. |
|
81 | + * |
|
82 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
83 | + * @return int |
|
84 | + */ |
|
85 | + public function insertGetId(GeoAnalysisMapAdapter $map_adapter): int |
|
86 | + { |
|
87 | + return DB::table('maj_geodisp_mapviews') |
|
88 | + ->insertGetId([ |
|
89 | + 'majgm_majgv_id' => $map_adapter->geoAnalysisViewId(), |
|
90 | + 'majgm_map_id' => $map_adapter->map()->id(), |
|
91 | + 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
92 | + 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
93 | + 'majgm_config' => json_encode($map_adapter->viewConfig()->mapperConfig()) |
|
94 | + ]); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Update a GeoAnalysisMapAdapter in the database. |
|
99 | - * |
|
100 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
101 | - * @return int |
|
102 | - */ |
|
103 | - public function update(GeoAnalysisMapAdapter $map_adapter): int |
|
104 | - { |
|
105 | - return DB::table('maj_geodisp_mapviews') |
|
106 | - ->where('majgm_id', '=', $map_adapter->id()) |
|
107 | - ->update([ |
|
108 | - 'majgm_map_id' => $map_adapter->map()->id(), |
|
109 | - 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
110 | - 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
111 | - 'majgm_config' => json_encode($map_adapter->placeMapper()->config()) |
|
112 | - ]); |
|
113 | - } |
|
97 | + /** |
|
98 | + * Update a GeoAnalysisMapAdapter in the database. |
|
99 | + * |
|
100 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
101 | + * @return int |
|
102 | + */ |
|
103 | + public function update(GeoAnalysisMapAdapter $map_adapter): int |
|
104 | + { |
|
105 | + return DB::table('maj_geodisp_mapviews') |
|
106 | + ->where('majgm_id', '=', $map_adapter->id()) |
|
107 | + ->update([ |
|
108 | + 'majgm_map_id' => $map_adapter->map()->id(), |
|
109 | + 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
110 | + 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
111 | + 'majgm_config' => json_encode($map_adapter->placeMapper()->config()) |
|
112 | + ]); |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Delete a GeoAnalysisMapAdapter from the database. |
|
117 | - * |
|
118 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function delete(GeoAnalysisMapAdapter $map_adapter): int |
|
122 | - { |
|
123 | - return DB::table('maj_geodisp_mapviews') |
|
124 | - ->where('majgm_id', '=', $map_adapter->id()) |
|
125 | - ->delete(); |
|
126 | - } |
|
115 | + /** |
|
116 | + * Delete a GeoAnalysisMapAdapter from the database. |
|
117 | + * |
|
118 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function delete(GeoAnalysisMapAdapter $map_adapter): int |
|
122 | + { |
|
123 | + return DB::table('maj_geodisp_mapviews') |
|
124 | + ->where('majgm_id', '=', $map_adapter->id()) |
|
125 | + ->delete(); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Delete invalid GeoAnalysisMapAdapters from the database. |
|
130 | - * |
|
131 | - * @param AbstractGeoAnalysisView $view |
|
132 | - * @param Collection<int> $valid_map_adapters |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function deleteInvalid(AbstractGeoAnalysisView $view, Collection $valid_map_adapters): int |
|
136 | - { |
|
137 | - return DB::table('maj_geodisp_mapviews') |
|
138 | - ->where('majgm_majgv_id', '=', $view->id()) |
|
139 | - ->whereNotIn('majgm_id', $valid_map_adapters) |
|
140 | - ->delete(); |
|
141 | - } |
|
128 | + /** |
|
129 | + * Delete invalid GeoAnalysisMapAdapters from the database. |
|
130 | + * |
|
131 | + * @param AbstractGeoAnalysisView $view |
|
132 | + * @param Collection<int> $valid_map_adapters |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function deleteInvalid(AbstractGeoAnalysisView $view, Collection $valid_map_adapters): int |
|
136 | + { |
|
137 | + return DB::table('maj_geodisp_mapviews') |
|
138 | + ->where('majgm_majgv_id', '=', $view->id()) |
|
139 | + ->whereNotIn('majgm_id', $valid_map_adapters) |
|
140 | + ->delete(); |
|
141 | + } |
|
142 | 142 | |
143 | - /** |
|
144 | - * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
145 | - * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
146 | - * or if the types do not match with the ones expected. |
|
147 | - * |
|
148 | - * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
149 | - */ |
|
150 | - private function mapAdapterMapper(): Closure |
|
151 | - { |
|
152 | - return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
153 | - if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
154 | - return null; |
|
155 | - } |
|
156 | - try { |
|
157 | - $mapper = app($row->majgm_mapper); |
|
158 | - if (!($mapper instanceof PlaceMapperInterface)) { |
|
159 | - return null; |
|
160 | - } |
|
143 | + /** |
|
144 | + * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
145 | + * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
146 | + * or if the types do not match with the ones expected. |
|
147 | + * |
|
148 | + * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
149 | + */ |
|
150 | + private function mapAdapterMapper(): Closure |
|
151 | + { |
|
152 | + return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
153 | + if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
154 | + return null; |
|
155 | + } |
|
156 | + try { |
|
157 | + $mapper = app($row->majgm_mapper); |
|
158 | + if (!($mapper instanceof PlaceMapperInterface)) { |
|
159 | + return null; |
|
160 | + } |
|
161 | 161 | |
162 | - return new GeoAnalysisMapAdapter( |
|
163 | - (int) $row->majgm_id, |
|
164 | - (int) $row->majgm_majgv_id, |
|
165 | - $map, |
|
166 | - app($row->majgm_mapper), |
|
167 | - new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
168 | - ); |
|
169 | - } catch (BindingResolutionException $ex) { |
|
170 | - return null; |
|
171 | - } |
|
172 | - }; |
|
173 | - } |
|
162 | + return new GeoAnalysisMapAdapter( |
|
163 | + (int) $row->majgm_id, |
|
164 | + (int) $row->majgm_majgv_id, |
|
165 | + $map, |
|
166 | + app($row->majgm_mapper), |
|
167 | + new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
168 | + ); |
|
169 | + } catch (BindingResolutionException $ex) { |
|
170 | + return null; |
|
171 | + } |
|
172 | + }; |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
177 | - * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
178 | - * through the Laravel container or if the type do not match with the one expected. |
|
179 | - * |
|
180 | - * @param string $json_config |
|
181 | - * @return PlaceMapperConfigInterface|NULL |
|
182 | - */ |
|
183 | - private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
184 | - { |
|
185 | - $config = $json_config === null ? [] : json_decode($json_config, true); |
|
186 | - $class = $config['class'] ?? null; |
|
187 | - $json_mapper_config = $config['config'] ?? null; |
|
188 | - if ($class === null || $json_mapper_config === null) { |
|
189 | - return null; |
|
190 | - } |
|
191 | - try { |
|
192 | - $mapper_config = app($class); |
|
193 | - if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
194 | - return null; |
|
195 | - } |
|
196 | - return $mapper_config->jsonDeserialize($json_mapper_config); |
|
197 | - } catch (BindingResolutionException $ex) { |
|
198 | - return null; |
|
199 | - } |
|
200 | - } |
|
175 | + /** |
|
176 | + * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
177 | + * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
178 | + * through the Laravel container or if the type do not match with the one expected. |
|
179 | + * |
|
180 | + * @param string $json_config |
|
181 | + * @return PlaceMapperConfigInterface|NULL |
|
182 | + */ |
|
183 | + private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
184 | + { |
|
185 | + $config = $json_config === null ? [] : json_decode($json_config, true); |
|
186 | + $class = $config['class'] ?? null; |
|
187 | + $json_mapper_config = $config['config'] ?? null; |
|
188 | + if ($class === null || $json_mapper_config === null) { |
|
189 | + return null; |
|
190 | + } |
|
191 | + try { |
|
192 | + $mapper_config = app($class); |
|
193 | + if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
194 | + return null; |
|
195 | + } |
|
196 | + return $mapper_config->jsonDeserialize($json_mapper_config); |
|
197 | + } catch (BindingResolutionException $ex) { |
|
198 | + return null; |
|
199 | + } |
|
200 | + } |
|
201 | 201 | } |
@@ -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,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 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | $title = I18N::translate('Certificates'); |
81 | 81 | |
82 | - $cities = array_map(function (string $item): array { |
|
82 | + $cities = array_map(function(string $item): array { |
|
83 | 83 | return [$this->url_obfuscator_service->obfuscate($item), $item]; |
84 | 84 | }, $this->certif_filesystem->cities($tree)); |
85 | 85 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
91 | 91 | } |
92 | 92 | |
93 | - return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
93 | + return $this->viewResponse($this->module->name().'::certificates-list', [ |
|
94 | 94 | 'title' => $title, |
95 | 95 | 'tree' => $tree, |
96 | 96 | 'module_name' => $this->module->name(), |
@@ -32,63 +32,63 @@ |
||
32 | 32 | */ |
33 | 33 | class CertificatesList implements RequestHandlerInterface |
34 | 34 | { |
35 | - use ViewResponseTrait; |
|
35 | + use ViewResponseTrait; |
|
36 | 36 | |
37 | - private ?CertificatesModule $module; |
|
38 | - private CertificateFilesystemService $certif_filesystem; |
|
39 | - private UrlObfuscatorService $url_obfuscator_service; |
|
37 | + private ?CertificatesModule $module; |
|
38 | + private CertificateFilesystemService $certif_filesystem; |
|
39 | + private UrlObfuscatorService $url_obfuscator_service; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor for CertificatesList Request Handler |
|
43 | - * |
|
44 | - * @param ModuleService $module_service |
|
45 | - */ |
|
46 | - public function __construct( |
|
47 | - ModuleService $module_service, |
|
48 | - CertificateFilesystemService $certif_filesystem, |
|
49 | - UrlObfuscatorService $url_obfuscator_service |
|
50 | - ) { |
|
51 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
52 | - $this->certif_filesystem = $certif_filesystem; |
|
53 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
54 | - } |
|
41 | + /** |
|
42 | + * Constructor for CertificatesList Request Handler |
|
43 | + * |
|
44 | + * @param ModuleService $module_service |
|
45 | + */ |
|
46 | + public function __construct( |
|
47 | + ModuleService $module_service, |
|
48 | + CertificateFilesystemService $certif_filesystem, |
|
49 | + UrlObfuscatorService $url_obfuscator_service |
|
50 | + ) { |
|
51 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
52 | + $this->certif_filesystem = $certif_filesystem; |
|
53 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | - */ |
|
60 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | - { |
|
62 | - if ($this->module === null) { |
|
63 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | - } |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | + */ |
|
60 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | + { |
|
62 | + if ($this->module === null) { |
|
63 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | + } |
|
65 | 65 | |
66 | - $tree = Validator::attributes($request)->tree(); |
|
66 | + $tree = Validator::attributes($request)->tree(); |
|
67 | 67 | |
68 | - $title = I18N::translate('Certificates'); |
|
68 | + $title = I18N::translate('Certificates'); |
|
69 | 69 | |
70 | - $cities = array_map(function (string $item): array { |
|
71 | - return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
72 | - }, $this->certif_filesystem->cities($tree)); |
|
70 | + $cities = array_map(function (string $item): array { |
|
71 | + return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
72 | + }, $this->certif_filesystem->cities($tree)); |
|
73 | 73 | |
74 | - $city = Validator::queryParams($request)->string( |
|
75 | - 'cityobf', |
|
76 | - Validator::attributes($request)->string('cityobf', '') |
|
77 | - ); |
|
74 | + $city = Validator::queryParams($request)->string( |
|
75 | + 'cityobf', |
|
76 | + Validator::attributes($request)->string('cityobf', '') |
|
77 | + ); |
|
78 | 78 | |
79 | - if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
80 | - $title = I18N::translate('Certificates for %s', $city); |
|
81 | - $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
|
82 | - } |
|
79 | + if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
80 | + $title = I18N::translate('Certificates for %s', $city); |
|
81 | + $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
|
82 | + } |
|
83 | 83 | |
84 | - return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
85 | - 'title' => $title, |
|
86 | - 'tree' => $tree, |
|
87 | - 'module_name' => $this->module->name(), |
|
88 | - 'cities' => $cities, |
|
89 | - 'selected_city' => $city, |
|
90 | - 'certificates_list' => $certificates ?? collect(), |
|
91 | - 'url_obfuscator_service' => $this->url_obfuscator_service |
|
92 | - ]); |
|
93 | - } |
|
84 | + return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
85 | + 'title' => $title, |
|
86 | + 'tree' => $tree, |
|
87 | + 'module_name' => $this->module->name(), |
|
88 | + 'cities' => $cities, |
|
89 | + 'selected_city' => $city, |
|
90 | + 'certificates_list' => $certificates ?? collect(), |
|
91 | + 'url_obfuscator_service' => $this->url_obfuscator_service |
|
92 | + ]); |
|
93 | + } |
|
94 | 94 | } |
@@ -87,7 +87,7 @@ |
||
87 | 87 | throw new HttpAccessDeniedException(); |
88 | 88 | } |
89 | 89 | |
90 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
90 | + return $this->viewResponse($this->module->name().'::admin/config', [ |
|
91 | 91 | 'module_name' => $this->module->name(), |
92 | 92 | 'title' => $this->module->title(), |
93 | 93 | 'tree' => $tree, |
@@ -35,56 +35,56 @@ |
||
35 | 35 | */ |
36 | 36 | class AdminConfigPage implements RequestHandlerInterface |
37 | 37 | { |
38 | - use ViewResponseTrait; |
|
38 | + use ViewResponseTrait; |
|
39 | 39 | |
40 | - private ?CertificatesModule $module; |
|
41 | - private TreeService $tree_service; |
|
40 | + private ?CertificatesModule $module; |
|
41 | + private TreeService $tree_service; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor for Admin Config page request handler |
|
45 | - * |
|
46 | - * @param ModuleService $module_service |
|
47 | - */ |
|
48 | - public function __construct(ModuleService $module_service, TreeService $tree_service) |
|
49 | - { |
|
50 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
51 | - $this->tree_service = $tree_service; |
|
52 | - } |
|
43 | + /** |
|
44 | + * Constructor for Admin Config page request handler |
|
45 | + * |
|
46 | + * @param ModuleService $module_service |
|
47 | + */ |
|
48 | + public function __construct(ModuleService $module_service, TreeService $tree_service) |
|
49 | + { |
|
50 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
51 | + $this->tree_service = $tree_service; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
57 | - */ |
|
58 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
59 | - { |
|
60 | - $this->layout = 'layouts/administration'; |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
57 | + */ |
|
58 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
59 | + { |
|
60 | + $this->layout = 'layouts/administration'; |
|
61 | 61 | |
62 | - if ($this->module === null) { |
|
63 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | - } |
|
62 | + if ($this->module === null) { |
|
63 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | + } |
|
65 | 65 | |
66 | - $user = Validator::attributes($request)->user(); |
|
66 | + $user = Validator::attributes($request)->user(); |
|
67 | 67 | |
68 | - $all_trees = $this->tree_service->all()->filter(fn(Tree $tree) => Auth::isManager($tree, $user)); |
|
69 | - if ($all_trees->count() === 0) { |
|
70 | - throw new HttpAccessDeniedException(); |
|
71 | - } |
|
68 | + $all_trees = $this->tree_service->all()->filter(fn(Tree $tree) => Auth::isManager($tree, $user)); |
|
69 | + if ($all_trees->count() === 0) { |
|
70 | + throw new HttpAccessDeniedException(); |
|
71 | + } |
|
72 | 72 | |
73 | - $tree = Validator::attributes($request)->treeOptional('tree') ?? $all_trees->first(); |
|
73 | + $tree = Validator::attributes($request)->treeOptional('tree') ?? $all_trees->first(); |
|
74 | 74 | |
75 | - $data_folder = Registry::filesystem()->dataName(); |
|
75 | + $data_folder = Registry::filesystem()->dataName(); |
|
76 | 76 | |
77 | - $same_tree = fn(Tree $tree_collection): bool => $tree->id() === $tree_collection->id(); |
|
78 | - if (!$all_trees->contains($same_tree)) { |
|
79 | - throw new HttpAccessDeniedException(); |
|
80 | - } |
|
77 | + $same_tree = fn(Tree $tree_collection): bool => $tree->id() === $tree_collection->id(); |
|
78 | + if (!$all_trees->contains($same_tree)) { |
|
79 | + throw new HttpAccessDeniedException(); |
|
80 | + } |
|
81 | 81 | |
82 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
83 | - 'module_name' => $this->module->name(), |
|
84 | - 'title' => $this->module->title(), |
|
85 | - 'tree' => $tree, |
|
86 | - 'other_trees' => $all_trees->reject($same_tree), |
|
87 | - 'data_folder' => $data_folder |
|
88 | - ]); |
|
89 | - } |
|
82 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
83 | + 'module_name' => $this->module->name(), |
|
84 | + 'title' => $this->module->title(), |
|
85 | + 'tree' => $tree, |
|
86 | + 'other_trees' => $all_trees->reject($same_tree), |
|
87 | + 'data_folder' => $data_folder |
|
88 | + ]); |
|
89 | + } |
|
90 | 90 | } |