@@ -22,81 +22,81 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class MapFeatureAnalysisData |
| 24 | 24 | { |
| 25 | - private string $id; |
|
| 26 | - private int $count; |
|
| 27 | - private bool $in_map; |
|
| 28 | - /** |
|
| 29 | - * @var Collection<GeoAnalysisPlace> $places |
|
| 30 | - */ |
|
| 31 | - private Collection $places; |
|
| 25 | + private string $id; |
|
| 26 | + private int $count; |
|
| 27 | + private bool $in_map; |
|
| 28 | + /** |
|
| 29 | + * @var Collection<GeoAnalysisPlace> $places |
|
| 30 | + */ |
|
| 31 | + private Collection $places; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor for MapFeatureAnalysisData |
|
| 35 | - * |
|
| 36 | - * @param string $id |
|
| 37 | - */ |
|
| 38 | - public function __construct(string $id) |
|
| 39 | - { |
|
| 40 | - $this->id = $id; |
|
| 41 | - $this->count = 0; |
|
| 42 | - $this->places = new Collection(); |
|
| 43 | - $this->in_map = false; |
|
| 44 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor for MapFeatureAnalysisData |
|
| 35 | + * |
|
| 36 | + * @param string $id |
|
| 37 | + */ |
|
| 38 | + public function __construct(string $id) |
|
| 39 | + { |
|
| 40 | + $this->id = $id; |
|
| 41 | + $this->count = 0; |
|
| 42 | + $this->places = new Collection(); |
|
| 43 | + $this->in_map = false; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get the list of places mapped to the feature |
|
| 48 | - * |
|
| 49 | - * @return Collection<GeoAnalysisPlace> |
|
| 50 | - */ |
|
| 51 | - public function places(): Collection |
|
| 52 | - { |
|
| 53 | - return $this->places; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * Get the list of places mapped to the feature |
|
| 48 | + * |
|
| 49 | + * @return Collection<GeoAnalysisPlace> |
|
| 50 | + */ |
|
| 51 | + public function places(): Collection |
|
| 52 | + { |
|
| 53 | + return $this->places; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get the count of analysis items occurring in the feature |
|
| 58 | - * |
|
| 59 | - * @return int |
|
| 60 | - */ |
|
| 61 | - public function count(): int |
|
| 62 | - { |
|
| 63 | - return $this->count; |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Get the count of analysis items occurring in the feature |
|
| 58 | + * |
|
| 59 | + * @return int |
|
| 60 | + */ |
|
| 61 | + public function count(): int |
|
| 62 | + { |
|
| 63 | + return $this->count; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Check whether the feature exist in the target map |
|
| 68 | - * |
|
| 69 | - * @return bool |
|
| 70 | - */ |
|
| 71 | - public function existsInMap(): bool |
|
| 72 | - { |
|
| 73 | - return $this->in_map; |
|
| 74 | - } |
|
| 66 | + /** |
|
| 67 | + * Check whether the feature exist in the target map |
|
| 68 | + * |
|
| 69 | + * @return bool |
|
| 70 | + */ |
|
| 71 | + public function existsInMap(): bool |
|
| 72 | + { |
|
| 73 | + return $this->in_map; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Confirm that the feature exist in the target map |
|
| 78 | - * |
|
| 79 | - * @return $this |
|
| 80 | - */ |
|
| 81 | - public function tagAsExisting(): self |
|
| 82 | - { |
|
| 83 | - $this->in_map = true; |
|
| 84 | - return $this; |
|
| 85 | - } |
|
| 76 | + /** |
|
| 77 | + * Confirm that the feature exist in the target map |
|
| 78 | + * |
|
| 79 | + * @return $this |
|
| 80 | + */ |
|
| 81 | + public function tagAsExisting(): self |
|
| 82 | + { |
|
| 83 | + $this->in_map = true; |
|
| 84 | + return $this; |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Add a GeoAnalysisPlace to the feature |
|
| 89 | - * |
|
| 90 | - * @param GeoAnalysisPlace $place |
|
| 91 | - * @param int $count |
|
| 92 | - * @return $this |
|
| 93 | - */ |
|
| 94 | - public function add(GeoAnalysisPlace $place, int $count): self |
|
| 95 | - { |
|
| 96 | - if (!$place->isExcluded()) { |
|
| 97 | - $this->places->add($place); |
|
| 98 | - $this->count += $count; |
|
| 99 | - } |
|
| 100 | - return $this; |
|
| 101 | - } |
|
| 87 | + /** |
|
| 88 | + * Add a GeoAnalysisPlace to the feature |
|
| 89 | + * |
|
| 90 | + * @param GeoAnalysisPlace $place |
|
| 91 | + * @param int $count |
|
| 92 | + * @return $this |
|
| 93 | + */ |
|
| 94 | + public function add(GeoAnalysisPlace $place, int $count): self |
|
| 95 | + { |
|
| 96 | + if (!$place->isExcluded()) { |
|
| 97 | + $this->places->add($place); |
|
| 98 | + $this->count += $count; |
|
| 99 | + } |
|
| 100 | + return $this; |
|
| 101 | + } |
|
| 102 | 102 | } |
@@ -24,57 +24,57 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class MapAdapterResult |
| 26 | 26 | { |
| 27 | - private GeoAnalysisResult $result; |
|
| 27 | + private GeoAnalysisResult $result; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var \Brick\Geo\IO\GeoJSON\Feature[] $features |
|
| 31 | - */ |
|
| 32 | - private array $features; |
|
| 29 | + /** |
|
| 30 | + * @var \Brick\Geo\IO\GeoJSON\Feature[] $features |
|
| 31 | + */ |
|
| 32 | + private array $features; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor for MapAdapterResult |
|
| 36 | - * |
|
| 37 | - * @param GeoAnalysisResult $result |
|
| 38 | - * @param \Brick\Geo\IO\GeoJSON\Feature[] $features |
|
| 39 | - */ |
|
| 40 | - final public function __construct(GeoAnalysisResult $result, array $features) |
|
| 41 | - { |
|
| 42 | - $this->result = $result; |
|
| 43 | - $this->features = $features; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor for MapAdapterResult |
|
| 36 | + * |
|
| 37 | + * @param GeoAnalysisResult $result |
|
| 38 | + * @param \Brick\Geo\IO\GeoJSON\Feature[] $features |
|
| 39 | + */ |
|
| 40 | + final public function __construct(GeoAnalysisResult $result, array $features) |
|
| 41 | + { |
|
| 42 | + $this->result = $result; |
|
| 43 | + $this->features = $features; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get the GeoAnalysisResult after mapping of the places |
|
| 48 | - * |
|
| 49 | - * @return GeoAnalysisResult |
|
| 50 | - */ |
|
| 51 | - public function geoAnalysisResult(): GeoAnalysisResult |
|
| 52 | - { |
|
| 53 | - return $this->result; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * Get the GeoAnalysisResult after mapping of the places |
|
| 48 | + * |
|
| 49 | + * @return GeoAnalysisResult |
|
| 50 | + */ |
|
| 51 | + public function geoAnalysisResult(): GeoAnalysisResult |
|
| 52 | + { |
|
| 53 | + return $this->result; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get the list of features to display on the map |
|
| 58 | - * |
|
| 59 | - * @return \Brick\Geo\IO\GeoJSON\Feature[] |
|
| 60 | - */ |
|
| 61 | - public function features(): array |
|
| 62 | - { |
|
| 63 | - return $this->features; |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Get the list of features to display on the map |
|
| 58 | + * |
|
| 59 | + * @return \Brick\Geo\IO\GeoJSON\Feature[] |
|
| 60 | + */ |
|
| 61 | + public function features(): array |
|
| 62 | + { |
|
| 63 | + return $this->features; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Merge the current MapAdapter with another. |
|
| 68 | - * The current object is modified, not the second one. |
|
| 69 | - * |
|
| 70 | - * @param MapAdapterResult $other |
|
| 71 | - * @return static |
|
| 72 | - */ |
|
| 73 | - public function merge(MapAdapterResult $other): self |
|
| 74 | - { |
|
| 75 | - return new static( |
|
| 76 | - $this->result->merge($other->result), |
|
| 77 | - array_merge($this->features, $other->features) |
|
| 78 | - ); |
|
| 79 | - } |
|
| 66 | + /** |
|
| 67 | + * Merge the current MapAdapter with another. |
|
| 68 | + * The current object is modified, not the second one. |
|
| 69 | + * |
|
| 70 | + * @param MapAdapterResult $other |
|
| 71 | + * @return static |
|
| 72 | + */ |
|
| 73 | + public function merge(MapAdapterResult $other): self |
|
| 74 | + { |
|
| 75 | + return new static( |
|
| 76 | + $this->result->merge($other->result), |
|
| 77 | + array_merge($this->features, $other->features) |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -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 array |
|
| 185 | - */ |
|
| 186 | - protected function featureAnalysisData(GeoAnalysisResult $result): array |
|
| 187 | - { |
|
| 188 | - $features_mapping = new Collection(); |
|
| 189 | - |
|
| 190 | - $byplaces = $result->knownPlaces(); |
|
| 191 | - $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
| 192 | - $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty()); |
|
| 193 | - |
|
| 194 | - if ($id !== null && mb_strlen($id) > 0) { |
|
| 195 | - $features_mapping->put( |
|
| 196 | - $id, |
|
| 197 | - $features_mapping->get($id, new MapFeatureAnalysisData($id))->add($item->place(), $item->count()) |
|
| 198 | - ); |
|
| 199 | - } else { |
|
| 200 | - $result->exclude($item->place()); |
|
| 201 | - } |
|
| 202 | - }); |
|
| 203 | - |
|
| 204 | - return [ $features_mapping, $result]; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Get the value of the feature property used for the mapping |
|
| 209 | - * |
|
| 210 | - * @param Feature $feature |
|
| 211 | - * @return string|NULL |
|
| 212 | - */ |
|
| 213 | - protected function featureId(Feature $feature): ?string |
|
| 214 | - { |
|
| 215 | - return $feature->getProperty($this->config->mapMappingProperty()); |
|
| 216 | - } |
|
| 32 | + private int $id; |
|
| 33 | + private int $view_id; |
|
| 34 | + private MapDefinitionInterface $map; |
|
| 35 | + private PlaceMapperInterface $place_mapper; |
|
| 36 | + private MapViewConfigInterface $config; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Constructor for GeoAnalysisMapAdapter |
|
| 40 | + * |
|
| 41 | + * @param int $id |
|
| 42 | + * @param MapDefinitionInterface $map |
|
| 43 | + * @param PlaceMapperInterface $mapper |
|
| 44 | + * @param MapViewConfigInterface $config |
|
| 45 | + */ |
|
| 46 | + public function __construct( |
|
| 47 | + int $id, |
|
| 48 | + int $view_id, |
|
| 49 | + MapDefinitionInterface $map, |
|
| 50 | + PlaceMapperInterface $mapper, |
|
| 51 | + MapViewConfigInterface $config |
|
| 52 | + ) { |
|
| 53 | + $this->id = $id; |
|
| 54 | + $this->view_id = $view_id; |
|
| 55 | + $this->map = $map; |
|
| 56 | + $this->place_mapper = $mapper; |
|
| 57 | + $this->config = $config; |
|
| 58 | + $this->place_mapper->setConfig($this->config->mapperConfig()); |
|
| 59 | + $this->place_mapper->setData('map', $map); |
|
| 60 | + $this->place_mapper->boot(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Create a copy of the GeoAnalysisMapAdapter with new properties. |
|
| 65 | + * |
|
| 66 | + * @param MapDefinitionInterface $map |
|
| 67 | + * @param PlaceMapperInterface $mapper |
|
| 68 | + * @param string $mapping_property |
|
| 69 | + * @return 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 array |
|
| 185 | + */ |
|
| 186 | + protected function featureAnalysisData(GeoAnalysisResult $result): array |
|
| 187 | + { |
|
| 188 | + $features_mapping = new Collection(); |
|
| 189 | + |
|
| 190 | + $byplaces = $result->knownPlaces(); |
|
| 191 | + $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
| 192 | + $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty()); |
|
| 193 | + |
|
| 194 | + if ($id !== null && mb_strlen($id) > 0) { |
|
| 195 | + $features_mapping->put( |
|
| 196 | + $id, |
|
| 197 | + $features_mapping->get($id, new MapFeatureAnalysisData($id))->add($item->place(), $item->count()) |
|
| 198 | + ); |
|
| 199 | + } else { |
|
| 200 | + $result->exclude($item->place()); |
|
| 201 | + } |
|
| 202 | + }); |
|
| 203 | + |
|
| 204 | + return [ $features_mapping, $result]; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Get the value of the feature property used for the mapping |
|
| 209 | + * |
|
| 210 | + * @param Feature $feature |
|
| 211 | + * @return string|NULL |
|
| 212 | + */ |
|
| 213 | + protected function featureId(Feature $feature): ?string |
|
| 214 | + { |
|
| 215 | + return $feature->getProperty($this->config->mapMappingProperty()); |
|
| 216 | + } |
|
| 217 | 217 | } |
@@ -27,57 +27,57 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | class SourceCertificateIconHook implements FactSourceTextExtenderInterface |
| 29 | 29 | { |
| 30 | - private CertificatesModule $module; |
|
| 31 | - private UrlObfuscatorService $url_obfuscator_service; |
|
| 30 | + private CertificatesModule $module; |
|
| 31 | + private UrlObfuscatorService $url_obfuscator_service; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Constructor for SourceCertificateIconHook |
|
| 35 | - * |
|
| 36 | - * @param CertificatesModule $module |
|
| 37 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
| 38 | - */ |
|
| 39 | - public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
| 40 | - { |
|
| 41 | - $this->module = $module; |
|
| 42 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 43 | - } |
|
| 33 | + /** |
|
| 34 | + * Constructor for SourceCertificateIconHook |
|
| 35 | + * |
|
| 36 | + * @param CertificatesModule $module |
|
| 37 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
| 38 | + */ |
|
| 39 | + public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
| 40 | + { |
|
| 41 | + $this->module = $module; |
|
| 42 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * {@inheritDoc} |
|
| 47 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 48 | - */ |
|
| 49 | - public function module(): ModuleInterface |
|
| 50 | - { |
|
| 51 | - return $this->module; |
|
| 52 | - } |
|
| 45 | + /** |
|
| 46 | + * {@inheritDoc} |
|
| 47 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 48 | + */ |
|
| 49 | + public function module(): ModuleInterface |
|
| 50 | + { |
|
| 51 | + return $this->module; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * {@inheritDoc} |
|
| 56 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
| 57 | - */ |
|
| 58 | - public function factSourcePrepend(Tree $tree, string $source_record, int $level): string |
|
| 59 | - { |
|
| 60 | - $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
| 61 | - if ( |
|
| 62 | - is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level && |
|
| 63 | - preg_match('/^' . $level . ' _ACT (.*)$/m', $source_record, $match) === 1 |
|
| 64 | - ) { |
|
| 65 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
| 66 | - 'module_name' => $this->module->name(), |
|
| 67 | - 'certificate' => new Certificate($tree, $match[1]), |
|
| 68 | - 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
| 69 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
| 70 | - ]); |
|
| 71 | - } |
|
| 72 | - return ''; |
|
| 73 | - } |
|
| 54 | + /** |
|
| 55 | + * {@inheritDoc} |
|
| 56 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
| 57 | + */ |
|
| 58 | + public function factSourcePrepend(Tree $tree, string $source_record, int $level): string |
|
| 59 | + { |
|
| 60 | + $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
| 61 | + if ( |
|
| 62 | + is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level && |
|
| 63 | + preg_match('/^' . $level . ' _ACT (.*)$/m', $source_record, $match) === 1 |
|
| 64 | + ) { |
|
| 65 | + return view($this->module->name() . '::components/certificate-icon', [ |
|
| 66 | + 'module_name' => $this->module->name(), |
|
| 67 | + 'certificate' => new Certificate($tree, $match[1]), |
|
| 68 | + 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
| 69 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
| 70 | + ]); |
|
| 71 | + } |
|
| 72 | + return ''; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * {@inheritDoc} |
|
| 77 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
| 78 | - */ |
|
| 79 | - public function factSourceAppend(Tree $tree, string $source_record, int $level): string |
|
| 80 | - { |
|
| 81 | - return ''; |
|
| 82 | - } |
|
| 75 | + /** |
|
| 76 | + * {@inheritDoc} |
|
| 77 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
| 78 | + */ |
|
| 79 | + public function factSourceAppend(Tree $tree, string $source_record, int $level): string |
|
| 80 | + { |
|
| 81 | + return ''; |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -59,10 +59,10 @@ |
||
| 59 | 59 | { |
| 60 | 60 | $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
| 61 | 61 | if ( |
| 62 | - is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level && |
|
| 63 | - preg_match('/^' . $level . ' _ACT (.*)$/m', $source_record, $match) === 1 |
|
| 62 | + is_numeric($permission_level) && Auth::accessLevel($tree) <= (int)$permission_level && |
|
| 63 | + preg_match('/^'.$level.' _ACT (.*)$/m', $source_record, $match) === 1 |
|
| 64 | 64 | ) { |
| 65 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
| 65 | + return view($this->module->name().'::components/certificate-icon', [ |
|
| 66 | 66 | 'module_name' => $this->module->name(), |
| 67 | 67 | 'certificate' => new Certificate($tree, $match[1]), |
| 68 | 68 | 'url_obfuscator_service' => $this->url_obfuscator_service, |
@@ -24,60 +24,60 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class CertificateTagEditorHook implements CustomSimpleTagEditorInterface |
| 26 | 26 | { |
| 27 | - private ModuleInterface $module; |
|
| 27 | + private ModuleInterface $module; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Constructor for CertificateTagEditorHook |
|
| 31 | - * |
|
| 32 | - * @param ModuleInterface $module |
|
| 33 | - */ |
|
| 34 | - public function __construct(ModuleInterface $module) |
|
| 35 | - { |
|
| 36 | - $this->module = $module; |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Constructor for CertificateTagEditorHook |
|
| 31 | + * |
|
| 32 | + * @param ModuleInterface $module |
|
| 33 | + */ |
|
| 34 | + public function __construct(ModuleInterface $module) |
|
| 35 | + { |
|
| 36 | + $this->module = $module; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * {@inheritDoc} |
|
| 41 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 42 | - */ |
|
| 43 | - public function module(): ModuleInterface |
|
| 44 | - { |
|
| 45 | - return $this->module; |
|
| 46 | - } |
|
| 39 | + /** |
|
| 40 | + * {@inheritDoc} |
|
| 41 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 42 | + */ |
|
| 43 | + public function module(): ModuleInterface |
|
| 44 | + { |
|
| 45 | + return $this->module; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * {@inheritDoc} |
|
| 50 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\CustomSimpleTagEditorInterface::addExpectedTags() |
|
| 51 | - */ |
|
| 52 | - public function addExpectedTags(array $expected_tags): array |
|
| 53 | - { |
|
| 54 | - return array_merge_recursive($expected_tags, [ |
|
| 55 | - 'SOUR' => [ '_ACT' ] |
|
| 56 | - ]); |
|
| 57 | - } |
|
| 48 | + /** |
|
| 49 | + * {@inheritDoc} |
|
| 50 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\CustomSimpleTagEditorInterface::addExpectedTags() |
|
| 51 | + */ |
|
| 52 | + public function addExpectedTags(array $expected_tags): array |
|
| 53 | + { |
|
| 54 | + return array_merge_recursive($expected_tags, [ |
|
| 55 | + 'SOUR' => [ '_ACT' ] |
|
| 56 | + ]); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * {@inheritDoc} |
|
| 61 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\CustomSimpleTagEditorInterface::getLabel() |
|
| 62 | - */ |
|
| 63 | - public function getLabel(string $tag): string |
|
| 64 | - { |
|
| 65 | - if (substr($tag, -4) === '_ACT') { |
|
| 66 | - return Registry::elementFactory()->make(substr('INDI:SOUR:_ACT', 0, -strlen($tag)) . $tag)->label(); |
|
| 67 | - } |
|
| 68 | - return ''; |
|
| 69 | - } |
|
| 59 | + /** |
|
| 60 | + * {@inheritDoc} |
|
| 61 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\CustomSimpleTagEditorInterface::getLabel() |
|
| 62 | + */ |
|
| 63 | + public function getLabel(string $tag): string |
|
| 64 | + { |
|
| 65 | + if (substr($tag, -4) === '_ACT') { |
|
| 66 | + return Registry::elementFactory()->make(substr('INDI:SOUR:_ACT', 0, -strlen($tag)) . $tag)->label(); |
|
| 67 | + } |
|
| 68 | + return ''; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * {@inheritDoc} |
|
| 73 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\CustomSimpleTagEditorInterface::editForm() |
|
| 74 | - */ |
|
| 75 | - public function editForm(string $tag, string $id, string $name, string $value, Tree $tree): string |
|
| 76 | - { |
|
| 77 | - if (substr($tag, -4) === '_ACT') { |
|
| 78 | - return Registry::elementFactory()->make(substr('INDI:SOUR:_ACT', 0, -strlen($tag)) . $tag) |
|
| 79 | - ->edit($id, $name, $value, $tree); |
|
| 80 | - } |
|
| 81 | - return ''; |
|
| 82 | - } |
|
| 71 | + /** |
|
| 72 | + * {@inheritDoc} |
|
| 73 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\CustomSimpleTagEditorInterface::editForm() |
|
| 74 | + */ |
|
| 75 | + public function editForm(string $tag, string $id, string $name, string $value, Tree $tree): string |
|
| 76 | + { |
|
| 77 | + if (substr($tag, -4) === '_ACT') { |
|
| 78 | + return Registry::elementFactory()->make(substr('INDI:SOUR:_ACT', 0, -strlen($tag)) . $tag) |
|
| 79 | + ->edit($id, $name, $value, $tree); |
|
| 80 | + } |
|
| 81 | + return ''; |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | public function addExpectedTags(array $expected_tags): array |
| 53 | 53 | { |
| 54 | 54 | return array_merge_recursive($expected_tags, [ |
| 55 | - 'SOUR' => [ '_ACT' ] |
|
| 55 | + 'SOUR' => ['_ACT'] |
|
| 56 | 56 | ]); |
| 57 | 57 | } |
| 58 | 58 | |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | public function getLabel(string $tag): string |
| 64 | 64 | { |
| 65 | 65 | if (substr($tag, -4) === '_ACT') { |
| 66 | - return Registry::elementFactory()->make(substr('INDI:SOUR:_ACT', 0, -strlen($tag)) . $tag)->label(); |
|
| 66 | + return Registry::elementFactory()->make(substr('INDI:SOUR:_ACT', 0, -strlen($tag)).$tag)->label(); |
|
| 67 | 67 | } |
| 68 | 68 | return ''; |
| 69 | 69 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | public function editForm(string $tag, string $id, string $name, string $value, Tree $tree): string |
| 76 | 76 | { |
| 77 | 77 | if (substr($tag, -4) === '_ACT') { |
| 78 | - return Registry::elementFactory()->make(substr('INDI:SOUR:_ACT', 0, -strlen($tag)) . $tag) |
|
| 78 | + return Registry::elementFactory()->make(substr('INDI:SOUR:_ACT', 0, -strlen($tag)).$tag) |
|
| 79 | 79 | ->edit($id, $name, $value, $tree); |
| 80 | 80 | } |
| 81 | 81 | return ''; |
@@ -45,167 +45,167 @@ |
||
| 45 | 45 | * Certificates Module. |
| 46 | 46 | */ |
| 47 | 47 | class CertificatesModule extends AbstractModule implements |
| 48 | - ModuleMyArtJaubInterface, |
|
| 49 | - ModuleConfigInterface, |
|
| 50 | - ModuleGlobalInterface, |
|
| 51 | - ModuleListInterface, |
|
| 52 | - ModuleHookSubscriberInterface |
|
| 48 | + ModuleMyArtJaubInterface, |
|
| 49 | + ModuleConfigInterface, |
|
| 50 | + ModuleGlobalInterface, |
|
| 51 | + ModuleListInterface, |
|
| 52 | + ModuleHookSubscriberInterface |
|
| 53 | 53 | { |
| 54 | - use ModuleMyArtJaubTrait { |
|
| 55 | - boot as traitBoot; |
|
| 56 | - } |
|
| 57 | - use ModuleConfigTrait; |
|
| 58 | - use ModuleGlobalTrait; |
|
| 59 | - use ModuleListTrait; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * {@inheritDoc} |
|
| 63 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 64 | - */ |
|
| 65 | - public function title(): string |
|
| 66 | - { |
|
| 67 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * {@inheritDoc} |
|
| 72 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 73 | - */ |
|
| 74 | - public function description(): string |
|
| 75 | - { |
|
| 76 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 77 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * {@inheritDoc} |
|
| 82 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 83 | - */ |
|
| 84 | - public function boot(): void |
|
| 85 | - { |
|
| 86 | - $this->traitBoot(); |
|
| 87 | - Registry::elementFactory()->register([ |
|
| 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 | - |
|
| 99 | - /** |
|
| 100 | - * {@inheritDoc} |
|
| 101 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 102 | - */ |
|
| 103 | - public function loadRoutes($router): void |
|
| 104 | - { |
|
| 105 | - $router->attach('', '', static function (Map $router): void { |
|
| 106 | - |
|
| 107 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
| 108 | - |
|
| 109 | - $router->attach('', '/admin', static function (Map $router): void { |
|
| 110 | - |
|
| 111 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
| 112 | - $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
| 113 | - ->extras([ |
|
| 114 | - 'middleware' => [ |
|
| 115 | - AuthManager::class, |
|
| 116 | - ], |
|
| 117 | - ]); |
|
| 118 | - }); |
|
| 119 | - |
|
| 120 | - $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
| 121 | - ->extras([ |
|
| 122 | - 'middleware' => [AuthTreePreference::class], |
|
| 123 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
| 124 | - ]); |
|
| 125 | - |
|
| 126 | - $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
| 127 | - ->extras([ |
|
| 128 | - 'middleware' => [AuthTreePreference::class], |
|
| 129 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
| 130 | - ]); |
|
| 131 | - |
|
| 132 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
| 133 | - |
|
| 134 | - $router->extras([ |
|
| 135 | - 'middleware' => [AuthTreePreference::class], |
|
| 136 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
| 137 | - ]); |
|
| 138 | - |
|
| 139 | - $router->get(CertificatePage::class, '', CertificatePage::class); |
|
| 140 | - $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
| 141 | - }); |
|
| 142 | - }); |
|
| 143 | - }); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * {@inheritDoc} |
|
| 148 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 149 | - */ |
|
| 150 | - public function customModuleVersion(): string |
|
| 151 | - { |
|
| 152 | - return '2.1.0-v.1'; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * {@inheritDoc} |
|
| 157 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
| 158 | - */ |
|
| 159 | - public function getConfigLink(): string |
|
| 160 | - { |
|
| 161 | - return route(AdminConfigPage::class); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * {@inheritDoc} |
|
| 166 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
| 167 | - */ |
|
| 168 | - public function headContent(): string |
|
| 169 | - { |
|
| 170 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * {@inheritDoc} |
|
| 175 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
| 176 | - */ |
|
| 177 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
| 178 | - { |
|
| 179 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * {@inheritDoc} |
|
| 184 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
| 185 | - */ |
|
| 186 | - public function listMenuClass(): string |
|
| 187 | - { |
|
| 188 | - return 'menu-maj-certificates'; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * {@inheritDoc} |
|
| 193 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
| 194 | - */ |
|
| 195 | - public function listIsEmpty(Tree $tree): bool |
|
| 196 | - { |
|
| 197 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * {@inheritDoc} |
|
| 202 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 203 | - */ |
|
| 204 | - public function listSubscribedHooks(): array |
|
| 205 | - { |
|
| 206 | - return [ |
|
| 207 | - app()->makeWith(CertificateTagEditorHook::class, ['module' => $this]), |
|
| 208 | - app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
| 209 | - ]; |
|
| 210 | - } |
|
| 54 | + use ModuleMyArtJaubTrait { |
|
| 55 | + boot as traitBoot; |
|
| 56 | + } |
|
| 57 | + use ModuleConfigTrait; |
|
| 58 | + use ModuleGlobalTrait; |
|
| 59 | + use ModuleListTrait; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * {@inheritDoc} |
|
| 63 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 64 | + */ |
|
| 65 | + public function title(): string |
|
| 66 | + { |
|
| 67 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * {@inheritDoc} |
|
| 72 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 73 | + */ |
|
| 74 | + public function description(): string |
|
| 75 | + { |
|
| 76 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 77 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * {@inheritDoc} |
|
| 82 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 83 | + */ |
|
| 84 | + public function boot(): void |
|
| 85 | + { |
|
| 86 | + $this->traitBoot(); |
|
| 87 | + Registry::elementFactory()->register([ |
|
| 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 | + |
|
| 99 | + /** |
|
| 100 | + * {@inheritDoc} |
|
| 101 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 102 | + */ |
|
| 103 | + public function loadRoutes($router): void |
|
| 104 | + { |
|
| 105 | + $router->attach('', '', static function (Map $router): void { |
|
| 106 | + |
|
| 107 | + $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
| 108 | + |
|
| 109 | + $router->attach('', '/admin', static function (Map $router): void { |
|
| 110 | + |
|
| 111 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
| 112 | + $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
| 113 | + ->extras([ |
|
| 114 | + 'middleware' => [ |
|
| 115 | + AuthManager::class, |
|
| 116 | + ], |
|
| 117 | + ]); |
|
| 118 | + }); |
|
| 119 | + |
|
| 120 | + $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
| 121 | + ->extras([ |
|
| 122 | + 'middleware' => [AuthTreePreference::class], |
|
| 123 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
| 124 | + ]); |
|
| 125 | + |
|
| 126 | + $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
| 127 | + ->extras([ |
|
| 128 | + 'middleware' => [AuthTreePreference::class], |
|
| 129 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
| 130 | + ]); |
|
| 131 | + |
|
| 132 | + $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
| 133 | + |
|
| 134 | + $router->extras([ |
|
| 135 | + 'middleware' => [AuthTreePreference::class], |
|
| 136 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
| 137 | + ]); |
|
| 138 | + |
|
| 139 | + $router->get(CertificatePage::class, '', CertificatePage::class); |
|
| 140 | + $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
| 141 | + }); |
|
| 142 | + }); |
|
| 143 | + }); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * {@inheritDoc} |
|
| 148 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 149 | + */ |
|
| 150 | + public function customModuleVersion(): string |
|
| 151 | + { |
|
| 152 | + return '2.1.0-v.1'; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * {@inheritDoc} |
|
| 157 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
| 158 | + */ |
|
| 159 | + public function getConfigLink(): string |
|
| 160 | + { |
|
| 161 | + return route(AdminConfigPage::class); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * {@inheritDoc} |
|
| 166 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
| 167 | + */ |
|
| 168 | + public function headContent(): string |
|
| 169 | + { |
|
| 170 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * {@inheritDoc} |
|
| 175 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
| 176 | + */ |
|
| 177 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
| 178 | + { |
|
| 179 | + return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * {@inheritDoc} |
|
| 184 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
| 185 | + */ |
|
| 186 | + public function listMenuClass(): string |
|
| 187 | + { |
|
| 188 | + return 'menu-maj-certificates'; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * {@inheritDoc} |
|
| 193 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
| 194 | + */ |
|
| 195 | + public function listIsEmpty(Tree $tree): bool |
|
| 196 | + { |
|
| 197 | + return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * {@inheritDoc} |
|
| 202 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 203 | + */ |
|
| 204 | + public function listSubscribedHooks(): array |
|
| 205 | + { |
|
| 206 | + return [ |
|
| 207 | + app()->makeWith(CertificateTagEditorHook::class, ['module' => $this]), |
|
| 208 | + app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
| 209 | + ]; |
|
| 210 | + } |
|
| 211 | 211 | } |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function loadRoutes($router): void |
| 104 | 104 | { |
| 105 | - $router->attach('', '', static function (Map $router): void { |
|
| 105 | + $router->attach('', '', static function(Map $router): void { |
|
| 106 | 106 | |
| 107 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
| 107 | + $router->attach('', '/module-maj/certificates', static function(Map $router): void { |
|
| 108 | 108 | |
| 109 | - $router->attach('', '/admin', static function (Map $router): void { |
|
| 109 | + $router->attach('', '/admin', static function(Map $router): void { |
|
| 110 | 110 | |
| 111 | 111 | $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
| 112 | 112 | $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
| 130 | 130 | ]); |
| 131 | 131 | |
| 132 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
| 132 | + $router->attach('', '/certificate/{tree}/{cid}', static function(Map $router): void { |
|
| 133 | 133 | |
| 134 | 134 | $router->extras([ |
| 135 | 135 | 'middleware' => [AuthTreePreference::class], |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | */ |
| 168 | 168 | public function headContent(): string |
| 169 | 169 | { |
| 170 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 170 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | */ |
| 177 | 177 | public function listUrl(Tree $tree, array $parameters = []): string |
| 178 | 178 | { |
| 179 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
| 179 | + return route(CertificatesList::class, ['tree' => $tree->name()] + $parameters); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | */ |
| 195 | 195 | public function listIsEmpty(Tree $tree): bool |
| 196 | 196 | { |
| 197 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
| 197 | + return Auth::accessLevel($tree) > (int)$tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string)Auth::PRIV_HIDE); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -34,58 +34,58 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class AdminConfigPage implements RequestHandlerInterface |
| 36 | 36 | { |
| 37 | - use ViewResponseTrait; |
|
| 37 | + use ViewResponseTrait; |
|
| 38 | 38 | |
| 39 | - private ?CertificatesModule $module; |
|
| 40 | - private TreeService $tree_service; |
|
| 39 | + private ?CertificatesModule $module; |
|
| 40 | + private TreeService $tree_service; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor for Admin Config page request handler |
|
| 44 | - * |
|
| 45 | - * @param ModuleService $module_service |
|
| 46 | - */ |
|
| 47 | - public function __construct(ModuleService $module_service, TreeService $tree_service) |
|
| 48 | - { |
|
| 49 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 50 | - $this->tree_service = $tree_service; |
|
| 51 | - } |
|
| 42 | + /** |
|
| 43 | + * Constructor for Admin Config page request handler |
|
| 44 | + * |
|
| 45 | + * @param ModuleService $module_service |
|
| 46 | + */ |
|
| 47 | + public function __construct(ModuleService $module_service, TreeService $tree_service) |
|
| 48 | + { |
|
| 49 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 50 | + $this->tree_service = $tree_service; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 56 | - */ |
|
| 57 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 58 | - { |
|
| 59 | - $this->layout = 'layouts/administration'; |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 56 | + */ |
|
| 57 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 58 | + { |
|
| 59 | + $this->layout = 'layouts/administration'; |
|
| 60 | 60 | |
| 61 | - if ($this->module === null) { |
|
| 62 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 63 | - } |
|
| 61 | + if ($this->module === null) { |
|
| 62 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - $user = $request->getAttribute('user'); |
|
| 66 | - assert($user instanceof UserInterface); |
|
| 65 | + $user = $request->getAttribute('user'); |
|
| 66 | + assert($user instanceof UserInterface); |
|
| 67 | 67 | |
| 68 | - $all_trees = $this->tree_service->all()->filter(fn(Tree $tree) => Auth::isManager($tree, $user)); |
|
| 69 | - if ($all_trees->count() === 0) { |
|
| 70 | - throw new HttpAccessDeniedException(); |
|
| 71 | - } |
|
| 68 | + $all_trees = $this->tree_service->all()->filter(fn(Tree $tree) => Auth::isManager($tree, $user)); |
|
| 69 | + if ($all_trees->count() === 0) { |
|
| 70 | + throw new HttpAccessDeniedException(); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - $tree = $request->getAttribute('tree') ?? $all_trees->first(); |
|
| 74 | - assert($tree instanceof Tree); |
|
| 73 | + $tree = $request->getAttribute('tree') ?? $all_trees->first(); |
|
| 74 | + assert($tree instanceof Tree); |
|
| 75 | 75 | |
| 76 | - $data_folder = Registry::filesystem()->dataName(); |
|
| 76 | + $data_folder = Registry::filesystem()->dataName(); |
|
| 77 | 77 | |
| 78 | - $same_tree = fn(Tree $tree_collection): bool => $tree->id() === $tree_collection->id(); |
|
| 79 | - if (!$all_trees->contains($same_tree)) { |
|
| 80 | - throw new HttpAccessDeniedException(); |
|
| 81 | - } |
|
| 78 | + $same_tree = fn(Tree $tree_collection): bool => $tree->id() === $tree_collection->id(); |
|
| 79 | + if (!$all_trees->contains($same_tree)) { |
|
| 80 | + throw new HttpAccessDeniedException(); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
| 84 | - 'module_name' => $this->module->name(), |
|
| 85 | - 'title' => $this->module->title(), |
|
| 86 | - 'tree' => $tree, |
|
| 87 | - 'other_trees' => $all_trees->reject($same_tree), |
|
| 88 | - 'data_folder' => $data_folder |
|
| 89 | - ]); |
|
| 90 | - } |
|
| 83 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
| 84 | + 'module_name' => $this->module->name(), |
|
| 85 | + 'title' => $this->module->title(), |
|
| 86 | + 'tree' => $tree, |
|
| 87 | + 'other_trees' => $all_trees->reject($same_tree), |
|
| 88 | + 'data_folder' => $data_folder |
|
| 89 | + ]); |
|
| 90 | + } |
|
| 91 | 91 | } |
@@ -87,7 +87,7 @@ |
||
| 87 | 87 | throw new HttpAccessDeniedException(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
| 90 | + return $this->viewResponse($this->module->name().'::admin/config', [ |
|
| 91 | 91 | 'module_name' => $this->module->name(), |
| 92 | 92 | 'title' => $this->module->title(), |
| 93 | 93 | 'tree' => $tree, |
@@ -30,55 +30,55 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class AutoCompleteFile extends AbstractAutocompleteHandler |
| 32 | 32 | { |
| 33 | - // Tell the browser to cache the results |
|
| 34 | - protected const CACHE_LIFE = 10; |
|
| 33 | + // Tell the browser to cache the results |
|
| 34 | + protected const CACHE_LIFE = 10; |
|
| 35 | 35 | |
| 36 | - private ?CertificatesModule $module; |
|
| 37 | - private CertificateFilesystemService $certif_filesystem; |
|
| 38 | - private UrlObfuscatorService $url_obfuscator_service; |
|
| 36 | + private ?CertificatesModule $module; |
|
| 37 | + private CertificateFilesystemService $certif_filesystem; |
|
| 38 | + private UrlObfuscatorService $url_obfuscator_service; |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Constructor for AutoCompleteFile Request Handler |
|
| 42 | - * |
|
| 43 | - * @param ModuleService $module_service |
|
| 44 | - * @param CertificateFilesystemService $certif_filesystem |
|
| 45 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
| 46 | - * @param SearchService $search_service |
|
| 47 | - */ |
|
| 48 | - public function __construct( |
|
| 49 | - ModuleService $module_service, |
|
| 50 | - CertificateFilesystemService $certif_filesystem, |
|
| 51 | - UrlObfuscatorService $url_obfuscator_service, |
|
| 52 | - SearchService $search_service |
|
| 53 | - ) { |
|
| 54 | - parent::__construct($search_service); |
|
| 55 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 56 | - $this->certif_filesystem = $certif_filesystem; |
|
| 57 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 58 | - } |
|
| 40 | + /** |
|
| 41 | + * Constructor for AutoCompleteFile Request Handler |
|
| 42 | + * |
|
| 43 | + * @param ModuleService $module_service |
|
| 44 | + * @param CertificateFilesystemService $certif_filesystem |
|
| 45 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
| 46 | + * @param SearchService $search_service |
|
| 47 | + */ |
|
| 48 | + public function __construct( |
|
| 49 | + ModuleService $module_service, |
|
| 50 | + CertificateFilesystemService $certif_filesystem, |
|
| 51 | + UrlObfuscatorService $url_obfuscator_service, |
|
| 52 | + SearchService $search_service |
|
| 53 | + ) { |
|
| 54 | + parent::__construct($search_service); |
|
| 55 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 56 | + $this->certif_filesystem = $certif_filesystem; |
|
| 57 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * {@inheritDoc} |
|
| 62 | - * @see \Fisharebest\Webtrees\Http\RequestHandlers\AbstractAutocompleteHandler::search() |
|
| 63 | - */ |
|
| 64 | - protected function search(ServerRequestInterface $request): Collection |
|
| 65 | - { |
|
| 66 | - $tree = $request->getAttribute('tree'); |
|
| 67 | - assert($tree instanceof Tree); |
|
| 60 | + /** |
|
| 61 | + * {@inheritDoc} |
|
| 62 | + * @see \Fisharebest\Webtrees\Http\RequestHandlers\AbstractAutocompleteHandler::search() |
|
| 63 | + */ |
|
| 64 | + protected function search(ServerRequestInterface $request): Collection |
|
| 65 | + { |
|
| 66 | + $tree = $request->getAttribute('tree'); |
|
| 67 | + assert($tree instanceof Tree); |
|
| 68 | 68 | |
| 69 | - $city = $request->getQueryParams()['cityobf'] ?? ''; |
|
| 69 | + $city = $request->getQueryParams()['cityobf'] ?? ''; |
|
| 70 | 70 | |
| 71 | - if ($this->module === null || $city === '' || !$this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
| 72 | - return collect(); |
|
| 73 | - } |
|
| 71 | + if ($this->module === null || $city === '' || !$this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
| 72 | + return collect(); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - $query = $request->getAttribute('query') ?? ''; |
|
| 75 | + $query = $request->getAttribute('query') ?? ''; |
|
| 76 | 76 | |
| 77 | - /** @var Collection<string> $results */ |
|
| 78 | - $results = $this->certif_filesystem |
|
| 79 | - ->certificatesForCityContaining($tree, $city, $query) |
|
| 80 | - ->map(fn(Certificate $certificate): string => $certificate->filename()); |
|
| 77 | + /** @var Collection<string> $results */ |
|
| 78 | + $results = $this->certif_filesystem |
|
| 79 | + ->certificatesForCityContaining($tree, $city, $query) |
|
| 80 | + ->map(fn(Certificate $certificate): string => $certificate->filename()); |
|
| 81 | 81 | |
| 82 | - return $results; |
|
| 83 | - } |
|
| 82 | + return $results; |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -72,10 +72,10 @@ |
||
| 72 | 72 | return collect(); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - $query = $request->getAttribute('query') ?? ''; |
|
| 75 | + $query = $request->getAttribute('query') ?? ''; |
|
| 76 | 76 | |
| 77 | 77 | /** @var Collection<string> $results */ |
| 78 | - $results = $this->certif_filesystem |
|
| 78 | + $results = $this->certif_filesystem |
|
| 79 | 79 | ->certificatesForCityContaining($tree, $city, $query) |
| 80 | 80 | ->map(fn(Certificate $certificate): string => $certificate->filename()); |
| 81 | 81 | |
@@ -29,143 +29,143 @@ |
||
| 29 | 29 | class CertificateDataService |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Find individuals linked to a certificate. |
|
| 34 | - * |
|
| 35 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
| 36 | - * but does not work with Sqlite if no default escape has been defined} |
|
| 37 | - * |
|
| 38 | - * @param Certificate $certificate |
|
| 39 | - * @return Collection<\Fisharebest\Webtrees\Individual> |
|
| 40 | - */ |
|
| 41 | - public function linkedIndividuals(Certificate $certificate): Collection |
|
| 42 | - { |
|
| 43 | - $tree = $certificate->tree(); |
|
| 44 | - return DB::table('individuals') |
|
| 45 | - ->where('i_file', '=', $tree->id()) |
|
| 46 | - ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
| 47 | - ->select(['individuals.*']) |
|
| 48 | - ->get() |
|
| 49 | - ->map(Registry::individualFactory()->mapper($tree)) |
|
| 50 | - ->filter(GedcomRecord::accessFilter()); |
|
| 51 | - } |
|
| 32 | + /** |
|
| 33 | + * Find individuals linked to a certificate. |
|
| 34 | + * |
|
| 35 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
| 36 | + * but does not work with Sqlite if no default escape has been defined} |
|
| 37 | + * |
|
| 38 | + * @param Certificate $certificate |
|
| 39 | + * @return Collection<\Fisharebest\Webtrees\Individual> |
|
| 40 | + */ |
|
| 41 | + public function linkedIndividuals(Certificate $certificate): Collection |
|
| 42 | + { |
|
| 43 | + $tree = $certificate->tree(); |
|
| 44 | + return DB::table('individuals') |
|
| 45 | + ->where('i_file', '=', $tree->id()) |
|
| 46 | + ->where('i_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
| 47 | + ->select(['individuals.*']) |
|
| 48 | + ->get() |
|
| 49 | + ->map(Registry::individualFactory()->mapper($tree)) |
|
| 50 | + ->filter(GedcomRecord::accessFilter()); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Find families linked to a certificate. |
|
| 55 | - * |
|
| 56 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
| 57 | - * but does not work with Sqlite if no default escape has been defined} |
|
| 58 | - * |
|
| 59 | - * @param Certificate $certificate |
|
| 60 | - * @return Collection<\Fisharebest\Webtrees\Family> |
|
| 61 | - */ |
|
| 62 | - public function linkedFamilies(Certificate $certificate): Collection |
|
| 63 | - { |
|
| 64 | - $tree = $certificate->tree(); |
|
| 65 | - return DB::table('families') |
|
| 66 | - ->where('f_file', '=', $tree->id()) |
|
| 67 | - ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
| 68 | - ->select(['families.*']) |
|
| 69 | - ->get() |
|
| 70 | - ->map(Registry::familyFactory()->mapper($tree)) |
|
| 71 | - ->filter(GedcomRecord::accessFilter()); |
|
| 72 | - } |
|
| 53 | + /** |
|
| 54 | + * Find families linked to a certificate. |
|
| 55 | + * |
|
| 56 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
| 57 | + * but does not work with Sqlite if no default escape has been defined} |
|
| 58 | + * |
|
| 59 | + * @param Certificate $certificate |
|
| 60 | + * @return Collection<\Fisharebest\Webtrees\Family> |
|
| 61 | + */ |
|
| 62 | + public function linkedFamilies(Certificate $certificate): Collection |
|
| 63 | + { |
|
| 64 | + $tree = $certificate->tree(); |
|
| 65 | + return DB::table('families') |
|
| 66 | + ->where('f_file', '=', $tree->id()) |
|
| 67 | + ->where('f_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
| 68 | + ->select(['families.*']) |
|
| 69 | + ->get() |
|
| 70 | + ->map(Registry::familyFactory()->mapper($tree)) |
|
| 71 | + ->filter(GedcomRecord::accessFilter()); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Find media objects linked to a certificate. |
|
| 76 | - * |
|
| 77 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
| 78 | - * but does not work with Sqlite if no default escape has been defined} |
|
| 79 | - * |
|
| 80 | - * @param Certificate $certificate |
|
| 81 | - * @return Collection<\Fisharebest\Webtrees\Media> |
|
| 82 | - */ |
|
| 83 | - public function linkedMedias(Certificate $certificate): Collection |
|
| 84 | - { |
|
| 85 | - $tree = $certificate->tree(); |
|
| 86 | - return DB::table('media') |
|
| 87 | - ->where('m_file', '=', $tree->id()) |
|
| 88 | - ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
| 89 | - ->select(['media.*']) |
|
| 90 | - ->get() |
|
| 91 | - ->map(Registry::mediaFactory()->mapper($tree)) |
|
| 92 | - ->filter(GedcomRecord::accessFilter()); |
|
| 93 | - } |
|
| 74 | + /** |
|
| 75 | + * Find media objects linked to a certificate. |
|
| 76 | + * |
|
| 77 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
| 78 | + * but does not work with Sqlite if no default escape has been defined} |
|
| 79 | + * |
|
| 80 | + * @param Certificate $certificate |
|
| 81 | + * @return Collection<\Fisharebest\Webtrees\Media> |
|
| 82 | + */ |
|
| 83 | + public function linkedMedias(Certificate $certificate): Collection |
|
| 84 | + { |
|
| 85 | + $tree = $certificate->tree(); |
|
| 86 | + return DB::table('media') |
|
| 87 | + ->where('m_file', '=', $tree->id()) |
|
| 88 | + ->where('m_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
| 89 | + ->select(['media.*']) |
|
| 90 | + ->get() |
|
| 91 | + ->map(Registry::mediaFactory()->mapper($tree)) |
|
| 92 | + ->filter(GedcomRecord::accessFilter()); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Find notes linked to a certificate. |
|
| 97 | - * |
|
| 98 | - * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
| 99 | - * but does not work with Sqlite if no default escape has been defined} |
|
| 100 | - * |
|
| 101 | - * @param Certificate $certificate |
|
| 102 | - * @return Collection<\Fisharebest\Webtrees\Note> |
|
| 103 | - */ |
|
| 104 | - public function linkedNotes(Certificate $certificate): Collection |
|
| 105 | - { |
|
| 106 | - $tree = $certificate->tree(); |
|
| 107 | - return DB::table('other') |
|
| 108 | - ->where('o_file', '=', $tree->id()) |
|
| 109 | - ->where('o_type', '=', 'NOTE') |
|
| 110 | - ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
| 111 | - ->select(['other.*']) |
|
| 112 | - ->get() |
|
| 113 | - ->map(Registry::noteFactory()->mapper($tree)) |
|
| 114 | - ->filter(GedcomRecord::accessFilter()); |
|
| 115 | - } |
|
| 95 | + /** |
|
| 96 | + * Find notes linked to a certificate. |
|
| 97 | + * |
|
| 98 | + * {@internal Ideally, the underscore should be escaped in the WHERE clause, |
|
| 99 | + * but does not work with Sqlite if no default escape has been defined} |
|
| 100 | + * |
|
| 101 | + * @param Certificate $certificate |
|
| 102 | + * @return Collection<\Fisharebest\Webtrees\Note> |
|
| 103 | + */ |
|
| 104 | + public function linkedNotes(Certificate $certificate): Collection |
|
| 105 | + { |
|
| 106 | + $tree = $certificate->tree(); |
|
| 107 | + return DB::table('other') |
|
| 108 | + ->where('o_file', '=', $tree->id()) |
|
| 109 | + ->where('o_type', '=', 'NOTE') |
|
| 110 | + ->where('o_gedcom', 'like', '% _ACT ' . $this->escapedSqlPath($certificate) . '%') |
|
| 111 | + ->select(['other.*']) |
|
| 112 | + ->get() |
|
| 113 | + ->map(Registry::noteFactory()->mapper($tree)) |
|
| 114 | + ->filter(GedcomRecord::accessFilter()); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Return an escaped string to be used in SQL LIKE comparisons. |
|
| 119 | - * This would not work well for Sqlite, if the escape character is not defined. |
|
| 120 | - * |
|
| 121 | - * @param Certificate $certificate |
|
| 122 | - * @return string |
|
| 123 | - */ |
|
| 124 | - protected function escapedSqlPath(Certificate $certificate): string |
|
| 125 | - { |
|
| 126 | - return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $certificate->gedcomPath()); |
|
| 127 | - } |
|
| 117 | + /** |
|
| 118 | + * Return an escaped string to be used in SQL LIKE comparisons. |
|
| 119 | + * This would not work well for Sqlite, if the escape character is not defined. |
|
| 120 | + * |
|
| 121 | + * @param Certificate $certificate |
|
| 122 | + * @return string |
|
| 123 | + */ |
|
| 124 | + protected function escapedSqlPath(Certificate $certificate): string |
|
| 125 | + { |
|
| 126 | + return str_replace(array('\\', '%', '_'), array('\\\\', '\\%', '\\_'), $certificate->gedcomPath()); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Find a source linked to a citation where a certificate file is referenced. |
|
| 131 | - * |
|
| 132 | - * @param Certificate $certificate |
|
| 133 | - * @return Source|NULL |
|
| 134 | - */ |
|
| 135 | - public function oneLinkedSource(Certificate $certificate): ?Source |
|
| 136 | - { |
|
| 137 | - $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
|
| 138 | - $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 129 | + /** |
|
| 130 | + * Find a source linked to a citation where a certificate file is referenced. |
|
| 131 | + * |
|
| 132 | + * @param Certificate $certificate |
|
| 133 | + * @return Source|NULL |
|
| 134 | + */ |
|
| 135 | + public function oneLinkedSource(Certificate $certificate): ?Source |
|
| 136 | + { |
|
| 137 | + $regex_query = preg_quote($certificate->gedcomPath(), '/'); |
|
| 138 | + $regex_pattern = '/[1-9] SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[2-9]\s(?:(?!SOUR)\w+)\s.*)*\n[2-9] _ACT ' . $regex_query . '/i'; //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 139 | 139 | |
| 140 | - foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
|
| 141 | - foreach ($linked_records as $gedcom_record) { |
|
| 142 | - foreach ($gedcom_record->facts() as $fact) { |
|
| 143 | - if (preg_match_all($regex_pattern, $fact->gedcom(), $matches, PREG_SET_ORDER) >= 1) { |
|
| 144 | - foreach ($matches as $match) { |
|
| 145 | - $source = Registry::sourceFactory()->make($match[1], $certificate->tree()); |
|
| 146 | - if ($source !== null && $source->canShowName()) { |
|
| 147 | - return $source; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 140 | + foreach ($this->linkedRecordsLists($certificate) as $linked_records) { |
|
| 141 | + foreach ($linked_records as $gedcom_record) { |
|
| 142 | + foreach ($gedcom_record->facts() as $fact) { |
|
| 143 | + if (preg_match_all($regex_pattern, $fact->gedcom(), $matches, PREG_SET_ORDER) >= 1) { |
|
| 144 | + foreach ($matches as $match) { |
|
| 145 | + $source = Registry::sourceFactory()->make($match[1], $certificate->tree()); |
|
| 146 | + if ($source !== null && $source->canShowName()) { |
|
| 147 | + return $source; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - return null; |
|
| 156 | - } |
|
| 155 | + return null; |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * Yield lists of gedcom records linked to a certificate. |
|
| 160 | - * |
|
| 161 | - * @param Certificate $certificate |
|
| 162 | - * @return Generator |
|
| 163 | - */ |
|
| 164 | - protected function linkedRecordsLists(Certificate $certificate): Generator |
|
| 165 | - { |
|
| 166 | - yield $this->linkedIndividuals($certificate); |
|
| 167 | - yield $this->linkedFamilies($certificate); |
|
| 168 | - yield $this->linkedMedias($certificate); |
|
| 169 | - yield $this->linkedNotes($certificate); |
|
| 170 | - } |
|
| 158 | + /** |
|
| 159 | + * Yield lists of gedcom records linked to a certificate. |
|
| 160 | + * |
|
| 161 | + * @param Certificate $certificate |
|
| 162 | + * @return Generator |
|
| 163 | + */ |
|
| 164 | + protected function linkedRecordsLists(Certificate $certificate): Generator |
|
| 165 | + { |
|
| 166 | + yield $this->linkedIndividuals($certificate); |
|
| 167 | + yield $this->linkedFamilies($certificate); |
|
| 168 | + yield $this->linkedMedias($certificate); |
|
| 169 | + yield $this->linkedNotes($certificate); |
|
| 170 | + } |
|
| 171 | 171 | } |