Passed
Branch feature/2.1-geodispersion-dev (38d49e)
by Jonathan
04:17
created
src/Webtrees/Module/GeoDispersion/Model/MapAdapterResult.php 1 patch
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -24,57 +24,57 @@
 block discarded – undo
24 24
  */
25 25
 class MapAdapterResult
26 26
 {
27
-    private GeoAnalysisResult $result;
27
+	private GeoAnalysisResult $result;
28 28
 
29
-    /**
30
-     * @var \Brick\Geo\IO\GeoJSON\Feature[] $features
31
-     */
32
-    private array $features;
29
+	/**
30
+	 * @var \Brick\Geo\IO\GeoJSON\Feature[] $features
31
+	 */
32
+	private array $features;
33 33
 
34
-    /**
35
-     * Constructor for MapAdapterResult
36
-     *
37
-     * @param GeoAnalysisResult $result
38
-     * @param \Brick\Geo\IO\GeoJSON\Feature[] $features
39
-     */
40
-    final public function __construct(GeoAnalysisResult $result, array $features)
41
-    {
42
-        $this->result = $result;
43
-        $this->features = $features;
44
-    }
34
+	/**
35
+	 * Constructor for MapAdapterResult
36
+	 *
37
+	 * @param GeoAnalysisResult $result
38
+	 * @param \Brick\Geo\IO\GeoJSON\Feature[] $features
39
+	 */
40
+	final public function __construct(GeoAnalysisResult $result, array $features)
41
+	{
42
+		$this->result = $result;
43
+		$this->features = $features;
44
+	}
45 45
 
46
-    /**
47
-     * Get the GeoAnalysisResult after mapping of the places
48
-     *
49
-     * @return GeoAnalysisResult
50
-     */
51
-    public function geoAnalysisResult(): GeoAnalysisResult
52
-    {
53
-        return $this->result;
54
-    }
46
+	/**
47
+	 * Get the GeoAnalysisResult after mapping of the places
48
+	 *
49
+	 * @return GeoAnalysisResult
50
+	 */
51
+	public function geoAnalysisResult(): GeoAnalysisResult
52
+	{
53
+		return $this->result;
54
+	}
55 55
 
56
-    /**
57
-     * Get the list of features to display on the map
58
-     *
59
-     * @return \Brick\Geo\IO\GeoJSON\Feature[]
60
-     */
61
-    public function features(): array
62
-    {
63
-        return $this->features;
64
-    }
56
+	/**
57
+	 * Get the list of features to display on the map
58
+	 *
59
+	 * @return \Brick\Geo\IO\GeoJSON\Feature[]
60
+	 */
61
+	public function features(): array
62
+	{
63
+		return $this->features;
64
+	}
65 65
 
66
-    /**
67
-     * Merge the current MapAdapter with another.
68
-     * The current object is modified, not the second one.
69
-     *
70
-     * @param MapAdapterResult $other
71
-     * @return self
72
-     */
73
-    public function merge(MapAdapterResult $other): self
74
-    {
75
-        return new static(
76
-            $this->result->merge($other->result),
77
-            array_merge($this->features, $other->features)
78
-        );
79
-    }
66
+	/**
67
+	 * Merge the current MapAdapter with another.
68
+	 * The current object is modified, not the second one.
69
+	 *
70
+	 * @param MapAdapterResult $other
71
+	 * @return self
72
+	 */
73
+	public function merge(MapAdapterResult $other): self
74
+	{
75
+		return new static(
76
+			$this->result->merge($other->result),
77
+			array_merge($this->features, $other->features)
78
+		);
79
+	}
80 80
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/Model/MapFeatureAnalysisData.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -22,81 +22,81 @@
 block discarded – undo
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 self
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 self
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 self
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 self
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
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/Model/GeoAnalysisMapAdapter.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                     ->withProperty(
124 124
                         'places',
125 125
                         $feature_data->places()
126
-                            ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
126
+                            ->map(fn(GeoAnalysisPlace $place) : string => $place->place()->firstParts(1)->first())
127 127
                             ->sort(I18N::comparator())
128 128
                             ->toArray()
129 129
                     );
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
         $features_data
136 136
             ->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
137 137
             ->each(
138
-                fn (MapFeatureAnalysisData $data) =>
138
+                fn(MapFeatureAnalysisData $data) =>
139 139
                     $data->places()->each(
140 140
                         fn(GeoAnalysisPlace $place) => $result->exclude($place)
141 141
                     )
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
         $features_mapping = new Collection();
156 156
 
157 157
         $byplaces = $result->knownPlaces();
158
-        $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
158
+        $byplaces->each(function(GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
159 159
             $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
160 160
 
161 161
             if ($id !== null && mb_strlen($id) > 0) {
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
             }
169 169
         });
170 170
 
171
-        return [ $features_mapping, $result];
171
+        return [$features_mapping, $result];
172 172
     }
173 173
 
174 174
     /**
Please login to merge, or discard this patch.
Indentation   +185 added lines, -185 removed lines patch added patch discarded remove patch
@@ -29,189 +29,189 @@
 block discarded – undo
29 29
  */
30 30
 class GeoAnalysisMapAdapter
31 31
 {
32
-    private int $id;
33
-    private int $view_id;
34
-    private MapDefinitionInterface $map;
35
-    private PlaceMapperInterface $place_mapper;
36
-    private MapViewConfigInterface $config;
37
-
38
-    /**
39
-     * Constructor for GeoAnalysisMapAdapter
40
-     *
41
-     * @param int $id
42
-     * @param MapDefinitionInterface $map
43
-     * @param PlaceMapperInterface $mapper
44
-     * @param MapViewConfigInterface $config
45
-     */
46
-    public function __construct(
47
-        int $id,
48
-        int $view_id,
49
-        MapDefinitionInterface $map,
50
-        PlaceMapperInterface $mapper,
51
-        MapViewConfigInterface $config
52
-    ) {
53
-        $this->id = $id;
54
-        $this->view_id = $view_id;
55
-        $this->map = $map;
56
-        $this->place_mapper = $mapper;
57
-        $this->config = $config;
58
-        $this->place_mapper->setConfig($this->config->mapperConfig());
59
-        $this->place_mapper->setData('map', $map);
60
-        $this->place_mapper->boot();
61
-    }
62
-
63
-    /**
64
-     * Create a copy of the GeoAnalysisMapAdapter with new properties.
65
-     *
66
-     * @param MapDefinitionInterface $map
67
-     * @param PlaceMapperInterface $mapper
68
-     * @param string $mapping_property
69
-     * @return self
70
-     */
71
-    public function with(
72
-        MapDefinitionInterface $map,
73
-        PlaceMapperInterface $mapper,
74
-        string $mapping_property
75
-    ): self {
76
-        $new = clone $this;
77
-        $new->map = $map;
78
-        $new->place_mapper = $mapper;
79
-        $new->config = $this->config->with($mapping_property, $mapper->config());
80
-        return $new;
81
-    }
82
-
83
-    /**
84
-     * Get the GeoAnalysisMapAdapter ID
85
-     *
86
-     * @return int
87
-     */
88
-    public function id(): int
89
-    {
90
-        return $this->id;
91
-    }
92
-
93
-    /**
94
-     * Get the ID of the associated GeoAnalysisView
95
-     *
96
-     * @return int
97
-     */
98
-    public function geoAnalysisViewId(): int
99
-    {
100
-        return $this->view_id;
101
-    }
102
-
103
-    /**
104
-     * Get the associated target map
105
-     *
106
-     * @return MapDefinitionInterface
107
-     */
108
-    public function map(): MapDefinitionInterface
109
-    {
110
-        return $this->map;
111
-    }
112
-
113
-    /**
114
-     * Get the Place Mapper used for the mapping
115
-     *
116
-     * @return PlaceMapperInterface
117
-     */
118
-    public function placeMapper(): PlaceMapperInterface
119
-    {
120
-        return $this->place_mapper;
121
-    }
122
-
123
-    /**
124
-     * Get the configuration of the Map View.
125
-     *
126
-     * @return MapViewConfigInterface
127
-     */
128
-    public function viewConfig(): MapViewConfigInterface
129
-    {
130
-        return $this->config;
131
-    }
132
-
133
-    /**
134
-     * Convert the geographical analysis result to a MapAdapter result for usage in the Map View
135
-     *
136
-     * @param GeoAnalysisResult $result
137
-     * @return MapAdapterResult
138
-     */
139
-    public function convert(GeoAnalysisResult $result): MapAdapterResult
140
-    {
141
-        $result = $result->copy();
142
-
143
-        $features = [];
144
-        list($features_data, $result) = $this->featureAnalysisData($result);
145
-
146
-        $places_found = $result->countFound();
147
-        foreach ($this->map->features() as $feature) {
148
-            $feature_id = $this->featureId($feature);
149
-            if ($feature_id !== null && $features_data->has($feature_id)) {
150
-                /** @var MapFeatureAnalysisData $feature_data */
151
-                $feature_data = $features_data->get($feature_id)->tagAsExisting();
152
-                $place_count = $feature_data->count();
153
-                $features[] = $feature
154
-                    ->withProperty('count', $place_count)
155
-                    ->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0)
156
-                    ->withProperty(
157
-                        'places',
158
-                        $feature_data->places()
159
-                            ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
160
-                            ->sort(I18N::comparator())
161
-                            ->toArray()
162
-                    );
163
-            } else {
164
-                $features[] = $feature;
165
-            }
166
-        }
167
-
168
-        $features_data
169
-            ->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
170
-            ->each(
171
-                fn (MapFeatureAnalysisData $data) =>
172
-                    $data->places()->each(
173
-                        fn(GeoAnalysisPlace $place) => $result->exclude($place)
174
-                    )
175
-            );
176
-
177
-        return new MapAdapterResult($result, $features);
178
-    }
179
-
180
-    /**
181
-     * Populate the map features with the mapped Places and total count
182
-     *
183
-     * @param GeoAnalysisResult $result
184
-     * @return array
185
-     */
186
-    protected function featureAnalysisData(GeoAnalysisResult $result): array
187
-    {
188
-        $features_mapping = new Collection();
189
-
190
-        $byplaces = $result->knownPlaces();
191
-        $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
192
-            $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
193
-
194
-            if ($id !== null && mb_strlen($id) > 0) {
195
-                $features_mapping->put(
196
-                    $id,
197
-                    $features_mapping->get($id, new MapFeatureAnalysisData($id))->add($item->place(), $item->count())
198
-                );
199
-            } else {
200
-                $result->exclude($item->place());
201
-            }
202
-        });
203
-
204
-        return [ $features_mapping, $result];
205
-    }
206
-
207
-    /**
208
-     * Get the value of the feature property used for the mapping
209
-     *
210
-     * @param Feature $feature
211
-     * @return string|NULL
212
-     */
213
-    protected function featureId(Feature $feature): ?string
214
-    {
215
-        return $feature->getProperty($this->config->mapMappingProperty());
216
-    }
32
+	private int $id;
33
+	private int $view_id;
34
+	private MapDefinitionInterface $map;
35
+	private PlaceMapperInterface $place_mapper;
36
+	private MapViewConfigInterface $config;
37
+
38
+	/**
39
+	 * Constructor for GeoAnalysisMapAdapter
40
+	 *
41
+	 * @param int $id
42
+	 * @param MapDefinitionInterface $map
43
+	 * @param PlaceMapperInterface $mapper
44
+	 * @param MapViewConfigInterface $config
45
+	 */
46
+	public function __construct(
47
+		int $id,
48
+		int $view_id,
49
+		MapDefinitionInterface $map,
50
+		PlaceMapperInterface $mapper,
51
+		MapViewConfigInterface $config
52
+	) {
53
+		$this->id = $id;
54
+		$this->view_id = $view_id;
55
+		$this->map = $map;
56
+		$this->place_mapper = $mapper;
57
+		$this->config = $config;
58
+		$this->place_mapper->setConfig($this->config->mapperConfig());
59
+		$this->place_mapper->setData('map', $map);
60
+		$this->place_mapper->boot();
61
+	}
62
+
63
+	/**
64
+	 * Create a copy of the GeoAnalysisMapAdapter with new properties.
65
+	 *
66
+	 * @param MapDefinitionInterface $map
67
+	 * @param PlaceMapperInterface $mapper
68
+	 * @param string $mapping_property
69
+	 * @return self
70
+	 */
71
+	public function with(
72
+		MapDefinitionInterface $map,
73
+		PlaceMapperInterface $mapper,
74
+		string $mapping_property
75
+	): self {
76
+		$new = clone $this;
77
+		$new->map = $map;
78
+		$new->place_mapper = $mapper;
79
+		$new->config = $this->config->with($mapping_property, $mapper->config());
80
+		return $new;
81
+	}
82
+
83
+	/**
84
+	 * Get the GeoAnalysisMapAdapter ID
85
+	 *
86
+	 * @return int
87
+	 */
88
+	public function id(): int
89
+	{
90
+		return $this->id;
91
+	}
92
+
93
+	/**
94
+	 * Get the ID of the associated GeoAnalysisView
95
+	 *
96
+	 * @return int
97
+	 */
98
+	public function geoAnalysisViewId(): int
99
+	{
100
+		return $this->view_id;
101
+	}
102
+
103
+	/**
104
+	 * Get the associated target map
105
+	 *
106
+	 * @return MapDefinitionInterface
107
+	 */
108
+	public function map(): MapDefinitionInterface
109
+	{
110
+		return $this->map;
111
+	}
112
+
113
+	/**
114
+	 * Get the Place Mapper used for the mapping
115
+	 *
116
+	 * @return PlaceMapperInterface
117
+	 */
118
+	public function placeMapper(): PlaceMapperInterface
119
+	{
120
+		return $this->place_mapper;
121
+	}
122
+
123
+	/**
124
+	 * Get the configuration of the Map View.
125
+	 *
126
+	 * @return MapViewConfigInterface
127
+	 */
128
+	public function viewConfig(): MapViewConfigInterface
129
+	{
130
+		return $this->config;
131
+	}
132
+
133
+	/**
134
+	 * Convert the geographical analysis result to a MapAdapter result for usage in the Map View
135
+	 *
136
+	 * @param GeoAnalysisResult $result
137
+	 * @return MapAdapterResult
138
+	 */
139
+	public function convert(GeoAnalysisResult $result): MapAdapterResult
140
+	{
141
+		$result = $result->copy();
142
+
143
+		$features = [];
144
+		list($features_data, $result) = $this->featureAnalysisData($result);
145
+
146
+		$places_found = $result->countFound();
147
+		foreach ($this->map->features() as $feature) {
148
+			$feature_id = $this->featureId($feature);
149
+			if ($feature_id !== null && $features_data->has($feature_id)) {
150
+				/** @var MapFeatureAnalysisData $feature_data */
151
+				$feature_data = $features_data->get($feature_id)->tagAsExisting();
152
+				$place_count = $feature_data->count();
153
+				$features[] = $feature
154
+					->withProperty('count', $place_count)
155
+					->withProperty('ratio', $places_found > 0 ? $place_count / $places_found : 0)
156
+					->withProperty(
157
+						'places',
158
+						$feature_data->places()
159
+							->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first())
160
+							->sort(I18N::comparator())
161
+							->toArray()
162
+					);
163
+			} else {
164
+				$features[] = $feature;
165
+			}
166
+		}
167
+
168
+		$features_data
169
+			->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap())
170
+			->each(
171
+				fn (MapFeatureAnalysisData $data) =>
172
+					$data->places()->each(
173
+						fn(GeoAnalysisPlace $place) => $result->exclude($place)
174
+					)
175
+			);
176
+
177
+		return new MapAdapterResult($result, $features);
178
+	}
179
+
180
+	/**
181
+	 * Populate the map features with the mapped Places and total count
182
+	 *
183
+	 * @param GeoAnalysisResult $result
184
+	 * @return array
185
+	 */
186
+	protected function featureAnalysisData(GeoAnalysisResult $result): array
187
+	{
188
+		$features_mapping = new Collection();
189
+
190
+		$byplaces = $result->knownPlaces();
191
+		$byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void {
192
+			$id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty());
193
+
194
+			if ($id !== null && mb_strlen($id) > 0) {
195
+				$features_mapping->put(
196
+					$id,
197
+					$features_mapping->get($id, new MapFeatureAnalysisData($id))->add($item->place(), $item->count())
198
+				);
199
+			} else {
200
+				$result->exclude($item->place());
201
+			}
202
+		});
203
+
204
+		return [ $features_mapping, $result];
205
+	}
206
+
207
+	/**
208
+	 * Get the value of the feature property used for the mapping
209
+	 *
210
+	 * @param Feature $feature
211
+	 * @return string|NULL
212
+	 */
213
+	protected function featureId(Feature $feature): ?string
214
+	{
215
+		return $feature->getProperty($this->config->mapMappingProperty());
216
+	}
217 217
 }
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewTabs.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@
 block discarded – undo
60 60
         assert($tree instanceof Tree);
61 61
 
62 62
         $view_id = $request->getAttribute('view_id');
63
-        $view_id = is_numeric($view_id) ? (int) $view_id : 0;
63
+        $view_id = is_numeric($view_id) ? (int)$view_id : 0;
64 64
 
65 65
         $view = $this->geoviewdata_service->find($tree, $view_id);
66 66
 
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -30,61 +30,61 @@
 block discarded – undo
30 30
  */
31 31
 class GeoAnalysisViewTabs implements RequestHandlerInterface
32 32
 {
33
-    private ?GeoDispersionModule $module;
34
-    private GeoAnalysisViewDataService $geoviewdata_service;
33
+	private ?GeoDispersionModule $module;
34
+	private GeoAnalysisViewDataService $geoviewdata_service;
35 35
 
36
-    /**
37
-     * Constructor for GeoAnalysisMapsList Request Handler
38
-     *
39
-     * @param ModuleService $module_service
40
-     */
41
-    public function __construct(
42
-        ModuleService $module_service,
43
-        GeoAnalysisViewDataService $geoviewdata_service
44
-    ) {
45
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
46
-        $this->geoviewdata_service = $geoviewdata_service;
47
-    }
36
+	/**
37
+	 * Constructor for GeoAnalysisMapsList Request Handler
38
+	 *
39
+	 * @param ModuleService $module_service
40
+	 */
41
+	public function __construct(
42
+		ModuleService $module_service,
43
+		GeoAnalysisViewDataService $geoviewdata_service
44
+	) {
45
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
46
+		$this->geoviewdata_service = $geoviewdata_service;
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritDoc}
51
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
-     */
53
-    public function handle(ServerRequestInterface $request): ResponseInterface
54
-    {
55
-        if ($this->module === null) {
56
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
57
-        }
49
+	/**
50
+	 * {@inheritDoc}
51
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
+	 */
53
+	public function handle(ServerRequestInterface $request): ResponseInterface
54
+	{
55
+		if ($this->module === null) {
56
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
57
+		}
58 58
 
59
-        $tree = $request->getAttribute('tree');
60
-        assert($tree instanceof Tree);
59
+		$tree = $request->getAttribute('tree');
60
+		assert($tree instanceof Tree);
61 61
 
62
-        $view_id = $request->getAttribute('view_id');
63
-        $view_id = is_numeric($view_id) ? (int) $view_id : 0;
62
+		$view_id = $request->getAttribute('view_id');
63
+		$view_id = is_numeric($view_id) ? (int) $view_id : 0;
64 64
 
65
-        $view = $this->geoviewdata_service->find($tree, $view_id);
65
+		$view = $this->geoviewdata_service->find($tree, $view_id);
66 66
 
67
-        if ($view === null) {
68
-            throw new HttpNotFoundException(I18N::translate('The requested dispersion analysis does not exist.'));
69
-        }
67
+		if ($view === null) {
68
+			throw new HttpNotFoundException(I18N::translate('The requested dispersion analysis does not exist.'));
69
+		}
70 70
 
71
-        $results = $view->analysis()->results($tree, $view->placesDepth());
71
+		$results = $view->analysis()->results($tree, $view->placesDepth());
72 72
 
73
-        $params = [
74
-            'module_name'   =>  $this->module->name(),
75
-            'tree'          =>  $tree,
76
-            'view'          =>  $view,
77
-            'items_descr'   =>  $view->analysis()->itemsDescription()
78
-        ];
79
-        $response = [
80
-            'global'    =>  view('layouts/ajax', [
81
-                'content' =>    $view->globalTabContent($this->module, $results->global(), $params)
82
-            ]),
83
-            'detailed'  => view('layouts/ajax', [
84
-                'content' =>    $view->detailedTabContent($this->module, $results->sortedDetailed(), $params)
85
-            ])
86
-        ];
73
+		$params = [
74
+			'module_name'   =>  $this->module->name(),
75
+			'tree'          =>  $tree,
76
+			'view'          =>  $view,
77
+			'items_descr'   =>  $view->analysis()->itemsDescription()
78
+		];
79
+		$response = [
80
+			'global'    =>  view('layouts/ajax', [
81
+				'content' =>    $view->globalTabContent($this->module, $results->global(), $params)
82
+			]),
83
+			'detailed'  => view('layouts/ajax', [
84
+				'content' =>    $view->detailedTabContent($this->module, $results->sortedDetailed(), $params)
85
+			])
86
+		];
87 87
 
88
-        return response($response);
89
-    }
88
+		return response($response);
89
+	}
90 90
 }
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewsList.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -32,47 +32,47 @@
 block discarded – undo
32 32
  */
33 33
 class GeoAnalysisViewsList implements RequestHandlerInterface
34 34
 {
35
-    use ViewResponseTrait;
35
+	use ViewResponseTrait;
36 36
 
37
-    private ?GeoDispersionModule $module;
38
-    private GeoAnalysisViewDataService $geoviewdata_service;
37
+	private ?GeoDispersionModule $module;
38
+	private GeoAnalysisViewDataService $geoviewdata_service;
39 39
 
40
-    /**
41
-     * Constructor for GeoAnalysisViewsList Request Handler
42
-     *
43
-     * @param ModuleService $module_service
44
-     */
45
-    public function __construct(
46
-        ModuleService $module_service,
47
-        GeoAnalysisViewDataService $geoviewdata_service
48
-    ) {
49
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
50
-        $this->geoviewdata_service = $geoviewdata_service;
51
-    }
40
+	/**
41
+	 * Constructor for GeoAnalysisViewsList Request Handler
42
+	 *
43
+	 * @param ModuleService $module_service
44
+	 */
45
+	public function __construct(
46
+		ModuleService $module_service,
47
+		GeoAnalysisViewDataService $geoviewdata_service
48
+	) {
49
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
50
+		$this->geoviewdata_service = $geoviewdata_service;
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritDoc}
55
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
-     */
57
-    public function handle(ServerRequestInterface $request): ResponseInterface
58
-    {
59
-        if ($this->module === null) {
60
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
-        }
53
+	/**
54
+	 * {@inheritDoc}
55
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
+	 */
57
+	public function handle(ServerRequestInterface $request): ResponseInterface
58
+	{
59
+		if ($this->module === null) {
60
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
+		}
62 62
 
63
-        $tree = $request->getAttribute('tree');
64
-        assert($tree instanceof Tree);
63
+		$tree = $request->getAttribute('tree');
64
+		assert($tree instanceof Tree);
65 65
 
66
-        $views_list = $this->geoviewdata_service
67
-            ->all($tree)
68
-            ->sortBy(fn(AbstractGeoAnalysisView $view) => $view->description());
66
+		$views_list = $this->geoviewdata_service
67
+			->all($tree)
68
+			->sortBy(fn(AbstractGeoAnalysisView $view) => $view->description());
69 69
 
70
-        return $this->viewResponse($this->module->name() . '::geoanalysisviews-list', [
71
-            'module'        =>  $this->module,
72
-            'title'         =>  I18N::translate('Geographical dispersion'),
73
-            'tree'          =>  $tree,
74
-            'views_list'    =>  $views_list,
75
-            'js_script_url' =>  $this->module->assetUrl('js/geodispersion.min.js')
76
-        ]);
77
-    }
70
+		return $this->viewResponse($this->module->name() . '::geoanalysisviews-list', [
71
+			'module'        =>  $this->module,
72
+			'title'         =>  I18N::translate('Geographical dispersion'),
73
+			'tree'          =>  $tree,
74
+			'views_list'    =>  $views_list,
75
+			'js_script_url' =>  $this->module->assetUrl('js/geodispersion.min.js')
76
+		]);
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@
 block discarded – undo
67 67
             ->all($tree)
68 68
             ->sortBy(fn(AbstractGeoAnalysisView $view) => $view->description());
69 69
 
70
-        return $this->viewResponse($this->module->name() . '::geoanalysisviews-list', [
70
+        return $this->viewResponse($this->module->name().'::geoanalysisviews-list', [
71 71
             'module'        =>  $this->module,
72 72
             'title'         =>  I18N::translate('Geographical dispersion'),
73 73
             'tree'          =>  $tree,
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/Http/RequestHandlers/GeoAnalysisViewPage.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -31,45 +31,45 @@
 block discarded – undo
31 31
  */
32 32
 class GeoAnalysisViewPage implements RequestHandlerInterface
33 33
 {
34
-    use ViewResponseTrait;
34
+	use ViewResponseTrait;
35 35
 
36
-    private ?GeoDispersionModule $module;
37
-    private GeoAnalysisViewDataService $geoviewdata_service;
36
+	private ?GeoDispersionModule $module;
37
+	private GeoAnalysisViewDataService $geoviewdata_service;
38 38
 
39
-    /**
40
-     * Constructor for GeoAnalysisViewPage Request Handler
41
-     *
42
-     * @param ModuleService $module_service
43
-     */
44
-    public function __construct(
45
-        ModuleService $module_service,
46
-        GeoAnalysisViewDataService $geoviewdata_service
47
-    ) {
48
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
49
-        $this->geoviewdata_service = $geoviewdata_service;
50
-    }
39
+	/**
40
+	 * Constructor for GeoAnalysisViewPage Request Handler
41
+	 *
42
+	 * @param ModuleService $module_service
43
+	 */
44
+	public function __construct(
45
+		ModuleService $module_service,
46
+		GeoAnalysisViewDataService $geoviewdata_service
47
+	) {
48
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
49
+		$this->geoviewdata_service = $geoviewdata_service;
50
+	}
51 51
 
52
-    /**
53
-     * {@inheritDoc}
54
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
55
-     */
56
-    public function handle(ServerRequestInterface $request): ResponseInterface
57
-    {
58
-        if ($this->module === null) {
59
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
-        }
52
+	/**
53
+	 * {@inheritDoc}
54
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
55
+	 */
56
+	public function handle(ServerRequestInterface $request): ResponseInterface
57
+	{
58
+		if ($this->module === null) {
59
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
+		}
61 61
 
62
-        $tree = $request->getAttribute('tree');
63
-        assert($tree instanceof Tree);
62
+		$tree = $request->getAttribute('tree');
63
+		assert($tree instanceof Tree);
64 64
 
65
-        $view_id = $request->getAttribute('view_id');
66
-        $view_id = is_numeric($view_id) ? (int) $view_id : 0;
65
+		$view_id = $request->getAttribute('view_id');
66
+		$view_id = is_numeric($view_id) ? (int) $view_id : 0;
67 67
 
68
-        return $this->viewResponse($this->module->name() . '::geoanalysisview-page', [
69
-            'module_name'           =>  $this->module->name(),
70
-            'title'                 =>  I18N::translate('Geographical dispersion'),
71
-            'tree'                  =>  $tree,
72
-            'view'                  =>  $this->geoviewdata_service->find($tree, $view_id)
73
-        ]);
74
-    }
68
+		return $this->viewResponse($this->module->name() . '::geoanalysisview-page', [
69
+			'module_name'           =>  $this->module->name(),
70
+			'title'                 =>  I18N::translate('Geographical dispersion'),
71
+			'tree'                  =>  $tree,
72
+			'view'                  =>  $this->geoviewdata_service->find($tree, $view_id)
73
+		]);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@
 block discarded – undo
63 63
         assert($tree instanceof Tree);
64 64
 
65 65
         $view_id = $request->getAttribute('view_id');
66
-        $view_id = is_numeric($view_id) ? (int) $view_id : 0;
66
+        $view_id = is_numeric($view_id) ? (int)$view_id : 0;
67 67
 
68
-        return $this->viewResponse($this->module->name() . '::geoanalysisview-page', [
68
+        return $this->viewResponse($this->module->name().'::geoanalysisview-page', [
69 69
             'module_name'           =>  $this->module->name(),
70 70
             'title'                 =>  I18N::translate('Geographical dispersion'),
71 71
             'tree'                  =>  $tree,
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/PlaceMappers/CoordinatesPlaceMapper.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         if ($cacheKey === null) {
126 126
             return null;
127 127
         }
128
-        return Registry::cache()->array()->remember($cacheKey, function (): ?array {
128
+        return Registry::cache()->array()->remember($cacheKey, function(): ?array {
129 129
             $map_def = $this->data('map');
130 130
             if (
131 131
                 !$this->setGeometryEngine()
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
             if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) {
202 202
                 return null;
203 203
             }
204
-            return spl_object_id($this) . '-map-' . $map_def->id();
204
+            return spl_object_id($this).'-map-'.$map_def->id();
205 205
         }
206 206
         return $this->cache_key;
207 207
     }
Please login to merge, or discard this patch.
Indentation   +179 added lines, -179 removed lines patch added patch discarded remove patch
@@ -36,183 +36,183 @@
 block discarded – undo
36 36
  */
37 37
 class CoordinatesPlaceMapper implements PlaceMapperInterface
38 38
 {
39
-    use PlaceMapperTrait;
40
-
41
-    private ?string $cache_key = null;
42
-
43
-    /**
44
-     * {@inheritDoc}
45
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title()
46
-     */
47
-    public function title(): string
48
-    {
49
-        return I18N::translate('Mapping on place coordinates');
50
-    }
51
-
52
-    /**
53
-     * {@inheritDoc}
54
-     *
55
-     * {@internal The Place is associated to a Point only.
56
-     * PlaceLocation can calculate a BoundingBox.
57
-     * Using a BoundingBox could make the mapping more complex and potentially arbitary.
58
-     * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents.
59
-     * This could create the unwanted side effect of a very large area to consider}
60
-     *
61
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
62
-     */
63
-    public function map(Place $place, string $feature_property): ?string
64
-    {
65
-        $location = new PlaceLocation($place->gedcomName());
66
-        $longitude = $location->longitude();
67
-        $latitude = $location->latitude();
68
-        if ($longitude === null || $latitude === null) {
69
-            return null;
70
-        }
71
-
72
-        $features_index = $this->featuresIndex();
73
-        if ($features_index === null) {
74
-            return null;
75
-        }
76
-
77
-        $place_point = Point::xy($longitude, $latitude, $features_index['SRID']);
78
-        $grid_box = $this->getGridCell(
79
-            $place_point,
80
-            $features_index['map_NE'],
81
-            $features_index['map_SW'],
82
-            $features_index['nb_columns']
83
-        );
84
-        if ($grid_box === null || !$this->setGeometryEngine()) {
85
-            return null;
86
-        }
87
-        $features = $features_index['grid'][$grid_box[0]][$grid_box[1]];
88
-        foreach ($features as $feature) {
89
-            $geometry = $feature->getGeometry();
90
-            if ($place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) {
91
-                return $feature->getProperty($feature_property);
92
-            }
93
-        }
94
-        return null;
95
-    }
96
-
97
-    /**
98
-     * Return the XY coordinates in a bounded grid of the cell containing a specific point.
99
-     *
100
-     * @param Point $point Point to find
101
-     * @param Point $grid_NE North-East point of the bounded grid
102
-     * @param Point $grid_SW South-West point fo the bounded grid
103
-     * @param int $grid_columns Number of columns/rows in the grid
104
-     * @return array|NULL
105
-     */
106
-    protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array
107
-    {
108
-        list($x, $y) = $point->toArray();
109
-        list($x_max, $y_max) = $grid_NE->toArray();
110
-        list($x_min, $y_min) = $grid_SW->toArray();
111
-
112
-        $x_step = ($x_max - $x_min) / $grid_columns;
113
-        $y_step = ($y_max - $y_min) / $grid_columns;
114
-
115
-        if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) {
116
-            return [
117
-                $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step),
118
-                $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step)
119
-            ];
120
-        }
121
-        return null;
122
-    }
123
-
124
-    /**
125
-     * Get an indexed array of the features of the map.
126
-     *
127
-     * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell.
128
-     * The grid is computed once for each map, and cached.}
129
-     *
130
-     * @return array|NULL
131
-     */
132
-    protected function featuresIndex(): ?array
133
-    {
134
-        $cacheKey = $this->cacheKey();
135
-        if ($cacheKey === null) {
136
-            return null;
137
-        }
138
-        return Registry::cache()->array()->remember($cacheKey, function (): ?array {
139
-            $map_def = $this->data('map');
140
-            if (
141
-                !$this->setGeometryEngine()
142
-                || $map_def === null
143
-                || !($map_def instanceof MapDefinitionInterface)
144
-            ) {
145
-                return null;
146
-            }
147
-            $bounding_boxes = [];
148
-            $map_bounding_box = new BoundingBox();
149
-            $srid = 0;
150
-            foreach ($map_def->features() as $feature) {
151
-                $geometry = $feature->getGeometry();
152
-                if ($geometry === null) {
153
-                    continue;
154
-                }
155
-                $srid = $geometry->SRID();
156
-                $bounding_box = $geometry->getBoundingBox();
157
-                $bounding_boxes[] = [$feature, $bounding_box];
158
-                $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box);
159
-            }
160
-            $grid_columns = count($bounding_boxes);
161
-            $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, []));
162
-            $map_NE = $map_bounding_box->getNorthEast();
163
-            $map_SW = $map_bounding_box->getSouthWest();
164
-            foreach ($bounding_boxes as $item) {
165
-                $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1];
166
-                $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0];
167
-                for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) {
168
-                    for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) {
169
-                        $grid[$i][$j][] = $item[0];
170
-                    }
171
-                }
172
-            }
173
-            return [
174
-                'grid'          =>  $grid,
175
-                'nb_columns'    =>  $grid_columns,
176
-                'map_NE'        =>  $map_NE,
177
-                'map_SW'        =>  $map_SW,
178
-                'SRID'          =>  $srid
179
-            ];
180
-        });
181
-    }
182
-
183
-    /**
184
-     * Set the Brick Geo Engine to use the database for geospatial computations.
185
-     * The engine is set only if it has not been set beforehand.
186
-     *
187
-     * @return bool
188
-     */
189
-    protected function setGeometryEngine(): bool
190
-    {
191
-        try {
192
-            if (!GeometryEngineRegistry::has()) {
193
-                GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo()));
194
-            }
195
-            $point = Point::xy(1, 1);
196
-            return $point->equals($point);
197
-        } catch (Throwable $ex) {
198
-        }
199
-        return false;
200
-    }
201
-
202
-    /**
203
-     * Get the key to cache the indexed grid of features.
204
-     *
205
-     * @return string|NULL
206
-     */
207
-    protected function cacheKey(): ?string
208
-    {
209
-        if ($this->cache_key === null) {
210
-            $map_def = $this->data('map');
211
-            if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) {
212
-                return null;
213
-            }
214
-            return spl_object_id($this) . '-map-' . $map_def->id();
215
-        }
216
-        return $this->cache_key;
217
-    }
39
+	use PlaceMapperTrait;
40
+
41
+	private ?string $cache_key = null;
42
+
43
+	/**
44
+	 * {@inheritDoc}
45
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title()
46
+	 */
47
+	public function title(): string
48
+	{
49
+		return I18N::translate('Mapping on place coordinates');
50
+	}
51
+
52
+	/**
53
+	 * {@inheritDoc}
54
+	 *
55
+	 * {@internal The Place is associated to a Point only.
56
+	 * PlaceLocation can calculate a BoundingBox.
57
+	 * Using a BoundingBox could make the mapping more complex and potentially arbitary.
58
+	 * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents.
59
+	 * This could create the unwanted side effect of a very large area to consider}
60
+	 *
61
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map()
62
+	 */
63
+	public function map(Place $place, string $feature_property): ?string
64
+	{
65
+		$location = new PlaceLocation($place->gedcomName());
66
+		$longitude = $location->longitude();
67
+		$latitude = $location->latitude();
68
+		if ($longitude === null || $latitude === null) {
69
+			return null;
70
+		}
71
+
72
+		$features_index = $this->featuresIndex();
73
+		if ($features_index === null) {
74
+			return null;
75
+		}
76
+
77
+		$place_point = Point::xy($longitude, $latitude, $features_index['SRID']);
78
+		$grid_box = $this->getGridCell(
79
+			$place_point,
80
+			$features_index['map_NE'],
81
+			$features_index['map_SW'],
82
+			$features_index['nb_columns']
83
+		);
84
+		if ($grid_box === null || !$this->setGeometryEngine()) {
85
+			return null;
86
+		}
87
+		$features = $features_index['grid'][$grid_box[0]][$grid_box[1]];
88
+		foreach ($features as $feature) {
89
+			$geometry = $feature->getGeometry();
90
+			if ($place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) {
91
+				return $feature->getProperty($feature_property);
92
+			}
93
+		}
94
+		return null;
95
+	}
96
+
97
+	/**
98
+	 * Return the XY coordinates in a bounded grid of the cell containing a specific point.
99
+	 *
100
+	 * @param Point $point Point to find
101
+	 * @param Point $grid_NE North-East point of the bounded grid
102
+	 * @param Point $grid_SW South-West point fo the bounded grid
103
+	 * @param int $grid_columns Number of columns/rows in the grid
104
+	 * @return array|NULL
105
+	 */
106
+	protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array
107
+	{
108
+		list($x, $y) = $point->toArray();
109
+		list($x_max, $y_max) = $grid_NE->toArray();
110
+		list($x_min, $y_min) = $grid_SW->toArray();
111
+
112
+		$x_step = ($x_max - $x_min) / $grid_columns;
113
+		$y_step = ($y_max - $y_min) / $grid_columns;
114
+
115
+		if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) {
116
+			return [
117
+				$x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step),
118
+				$y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step)
119
+			];
120
+		}
121
+		return null;
122
+	}
123
+
124
+	/**
125
+	 * Get an indexed array of the features of the map.
126
+	 *
127
+	 * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell.
128
+	 * The grid is computed once for each map, and cached.}
129
+	 *
130
+	 * @return array|NULL
131
+	 */
132
+	protected function featuresIndex(): ?array
133
+	{
134
+		$cacheKey = $this->cacheKey();
135
+		if ($cacheKey === null) {
136
+			return null;
137
+		}
138
+		return Registry::cache()->array()->remember($cacheKey, function (): ?array {
139
+			$map_def = $this->data('map');
140
+			if (
141
+				!$this->setGeometryEngine()
142
+				|| $map_def === null
143
+				|| !($map_def instanceof MapDefinitionInterface)
144
+			) {
145
+				return null;
146
+			}
147
+			$bounding_boxes = [];
148
+			$map_bounding_box = new BoundingBox();
149
+			$srid = 0;
150
+			foreach ($map_def->features() as $feature) {
151
+				$geometry = $feature->getGeometry();
152
+				if ($geometry === null) {
153
+					continue;
154
+				}
155
+				$srid = $geometry->SRID();
156
+				$bounding_box = $geometry->getBoundingBox();
157
+				$bounding_boxes[] = [$feature, $bounding_box];
158
+				$map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box);
159
+			}
160
+			$grid_columns = count($bounding_boxes);
161
+			$grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, []));
162
+			$map_NE = $map_bounding_box->getNorthEast();
163
+			$map_SW = $map_bounding_box->getSouthWest();
164
+			foreach ($bounding_boxes as $item) {
165
+				$grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1];
166
+				$grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0];
167
+				for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) {
168
+					for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) {
169
+						$grid[$i][$j][] = $item[0];
170
+					}
171
+				}
172
+			}
173
+			return [
174
+				'grid'          =>  $grid,
175
+				'nb_columns'    =>  $grid_columns,
176
+				'map_NE'        =>  $map_NE,
177
+				'map_SW'        =>  $map_SW,
178
+				'SRID'          =>  $srid
179
+			];
180
+		});
181
+	}
182
+
183
+	/**
184
+	 * Set the Brick Geo Engine to use the database for geospatial computations.
185
+	 * The engine is set only if it has not been set beforehand.
186
+	 *
187
+	 * @return bool
188
+	 */
189
+	protected function setGeometryEngine(): bool
190
+	{
191
+		try {
192
+			if (!GeometryEngineRegistry::has()) {
193
+				GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo()));
194
+			}
195
+			$point = Point::xy(1, 1);
196
+			return $point->equals($point);
197
+		} catch (Throwable $ex) {
198
+		}
199
+		return false;
200
+	}
201
+
202
+	/**
203
+	 * Get the key to cache the indexed grid of features.
204
+	 *
205
+	 * @return string|NULL
206
+	 */
207
+	protected function cacheKey(): ?string
208
+	{
209
+		if ($this->cache_key === null) {
210
+			$map_def = $this->data('map');
211
+			if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) {
212
+				return null;
213
+			}
214
+			return spl_object_id($this) . '-map-' . $map_def->id();
215
+		}
216
+		return $this->cache_key;
217
+	}
218 218
 }
Please login to merge, or discard this patch.
Webtrees/Module/GeoDispersion/PlaceMappers/TopFilteredPlaceMapperTrait.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -21,65 +21,65 @@
 block discarded – undo
21 21
  */
22 22
 trait TopFilteredPlaceMapperTrait
23 23
 {
24
-    /**
25
-     * @var Place[] $top_places
26
-     */
27
-    private array $top_places = [];
24
+	/**
25
+	 * @var Place[] $top_places
26
+	 */
27
+	private array $top_places = [];
28 28
 
29
-    /**
30
-     * Get the list of top level places.
31
-     *
32
-     * @return Place[]
33
-     */
34
-    public function topPlaces(): array
35
-    {
36
-        return $this->top_places;
37
-    }
29
+	/**
30
+	 * Get the list of top level places.
31
+	 *
32
+	 * @return Place[]
33
+	 */
34
+	public function topPlaces(): array
35
+	{
36
+		return $this->top_places;
37
+	}
38 38
 
39
-    /**
40
-     * Set the list of defined top level places.
41
-     *
42
-     * @param array $top_places
43
-     */
44
-    public function setTopPlaces(array $top_places): void
45
-    {
46
-        $this->top_places = collect($top_places)
47
-            ->filter(
48
-                /** @psalm-suppress MissingClosureParamType */
49
-                fn($top_places) => $top_places instanceof Place
50
-            )->toArray();
51
-    }
39
+	/**
40
+	 * Set the list of defined top level places.
41
+	 *
42
+	 * @param array $top_places
43
+	 */
44
+	public function setTopPlaces(array $top_places): void
45
+	{
46
+		$this->top_places = collect($top_places)
47
+			->filter(
48
+				/** @psalm-suppress MissingClosureParamType */
49
+				fn($top_places) => $top_places instanceof Place
50
+			)->toArray();
51
+	}
52 52
 
53
-    /**
54
-     * Check whether a string ($haystack) ends with another string ($needle)
55
-     *
56
-     * {@internal This is redundant with the function str_ends_with in PHP8}
57
-     *
58
-     * @param string $haystack
59
-     * @param string $needle
60
-     * @return bool
61
-     */
62
-    private function endsWith(string $haystack, string $needle): bool
63
-    {
64
-        return substr_compare($haystack, $needle, -strlen($needle)) === 0;
65
-    }
53
+	/**
54
+	 * Check whether a string ($haystack) ends with another string ($needle)
55
+	 *
56
+	 * {@internal This is redundant with the function str_ends_with in PHP8}
57
+	 *
58
+	 * @param string $haystack
59
+	 * @param string $needle
60
+	 * @return bool
61
+	 */
62
+	private function endsWith(string $haystack, string $needle): bool
63
+	{
64
+		return substr_compare($haystack, $needle, -strlen($needle)) === 0;
65
+	}
66 66
 
67
-    /**
68
-     * Check whether a Place belongs to one of the defined top places.
69
-     *
70
-     * @param Place $place
71
-     * @return bool
72
-     */
73
-    protected function belongsToTopLevels(Place $place): bool
74
-    {
75
-        foreach ($this->top_places as $top_place) {
76
-            if (
77
-                $top_place->tree()->id() === $place->tree()->id() &&
78
-                $this->endsWith($place->gedcomName(), $top_place->gedcomName())
79
-            ) {
80
-                    return true;
81
-            }
82
-        }
83
-        return false;
84
-    }
67
+	/**
68
+	 * Check whether a Place belongs to one of the defined top places.
69
+	 *
70
+	 * @param Place $place
71
+	 * @return bool
72
+	 */
73
+	protected function belongsToTopLevels(Place $place): bool
74
+	{
75
+		foreach ($this->top_places as $top_place) {
76
+			if (
77
+				$top_place->tree()->id() === $place->tree()->id() &&
78
+				$this->endsWith($place->gedcomName(), $top_place->gedcomName())
79
+			) {
80
+					return true;
81
+			}
82
+		}
83
+		return false;
84
+	}
85 85
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/PlaceMappers/PlaceMapperTrait.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -24,65 +24,65 @@
 block discarded – undo
24 24
  */
25 25
 trait PlaceMapperTrait
26 26
 {
27
-    private ?PlaceMapperConfigInterface $config = null;
28
-    private array $data = [];
27
+	private ?PlaceMapperConfigInterface $config = null;
28
+	private array $data = [];
29 29
 
30
-    /**
31
-     * Implementation of PlaceMapperInterface::boot
32
-     *
33
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot()
34
-     */
35
-    public function boot(): void
36
-    {
37
-    }
30
+	/**
31
+	 * Implementation of PlaceMapperInterface::boot
32
+	 *
33
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot()
34
+	 */
35
+	public function boot(): void
36
+	{
37
+	}
38 38
 
39
-    /**
40
-     * Implementation of PlaceMapperInterface::config
41
-     *
42
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config()
43
-     *
44
-     * @return PlaceMapperConfigInterface
45
-     */
46
-    public function config(): PlaceMapperConfigInterface
47
-    {
48
-        return $this->config ?? new NullPlaceMapperConfig();
49
-    }
39
+	/**
40
+	 * Implementation of PlaceMapperInterface::config
41
+	 *
42
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config()
43
+	 *
44
+	 * @return PlaceMapperConfigInterface
45
+	 */
46
+	public function config(): PlaceMapperConfigInterface
47
+	{
48
+		return $this->config ?? new NullPlaceMapperConfig();
49
+	}
50 50
 
51
-    /**
52
-     * Implementation of PlaceMapperInterface::setConfig
53
-     *
54
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setConfig()
55
-     *
56
-     * @param PlaceMapperConfigInterface $config
57
-     */
58
-    public function setConfig(PlaceMapperConfigInterface $config): void
59
-    {
60
-        $this->config = $config;
61
-    }
51
+	/**
52
+	 * Implementation of PlaceMapperInterface::setConfig
53
+	 *
54
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setConfig()
55
+	 *
56
+	 * @param PlaceMapperConfigInterface $config
57
+	 */
58
+	public function setConfig(PlaceMapperConfigInterface $config): void
59
+	{
60
+		$this->config = $config;
61
+	}
62 62
 
63
-    /**
64
-     * Implementation of PlaceMapperInterface::data
65
-     *
66
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::data()
67
-     *
68
-     * @param string $key
69
-     * @return NULL|mixed
70
-     */
71
-    public function data(string $key)
72
-    {
73
-        return $this->data[$key] ?? null;
74
-    }
63
+	/**
64
+	 * Implementation of PlaceMapperInterface::data
65
+	 *
66
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::data()
67
+	 *
68
+	 * @param string $key
69
+	 * @return NULL|mixed
70
+	 */
71
+	public function data(string $key)
72
+	{
73
+		return $this->data[$key] ?? null;
74
+	}
75 75
 
76
-    /**
77
-     * Implementation of PlaceMapperInterface::setData
78
-     *
79
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setData()
80
-     *
81
-     * @param string $key
82
-     * @param mixed|null $data
83
-     */
84
-    public function setData(string $key, $data): void
85
-    {
86
-        $this->data[$key] = $data;
87
-    }
76
+	/**
77
+	 * Implementation of PlaceMapperInterface::setData
78
+	 *
79
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setData()
80
+	 *
81
+	 * @param string $key
82
+	 * @param mixed|null $data
83
+	 */
84
+	public function setData(string $key, $data): void
85
+	{
86
+		$this->data[$key] = $data;
87
+	}
88 88
 }
Please login to merge, or discard this patch.