@@ -28,15 +28,15 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | function hook(string $hook_interface, callable $apply, $default = null) |
| 30 | 30 | { |
| 31 | - try { |
|
| 32 | - $hook_collector = app(HookServiceInterface::class)->use($hook_interface); |
|
| 33 | - if ($hook_collector !== null) { |
|
| 34 | - return $apply($hook_collector); |
|
| 35 | - } |
|
| 36 | - } catch (BindingResolutionException $ex) { |
|
| 37 | - } |
|
| 31 | + try { |
|
| 32 | + $hook_collector = app(HookServiceInterface::class)->use($hook_interface); |
|
| 33 | + if ($hook_collector !== null) { |
|
| 34 | + return $apply($hook_collector); |
|
| 35 | + } |
|
| 36 | + } catch (BindingResolutionException $ex) { |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - return $default; |
|
| 39 | + return $default; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -48,5 +48,5 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function columnIndex(int $initial_index, Collection $new_column_indexes): int |
| 50 | 50 | { |
| 51 | - return $initial_index + $new_column_indexes->filter(fn(int $i) => $i <= $initial_index)->count(); |
|
| 51 | + return $initial_index + $new_column_indexes->filter(fn(int $i) => $i <= $initial_index)->count(); |
|
| 52 | 52 | } |
@@ -24,225 +24,225 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class GeoAnalysisResult |
| 26 | 26 | { |
| 27 | - private string $description; |
|
| 28 | - private int $order; |
|
| 29 | - private int $unknown_count; |
|
| 30 | - /** |
|
| 31 | - * @var Collection<GeoAnalysisResultItem> |
|
| 32 | - */ |
|
| 33 | - private Collection $places; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Constructor for GeoAnalysisResult |
|
| 37 | - * |
|
| 38 | - * @param string $description |
|
| 39 | - * @param int $order |
|
| 40 | - * @param Collection<GeoAnalysisResultItem> $places |
|
| 41 | - * @param int $unknown |
|
| 42 | - */ |
|
| 43 | - final public function __construct( |
|
| 44 | - string $description, |
|
| 45 | - int $order = 0, |
|
| 46 | - Collection $places = null, |
|
| 47 | - int $unknown = 0 |
|
| 48 | - ) { |
|
| 49 | - $this->description = $description; |
|
| 50 | - $this->order = $order; |
|
| 51 | - $this->places = $places ?? new Collection(); |
|
| 52 | - $this->unknown_count = $unknown; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Get the category description |
|
| 57 | - * |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function description(): string |
|
| 61 | - { |
|
| 62 | - return $this->description; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Get the category order |
|
| 67 | - * |
|
| 68 | - * @return int |
|
| 69 | - */ |
|
| 70 | - public function order(): int |
|
| 71 | - { |
|
| 72 | - return $this->order; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Add a place to the analysis result |
|
| 77 | - * |
|
| 78 | - * @param GeoAnalysisPlace $place |
|
| 79 | - */ |
|
| 80 | - public function addPlace(GeoAnalysisPlace $place): void |
|
| 81 | - { |
|
| 82 | - if ($place->isKnown()) { |
|
| 83 | - /** @var GeoAnalysisResultItem $item */ |
|
| 84 | - $item = $this->places->get($place->key(), new GeoAnalysisResultItem($place)); |
|
| 85 | - $this->places->put($item->key(), $item->increment()); |
|
| 86 | - } else { |
|
| 87 | - $this->addUnknown(); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Exclude a place from the analysis result |
|
| 93 | - * |
|
| 94 | - * @param GeoAnalysisPlace $place |
|
| 95 | - */ |
|
| 96 | - public function exclude(GeoAnalysisPlace $place): void |
|
| 97 | - { |
|
| 98 | - /** @var GeoAnalysisResultItem|null $item */ |
|
| 99 | - $item = $this->places->get($place->key()); |
|
| 100 | - if ($item !== null) { |
|
| 101 | - $item->place()->exclude(); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Add an unknown place to the analysis result |
|
| 107 | - */ |
|
| 108 | - public function addUnknown(): void |
|
| 109 | - { |
|
| 110 | - $this->unknown_count++; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Take a copy of the current analysis result |
|
| 115 | - * |
|
| 116 | - * @return static |
|
| 117 | - */ |
|
| 118 | - public function copy(): self |
|
| 119 | - { |
|
| 120 | - return new static( |
|
| 121 | - $this->description(), |
|
| 122 | - $this->order(), |
|
| 123 | - $this->places->map(fn(GeoAnalysisResultItem $item): GeoAnalysisResultItem => clone $item), |
|
| 124 | - $this->countUnknown() |
|
| 125 | - ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Merge the current analysis result with another. |
|
| 130 | - * The current object is modified, not the second one. |
|
| 131 | - * |
|
| 132 | - * @param GeoAnalysisResult $other |
|
| 133 | - * @return $this |
|
| 134 | - */ |
|
| 135 | - public function merge(GeoAnalysisResult $other): self |
|
| 136 | - { |
|
| 137 | - $this->places->each(function (GeoAnalysisResultItem $item) use ($other): void { |
|
| 138 | - if ($other->places->has($item->key())) { |
|
| 139 | - $item->place()->exclude( |
|
| 140 | - $item->place()->isExcluded() |
|
| 141 | - && $other->places->get($item->key())->place()->isExcluded() |
|
| 142 | - ); |
|
| 143 | - } |
|
| 144 | - }); |
|
| 145 | - |
|
| 146 | - $other->places->each(function (GeoAnalysisResultItem $item): void { |
|
| 147 | - if (!$this->places->has($item->key())) { |
|
| 148 | - $this->addPlace($item->place()); |
|
| 149 | - } |
|
| 150 | - }); |
|
| 151 | - |
|
| 152 | - return $this; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Get the count of Known places |
|
| 157 | - * |
|
| 158 | - * @return int |
|
| 159 | - */ |
|
| 160 | - public function countKnown(): int |
|
| 161 | - { |
|
| 162 | - return $this->places->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Get the count of Found places |
|
| 167 | - * |
|
| 168 | - * @return int |
|
| 169 | - */ |
|
| 170 | - public function countFound(): int |
|
| 171 | - { |
|
| 172 | - return $this->places |
|
| 173 | - ->reject(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()) |
|
| 174 | - ->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Get the count of Excluded places |
|
| 179 | - * |
|
| 180 | - * @return int |
|
| 181 | - */ |
|
| 182 | - public function countExcluded(): int |
|
| 183 | - { |
|
| 184 | - return $this->places |
|
| 185 | - ->filter(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()) |
|
| 186 | - ->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - /** |
|
| 190 | - * Get the count of Unknown places |
|
| 191 | - * |
|
| 192 | - * @return int |
|
| 193 | - */ |
|
| 194 | - public function countUnknown(): int |
|
| 195 | - { |
|
| 196 | - return $this->unknown_count; |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Get the count of the most represented Place in the analysis result |
|
| 201 | - * |
|
| 202 | - * @return int |
|
| 203 | - */ |
|
| 204 | - public function maxCount(): int |
|
| 205 | - { |
|
| 206 | - return $this->places->max(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Get the list of Known places with their associated count |
|
| 211 | - * |
|
| 212 | - * @param bool $exclude_other |
|
| 213 | - * @return Collection<GeoAnalysisResultItem> |
|
| 214 | - */ |
|
| 215 | - public function knownPlaces(bool $exclude_other = false): Collection |
|
| 216 | - { |
|
| 217 | - if ($exclude_other) { |
|
| 218 | - return $this->places->reject(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()); |
|
| 219 | - } |
|
| 220 | - return $this->places; |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * Get the list of Known places with their associated count. |
|
| 225 | - * The list is sorted first by descending count, then by ascending Place name |
|
| 226 | - * |
|
| 227 | - * @param bool $exclude_other |
|
| 228 | - * @return Collection<GeoAnalysisResultItem> |
|
| 229 | - */ |
|
| 230 | - public function sortedKnownPlaces(bool $exclude_other = false): Collection |
|
| 231 | - { |
|
| 232 | - return $this->knownPlaces($exclude_other)->sortBy([ |
|
| 233 | - fn (GeoAnalysisResultItem $a, GeoAnalysisResultItem $b): int => $b->count() <=> $a->count(), |
|
| 234 | - fn (GeoAnalysisResultItem $a, GeoAnalysisResultItem $b): int => |
|
| 235 | - I18N::comparator()($a->place()->place()->gedcomName(), $b->place()->place()->gedcomName()) |
|
| 236 | - ]); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - /** |
|
| 240 | - * Get the list of Excluded places |
|
| 241 | - * |
|
| 242 | - * @return Collection<GeoAnalysisResultItem> |
|
| 243 | - */ |
|
| 244 | - public function excludedPlaces(): Collection |
|
| 245 | - { |
|
| 246 | - return $this->places->filter(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()); |
|
| 247 | - } |
|
| 27 | + private string $description; |
|
| 28 | + private int $order; |
|
| 29 | + private int $unknown_count; |
|
| 30 | + /** |
|
| 31 | + * @var Collection<GeoAnalysisResultItem> |
|
| 32 | + */ |
|
| 33 | + private Collection $places; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Constructor for GeoAnalysisResult |
|
| 37 | + * |
|
| 38 | + * @param string $description |
|
| 39 | + * @param int $order |
|
| 40 | + * @param Collection<GeoAnalysisResultItem> $places |
|
| 41 | + * @param int $unknown |
|
| 42 | + */ |
|
| 43 | + final public function __construct( |
|
| 44 | + string $description, |
|
| 45 | + int $order = 0, |
|
| 46 | + Collection $places = null, |
|
| 47 | + int $unknown = 0 |
|
| 48 | + ) { |
|
| 49 | + $this->description = $description; |
|
| 50 | + $this->order = $order; |
|
| 51 | + $this->places = $places ?? new Collection(); |
|
| 52 | + $this->unknown_count = $unknown; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Get the category description |
|
| 57 | + * |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function description(): string |
|
| 61 | + { |
|
| 62 | + return $this->description; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Get the category order |
|
| 67 | + * |
|
| 68 | + * @return int |
|
| 69 | + */ |
|
| 70 | + public function order(): int |
|
| 71 | + { |
|
| 72 | + return $this->order; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Add a place to the analysis result |
|
| 77 | + * |
|
| 78 | + * @param GeoAnalysisPlace $place |
|
| 79 | + */ |
|
| 80 | + public function addPlace(GeoAnalysisPlace $place): void |
|
| 81 | + { |
|
| 82 | + if ($place->isKnown()) { |
|
| 83 | + /** @var GeoAnalysisResultItem $item */ |
|
| 84 | + $item = $this->places->get($place->key(), new GeoAnalysisResultItem($place)); |
|
| 85 | + $this->places->put($item->key(), $item->increment()); |
|
| 86 | + } else { |
|
| 87 | + $this->addUnknown(); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Exclude a place from the analysis result |
|
| 93 | + * |
|
| 94 | + * @param GeoAnalysisPlace $place |
|
| 95 | + */ |
|
| 96 | + public function exclude(GeoAnalysisPlace $place): void |
|
| 97 | + { |
|
| 98 | + /** @var GeoAnalysisResultItem|null $item */ |
|
| 99 | + $item = $this->places->get($place->key()); |
|
| 100 | + if ($item !== null) { |
|
| 101 | + $item->place()->exclude(); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Add an unknown place to the analysis result |
|
| 107 | + */ |
|
| 108 | + public function addUnknown(): void |
|
| 109 | + { |
|
| 110 | + $this->unknown_count++; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Take a copy of the current analysis result |
|
| 115 | + * |
|
| 116 | + * @return static |
|
| 117 | + */ |
|
| 118 | + public function copy(): self |
|
| 119 | + { |
|
| 120 | + return new static( |
|
| 121 | + $this->description(), |
|
| 122 | + $this->order(), |
|
| 123 | + $this->places->map(fn(GeoAnalysisResultItem $item): GeoAnalysisResultItem => clone $item), |
|
| 124 | + $this->countUnknown() |
|
| 125 | + ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Merge the current analysis result with another. |
|
| 130 | + * The current object is modified, not the second one. |
|
| 131 | + * |
|
| 132 | + * @param GeoAnalysisResult $other |
|
| 133 | + * @return $this |
|
| 134 | + */ |
|
| 135 | + public function merge(GeoAnalysisResult $other): self |
|
| 136 | + { |
|
| 137 | + $this->places->each(function (GeoAnalysisResultItem $item) use ($other): void { |
|
| 138 | + if ($other->places->has($item->key())) { |
|
| 139 | + $item->place()->exclude( |
|
| 140 | + $item->place()->isExcluded() |
|
| 141 | + && $other->places->get($item->key())->place()->isExcluded() |
|
| 142 | + ); |
|
| 143 | + } |
|
| 144 | + }); |
|
| 145 | + |
|
| 146 | + $other->places->each(function (GeoAnalysisResultItem $item): void { |
|
| 147 | + if (!$this->places->has($item->key())) { |
|
| 148 | + $this->addPlace($item->place()); |
|
| 149 | + } |
|
| 150 | + }); |
|
| 151 | + |
|
| 152 | + return $this; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Get the count of Known places |
|
| 157 | + * |
|
| 158 | + * @return int |
|
| 159 | + */ |
|
| 160 | + public function countKnown(): int |
|
| 161 | + { |
|
| 162 | + return $this->places->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Get the count of Found places |
|
| 167 | + * |
|
| 168 | + * @return int |
|
| 169 | + */ |
|
| 170 | + public function countFound(): int |
|
| 171 | + { |
|
| 172 | + return $this->places |
|
| 173 | + ->reject(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()) |
|
| 174 | + ->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Get the count of Excluded places |
|
| 179 | + * |
|
| 180 | + * @return int |
|
| 181 | + */ |
|
| 182 | + public function countExcluded(): int |
|
| 183 | + { |
|
| 184 | + return $this->places |
|
| 185 | + ->filter(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()) |
|
| 186 | + ->sum(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + /** |
|
| 190 | + * Get the count of Unknown places |
|
| 191 | + * |
|
| 192 | + * @return int |
|
| 193 | + */ |
|
| 194 | + public function countUnknown(): int |
|
| 195 | + { |
|
| 196 | + return $this->unknown_count; |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Get the count of the most represented Place in the analysis result |
|
| 201 | + * |
|
| 202 | + * @return int |
|
| 203 | + */ |
|
| 204 | + public function maxCount(): int |
|
| 205 | + { |
|
| 206 | + return $this->places->max(fn(GeoAnalysisResultItem $item): int => $item->count()) ?? 0; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Get the list of Known places with their associated count |
|
| 211 | + * |
|
| 212 | + * @param bool $exclude_other |
|
| 213 | + * @return Collection<GeoAnalysisResultItem> |
|
| 214 | + */ |
|
| 215 | + public function knownPlaces(bool $exclude_other = false): Collection |
|
| 216 | + { |
|
| 217 | + if ($exclude_other) { |
|
| 218 | + return $this->places->reject(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()); |
|
| 219 | + } |
|
| 220 | + return $this->places; |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * Get the list of Known places with their associated count. |
|
| 225 | + * The list is sorted first by descending count, then by ascending Place name |
|
| 226 | + * |
|
| 227 | + * @param bool $exclude_other |
|
| 228 | + * @return Collection<GeoAnalysisResultItem> |
|
| 229 | + */ |
|
| 230 | + public function sortedKnownPlaces(bool $exclude_other = false): Collection |
|
| 231 | + { |
|
| 232 | + return $this->knownPlaces($exclude_other)->sortBy([ |
|
| 233 | + fn (GeoAnalysisResultItem $a, GeoAnalysisResultItem $b): int => $b->count() <=> $a->count(), |
|
| 234 | + fn (GeoAnalysisResultItem $a, GeoAnalysisResultItem $b): int => |
|
| 235 | + I18N::comparator()($a->place()->place()->gedcomName(), $b->place()->place()->gedcomName()) |
|
| 236 | + ]); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + /** |
|
| 240 | + * Get the list of Excluded places |
|
| 241 | + * |
|
| 242 | + * @return Collection<GeoAnalysisResultItem> |
|
| 243 | + */ |
|
| 244 | + public function excludedPlaces(): Collection |
|
| 245 | + { |
|
| 246 | + return $this->places->filter(fn(GeoAnalysisResultItem $item): bool => $item->place()->isExcluded()); |
|
| 247 | + } |
|
| 248 | 248 | } |
@@ -27,59 +27,59 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class SimpleFilesystemMap implements MapDefinitionInterface |
| 29 | 29 | { |
| 30 | - private string $id; |
|
| 31 | - private string $title; |
|
| 32 | - private string $path; |
|
| 33 | - private FilesystemReader $filesystem; |
|
| 30 | + private string $id; |
|
| 31 | + private string $title; |
|
| 32 | + private string $path; |
|
| 33 | + private FilesystemReader $filesystem; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor for SimpleFilesystemMap |
|
| 37 | - * |
|
| 38 | - * @param string $id |
|
| 39 | - * @param string $title |
|
| 40 | - * @param FilesystemReader $filesystem |
|
| 41 | - * @param string $path |
|
| 42 | - */ |
|
| 43 | - public function __construct(string $id, string $title, FilesystemReader $filesystem, string $path) |
|
| 44 | - { |
|
| 45 | - $this->id = $id; |
|
| 46 | - $this->title = $title; |
|
| 47 | - $this->filesystem = $filesystem; |
|
| 48 | - $this->path = $path; |
|
| 49 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor for SimpleFilesystemMap |
|
| 37 | + * |
|
| 38 | + * @param string $id |
|
| 39 | + * @param string $title |
|
| 40 | + * @param FilesystemReader $filesystem |
|
| 41 | + * @param string $path |
|
| 42 | + */ |
|
| 43 | + public function __construct(string $id, string $title, FilesystemReader $filesystem, string $path) |
|
| 44 | + { |
|
| 45 | + $this->id = $id; |
|
| 46 | + $this->title = $title; |
|
| 47 | + $this->filesystem = $filesystem; |
|
| 48 | + $this->path = $path; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * {@inheritDoc} |
|
| 53 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::id() |
|
| 54 | - */ |
|
| 55 | - public function id(): string |
|
| 56 | - { |
|
| 57 | - return $this->id; |
|
| 58 | - } |
|
| 51 | + /** |
|
| 52 | + * {@inheritDoc} |
|
| 53 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::id() |
|
| 54 | + */ |
|
| 55 | + public function id(): string |
|
| 56 | + { |
|
| 57 | + return $this->id; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * {@inheritDoc} |
|
| 62 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::title() |
|
| 63 | - */ |
|
| 64 | - public function title(): string |
|
| 65 | - { |
|
| 66 | - return $this->title; |
|
| 67 | - } |
|
| 60 | + /** |
|
| 61 | + * {@inheritDoc} |
|
| 62 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::title() |
|
| 63 | + */ |
|
| 64 | + public function title(): string |
|
| 65 | + { |
|
| 66 | + return $this->title; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * {@inheritDoc} |
|
| 71 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::features() |
|
| 72 | - */ |
|
| 73 | - public function features(): array |
|
| 74 | - { |
|
| 75 | - $reader = new GeoJSONReader(); |
|
| 76 | - try { |
|
| 77 | - $feature_collection = $reader->read($this->filesystem->read($this->path)); |
|
| 78 | - if ($feature_collection instanceof FeatureCollection) { |
|
| 79 | - return $feature_collection->getFeatures(); |
|
| 80 | - } |
|
| 81 | - } catch (Throwable $ex) { |
|
| 82 | - } |
|
| 83 | - return []; |
|
| 84 | - } |
|
| 69 | + /** |
|
| 70 | + * {@inheritDoc} |
|
| 71 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapDefinitionInterface::features() |
|
| 72 | + */ |
|
| 73 | + public function features(): array |
|
| 74 | + { |
|
| 75 | + $reader = new GeoJSONReader(); |
|
| 76 | + try { |
|
| 77 | + $feature_collection = $reader->read($this->filesystem->read($this->path)); |
|
| 78 | + if ($feature_collection instanceof FeatureCollection) { |
|
| 79 | + return $feature_collection->getFeatures(); |
|
| 80 | + } |
|
| 81 | + } catch (Throwable $ex) { |
|
| 82 | + } |
|
| 83 | + return []; |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -23,51 +23,51 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class MapViewConfig implements MapViewConfigInterface |
| 25 | 25 | { |
| 26 | - private string $map_mapping_property; |
|
| 27 | - private PlaceMapperConfigInterface $mapper_config; |
|
| 26 | + private string $map_mapping_property; |
|
| 27 | + private PlaceMapperConfigInterface $mapper_config; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Constructor for MapViewConfig |
|
| 31 | - * |
|
| 32 | - * @param string $map_mapping_property |
|
| 33 | - * @param PlaceMapperConfigInterface $mapper_config |
|
| 34 | - */ |
|
| 35 | - public function __construct( |
|
| 36 | - string $map_mapping_property, |
|
| 37 | - PlaceMapperConfigInterface $mapper_config = null |
|
| 38 | - ) { |
|
| 39 | - $this->map_mapping_property = $map_mapping_property; |
|
| 40 | - $this->mapper_config = $mapper_config ?? new NullPlaceMapperConfig(); |
|
| 41 | - } |
|
| 29 | + /** |
|
| 30 | + * Constructor for MapViewConfig |
|
| 31 | + * |
|
| 32 | + * @param string $map_mapping_property |
|
| 33 | + * @param PlaceMapperConfigInterface $mapper_config |
|
| 34 | + */ |
|
| 35 | + public function __construct( |
|
| 36 | + string $map_mapping_property, |
|
| 37 | + PlaceMapperConfigInterface $mapper_config = null |
|
| 38 | + ) { |
|
| 39 | + $this->map_mapping_property = $map_mapping_property; |
|
| 40 | + $this->mapper_config = $mapper_config ?? new NullPlaceMapperConfig(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * {@inheritDoc} |
|
| 45 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapMappingProperty() |
|
| 46 | - */ |
|
| 47 | - public function mapMappingProperty(): string |
|
| 48 | - { |
|
| 49 | - return $this->map_mapping_property; |
|
| 50 | - } |
|
| 43 | + /** |
|
| 44 | + * {@inheritDoc} |
|
| 45 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapMappingProperty() |
|
| 46 | + */ |
|
| 47 | + public function mapMappingProperty(): string |
|
| 48 | + { |
|
| 49 | + return $this->map_mapping_property; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapperConfig() |
|
| 55 | - */ |
|
| 56 | - public function mapperConfig(): PlaceMapperConfigInterface |
|
| 57 | - { |
|
| 58 | - return $this->mapper_config; |
|
| 59 | - } |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::mapperConfig() |
|
| 55 | + */ |
|
| 56 | + public function mapperConfig(): PlaceMapperConfigInterface |
|
| 57 | + { |
|
| 58 | + return $this->mapper_config; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritDoc} |
|
| 63 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::with() |
|
| 64 | - * @return static |
|
| 65 | - */ |
|
| 66 | - public function with(string $mapping_property, PlaceMapperConfigInterface $mapper_config): self |
|
| 67 | - { |
|
| 68 | - $new = clone $this; |
|
| 69 | - $new->map_mapping_property = $mapping_property; |
|
| 70 | - $new->mapper_config = $mapper_config; |
|
| 71 | - return $new; |
|
| 72 | - } |
|
| 61 | + /** |
|
| 62 | + * {@inheritDoc} |
|
| 63 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\MapViewConfigInterface::with() |
|
| 64 | + * @return static |
|
| 65 | + */ |
|
| 66 | + public function with(string $mapping_property, PlaceMapperConfigInterface $mapper_config): self |
|
| 67 | + { |
|
| 68 | + $new = clone $this; |
|
| 69 | + $new->map_mapping_property = $mapping_property; |
|
| 70 | + $new->mapper_config = $mapper_config; |
|
| 71 | + return $new; |
|
| 72 | + } |
|
| 73 | 73 | } |
@@ -32,129 +32,129 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class CertificateFilesystemService |
| 34 | 34 | { |
| 35 | - /** |
|
| 36 | - * @var array<int,FilesystemOperator> $filesystem |
|
| 37 | - */ |
|
| 38 | - private array $filesystem = []; |
|
| 35 | + /** |
|
| 36 | + * @var array<int,FilesystemOperator> $filesystem |
|
| 37 | + */ |
|
| 38 | + private array $filesystem = []; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Get the filesystem containing certificates for a tree. |
|
| 42 | - * |
|
| 43 | - * @param Tree $tree |
|
| 44 | - * @return FilesystemOperator |
|
| 45 | - */ |
|
| 46 | - public function filesystem(Tree $tree): FilesystemOperator |
|
| 47 | - { |
|
| 48 | - if (!isset($this->filesystem[$tree->id()])) { |
|
| 49 | - $cert_dir = $tree->getPreference('MAJ_CERTIF_ROOTDIR', 'certificates/'); |
|
| 50 | - $adapter = new ChrootAdapter(Registry::filesystem()->data(), $cert_dir); |
|
| 40 | + /** |
|
| 41 | + * Get the filesystem containing certificates for a tree. |
|
| 42 | + * |
|
| 43 | + * @param Tree $tree |
|
| 44 | + * @return FilesystemOperator |
|
| 45 | + */ |
|
| 46 | + public function filesystem(Tree $tree): FilesystemOperator |
|
| 47 | + { |
|
| 48 | + if (!isset($this->filesystem[$tree->id()])) { |
|
| 49 | + $cert_dir = $tree->getPreference('MAJ_CERTIF_ROOTDIR', 'certificates/'); |
|
| 50 | + $adapter = new ChrootAdapter(Registry::filesystem()->data(), $cert_dir); |
|
| 51 | 51 | |
| 52 | - $this->filesystem[$tree->id()] = new FileSystem($adapter); |
|
| 53 | - } |
|
| 54 | - return $this->filesystem[$tree->id()]; |
|
| 55 | - } |
|
| 52 | + $this->filesystem[$tree->id()] = new FileSystem($adapter); |
|
| 53 | + } |
|
| 54 | + return $this->filesystem[$tree->id()]; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Set the filesystem containing certificates for a tree. |
|
| 59 | - * |
|
| 60 | - * @param Tree $tree |
|
| 61 | - * @param FilesystemOperator $filesystem |
|
| 62 | - */ |
|
| 63 | - public function setFilesystem(Tree $tree, FilesystemOperator $filesystem): void |
|
| 64 | - { |
|
| 65 | - $this->filesystem[$tree->id()] = $filesystem; |
|
| 66 | - } |
|
| 57 | + /** |
|
| 58 | + * Set the filesystem containing certificates for a tree. |
|
| 59 | + * |
|
| 60 | + * @param Tree $tree |
|
| 61 | + * @param FilesystemOperator $filesystem |
|
| 62 | + */ |
|
| 63 | + public function setFilesystem(Tree $tree, FilesystemOperator $filesystem): void |
|
| 64 | + { |
|
| 65 | + $this->filesystem[$tree->id()] = $filesystem; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Create the Certificate object defined by a path on the filesystem. |
|
| 70 | - * |
|
| 71 | - * @param Tree $tree |
|
| 72 | - * @param string $path |
|
| 73 | - * @return Certificate|NULL |
|
| 74 | - */ |
|
| 75 | - public function certificate(Tree $tree, string $path): ?Certificate |
|
| 76 | - { |
|
| 77 | - $filesystem = $this->filesystem($tree); |
|
| 78 | - if ($filesystem->fileExists($path) && $this->isFileSupported($filesystem, $path)) { |
|
| 79 | - return new Certificate($tree, $path); |
|
| 80 | - } |
|
| 81 | - return null; |
|
| 82 | - } |
|
| 68 | + /** |
|
| 69 | + * Create the Certificate object defined by a path on the filesystem. |
|
| 70 | + * |
|
| 71 | + * @param Tree $tree |
|
| 72 | + * @param string $path |
|
| 73 | + * @return Certificate|NULL |
|
| 74 | + */ |
|
| 75 | + public function certificate(Tree $tree, string $path): ?Certificate |
|
| 76 | + { |
|
| 77 | + $filesystem = $this->filesystem($tree); |
|
| 78 | + if ($filesystem->fileExists($path) && $this->isFileSupported($filesystem, $path)) { |
|
| 79 | + return new Certificate($tree, $path); |
|
| 80 | + } |
|
| 81 | + return null; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Get the cities (first-level folder) available in a the filesystem. |
|
| 86 | - * |
|
| 87 | - * @param Tree $tree |
|
| 88 | - * @return string[] |
|
| 89 | - */ |
|
| 90 | - public function cities(Tree $tree): array |
|
| 91 | - { |
|
| 92 | - $cities = $this->filesystem($tree) |
|
| 93 | - ->listContents('') |
|
| 94 | - ->filter(fn (StorageAttributes $attributes): bool => $attributes->isDir()) |
|
| 95 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
| 96 | - ->toArray(); |
|
| 97 | - usort($cities, I18N::comparator()); |
|
| 98 | - return $cities; |
|
| 99 | - } |
|
| 84 | + /** |
|
| 85 | + * Get the cities (first-level folder) available in a the filesystem. |
|
| 86 | + * |
|
| 87 | + * @param Tree $tree |
|
| 88 | + * @return string[] |
|
| 89 | + */ |
|
| 90 | + public function cities(Tree $tree): array |
|
| 91 | + { |
|
| 92 | + $cities = $this->filesystem($tree) |
|
| 93 | + ->listContents('') |
|
| 94 | + ->filter(fn (StorageAttributes $attributes): bool => $attributes->isDir()) |
|
| 95 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
| 96 | + ->toArray(); |
|
| 97 | + usort($cities, I18N::comparator()); |
|
| 98 | + return $cities; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Get the certificates available for a city (first-level folder). |
|
| 103 | - * |
|
| 104 | - * @param Tree $tree |
|
| 105 | - * @param string $city |
|
| 106 | - * @return Collection<Certificate> |
|
| 107 | - */ |
|
| 108 | - public function certificatesForCity(Tree $tree, string $city): Collection |
|
| 109 | - { |
|
| 110 | - $filesystem = $this->filesystem($tree); |
|
| 111 | - $certificates_paths = $filesystem->listContents($city) |
|
| 112 | - ->filter(fn (StorageAttributes $attributes): bool => |
|
| 113 | - $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path())) |
|
| 114 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
| 115 | - ->toArray(); |
|
| 116 | - usort($certificates_paths, I18N::comparator()); |
|
| 117 | - return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
| 118 | - } |
|
| 101 | + /** |
|
| 102 | + * Get the certificates available for a city (first-level folder). |
|
| 103 | + * |
|
| 104 | + * @param Tree $tree |
|
| 105 | + * @param string $city |
|
| 106 | + * @return Collection<Certificate> |
|
| 107 | + */ |
|
| 108 | + public function certificatesForCity(Tree $tree, string $city): Collection |
|
| 109 | + { |
|
| 110 | + $filesystem = $this->filesystem($tree); |
|
| 111 | + $certificates_paths = $filesystem->listContents($city) |
|
| 112 | + ->filter(fn (StorageAttributes $attributes): bool => |
|
| 113 | + $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path())) |
|
| 114 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
| 115 | + ->toArray(); |
|
| 116 | + usort($certificates_paths, I18N::comparator()); |
|
| 117 | + return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Get the certificates available for a city (first-level folder), containing a specified text. |
|
| 122 | - * |
|
| 123 | - * @param Tree $tree |
|
| 124 | - * @param string $city |
|
| 125 | - * @param string $contains |
|
| 126 | - * @return Collection<Certificate> |
|
| 127 | - */ |
|
| 128 | - public function certificatesForCityContaining(Tree $tree, string $city, string $contains): Collection |
|
| 129 | - { |
|
| 130 | - $filesystem = $this->filesystem($tree); |
|
| 131 | - $certificates_paths = $filesystem->listContents($city) |
|
| 132 | - ->filter(fn (StorageAttributes $attributes): bool => |
|
| 133 | - $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path()) |
|
| 134 | - && mb_stripos($attributes->path(), $contains) !== false) |
|
| 135 | - ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
| 136 | - ->toArray(); |
|
| 137 | - usort($certificates_paths, I18N::comparator()); |
|
| 138 | - return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
| 139 | - } |
|
| 120 | + /** |
|
| 121 | + * Get the certificates available for a city (first-level folder), containing a specified text. |
|
| 122 | + * |
|
| 123 | + * @param Tree $tree |
|
| 124 | + * @param string $city |
|
| 125 | + * @param string $contains |
|
| 126 | + * @return Collection<Certificate> |
|
| 127 | + */ |
|
| 128 | + public function certificatesForCityContaining(Tree $tree, string $city, string $contains): Collection |
|
| 129 | + { |
|
| 130 | + $filesystem = $this->filesystem($tree); |
|
| 131 | + $certificates_paths = $filesystem->listContents($city) |
|
| 132 | + ->filter(fn (StorageAttributes $attributes): bool => |
|
| 133 | + $attributes->isFile() && $this->isFileSupported($filesystem, $attributes->path()) |
|
| 134 | + && mb_stripos($attributes->path(), $contains) !== false) |
|
| 135 | + ->map(fn (StorageAttributes $attributes): string => $attributes->path()) |
|
| 136 | + ->toArray(); |
|
| 137 | + usort($certificates_paths, I18N::comparator()); |
|
| 138 | + return collect($certificates_paths)->map(fn (string $path): Certificate => new Certificate($tree, $path)); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Check if a file on the filesystem is supported by the certificate module. |
|
| 143 | - * |
|
| 144 | - * @param FilesystemOperator $filesystem |
|
| 145 | - * @param string $path |
|
| 146 | - * @return bool |
|
| 147 | - */ |
|
| 148 | - protected function isFileSupported(FilesystemOperator $filesystem, string $path): bool |
|
| 149 | - { |
|
| 150 | - try { |
|
| 151 | - $mime = $filesystem->mimeType($path); |
|
| 152 | - return Registry::cache()->array()->remember( |
|
| 153 | - 'maj-certif-supportedfiles-' . $mime, |
|
| 154 | - fn (): bool => app(CertificateImageFactory::class)->isMimeTypeSupported($mime) |
|
| 155 | - ); |
|
| 156 | - } catch (UnableToRetrieveMetadata | FilesystemException $ex) { |
|
| 157 | - } |
|
| 158 | - return false; |
|
| 159 | - } |
|
| 141 | + /** |
|
| 142 | + * Check if a file on the filesystem is supported by the certificate module. |
|
| 143 | + * |
|
| 144 | + * @param FilesystemOperator $filesystem |
|
| 145 | + * @param string $path |
|
| 146 | + * @return bool |
|
| 147 | + */ |
|
| 148 | + protected function isFileSupported(FilesystemOperator $filesystem, string $path): bool |
|
| 149 | + { |
|
| 150 | + try { |
|
| 151 | + $mime = $filesystem->mimeType($path); |
|
| 152 | + return Registry::cache()->array()->remember( |
|
| 153 | + 'maj-certif-supportedfiles-' . $mime, |
|
| 154 | + fn (): bool => app(CertificateImageFactory::class)->isMimeTypeSupported($mime) |
|
| 155 | + ); |
|
| 156 | + } catch (UnableToRetrieveMetadata | FilesystemException $ex) { |
|
| 157 | + } |
|
| 158 | + return false; |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -21,19 +21,19 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | interface ModuleMyArtJaubInterface extends ModuleCustomInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * Add module routes to webtrees route loader |
|
| 26 | - * |
|
| 27 | - * @param Map<\Aura\Router\Route> $router |
|
| 28 | - */ |
|
| 29 | - public function loadRoutes(Map $router): void; |
|
| 24 | + /** |
|
| 25 | + * Add module routes to webtrees route loader |
|
| 26 | + * |
|
| 27 | + * @param Map<\Aura\Router\Route> $router |
|
| 28 | + */ |
|
| 29 | + public function loadRoutes(Map $router): void; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Returns the URL of the module specific stylesheets. |
|
| 33 | - * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
| 34 | - * and fallback to default.min.css if none are found |
|
| 35 | - * |
|
| 36 | - * @return string |
|
| 37 | - */ |
|
| 38 | - public function moduleCssUrl(): string; |
|
| 31 | + /** |
|
| 32 | + * Returns the URL of the module specific stylesheets. |
|
| 33 | + * It will look for a CSS file matching the theme name (e.g. xenea.min.css), |
|
| 34 | + * and fallback to default.min.css if none are found |
|
| 35 | + * |
|
| 36 | + * @return string |
|
| 37 | + */ |
|
| 38 | + public function moduleCssUrl(): string; |
|
| 39 | 39 | } |
@@ -31,171 +31,171 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class MapAdapterDataService |
| 33 | 33 | { |
| 34 | - private MapDefinitionsService $mapdefinition_service; |
|
| 34 | + private MapDefinitionsService $mapdefinition_service; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for MapAdapterDataService |
|
| 38 | - * |
|
| 39 | - * @param MapDefinitionsService $mapdefinition_service |
|
| 40 | - */ |
|
| 41 | - public function __construct(MapDefinitionsService $mapdefinition_service) |
|
| 42 | - { |
|
| 43 | - $this->mapdefinition_service = $mapdefinition_service; |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for MapAdapterDataService |
|
| 38 | + * |
|
| 39 | + * @param MapDefinitionsService $mapdefinition_service |
|
| 40 | + */ |
|
| 41 | + public function __construct(MapDefinitionsService $mapdefinition_service) |
|
| 42 | + { |
|
| 43 | + $this->mapdefinition_service = $mapdefinition_service; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Find a GeoAnalysisMapAdapter by ID |
|
| 48 | - * |
|
| 49 | - * @param int $id |
|
| 50 | - * @return GeoAnalysisMapAdapter|NULL |
|
| 51 | - */ |
|
| 52 | - public function find(int $id): ?GeoAnalysisMapAdapter |
|
| 53 | - { |
|
| 54 | - return DB::table('maj_geodisp_mapviews') |
|
| 55 | - ->select('maj_geodisp_mapviews.*') |
|
| 56 | - ->where('majgm_id', '=', $id) |
|
| 57 | - ->get() |
|
| 58 | - ->map($this->mapAdapterMapper()) |
|
| 59 | - ->first(); |
|
| 60 | - } |
|
| 46 | + /** |
|
| 47 | + * Find a GeoAnalysisMapAdapter by ID |
|
| 48 | + * |
|
| 49 | + * @param int $id |
|
| 50 | + * @return GeoAnalysisMapAdapter|NULL |
|
| 51 | + */ |
|
| 52 | + public function find(int $id): ?GeoAnalysisMapAdapter |
|
| 53 | + { |
|
| 54 | + return DB::table('maj_geodisp_mapviews') |
|
| 55 | + ->select('maj_geodisp_mapviews.*') |
|
| 56 | + ->where('majgm_id', '=', $id) |
|
| 57 | + ->get() |
|
| 58 | + ->map($this->mapAdapterMapper()) |
|
| 59 | + ->first(); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
| 64 | - * |
|
| 65 | - * @param GeoAnalysisMap $map_view |
|
| 66 | - * @param bool $show_invalid |
|
| 67 | - * @return Collection<GeoAnalysisMapAdapter|null> |
|
| 68 | - */ |
|
| 69 | - public function allForView(GeoAnalysisMap $map_view, bool $show_invalid = false): Collection |
|
| 70 | - { |
|
| 71 | - $map_adapters = DB::table('maj_geodisp_mapviews') |
|
| 72 | - ->select('maj_geodisp_mapviews.*') |
|
| 73 | - ->where('majgm_majgv_id', '=', $map_view->id()) |
|
| 74 | - ->get() |
|
| 75 | - ->map($this->mapAdapterMapper()); |
|
| 76 | - return $show_invalid ? $map_adapters : $map_adapters->filter(); |
|
| 77 | - } |
|
| 62 | + /** |
|
| 63 | + * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
| 64 | + * |
|
| 65 | + * @param GeoAnalysisMap $map_view |
|
| 66 | + * @param bool $show_invalid |
|
| 67 | + * @return Collection<GeoAnalysisMapAdapter|null> |
|
| 68 | + */ |
|
| 69 | + public function allForView(GeoAnalysisMap $map_view, bool $show_invalid = false): Collection |
|
| 70 | + { |
|
| 71 | + $map_adapters = DB::table('maj_geodisp_mapviews') |
|
| 72 | + ->select('maj_geodisp_mapviews.*') |
|
| 73 | + ->where('majgm_majgv_id', '=', $map_view->id()) |
|
| 74 | + ->get() |
|
| 75 | + ->map($this->mapAdapterMapper()); |
|
| 76 | + return $show_invalid ? $map_adapters : $map_adapters->filter(); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Insert a GeoAnalysisMapAdapter in the database. |
|
| 81 | - * |
|
| 82 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
| 83 | - * @return int |
|
| 84 | - */ |
|
| 85 | - public function insertGetId(GeoAnalysisMapAdapter $map_adapter): int |
|
| 86 | - { |
|
| 87 | - return DB::table('maj_geodisp_mapviews') |
|
| 88 | - ->insertGetId([ |
|
| 89 | - 'majgm_majgv_id' => $map_adapter->geoAnalysisViewId(), |
|
| 90 | - 'majgm_map_id' => $map_adapter->map()->id(), |
|
| 91 | - 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
| 92 | - 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
| 93 | - 'majgm_config' => json_encode($map_adapter->viewConfig()->mapperConfig()) |
|
| 94 | - ]); |
|
| 95 | - } |
|
| 79 | + /** |
|
| 80 | + * Insert a GeoAnalysisMapAdapter in the database. |
|
| 81 | + * |
|
| 82 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
| 83 | + * @return int |
|
| 84 | + */ |
|
| 85 | + public function insertGetId(GeoAnalysisMapAdapter $map_adapter): int |
|
| 86 | + { |
|
| 87 | + return DB::table('maj_geodisp_mapviews') |
|
| 88 | + ->insertGetId([ |
|
| 89 | + 'majgm_majgv_id' => $map_adapter->geoAnalysisViewId(), |
|
| 90 | + 'majgm_map_id' => $map_adapter->map()->id(), |
|
| 91 | + 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
| 92 | + 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
| 93 | + 'majgm_config' => json_encode($map_adapter->viewConfig()->mapperConfig()) |
|
| 94 | + ]); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Update a GeoAnalysisMapAdapter in the database. |
|
| 99 | - * |
|
| 100 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
| 101 | - * @return int |
|
| 102 | - */ |
|
| 103 | - public function update(GeoAnalysisMapAdapter $map_adapter): int |
|
| 104 | - { |
|
| 105 | - return DB::table('maj_geodisp_mapviews') |
|
| 106 | - ->where('majgm_id', '=', $map_adapter->id()) |
|
| 107 | - ->update([ |
|
| 108 | - 'majgm_map_id' => $map_adapter->map()->id(), |
|
| 109 | - 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
| 110 | - 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
| 111 | - 'majgm_config' => json_encode($map_adapter->placeMapper()->config()) |
|
| 112 | - ]); |
|
| 113 | - } |
|
| 97 | + /** |
|
| 98 | + * Update a GeoAnalysisMapAdapter in the database. |
|
| 99 | + * |
|
| 100 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
| 101 | + * @return int |
|
| 102 | + */ |
|
| 103 | + public function update(GeoAnalysisMapAdapter $map_adapter): int |
|
| 104 | + { |
|
| 105 | + return DB::table('maj_geodisp_mapviews') |
|
| 106 | + ->where('majgm_id', '=', $map_adapter->id()) |
|
| 107 | + ->update([ |
|
| 108 | + 'majgm_map_id' => $map_adapter->map()->id(), |
|
| 109 | + 'majgm_mapper' => get_class($map_adapter->placeMapper()), |
|
| 110 | + 'majgm_feature_prop' => $map_adapter->viewConfig()->mapMappingProperty(), |
|
| 111 | + 'majgm_config' => json_encode($map_adapter->placeMapper()->config()) |
|
| 112 | + ]); |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Delete a GeoAnalysisMapAdapter from the database. |
|
| 117 | - * |
|
| 118 | - * @param GeoAnalysisMapAdapter $map_adapter |
|
| 119 | - * @return int |
|
| 120 | - */ |
|
| 121 | - public function delete(GeoAnalysisMapAdapter $map_adapter): int |
|
| 122 | - { |
|
| 123 | - return DB::table('maj_geodisp_mapviews') |
|
| 124 | - ->where('majgm_id', '=', $map_adapter->id()) |
|
| 125 | - ->delete(); |
|
| 126 | - } |
|
| 115 | + /** |
|
| 116 | + * Delete a GeoAnalysisMapAdapter from the database. |
|
| 117 | + * |
|
| 118 | + * @param GeoAnalysisMapAdapter $map_adapter |
|
| 119 | + * @return int |
|
| 120 | + */ |
|
| 121 | + public function delete(GeoAnalysisMapAdapter $map_adapter): int |
|
| 122 | + { |
|
| 123 | + return DB::table('maj_geodisp_mapviews') |
|
| 124 | + ->where('majgm_id', '=', $map_adapter->id()) |
|
| 125 | + ->delete(); |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - /** |
|
| 129 | - * Delete invalid GeoAnalysisMapAdapters from the database. |
|
| 130 | - * |
|
| 131 | - * @param AbstractGeoAnalysisView $view |
|
| 132 | - * @param Collection<int> $valid_map_adapters |
|
| 133 | - * @return int |
|
| 134 | - */ |
|
| 135 | - public function deleteInvalid(AbstractGeoAnalysisView $view, Collection $valid_map_adapters): int |
|
| 136 | - { |
|
| 137 | - return DB::table('maj_geodisp_mapviews') |
|
| 138 | - ->where('majgm_majgv_id', '=', $view->id()) |
|
| 139 | - ->whereNotIn('majgm_id', $valid_map_adapters) |
|
| 140 | - ->delete(); |
|
| 141 | - } |
|
| 128 | + /** |
|
| 129 | + * Delete invalid GeoAnalysisMapAdapters from the database. |
|
| 130 | + * |
|
| 131 | + * @param AbstractGeoAnalysisView $view |
|
| 132 | + * @param Collection<int> $valid_map_adapters |
|
| 133 | + * @return int |
|
| 134 | + */ |
|
| 135 | + public function deleteInvalid(AbstractGeoAnalysisView $view, Collection $valid_map_adapters): int |
|
| 136 | + { |
|
| 137 | + return DB::table('maj_geodisp_mapviews') |
|
| 138 | + ->where('majgm_majgv_id', '=', $view->id()) |
|
| 139 | + ->whereNotIn('majgm_id', $valid_map_adapters) |
|
| 140 | + ->delete(); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
| 145 | - * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
| 146 | - * or if the types do not match with the ones expected. |
|
| 147 | - * |
|
| 148 | - * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
| 149 | - */ |
|
| 150 | - private function mapAdapterMapper(): Closure |
|
| 151 | - { |
|
| 152 | - return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
| 153 | - if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
| 154 | - return null; |
|
| 155 | - } |
|
| 156 | - try { |
|
| 157 | - $mapper = app($row->majgm_mapper); |
|
| 158 | - if (!($mapper instanceof PlaceMapperInterface)) { |
|
| 159 | - return null; |
|
| 160 | - } |
|
| 143 | + /** |
|
| 144 | + * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
| 145 | + * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
| 146 | + * or if the types do not match with the ones expected. |
|
| 147 | + * |
|
| 148 | + * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
| 149 | + */ |
|
| 150 | + private function mapAdapterMapper(): Closure |
|
| 151 | + { |
|
| 152 | + return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
| 153 | + if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
| 154 | + return null; |
|
| 155 | + } |
|
| 156 | + try { |
|
| 157 | + $mapper = app($row->majgm_mapper); |
|
| 158 | + if (!($mapper instanceof PlaceMapperInterface)) { |
|
| 159 | + return null; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return new GeoAnalysisMapAdapter( |
|
| 163 | - (int) $row->majgm_id, |
|
| 164 | - (int) $row->majgm_majgv_id, |
|
| 165 | - $map, |
|
| 166 | - app($row->majgm_mapper), |
|
| 167 | - new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
| 168 | - ); |
|
| 169 | - } catch (BindingResolutionException $ex) { |
|
| 170 | - return null; |
|
| 171 | - } |
|
| 172 | - }; |
|
| 173 | - } |
|
| 162 | + return new GeoAnalysisMapAdapter( |
|
| 163 | + (int) $row->majgm_id, |
|
| 164 | + (int) $row->majgm_majgv_id, |
|
| 165 | + $map, |
|
| 166 | + app($row->majgm_mapper), |
|
| 167 | + new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
| 168 | + ); |
|
| 169 | + } catch (BindingResolutionException $ex) { |
|
| 170 | + return null; |
|
| 171 | + } |
|
| 172 | + }; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
| 177 | - * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
| 178 | - * through the Laravel container or if the type do not match with the one expected. |
|
| 179 | - * |
|
| 180 | - * @param string $json_config |
|
| 181 | - * @return PlaceMapperConfigInterface|NULL |
|
| 182 | - */ |
|
| 183 | - private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
| 184 | - { |
|
| 185 | - $config = $json_config === null ? [] : json_decode($json_config, true); |
|
| 186 | - $class = $config['class'] ?? null; |
|
| 187 | - $json_mapper_config = $config['config'] ?? null; |
|
| 188 | - if ($class === null || $json_mapper_config === null) { |
|
| 189 | - return null; |
|
| 190 | - } |
|
| 191 | - try { |
|
| 192 | - $mapper_config = app($class); |
|
| 193 | - if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
| 194 | - return null; |
|
| 195 | - } |
|
| 196 | - return $mapper_config->jsonDeserialize($json_mapper_config); |
|
| 197 | - } catch (BindingResolutionException $ex) { |
|
| 198 | - return null; |
|
| 199 | - } |
|
| 200 | - } |
|
| 175 | + /** |
|
| 176 | + * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
| 177 | + * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
| 178 | + * through the Laravel container or if the type do not match with the one expected. |
|
| 179 | + * |
|
| 180 | + * @param string $json_config |
|
| 181 | + * @return PlaceMapperConfigInterface|NULL |
|
| 182 | + */ |
|
| 183 | + private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
| 184 | + { |
|
| 185 | + $config = $json_config === null ? [] : json_decode($json_config, true); |
|
| 186 | + $class = $config['class'] ?? null; |
|
| 187 | + $json_mapper_config = $config['config'] ?? null; |
|
| 188 | + if ($class === null || $json_mapper_config === null) { |
|
| 189 | + return null; |
|
| 190 | + } |
|
| 191 | + try { |
|
| 192 | + $mapper_config = app($class); |
|
| 193 | + if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
| 194 | + return null; |
|
| 195 | + } |
|
| 196 | + return $mapper_config->jsonDeserialize($json_mapper_config); |
|
| 197 | + } catch (BindingResolutionException $ex) { |
|
| 198 | + return null; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | 201 | } |
@@ -25,41 +25,41 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class GeoAnalysisService |
| 27 | 27 | { |
| 28 | - private ModuleService $module_service; |
|
| 28 | + private ModuleService $module_service; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor for MapDefinitionsService |
|
| 32 | - * |
|
| 33 | - * @param ModuleService $module_service |
|
| 34 | - */ |
|
| 35 | - public function __construct(ModuleService $module_service) |
|
| 36 | - { |
|
| 37 | - $this->module_service = $module_service; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor for MapDefinitionsService |
|
| 32 | + * |
|
| 33 | + * @param ModuleService $module_service |
|
| 34 | + */ |
|
| 35 | + public function __construct(ModuleService $module_service) |
|
| 36 | + { |
|
| 37 | + $this->module_service = $module_service; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Get all available geographical dispersion analyses. |
|
| 42 | - * |
|
| 43 | - * {@internal The list is generated based on the modules exposing ModuleGeoAnalysisProviderInterface |
|
| 44 | - * |
|
| 45 | - * @param bool $include_disabled |
|
| 46 | - * @return Collection<GeoAnalysisInterface> |
|
| 47 | - */ |
|
| 48 | - public function all(bool $include_disabled = false): Collection |
|
| 49 | - { |
|
| 50 | - /** @var Collection<GeoAnalysisInterface> $geoanalyses */ |
|
| 51 | - $geoanalyses = $this->module_service |
|
| 52 | - ->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
|
| 53 | - ->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
|
| 54 | - ->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
|
| 55 | - try { |
|
| 56 | - $analysis = app($analysis_class); |
|
| 57 | - return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
|
| 58 | - } catch (BindingResolutionException $ex) { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 61 | - })->filter(); |
|
| 40 | + /** |
|
| 41 | + * Get all available geographical dispersion analyses. |
|
| 42 | + * |
|
| 43 | + * {@internal The list is generated based on the modules exposing ModuleGeoAnalysisProviderInterface |
|
| 44 | + * |
|
| 45 | + * @param bool $include_disabled |
|
| 46 | + * @return Collection<GeoAnalysisInterface> |
|
| 47 | + */ |
|
| 48 | + public function all(bool $include_disabled = false): Collection |
|
| 49 | + { |
|
| 50 | + /** @var Collection<GeoAnalysisInterface> $geoanalyses */ |
|
| 51 | + $geoanalyses = $this->module_service |
|
| 52 | + ->findByInterface(ModuleGeoAnalysisProviderInterface::class, $include_disabled) |
|
| 53 | + ->flatMap(fn(ModuleGeoAnalysisProviderInterface $module) => $module->listGeoAnalyses()) |
|
| 54 | + ->map(static function (string $analysis_class): ?GeoAnalysisInterface { |
|
| 55 | + try { |
|
| 56 | + $analysis = app($analysis_class); |
|
| 57 | + return $analysis instanceof GeoAnalysisInterface ? $analysis : null; |
|
| 58 | + } catch (BindingResolutionException $ex) { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | + })->filter(); |
|
| 62 | 62 | |
| 63 | - return $geoanalyses; |
|
| 64 | - } |
|
| 63 | + return $geoanalyses; |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -25,41 +25,41 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class PlaceMapperService |
| 27 | 27 | { |
| 28 | - private ModuleService $module_service; |
|
| 28 | + private ModuleService $module_service; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor for PlaceMapperService |
|
| 32 | - * |
|
| 33 | - * @param ModuleService $module_service |
|
| 34 | - */ |
|
| 35 | - public function __construct(ModuleService $module_service) |
|
| 36 | - { |
|
| 37 | - $this->module_service = $module_service; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor for PlaceMapperService |
|
| 32 | + * |
|
| 33 | + * @param ModuleService $module_service |
|
| 34 | + */ |
|
| 35 | + public function __construct(ModuleService $module_service) |
|
| 36 | + { |
|
| 37 | + $this->module_service = $module_service; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Get all place mappers available. |
|
| 42 | - * |
|
| 43 | - * {@internal The list is generated based on the modules exposing ModulePlaceMapperProviderInterface} |
|
| 44 | - * |
|
| 45 | - * @param bool $include_disabled |
|
| 46 | - * @return Collection<PlaceMapperInterface> |
|
| 47 | - */ |
|
| 48 | - public function all(bool $include_disabled = false): Collection |
|
| 49 | - { |
|
| 50 | - /** @var Collection<PlaceMapperInterface> $place_mappers */ |
|
| 51 | - $place_mappers = $this->module_service |
|
| 52 | - ->findByInterface(ModulePlaceMapperProviderInterface::class, $include_disabled) |
|
| 53 | - ->flatMap(fn(ModulePlaceMapperProviderInterface $module) => $module->listPlaceMappers()) |
|
| 54 | - ->map(static function (string $mapper_class): ?PlaceMapperInterface { |
|
| 55 | - try { |
|
| 56 | - $mapper = app($mapper_class); |
|
| 57 | - return $mapper instanceof PlaceMapperInterface ? $mapper : null; |
|
| 58 | - } catch (BindingResolutionException $ex) { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 61 | - })->filter(); |
|
| 40 | + /** |
|
| 41 | + * Get all place mappers available. |
|
| 42 | + * |
|
| 43 | + * {@internal The list is generated based on the modules exposing ModulePlaceMapperProviderInterface} |
|
| 44 | + * |
|
| 45 | + * @param bool $include_disabled |
|
| 46 | + * @return Collection<PlaceMapperInterface> |
|
| 47 | + */ |
|
| 48 | + public function all(bool $include_disabled = false): Collection |
|
| 49 | + { |
|
| 50 | + /** @var Collection<PlaceMapperInterface> $place_mappers */ |
|
| 51 | + $place_mappers = $this->module_service |
|
| 52 | + ->findByInterface(ModulePlaceMapperProviderInterface::class, $include_disabled) |
|
| 53 | + ->flatMap(fn(ModulePlaceMapperProviderInterface $module) => $module->listPlaceMappers()) |
|
| 54 | + ->map(static function (string $mapper_class): ?PlaceMapperInterface { |
|
| 55 | + try { |
|
| 56 | + $mapper = app($mapper_class); |
|
| 57 | + return $mapper instanceof PlaceMapperInterface ? $mapper : null; |
|
| 58 | + } catch (BindingResolutionException $ex) { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | + })->filter(); |
|
| 62 | 62 | |
| 63 | - return $place_mappers; |
|
| 64 | - } |
|
| 63 | + return $place_mappers; |
|
| 64 | + } |
|
| 65 | 65 | } |