@@ -28,51 +28,51 @@ |
||
28 | 28 | */ |
29 | 29 | class SimpleTopFilteredPlaceMapper extends SimplePlaceMapper implements PlaceMapperInterface |
30 | 30 | { |
31 | - use TopFilteredPlaceMapperTrait; |
|
31 | + use TopFilteredPlaceMapperTrait; |
|
32 | 32 | |
33 | - /** |
|
34 | - * {@inheritDoc} |
|
35 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title() |
|
36 | - */ |
|
37 | - public function title(): string |
|
38 | - { |
|
39 | - return I18N::translate('Mapping on place name with filter'); |
|
40 | - } |
|
33 | + /** |
|
34 | + * {@inheritDoc} |
|
35 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title() |
|
36 | + */ |
|
37 | + public function title(): string |
|
38 | + { |
|
39 | + return I18N::translate('Mapping on place name with filter'); |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * {@inheritDoc} |
|
44 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
45 | - */ |
|
46 | - public function boot(): void |
|
47 | - { |
|
48 | - parent::boot(); |
|
49 | - $top_places = $this->config()->get('topPlaces'); |
|
50 | - if (is_array($top_places)) { |
|
51 | - $this->setTopPlaces($top_places); |
|
52 | - } |
|
53 | - } |
|
42 | + /** |
|
43 | + * {@inheritDoc} |
|
44 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
45 | + */ |
|
46 | + public function boot(): void |
|
47 | + { |
|
48 | + parent::boot(); |
|
49 | + $top_places = $this->config()->get('topPlaces'); |
|
50 | + if (is_array($top_places)) { |
|
51 | + $this->setTopPlaces($top_places); |
|
52 | + } |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
58 | - */ |
|
59 | - public function config(): PlaceMapperConfigInterface |
|
60 | - { |
|
61 | - if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) { |
|
62 | - $this->setConfig(app(FilteredTopPlaceMapperConfig::class)); |
|
63 | - } |
|
64 | - return parent::config(); |
|
65 | - } |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
58 | + */ |
|
59 | + public function config(): PlaceMapperConfigInterface |
|
60 | + { |
|
61 | + if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) { |
|
62 | + $this->setConfig(app(FilteredTopPlaceMapperConfig::class)); |
|
63 | + } |
|
64 | + return parent::config(); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inheritDoc} |
|
69 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map() |
|
70 | - */ |
|
71 | - public function map(Place $place, string $feature_property): ?string |
|
72 | - { |
|
73 | - if (!$this->belongsToTopLevels($place)) { |
|
74 | - return null; |
|
75 | - } |
|
76 | - return parent::map($place, $feature_property); |
|
77 | - } |
|
67 | + /** |
|
68 | + * {@inheritDoc} |
|
69 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map() |
|
70 | + */ |
|
71 | + public function map(Place $place, string $feature_property): ?string |
|
72 | + { |
|
73 | + if (!$this->belongsToTopLevels($place)) { |
|
74 | + return null; |
|
75 | + } |
|
76 | + return parent::map($place, $feature_property); |
|
77 | + } |
|
78 | 78 | } |
@@ -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,188 +36,188 @@ |
||
36 | 36 | */ |
37 | 37 | class CoordinatesPlaceMapper implements PlaceMapperInterface |
38 | 38 | { |
39 | - use PlaceMapperTrait; |
|
40 | - |
|
41 | - private ?string $cache_key = null; |
|
42 | - private ?GeometryEngine $geometry_engine = null; |
|
43 | - |
|
44 | - /** |
|
45 | - * {@inheritDoc} |
|
46 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
47 | - */ |
|
48 | - public function title(): string |
|
49 | - { |
|
50 | - return I18N::translate('Mapping on place coordinates'); |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * {@inheritDoc} |
|
55 | - * |
|
56 | - * {@internal The Place is associated to a Point only. |
|
57 | - * PlaceLocation can calculate a BoundingBox. |
|
58 | - * Using a BoundingBox could make the mapping more complex and potentially arbitary. |
|
59 | - * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents. |
|
60 | - * This could create the unwanted side effect of a very large area to consider} |
|
61 | - * |
|
62 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
63 | - */ |
|
64 | - public function map(Place $place, string $feature_property): ?string |
|
65 | - { |
|
66 | - $location = new PlaceLocation($place->gedcomName()); |
|
67 | - $longitude = $location->longitude(); |
|
68 | - $latitude = $location->latitude(); |
|
69 | - if ($longitude === null || $latitude === null) { |
|
70 | - return null; |
|
71 | - } |
|
72 | - |
|
73 | - $features_index = $this->featuresIndex(); |
|
74 | - if ($features_index === null) { |
|
75 | - return null; |
|
76 | - } |
|
77 | - |
|
78 | - $place_point = Point::xy($longitude, $latitude, $features_index['SRID']); |
|
79 | - $grid_box = $this->getGridCell( |
|
80 | - $place_point, |
|
81 | - $features_index['map_NE'], |
|
82 | - $features_index['map_SW'], |
|
83 | - $features_index['nb_columns'] |
|
84 | - ); |
|
85 | - if ($grid_box === null || !$this->setGeometryEngine() || $this->geometry_engine == null) { |
|
86 | - return null; |
|
87 | - } |
|
88 | - $features = $features_index['grid'][$grid_box[0]][$grid_box[1]]; |
|
89 | - foreach ($features as $feature) { |
|
90 | - $geometry = $feature->getGeometry(); |
|
91 | - if ( |
|
92 | - $geometry !== null && $place_point->SRID() === $geometry->SRID() && |
|
93 | - $this->geometry_engine->contains($geometry, $place_point) |
|
94 | - ) { |
|
95 | - return $feature->getProperty($feature_property); |
|
96 | - } |
|
97 | - } |
|
98 | - return null; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Return the XY coordinates in a bounded grid of the cell containing a specific point. |
|
103 | - * |
|
104 | - * @param Point $point Point to find |
|
105 | - * @param Point $grid_NE North-East point of the bounded grid |
|
106 | - * @param Point $grid_SW South-West point fo the bounded grid |
|
107 | - * @param int $grid_columns Number of columns/rows in the grid |
|
108 | - * @return int[]|NULL |
|
109 | - */ |
|
110 | - protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array |
|
111 | - { |
|
112 | - list($x, $y) = $point->toArray(); |
|
113 | - list($x_max, $y_max) = $grid_NE->toArray(); |
|
114 | - list($x_min, $y_min) = $grid_SW->toArray(); |
|
115 | - |
|
116 | - $x_step = ($x_max - $x_min) / $grid_columns; |
|
117 | - $y_step = ($y_max - $y_min) / $grid_columns; |
|
118 | - |
|
119 | - if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) { |
|
120 | - return [ |
|
121 | - $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step), |
|
122 | - $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step) |
|
123 | - ]; |
|
124 | - } |
|
125 | - return null; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Get an indexed array of the features of the map. |
|
130 | - * |
|
131 | - * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell. |
|
132 | - * The grid is computed once for each map, and cached.} |
|
133 | - * |
|
134 | - * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
135 | - * @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 |
|
136 | - */ |
|
137 | - protected function featuresIndex(): ?array |
|
138 | - { |
|
139 | - $cacheKey = $this->cacheKey(); |
|
140 | - if ($cacheKey === null) { |
|
141 | - return null; |
|
142 | - } |
|
143 | - return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
144 | - $map_def = $this->data('map'); |
|
145 | - if ( |
|
146 | - !$this->setGeometryEngine() |
|
147 | - || $map_def === null |
|
148 | - || !($map_def instanceof MapDefinitionInterface) |
|
149 | - ) { |
|
150 | - return null; |
|
151 | - } |
|
152 | - $bounding_boxes = []; |
|
153 | - $map_bounding_box = new BoundingBox(); |
|
154 | - $srid = 0; |
|
155 | - foreach ($map_def->features() as $feature) { |
|
156 | - $geometry = $feature->getGeometry(); |
|
157 | - if ($geometry === null) { |
|
158 | - continue; |
|
159 | - } |
|
160 | - $srid = $geometry->SRID(); |
|
161 | - $bounding_box = $geometry->getBoundingBox(); |
|
162 | - $bounding_boxes[] = [$feature, $bounding_box]; |
|
163 | - $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
164 | - } |
|
165 | - $grid_columns = count($bounding_boxes); |
|
166 | - $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
167 | - $map_NE = $map_bounding_box->getNorthEast(); |
|
168 | - $map_SW = $map_bounding_box->getSouthWest(); |
|
169 | - foreach ($bounding_boxes as $item) { |
|
170 | - $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
171 | - $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
172 | - for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
173 | - for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
174 | - $grid[$i][$j][] = $item[0]; |
|
175 | - } |
|
176 | - } |
|
177 | - } |
|
178 | - return [ |
|
179 | - 'grid' => $grid, |
|
180 | - 'nb_columns' => $grid_columns, |
|
181 | - 'map_NE' => $map_NE, |
|
182 | - 'map_SW' => $map_SW, |
|
183 | - 'SRID' => $srid |
|
184 | - ]; |
|
185 | - }); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Set the Brick Geo Engine to use the database for geospatial computations. |
|
190 | - * The engine is set only if it has not been set beforehand. |
|
191 | - * |
|
192 | - * @return bool |
|
193 | - */ |
|
194 | - protected function setGeometryEngine(): bool |
|
195 | - { |
|
196 | - try { |
|
197 | - if ($this->geometry_engine === null) { |
|
198 | - $this->geometry_engine = new PDOEngine(DB::connection()->getPdo()); |
|
199 | - } |
|
200 | - $point = Point::xy(1, 1); |
|
201 | - return $this->geometry_engine->equals($point, $point); |
|
202 | - } catch (Throwable $ex) { |
|
203 | - } |
|
204 | - return false; |
|
205 | - } |
|
206 | - |
|
207 | - /** |
|
208 | - * Get the key to cache the indexed grid of features. |
|
209 | - * |
|
210 | - * @return string|NULL |
|
211 | - */ |
|
212 | - protected function cacheKey(): ?string |
|
213 | - { |
|
214 | - if ($this->cache_key === null) { |
|
215 | - $map_def = $this->data('map'); |
|
216 | - if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
217 | - return null; |
|
218 | - } |
|
219 | - return spl_object_id($this) . '-map-' . $map_def->id(); |
|
220 | - } |
|
221 | - return $this->cache_key; |
|
222 | - } |
|
39 | + use PlaceMapperTrait; |
|
40 | + |
|
41 | + private ?string $cache_key = null; |
|
42 | + private ?GeometryEngine $geometry_engine = null; |
|
43 | + |
|
44 | + /** |
|
45 | + * {@inheritDoc} |
|
46 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
47 | + */ |
|
48 | + public function title(): string |
|
49 | + { |
|
50 | + return I18N::translate('Mapping on place coordinates'); |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * {@inheritDoc} |
|
55 | + * |
|
56 | + * {@internal The Place is associated to a Point only. |
|
57 | + * PlaceLocation can calculate a BoundingBox. |
|
58 | + * Using a BoundingBox could make the mapping more complex and potentially arbitary. |
|
59 | + * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents. |
|
60 | + * This could create the unwanted side effect of a very large area to consider} |
|
61 | + * |
|
62 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
63 | + */ |
|
64 | + public function map(Place $place, string $feature_property): ?string |
|
65 | + { |
|
66 | + $location = new PlaceLocation($place->gedcomName()); |
|
67 | + $longitude = $location->longitude(); |
|
68 | + $latitude = $location->latitude(); |
|
69 | + if ($longitude === null || $latitude === null) { |
|
70 | + return null; |
|
71 | + } |
|
72 | + |
|
73 | + $features_index = $this->featuresIndex(); |
|
74 | + if ($features_index === null) { |
|
75 | + return null; |
|
76 | + } |
|
77 | + |
|
78 | + $place_point = Point::xy($longitude, $latitude, $features_index['SRID']); |
|
79 | + $grid_box = $this->getGridCell( |
|
80 | + $place_point, |
|
81 | + $features_index['map_NE'], |
|
82 | + $features_index['map_SW'], |
|
83 | + $features_index['nb_columns'] |
|
84 | + ); |
|
85 | + if ($grid_box === null || !$this->setGeometryEngine() || $this->geometry_engine == null) { |
|
86 | + return null; |
|
87 | + } |
|
88 | + $features = $features_index['grid'][$grid_box[0]][$grid_box[1]]; |
|
89 | + foreach ($features as $feature) { |
|
90 | + $geometry = $feature->getGeometry(); |
|
91 | + if ( |
|
92 | + $geometry !== null && $place_point->SRID() === $geometry->SRID() && |
|
93 | + $this->geometry_engine->contains($geometry, $place_point) |
|
94 | + ) { |
|
95 | + return $feature->getProperty($feature_property); |
|
96 | + } |
|
97 | + } |
|
98 | + return null; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Return the XY coordinates in a bounded grid of the cell containing a specific point. |
|
103 | + * |
|
104 | + * @param Point $point Point to find |
|
105 | + * @param Point $grid_NE North-East point of the bounded grid |
|
106 | + * @param Point $grid_SW South-West point fo the bounded grid |
|
107 | + * @param int $grid_columns Number of columns/rows in the grid |
|
108 | + * @return int[]|NULL |
|
109 | + */ |
|
110 | + protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array |
|
111 | + { |
|
112 | + list($x, $y) = $point->toArray(); |
|
113 | + list($x_max, $y_max) = $grid_NE->toArray(); |
|
114 | + list($x_min, $y_min) = $grid_SW->toArray(); |
|
115 | + |
|
116 | + $x_step = ($x_max - $x_min) / $grid_columns; |
|
117 | + $y_step = ($y_max - $y_min) / $grid_columns; |
|
118 | + |
|
119 | + if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) { |
|
120 | + return [ |
|
121 | + $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step), |
|
122 | + $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step) |
|
123 | + ]; |
|
124 | + } |
|
125 | + return null; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Get an indexed array of the features of the map. |
|
130 | + * |
|
131 | + * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell. |
|
132 | + * The grid is computed once for each map, and cached.} |
|
133 | + * |
|
134 | + * @phpcs:ignore Generic.Files.LineLength.TooLong |
|
135 | + * @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 |
|
136 | + */ |
|
137 | + protected function featuresIndex(): ?array |
|
138 | + { |
|
139 | + $cacheKey = $this->cacheKey(); |
|
140 | + if ($cacheKey === null) { |
|
141 | + return null; |
|
142 | + } |
|
143 | + return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
144 | + $map_def = $this->data('map'); |
|
145 | + if ( |
|
146 | + !$this->setGeometryEngine() |
|
147 | + || $map_def === null |
|
148 | + || !($map_def instanceof MapDefinitionInterface) |
|
149 | + ) { |
|
150 | + return null; |
|
151 | + } |
|
152 | + $bounding_boxes = []; |
|
153 | + $map_bounding_box = new BoundingBox(); |
|
154 | + $srid = 0; |
|
155 | + foreach ($map_def->features() as $feature) { |
|
156 | + $geometry = $feature->getGeometry(); |
|
157 | + if ($geometry === null) { |
|
158 | + continue; |
|
159 | + } |
|
160 | + $srid = $geometry->SRID(); |
|
161 | + $bounding_box = $geometry->getBoundingBox(); |
|
162 | + $bounding_boxes[] = [$feature, $bounding_box]; |
|
163 | + $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
164 | + } |
|
165 | + $grid_columns = count($bounding_boxes); |
|
166 | + $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
167 | + $map_NE = $map_bounding_box->getNorthEast(); |
|
168 | + $map_SW = $map_bounding_box->getSouthWest(); |
|
169 | + foreach ($bounding_boxes as $item) { |
|
170 | + $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
171 | + $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
172 | + for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
173 | + for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
174 | + $grid[$i][$j][] = $item[0]; |
|
175 | + } |
|
176 | + } |
|
177 | + } |
|
178 | + return [ |
|
179 | + 'grid' => $grid, |
|
180 | + 'nb_columns' => $grid_columns, |
|
181 | + 'map_NE' => $map_NE, |
|
182 | + 'map_SW' => $map_SW, |
|
183 | + 'SRID' => $srid |
|
184 | + ]; |
|
185 | + }); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Set the Brick Geo Engine to use the database for geospatial computations. |
|
190 | + * The engine is set only if it has not been set beforehand. |
|
191 | + * |
|
192 | + * @return bool |
|
193 | + */ |
|
194 | + protected function setGeometryEngine(): bool |
|
195 | + { |
|
196 | + try { |
|
197 | + if ($this->geometry_engine === null) { |
|
198 | + $this->geometry_engine = new PDOEngine(DB::connection()->getPdo()); |
|
199 | + } |
|
200 | + $point = Point::xy(1, 1); |
|
201 | + return $this->geometry_engine->equals($point, $point); |
|
202 | + } catch (Throwable $ex) { |
|
203 | + } |
|
204 | + return false; |
|
205 | + } |
|
206 | + |
|
207 | + /** |
|
208 | + * Get the key to cache the indexed grid of features. |
|
209 | + * |
|
210 | + * @return string|NULL |
|
211 | + */ |
|
212 | + protected function cacheKey(): ?string |
|
213 | + { |
|
214 | + if ($this->cache_key === null) { |
|
215 | + $map_def = $this->data('map'); |
|
216 | + if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
217 | + return null; |
|
218 | + } |
|
219 | + return spl_object_id($this) . '-map-' . $map_def->id(); |
|
220 | + } |
|
221 | + return $this->cache_key; |
|
222 | + } |
|
223 | 223 | } |
@@ -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 | /** |
@@ -44,180 +44,180 @@ |
||
44 | 44 | * Certificates Module. |
45 | 45 | */ |
46 | 46 | class CertificatesModule extends AbstractModule implements |
47 | - ModuleMyArtJaubInterface, |
|
48 | - ModuleConfigInterface, |
|
49 | - ModuleGlobalInterface, |
|
50 | - ModuleListInterface, |
|
51 | - ModuleHookSubscriberInterface |
|
47 | + ModuleMyArtJaubInterface, |
|
48 | + ModuleConfigInterface, |
|
49 | + ModuleGlobalInterface, |
|
50 | + ModuleListInterface, |
|
51 | + ModuleHookSubscriberInterface |
|
52 | 52 | { |
53 | - use ModuleMyArtJaubTrait { |
|
54 | - ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
55 | - } |
|
56 | - use ModuleConfigTrait; |
|
57 | - use ModuleGlobalTrait; |
|
58 | - use ModuleListTrait; |
|
59 | - |
|
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | - */ |
|
64 | - public function title(): string |
|
65 | - { |
|
66 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | - */ |
|
73 | - public function description(): string |
|
74 | - { |
|
75 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
76 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * {@inheritDoc} |
|
81 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
82 | - */ |
|
83 | - public function boot(): void |
|
84 | - { |
|
85 | - $this->traitMajBoot(); |
|
86 | - |
|
87 | - Registry::elementFactory()->registerTags([ |
|
88 | - 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
89 | - 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
90 | - 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
91 | - 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
92 | - 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
93 | - 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
94 | - 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
95 | - 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
96 | - ]); |
|
97 | - |
|
98 | - Registry::elementFactory()->registerSubTags([ |
|
99 | - 'FAM:SOUR' => [['_ACT', '0:1']], |
|
100 | - 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
101 | - 'INDI:SOUR' => [['_ACT', '0:1']], |
|
102 | - 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
103 | - 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
104 | - 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
105 | - 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
106 | - 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
107 | - ]); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * {@inheritDoc} |
|
112 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
113 | - */ |
|
114 | - public function loadRoutes($router): void |
|
115 | - { |
|
116 | - $router->attach('', '', static function (Map $router): void { |
|
117 | - |
|
118 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
119 | - |
|
120 | - $router->attach('', '/admin', static function (Map $router): void { |
|
121 | - |
|
122 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
123 | - $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
124 | - ->extras([ |
|
125 | - 'middleware' => [ |
|
126 | - AuthManager::class, |
|
127 | - ], |
|
128 | - ]); |
|
129 | - }); |
|
130 | - |
|
131 | - $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
132 | - ->extras([ |
|
133 | - 'middleware' => [AuthTreePreference::class], |
|
134 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
135 | - ]); |
|
136 | - |
|
137 | - $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
138 | - ->extras([ |
|
139 | - 'middleware' => [AuthTreePreference::class], |
|
140 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
141 | - ]); |
|
142 | - |
|
143 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
144 | - |
|
145 | - $router->extras([ |
|
146 | - 'middleware' => [AuthTreePreference::class], |
|
147 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
148 | - ]); |
|
149 | - |
|
150 | - $router->get(CertificatePage::class, '', CertificatePage::class); |
|
151 | - $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
152 | - }); |
|
153 | - }); |
|
154 | - }); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * {@inheritDoc} |
|
159 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
160 | - */ |
|
161 | - public function customModuleVersion(): string |
|
162 | - { |
|
163 | - return '2.1.3-v.1'; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * {@inheritDoc} |
|
168 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
169 | - */ |
|
170 | - public function getConfigLink(): string |
|
171 | - { |
|
172 | - return route(AdminConfigPage::class); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * {@inheritDoc} |
|
177 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
178 | - */ |
|
179 | - public function headContent(): string |
|
180 | - { |
|
181 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
182 | - } |
|
183 | - |
|
184 | - /** |
|
185 | - * {@inheritDoc} |
|
186 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
187 | - * |
|
188 | - * @param array<bool|int|string|array<mixed>|null> $parameters |
|
189 | - */ |
|
190 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
191 | - { |
|
192 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * {@inheritDoc} |
|
197 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
198 | - */ |
|
199 | - public function listMenuClass(): string |
|
200 | - { |
|
201 | - return 'menu-maj-certificates'; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * {@inheritDoc} |
|
206 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
207 | - */ |
|
208 | - public function listIsEmpty(Tree $tree): bool |
|
209 | - { |
|
210 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * {@inheritDoc} |
|
215 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
216 | - */ |
|
217 | - public function listSubscribedHooks(): array |
|
218 | - { |
|
219 | - return [ |
|
220 | - app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
221 | - ]; |
|
222 | - } |
|
53 | + use ModuleMyArtJaubTrait { |
|
54 | + ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
55 | + } |
|
56 | + use ModuleConfigTrait; |
|
57 | + use ModuleGlobalTrait; |
|
58 | + use ModuleListTrait; |
|
59 | + |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
63 | + */ |
|
64 | + public function title(): string |
|
65 | + { |
|
66 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
72 | + */ |
|
73 | + public function description(): string |
|
74 | + { |
|
75 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
76 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * {@inheritDoc} |
|
81 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
82 | + */ |
|
83 | + public function boot(): void |
|
84 | + { |
|
85 | + $this->traitMajBoot(); |
|
86 | + |
|
87 | + Registry::elementFactory()->registerTags([ |
|
88 | + 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
89 | + 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
90 | + 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
91 | + 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
92 | + 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
93 | + 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
94 | + 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
95 | + 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
96 | + ]); |
|
97 | + |
|
98 | + Registry::elementFactory()->registerSubTags([ |
|
99 | + 'FAM:SOUR' => [['_ACT', '0:1']], |
|
100 | + 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
101 | + 'INDI:SOUR' => [['_ACT', '0:1']], |
|
102 | + 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
103 | + 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
104 | + 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
105 | + 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
106 | + 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
107 | + ]); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * {@inheritDoc} |
|
112 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
113 | + */ |
|
114 | + public function loadRoutes($router): void |
|
115 | + { |
|
116 | + $router->attach('', '', static function (Map $router): void { |
|
117 | + |
|
118 | + $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
119 | + |
|
120 | + $router->attach('', '/admin', static function (Map $router): void { |
|
121 | + |
|
122 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
123 | + $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
124 | + ->extras([ |
|
125 | + 'middleware' => [ |
|
126 | + AuthManager::class, |
|
127 | + ], |
|
128 | + ]); |
|
129 | + }); |
|
130 | + |
|
131 | + $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
132 | + ->extras([ |
|
133 | + 'middleware' => [AuthTreePreference::class], |
|
134 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
135 | + ]); |
|
136 | + |
|
137 | + $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
138 | + ->extras([ |
|
139 | + 'middleware' => [AuthTreePreference::class], |
|
140 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
141 | + ]); |
|
142 | + |
|
143 | + $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
144 | + |
|
145 | + $router->extras([ |
|
146 | + 'middleware' => [AuthTreePreference::class], |
|
147 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
148 | + ]); |
|
149 | + |
|
150 | + $router->get(CertificatePage::class, '', CertificatePage::class); |
|
151 | + $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
152 | + }); |
|
153 | + }); |
|
154 | + }); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * {@inheritDoc} |
|
159 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
160 | + */ |
|
161 | + public function customModuleVersion(): string |
|
162 | + { |
|
163 | + return '2.1.3-v.1'; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * {@inheritDoc} |
|
168 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
169 | + */ |
|
170 | + public function getConfigLink(): string |
|
171 | + { |
|
172 | + return route(AdminConfigPage::class); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * {@inheritDoc} |
|
177 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
178 | + */ |
|
179 | + public function headContent(): string |
|
180 | + { |
|
181 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
182 | + } |
|
183 | + |
|
184 | + /** |
|
185 | + * {@inheritDoc} |
|
186 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
187 | + * |
|
188 | + * @param array<bool|int|string|array<mixed>|null> $parameters |
|
189 | + */ |
|
190 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
191 | + { |
|
192 | + return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * {@inheritDoc} |
|
197 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
198 | + */ |
|
199 | + public function listMenuClass(): string |
|
200 | + { |
|
201 | + return 'menu-maj-certificates'; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * {@inheritDoc} |
|
206 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
207 | + */ |
|
208 | + public function listIsEmpty(Tree $tree): bool |
|
209 | + { |
|
210 | + return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * {@inheritDoc} |
|
215 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
216 | + */ |
|
217 | + public function listSubscribedHooks(): array |
|
218 | + { |
|
219 | + return [ |
|
220 | + app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
221 | + ]; |
|
222 | + } |
|
223 | 223 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | |
80 | 80 | $title = I18N::translate('Certificates'); |
81 | 81 | |
82 | - $cities = array_map(function (string $item): array { |
|
82 | + $cities = array_map(function(string $item): array { |
|
83 | 83 | return [$this->url_obfuscator_service->obfuscate($item), $item]; |
84 | 84 | }, $this->certif_filesystem->cities($tree)); |
85 | 85 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
91 | 91 | } |
92 | 92 | |
93 | - return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
93 | + return $this->viewResponse($this->module->name().'::certificates-list', [ |
|
94 | 94 | 'title' => $title, |
95 | 95 | 'tree' => $tree, |
96 | 96 | 'module_name' => $this->module->name(), |
@@ -32,63 +32,63 @@ |
||
32 | 32 | */ |
33 | 33 | class CertificatesList implements RequestHandlerInterface |
34 | 34 | { |
35 | - use ViewResponseTrait; |
|
35 | + use ViewResponseTrait; |
|
36 | 36 | |
37 | - private ?CertificatesModule $module; |
|
38 | - private CertificateFilesystemService $certif_filesystem; |
|
39 | - private UrlObfuscatorService $url_obfuscator_service; |
|
37 | + private ?CertificatesModule $module; |
|
38 | + private CertificateFilesystemService $certif_filesystem; |
|
39 | + private UrlObfuscatorService $url_obfuscator_service; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor for CertificatesList Request Handler |
|
43 | - * |
|
44 | - * @param ModuleService $module_service |
|
45 | - */ |
|
46 | - public function __construct( |
|
47 | - ModuleService $module_service, |
|
48 | - CertificateFilesystemService $certif_filesystem, |
|
49 | - UrlObfuscatorService $url_obfuscator_service |
|
50 | - ) { |
|
51 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
52 | - $this->certif_filesystem = $certif_filesystem; |
|
53 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
54 | - } |
|
41 | + /** |
|
42 | + * Constructor for CertificatesList Request Handler |
|
43 | + * |
|
44 | + * @param ModuleService $module_service |
|
45 | + */ |
|
46 | + public function __construct( |
|
47 | + ModuleService $module_service, |
|
48 | + CertificateFilesystemService $certif_filesystem, |
|
49 | + UrlObfuscatorService $url_obfuscator_service |
|
50 | + ) { |
|
51 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
52 | + $this->certif_filesystem = $certif_filesystem; |
|
53 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | - */ |
|
60 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | - { |
|
62 | - if ($this->module === null) { |
|
63 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | - } |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | + */ |
|
60 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | + { |
|
62 | + if ($this->module === null) { |
|
63 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | + } |
|
65 | 65 | |
66 | - $tree = Validator::attributes($request)->tree(); |
|
66 | + $tree = Validator::attributes($request)->tree(); |
|
67 | 67 | |
68 | - $title = I18N::translate('Certificates'); |
|
68 | + $title = I18N::translate('Certificates'); |
|
69 | 69 | |
70 | - $cities = array_map(function (string $item): array { |
|
71 | - return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
72 | - }, $this->certif_filesystem->cities($tree)); |
|
70 | + $cities = array_map(function (string $item): array { |
|
71 | + return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
72 | + }, $this->certif_filesystem->cities($tree)); |
|
73 | 73 | |
74 | - $city = Validator::queryParams($request)->string( |
|
75 | - 'cityobf', |
|
76 | - Validator::attributes($request)->string('cityobf', '') |
|
77 | - ); |
|
74 | + $city = Validator::queryParams($request)->string( |
|
75 | + 'cityobf', |
|
76 | + Validator::attributes($request)->string('cityobf', '') |
|
77 | + ); |
|
78 | 78 | |
79 | - if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
80 | - $title = I18N::translate('Certificates for %s', $city); |
|
81 | - $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
|
82 | - } |
|
79 | + if ($city !== '' && $this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
80 | + $title = I18N::translate('Certificates for %s', $city); |
|
81 | + $certificates = $this->certif_filesystem->certificatesForCity($tree, $city); |
|
82 | + } |
|
83 | 83 | |
84 | - return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
85 | - 'title' => $title, |
|
86 | - 'tree' => $tree, |
|
87 | - 'module_name' => $this->module->name(), |
|
88 | - 'cities' => $cities, |
|
89 | - 'selected_city' => $city, |
|
90 | - 'certificates_list' => $certificates ?? collect(), |
|
91 | - 'url_obfuscator_service' => $this->url_obfuscator_service |
|
92 | - ]); |
|
93 | - } |
|
84 | + return $this->viewResponse($this->module->name() . '::certificates-list', [ |
|
85 | + 'title' => $title, |
|
86 | + 'tree' => $tree, |
|
87 | + 'module_name' => $this->module->name(), |
|
88 | + 'cities' => $cities, |
|
89 | + 'selected_city' => $city, |
|
90 | + 'certificates_list' => $certificates ?? collect(), |
|
91 | + 'url_obfuscator_service' => $this->url_obfuscator_service |
|
92 | + ]); |
|
93 | + } |
|
94 | 94 | } |
@@ -87,7 +87,7 @@ |
||
87 | 87 | throw new HttpAccessDeniedException(); |
88 | 88 | } |
89 | 89 | |
90 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
90 | + return $this->viewResponse($this->module->name().'::admin/config', [ |
|
91 | 91 | 'module_name' => $this->module->name(), |
92 | 92 | 'title' => $this->module->title(), |
93 | 93 | 'tree' => $tree, |
@@ -35,56 +35,56 @@ |
||
35 | 35 | */ |
36 | 36 | class AdminConfigPage implements RequestHandlerInterface |
37 | 37 | { |
38 | - use ViewResponseTrait; |
|
38 | + use ViewResponseTrait; |
|
39 | 39 | |
40 | - private ?CertificatesModule $module; |
|
41 | - private TreeService $tree_service; |
|
40 | + private ?CertificatesModule $module; |
|
41 | + private TreeService $tree_service; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor for Admin Config page request handler |
|
45 | - * |
|
46 | - * @param ModuleService $module_service |
|
47 | - */ |
|
48 | - public function __construct(ModuleService $module_service, TreeService $tree_service) |
|
49 | - { |
|
50 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
51 | - $this->tree_service = $tree_service; |
|
52 | - } |
|
43 | + /** |
|
44 | + * Constructor for Admin Config page request handler |
|
45 | + * |
|
46 | + * @param ModuleService $module_service |
|
47 | + */ |
|
48 | + public function __construct(ModuleService $module_service, TreeService $tree_service) |
|
49 | + { |
|
50 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
51 | + $this->tree_service = $tree_service; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
57 | - */ |
|
58 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
59 | - { |
|
60 | - $this->layout = 'layouts/administration'; |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
57 | + */ |
|
58 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
59 | + { |
|
60 | + $this->layout = 'layouts/administration'; |
|
61 | 61 | |
62 | - if ($this->module === null) { |
|
63 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | - } |
|
62 | + if ($this->module === null) { |
|
63 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | + } |
|
65 | 65 | |
66 | - $user = Validator::attributes($request)->user(); |
|
66 | + $user = Validator::attributes($request)->user(); |
|
67 | 67 | |
68 | - $all_trees = $this->tree_service->all()->filter(fn(Tree $tree) => Auth::isManager($tree, $user)); |
|
69 | - if ($all_trees->count() === 0) { |
|
70 | - throw new HttpAccessDeniedException(); |
|
71 | - } |
|
68 | + $all_trees = $this->tree_service->all()->filter(fn(Tree $tree) => Auth::isManager($tree, $user)); |
|
69 | + if ($all_trees->count() === 0) { |
|
70 | + throw new HttpAccessDeniedException(); |
|
71 | + } |
|
72 | 72 | |
73 | - $tree = Validator::attributes($request)->treeOptional('tree') ?? $all_trees->first(); |
|
73 | + $tree = Validator::attributes($request)->treeOptional('tree') ?? $all_trees->first(); |
|
74 | 74 | |
75 | - $data_folder = Registry::filesystem()->dataName(); |
|
75 | + $data_folder = Registry::filesystem()->dataName(); |
|
76 | 76 | |
77 | - $same_tree = fn(Tree $tree_collection): bool => $tree->id() === $tree_collection->id(); |
|
78 | - if (!$all_trees->contains($same_tree)) { |
|
79 | - throw new HttpAccessDeniedException(); |
|
80 | - } |
|
77 | + $same_tree = fn(Tree $tree_collection): bool => $tree->id() === $tree_collection->id(); |
|
78 | + if (!$all_trees->contains($same_tree)) { |
|
79 | + throw new HttpAccessDeniedException(); |
|
80 | + } |
|
81 | 81 | |
82 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
83 | - 'module_name' => $this->module->name(), |
|
84 | - 'title' => $this->module->title(), |
|
85 | - 'tree' => $tree, |
|
86 | - 'other_trees' => $all_trees->reject($same_tree), |
|
87 | - 'data_folder' => $data_folder |
|
88 | - ]); |
|
89 | - } |
|
82 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
83 | + 'module_name' => $this->module->name(), |
|
84 | + 'title' => $this->module->title(), |
|
85 | + 'tree' => $tree, |
|
86 | + 'other_trees' => $all_trees->reject($same_tree), |
|
87 | + 'data_folder' => $data_folder |
|
88 | + ]); |
|
89 | + } |
|
90 | 90 | } |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $tree = $certificate->tree(); |
44 | 44 | return DB::table('individuals') |
45 | 45 | ->where('i_file', '=', $tree->id()) |
46 | - ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
46 | + ->where('i_gedcom', 'like', '% _ACT '.$this->escapedSqlPath($certificate).'%') |
|
47 | 47 | ->select(['individuals.*']) |
48 | 48 | ->get() |
49 | 49 | ->map(Registry::individualFactory()->mapper($tree)) |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $tree = $certificate->tree(); |
65 | 65 | return DB::table('families') |
66 | 66 | ->where('f_file', '=', $tree->id()) |
67 | - ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
67 | + ->where('f_gedcom', 'like', '% _ACT '.$this->escapedSqlPath($certificate).'%') |
|
68 | 68 | ->select(['families.*']) |
69 | 69 | ->get() |
70 | 70 | ->map(Registry::familyFactory()->mapper($tree)) |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $tree = $certificate->tree(); |
86 | 86 | return DB::table('media') |
87 | 87 | ->where('m_file', '=', $tree->id()) |
88 | - ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
88 | + ->where('m_gedcom', 'like', '% _ACT '.$this->escapedSqlPath($certificate).'%') |
|
89 | 89 | ->select(['media.*']) |
90 | 90 | ->get() |
91 | 91 | ->map(Registry::mediaFactory()->mapper($tree)) |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | return DB::table('other') |
108 | 108 | ->where('o_file', '=', $tree->id()) |
109 | 109 | ->where('o_type', '=', 'NOTE') |
110 | - ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
110 | + ->where('o_gedcom', 'like', '% _ACT '.$this->escapedSqlPath($certificate).'%') |
|
111 | 111 | ->select(['other.*']) |
112 | 112 | ->get() |
113 | 113 | ->map(Registry::noteFactory()->mapper($tree)) |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | public function oneLinkedSource(Certificate $certificate): ?Source |
136 | 136 | { |
137 | 137 | $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
138 | - $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
138 | + $regex_pattern = '/[1-9] SOUR @('.Gedcom::REGEX_XREF.')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT '.$regex_query.'/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
139 | 139 | |
140 | 140 | foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
141 | 141 | foreach ($linked_records as $gedcom_record) { |
@@ -28,144 +28,144 @@ |
||
28 | 28 | */ |
29 | 29 | class CertificateDataService |
30 | 30 | { |
31 | - /** |
|
32 | - * Find individuals linked to a certificate. |
|
33 | - * |
|
34 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
35 | - * but does not work with Sqlite if no default escape has been defined} |
|
36 | - * |
|
37 | - * @param Certificate $certificate |
|
38 | - * @return Collection<\Fisharebest\Webtrees\Individual> |
|
39 | - */ |
|
40 | - public function linkedIndividuals(Certificate $certificate): Collection |
|
41 | - { |
|
42 | - $tree = $certificate->tree(); |
|
43 | - return DB::table('individuals') |
|
44 | - ->where('i_file', '=', $tree->id()) |
|
45 | - ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
46 | - ->select(['individuals.*']) |
|
47 | - ->get() |
|
48 | - ->map(Registry::individualFactory()->mapper($tree)) |
|
49 | - ->filter(GedcomRecord::accessFilter()); |
|
50 | - } |
|
31 | + /** |
|
32 | + * Find individuals linked to a certificate. |
|
33 | + * |
|
34 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
35 | + * but does not work with Sqlite if no default escape has been defined} |
|
36 | + * |
|
37 | + * @param Certificate $certificate |
|
38 | + * @return Collection<\Fisharebest\Webtrees\Individual> |
|
39 | + */ |
|
40 | + public function linkedIndividuals(Certificate $certificate): Collection |
|
41 | + { |
|
42 | + $tree = $certificate->tree(); |
|
43 | + return DB::table('individuals') |
|
44 | + ->where('i_file', '=', $tree->id()) |
|
45 | + ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
46 | + ->select(['individuals.*']) |
|
47 | + ->get() |
|
48 | + ->map(Registry::individualFactory()->mapper($tree)) |
|
49 | + ->filter(GedcomRecord::accessFilter()); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Find families linked to a certificate. |
|
54 | - * |
|
55 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
56 | - * but does not work with Sqlite if no default escape has been defined} |
|
57 | - * |
|
58 | - * @param Certificate $certificate |
|
59 | - * @return Collection<\Fisharebest\Webtrees\Family> |
|
60 | - */ |
|
61 | - public function linkedFamilies(Certificate $certificate): Collection |
|
62 | - { |
|
63 | - $tree = $certificate->tree(); |
|
64 | - return DB::table('families') |
|
65 | - ->where('f_file', '=', $tree->id()) |
|
66 | - ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
67 | - ->select(['families.*']) |
|
68 | - ->get() |
|
69 | - ->map(Registry::familyFactory()->mapper($tree)) |
|
70 | - ->filter(GedcomRecord::accessFilter()); |
|
71 | - } |
|
52 | + /** |
|
53 | + * Find families linked to a certificate. |
|
54 | + * |
|
55 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
56 | + * but does not work with Sqlite if no default escape has been defined} |
|
57 | + * |
|
58 | + * @param Certificate $certificate |
|
59 | + * @return Collection<\Fisharebest\Webtrees\Family> |
|
60 | + */ |
|
61 | + public function linkedFamilies(Certificate $certificate): Collection |
|
62 | + { |
|
63 | + $tree = $certificate->tree(); |
|
64 | + return DB::table('families') |
|
65 | + ->where('f_file', '=', $tree->id()) |
|
66 | + ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
67 | + ->select(['families.*']) |
|
68 | + ->get() |
|
69 | + ->map(Registry::familyFactory()->mapper($tree)) |
|
70 | + ->filter(GedcomRecord::accessFilter()); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * Find media objects linked to a certificate. |
|
75 | - * |
|
76 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
77 | - * but does not work with Sqlite if no default escape has been defined} |
|
78 | - * |
|
79 | - * @param Certificate $certificate |
|
80 | - * @return Collection<\Fisharebest\Webtrees\Media> |
|
81 | - */ |
|
82 | - public function linkedMedias(Certificate $certificate): Collection |
|
83 | - { |
|
84 | - $tree = $certificate->tree(); |
|
85 | - return DB::table('media') |
|
86 | - ->where('m_file', '=', $tree->id()) |
|
87 | - ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
88 | - ->select(['media.*']) |
|
89 | - ->get() |
|
90 | - ->map(Registry::mediaFactory()->mapper($tree)) |
|
91 | - ->filter(GedcomRecord::accessFilter()); |
|
92 | - } |
|
73 | + /** |
|
74 | + * Find media objects linked to a certificate. |
|
75 | + * |
|
76 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
77 | + * but does not work with Sqlite if no default escape has been defined} |
|
78 | + * |
|
79 | + * @param Certificate $certificate |
|
80 | + * @return Collection<\Fisharebest\Webtrees\Media> |
|
81 | + */ |
|
82 | + public function linkedMedias(Certificate $certificate): Collection |
|
83 | + { |
|
84 | + $tree = $certificate->tree(); |
|
85 | + return DB::table('media') |
|
86 | + ->where('m_file', '=', $tree->id()) |
|
87 | + ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
88 | + ->select(['media.*']) |
|
89 | + ->get() |
|
90 | + ->map(Registry::mediaFactory()->mapper($tree)) |
|
91 | + ->filter(GedcomRecord::accessFilter()); |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Find notes linked to a certificate. |
|
96 | - * |
|
97 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
98 | - * but does not work with Sqlite if no default escape has been defined} |
|
99 | - * |
|
100 | - * @param Certificate $certificate |
|
101 | - * @return Collection<\Fisharebest\Webtrees\Note> |
|
102 | - */ |
|
103 | - public function linkedNotes(Certificate $certificate): Collection |
|
104 | - { |
|
105 | - $tree = $certificate->tree(); |
|
106 | - return DB::table('other') |
|
107 | - ->where('o_file', '=', $tree->id()) |
|
108 | - ->where('o_type', '=', 'NOTE') |
|
109 | - ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
110 | - ->select(['other.*']) |
|
111 | - ->get() |
|
112 | - ->map(Registry::noteFactory()->mapper($tree)) |
|
113 | - ->filter(GedcomRecord::accessFilter()); |
|
114 | - } |
|
94 | + /** |
|
95 | + * Find notes linked to a certificate. |
|
96 | + * |
|
97 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
98 | + * but does not work with Sqlite if no default escape has been defined} |
|
99 | + * |
|
100 | + * @param Certificate $certificate |
|
101 | + * @return Collection<\Fisharebest\Webtrees\Note> |
|
102 | + */ |
|
103 | + public function linkedNotes(Certificate $certificate): Collection |
|
104 | + { |
|
105 | + $tree = $certificate->tree(); |
|
106 | + return DB::table('other') |
|
107 | + ->where('o_file', '=', $tree->id()) |
|
108 | + ->where('o_type', '=', 'NOTE') |
|
109 | + ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
110 | + ->select(['other.*']) |
|
111 | + ->get() |
|
112 | + ->map(Registry::noteFactory()->mapper($tree)) |
|
113 | + ->filter(GedcomRecord::accessFilter()); |
|
114 | + } |
|
115 | 115 | |
116 | - /** |
|
117 | - * Return an escaped string to be used in SQL LIKE comparisons. |
|
118 | - * This would not work well for Sqlite, if the escape character is not defined. |
|
119 | - * |
|
120 | - * @param Certificate $certificate |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - protected function escapedSqlPath(Certificate $certificate): string |
|
124 | - { |
|
125 | - return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $certificate->gedcomPath()); |
|
126 | - } |
|
116 | + /** |
|
117 | + * Return an escaped string to be used in SQL LIKE comparisons. |
|
118 | + * This would not work well for Sqlite, if the escape character is not defined. |
|
119 | + * |
|
120 | + * @param Certificate $certificate |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + protected function escapedSqlPath(Certificate $certificate): string |
|
124 | + { |
|
125 | + return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $certificate->gedcomPath()); |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Find a source linked to a citation where a certificate file is referenced. |
|
130 | - * |
|
131 | - * @param Certificate $certificate |
|
132 | - * @return Source|NULL |
|
133 | - */ |
|
134 | - public function oneLinkedSource(Certificate $certificate): ?Source |
|
135 | - { |
|
136 | - $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
|
137 | - $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
128 | + /** |
|
129 | + * Find a source linked to a citation where a certificate file is referenced. |
|
130 | + * |
|
131 | + * @param Certificate $certificate |
|
132 | + * @return Source|NULL |
|
133 | + */ |
|
134 | + public function oneLinkedSource(Certificate $certificate): ?Source |
|
135 | + { |
|
136 | + $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
|
137 | + $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
138 | 138 | |
139 | - foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
|
140 | - foreach ($linked_records as $gedcom_record) { |
|
141 | - foreach ($gedcom_record->facts() as $fact) { |
|
142 | - if (preg_match_all($regex_pattern, $fact->gedcom(), $matches, PREG_SET_ORDER) >= 1) { |
|
143 | - foreach ($matches as $match) { |
|
144 | - $source = Registry::sourceFactory()->make($match[1], $certificate->tree()); |
|
145 | - if ($source !== null && $source->canShowName()) { |
|
146 | - return $source; |
|
147 | - } |
|
148 | - } |
|
149 | - } |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
139 | + foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
|
140 | + foreach ($linked_records as $gedcom_record) { |
|
141 | + foreach ($gedcom_record->facts() as $fact) { |
|
142 | + if (preg_match_all($regex_pattern, $fact->gedcom(), $matches, PREG_SET_ORDER) >= 1) { |
|
143 | + foreach ($matches as $match) { |
|
144 | + $source = Registry::sourceFactory()->make($match[1], $certificate->tree()); |
|
145 | + if ($source !== null && $source->canShowName()) { |
|
146 | + return $source; |
|
147 | + } |
|
148 | + } |
|
149 | + } |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | 153 | |
154 | - return null; |
|
155 | - } |
|
154 | + return null; |
|
155 | + } |
|
156 | 156 | |
157 | - /** |
|
158 | - * Yield lists of gedcom records linked to a certificate. |
|
159 | - * |
|
160 | - * @param Certificate $certificate |
|
161 | - * @return Generator<int, Collection<GedcomRecord>, mixed, void> |
|
162 | - * @psalm-suppress InvalidReturnType |
|
163 | - */ |
|
164 | - protected function linkedRecordsLists(Certificate $certificate): Generator |
|
165 | - { |
|
166 | - yield $this->linkedIndividuals($certificate); |
|
167 | - yield $this->linkedFamilies($certificate); |
|
168 | - yield $this->linkedMedias($certificate); |
|
169 | - yield $this->linkedNotes($certificate); |
|
170 | - } |
|
157 | + /** |
|
158 | + * Yield lists of gedcom records linked to a certificate. |
|
159 | + * |
|
160 | + * @param Certificate $certificate |
|
161 | + * @return Generator<int, Collection<GedcomRecord>, mixed, void> |
|
162 | + * @psalm-suppress InvalidReturnType |
|
163 | + */ |
|
164 | + protected function linkedRecordsLists(Certificate $certificate): Generator |
|
165 | + { |
|
166 | + yield $this->linkedIndividuals($certificate); |
|
167 | + yield $this->linkedFamilies($certificate); |
|
168 | + yield $this->linkedMedias($certificate); |
|
169 | + yield $this->linkedNotes($certificate); |
|
170 | + } |
|
171 | 171 | } |
@@ -125,6 +125,6 @@ |
||
125 | 125 | */ |
126 | 126 | private function stringLengthEstimate(int $text_length, int $font_size): int |
127 | 127 | { |
128 | - return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
128 | + return $text_length * (int)ceil(($font_size + 2) * 0.5); |
|
129 | 129 | } |
130 | 130 | } |
@@ -19,112 +19,112 @@ |
||
19 | 19 | */ |
20 | 20 | class Watermark |
21 | 21 | { |
22 | - /** |
|
23 | - * Default font color for watermarks |
|
24 | - * @var string DEFAULT_COLOR |
|
25 | - * */ |
|
26 | - public const DEFAULT_COLOR = '#4D6DF3'; |
|
27 | - |
|
28 | - /** |
|
29 | - * Default maximum font size for watermarks |
|
30 | - * @var int DEFAULT_SIZE |
|
31 | - * */ |
|
32 | - public const DEFAULT_SIZE = 18; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string $text |
|
36 | - */ |
|
37 | - private $text; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string $color; |
|
41 | - */ |
|
42 | - private $color; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @var int $size |
|
47 | - */ |
|
48 | - private $size; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for Watermark data class |
|
52 | - * |
|
53 | - * @param string $text |
|
54 | - * @param string $color |
|
55 | - * @param int $size |
|
56 | - */ |
|
57 | - public function __construct(string $text, string $color, int $size) |
|
58 | - { |
|
59 | - $this->text = $text; |
|
60 | - $this->color = $color; |
|
61 | - $this->size = $size; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Get the watermark text. |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function text(): string |
|
70 | - { |
|
71 | - return $this->text; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Get the watermark font color. |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function color(): string |
|
80 | - { |
|
81 | - return $this->color; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Get the watermark maximum font size. |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public function size(): int |
|
89 | - { |
|
90 | - return $this->size; |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * Return an estimate of the size in pixels of the watermark text length. |
|
95 | - * |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function textLengthEstimate(): int |
|
99 | - { |
|
100 | - return $this->stringLengthEstimate(mb_strlen($this->text), $this->size); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Decrease the font size if necessary, based on the image width. |
|
105 | - * |
|
106 | - * @param int $width |
|
107 | - */ |
|
108 | - public function adjustSize(int $width): void |
|
109 | - { |
|
110 | - $len = mb_strlen($this->text); |
|
111 | - while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) { |
|
112 | - $this->size--; |
|
113 | - if ($this->size === 2) { |
|
114 | - return; |
|
115 | - } |
|
116 | - } |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Return an estimate of the size in pixels of a text in a specified font size. |
|
121 | - * |
|
122 | - * @param int $text_length |
|
123 | - * @param int $font_size |
|
124 | - * @return int |
|
125 | - */ |
|
126 | - private function stringLengthEstimate(int $text_length, int $font_size): int |
|
127 | - { |
|
128 | - return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
129 | - } |
|
22 | + /** |
|
23 | + * Default font color for watermarks |
|
24 | + * @var string DEFAULT_COLOR |
|
25 | + * */ |
|
26 | + public const DEFAULT_COLOR = '#4D6DF3'; |
|
27 | + |
|
28 | + /** |
|
29 | + * Default maximum font size for watermarks |
|
30 | + * @var int DEFAULT_SIZE |
|
31 | + * */ |
|
32 | + public const DEFAULT_SIZE = 18; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string $text |
|
36 | + */ |
|
37 | + private $text; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string $color; |
|
41 | + */ |
|
42 | + private $color; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @var int $size |
|
47 | + */ |
|
48 | + private $size; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for Watermark data class |
|
52 | + * |
|
53 | + * @param string $text |
|
54 | + * @param string $color |
|
55 | + * @param int $size |
|
56 | + */ |
|
57 | + public function __construct(string $text, string $color, int $size) |
|
58 | + { |
|
59 | + $this->text = $text; |
|
60 | + $this->color = $color; |
|
61 | + $this->size = $size; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Get the watermark text. |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function text(): string |
|
70 | + { |
|
71 | + return $this->text; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Get the watermark font color. |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function color(): string |
|
80 | + { |
|
81 | + return $this->color; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Get the watermark maximum font size. |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public function size(): int |
|
89 | + { |
|
90 | + return $this->size; |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * Return an estimate of the size in pixels of the watermark text length. |
|
95 | + * |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function textLengthEstimate(): int |
|
99 | + { |
|
100 | + return $this->stringLengthEstimate(mb_strlen($this->text), $this->size); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Decrease the font size if necessary, based on the image width. |
|
105 | + * |
|
106 | + * @param int $width |
|
107 | + */ |
|
108 | + public function adjustSize(int $width): void |
|
109 | + { |
|
110 | + $len = mb_strlen($this->text); |
|
111 | + while ($this->stringLengthEstimate($len, $this->size) > 0.9 * $width) { |
|
112 | + $this->size--; |
|
113 | + if ($this->size === 2) { |
|
114 | + return; |
|
115 | + } |
|
116 | + } |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Return an estimate of the size in pixels of a text in a specified font size. |
|
121 | + * |
|
122 | + * @param int $text_length |
|
123 | + * @param int $font_size |
|
124 | + * @return int |
|
125 | + */ |
|
126 | + private function stringLengthEstimate(int $text_length, int $font_size): int |
|
127 | + { |
|
128 | + return $text_length * (int) ceil(($font_size + 2) * 0.5); |
|
129 | + } |
|
130 | 130 | } |
@@ -202,11 +202,11 @@ |
||
202 | 202 | { |
203 | 203 | $sort_prefix = ''; |
204 | 204 | if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
205 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
205 | + $sort_prefix = implode('_', array_map(function($match) { |
|
206 | 206 | return $match[1]; |
207 | - }, $matches)) . '_'; |
|
207 | + }, $matches)).'_'; |
|
208 | 208 | } |
209 | - return $sort_prefix . $this->description(); |
|
209 | + return $sort_prefix.$this->description(); |
|
210 | 210 | } |
211 | 211 | |
212 | 212 | /** |
@@ -25,193 +25,193 @@ |
||
25 | 25 | */ |
26 | 26 | class Certificate |
27 | 27 | { |
28 | - /** |
|
29 | - * Pattern to extract information from a file name. |
|
30 | - * Specific to the author's workflow. |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | - |
|
35 | - private Tree $tree; |
|
36 | - private string $path; |
|
37 | - private ?string $city = null; |
|
38 | - private ?string $basename = null; |
|
39 | - private ?string $filename = null; |
|
40 | - private ?string $extension = null; |
|
41 | - private ?string $type = null; |
|
42 | - private ?string $description = null; |
|
43 | - private ?Date $date = null; |
|
44 | - |
|
45 | - /** |
|
46 | - * Contructor for Certificate |
|
47 | - * |
|
48 | - * @param Tree $tree |
|
49 | - * @param string $path |
|
50 | - */ |
|
51 | - public function __construct(Tree $tree, string $path) |
|
52 | - { |
|
53 | - $this->tree = $tree; |
|
54 | - $this->path = $path; |
|
55 | - $this->extractDataFromPath($path); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Populate fields from the filename, based on a predeterminate pattern. |
|
60 | - * Logic specific to the author. |
|
61 | - * |
|
62 | - * @param string $path |
|
63 | - */ |
|
64 | - protected function extractDataFromPath(string $path): void |
|
65 | - { |
|
66 | - $path_parts = pathinfo($this->gedcomPath()); |
|
67 | - $this->city = $path_parts['dirname'] ?? ''; |
|
68 | - $this->basename = $path_parts['basename']; |
|
69 | - $this->filename = $path_parts['filename']; |
|
70 | - $this->extension = strtoupper($path_parts['extension'] ?? ''); |
|
71 | - |
|
72 | - if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
73 | - $this->type = $match['type']; |
|
74 | - $this->description = $match['descr']; |
|
75 | - |
|
76 | - $day = $match['day'] ?? ''; |
|
77 | - $month_date = DateTime::createFromFormat('m', $match['month'] ?? ''); |
|
78 | - $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
79 | - $year = $match['year'] ?? ''; |
|
80 | - |
|
81 | - $this->date = new Date(sprintf('%s %s %s', $day, $month, $year)); |
|
82 | - } else { |
|
83 | - $this->description = $this->filename; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Get the family tree of the certificate |
|
89 | - * |
|
90 | - * @return Tree |
|
91 | - */ |
|
92 | - public function tree(): Tree |
|
93 | - { |
|
94 | - return $this->tree; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Get the path of the certificate in the file system. |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function path(): string |
|
103 | - { |
|
104 | - return $this->path; |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * The the path of the certificate, in a Gedcom canonical form. |
|
109 | - * |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - public function gedcomPath(): string |
|
113 | - { |
|
114 | - return str_replace('\\', '/', $this->path); |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Get the certificate name. |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - public function name(): string |
|
123 | - { |
|
124 | - return $this->filename ?? ''; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Get the certificate file name. |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function filename(): string |
|
133 | - { |
|
134 | - return $this->basename ?? ''; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Get the certificate's city (the first level folder). |
|
139 | - * |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function city(): string |
|
143 | - { |
|
144 | - return $this->city ?? ''; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Get the certificate's date. Extracted from the file name. |
|
149 | - * |
|
150 | - * @return Date |
|
151 | - */ |
|
152 | - public function date(): Date |
|
153 | - { |
|
154 | - return $this->date ?? new Date(''); |
|
155 | - } |
|
156 | - |
|
157 | - /** |
|
158 | - * Get the certificate's type. Extracted from the file name. |
|
159 | - * |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function type(): string |
|
163 | - { |
|
164 | - return $this->type ?? ''; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Get the certificate's description. Extracted from the file name. |
|
169 | - * @return string |
|
170 | - */ |
|
171 | - public function description(): string |
|
172 | - { |
|
173 | - return $this->description ?? ''; |
|
174 | - } |
|
175 | - |
|
176 | - /** |
|
177 | - * Get the certificate's description to be used for sorting. |
|
178 | - * This is based on surnames (at least 3 letters) found in the file name. |
|
179 | - * |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function sortDescription(): string |
|
183 | - { |
|
184 | - $sort_prefix = ''; |
|
185 | - if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
186 | - $sort_prefix = implode('_', array_map(function ($match) { |
|
187 | - return $match[1]; |
|
188 | - }, $matches)) . '_'; |
|
189 | - } |
|
190 | - return $sort_prefix . $this->description(); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Get the certificate's MIME type. |
|
195 | - * |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function mimeType(): string |
|
199 | - { |
|
200 | - return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
201 | - } |
|
202 | - |
|
203 | - /** |
|
204 | - * Get the base parameters to be used in url referencing the certificate. |
|
205 | - * |
|
206 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
207 | - * @return array{tree: string, cid: mixed} |
|
208 | - */ |
|
209 | - public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
210 | - { |
|
211 | - $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
212 | - return [ |
|
213 | - 'tree' => $this->tree->name(), |
|
214 | - 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
215 | - ]; |
|
216 | - } |
|
28 | + /** |
|
29 | + * Pattern to extract information from a file name. |
|
30 | + * Specific to the author's workflow. |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + private const FILENAME_PATTERN = '/^(?<year>\d{1,4})(\.(?<month>\d{1,2}))?(\.(?<day>\d{1,2}))?( (?<type>[A-Z]{1,2}))?\s(?<descr>.*)/'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
34 | + |
|
35 | + private Tree $tree; |
|
36 | + private string $path; |
|
37 | + private ?string $city = null; |
|
38 | + private ?string $basename = null; |
|
39 | + private ?string $filename = null; |
|
40 | + private ?string $extension = null; |
|
41 | + private ?string $type = null; |
|
42 | + private ?string $description = null; |
|
43 | + private ?Date $date = null; |
|
44 | + |
|
45 | + /** |
|
46 | + * Contructor for Certificate |
|
47 | + * |
|
48 | + * @param Tree $tree |
|
49 | + * @param string $path |
|
50 | + */ |
|
51 | + public function __construct(Tree $tree, string $path) |
|
52 | + { |
|
53 | + $this->tree = $tree; |
|
54 | + $this->path = $path; |
|
55 | + $this->extractDataFromPath($path); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Populate fields from the filename, based on a predeterminate pattern. |
|
60 | + * Logic specific to the author. |
|
61 | + * |
|
62 | + * @param string $path |
|
63 | + */ |
|
64 | + protected function extractDataFromPath(string $path): void |
|
65 | + { |
|
66 | + $path_parts = pathinfo($this->gedcomPath()); |
|
67 | + $this->city = $path_parts['dirname'] ?? ''; |
|
68 | + $this->basename = $path_parts['basename']; |
|
69 | + $this->filename = $path_parts['filename']; |
|
70 | + $this->extension = strtoupper($path_parts['extension'] ?? ''); |
|
71 | + |
|
72 | + if (preg_match(self::FILENAME_PATTERN, $this->filename, $match) === 1) { |
|
73 | + $this->type = $match['type']; |
|
74 | + $this->description = $match['descr']; |
|
75 | + |
|
76 | + $day = $match['day'] ?? ''; |
|
77 | + $month_date = DateTime::createFromFormat('m', $match['month'] ?? ''); |
|
78 | + $month = $month_date !== false ? strtoupper($month_date->format('M')) : ''; |
|
79 | + $year = $match['year'] ?? ''; |
|
80 | + |
|
81 | + $this->date = new Date(sprintf('%s %s %s', $day, $month, $year)); |
|
82 | + } else { |
|
83 | + $this->description = $this->filename; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Get the family tree of the certificate |
|
89 | + * |
|
90 | + * @return Tree |
|
91 | + */ |
|
92 | + public function tree(): Tree |
|
93 | + { |
|
94 | + return $this->tree; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Get the path of the certificate in the file system. |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function path(): string |
|
103 | + { |
|
104 | + return $this->path; |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * The the path of the certificate, in a Gedcom canonical form. |
|
109 | + * |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + public function gedcomPath(): string |
|
113 | + { |
|
114 | + return str_replace('\\', '/', $this->path); |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Get the certificate name. |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + public function name(): string |
|
123 | + { |
|
124 | + return $this->filename ?? ''; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Get the certificate file name. |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function filename(): string |
|
133 | + { |
|
134 | + return $this->basename ?? ''; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Get the certificate's city (the first level folder). |
|
139 | + * |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function city(): string |
|
143 | + { |
|
144 | + return $this->city ?? ''; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Get the certificate's date. Extracted from the file name. |
|
149 | + * |
|
150 | + * @return Date |
|
151 | + */ |
|
152 | + public function date(): Date |
|
153 | + { |
|
154 | + return $this->date ?? new Date(''); |
|
155 | + } |
|
156 | + |
|
157 | + /** |
|
158 | + * Get the certificate's type. Extracted from the file name. |
|
159 | + * |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function type(): string |
|
163 | + { |
|
164 | + return $this->type ?? ''; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Get the certificate's description. Extracted from the file name. |
|
169 | + * @return string |
|
170 | + */ |
|
171 | + public function description(): string |
|
172 | + { |
|
173 | + return $this->description ?? ''; |
|
174 | + } |
|
175 | + |
|
176 | + /** |
|
177 | + * Get the certificate's description to be used for sorting. |
|
178 | + * This is based on surnames (at least 3 letters) found in the file name. |
|
179 | + * |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function sortDescription(): string |
|
183 | + { |
|
184 | + $sort_prefix = ''; |
|
185 | + if (preg_match_all('/\b([A-Z]{3,})\b/', $this->description(), $matches, PREG_SET_ORDER) >= 1) { |
|
186 | + $sort_prefix = implode('_', array_map(function ($match) { |
|
187 | + return $match[1]; |
|
188 | + }, $matches)) . '_'; |
|
189 | + } |
|
190 | + return $sort_prefix . $this->description(); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Get the certificate's MIME type. |
|
195 | + * |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function mimeType(): string |
|
199 | + { |
|
200 | + return Mime::TYPES[$this->extension] ?? Mime::DEFAULT_TYPE; |
|
201 | + } |
|
202 | + |
|
203 | + /** |
|
204 | + * Get the base parameters to be used in url referencing the certificate. |
|
205 | + * |
|
206 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
207 | + * @return array{tree: string, cid: mixed} |
|
208 | + */ |
|
209 | + public function urlParameters(UrlObfuscatorService $url_obfuscator_service = null): array |
|
210 | + { |
|
211 | + $url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
212 | + return [ |
|
213 | + 'tree' => $this->tree->name(), |
|
214 | + 'cid' => $url_obfuscator_service->obfuscate($this->path) |
|
215 | + ]; |
|
216 | + } |
|
217 | 217 | } |
@@ -69,11 +69,11 @@ |
||
69 | 69 | { |
70 | 70 | list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
71 | 71 | |
72 | - $cities = array_map(function (string $item): array { |
|
72 | + $cities = array_map(function(string $item): array { |
|
73 | 73 | return [$this->url_obfuscator_service->obfuscate($item), $item]; |
74 | 74 | }, $this->certif_filesystem->cities($tree)); |
75 | 75 | |
76 | - return view($this->module->name() . '::components/edit-certificate', [ |
|
76 | + return view($this->module->name().'::components/edit-certificate', [ |
|
77 | 77 | 'module_name' => $this->module->name(), |
78 | 78 | 'tree' => $tree, |
79 | 79 | 'id' => $id, |
@@ -28,61 +28,61 @@ |
||
28 | 28 | */ |
29 | 29 | class SourceCertificate extends AbstractElement |
30 | 30 | { |
31 | - protected CertificatesModule $module; |
|
32 | - protected CertificateFilesystemService $certif_filesystem; |
|
33 | - protected UrlObfuscatorService $url_obfuscator_service; |
|
31 | + protected CertificatesModule $module; |
|
32 | + protected CertificateFilesystemService $certif_filesystem; |
|
33 | + protected UrlObfuscatorService $url_obfuscator_service; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Constructor for SourceCertificate element |
|
37 | - * |
|
38 | - * @param string $label |
|
39 | - * @param CertificatesModule $module |
|
40 | - * @param CertificateFilesystemService $certif_filesystem |
|
41 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
42 | - */ |
|
43 | - public function __construct( |
|
44 | - string $label, |
|
45 | - CertificatesModule $module, |
|
46 | - CertificateFilesystemService $certif_filesystem = null, |
|
47 | - UrlObfuscatorService $url_obfuscator_service = null |
|
48 | - ) { |
|
49 | - parent::__construct($label, null); |
|
50 | - $this->module = $module; |
|
51 | - $this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class); |
|
52 | - $this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
53 | - } |
|
35 | + /** |
|
36 | + * Constructor for SourceCertificate element |
|
37 | + * |
|
38 | + * @param string $label |
|
39 | + * @param CertificatesModule $module |
|
40 | + * @param CertificateFilesystemService $certif_filesystem |
|
41 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
42 | + */ |
|
43 | + public function __construct( |
|
44 | + string $label, |
|
45 | + CertificatesModule $module, |
|
46 | + CertificateFilesystemService $certif_filesystem = null, |
|
47 | + UrlObfuscatorService $url_obfuscator_service = null |
|
48 | + ) { |
|
49 | + parent::__construct($label, null); |
|
50 | + $this->module = $module; |
|
51 | + $this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class); |
|
52 | + $this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
|
58 | - */ |
|
59 | - public function canonical(string $value): string |
|
60 | - { |
|
61 | - return strtr($value, '\\', '/'); |
|
62 | - } |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
|
58 | + */ |
|
59 | + public function canonical(string $value): string |
|
60 | + { |
|
61 | + return strtr($value, '\\', '/'); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \Fisharebest\Webtrees\Elements\AbstractElement::edit() |
|
67 | - */ |
|
68 | - public function edit(string $id, string $name, string $value, Tree $tree): string |
|
69 | - { |
|
70 | - list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \Fisharebest\Webtrees\Elements\AbstractElement::edit() |
|
67 | + */ |
|
68 | + public function edit(string $id, string $name, string $value, Tree $tree): string |
|
69 | + { |
|
70 | + list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
|
71 | 71 | |
72 | - $cities = array_map(function (string $item): array { |
|
73 | - return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
74 | - }, $this->certif_filesystem->cities($tree)); |
|
72 | + $cities = array_map(function (string $item): array { |
|
73 | + return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
74 | + }, $this->certif_filesystem->cities($tree)); |
|
75 | 75 | |
76 | - return view($this->module->name() . '::components/edit-certificate', [ |
|
77 | - 'module_name' => $this->module->name(), |
|
78 | - 'tree' => $tree, |
|
79 | - 'id' => $id, |
|
80 | - 'name' => $name, |
|
81 | - 'cities' => $cities, |
|
82 | - 'value' => $this->canonical($value), |
|
83 | - 'value_city' => $city, |
|
84 | - 'value_file' => $file, |
|
85 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
86 | - ]); |
|
87 | - } |
|
76 | + return view($this->module->name() . '::components/edit-certificate', [ |
|
77 | + 'module_name' => $this->module->name(), |
|
78 | + 'tree' => $tree, |
|
79 | + 'id' => $id, |
|
80 | + 'name' => $name, |
|
81 | + 'cities' => $cities, |
|
82 | + 'value' => $this->canonical($value), |
|
83 | + 'value_city' => $city, |
|
84 | + 'value_file' => $file, |
|
85 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
86 | + ]); |
|
87 | + } |
|
88 | 88 | } |