@@ -28,114 +28,114 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class FilteredTopPlaceMapperConfig extends GenericPlaceMapperConfig |
| 30 | 30 | { |
| 31 | - private TreeService $tree_service; |
|
| 31 | + private TreeService $tree_service; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * FilteredTopPlaceMapperConfig |
|
| 35 | - * |
|
| 36 | - * @param TreeService $tree_service |
|
| 37 | - */ |
|
| 38 | - public function __construct(TreeService $tree_service) |
|
| 39 | - { |
|
| 40 | - $this->tree_service = $tree_service; |
|
| 41 | - } |
|
| 33 | + /** |
|
| 34 | + * FilteredTopPlaceMapperConfig |
|
| 35 | + * |
|
| 36 | + * @param TreeService $tree_service |
|
| 37 | + */ |
|
| 38 | + public function __construct(TreeService $tree_service) |
|
| 39 | + { |
|
| 40 | + $this->tree_service = $tree_service; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Get the configured Top Places to filter on |
|
| 45 | - * |
|
| 46 | - * @return Collection<Place> |
|
| 47 | - */ |
|
| 48 | - public function topPlaces(): Collection |
|
| 49 | - { |
|
| 50 | - return collect($this->get('topPlaces', [])) |
|
| 51 | - ->filter( |
|
| 52 | - /** @psalm-suppress MissingClosureParamType */ |
|
| 53 | - fn($item): bool => $item instanceof Place |
|
| 54 | - ); |
|
| 55 | - } |
|
| 43 | + /** |
|
| 44 | + * Get the configured Top Places to filter on |
|
| 45 | + * |
|
| 46 | + * @return Collection<Place> |
|
| 47 | + */ |
|
| 48 | + public function topPlaces(): Collection |
|
| 49 | + { |
|
| 50 | + return collect($this->get('topPlaces', [])) |
|
| 51 | + ->filter( |
|
| 52 | + /** @psalm-suppress MissingClosureParamType */ |
|
| 53 | + fn($item): bool => $item instanceof Place |
|
| 54 | + ); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * {@inheritDoc} |
|
| 59 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonSerializeConfig() |
|
| 60 | - */ |
|
| 61 | - public function jsonSerializeConfig() |
|
| 62 | - { |
|
| 63 | - return [ |
|
| 64 | - 'topPlaces' => $this->topPlaces() |
|
| 65 | - ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
| 66 | - ->toArray() |
|
| 67 | - ]; |
|
| 68 | - } |
|
| 57 | + /** |
|
| 58 | + * {@inheritDoc} |
|
| 59 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonSerializeConfig() |
|
| 60 | + */ |
|
| 61 | + public function jsonSerializeConfig() |
|
| 62 | + { |
|
| 63 | + return [ |
|
| 64 | + 'topPlaces' => $this->topPlaces() |
|
| 65 | + ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
| 66 | + ->toArray() |
|
| 67 | + ]; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * {@inheritDoc} |
|
| 72 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonDeserialize() |
|
| 73 | - * |
|
| 74 | - * @param mixed $config |
|
| 75 | - * @return $this |
|
| 76 | - */ |
|
| 77 | - public function jsonDeserialize($config): self |
|
| 78 | - { |
|
| 79 | - if (is_string($config)) { |
|
| 80 | - return $this->jsonDeserialize(json_decode($config)); |
|
| 81 | - } |
|
| 82 | - if (is_array($config)) { |
|
| 83 | - $this->setConfig([ |
|
| 84 | - 'topPlaces' => collect($config['topPlaces'] ?? []) |
|
| 85 | - ->filter( |
|
| 86 | - /** @psalm-suppress MissingClosureParamType */ |
|
| 87 | - fn($item): bool => is_array($item) && count($item) == 2 |
|
| 88 | - )->map(function (array $item): ?Place { |
|
| 89 | - try { |
|
| 90 | - return new Place($item[1], $this->tree_service->find($item[0])); |
|
| 91 | - } catch (RuntimeException $ex) { |
|
| 92 | - return null; |
|
| 93 | - } |
|
| 94 | - }) |
|
| 95 | - ->filter() |
|
| 96 | - ->toArray() |
|
| 97 | - ]); |
|
| 98 | - } |
|
| 99 | - return $this; |
|
| 100 | - } |
|
| 70 | + /** |
|
| 71 | + * {@inheritDoc} |
|
| 72 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::jsonDeserialize() |
|
| 73 | + * |
|
| 74 | + * @param mixed $config |
|
| 75 | + * @return $this |
|
| 76 | + */ |
|
| 77 | + public function jsonDeserialize($config): self |
|
| 78 | + { |
|
| 79 | + if (is_string($config)) { |
|
| 80 | + return $this->jsonDeserialize(json_decode($config)); |
|
| 81 | + } |
|
| 82 | + if (is_array($config)) { |
|
| 83 | + $this->setConfig([ |
|
| 84 | + 'topPlaces' => collect($config['topPlaces'] ?? []) |
|
| 85 | + ->filter( |
|
| 86 | + /** @psalm-suppress MissingClosureParamType */ |
|
| 87 | + fn($item): bool => is_array($item) && count($item) == 2 |
|
| 88 | + )->map(function (array $item): ?Place { |
|
| 89 | + try { |
|
| 90 | + return new Place($item[1], $this->tree_service->find($item[0])); |
|
| 91 | + } catch (RuntimeException $ex) { |
|
| 92 | + return null; |
|
| 93 | + } |
|
| 94 | + }) |
|
| 95 | + ->filter() |
|
| 96 | + ->toArray() |
|
| 97 | + ]); |
|
| 98 | + } |
|
| 99 | + return $this; |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - /** |
|
| 103 | - * {@inheritDoc} |
|
| 104 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::configContent() |
|
| 105 | - */ |
|
| 106 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 107 | - { |
|
| 108 | - return view($module->name() . '::mappers/filtered-top-config', [ |
|
| 109 | - 'tree' => $tree, |
|
| 110 | - 'top_places' => $this->topPlaces() |
|
| 111 | - ]); |
|
| 112 | - } |
|
| 102 | + /** |
|
| 103 | + * {@inheritDoc} |
|
| 104 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::configContent() |
|
| 105 | + */ |
|
| 106 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 107 | + { |
|
| 108 | + return view($module->name() . '::mappers/filtered-top-config', [ |
|
| 109 | + 'tree' => $tree, |
|
| 110 | + 'top_places' => $this->topPlaces() |
|
| 111 | + ]); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * {@inheritDoc} |
|
| 116 | - * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::withConfigUpdate() |
|
| 117 | - * @return $this |
|
| 118 | - */ |
|
| 119 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 120 | - { |
|
| 121 | - $tree = $request->getAttribute('tree'); |
|
| 122 | - if (!($tree instanceof Tree)) { |
|
| 123 | - return $this; |
|
| 124 | - } |
|
| 114 | + /** |
|
| 115 | + * {@inheritDoc} |
|
| 116 | + * @see \MyArtJaub\Webtrees\Common\GeoDispersion\Config\GenericPlaceMapperConfig::withConfigUpdate() |
|
| 117 | + * @return $this |
|
| 118 | + */ |
|
| 119 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 120 | + { |
|
| 121 | + $tree = $request->getAttribute('tree'); |
|
| 122 | + if (!($tree instanceof Tree)) { |
|
| 123 | + return $this; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $params = (array) $request->getParsedBody(); |
|
| 126 | + $params = (array) $request->getParsedBody(); |
|
| 127 | 127 | |
| 128 | - $top_places = $params['mapper_filt_top_places'] ?? []; |
|
| 129 | - if (is_array($top_places)) { |
|
| 130 | - $config = ['topPlaces' => []]; |
|
| 131 | - foreach ($top_places as $top_place_id) { |
|
| 132 | - $place = Place::find((int) $top_place_id, $tree); |
|
| 133 | - if (mb_strlen($place->gedcomName()) > 0) { |
|
| 134 | - $config['topPlaces'][] = $place; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - $this->setConfig($config); |
|
| 138 | - } |
|
| 139 | - return $this; |
|
| 140 | - } |
|
| 128 | + $top_places = $params['mapper_filt_top_places'] ?? []; |
|
| 129 | + if (is_array($top_places)) { |
|
| 130 | + $config = ['topPlaces' => []]; |
|
| 131 | + foreach ($top_places as $top_place_id) { |
|
| 132 | + $place = Place::find((int) $top_place_id, $tree); |
|
| 133 | + if (mb_strlen($place->gedcomName()) > 0) { |
|
| 134 | + $config['topPlaces'][] = $place; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + $this->setConfig($config); |
|
| 138 | + } |
|
| 139 | + return $this; |
|
| 140 | + } |
|
| 141 | 141 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | { |
| 63 | 63 | return [ |
| 64 | 64 | 'topPlaces' => $this->topPlaces() |
| 65 | - ->map(fn(Place $place): array => [ $place->tree()->id(), $place->gedcomName() ]) |
|
| 65 | + ->map(fn(Place $place): array => [$place->tree()->id(), $place->gedcomName()]) |
|
| 66 | 66 | ->toArray() |
| 67 | 67 | ]; |
| 68 | 68 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | ->filter( |
| 83 | 83 | /** @psalm-suppress MissingClosureParamType */ |
| 84 | 84 | fn($item): bool => is_array($item) && count($item) == 2 |
| 85 | - )->map(function (array $item): ?Place { |
|
| 85 | + )->map(function(array $item): ?Place { |
|
| 86 | 86 | try { |
| 87 | 87 | return new Place($item[1], $this->tree_service->find($item[0])); |
| 88 | 88 | } catch (RuntimeException $ex) { |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function configContent(ModuleInterface $module, Tree $tree): string |
| 104 | 104 | { |
| 105 | - return view($module->name() . '::mappers/filtered-top-config', [ |
|
| 105 | + return view($module->name().'::mappers/filtered-top-config', [ |
|
| 106 | 106 | 'tree' => $tree, |
| 107 | 107 | 'top_places' => $this->topPlaces() |
| 108 | 108 | ]); |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | return $this; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $params = (array) $request->getParsedBody(); |
|
| 122 | + $params = (array)$request->getParsedBody(); |
|
| 123 | 123 | |
| 124 | 124 | $top_places = $params['mapper_filt_top_places'] ?? []; |
| 125 | 125 | if (is_array($top_places)) { |
| 126 | 126 | $config = ['topPlaces' => []]; |
| 127 | 127 | foreach ($top_places as $top_place_id) { |
| 128 | - $place = Place::find((int) $top_place_id, $tree); |
|
| 128 | + $place = Place::find((int)$top_place_id, $tree); |
|
| 129 | 129 | if (mb_strlen($place->gedcomName()) > 0) { |
| 130 | 130 | $config['topPlaces'][] = $place; |
| 131 | 131 | } |
@@ -28,51 +28,51 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class SimpleTopFilteredPlaceMapper extends SimplePlaceMapper implements PlaceMapperInterface |
| 30 | 30 | { |
| 31 | - use TopFilteredPlaceMapperTrait; |
|
| 31 | + use TopFilteredPlaceMapperTrait; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * {@inheritDoc} |
|
| 35 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title() |
|
| 36 | - */ |
|
| 37 | - public function title(): string |
|
| 38 | - { |
|
| 39 | - return I18N::translate('Mapping on place name with filter'); |
|
| 40 | - } |
|
| 33 | + /** |
|
| 34 | + * {@inheritDoc} |
|
| 35 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::title() |
|
| 36 | + */ |
|
| 37 | + public function title(): string |
|
| 38 | + { |
|
| 39 | + return I18N::translate('Mapping on place name with filter'); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * {@inheritDoc} |
|
| 44 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
| 45 | - */ |
|
| 46 | - public function boot(): void |
|
| 47 | - { |
|
| 48 | - parent::boot(); |
|
| 49 | - $top_places = $this->config()->get('topPlaces'); |
|
| 50 | - if (is_array($top_places)) { |
|
| 51 | - $this->setTopPlaces($top_places); |
|
| 52 | - } |
|
| 53 | - } |
|
| 42 | + /** |
|
| 43 | + * {@inheritDoc} |
|
| 44 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
| 45 | + */ |
|
| 46 | + public function boot(): void |
|
| 47 | + { |
|
| 48 | + parent::boot(); |
|
| 49 | + $top_places = $this->config()->get('topPlaces'); |
|
| 50 | + if (is_array($top_places)) { |
|
| 51 | + $this->setTopPlaces($top_places); |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * {@inheritDoc} |
|
| 57 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
| 58 | - */ |
|
| 59 | - public function config(): PlaceMapperConfigInterface |
|
| 60 | - { |
|
| 61 | - if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) { |
|
| 62 | - $this->setConfig(app(FilteredTopPlaceMapperConfig::class)); |
|
| 63 | - } |
|
| 64 | - return parent::config(); |
|
| 65 | - } |
|
| 55 | + /** |
|
| 56 | + * {@inheritDoc} |
|
| 57 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
| 58 | + */ |
|
| 59 | + public function config(): PlaceMapperConfigInterface |
|
| 60 | + { |
|
| 61 | + if (!(parent::config() instanceof FilteredTopPlaceMapperConfig)) { |
|
| 62 | + $this->setConfig(app(FilteredTopPlaceMapperConfig::class)); |
|
| 63 | + } |
|
| 64 | + return parent::config(); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * {@inheritDoc} |
|
| 69 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map() |
|
| 70 | - */ |
|
| 71 | - public function map(Place $place, string $feature_property): ?string |
|
| 72 | - { |
|
| 73 | - if (!$this->belongsToTopLevels($place)) { |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - return parent::map($place, $feature_property); |
|
| 77 | - } |
|
| 67 | + /** |
|
| 68 | + * {@inheritDoc} |
|
| 69 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\PlaceMappers\SimplePlaceMapper::map() |
|
| 70 | + */ |
|
| 71 | + public function map(Place $place, string $feature_property): ?string |
|
| 72 | + { |
|
| 73 | + if (!$this->belongsToTopLevels($place)) { |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + return parent::map($place, $feature_property); |
|
| 77 | + } |
|
| 78 | 78 | } |
@@ -36,183 +36,183 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class CoordinatesPlaceMapper implements PlaceMapperInterface |
| 38 | 38 | { |
| 39 | - use PlaceMapperTrait; |
|
| 40 | - |
|
| 41 | - private ?string $cache_key = null; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * {@inheritDoc} |
|
| 45 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
| 46 | - */ |
|
| 47 | - public function title(): string |
|
| 48 | - { |
|
| 49 | - return I18N::translate('Mapping on place coordinates'); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * |
|
| 55 | - * {@internal The Place is associated to a Point only. |
|
| 56 | - * PlaceLocation can calculate a BoundingBox. |
|
| 57 | - * Using a BoundingBox could make the mapping more complex and potentially arbitary. |
|
| 58 | - * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents. |
|
| 59 | - * This could create the unwanted side effect of a very large area to consider} |
|
| 60 | - * |
|
| 61 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
| 62 | - */ |
|
| 63 | - public function map(Place $place, string $feature_property): ?string |
|
| 64 | - { |
|
| 65 | - $location = new PlaceLocation($place->gedcomName()); |
|
| 66 | - $longitude = $location->longitude(); |
|
| 67 | - $latitude = $location->latitude(); |
|
| 68 | - if ($longitude === null || $latitude === null) { |
|
| 69 | - return null; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - $features_index = $this->featuresIndex(); |
|
| 73 | - if ($features_index === null) { |
|
| 74 | - return null; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $place_point = Point::xy($longitude, $latitude, $features_index['SRID']); |
|
| 78 | - $grid_box = $this->getGridCell( |
|
| 79 | - $place_point, |
|
| 80 | - $features_index['map_NE'], |
|
| 81 | - $features_index['map_SW'], |
|
| 82 | - $features_index['nb_columns'] |
|
| 83 | - ); |
|
| 84 | - if ($grid_box === null || !$this->setGeometryEngine()) { |
|
| 85 | - return null; |
|
| 86 | - } |
|
| 87 | - $features = $features_index['grid'][$grid_box[0]][$grid_box[1]]; |
|
| 88 | - foreach ($features as $feature) { |
|
| 89 | - $geometry = $feature->getGeometry(); |
|
| 90 | - if ($place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) { |
|
| 91 | - return $feature->getProperty($feature_property); |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - return null; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * Return the XY coordinates in a bounded grid of the cell containing a specific point. |
|
| 99 | - * |
|
| 100 | - * @param Point $point Point to find |
|
| 101 | - * @param Point $grid_NE North-East point of the bounded grid |
|
| 102 | - * @param Point $grid_SW South-West point fo the bounded grid |
|
| 103 | - * @param int $grid_columns Number of columns/rows in the grid |
|
| 104 | - * @return array|NULL |
|
| 105 | - */ |
|
| 106 | - protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array |
|
| 107 | - { |
|
| 108 | - list($x, $y) = $point->toArray(); |
|
| 109 | - list($x_max, $y_max) = $grid_NE->toArray(); |
|
| 110 | - list($x_min, $y_min) = $grid_SW->toArray(); |
|
| 111 | - |
|
| 112 | - $x_step = ($x_max - $x_min) / $grid_columns; |
|
| 113 | - $y_step = ($y_max - $y_min) / $grid_columns; |
|
| 114 | - |
|
| 115 | - if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) { |
|
| 116 | - return [ |
|
| 117 | - $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step), |
|
| 118 | - $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step) |
|
| 119 | - ]; |
|
| 120 | - } |
|
| 121 | - return null; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Get an indexed array of the features of the map. |
|
| 126 | - * |
|
| 127 | - * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell. |
|
| 128 | - * The grid is computed once for each map, and cached.} |
|
| 129 | - * |
|
| 130 | - * @return array|NULL |
|
| 131 | - */ |
|
| 132 | - protected function featuresIndex(): ?array |
|
| 133 | - { |
|
| 134 | - $cacheKey = $this->cacheKey(); |
|
| 135 | - if ($cacheKey === null) { |
|
| 136 | - return null; |
|
| 137 | - } |
|
| 138 | - return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
| 139 | - $map_def = $this->data('map'); |
|
| 140 | - if ( |
|
| 141 | - !$this->setGeometryEngine() |
|
| 142 | - || $map_def === null |
|
| 143 | - || !($map_def instanceof MapDefinitionInterface) |
|
| 144 | - ) { |
|
| 145 | - return null; |
|
| 146 | - } |
|
| 147 | - $bounding_boxes = []; |
|
| 148 | - $map_bounding_box = new BoundingBox(); |
|
| 149 | - $srid = 0; |
|
| 150 | - foreach ($map_def->features() as $feature) { |
|
| 151 | - $geometry = $feature->getGeometry(); |
|
| 152 | - if ($geometry === null) { |
|
| 153 | - continue; |
|
| 154 | - } |
|
| 155 | - $srid = $geometry->SRID(); |
|
| 156 | - $bounding_box = $geometry->getBoundingBox(); |
|
| 157 | - $bounding_boxes[] = [$feature, $bounding_box]; |
|
| 158 | - $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
| 159 | - } |
|
| 160 | - $grid_columns = count($bounding_boxes); |
|
| 161 | - $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
| 162 | - $map_NE = $map_bounding_box->getNorthEast(); |
|
| 163 | - $map_SW = $map_bounding_box->getSouthWest(); |
|
| 164 | - foreach ($bounding_boxes as $item) { |
|
| 165 | - $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
| 166 | - $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
| 167 | - for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
| 168 | - for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
| 169 | - $grid[$i][$j][] = $item[0]; |
|
| 170 | - } |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - return [ |
|
| 174 | - 'grid' => $grid, |
|
| 175 | - 'nb_columns' => $grid_columns, |
|
| 176 | - 'map_NE' => $map_NE, |
|
| 177 | - 'map_SW' => $map_SW, |
|
| 178 | - 'SRID' => $srid |
|
| 179 | - ]; |
|
| 180 | - }); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Set the Brick Geo Engine to use the database for geospatial computations. |
|
| 185 | - * The engine is set only if it has not been set beforehand. |
|
| 186 | - * |
|
| 187 | - * @return bool |
|
| 188 | - */ |
|
| 189 | - protected function setGeometryEngine(): bool |
|
| 190 | - { |
|
| 191 | - try { |
|
| 192 | - if (!GeometryEngineRegistry::has()) { |
|
| 193 | - GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo())); |
|
| 194 | - } |
|
| 195 | - $point = Point::xy(1, 1); |
|
| 196 | - return $point->equals($point); |
|
| 197 | - } catch (Throwable $ex) { |
|
| 198 | - } |
|
| 199 | - return false; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Get the key to cache the indexed grid of features. |
|
| 204 | - * |
|
| 205 | - * @return string|NULL |
|
| 206 | - */ |
|
| 207 | - protected function cacheKey(): ?string |
|
| 208 | - { |
|
| 209 | - if ($this->cache_key === null) { |
|
| 210 | - $map_def = $this->data('map'); |
|
| 211 | - if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
| 212 | - return null; |
|
| 213 | - } |
|
| 214 | - return spl_object_id($this) . '-map-' . $map_def->id(); |
|
| 215 | - } |
|
| 216 | - return $this->cache_key; |
|
| 217 | - } |
|
| 39 | + use PlaceMapperTrait; |
|
| 40 | + |
|
| 41 | + private ?string $cache_key = null; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * {@inheritDoc} |
|
| 45 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::title() |
|
| 46 | + */ |
|
| 47 | + public function title(): string |
|
| 48 | + { |
|
| 49 | + return I18N::translate('Mapping on place coordinates'); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * |
|
| 55 | + * {@internal The Place is associated to a Point only. |
|
| 56 | + * PlaceLocation can calculate a BoundingBox. |
|
| 57 | + * Using a BoundingBox could make the mapping more complex and potentially arbitary. |
|
| 58 | + * Furthermore, when no coordinate is found for the place or its children, then it bubbles up to the parents. |
|
| 59 | + * This could create the unwanted side effect of a very large area to consider} |
|
| 60 | + * |
|
| 61 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::map() |
|
| 62 | + */ |
|
| 63 | + public function map(Place $place, string $feature_property): ?string |
|
| 64 | + { |
|
| 65 | + $location = new PlaceLocation($place->gedcomName()); |
|
| 66 | + $longitude = $location->longitude(); |
|
| 67 | + $latitude = $location->latitude(); |
|
| 68 | + if ($longitude === null || $latitude === null) { |
|
| 69 | + return null; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + $features_index = $this->featuresIndex(); |
|
| 73 | + if ($features_index === null) { |
|
| 74 | + return null; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $place_point = Point::xy($longitude, $latitude, $features_index['SRID']); |
|
| 78 | + $grid_box = $this->getGridCell( |
|
| 79 | + $place_point, |
|
| 80 | + $features_index['map_NE'], |
|
| 81 | + $features_index['map_SW'], |
|
| 82 | + $features_index['nb_columns'] |
|
| 83 | + ); |
|
| 84 | + if ($grid_box === null || !$this->setGeometryEngine()) { |
|
| 85 | + return null; |
|
| 86 | + } |
|
| 87 | + $features = $features_index['grid'][$grid_box[0]][$grid_box[1]]; |
|
| 88 | + foreach ($features as $feature) { |
|
| 89 | + $geometry = $feature->getGeometry(); |
|
| 90 | + if ($place_point->SRID() === $geometry->SRID() && $geometry->contains($place_point)) { |
|
| 91 | + return $feature->getProperty($feature_property); |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + return null; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * Return the XY coordinates in a bounded grid of the cell containing a specific point. |
|
| 99 | + * |
|
| 100 | + * @param Point $point Point to find |
|
| 101 | + * @param Point $grid_NE North-East point of the bounded grid |
|
| 102 | + * @param Point $grid_SW South-West point fo the bounded grid |
|
| 103 | + * @param int $grid_columns Number of columns/rows in the grid |
|
| 104 | + * @return array|NULL |
|
| 105 | + */ |
|
| 106 | + protected function getGridCell(Point $point, Point $grid_NE, Point $grid_SW, int $grid_columns): ?array |
|
| 107 | + { |
|
| 108 | + list($x, $y) = $point->toArray(); |
|
| 109 | + list($x_max, $y_max) = $grid_NE->toArray(); |
|
| 110 | + list($x_min, $y_min) = $grid_SW->toArray(); |
|
| 111 | + |
|
| 112 | + $x_step = ($x_max - $x_min) / $grid_columns; |
|
| 113 | + $y_step = ($y_max - $y_min) / $grid_columns; |
|
| 114 | + |
|
| 115 | + if ($x_min <= $x && $x <= $x_max && $y_min <= $y && $y <= $y_max) { |
|
| 116 | + return [ |
|
| 117 | + $x === $x_max ? $grid_columns - 1 : intval(($x - $x_min) / $x_step), |
|
| 118 | + $y === $y_max ? $grid_columns - 1 : intval(($y - $y_min) / $y_step) |
|
| 119 | + ]; |
|
| 120 | + } |
|
| 121 | + return null; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Get an indexed array of the features of the map. |
|
| 126 | + * |
|
| 127 | + * {@internal The map is divided in a grid, eacg cell containing the features which bounding box overlaps that cell. |
|
| 128 | + * The grid is computed once for each map, and cached.} |
|
| 129 | + * |
|
| 130 | + * @return array|NULL |
|
| 131 | + */ |
|
| 132 | + protected function featuresIndex(): ?array |
|
| 133 | + { |
|
| 134 | + $cacheKey = $this->cacheKey(); |
|
| 135 | + if ($cacheKey === null) { |
|
| 136 | + return null; |
|
| 137 | + } |
|
| 138 | + return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
| 139 | + $map_def = $this->data('map'); |
|
| 140 | + if ( |
|
| 141 | + !$this->setGeometryEngine() |
|
| 142 | + || $map_def === null |
|
| 143 | + || !($map_def instanceof MapDefinitionInterface) |
|
| 144 | + ) { |
|
| 145 | + return null; |
|
| 146 | + } |
|
| 147 | + $bounding_boxes = []; |
|
| 148 | + $map_bounding_box = new BoundingBox(); |
|
| 149 | + $srid = 0; |
|
| 150 | + foreach ($map_def->features() as $feature) { |
|
| 151 | + $geometry = $feature->getGeometry(); |
|
| 152 | + if ($geometry === null) { |
|
| 153 | + continue; |
|
| 154 | + } |
|
| 155 | + $srid = $geometry->SRID(); |
|
| 156 | + $bounding_box = $geometry->getBoundingBox(); |
|
| 157 | + $bounding_boxes[] = [$feature, $bounding_box]; |
|
| 158 | + $map_bounding_box = $map_bounding_box->extendedWithBoundingBox($bounding_box); |
|
| 159 | + } |
|
| 160 | + $grid_columns = count($bounding_boxes); |
|
| 161 | + $grid = array_fill(0, $grid_columns, array_fill(0, $grid_columns, [])); |
|
| 162 | + $map_NE = $map_bounding_box->getNorthEast(); |
|
| 163 | + $map_SW = $map_bounding_box->getSouthWest(); |
|
| 164 | + foreach ($bounding_boxes as $item) { |
|
| 165 | + $grid_box_SW = $this->getGridCell($item[1]->getSouthWest(), $map_NE, $map_SW, $grid_columns) ?? [1, 1]; |
|
| 166 | + $grid_box_NE = $this->getGridCell($item[1]->getNorthEast(), $map_NE, $map_SW, $grid_columns) ?? [0, 0]; |
|
| 167 | + for ($i = $grid_box_SW[0]; $i <= $grid_box_NE[0]; $i++) { |
|
| 168 | + for ($j = $grid_box_SW[1]; $j <= $grid_box_NE[1]; $j++) { |
|
| 169 | + $grid[$i][$j][] = $item[0]; |
|
| 170 | + } |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + return [ |
|
| 174 | + 'grid' => $grid, |
|
| 175 | + 'nb_columns' => $grid_columns, |
|
| 176 | + 'map_NE' => $map_NE, |
|
| 177 | + 'map_SW' => $map_SW, |
|
| 178 | + 'SRID' => $srid |
|
| 179 | + ]; |
|
| 180 | + }); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Set the Brick Geo Engine to use the database for geospatial computations. |
|
| 185 | + * The engine is set only if it has not been set beforehand. |
|
| 186 | + * |
|
| 187 | + * @return bool |
|
| 188 | + */ |
|
| 189 | + protected function setGeometryEngine(): bool |
|
| 190 | + { |
|
| 191 | + try { |
|
| 192 | + if (!GeometryEngineRegistry::has()) { |
|
| 193 | + GeometryEngineRegistry::set(new PDOEngine(DB::connection()->getPdo())); |
|
| 194 | + } |
|
| 195 | + $point = Point::xy(1, 1); |
|
| 196 | + return $point->equals($point); |
|
| 197 | + } catch (Throwable $ex) { |
|
| 198 | + } |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Get the key to cache the indexed grid of features. |
|
| 204 | + * |
|
| 205 | + * @return string|NULL |
|
| 206 | + */ |
|
| 207 | + protected function cacheKey(): ?string |
|
| 208 | + { |
|
| 209 | + if ($this->cache_key === null) { |
|
| 210 | + $map_def = $this->data('map'); |
|
| 211 | + if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
|
| 212 | + return null; |
|
| 213 | + } |
|
| 214 | + return spl_object_id($this) . '-map-' . $map_def->id(); |
|
| 215 | + } |
|
| 216 | + return $this->cache_key; |
|
| 217 | + } |
|
| 218 | 218 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | if ($cacheKey === null) { |
| 126 | 126 | return null; |
| 127 | 127 | } |
| 128 | - return Registry::cache()->array()->remember($cacheKey, function (): ?array { |
|
| 128 | + return Registry::cache()->array()->remember($cacheKey, function(): ?array { |
|
| 129 | 129 | $map_def = $this->data('map'); |
| 130 | 130 | if ( |
| 131 | 131 | !$this->setGeometryEngine() |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | if ($map_def === null || !($map_def instanceof MapDefinitionInterface)) { |
| 202 | 202 | return null; |
| 203 | 203 | } |
| 204 | - return spl_object_id($this) . '-map-' . $map_def->id(); |
|
| 204 | + return spl_object_id($this).'-map-'.$map_def->id(); |
|
| 205 | 205 | } |
| 206 | 206 | return $this->cache_key; |
| 207 | 207 | } |
@@ -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 | } |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | ->withProperty( |
| 124 | 124 | 'places', |
| 125 | 125 | $feature_data->places() |
| 126 | - ->map(fn(GeoAnalysisPlace $place): string => $place->place()->firstParts(1)->first()) |
|
| 126 | + ->map(fn(GeoAnalysisPlace $place) : string => $place->place()->firstParts(1)->first()) |
|
| 127 | 127 | ->sort(I18N::comparator()) |
| 128 | 128 | ->toArray() |
| 129 | 129 | ); |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | $features_data |
| 136 | 136 | ->filter(fn(MapFeatureAnalysisData $data) => !$data->existsInMap()) |
| 137 | 137 | ->each( |
| 138 | - fn (MapFeatureAnalysisData $data) => |
|
| 138 | + fn(MapFeatureAnalysisData $data) => |
|
| 139 | 139 | $data->places()->each( |
| 140 | 140 | fn(GeoAnalysisPlace $place) => $result->exclude($place) |
| 141 | 141 | ) |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $features_mapping = new Collection(); |
| 156 | 156 | |
| 157 | 157 | $byplaces = $result->knownPlaces(); |
| 158 | - $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
| 158 | + $byplaces->each(function(GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
| 159 | 159 | $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty()); |
| 160 | 160 | |
| 161 | 161 | if ($id !== null && mb_strlen($id) > 0) { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | } |
| 169 | 169 | }); |
| 170 | 170 | |
| 171 | - return [ $features_mapping, $result]; |
|
| 171 | + return [$features_mapping, $result]; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -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 | /** |