@@ -125,7 +125,7 @@ discard block |
||
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 |
||
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 | } |
@@ -36,184 +36,184 @@ |
||
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 ($geometry !== null && $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 int[]|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 | - * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
131 | - * @return array{grid: array<int, array<int, \Brick\Geo\IO\GeoJSON\Feature[]>>, nb_columns: int, map_NE: \Brick\Geo\Point, map_SW: \Brick\Geo\Point, SRID: int}|NULL |
|
132 | - */ |
|
133 | - protected function featuresIndex(): ?array |
|
134 | - { |
|
135 | - $cacheKey = $this->cacheKey(); |
|
136 | - if ($cacheKey === null) { |
|
137 | - return null; |
|
138 | - } |
|
139 | - return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
140 | - $map_def = $this->data('map'); |
|
141 | - if ( |
|
142 | - !$this->setGeometryEngine() |
|
143 | - || $map_def === null |
|
144 | - || !($map_def instanceof MapDefinitionInterface) |
|
145 | - ) { |
|
146 | - return null; |
|
147 | - } |
|
148 | - $bounding_boxes = []; |
|
149 | - $map_bounding_box = new BoundingBox(); |
|
150 | - $srid = 0; |
|
151 | - foreach ($map_def->features() as $feature) { |
|
152 | - $geometry = $feature->getGeometry(); |
|
153 | - if ($geometry === null) { |
|
154 | - continue; |
|
155 | - } |
|
156 | - $srid = $geometry->SRID(); |
|
157 | - $bounding_box = $geometry->getBoundingBox(); |
|
158 | - $bounding_boxes[] = [$feature, $bounding_box]; |
|
159 | - $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
160 | - } |
|
161 | - $grid_columns = count($bounding_boxes); |
|
162 | - $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
163 | - $map_NE = $map_bounding_box->getNorthEast(); |
|
164 | - $map_SW = $map_bounding_box->getSouthWest(); |
|
165 | - foreach ($bounding_boxes as $item) { |
|
166 | - $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
167 | - $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
168 | - for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
169 | - for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
170 | - $grid[$i][$j][] = $item[0]; |
|
171 | - } |
|
172 | - } |
|
173 | - } |
|
174 | - return [ |
|
175 | - 'grid' => $grid, |
|
176 | - 'nb_columns' => $grid_columns, |
|
177 | - 'map_NE' => $map_NE, |
|
178 | - 'map_SW' => $map_SW, |
|
179 | - 'SRID' => $srid |
|
180 | - ]; |
|
181 | - }); |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * Set the Brick Geo Engine to use the database for geospatial computations. |
|
186 | - * The engine is set only if it has not been set beforehand. |
|
187 | - * |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - protected function setGeometryEngine(): bool |
|
191 | - { |
|
192 | - try { |
|
193 | - if (!GeometryEngineRegistry::has()) { |
|
194 | - GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo())); |
|
195 | - } |
|
196 | - $point = Point::xy(1, 1); |
|
197 | - return $point->equals($point); |
|
198 | - } catch (Throwable $ex) { |
|
199 | - } |
|
200 | - return false; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Get the key to cache the indexed grid of features. |
|
205 | - * |
|
206 | - * @return string|NULL |
|
207 | - */ |
|
208 | - protected function cacheKey(): ?string |
|
209 | - { |
|
210 | - if ($this->cache_key === null) { |
|
211 | - $map_def = $this->data('map'); |
|
212 | - if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
213 | - return null; |
|
214 | - } |
|
215 | - return spl_object_id($this) . '-map-' . $map_def->id(); |
|
216 | - } |
|
217 | - return $this->cache_key; |
|
218 | - } |
|
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 ($geometry !== null && $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 int[]|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 | + * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
131 | + * @return array{grid: array<int, array<int, \Brick\Geo\IO\GeoJSON\Feature[]>>, nb_columns: int, map_NE: \Brick\Geo\Point, map_SW: \Brick\Geo\Point, SRID: int}|NULL |
|
132 | + */ |
|
133 | + protected function featuresIndex(): ?array |
|
134 | + { |
|
135 | + $cacheKey = $this->cacheKey(); |
|
136 | + if ($cacheKey === null) { |
|
137 | + return null; |
|
138 | + } |
|
139 | + return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
140 | + $map_def = $this->data('map'); |
|
141 | + if ( |
|
142 | + !$this->setGeometryEngine() |
|
143 | + || $map_def === null |
|
144 | + || !($map_def instanceof MapDefinitionInterface) |
|
145 | + ) { |
|
146 | + return null; |
|
147 | + } |
|
148 | + $bounding_boxes = []; |
|
149 | + $map_bounding_box = new BoundingBox(); |
|
150 | + $srid = 0; |
|
151 | + foreach ($map_def->features() as $feature) { |
|
152 | + $geometry = $feature->getGeometry(); |
|
153 | + if ($geometry === null) { |
|
154 | + continue; |
|
155 | + } |
|
156 | + $srid = $geometry->SRID(); |
|
157 | + $bounding_box = $geometry->getBoundingBox(); |
|
158 | + $bounding_boxes[] = [$feature, $bounding_box]; |
|
159 | + $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
160 | + } |
|
161 | + $grid_columns = count($bounding_boxes); |
|
162 | + $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
163 | + $map_NE = $map_bounding_box->getNorthEast(); |
|
164 | + $map_SW = $map_bounding_box->getSouthWest(); |
|
165 | + foreach ($bounding_boxes as $item) { |
|
166 | + $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
167 | + $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
168 | + for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
169 | + for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
170 | + $grid[$i][$j][] = $item[0]; |
|
171 | + } |
|
172 | + } |
|
173 | + } |
|
174 | + return [ |
|
175 | + 'grid' => $grid, |
|
176 | + 'nb_columns' => $grid_columns, |
|
177 | + 'map_NE' => $map_NE, |
|
178 | + 'map_SW' => $map_SW, |
|
179 | + 'SRID' => $srid |
|
180 | + ]; |
|
181 | + }); |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * Set the Brick Geo Engine to use the database for geospatial computations. |
|
186 | + * The engine is set only if it has not been set beforehand. |
|
187 | + * |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + protected function setGeometryEngine(): bool |
|
191 | + { |
|
192 | + try { |
|
193 | + if (!GeometryEngineRegistry::has()) { |
|
194 | + GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo())); |
|
195 | + } |
|
196 | + $point = Point::xy(1, 1); |
|
197 | + return $point->equals($point); |
|
198 | + } catch (Throwable $ex) { |
|
199 | + } |
|
200 | + return false; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Get the key to cache the indexed grid of features. |
|
205 | + * |
|
206 | + * @return string|NULL |
|
207 | + */ |
|
208 | + protected function cacheKey(): ?string |
|
209 | + { |
|
210 | + if ($this->cache_key === null) { |
|
211 | + $map_def = $this->data('map'); |
|
212 | + if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
213 | + return null; |
|
214 | + } |
|
215 | + return spl_object_id($this) . '-map-' . $map_def->id(); |
|
216 | + } |
|
217 | + return $this->cache_key; |
|
218 | + } |
|
219 | 219 | } |
@@ -22,81 +22,81 @@ |
||
22 | 22 | */ |
23 | 23 | class MapFeatureAnalysisData |
24 | 24 | { |
25 | - private string $id; |
|
26 | - private int $count; |
|
27 | - private bool $in_map; |
|
28 | - /** |
|
29 | - * @var Collection<GeoAnalysisPlace> $places |
|
30 | - */ |
|
31 | - private Collection $places; |
|
25 | + private string $id; |
|
26 | + private int $count; |
|
27 | + private bool $in_map; |
|
28 | + /** |
|
29 | + * @var Collection<GeoAnalysisPlace> $places |
|
30 | + */ |
|
31 | + private Collection $places; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor for MapFeatureAnalysisData |
|
35 | - * |
|
36 | - * @param string $id |
|
37 | - */ |
|
38 | - public function __construct(string $id) |
|
39 | - { |
|
40 | - $this->id = $id; |
|
41 | - $this->count = 0; |
|
42 | - $this->places = new Collection(); |
|
43 | - $this->in_map = false; |
|
44 | - } |
|
33 | + /** |
|
34 | + * Constructor for MapFeatureAnalysisData |
|
35 | + * |
|
36 | + * @param string $id |
|
37 | + */ |
|
38 | + public function __construct(string $id) |
|
39 | + { |
|
40 | + $this->id = $id; |
|
41 | + $this->count = 0; |
|
42 | + $this->places = new Collection(); |
|
43 | + $this->in_map = false; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Get the list of places mapped to the feature |
|
48 | - * |
|
49 | - * @return Collection<GeoAnalysisPlace> |
|
50 | - */ |
|
51 | - public function places(): Collection |
|
52 | - { |
|
53 | - return $this->places; |
|
54 | - } |
|
46 | + /** |
|
47 | + * Get the list of places mapped to the feature |
|
48 | + * |
|
49 | + * @return Collection<GeoAnalysisPlace> |
|
50 | + */ |
|
51 | + public function places(): Collection |
|
52 | + { |
|
53 | + return $this->places; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Get the count of analysis items occurring in the feature |
|
58 | - * |
|
59 | - * @return int |
|
60 | - */ |
|
61 | - public function count(): int |
|
62 | - { |
|
63 | - return $this->count; |
|
64 | - } |
|
56 | + /** |
|
57 | + * Get the count of analysis items occurring in the feature |
|
58 | + * |
|
59 | + * @return int |
|
60 | + */ |
|
61 | + public function count(): int |
|
62 | + { |
|
63 | + return $this->count; |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Check whether the feature exist in the target map |
|
68 | - * |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - public function existsInMap(): bool |
|
72 | - { |
|
73 | - return $this->in_map; |
|
74 | - } |
|
66 | + /** |
|
67 | + * Check whether the feature exist in the target map |
|
68 | + * |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + public function existsInMap(): bool |
|
72 | + { |
|
73 | + return $this->in_map; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Confirm that the feature exist in the target map |
|
78 | - * |
|
79 | - * @return $this |
|
80 | - */ |
|
81 | - public function tagAsExisting(): self |
|
82 | - { |
|
83 | - $this->in_map = true; |
|
84 | - return $this; |
|
85 | - } |
|
76 | + /** |
|
77 | + * Confirm that the feature exist in the target map |
|
78 | + * |
|
79 | + * @return $this |
|
80 | + */ |
|
81 | + public function tagAsExisting(): self |
|
82 | + { |
|
83 | + $this->in_map = true; |
|
84 | + return $this; |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * Add a GeoAnalysisPlace to the feature |
|
89 | - * |
|
90 | - * @param GeoAnalysisPlace $place |
|
91 | - * @param int $count |
|
92 | - * @return $this |
|
93 | - */ |
|
94 | - public function add(GeoAnalysisPlace $place, int $count): self |
|
95 | - { |
|
96 | - if (!$place->isExcluded()) { |
|
97 | - $this->places->add($place); |
|
98 | - $this->count += $count; |
|
99 | - } |
|
100 | - return $this; |
|
101 | - } |
|
87 | + /** |
|
88 | + * Add a GeoAnalysisPlace to the feature |
|
89 | + * |
|
90 | + * @param GeoAnalysisPlace $place |
|
91 | + * @param int $count |
|
92 | + * @return $this |
|
93 | + */ |
|
94 | + public function add(GeoAnalysisPlace $place, int $count): self |
|
95 | + { |
|
96 | + if (!$place->isExcluded()) { |
|
97 | + $this->places->add($place); |
|
98 | + $this->count += $count; |
|
99 | + } |
|
100 | + return $this; |
|
101 | + } |
|
102 | 102 | } |
@@ -24,57 +24,57 @@ |
||
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 static |
|
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 static |
|
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 | } |
@@ -123,7 +123,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
168 | 168 | } |
169 | 169 | }); |
170 | 170 | |
171 | - return [ $features_mapping, $result]; |
|
171 | + return [$features_mapping, $result]; |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | /** |
@@ -29,189 +29,189 @@ |
||
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 static |
|
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 mixed[] |
|
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 static |
|
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 mixed[] |
|
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 | } |
@@ -27,57 +27,57 @@ |
||
27 | 27 | */ |
28 | 28 | class SourceCertificateIconHook implements FactSourceTextExtenderInterface |
29 | 29 | { |
30 | - private CertificatesModule $module; |
|
31 | - private UrlObfuscatorService $url_obfuscator_service; |
|
30 | + private CertificatesModule $module; |
|
31 | + private UrlObfuscatorService $url_obfuscator_service; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor for SourceCertificateIconHook |
|
35 | - * |
|
36 | - * @param CertificatesModule $module |
|
37 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
38 | - */ |
|
39 | - public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
40 | - { |
|
41 | - $this->module = $module; |
|
42 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
43 | - } |
|
33 | + /** |
|
34 | + * Constructor for SourceCertificateIconHook |
|
35 | + * |
|
36 | + * @param CertificatesModule $module |
|
37 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
38 | + */ |
|
39 | + public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
40 | + { |
|
41 | + $this->module = $module; |
|
42 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
48 | - */ |
|
49 | - public function module(): ModuleInterface |
|
50 | - { |
|
51 | - return $this->module; |
|
52 | - } |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
48 | + */ |
|
49 | + public function module(): ModuleInterface |
|
50 | + { |
|
51 | + return $this->module; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
57 | - */ |
|
58 | - public function factSourcePrepend(Tree $tree, string $source_record, int $level): string |
|
59 | - { |
|
60 | - $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
61 | - if ( |
|
62 | - is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level && |
|
63 | - preg_match('/^' . $level . ' _ACT (.*)$/m', $source_record, $match) === 1 |
|
64 | - ) { |
|
65 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
66 | - 'module_name' => $this->module->name(), |
|
67 | - 'certificate' => new Certificate($tree, $match[1]), |
|
68 | - 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
69 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
70 | - ]); |
|
71 | - } |
|
72 | - return ''; |
|
73 | - } |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
57 | + */ |
|
58 | + public function factSourcePrepend(Tree $tree, string $source_record, int $level): string |
|
59 | + { |
|
60 | + $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
61 | + if ( |
|
62 | + is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level && |
|
63 | + preg_match('/^' . $level . ' _ACT (.*)$/m', $source_record, $match) === 1 |
|
64 | + ) { |
|
65 | + return view($this->module->name() . '::components/certificate-icon', [ |
|
66 | + 'module_name' => $this->module->name(), |
|
67 | + 'certificate' => new Certificate($tree, $match[1]), |
|
68 | + 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
69 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
70 | + ]); |
|
71 | + } |
|
72 | + return ''; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * {@inheritDoc} |
|
77 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
78 | - */ |
|
79 | - public function factSourceAppend(Tree $tree, string $source_record, int $level): string |
|
80 | - { |
|
81 | - return ''; |
|
82 | - } |
|
75 | + /** |
|
76 | + * {@inheritDoc} |
|
77 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
78 | + */ |
|
79 | + public function factSourceAppend(Tree $tree, string $source_record, int $level): string |
|
80 | + { |
|
81 | + return ''; |
|
82 | + } |
|
83 | 83 | } |
@@ -59,10 +59,10 @@ |
||
59 | 59 | { |
60 | 60 | $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
61 | 61 | if ( |
62 | - is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level && |
|
63 | - preg_match('/^' . $level . ' _ACT (.*)$/m', $source_record, $match) === 1 |
|
62 | + is_numeric($permission_level) && Auth::accessLevel($tree) <= (int)$permission_level && |
|
63 | + preg_match('/^'.$level.' _ACT (.*)$/m', $source_record, $match) === 1 |
|
64 | 64 | ) { |
65 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
65 | + return view($this->module->name().'::components/certificate-icon', [ |
|
66 | 66 | 'module_name' => $this->module->name(), |
67 | 67 | 'certificate' => new Certificate($tree, $match[1]), |
68 | 68 | 'url_obfuscator_service' => $this->url_obfuscator_service, |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | */ |
103 | 103 | public function loadRoutes($router): void |
104 | 104 | { |
105 | - $router->attach('', '', static function (Map $router): void { |
|
105 | + $router->attach('', '', static function(Map $router): void { |
|
106 | 106 | |
107 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
107 | + $router->attach('', '/module-maj/certificates', static function(Map $router): void { |
|
108 | 108 | |
109 | - $router->attach('', '/admin', static function (Map $router): void { |
|
109 | + $router->attach('', '/admin', static function(Map $router): void { |
|
110 | 110 | |
111 | 111 | $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
112 | 112 | $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
130 | 130 | ]); |
131 | 131 | |
132 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
132 | + $router->attach('', '/certificate/{tree}/{cid}', static function(Map $router): void { |
|
133 | 133 | |
134 | 134 | $router->extras([ |
135 | 135 | 'middleware' => [AuthTreePreference::class], |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | */ |
168 | 168 | public function headContent(): string |
169 | 169 | { |
170 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
170 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function listUrl(Tree $tree, array $parameters = []): string |
178 | 178 | { |
179 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
179 | + return route(CertificatesList::class, ['tree' => $tree->name()] + $parameters); |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | /** |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | */ |
195 | 195 | public function listIsEmpty(Tree $tree): bool |
196 | 196 | { |
197 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
197 | + return Auth::accessLevel($tree) > (int)$tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string)Auth::PRIV_HIDE); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | /** |
@@ -46,197 +46,197 @@ |
||
46 | 46 | * Certificates Module. |
47 | 47 | */ |
48 | 48 | class CertificatesModule extends AbstractModule implements |
49 | - ModuleMyArtJaubInterface, |
|
50 | - ModuleConfigInterface, |
|
51 | - ModuleCustomTagsInterface, |
|
52 | - ModuleGlobalInterface, |
|
53 | - ModuleListInterface, |
|
54 | - ModuleHookSubscriberInterface |
|
49 | + ModuleMyArtJaubInterface, |
|
50 | + ModuleConfigInterface, |
|
51 | + ModuleCustomTagsInterface, |
|
52 | + ModuleGlobalInterface, |
|
53 | + ModuleListInterface, |
|
54 | + ModuleHookSubscriberInterface |
|
55 | 55 | { |
56 | - use ModuleMyArtJaubTrait { |
|
57 | - ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
58 | - } |
|
59 | - use ModuleCustomTagsTrait { |
|
60 | - ModuleCustomTagsTrait::boot as traitCustomTagsBoot; |
|
61 | - } |
|
62 | - use ModuleConfigTrait; |
|
63 | - use ModuleGlobalTrait; |
|
64 | - use ModuleListTrait; |
|
65 | - |
|
66 | - /** |
|
67 | - * {@inheritDoc} |
|
68 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
69 | - */ |
|
70 | - public function title(): string |
|
71 | - { |
|
72 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * {@inheritDoc} |
|
77 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
78 | - */ |
|
79 | - public function description(): string |
|
80 | - { |
|
81 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
82 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * {@inheritDoc} |
|
87 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
88 | - */ |
|
89 | - public function boot(): void |
|
90 | - { |
|
91 | - $this->traitMajBoot(); |
|
92 | - $this->traitCustomTagsBoot(); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * {@inheritDoc} |
|
97 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
98 | - */ |
|
99 | - public function loadRoutes($router): void |
|
100 | - { |
|
101 | - $router->attach('', '', static function (Map $router): void { |
|
102 | - |
|
103 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
104 | - |
|
105 | - $router->attach('', '/admin', static function (Map $router): void { |
|
106 | - |
|
107 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
108 | - $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
109 | - ->extras([ |
|
110 | - 'middleware' => [ |
|
111 | - AuthManager::class, |
|
112 | - ], |
|
113 | - ]); |
|
114 | - }); |
|
115 | - |
|
116 | - $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
117 | - ->extras([ |
|
118 | - 'middleware' => [AuthTreePreference::class], |
|
119 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
120 | - ]); |
|
121 | - |
|
122 | - $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
123 | - ->extras([ |
|
124 | - 'middleware' => [AuthTreePreference::class], |
|
125 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
126 | - ]); |
|
127 | - |
|
128 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
129 | - |
|
130 | - $router->extras([ |
|
131 | - 'middleware' => [AuthTreePreference::class], |
|
132 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
133 | - ]); |
|
134 | - |
|
135 | - $router->get(CertificatePage::class, '', CertificatePage::class); |
|
136 | - $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
137 | - }); |
|
138 | - }); |
|
139 | - }); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * {@inheritDoc} |
|
144 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
145 | - */ |
|
146 | - public function customModuleVersion(): string |
|
147 | - { |
|
148 | - return '2.1.0-v.1'; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * {@inheritDoc} |
|
153 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
154 | - */ |
|
155 | - public function getConfigLink(): string |
|
156 | - { |
|
157 | - return route(AdminConfigPage::class); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * {@inheritDoc} |
|
162 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customSubTags() |
|
163 | - */ |
|
164 | - public function customSubTags(): array |
|
165 | - { |
|
166 | - return [ |
|
167 | - 'FAM:SOUR' => [['_ACT', '0:1']], |
|
168 | - 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
169 | - 'INDI:SOUR' => [['_ACT', '0:1']], |
|
170 | - 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
171 | - 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
172 | - 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
173 | - 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
174 | - 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
175 | - ]; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * {@inheritDoc} |
|
180 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customTags() |
|
181 | - */ |
|
182 | - public function customTags(): array |
|
183 | - { |
|
184 | - return [ |
|
185 | - 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
186 | - 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
187 | - 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
188 | - 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
189 | - 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
190 | - 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
191 | - 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
192 | - 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
193 | - ]; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * {@inheritDoc} |
|
198 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
199 | - */ |
|
200 | - public function headContent(): string |
|
201 | - { |
|
202 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * {@inheritDoc} |
|
207 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
208 | - */ |
|
209 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
210 | - { |
|
211 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * {@inheritDoc} |
|
216 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
217 | - */ |
|
218 | - public function listMenuClass(): string |
|
219 | - { |
|
220 | - return 'menu-maj-certificates'; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * {@inheritDoc} |
|
225 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
226 | - */ |
|
227 | - public function listIsEmpty(Tree $tree): bool |
|
228 | - { |
|
229 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * {@inheritDoc} |
|
234 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
235 | - */ |
|
236 | - public function listSubscribedHooks(): array |
|
237 | - { |
|
238 | - return [ |
|
239 | - app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
240 | - ]; |
|
241 | - } |
|
56 | + use ModuleMyArtJaubTrait { |
|
57 | + ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
58 | + } |
|
59 | + use ModuleCustomTagsTrait { |
|
60 | + ModuleCustomTagsTrait::boot as traitCustomTagsBoot; |
|
61 | + } |
|
62 | + use ModuleConfigTrait; |
|
63 | + use ModuleGlobalTrait; |
|
64 | + use ModuleListTrait; |
|
65 | + |
|
66 | + /** |
|
67 | + * {@inheritDoc} |
|
68 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
69 | + */ |
|
70 | + public function title(): string |
|
71 | + { |
|
72 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * {@inheritDoc} |
|
77 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
78 | + */ |
|
79 | + public function description(): string |
|
80 | + { |
|
81 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
82 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * {@inheritDoc} |
|
87 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
88 | + */ |
|
89 | + public function boot(): void |
|
90 | + { |
|
91 | + $this->traitMajBoot(); |
|
92 | + $this->traitCustomTagsBoot(); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * {@inheritDoc} |
|
97 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
98 | + */ |
|
99 | + public function loadRoutes($router): void |
|
100 | + { |
|
101 | + $router->attach('', '', static function (Map $router): void { |
|
102 | + |
|
103 | + $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
104 | + |
|
105 | + $router->attach('', '/admin', static function (Map $router): void { |
|
106 | + |
|
107 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
108 | + $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
109 | + ->extras([ |
|
110 | + 'middleware' => [ |
|
111 | + AuthManager::class, |
|
112 | + ], |
|
113 | + ]); |
|
114 | + }); |
|
115 | + |
|
116 | + $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
117 | + ->extras([ |
|
118 | + 'middleware' => [AuthTreePreference::class], |
|
119 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
120 | + ]); |
|
121 | + |
|
122 | + $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
123 | + ->extras([ |
|
124 | + 'middleware' => [AuthTreePreference::class], |
|
125 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
126 | + ]); |
|
127 | + |
|
128 | + $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
129 | + |
|
130 | + $router->extras([ |
|
131 | + 'middleware' => [AuthTreePreference::class], |
|
132 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
133 | + ]); |
|
134 | + |
|
135 | + $router->get(CertificatePage::class, '', CertificatePage::class); |
|
136 | + $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
137 | + }); |
|
138 | + }); |
|
139 | + }); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * {@inheritDoc} |
|
144 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
145 | + */ |
|
146 | + public function customModuleVersion(): string |
|
147 | + { |
|
148 | + return '2.1.0-v.1'; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * {@inheritDoc} |
|
153 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
154 | + */ |
|
155 | + public function getConfigLink(): string |
|
156 | + { |
|
157 | + return route(AdminConfigPage::class); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * {@inheritDoc} |
|
162 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customSubTags() |
|
163 | + */ |
|
164 | + public function customSubTags(): array |
|
165 | + { |
|
166 | + return [ |
|
167 | + 'FAM:SOUR' => [['_ACT', '0:1']], |
|
168 | + 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
169 | + 'INDI:SOUR' => [['_ACT', '0:1']], |
|
170 | + 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
171 | + 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
172 | + 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
173 | + 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
174 | + 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
175 | + ]; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * {@inheritDoc} |
|
180 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customTags() |
|
181 | + */ |
|
182 | + public function customTags(): array |
|
183 | + { |
|
184 | + return [ |
|
185 | + 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
186 | + 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
187 | + 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
188 | + 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
189 | + 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
190 | + 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
191 | + 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
192 | + 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
193 | + ]; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * {@inheritDoc} |
|
198 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
199 | + */ |
|
200 | + public function headContent(): string |
|
201 | + { |
|
202 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * {@inheritDoc} |
|
207 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
208 | + */ |
|
209 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
210 | + { |
|
211 | + return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * {@inheritDoc} |
|
216 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
217 | + */ |
|
218 | + public function listMenuClass(): string |
|
219 | + { |
|
220 | + return 'menu-maj-certificates'; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * {@inheritDoc} |
|
225 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
226 | + */ |
|
227 | + public function listIsEmpty(Tree $tree): bool |
|
228 | + { |
|
229 | + return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * {@inheritDoc} |
|
234 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
235 | + */ |
|
236 | + public function listSubscribedHooks(): array |
|
237 | + { |
|
238 | + return [ |
|
239 | + app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
240 | + ]; |
|
241 | + } |
|
242 | 242 | } |
@@ -29,71 +29,71 @@ |
||
29 | 29 | */ |
30 | 30 | class AdminConfigAction implements RequestHandlerInterface |
31 | 31 | { |
32 | - /** |
|
33 | - * @var CertificatesModule|null $module |
|
34 | - */ |
|
35 | - private $module; |
|
36 | - |
|
37 | - /** |
|
38 | - * Constructor for Admin Config Action request handler |
|
39 | - * |
|
40 | - * @param ModuleService $module_service |
|
41 | - */ |
|
42 | - public function __construct(ModuleService $module_service) |
|
43 | - { |
|
44 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | - */ |
|
51 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | - { |
|
53 | - $tree = $request->getAttribute('tree'); |
|
54 | - assert($tree instanceof Tree); |
|
55 | - |
|
56 | - $admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
57 | - |
|
58 | - if ($this->module === null) { |
|
59 | - FlashMessages::addMessage( |
|
60 | - I18N::translate('The attached module could not be found.'), |
|
61 | - 'danger' |
|
62 | - ); |
|
63 | - return redirect($admin_config_route); |
|
64 | - } |
|
65 | - |
|
66 | - $params = (array) $request->getParsedBody(); |
|
67 | - |
|
68 | - $tree->setPreference('MAJ_CERTIF_SHOW_CERT', $params['MAJ_CERTIF_SHOW_CERT'] ?? (string) Auth::PRIV_HIDE); |
|
69 | - $tree->setPreference( |
|
70 | - 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
|
71 | - $params['MAJ_CERTIF_SHOW_NO_WATERMARK'] ?? (string) Auth::PRIV_HIDE |
|
72 | - ); |
|
73 | - $tree->setPreference('MAJ_CERTIF_WM_DEFAULT', $params['MAJ_CERTIF_WM_DEFAULT'] ?? ''); |
|
74 | - |
|
75 | - $watermark_font_size = $params['MAJ_CERTIF_WM_FONT_MAXSIZE'] ?? ''; |
|
76 | - if (is_numeric($watermark_font_size) && $watermark_font_size > 0) { |
|
77 | - $tree->setPreference('MAJ_CERTIF_WM_FONT_MAXSIZE', $params['MAJ_CERTIF_WM_FONT_MAXSIZE']); |
|
78 | - } |
|
79 | - |
|
80 | - // Only accept valid color for MAJ_WM_FONT_COLOR |
|
81 | - $watermark_color = $params['MAJ_CERTIF_WM_FONT_COLOR'] ?? ''; |
|
82 | - if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
|
83 | - $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
|
84 | - } |
|
85 | - |
|
86 | - // Only accept valid folders for MAJ_CERT_ROOTDIR |
|
87 | - $cert_root_dir = $params['MAJ_CERTIF_ROOTDIR'] ?? ''; |
|
88 | - $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir); |
|
89 | - $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
90 | - $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
|
91 | - |
|
92 | - FlashMessages::addMessage( |
|
93 | - I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
94 | - 'success' |
|
95 | - ); |
|
96 | - |
|
97 | - return redirect($admin_config_route); |
|
98 | - } |
|
32 | + /** |
|
33 | + * @var CertificatesModule|null $module |
|
34 | + */ |
|
35 | + private $module; |
|
36 | + |
|
37 | + /** |
|
38 | + * Constructor for Admin Config Action request handler |
|
39 | + * |
|
40 | + * @param ModuleService $module_service |
|
41 | + */ |
|
42 | + public function __construct(ModuleService $module_service) |
|
43 | + { |
|
44 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | + */ |
|
51 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | + { |
|
53 | + $tree = $request->getAttribute('tree'); |
|
54 | + assert($tree instanceof Tree); |
|
55 | + |
|
56 | + $admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
57 | + |
|
58 | + if ($this->module === null) { |
|
59 | + FlashMessages::addMessage( |
|
60 | + I18N::translate('The attached module could not be found.'), |
|
61 | + 'danger' |
|
62 | + ); |
|
63 | + return redirect($admin_config_route); |
|
64 | + } |
|
65 | + |
|
66 | + $params = (array) $request->getParsedBody(); |
|
67 | + |
|
68 | + $tree->setPreference('MAJ_CERTIF_SHOW_CERT', $params['MAJ_CERTIF_SHOW_CERT'] ?? (string) Auth::PRIV_HIDE); |
|
69 | + $tree->setPreference( |
|
70 | + 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
|
71 | + $params['MAJ_CERTIF_SHOW_NO_WATERMARK'] ?? (string) Auth::PRIV_HIDE |
|
72 | + ); |
|
73 | + $tree->setPreference('MAJ_CERTIF_WM_DEFAULT', $params['MAJ_CERTIF_WM_DEFAULT'] ?? ''); |
|
74 | + |
|
75 | + $watermark_font_size = $params['MAJ_CERTIF_WM_FONT_MAXSIZE'] ?? ''; |
|
76 | + if (is_numeric($watermark_font_size) && $watermark_font_size > 0) { |
|
77 | + $tree->setPreference('MAJ_CERTIF_WM_FONT_MAXSIZE', $params['MAJ_CERTIF_WM_FONT_MAXSIZE']); |
|
78 | + } |
|
79 | + |
|
80 | + // Only accept valid color for MAJ_WM_FONT_COLOR |
|
81 | + $watermark_color = $params['MAJ_CERTIF_WM_FONT_COLOR'] ?? ''; |
|
82 | + if (preg_match('/#([a-fA-F0-9]{3}){1,2}/', $watermark_color) === 1) { |
|
83 | + $tree->setPreference('MAJ_CERTIF_WM_FONT_COLOR', $watermark_color); |
|
84 | + } |
|
85 | + |
|
86 | + // Only accept valid folders for MAJ_CERT_ROOTDIR |
|
87 | + $cert_root_dir = $params['MAJ_CERTIF_ROOTDIR'] ?? ''; |
|
88 | + $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir); |
|
89 | + $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
90 | + $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
|
91 | + |
|
92 | + FlashMessages::addMessage( |
|
93 | + I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
94 | + 'success' |
|
95 | + ); |
|
96 | + |
|
97 | + return redirect($admin_config_route); |
|
98 | + } |
|
99 | 99 | } |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | return redirect($admin_config_route); |
64 | 64 | } |
65 | 65 | |
66 | - $params = (array) $request->getParsedBody(); |
|
66 | + $params = (array)$request->getParsedBody(); |
|
67 | 67 | |
68 | - $tree->setPreference('MAJ_CERTIF_SHOW_CERT', $params['MAJ_CERTIF_SHOW_CERT'] ?? (string) Auth::PRIV_HIDE); |
|
68 | + $tree->setPreference('MAJ_CERTIF_SHOW_CERT', $params['MAJ_CERTIF_SHOW_CERT'] ?? (string)Auth::PRIV_HIDE); |
|
69 | 69 | $tree->setPreference( |
70 | 70 | 'MAJ_CERTIF_SHOW_NO_WATERMARK', |
71 | - $params['MAJ_CERTIF_SHOW_NO_WATERMARK'] ?? (string) Auth::PRIV_HIDE |
|
71 | + $params['MAJ_CERTIF_SHOW_NO_WATERMARK'] ?? (string)Auth::PRIV_HIDE |
|
72 | 72 | ); |
73 | 73 | $tree->setPreference('MAJ_CERTIF_WM_DEFAULT', $params['MAJ_CERTIF_WM_DEFAULT'] ?? ''); |
74 | 74 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | // Only accept valid folders for MAJ_CERT_ROOTDIR |
87 | 87 | $cert_root_dir = $params['MAJ_CERTIF_ROOTDIR'] ?? ''; |
88 | 88 | $cert_root_dir = preg_replace('/[:\/\\\\]+/', '/', $cert_root_dir); |
89 | - $cert_root_dir = trim($cert_root_dir, '/') . '/'; |
|
89 | + $cert_root_dir = trim($cert_root_dir, '/').'/'; |
|
90 | 90 | $tree->setPreference('MAJ_CERTIF_ROOTDIR', $cert_root_dir); |
91 | 91 | |
92 | 92 | FlashMessages::addMessage( |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | if ($certificate === null) { |
106 | 106 | return $this->certif_image_factory |
107 | - ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND) |
|
107 | + ->replacementImageResponse((string)StatusCodeInterface::STATUS_NOT_FOUND) |
|
108 | 108 | ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.')) |
109 | 109 | ; |
110 | 110 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE'); |
133 | 133 | $text = $this->watermarkText($request, $certificate); |
134 | 134 | |
135 | - return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE); |
|
135 | + return new Watermark($text, $color, is_numeric($size) ? (int)$size : Watermark::DEFAULT_SIZE); |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -37,128 +37,128 @@ |
||
37 | 37 | */ |
38 | 38 | class CertificateImage implements RequestHandlerInterface |
39 | 39 | { |
40 | - /** |
|
41 | - * @var CertificatesModule|null $module |
|
42 | - */ |
|
43 | - private $module; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var CertificateFilesystemService $certif_filesystem |
|
47 | - */ |
|
48 | - private $certif_filesystem; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var CertificateImageFactory $certif_image_factory |
|
52 | - */ |
|
53 | - private $certif_image_factory; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var CertificateDataService $certif_data_service |
|
57 | - */ |
|
58 | - private $certif_data_service; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var UrlObfuscatorService $url_obfuscator_service |
|
62 | - */ |
|
63 | - private $url_obfuscator_service; |
|
64 | - |
|
65 | - /** |
|
66 | - * Constructor for Certificate Image Request Handler |
|
67 | - * |
|
68 | - * @param ModuleService $module_service |
|
69 | - */ |
|
70 | - public function __construct( |
|
71 | - ModuleService $module_service, |
|
72 | - CertificateFilesystemService $certif_filesystem, |
|
73 | - CertificateDataService $certif_data_service, |
|
74 | - UrlObfuscatorService $url_obfuscator_service |
|
75 | - ) { |
|
76 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
77 | - $this->certif_filesystem = $certif_filesystem; |
|
78 | - $this->certif_image_factory = new CertificateImageFactory($this->certif_filesystem); |
|
79 | - $this->certif_data_service = $certif_data_service; |
|
80 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * {@inheritDoc} |
|
85 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
86 | - */ |
|
87 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
88 | - { |
|
89 | - if ($this->module === null) { |
|
90 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
91 | - } |
|
92 | - |
|
93 | - $tree = $request->getAttribute('tree'); |
|
94 | - assert($tree instanceof Tree); |
|
95 | - |
|
96 | - $user = $request->getAttribute('user'); |
|
97 | - assert($user instanceof UserInterface); |
|
98 | - |
|
99 | - $certif_path = $request->getAttribute('cid'); |
|
100 | - $certificate = null; |
|
101 | - if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
102 | - $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
103 | - } |
|
104 | - |
|
105 | - if ($certificate === null) { |
|
106 | - return $this->certif_image_factory |
|
107 | - ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND) |
|
108 | - ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.')) |
|
109 | - ; |
|
110 | - } |
|
111 | - |
|
112 | - $use_watermark = $this->certif_image_factory->certificateNeedsWatermark($certificate, $user); |
|
113 | - $watermark = $use_watermark ? $this->watermark($request, $certificate) : null; |
|
114 | - |
|
115 | - return $this->certif_image_factory->certificateFileResponse( |
|
116 | - $certificate, |
|
117 | - $use_watermark, |
|
118 | - $watermark |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Get watermark data for a certificate. |
|
124 | - * |
|
125 | - * @param ServerRequestInterface $request |
|
126 | - * @param Certificate $certificate |
|
127 | - * @return Watermark |
|
128 | - */ |
|
129 | - private function watermark(ServerRequestInterface $request, Certificate $certificate): Watermark |
|
130 | - { |
|
131 | - $color = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_COLOR', Watermark::DEFAULT_COLOR); |
|
132 | - $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE'); |
|
133 | - $text = $this->watermarkText($request, $certificate); |
|
134 | - |
|
135 | - return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Get the text to be watermarked for a certificate. |
|
140 | - * |
|
141 | - * @param ServerRequestInterface $request |
|
142 | - * @param Certificate $certificate |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - private function watermarkText(ServerRequestInterface $request, Certificate $certificate): string |
|
146 | - { |
|
147 | - $sid = $request->getQueryParams()['sid'] ?? ''; |
|
148 | - if ($sid !== '') { |
|
149 | - $source = Registry::sourceFactory()->make($sid, $certificate->tree()); |
|
150 | - } else { |
|
151 | - $source = $this->certif_data_service->oneLinkedSource($certificate); |
|
152 | - } |
|
153 | - |
|
154 | - if ($source !== null && $source->canShowName()) { |
|
155 | - $repo = $source->facts(['REPO'])->first(); |
|
156 | - if ($repo !== null && ($repo = $repo->target()) !== null && $repo->canShowName()) { |
|
157 | - return I18N::translate('© %s - %s', strip_tags($repo->fullName()), strip_tags($source->fullName())); |
|
158 | - } |
|
159 | - return strip_tags($source->fullName()); |
|
160 | - } |
|
161 | - $default_text = $certificate->tree()->getPreference('MAJ_CERTIF_WM_DEFAULT'); |
|
162 | - return $default_text !== '' ? $default_text : I18N::translate('This image is protected under copyright law.'); |
|
163 | - } |
|
40 | + /** |
|
41 | + * @var CertificatesModule|null $module |
|
42 | + */ |
|
43 | + private $module; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var CertificateFilesystemService $certif_filesystem |
|
47 | + */ |
|
48 | + private $certif_filesystem; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var CertificateImageFactory $certif_image_factory |
|
52 | + */ |
|
53 | + private $certif_image_factory; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var CertificateDataService $certif_data_service |
|
57 | + */ |
|
58 | + private $certif_data_service; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var UrlObfuscatorService $url_obfuscator_service |
|
62 | + */ |
|
63 | + private $url_obfuscator_service; |
|
64 | + |
|
65 | + /** |
|
66 | + * Constructor for Certificate Image Request Handler |
|
67 | + * |
|
68 | + * @param ModuleService $module_service |
|
69 | + */ |
|
70 | + public function __construct( |
|
71 | + ModuleService $module_service, |
|
72 | + CertificateFilesystemService $certif_filesystem, |
|
73 | + CertificateDataService $certif_data_service, |
|
74 | + UrlObfuscatorService $url_obfuscator_service |
|
75 | + ) { |
|
76 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
77 | + $this->certif_filesystem = $certif_filesystem; |
|
78 | + $this->certif_image_factory = new CertificateImageFactory($this->certif_filesystem); |
|
79 | + $this->certif_data_service = $certif_data_service; |
|
80 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * {@inheritDoc} |
|
85 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
86 | + */ |
|
87 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
88 | + { |
|
89 | + if ($this->module === null) { |
|
90 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
91 | + } |
|
92 | + |
|
93 | + $tree = $request->getAttribute('tree'); |
|
94 | + assert($tree instanceof Tree); |
|
95 | + |
|
96 | + $user = $request->getAttribute('user'); |
|
97 | + assert($user instanceof UserInterface); |
|
98 | + |
|
99 | + $certif_path = $request->getAttribute('cid'); |
|
100 | + $certificate = null; |
|
101 | + if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
102 | + $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
103 | + } |
|
104 | + |
|
105 | + if ($certificate === null) { |
|
106 | + return $this->certif_image_factory |
|
107 | + ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND) |
|
108 | + ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.')) |
|
109 | + ; |
|
110 | + } |
|
111 | + |
|
112 | + $use_watermark = $this->certif_image_factory->certificateNeedsWatermark($certificate, $user); |
|
113 | + $watermark = $use_watermark ? $this->watermark($request, $certificate) : null; |
|
114 | + |
|
115 | + return $this->certif_image_factory->certificateFileResponse( |
|
116 | + $certificate, |
|
117 | + $use_watermark, |
|
118 | + $watermark |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Get watermark data for a certificate. |
|
124 | + * |
|
125 | + * @param ServerRequestInterface $request |
|
126 | + * @param Certificate $certificate |
|
127 | + * @return Watermark |
|
128 | + */ |
|
129 | + private function watermark(ServerRequestInterface $request, Certificate $certificate): Watermark |
|
130 | + { |
|
131 | + $color = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_COLOR', Watermark::DEFAULT_COLOR); |
|
132 | + $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE'); |
|
133 | + $text = $this->watermarkText($request, $certificate); |
|
134 | + |
|
135 | + return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Get the text to be watermarked for a certificate. |
|
140 | + * |
|
141 | + * @param ServerRequestInterface $request |
|
142 | + * @param Certificate $certificate |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + private function watermarkText(ServerRequestInterface $request, Certificate $certificate): string |
|
146 | + { |
|
147 | + $sid = $request->getQueryParams()['sid'] ?? ''; |
|
148 | + if ($sid !== '') { |
|
149 | + $source = Registry::sourceFactory()->make($sid, $certificate->tree()); |
|
150 | + } else { |
|
151 | + $source = $this->certif_data_service->oneLinkedSource($certificate); |
|
152 | + } |
|
153 | + |
|
154 | + if ($source !== null && $source->canShowName()) { |
|
155 | + $repo = $source->facts(['REPO'])->first(); |
|
156 | + if ($repo !== null && ($repo = $repo->target()) !== null && $repo->canShowName()) { |
|
157 | + return I18N::translate('© %s - %s', strip_tags($repo->fullName()), strip_tags($source->fullName())); |
|
158 | + } |
|
159 | + return strip_tags($source->fullName()); |
|
160 | + } |
|
161 | + $default_text = $certificate->tree()->getPreference('MAJ_CERTIF_WM_DEFAULT'); |
|
162 | + return $default_text !== '' ? $default_text : I18N::translate('This image is protected under copyright law.'); |
|
163 | + } |
|
164 | 164 | } |
@@ -31,73 +31,73 @@ |
||
31 | 31 | */ |
32 | 32 | class CertificatesList implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var CertificatesModule|null $module |
|
38 | - */ |
|
39 | - private $module; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var CertificateFilesystemService $certif_filesystem |
|
43 | - */ |
|
44 | - private $certif_filesystem; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var UrlObfuscatorService $url_obfuscator_service |
|
48 | - */ |
|
49 | - private $url_obfuscator_service; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Constructor for CertificatesList Request Handler |
|
54 | - * |
|
55 | - * @param ModuleService $module_service |
|
56 | - */ |
|
57 | - public function __construct( |
|
58 | - ModuleService $module_service, |
|
59 | - CertificateFilesystemService $certif_filesystem, |
|
60 | - UrlObfuscatorService $url_obfuscator_service |
|
61 | - ) { |
|
62 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
63 | - $this->certif_filesystem = $certif_filesystem; |
|
64 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * {@inheritDoc} |
|
69 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
70 | - */ |
|
71 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
72 | - { |
|
73 | - if ($this->module === null) { |
|
74 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
75 | - } |
|
76 | - |
|
77 | - $tree = $request->getAttribute('tree'); |
|
78 | - assert($tree instanceof Tree); |
|
79 | - |
|
80 | - $title = I18N::translate('Certificates'); |
|
81 | - |
|
82 | - $cities = array_map(function (string $item): array { |
|
83 | - return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
84 | - }, $this->certif_filesystem->cities($tree)); |
|
85 | - |
|
86 | - $city = $request->getQueryParams()['cityobf'] ?? $request->getAttribute('cityobf') ?? ''; |
|
87 | - |
|
88 | - if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
89 | - $title = I18N::translate('Certificates for %s', $city); |
|
90 | - $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
|
91 | - } |
|
92 | - |
|
93 | - return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
94 | - 'title' => $title, |
|
95 | - 'tree' => $tree, |
|
96 | - 'module_name' => $this->module->name(), |
|
97 | - 'cities' => $cities, |
|
98 | - 'selected_city' => $city, |
|
99 | - 'certificates_list' => $certificates ?? collect(), |
|
100 | - 'url_obfuscator_service' => $this->url_obfuscator_service |
|
101 | - ]); |
|
102 | - } |
|
34 | + use ViewResponseTrait; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var CertificatesModule|null $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var CertificateFilesystemService $certif_filesystem |
|
43 | + */ |
|
44 | + private $certif_filesystem; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var UrlObfuscatorService $url_obfuscator_service |
|
48 | + */ |
|
49 | + private $url_obfuscator_service; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Constructor for CertificatesList Request Handler |
|
54 | + * |
|
55 | + * @param ModuleService $module_service |
|
56 | + */ |
|
57 | + public function __construct( |
|
58 | + ModuleService $module_service, |
|
59 | + CertificateFilesystemService $certif_filesystem, |
|
60 | + UrlObfuscatorService $url_obfuscator_service |
|
61 | + ) { |
|
62 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
63 | + $this->certif_filesystem = $certif_filesystem; |
|
64 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * {@inheritDoc} |
|
69 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
70 | + */ |
|
71 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
72 | + { |
|
73 | + if ($this->module === null) { |
|
74 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
75 | + } |
|
76 | + |
|
77 | + $tree = $request->getAttribute('tree'); |
|
78 | + assert($tree instanceof Tree); |
|
79 | + |
|
80 | + $title = I18N::translate('Certificates'); |
|
81 | + |
|
82 | + $cities = array_map(function (string $item): array { |
|
83 | + return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
84 | + }, $this->certif_filesystem->cities($tree)); |
|
85 | + |
|
86 | + $city = $request->getQueryParams()['cityobf'] ?? $request->getAttribute('cityobf') ?? ''; |
|
87 | + |
|
88 | + if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
89 | + $title = I18N::translate('Certificates for %s', $city); |
|
90 | + $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
|
91 | + } |
|
92 | + |
|
93 | + return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
94 | + 'title' => $title, |
|
95 | + 'tree' => $tree, |
|
96 | + 'module_name' => $this->module->name(), |
|
97 | + 'cities' => $cities, |
|
98 | + 'selected_city' => $city, |
|
99 | + 'certificates_list' => $certificates ?? collect(), |
|
100 | + 'url_obfuscator_service' => $this->url_obfuscator_service |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | } |
@@ -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(), |