@@ -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())->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())->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 | } |
@@ -22,77 +22,77 @@ |
||
22 | 22 | */ |
23 | 23 | class MapFeatureAnalysisData |
24 | 24 | { |
25 | - private int $count; |
|
26 | - private bool $in_map; |
|
27 | - /** |
|
28 | - * @var Collection<GeoAnalysisPlace> $places |
|
29 | - */ |
|
30 | - private Collection $places; |
|
25 | + private int $count; |
|
26 | + private bool $in_map; |
|
27 | + /** |
|
28 | + * @var Collection<GeoAnalysisPlace> $places |
|
29 | + */ |
|
30 | + private Collection $places; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Constructor for MapFeatureAnalysisData |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - $this->count = 0; |
|
38 | - $this->places = new Collection(); |
|
39 | - $this->in_map = false; |
|
40 | - } |
|
32 | + /** |
|
33 | + * Constructor for MapFeatureAnalysisData |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + $this->count = 0; |
|
38 | + $this->places = new Collection(); |
|
39 | + $this->in_map = false; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Get the list of places mapped to the feature |
|
44 | - * |
|
45 | - * @return Collection<GeoAnalysisPlace> |
|
46 | - */ |
|
47 | - public function places(): Collection |
|
48 | - { |
|
49 | - return $this->places; |
|
50 | - } |
|
42 | + /** |
|
43 | + * Get the list of places mapped to the feature |
|
44 | + * |
|
45 | + * @return Collection<GeoAnalysisPlace> |
|
46 | + */ |
|
47 | + public function places(): Collection |
|
48 | + { |
|
49 | + return $this->places; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get the count of analysis items occurring in the feature |
|
54 | - * |
|
55 | - * @return int |
|
56 | - */ |
|
57 | - public function count(): int |
|
58 | - { |
|
59 | - return $this->count; |
|
60 | - } |
|
52 | + /** |
|
53 | + * Get the count of analysis items occurring in the feature |
|
54 | + * |
|
55 | + * @return int |
|
56 | + */ |
|
57 | + public function count(): int |
|
58 | + { |
|
59 | + return $this->count; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * Check whether the feature exist in the target map |
|
64 | - * |
|
65 | - * @return bool |
|
66 | - */ |
|
67 | - public function existsInMap(): bool |
|
68 | - { |
|
69 | - return $this->in_map; |
|
70 | - } |
|
62 | + /** |
|
63 | + * Check whether the feature exist in the target map |
|
64 | + * |
|
65 | + * @return bool |
|
66 | + */ |
|
67 | + public function existsInMap(): bool |
|
68 | + { |
|
69 | + return $this->in_map; |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * Confirm that the feature exist in the target map |
|
74 | - * |
|
75 | - * @return $this |
|
76 | - */ |
|
77 | - public function tagAsExisting(): self |
|
78 | - { |
|
79 | - $this->in_map = true; |
|
80 | - return $this; |
|
81 | - } |
|
72 | + /** |
|
73 | + * Confirm that the feature exist in the target map |
|
74 | + * |
|
75 | + * @return $this |
|
76 | + */ |
|
77 | + public function tagAsExisting(): self |
|
78 | + { |
|
79 | + $this->in_map = true; |
|
80 | + return $this; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Add a GeoAnalysisPlace to the feature |
|
85 | - * |
|
86 | - * @param GeoAnalysisPlace $place |
|
87 | - * @param int $count |
|
88 | - * @return $this |
|
89 | - */ |
|
90 | - public function add(GeoAnalysisPlace $place, int $count): self |
|
91 | - { |
|
92 | - if (!$place->isExcluded()) { |
|
93 | - $this->places->add($place); |
|
94 | - $this->count += $count; |
|
95 | - } |
|
96 | - return $this; |
|
97 | - } |
|
83 | + /** |
|
84 | + * Add a GeoAnalysisPlace to the feature |
|
85 | + * |
|
86 | + * @param GeoAnalysisPlace $place |
|
87 | + * @param int $count |
|
88 | + * @return $this |
|
89 | + */ |
|
90 | + public function add(GeoAnalysisPlace $place, int $count): self |
|
91 | + { |
|
92 | + if (!$place->isExcluded()) { |
|
93 | + $this->places->add($place); |
|
94 | + $this->count += $count; |
|
95 | + } |
|
96 | + return $this; |
|
97 | + } |
|
98 | 98 | } |
@@ -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 array<int, \Brick\Geo\IO\GeoJSON\Feature> $features |
|
31 | - */ |
|
32 | - private array $features; |
|
29 | + /** |
|
30 | + * @var array<int, \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 array<int, \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 array<int, \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 | - [...$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 | + [...$this->features, ...$other->features] |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | } |
@@ -25,68 +25,68 @@ |
||
25 | 25 | */ |
26 | 26 | class TitlesCardHook implements NameAccordionExtenderInterface |
27 | 27 | { |
28 | - private ModuleInterface $module; |
|
28 | + private ModuleInterface $module; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Constructor for TitlesCardHook |
|
32 | - * |
|
33 | - * @param ModuleInterface $module |
|
34 | - */ |
|
35 | - public function __construct(ModuleInterface $module) |
|
36 | - { |
|
37 | - $this->module = $module; |
|
38 | - } |
|
30 | + /** |
|
31 | + * Constructor for TitlesCardHook |
|
32 | + * |
|
33 | + * @param ModuleInterface $module |
|
34 | + */ |
|
35 | + public function __construct(ModuleInterface $module) |
|
36 | + { |
|
37 | + $this->module = $module; |
|
38 | + } |
|
39 | 39 | |
40 | - /** |
|
41 | - * {@inheritDoc} |
|
42 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
43 | - */ |
|
44 | - public function module(): ModuleInterface |
|
45 | - { |
|
46 | - return $this->module; |
|
47 | - } |
|
40 | + /** |
|
41 | + * {@inheritDoc} |
|
42 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
43 | + */ |
|
44 | + public function module(): ModuleInterface |
|
45 | + { |
|
46 | + return $this->module; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritDoc} |
|
51 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\NameAccordionExtenderInterface::accordionCard() |
|
52 | - */ |
|
53 | - public function accordionCard(Individual $individual): string |
|
54 | - { |
|
55 | - $title_separator = $this->module->getPreference('MAJ_TITLE_PREFIX'); |
|
56 | - if ($title_separator === '') { |
|
57 | - return ''; |
|
58 | - } |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\NameAccordionExtenderInterface::accordionCard() |
|
52 | + */ |
|
53 | + public function accordionCard(Individual $individual): string |
|
54 | + { |
|
55 | + $title_separator = $this->module->getPreference('MAJ_TITLE_PREFIX'); |
|
56 | + if ($title_separator === '') { |
|
57 | + return ''; |
|
58 | + } |
|
59 | 59 | |
60 | - $titles = $this->individualTitles($individual, '/(.*?) ((' . $title_separator . ')(.*))/i'); |
|
60 | + $titles = $this->individualTitles($individual, '/(.*?) ((' . $title_separator . ')(.*))/i'); |
|
61 | 61 | |
62 | - return count($titles) === 0 ? '' : |
|
63 | - view($this->module()->name() . '::components/accordion-item-titles', [ 'titles' => $titles ]); |
|
64 | - } |
|
62 | + return count($titles) === 0 ? '' : |
|
63 | + view($this->module()->name() . '::components/accordion-item-titles', [ 'titles' => $titles ]); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * Extract the individual titles from the TITL tags. |
|
68 | - * Split the title based on a pattern to identify the title and the land it refers to. |
|
69 | - * |
|
70 | - * @param Individual $individual |
|
71 | - * @param string $pattern |
|
72 | - * @return array<string, string[]> |
|
73 | - */ |
|
74 | - protected function individualTitles(Individual $individual, string $pattern): array |
|
75 | - { |
|
76 | - $titles_list = []; |
|
77 | - /** @var \Illuminate\Support\Collection<string> $titles */ |
|
78 | - $titles = $individual->facts(['TITL']) |
|
79 | - ->sortByDesc(fn(Fact $fact) => $fact->date()->julianDay()) |
|
80 | - ->map(fn(Fact $fact) => $fact->value()); |
|
66 | + /** |
|
67 | + * Extract the individual titles from the TITL tags. |
|
68 | + * Split the title based on a pattern to identify the title and the land it refers to. |
|
69 | + * |
|
70 | + * @param Individual $individual |
|
71 | + * @param string $pattern |
|
72 | + * @return array<string, string[]> |
|
73 | + */ |
|
74 | + protected function individualTitles(Individual $individual, string $pattern): array |
|
75 | + { |
|
76 | + $titles_list = []; |
|
77 | + /** @var \Illuminate\Support\Collection<string> $titles */ |
|
78 | + $titles = $individual->facts(['TITL']) |
|
79 | + ->sortByDesc(fn(Fact $fact) => $fact->date()->julianDay()) |
|
80 | + ->map(fn(Fact $fact) => $fact->value()); |
|
81 | 81 | |
82 | - foreach ($titles as $title) { |
|
83 | - if (preg_match($pattern, $title, $match) === 1) { |
|
84 | - /** @var array<int, string> $match */ |
|
85 | - $titles_list[$match[1]][] = trim($match[2]); |
|
86 | - } else { |
|
87 | - $titles_list[$title][] = ''; |
|
88 | - } |
|
89 | - } |
|
90 | - return $titles_list; |
|
91 | - } |
|
82 | + foreach ($titles as $title) { |
|
83 | + if (preg_match($pattern, $title, $match) === 1) { |
|
84 | + /** @var array<int, string> $match */ |
|
85 | + $titles_list[$match[1]][] = trim($match[2]); |
|
86 | + } else { |
|
87 | + $titles_list[$title][] = ''; |
|
88 | + } |
|
89 | + } |
|
90 | + return $titles_list; |
|
91 | + } |
|
92 | 92 | } |
@@ -28,50 +28,50 @@ |
||
28 | 28 | */ |
29 | 29 | class AdminConfigAction implements RequestHandlerInterface |
30 | 30 | { |
31 | - private ?MiscExtensionsModule $module; |
|
31 | + private ?MiscExtensionsModule $module; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Constructor for AdminConfigPage Request Handler |
|
35 | - * |
|
36 | - * @param ModuleService $module_service |
|
37 | - */ |
|
38 | - public function __construct(ModuleService $module_service) |
|
39 | - { |
|
40 | - $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first(); |
|
41 | - } |
|
33 | + /** |
|
34 | + * Constructor for AdminConfigPage Request Handler |
|
35 | + * |
|
36 | + * @param ModuleService $module_service |
|
37 | + */ |
|
38 | + public function __construct(ModuleService $module_service) |
|
39 | + { |
|
40 | + $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first(); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
46 | - */ |
|
47 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
48 | - { |
|
49 | - if ($this->module === null) { |
|
50 | - FlashMessages::addMessage( |
|
51 | - I18N::translate('The attached module could not be found.'), |
|
52 | - 'danger' |
|
53 | - ); |
|
54 | - return redirect(route(AdminConfigPage::class)); |
|
55 | - } |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
46 | + */ |
|
47 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
48 | + { |
|
49 | + if ($this->module === null) { |
|
50 | + FlashMessages::addMessage( |
|
51 | + I18N::translate('The attached module could not be found.'), |
|
52 | + 'danger' |
|
53 | + ); |
|
54 | + return redirect(route(AdminConfigPage::class)); |
|
55 | + } |
|
56 | 56 | |
57 | - $this->module->setPreference( |
|
58 | - 'MAJ_TITLE_PREFIX', |
|
59 | - Validator::parsedBody($request)->string('MAJ_TITLE_PREFIX', '') |
|
60 | - ); |
|
61 | - $this->module->setPreference( |
|
62 | - 'MAJ_DISPLAY_CNIL', |
|
63 | - Validator::parsedBody($request)->string('MAJ_DISPLAY_CNIL', '') |
|
64 | - ); |
|
65 | - $this->module->setPreference( |
|
66 | - 'MAJ_CNIL_REFERENCE', |
|
67 | - Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '') |
|
68 | - ); |
|
57 | + $this->module->setPreference( |
|
58 | + 'MAJ_TITLE_PREFIX', |
|
59 | + Validator::parsedBody($request)->string('MAJ_TITLE_PREFIX', '') |
|
60 | + ); |
|
61 | + $this->module->setPreference( |
|
62 | + 'MAJ_DISPLAY_CNIL', |
|
63 | + Validator::parsedBody($request)->string('MAJ_DISPLAY_CNIL', '') |
|
64 | + ); |
|
65 | + $this->module->setPreference( |
|
66 | + 'MAJ_CNIL_REFERENCE', |
|
67 | + Validator::parsedBody($request)->string('MAJ_CNIL_REFERENCE', '') |
|
68 | + ); |
|
69 | 69 | |
70 | - FlashMessages::addMessage( |
|
71 | - I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
72 | - 'success' |
|
73 | - ); |
|
70 | + FlashMessages::addMessage( |
|
71 | + I18N::translate('The preferences for the module “%s” have been updated.', $this->module->title()), |
|
72 | + 'success' |
|
73 | + ); |
|
74 | 74 | |
75 | - return redirect(route(AdminConfigPage::class)); |
|
76 | - } |
|
75 | + return redirect(route(AdminConfigPage::class)); |
|
76 | + } |
|
77 | 77 | } |
@@ -32,89 +32,89 @@ |
||
32 | 32 | * Provide miscellaneous improvements to webtrees. |
33 | 33 | */ |
34 | 34 | class MiscExtensionsModule extends AbstractModule implements |
35 | - ModuleMyArtJaubInterface, |
|
36 | - ModuleConfigInterface, |
|
37 | - ModuleHookSubscriberInterface |
|
35 | + ModuleMyArtJaubInterface, |
|
36 | + ModuleConfigInterface, |
|
37 | + ModuleHookSubscriberInterface |
|
38 | 38 | { |
39 | - use ModuleMyArtJaubTrait { |
|
40 | - boot as traitBoot; |
|
41 | - } |
|
42 | - use ModuleConfigTrait; |
|
39 | + use ModuleMyArtJaubTrait { |
|
40 | + boot as traitBoot; |
|
41 | + } |
|
42 | + use ModuleConfigTrait; |
|
43 | 43 | |
44 | - /** |
|
45 | - * {@inheritDoc} |
|
46 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
47 | - */ |
|
48 | - public function title(): string |
|
49 | - { |
|
50 | - return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions'); |
|
51 | - } |
|
44 | + /** |
|
45 | + * {@inheritDoc} |
|
46 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
47 | + */ |
|
48 | + public function title(): string |
|
49 | + { |
|
50 | + return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions'); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * {@inheritDoc} |
|
55 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
56 | - */ |
|
57 | - public function description(): string |
|
58 | - { |
|
59 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
60 | - return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.'); |
|
61 | - } |
|
53 | + /** |
|
54 | + * {@inheritDoc} |
|
55 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
56 | + */ |
|
57 | + public function description(): string |
|
58 | + { |
|
59 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
60 | + return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.'); |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritDoc} |
|
65 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
66 | - */ |
|
67 | - public function boot(): void |
|
68 | - { |
|
69 | - $this->traitBoot(); |
|
70 | - View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy'); |
|
71 | - } |
|
63 | + /** |
|
64 | + * {@inheritDoc} |
|
65 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
66 | + */ |
|
67 | + public function boot(): void |
|
68 | + { |
|
69 | + $this->traitBoot(); |
|
70 | + View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy'); |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * {@inheritDoc} |
|
75 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
76 | - */ |
|
77 | - public function loadRoutes(Map $router): void |
|
78 | - { |
|
79 | - $router->attach('', '', static function (Map $router): void { |
|
73 | + /** |
|
74 | + * {@inheritDoc} |
|
75 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
76 | + */ |
|
77 | + public function loadRoutes(Map $router): void |
|
78 | + { |
|
79 | + $router->attach('', '', static function (Map $router): void { |
|
80 | 80 | |
81 | - $router->attach('', '/module-maj/misc', static function (Map $router): void { |
|
81 | + $router->attach('', '/module-maj/misc', static function (Map $router): void { |
|
82 | 82 | |
83 | - $router->attach('', '/config/admin', static function (Map $router): void { |
|
83 | + $router->attach('', '/config/admin', static function (Map $router): void { |
|
84 | 84 | |
85 | - $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
|
86 | - $router->post(AdminConfigAction::class, '', AdminConfigAction::class); |
|
87 | - }); |
|
88 | - }); |
|
89 | - }); |
|
90 | - } |
|
85 | + $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
|
86 | + $router->post(AdminConfigAction::class, '', AdminConfigAction::class); |
|
87 | + }); |
|
88 | + }); |
|
89 | + }); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * {@inheritDoc} |
|
94 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
95 | - */ |
|
96 | - public function customModuleVersion(): string |
|
97 | - { |
|
98 | - return '2.1.1-v.1'; |
|
99 | - } |
|
92 | + /** |
|
93 | + * {@inheritDoc} |
|
94 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
95 | + */ |
|
96 | + public function customModuleVersion(): string |
|
97 | + { |
|
98 | + return '2.1.1-v.1'; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * {@inheritDoc} |
|
103 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
104 | - */ |
|
105 | - public function getConfigLink(): string |
|
106 | - { |
|
107 | - return route(AdminConfigPage::class); |
|
108 | - } |
|
101 | + /** |
|
102 | + * {@inheritDoc} |
|
103 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
104 | + */ |
|
105 | + public function getConfigLink(): string |
|
106 | + { |
|
107 | + return route(AdminConfigPage::class); |
|
108 | + } |
|
109 | 109 | |
110 | - /** |
|
111 | - * {@inheritDoc} |
|
112 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
113 | - */ |
|
114 | - public function listSubscribedHooks(): array |
|
115 | - { |
|
116 | - return [ |
|
117 | - app()->makeWith(TitlesCardHook::class, [ 'module' => $this ]) |
|
118 | - ]; |
|
119 | - } |
|
110 | + /** |
|
111 | + * {@inheritDoc} |
|
112 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
113 | + */ |
|
114 | + public function listSubscribedHooks(): array |
|
115 | + { |
|
116 | + return [ |
|
117 | + app()->makeWith(TitlesCardHook::class, [ 'module' => $this ]) |
|
118 | + ]; |
|
119 | + } |
|
120 | 120 | } |
@@ -30,87 +30,87 @@ |
||
30 | 30 | */ |
31 | 31 | class SourceCertificateIconHook implements FactSourceTextExtenderInterface |
32 | 32 | { |
33 | - private CertificatesModule $module; |
|
34 | - private UrlObfuscatorService $url_obfuscator_service; |
|
33 | + private CertificatesModule $module; |
|
34 | + private UrlObfuscatorService $url_obfuscator_service; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for SourceCertificateIconHook |
|
38 | - * |
|
39 | - * @param CertificatesModule $module |
|
40 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
41 | - */ |
|
42 | - public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
43 | - { |
|
44 | - $this->module = $module; |
|
45 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
46 | - } |
|
36 | + /** |
|
37 | + * Constructor for SourceCertificateIconHook |
|
38 | + * |
|
39 | + * @param CertificatesModule $module |
|
40 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
41 | + */ |
|
42 | + public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
43 | + { |
|
44 | + $this->module = $module; |
|
45 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
51 | - */ |
|
52 | - public function module(): ModuleInterface |
|
53 | - { |
|
54 | - return $this->module; |
|
55 | - } |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
51 | + */ |
|
52 | + public function module(): ModuleInterface |
|
53 | + { |
|
54 | + return $this->module; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
60 | - */ |
|
61 | - public function factSourcePrepend(Tree $tree, $fact): string |
|
62 | - { |
|
63 | - $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
64 | - if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
65 | - $path = $this->extractPath($fact); |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
60 | + */ |
|
61 | + public function factSourcePrepend(Tree $tree, $fact): string |
|
62 | + { |
|
63 | + $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
64 | + if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
65 | + $path = $this->extractPath($fact); |
|
66 | 66 | |
67 | - if ($path !== '') { |
|
68 | - $certificate = new Certificate($tree, $path); |
|
69 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
70 | - 'module_name' => $this->module->name(), |
|
71 | - 'certificate' => $certificate, |
|
72 | - 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
73 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
74 | - ]); |
|
75 | - } |
|
76 | - } |
|
77 | - return ''; |
|
78 | - } |
|
67 | + if ($path !== '') { |
|
68 | + $certificate = new Certificate($tree, $path); |
|
69 | + return view($this->module->name() . '::components/certificate-icon', [ |
|
70 | + 'module_name' => $this->module->name(), |
|
71 | + 'certificate' => $certificate, |
|
72 | + 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
73 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
74 | + ]); |
|
75 | + } |
|
76 | + } |
|
77 | + return ''; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Extract path from the provided fact objet. |
|
82 | - * |
|
83 | - * @param \Fisharebest\Webtrees\Fact|array<array<\Fisharebest\Webtrees\Contracts\ElementInterface|string>> $fact |
|
84 | - * @return string |
|
85 | - * @psalm-suppress RedundantConditionGivenDocblockType |
|
86 | - */ |
|
87 | - private function extractPath($fact): string |
|
88 | - { |
|
89 | - if ($fact instanceof Fact && $fact->target() instanceof Source) { |
|
90 | - return $fact->attribute('_ACT'); |
|
91 | - } elseif ( |
|
92 | - is_array($fact) && count($fact) == 2 |
|
93 | - && null !== ($source_elements = $fact[0]) && is_array($source_elements) // @phpstan-ignore-line |
|
94 | - && null !== ($source_values = $fact[1]) && is_array($source_values) // @phpstan-ignore-line |
|
95 | - ) { |
|
96 | - foreach ($source_elements as $key => $element) { |
|
97 | - if ( |
|
98 | - $element instanceof SourceCertificate |
|
99 | - && isset($source_values[$key]) && is_string($source_values[$key]) |
|
100 | - ) { |
|
101 | - return $element->canonical($source_values[$key]); |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - return ''; |
|
106 | - } |
|
80 | + /** |
|
81 | + * Extract path from the provided fact objet. |
|
82 | + * |
|
83 | + * @param \Fisharebest\Webtrees\Fact|array<array<\Fisharebest\Webtrees\Contracts\ElementInterface|string>> $fact |
|
84 | + * @return string |
|
85 | + * @psalm-suppress RedundantConditionGivenDocblockType |
|
86 | + */ |
|
87 | + private function extractPath($fact): string |
|
88 | + { |
|
89 | + if ($fact instanceof Fact && $fact->target() instanceof Source) { |
|
90 | + return $fact->attribute('_ACT'); |
|
91 | + } elseif ( |
|
92 | + is_array($fact) && count($fact) == 2 |
|
93 | + && null !== ($source_elements = $fact[0]) && is_array($source_elements) // @phpstan-ignore-line |
|
94 | + && null !== ($source_values = $fact[1]) && is_array($source_values) // @phpstan-ignore-line |
|
95 | + ) { |
|
96 | + foreach ($source_elements as $key => $element) { |
|
97 | + if ( |
|
98 | + $element instanceof SourceCertificate |
|
99 | + && isset($source_values[$key]) && is_string($source_values[$key]) |
|
100 | + ) { |
|
101 | + return $element->canonical($source_values[$key]); |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + return ''; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * {@inheritDoc} |
|
110 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
111 | - */ |
|
112 | - public function factSourceAppend(Tree $tree, $fact): string |
|
113 | - { |
|
114 | - return ''; |
|
115 | - } |
|
108 | + /** |
|
109 | + * {@inheritDoc} |
|
110 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
111 | + */ |
|
112 | + public function factSourceAppend(Tree $tree, $fact): string |
|
113 | + { |
|
114 | + return ''; |
|
115 | + } |
|
116 | 116 | } |
@@ -39,164 +39,164 @@ |
||
39 | 39 | */ |
40 | 40 | class CertificateImageFactory extends ImageFactory implements ImageFactoryInterface |
41 | 41 | { |
42 | - /** |
|
43 | - * @var CertificateFilesystemService $filesystem_service |
|
44 | - */ |
|
45 | - private $filesystem_service; |
|
46 | - |
|
47 | - /** |
|
48 | - * Constructor for the Certificate Image Factory |
|
49 | - * |
|
50 | - * @param CertificateFilesystemService $filesystem_service |
|
51 | - */ |
|
52 | - public function __construct(CertificateFilesystemService $filesystem_service) |
|
53 | - { |
|
54 | - $this->filesystem_service = $filesystem_service; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Check is a file MIME type is supported by the system. |
|
59 | - * |
|
60 | - * @param string $mime |
|
61 | - * @return bool |
|
62 | - */ |
|
63 | - public function isMimeTypeSupported(string $mime): bool |
|
64 | - { |
|
65 | - return array_key_exists($mime, self::SUPPORTED_FORMATS); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * Create a full-size version of a certificate. |
|
70 | - * |
|
71 | - * @param Certificate $certificate |
|
72 | - * @param bool $add_watermark |
|
73 | - * @param Watermark $watermark |
|
74 | - * @throws InvalidArgumentException |
|
75 | - * @return ResponseInterface |
|
76 | - */ |
|
77 | - public function certificateFileResponse( |
|
78 | - Certificate $certificate, |
|
79 | - bool $add_watermark = false, |
|
80 | - Watermark $watermark = null |
|
81 | - ): ResponseInterface { |
|
82 | - $filesystem = $this->filesystem_service->filesystem($certificate->tree()); |
|
83 | - $filename = $certificate->path(); |
|
84 | - |
|
85 | - if (!$add_watermark) { |
|
86 | - return $this->fileResponse($filesystem, $filename, false); |
|
87 | - } |
|
88 | - |
|
89 | - try { |
|
90 | - $image = $this->imageManager()->make($filesystem->readStream($filename)); |
|
91 | - $image = $this->autorotateImage($image); |
|
92 | - |
|
93 | - if ($watermark == null) { |
|
94 | - throw new InvalidArgumentException('Watermark data not defined'); |
|
95 | - } |
|
96 | - |
|
97 | - $width = $image->width(); |
|
98 | - $height = $image->height(); |
|
99 | - |
|
100 | - $watermark->adjustSize($width); |
|
101 | - $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5); |
|
102 | - $watermark_y = $watermark->size() * 12 + 1; |
|
103 | - |
|
104 | - $font_definition = function (AbstractFont $font) use ($watermark): void { |
|
105 | - $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf'); |
|
106 | - $font->color($watermark->color()); |
|
107 | - $font->size($watermark->size()); |
|
108 | - $font->valign('top'); |
|
109 | - }; |
|
110 | - |
|
111 | - for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) { |
|
112 | - for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) { |
|
113 | - $image = $image->text($watermark->text(), $i, $j, $font_definition); |
|
114 | - } |
|
115 | - } |
|
116 | - |
|
117 | - $format = static::SUPPORTED_FORMATS[$image->mime()] ?? 'jpg'; |
|
118 | - $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY); |
|
119 | - $data = (string) $image->encode($format, $quality); |
|
120 | - |
|
121 | - return $this->imageResponse($data, $image->mime(), ''); |
|
122 | - } catch (NotReadableException $ex) { |
|
123 | - return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION)) |
|
124 | - ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
125 | - } catch (FilesystemException | UnableToReadFile $ex) { |
|
126 | - return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND); |
|
127 | - } catch (Throwable $ex) { |
|
128 | - return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR) |
|
129 | - ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
130 | - } |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * Does a full-sized certificate need a watermark? |
|
135 | - * |
|
136 | - * @param Certificate $certificate |
|
137 | - * @param UserInterface $user |
|
138 | - * @return bool |
|
139 | - */ |
|
140 | - public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool |
|
141 | - { |
|
142 | - $tree = $certificate->tree(); |
|
143 | - $watermark_level = (int) ($tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK', (string) Auth::PRIV_HIDE)); |
|
144 | - |
|
145 | - return Auth::accessLevel($tree, $user) > $watermark_level; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Neutralise the methods associated with MediaFile. |
|
150 | - */ |
|
151 | - |
|
152 | - /** |
|
153 | - * {@inheritDoc} |
|
154 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileResponse() |
|
155 | - */ |
|
156 | - public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface |
|
157 | - { |
|
158 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
159 | - } |
|
160 | - |
|
161 | - /** |
|
162 | - * {@inheritDoc} |
|
163 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileThumbnailResponse() |
|
164 | - */ |
|
165 | - public function mediaFileThumbnailResponse( |
|
166 | - MediaFile $media_file, |
|
167 | - int $width, |
|
168 | - int $height, |
|
169 | - string $fit, |
|
170 | - bool $add_watermark |
|
171 | - ): ResponseInterface { |
|
172 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * {@inheritDoc} |
|
177 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::createWatermark() |
|
178 | - */ |
|
179 | - public function createWatermark(int $width, int $height, MediaFile $media_file): Image |
|
180 | - { |
|
181 | - |
|
182 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * {@inheritDoc} |
|
187 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::fileNeedsWatermark() |
|
188 | - */ |
|
189 | - public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
190 | - { |
|
191 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * {@inheritDoc} |
|
196 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::thumbnailNeedsWatermark() |
|
197 | - */ |
|
198 | - public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
199 | - { |
|
200 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
201 | - } |
|
42 | + /** |
|
43 | + * @var CertificateFilesystemService $filesystem_service |
|
44 | + */ |
|
45 | + private $filesystem_service; |
|
46 | + |
|
47 | + /** |
|
48 | + * Constructor for the Certificate Image Factory |
|
49 | + * |
|
50 | + * @param CertificateFilesystemService $filesystem_service |
|
51 | + */ |
|
52 | + public function __construct(CertificateFilesystemService $filesystem_service) |
|
53 | + { |
|
54 | + $this->filesystem_service = $filesystem_service; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Check is a file MIME type is supported by the system. |
|
59 | + * |
|
60 | + * @param string $mime |
|
61 | + * @return bool |
|
62 | + */ |
|
63 | + public function isMimeTypeSupported(string $mime): bool |
|
64 | + { |
|
65 | + return array_key_exists($mime, self::SUPPORTED_FORMATS); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * Create a full-size version of a certificate. |
|
70 | + * |
|
71 | + * @param Certificate $certificate |
|
72 | + * @param bool $add_watermark |
|
73 | + * @param Watermark $watermark |
|
74 | + * @throws InvalidArgumentException |
|
75 | + * @return ResponseInterface |
|
76 | + */ |
|
77 | + public function certificateFileResponse( |
|
78 | + Certificate $certificate, |
|
79 | + bool $add_watermark = false, |
|
80 | + Watermark $watermark = null |
|
81 | + ): ResponseInterface { |
|
82 | + $filesystem = $this->filesystem_service->filesystem($certificate->tree()); |
|
83 | + $filename = $certificate->path(); |
|
84 | + |
|
85 | + if (!$add_watermark) { |
|
86 | + return $this->fileResponse($filesystem, $filename, false); |
|
87 | + } |
|
88 | + |
|
89 | + try { |
|
90 | + $image = $this->imageManager()->make($filesystem->readStream($filename)); |
|
91 | + $image = $this->autorotateImage($image); |
|
92 | + |
|
93 | + if ($watermark == null) { |
|
94 | + throw new InvalidArgumentException('Watermark data not defined'); |
|
95 | + } |
|
96 | + |
|
97 | + $width = $image->width(); |
|
98 | + $height = $image->height(); |
|
99 | + |
|
100 | + $watermark->adjustSize($width); |
|
101 | + $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5); |
|
102 | + $watermark_y = $watermark->size() * 12 + 1; |
|
103 | + |
|
104 | + $font_definition = function (AbstractFont $font) use ($watermark): void { |
|
105 | + $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf'); |
|
106 | + $font->color($watermark->color()); |
|
107 | + $font->size($watermark->size()); |
|
108 | + $font->valign('top'); |
|
109 | + }; |
|
110 | + |
|
111 | + for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) { |
|
112 | + for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) { |
|
113 | + $image = $image->text($watermark->text(), $i, $j, $font_definition); |
|
114 | + } |
|
115 | + } |
|
116 | + |
|
117 | + $format = static::SUPPORTED_FORMATS[$image->mime()] ?? 'jpg'; |
|
118 | + $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY); |
|
119 | + $data = (string) $image->encode($format, $quality); |
|
120 | + |
|
121 | + return $this->imageResponse($data, $image->mime(), ''); |
|
122 | + } catch (NotReadableException $ex) { |
|
123 | + return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION)) |
|
124 | + ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
125 | + } catch (FilesystemException | UnableToReadFile $ex) { |
|
126 | + return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND); |
|
127 | + } catch (Throwable $ex) { |
|
128 | + return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR) |
|
129 | + ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
130 | + } |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * Does a full-sized certificate need a watermark? |
|
135 | + * |
|
136 | + * @param Certificate $certificate |
|
137 | + * @param UserInterface $user |
|
138 | + * @return bool |
|
139 | + */ |
|
140 | + public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool |
|
141 | + { |
|
142 | + $tree = $certificate->tree(); |
|
143 | + $watermark_level = (int) ($tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK', (string) Auth::PRIV_HIDE)); |
|
144 | + |
|
145 | + return Auth::accessLevel($tree, $user) > $watermark_level; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Neutralise the methods associated with MediaFile. |
|
150 | + */ |
|
151 | + |
|
152 | + /** |
|
153 | + * {@inheritDoc} |
|
154 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileResponse() |
|
155 | + */ |
|
156 | + public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface |
|
157 | + { |
|
158 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
159 | + } |
|
160 | + |
|
161 | + /** |
|
162 | + * {@inheritDoc} |
|
163 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileThumbnailResponse() |
|
164 | + */ |
|
165 | + public function mediaFileThumbnailResponse( |
|
166 | + MediaFile $media_file, |
|
167 | + int $width, |
|
168 | + int $height, |
|
169 | + string $fit, |
|
170 | + bool $add_watermark |
|
171 | + ): ResponseInterface { |
|
172 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * {@inheritDoc} |
|
177 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::createWatermark() |
|
178 | + */ |
|
179 | + public function createWatermark(int $width, int $height, MediaFile $media_file): Image |
|
180 | + { |
|
181 | + |
|
182 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * {@inheritDoc} |
|
187 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::fileNeedsWatermark() |
|
188 | + */ |
|
189 | + public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
190 | + { |
|
191 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * {@inheritDoc} |
|
196 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::thumbnailNeedsWatermark() |
|
197 | + */ |
|
198 | + public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
199 | + { |
|
200 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
201 | + } |
|
202 | 202 | } |
@@ -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.1-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.1-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 | } |