@@ -25,53 +25,53 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class IsSourcedStatusHook implements RecordNameTextExtenderInterface |
| 27 | 27 | { |
| 28 | - private ModuleInterface $module; |
|
| 29 | - private SourceStatusService $source_status_service; |
|
| 28 | + private ModuleInterface $module; |
|
| 29 | + private SourceStatusService $source_status_service; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Constructor for IsSourcedStatusHook |
|
| 33 | - * |
|
| 34 | - * @param ModuleInterface $module |
|
| 35 | - * @param SourceStatusService $source_status_service |
|
| 36 | - */ |
|
| 37 | - public function __construct(ModuleInterface $module, SourceStatusService $source_status_service) |
|
| 38 | - { |
|
| 39 | - $this->module = $module; |
|
| 40 | - $this->source_status_service = $source_status_service; |
|
| 41 | - } |
|
| 31 | + /** |
|
| 32 | + * Constructor for IsSourcedStatusHook |
|
| 33 | + * |
|
| 34 | + * @param ModuleInterface $module |
|
| 35 | + * @param SourceStatusService $source_status_service |
|
| 36 | + */ |
|
| 37 | + public function __construct(ModuleInterface $module, SourceStatusService $source_status_service) |
|
| 38 | + { |
|
| 39 | + $this->module = $module; |
|
| 40 | + $this->source_status_service = $source_status_service; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * {@inheritDoc} |
|
| 45 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 46 | - */ |
|
| 47 | - public function module(): ModuleInterface |
|
| 48 | - { |
|
| 49 | - return $this->module; |
|
| 50 | - } |
|
| 43 | + /** |
|
| 44 | + * {@inheritDoc} |
|
| 45 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 46 | + */ |
|
| 47 | + public function module(): ModuleInterface |
|
| 48 | + { |
|
| 49 | + return $this->module; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
| 55 | - */ |
|
| 56 | - public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 57 | - { |
|
| 58 | - return ''; |
|
| 59 | - } |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
| 55 | + */ |
|
| 56 | + public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 57 | + { |
|
| 58 | + return ''; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritDoc} |
|
| 63 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
| 64 | - */ |
|
| 65 | - public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 66 | - { |
|
| 67 | - if ($use_long && $record instanceof Individual) { |
|
| 68 | - return view($this->module()->name() . '::hooks/name-append', [ |
|
| 69 | - 'module_name' => $this->module()->name(), |
|
| 70 | - 'source_status_service' => $this->source_status_service, |
|
| 71 | - 'individual' => $record, |
|
| 72 | - 'size_style' => $size |
|
| 73 | - ]); |
|
| 74 | - } |
|
| 75 | - return ''; |
|
| 76 | - } |
|
| 61 | + /** |
|
| 62 | + * {@inheritDoc} |
|
| 63 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
| 64 | + */ |
|
| 65 | + public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 66 | + { |
|
| 67 | + if ($use_long && $record instanceof Individual) { |
|
| 68 | + return view($this->module()->name() . '::hooks/name-append', [ |
|
| 69 | + 'module_name' => $this->module()->name(), |
|
| 70 | + 'source_status_service' => $this->source_status_service, |
|
| 71 | + 'individual' => $record, |
|
| 72 | + 'size_style' => $size |
|
| 73 | + ]); |
|
| 74 | + } |
|
| 75 | + return ''; |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -25,106 +25,106 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class GenericPlaceMapperConfig implements PlaceMapperConfigInterface |
| 27 | 27 | { |
| 28 | - /** @var array<string, mixed> $config */ |
|
| 29 | - private array $config = []; |
|
| 28 | + /** @var array<string, mixed> $config */ |
|
| 29 | + private array $config = []; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Get the generic mapper's config |
|
| 33 | - * |
|
| 34 | - * @return array<string, mixed> |
|
| 35 | - */ |
|
| 36 | - public function config(): array |
|
| 37 | - { |
|
| 38 | - return $this->config; |
|
| 39 | - } |
|
| 31 | + /** |
|
| 32 | + * Get the generic mapper's config |
|
| 33 | + * |
|
| 34 | + * @return array<string, mixed> |
|
| 35 | + */ |
|
| 36 | + public function config(): array |
|
| 37 | + { |
|
| 38 | + return $this->config; |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Set the generic mapper's config |
|
| 43 | - * |
|
| 44 | - * @param array<string, mixed> $config |
|
| 45 | - * @return $this |
|
| 46 | - */ |
|
| 47 | - public function setConfig(array $config): self |
|
| 48 | - { |
|
| 49 | - $this->config = $config; |
|
| 50 | - return $this; |
|
| 51 | - } |
|
| 41 | + /** |
|
| 42 | + * Set the generic mapper's config |
|
| 43 | + * |
|
| 44 | + * @param array<string, mixed> $config |
|
| 45 | + * @return $this |
|
| 46 | + */ |
|
| 47 | + public function setConfig(array $config): self |
|
| 48 | + { |
|
| 49 | + $this->config = $config; |
|
| 50 | + return $this; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 56 | - */ |
|
| 57 | - public function get(string $key, $default = null) |
|
| 58 | - { |
|
| 59 | - return $this->config[$key] ?? $default; |
|
| 60 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 56 | + */ |
|
| 57 | + public function get(string $key, $default = null) |
|
| 58 | + { |
|
| 59 | + return $this->config[$key] ?? $default; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * {@inheritDoc} |
|
| 64 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 65 | - */ |
|
| 66 | - public function has(string $key): bool |
|
| 67 | - { |
|
| 68 | - return key_exists($key, $this->config); |
|
| 69 | - } |
|
| 62 | + /** |
|
| 63 | + * {@inheritDoc} |
|
| 64 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 65 | + */ |
|
| 66 | + public function has(string $key): bool |
|
| 67 | + { |
|
| 68 | + return key_exists($key, $this->config); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * {@inheritDoc} |
|
| 73 | - * @see \JsonSerializable::jsonSerialize() |
|
| 74 | - */ |
|
| 75 | - #[\ReturnTypeWillChange] |
|
| 76 | - public function jsonSerialize() |
|
| 77 | - { |
|
| 78 | - return [ |
|
| 79 | - 'class' => get_class($this), |
|
| 80 | - 'config' => $this->jsonSerializeConfig() |
|
| 81 | - ]; |
|
| 82 | - } |
|
| 71 | + /** |
|
| 72 | + * {@inheritDoc} |
|
| 73 | + * @see \JsonSerializable::jsonSerialize() |
|
| 74 | + */ |
|
| 75 | + #[\ReturnTypeWillChange] |
|
| 76 | + public function jsonSerialize() |
|
| 77 | + { |
|
| 78 | + return [ |
|
| 79 | + 'class' => get_class($this), |
|
| 80 | + 'config' => $this->jsonSerializeConfig() |
|
| 81 | + ]; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Returns a representation of the mapper config compatible with Json serialisation |
|
| 86 | - * |
|
| 87 | - * @return mixed |
|
| 88 | - */ |
|
| 89 | - public function jsonSerializeConfig() |
|
| 90 | - { |
|
| 91 | - return $this->config; |
|
| 92 | - } |
|
| 84 | + /** |
|
| 85 | + * Returns a representation of the mapper config compatible with Json serialisation |
|
| 86 | + * |
|
| 87 | + * @return mixed |
|
| 88 | + */ |
|
| 89 | + public function jsonSerializeConfig() |
|
| 90 | + { |
|
| 91 | + return $this->config; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * {@inheritDoc} |
|
| 96 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 97 | - * |
|
| 98 | - * @param mixed $config |
|
| 99 | - * @return $this |
|
| 100 | - */ |
|
| 101 | - public function jsonDeserialize($config): self |
|
| 102 | - { |
|
| 103 | - if (is_string($config)) { |
|
| 104 | - return $this->jsonDeserialize((array) json_decode($config)); |
|
| 105 | - } |
|
| 106 | - if (is_array($config)) { |
|
| 107 | - return $this->setConfig($config); |
|
| 108 | - } |
|
| 109 | - return $this; |
|
| 110 | - } |
|
| 94 | + /** |
|
| 95 | + * {@inheritDoc} |
|
| 96 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 97 | + * |
|
| 98 | + * @param mixed $config |
|
| 99 | + * @return $this |
|
| 100 | + */ |
|
| 101 | + public function jsonDeserialize($config): self |
|
| 102 | + { |
|
| 103 | + if (is_string($config)) { |
|
| 104 | + return $this->jsonDeserialize((array) json_decode($config)); |
|
| 105 | + } |
|
| 106 | + if (is_array($config)) { |
|
| 107 | + return $this->setConfig($config); |
|
| 108 | + } |
|
| 109 | + return $this; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 113 | - * {@inheritDoc} |
|
| 114 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 115 | - */ |
|
| 116 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 117 | - { |
|
| 118 | - return ''; |
|
| 119 | - } |
|
| 112 | + /** |
|
| 113 | + * {@inheritDoc} |
|
| 114 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 115 | + */ |
|
| 116 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 117 | + { |
|
| 118 | + return ''; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * {@inheritDoc} |
|
| 123 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 124 | - * @return $this |
|
| 125 | - */ |
|
| 126 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 127 | - { |
|
| 128 | - return $this; |
|
| 129 | - } |
|
| 121 | + /** |
|
| 122 | + * {@inheritDoc} |
|
| 123 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 124 | + * @return $this |
|
| 125 | + */ |
|
| 126 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 127 | + { |
|
| 128 | + return $this; |
|
| 129 | + } |
|
| 130 | 130 | } |
@@ -26,62 +26,62 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class NullPlaceMapperConfig implements PlaceMapperConfigInterface |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * {@inheritDoc} |
|
| 31 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 32 | - */ |
|
| 33 | - public function get(string $key, $default = null) |
|
| 34 | - { |
|
| 35 | - return $default; |
|
| 36 | - } |
|
| 29 | + /** |
|
| 30 | + * {@inheritDoc} |
|
| 31 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::get() |
|
| 32 | + */ |
|
| 33 | + public function get(string $key, $default = null) |
|
| 34 | + { |
|
| 35 | + return $default; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * {@inheritDoc} |
|
| 40 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 41 | - */ |
|
| 42 | - public function has(string $key): bool |
|
| 43 | - { |
|
| 44 | - return false; |
|
| 45 | - } |
|
| 38 | + /** |
|
| 39 | + * {@inheritDoc} |
|
| 40 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::has() |
|
| 41 | + */ |
|
| 42 | + public function has(string $key): bool |
|
| 43 | + { |
|
| 44 | + return false; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * {@inheritDoc} |
|
| 49 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 50 | - * |
|
| 51 | - * @param mixed $config |
|
| 52 | - * @return $this |
|
| 53 | - */ |
|
| 54 | - public function jsonDeserialize($config): self |
|
| 55 | - { |
|
| 56 | - return $this; |
|
| 57 | - } |
|
| 47 | + /** |
|
| 48 | + * {@inheritDoc} |
|
| 49 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::jsonDeserialize() |
|
| 50 | + * |
|
| 51 | + * @param mixed $config |
|
| 52 | + * @return $this |
|
| 53 | + */ |
|
| 54 | + public function jsonDeserialize($config): self |
|
| 55 | + { |
|
| 56 | + return $this; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * {@inheritDoc} |
|
| 61 | - * @see JsonSerializable::jsonSerialize() |
|
| 62 | - */ |
|
| 63 | - #[\ReturnTypeWillChange] |
|
| 64 | - public function jsonSerialize() |
|
| 65 | - { |
|
| 66 | - return []; |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * {@inheritDoc} |
|
| 61 | + * @see JsonSerializable::jsonSerialize() |
|
| 62 | + */ |
|
| 63 | + #[\ReturnTypeWillChange] |
|
| 64 | + public function jsonSerialize() |
|
| 65 | + { |
|
| 66 | + return []; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * {@inheritDoc} |
|
| 71 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 72 | - */ |
|
| 73 | - public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 74 | - { |
|
| 75 | - return ''; |
|
| 76 | - } |
|
| 69 | + /** |
|
| 70 | + * {@inheritDoc} |
|
| 71 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::configContent() |
|
| 72 | + */ |
|
| 73 | + public function configContent(ModuleInterface $module, Tree $tree): string |
|
| 74 | + { |
|
| 75 | + return ''; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * {@inheritDoc} |
|
| 80 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 81 | - * @return $this |
|
| 82 | - */ |
|
| 83 | - public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 84 | - { |
|
| 85 | - return $this; |
|
| 86 | - } |
|
| 78 | + /** |
|
| 79 | + * {@inheritDoc} |
|
| 80 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperConfigInterface::withConfigUpdate() |
|
| 81 | + * @return $this |
|
| 82 | + */ |
|
| 83 | + public function withConfigUpdate(ServerRequestInterface $request): self |
|
| 84 | + { |
|
| 85 | + return $this; |
|
| 86 | + } |
|
| 87 | 87 | } |
@@ -23,93 +23,93 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class MapColorsConfig implements JsonSerializable |
| 25 | 25 | { |
| 26 | - private Color $default; |
|
| 27 | - private Color $stroke; |
|
| 28 | - private Color $max_value; |
|
| 29 | - private Color $hover; |
|
| 26 | + private Color $default; |
|
| 27 | + private Color $stroke; |
|
| 28 | + private Color $max_value; |
|
| 29 | + private Color $hover; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Constructor for MapColorsConfig |
|
| 33 | - * |
|
| 34 | - * @param Color $default |
|
| 35 | - * @param Color $stroke |
|
| 36 | - * @param Color $max_value |
|
| 37 | - * @param Color $hover |
|
| 38 | - */ |
|
| 39 | - public function __construct( |
|
| 40 | - Color $default, |
|
| 41 | - Color $stroke, |
|
| 42 | - Color $max_value, |
|
| 43 | - Color $hover |
|
| 44 | - ) { |
|
| 45 | - $this->default = $default; |
|
| 46 | - $this->stroke = $stroke; |
|
| 47 | - $this->max_value = $max_value; |
|
| 48 | - $this->hover = $hover; |
|
| 49 | - } |
|
| 31 | + /** |
|
| 32 | + * Constructor for MapColorsConfig |
|
| 33 | + * |
|
| 34 | + * @param Color $default |
|
| 35 | + * @param Color $stroke |
|
| 36 | + * @param Color $max_value |
|
| 37 | + * @param Color $hover |
|
| 38 | + */ |
|
| 39 | + public function __construct( |
|
| 40 | + Color $default, |
|
| 41 | + Color $stroke, |
|
| 42 | + Color $max_value, |
|
| 43 | + Color $hover |
|
| 44 | + ) { |
|
| 45 | + $this->default = $default; |
|
| 46 | + $this->stroke = $stroke; |
|
| 47 | + $this->max_value = $max_value; |
|
| 48 | + $this->hover = $hover; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Get the default color for the features |
|
| 53 | - * |
|
| 54 | - * @return Color |
|
| 55 | - */ |
|
| 56 | - public function defaultColor(): Color |
|
| 57 | - { |
|
| 58 | - return $this->default; |
|
| 59 | - } |
|
| 51 | + /** |
|
| 52 | + * Get the default color for the features |
|
| 53 | + * |
|
| 54 | + * @return Color |
|
| 55 | + */ |
|
| 56 | + public function defaultColor(): Color |
|
| 57 | + { |
|
| 58 | + return $this->default; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Get the color for the features' strokes |
|
| 63 | - * |
|
| 64 | - * @return Color |
|
| 65 | - */ |
|
| 66 | - public function strokeColor(): Color |
|
| 67 | - { |
|
| 68 | - return $this->stroke; |
|
| 69 | - } |
|
| 61 | + /** |
|
| 62 | + * Get the color for the features' strokes |
|
| 63 | + * |
|
| 64 | + * @return Color |
|
| 65 | + */ |
|
| 66 | + public function strokeColor(): Color |
|
| 67 | + { |
|
| 68 | + return $this->stroke; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Get the color for the features with the lowest count |
|
| 73 | - * |
|
| 74 | - * @return Color |
|
| 75 | - */ |
|
| 76 | - public function minValueColor(): Color |
|
| 77 | - { |
|
| 78 | - return new Rgb(255, 255, 255); |
|
| 79 | - } |
|
| 71 | + /** |
|
| 72 | + * Get the color for the features with the lowest count |
|
| 73 | + * |
|
| 74 | + * @return Color |
|
| 75 | + */ |
|
| 76 | + public function minValueColor(): Color |
|
| 77 | + { |
|
| 78 | + return new Rgb(255, 255, 255); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Get the color for the features with the highest count |
|
| 83 | - * |
|
| 84 | - * @return Color |
|
| 85 | - */ |
|
| 86 | - public function maxValueColor(): Color |
|
| 87 | - { |
|
| 88 | - return $this->max_value; |
|
| 89 | - } |
|
| 81 | + /** |
|
| 82 | + * Get the color for the features with the highest count |
|
| 83 | + * |
|
| 84 | + * @return Color |
|
| 85 | + */ |
|
| 86 | + public function maxValueColor(): Color |
|
| 87 | + { |
|
| 88 | + return $this->max_value; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Get the color for feature hovering |
|
| 93 | - * |
|
| 94 | - * @return Color |
|
| 95 | - */ |
|
| 96 | - public function hoverColor(): Color |
|
| 97 | - { |
|
| 98 | - return $this->hover; |
|
| 99 | - } |
|
| 91 | + /** |
|
| 92 | + * Get the color for feature hovering |
|
| 93 | + * |
|
| 94 | + * @return Color |
|
| 95 | + */ |
|
| 96 | + public function hoverColor(): Color |
|
| 97 | + { |
|
| 98 | + return $this->hover; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * {@inheritDoc} |
|
| 103 | - * @see JsonSerializable::jsonSerialize() |
|
| 104 | - */ |
|
| 105 | - #[\ReturnTypeWillChange] |
|
| 106 | - public function jsonSerialize() |
|
| 107 | - { |
|
| 108 | - return [ |
|
| 109 | - 'default' => (string) $this->defaultColor()->toHex(), |
|
| 110 | - 'stroke' => (string) $this->strokeColor()->toHex(), |
|
| 111 | - 'maxvalue' => (string) $this->maxValueColor()->toHex(), |
|
| 112 | - 'hover' => (string) $this->hoverColor()->toHex(), |
|
| 113 | - ]; |
|
| 114 | - } |
|
| 101 | + /** |
|
| 102 | + * {@inheritDoc} |
|
| 103 | + * @see JsonSerializable::jsonSerialize() |
|
| 104 | + */ |
|
| 105 | + #[\ReturnTypeWillChange] |
|
| 106 | + public function jsonSerialize() |
|
| 107 | + { |
|
| 108 | + return [ |
|
| 109 | + 'default' => (string) $this->defaultColor()->toHex(), |
|
| 110 | + 'stroke' => (string) $this->strokeColor()->toHex(), |
|
| 111 | + 'maxvalue' => (string) $this->maxValueColor()->toHex(), |
|
| 112 | + 'hover' => (string) $this->hoverColor()->toHex(), |
|
| 113 | + ]; |
|
| 114 | + } |
|
| 115 | 115 | } |
@@ -30,147 +30,147 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SourceStatusService |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * Maximum timespan between the date of a source and the date of the event to consider the source precise. |
|
| 35 | - * Arbitrally set to approximately a year around the event date. |
|
| 36 | - * |
|
| 37 | - * @var int DATE_PRECISION_MARGIN |
|
| 38 | - */ |
|
| 39 | - private const DATE_PRECISION_MARGIN = 180; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * Extract gedcom for all source citations of a fact. |
|
| 43 | - * Logic removed from \Fisharebest\Webtrees\Fact. |
|
| 44 | - * |
|
| 45 | - * @param Fact $fact |
|
| 46 | - * @return string[] |
|
| 47 | - */ |
|
| 48 | - private function extractCitations(Fact $fact) |
|
| 49 | - { |
|
| 50 | - $extract_regex = '/\n(2 SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[3-9] .*)*)/'; |
|
| 51 | - preg_match_all($extract_regex, $fact->gedcom(), $matches, PREG_SET_ORDER); |
|
| 52 | - $citations = []; |
|
| 53 | - foreach ($matches as $match) { |
|
| 54 | - $source = Registry::sourceFactory()->make($match[2], $fact->record()->tree()); |
|
| 55 | - if ($source !== null && $source->canShow()) { |
|
| 56 | - $citations[] = $match[1]; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - return $citations; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Return the status of source citations for a fact. |
|
| 64 | - * |
|
| 65 | - * @param Fact $fact |
|
| 66 | - * @return FactSourceStatus |
|
| 67 | - */ |
|
| 68 | - public function sourceStatusForFact(Fact $fact): FactSourceStatus |
|
| 69 | - { |
|
| 70 | - $source_status = new FactSourceStatus(); |
|
| 71 | - |
|
| 72 | - $date = $fact->date(); |
|
| 73 | - $source_status |
|
| 74 | - ->setFactHasDate($date->isOK()) |
|
| 75 | - ->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay()); |
|
| 76 | - |
|
| 77 | - foreach ($this->extractCitations($fact) as $citation) { |
|
| 78 | - $source_status |
|
| 79 | - ->setHasSource(true) |
|
| 80 | - ->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1); |
|
| 81 | - |
|
| 82 | - preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER); |
|
| 83 | - foreach ($date_matches as $date_match) { |
|
| 84 | - $source_date = new Date($date_match[1]); |
|
| 85 | - $source_status |
|
| 86 | - ->addSourceHasDate($source_date->isOK()) |
|
| 87 | - ->addSourceMatchesFactDate($date->isOK() && $source_date->isOK() |
|
| 88 | - && abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($source_status->isFullySourced()) { |
|
| 92 | - return $source_status; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return $source_status; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Return the status of sources for a Gedcom record. |
|
| 101 | - * |
|
| 102 | - * @param GedcomRecord $record |
|
| 103 | - * @return SourceStatus |
|
| 104 | - */ |
|
| 105 | - public function sourceStatusForRecord(GedcomRecord $record): SourceStatus |
|
| 106 | - { |
|
| 107 | - $source_status = new SourceStatus(); |
|
| 108 | - |
|
| 109 | - foreach ($record->facts(['SOUR']) as $source) { |
|
| 110 | - $source_status |
|
| 111 | - ->setHasSource(true) |
|
| 112 | - ->addHasSupportingDocument($source->attribute('_ACT') !== ''); |
|
| 113 | - |
|
| 114 | - if ($source_status->isFullySourced()) { |
|
| 115 | - return $source_status; |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - return $source_status; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Return the status of source citations for a list of fact types associated with a record. |
|
| 124 | - * |
|
| 125 | - * @param GedcomRecord $record |
|
| 126 | - * @param string[] $tags |
|
| 127 | - * @return FactSourceStatus |
|
| 128 | - */ |
|
| 129 | - public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus |
|
| 130 | - { |
|
| 131 | - $source_status = new NullFactSourceStatus(); |
|
| 132 | - |
|
| 133 | - foreach ($record->facts($tags) as $fact) { |
|
| 134 | - $source_status = $source_status->combineWith($this->sourceStatusForFact($fact)); |
|
| 135 | - if ($source_status->isFullySourced()) { |
|
| 136 | - return $source_status; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - return $source_status; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Return the status of source citations for an individual's birth events. |
|
| 145 | - * |
|
| 146 | - * @param Individual $individual |
|
| 147 | - * @return FactSourceStatus |
|
| 148 | - */ |
|
| 149 | - public function sourceStatusForBirth(Individual $individual): FactSourceStatus |
|
| 150 | - { |
|
| 151 | - return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Return the status of source citations for an individual's death events. |
|
| 156 | - * |
|
| 157 | - * @param Individual $individual |
|
| 158 | - * @return FactSourceStatus |
|
| 159 | - */ |
|
| 160 | - public function sourceStatusForDeath(Individual $individual): FactSourceStatus |
|
| 161 | - { |
|
| 162 | - return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * Return the status of source citations for a family's marriage events. |
|
| 167 | - * |
|
| 168 | - * @param Family $family |
|
| 169 | - * @return FactSourceStatus |
|
| 170 | - */ |
|
| 171 | - public function sourceStatusForMarriage(Family $family): FactSourceStatus |
|
| 172 | - { |
|
| 173 | - $marr_events = [...Gedcom::MARRIAGE_EVENTS, 'MARC', 'MARL', 'MARS']; |
|
| 174 | - return $this->sourceStatusForFactsWithTags($family, $marr_events); |
|
| 175 | - } |
|
| 33 | + /** |
|
| 34 | + * Maximum timespan between the date of a source and the date of the event to consider the source precise. |
|
| 35 | + * Arbitrally set to approximately a year around the event date. |
|
| 36 | + * |
|
| 37 | + * @var int DATE_PRECISION_MARGIN |
|
| 38 | + */ |
|
| 39 | + private const DATE_PRECISION_MARGIN = 180; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * Extract gedcom for all source citations of a fact. |
|
| 43 | + * Logic removed from \Fisharebest\Webtrees\Fact. |
|
| 44 | + * |
|
| 45 | + * @param Fact $fact |
|
| 46 | + * @return string[] |
|
| 47 | + */ |
|
| 48 | + private function extractCitations(Fact $fact) |
|
| 49 | + { |
|
| 50 | + $extract_regex = '/\n(2 SOUR @(' . Gedcom::REGEX_XREF . ')@(?:\n[3-9] .*)*)/'; |
|
| 51 | + preg_match_all($extract_regex, $fact->gedcom(), $matches, PREG_SET_ORDER); |
|
| 52 | + $citations = []; |
|
| 53 | + foreach ($matches as $match) { |
|
| 54 | + $source = Registry::sourceFactory()->make($match[2], $fact->record()->tree()); |
|
| 55 | + if ($source !== null && $source->canShow()) { |
|
| 56 | + $citations[] = $match[1]; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + return $citations; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Return the status of source citations for a fact. |
|
| 64 | + * |
|
| 65 | + * @param Fact $fact |
|
| 66 | + * @return FactSourceStatus |
|
| 67 | + */ |
|
| 68 | + public function sourceStatusForFact(Fact $fact): FactSourceStatus |
|
| 69 | + { |
|
| 70 | + $source_status = new FactSourceStatus(); |
|
| 71 | + |
|
| 72 | + $date = $fact->date(); |
|
| 73 | + $source_status |
|
| 74 | + ->setFactHasDate($date->isOK()) |
|
| 75 | + ->setFactHasPreciseDate($date->qual1 === '' && $date->minimumJulianDay() === $date->maximumJulianDay()); |
|
| 76 | + |
|
| 77 | + foreach ($this->extractCitations($fact) as $citation) { |
|
| 78 | + $source_status |
|
| 79 | + ->setHasSource(true) |
|
| 80 | + ->addHasSupportingDocument(preg_match('/\n3 _ACT (?:.*)/', $citation) === 1); |
|
| 81 | + |
|
| 82 | + preg_match_all("/\n3 DATA(?:\n[4-9] .*)*\n4 DATE (.*)/", $citation, $date_matches, PREG_SET_ORDER); |
|
| 83 | + foreach ($date_matches as $date_match) { |
|
| 84 | + $source_date = new Date($date_match[1]); |
|
| 85 | + $source_status |
|
| 86 | + ->addSourceHasDate($source_date->isOK()) |
|
| 87 | + ->addSourceMatchesFactDate($date->isOK() && $source_date->isOK() |
|
| 88 | + && abs($source_date->julianDay() - $date->julianDay()) < self::DATE_PRECISION_MARGIN); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($source_status->isFullySourced()) { |
|
| 92 | + return $source_status; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return $source_status; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Return the status of sources for a Gedcom record. |
|
| 101 | + * |
|
| 102 | + * @param GedcomRecord $record |
|
| 103 | + * @return SourceStatus |
|
| 104 | + */ |
|
| 105 | + public function sourceStatusForRecord(GedcomRecord $record): SourceStatus |
|
| 106 | + { |
|
| 107 | + $source_status = new SourceStatus(); |
|
| 108 | + |
|
| 109 | + foreach ($record->facts(['SOUR']) as $source) { |
|
| 110 | + $source_status |
|
| 111 | + ->setHasSource(true) |
|
| 112 | + ->addHasSupportingDocument($source->attribute('_ACT') !== ''); |
|
| 113 | + |
|
| 114 | + if ($source_status->isFullySourced()) { |
|
| 115 | + return $source_status; |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + return $source_status; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Return the status of source citations for a list of fact types associated with a record. |
|
| 124 | + * |
|
| 125 | + * @param GedcomRecord $record |
|
| 126 | + * @param string[] $tags |
|
| 127 | + * @return FactSourceStatus |
|
| 128 | + */ |
|
| 129 | + public function sourceStatusForFactsWithTags(GedcomRecord $record, array $tags): FactSourceStatus |
|
| 130 | + { |
|
| 131 | + $source_status = new NullFactSourceStatus(); |
|
| 132 | + |
|
| 133 | + foreach ($record->facts($tags) as $fact) { |
|
| 134 | + $source_status = $source_status->combineWith($this->sourceStatusForFact($fact)); |
|
| 135 | + if ($source_status->isFullySourced()) { |
|
| 136 | + return $source_status; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + return $source_status; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Return the status of source citations for an individual's birth events. |
|
| 145 | + * |
|
| 146 | + * @param Individual $individual |
|
| 147 | + * @return FactSourceStatus |
|
| 148 | + */ |
|
| 149 | + public function sourceStatusForBirth(Individual $individual): FactSourceStatus |
|
| 150 | + { |
|
| 151 | + return $this->sourceStatusForFactsWithTags($individual, Gedcom::BIRTH_EVENTS); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Return the status of source citations for an individual's death events. |
|
| 156 | + * |
|
| 157 | + * @param Individual $individual |
|
| 158 | + * @return FactSourceStatus |
|
| 159 | + */ |
|
| 160 | + public function sourceStatusForDeath(Individual $individual): FactSourceStatus |
|
| 161 | + { |
|
| 162 | + return $this->sourceStatusForFactsWithTags($individual, Gedcom::DEATH_EVENTS); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * Return the status of source citations for a family's marriage events. |
|
| 167 | + * |
|
| 168 | + * @param Family $family |
|
| 169 | + * @return FactSourceStatus |
|
| 170 | + */ |
|
| 171 | + public function sourceStatusForMarriage(Family $family): FactSourceStatus |
|
| 172 | + { |
|
| 173 | + $marr_events = [...Gedcom::MARRIAGE_EVENTS, 'MARC', 'MARL', 'MARS']; |
|
| 174 | + return $this->sourceStatusForFactsWithTags($family, $marr_events); |
|
| 175 | + } |
|
| 176 | 176 | } |
@@ -29,191 +29,191 @@ |
||
| 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 | - function (GeoAnalysisPlace $place) use ($result): void { |
|
| 174 | - $result->exclude($place); |
|
| 175 | - } |
|
| 176 | - ) |
|
| 177 | - ); |
|
| 178 | - |
|
| 179 | - return new MapAdapterResult($result, $features); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Populate the map features with the mapped Places and total count |
|
| 184 | - * |
|
| 185 | - * @param GeoAnalysisResult $result |
|
| 186 | - * @return mixed[] |
|
| 187 | - */ |
|
| 188 | - protected function featureAnalysisData(GeoAnalysisResult $result): array |
|
| 189 | - { |
|
| 190 | - $features_mapping = new Collection(); |
|
| 191 | - |
|
| 192 | - $byplaces = $result->knownPlaces(); |
|
| 193 | - $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
| 194 | - $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty()); |
|
| 195 | - |
|
| 196 | - if ($id !== null && mb_strlen($id) > 0) { |
|
| 197 | - $features_mapping->put( |
|
| 198 | - $id, |
|
| 199 | - $features_mapping->get($id, new MapFeatureAnalysisData())->add($item->place(), $item->count()) |
|
| 200 | - ); |
|
| 201 | - } else { |
|
| 202 | - $result->exclude($item->place()); |
|
| 203 | - } |
|
| 204 | - }); |
|
| 205 | - |
|
| 206 | - return [ $features_mapping, $result]; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * Get the value of the feature property used for the mapping |
|
| 211 | - * |
|
| 212 | - * @param Feature $feature |
|
| 213 | - * @return string|NULL |
|
| 214 | - */ |
|
| 215 | - protected function featureId(Feature $feature): ?string |
|
| 216 | - { |
|
| 217 | - return $feature->getProperty($this->config->mapMappingProperty()); |
|
| 218 | - } |
|
| 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 | + function (GeoAnalysisPlace $place) use ($result): void { |
|
| 174 | + $result->exclude($place); |
|
| 175 | + } |
|
| 176 | + ) |
|
| 177 | + ); |
|
| 178 | + |
|
| 179 | + return new MapAdapterResult($result, $features); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Populate the map features with the mapped Places and total count |
|
| 184 | + * |
|
| 185 | + * @param GeoAnalysisResult $result |
|
| 186 | + * @return mixed[] |
|
| 187 | + */ |
|
| 188 | + protected function featureAnalysisData(GeoAnalysisResult $result): array |
|
| 189 | + { |
|
| 190 | + $features_mapping = new Collection(); |
|
| 191 | + |
|
| 192 | + $byplaces = $result->knownPlaces(); |
|
| 193 | + $byplaces->each(function (GeoAnalysisResultItem $item) use ($features_mapping, $result): void { |
|
| 194 | + $id = $this->place_mapper->map($item->place()->place(), $this->config->mapMappingProperty()); |
|
| 195 | + |
|
| 196 | + if ($id !== null && mb_strlen($id) > 0) { |
|
| 197 | + $features_mapping->put( |
|
| 198 | + $id, |
|
| 199 | + $features_mapping->get($id, new MapFeatureAnalysisData())->add($item->place(), $item->count()) |
|
| 200 | + ); |
|
| 201 | + } else { |
|
| 202 | + $result->exclude($item->place()); |
|
| 203 | + } |
|
| 204 | + }); |
|
| 205 | + |
|
| 206 | + return [ $features_mapping, $result]; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * Get the value of the feature property used for the mapping |
|
| 211 | + * |
|
| 212 | + * @param Feature $feature |
|
| 213 | + * @return string|NULL |
|
| 214 | + */ |
|
| 215 | + protected function featureId(Feature $feature): ?string |
|
| 216 | + { |
|
| 217 | + return $feature->getProperty($this->config->mapMappingProperty()); |
|
| 218 | + } |
|
| 219 | 219 | } |
@@ -27,77 +27,77 @@ |
||
| 27 | 27 | */ |
| 28 | 28 | abstract class AbstractHookCollector implements HookCollectorInterface, HookInterface |
| 29 | 29 | { |
| 30 | - /** @var Collection<int, array<THook>> $hooks */ |
|
| 31 | - protected Collection $hooks; |
|
| 30 | + /** @var Collection<int, array<THook>> $hooks */ |
|
| 31 | + protected Collection $hooks; |
|
| 32 | 32 | |
| 33 | - private ModuleInterface $module; |
|
| 33 | + private ModuleInterface $module; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor for AbstractHookCollector |
|
| 37 | - * |
|
| 38 | - * @param ModuleInterface $module |
|
| 39 | - */ |
|
| 40 | - public function __construct(ModuleInterface $module) |
|
| 41 | - { |
|
| 42 | - $this->hooks = new Collection(); |
|
| 43 | - $this->module = $module; |
|
| 44 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor for AbstractHookCollector |
|
| 37 | + * |
|
| 38 | + * @param ModuleInterface $module |
|
| 39 | + */ |
|
| 40 | + public function __construct(ModuleInterface $module) |
|
| 41 | + { |
|
| 42 | + $this->hooks = new Collection(); |
|
| 43 | + $this->module = $module; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * {@inheritDoc} |
|
| 48 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 49 | - */ |
|
| 50 | - public function module(): ModuleInterface |
|
| 51 | - { |
|
| 52 | - return $this->module; |
|
| 53 | - } |
|
| 46 | + /** |
|
| 47 | + * {@inheritDoc} |
|
| 48 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 49 | + */ |
|
| 50 | + public function module(): ModuleInterface |
|
| 51 | + { |
|
| 52 | + return $this->module; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * {@inheritDoc} |
|
| 57 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::name() |
|
| 58 | - */ |
|
| 59 | - public function name(): string |
|
| 60 | - { |
|
| 61 | - return $this->module->name() . '-' . |
|
| 62 | - mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64); |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * {@inheritDoc} |
|
| 57 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::name() |
|
| 58 | + */ |
|
| 59 | + public function name(): string |
|
| 60 | + { |
|
| 61 | + return $this->module->name() . '-' . |
|
| 62 | + mb_substr(str_replace('collector', '', mb_strtolower((new ReflectionClass($this))->getShortName())), 0, 64); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * {@inheritDoc} |
|
| 67 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::title() |
|
| 68 | - */ |
|
| 69 | - abstract public function title(): string; |
|
| 65 | + /** |
|
| 66 | + * {@inheritDoc} |
|
| 67 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::title() |
|
| 68 | + */ |
|
| 69 | + abstract public function title(): string; |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * {@inheritDoc} |
|
| 73 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::description() |
|
| 74 | - */ |
|
| 75 | - abstract public function description(): string; |
|
| 71 | + /** |
|
| 72 | + * {@inheritDoc} |
|
| 73 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::description() |
|
| 74 | + */ |
|
| 75 | + abstract public function description(): string; |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * {@inheritDoc} |
|
| 79 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hookInterface() |
|
| 80 | - */ |
|
| 81 | - abstract public function hookInterface(): string; |
|
| 77 | + /** |
|
| 78 | + * {@inheritDoc} |
|
| 79 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hookInterface() |
|
| 80 | + */ |
|
| 81 | + abstract public function hookInterface(): string; |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * {@inheritDoc} |
|
| 85 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::register() |
|
| 86 | - */ |
|
| 87 | - public function register(HookInterface $hook_instance, int $order): void |
|
| 88 | - { |
|
| 89 | - $this->hooks->put($order, array_merge($this->hooks->get($order, []), [$hook_instance])); |
|
| 90 | - } |
|
| 83 | + /** |
|
| 84 | + * {@inheritDoc} |
|
| 85 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::register() |
|
| 86 | + */ |
|
| 87 | + public function register(HookInterface $hook_instance, int $order): void |
|
| 88 | + { |
|
| 89 | + $this->hooks->put($order, array_merge($this->hooks->get($order, []), [$hook_instance])); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * {@inheritDoc} |
|
| 94 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hooks() |
|
| 95 | - * |
|
| 96 | - * @return Collection<THook> |
|
| 97 | - */ |
|
| 98 | - public function hooks(): Collection |
|
| 99 | - { |
|
| 100 | - /** @var Collection<THook> */ |
|
| 101 | - return $this->hooks->sortKeys()->flatten(); |
|
| 102 | - } |
|
| 92 | + /** |
|
| 93 | + * {@inheritDoc} |
|
| 94 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookCollectorInterface::hooks() |
|
| 95 | + * |
|
| 96 | + * @return Collection<THook> |
|
| 97 | + */ |
|
| 98 | + public function hooks(): Collection |
|
| 99 | + { |
|
| 100 | + /** @var Collection<THook> */ |
|
| 101 | + return $this->hooks->sortKeys()->flatten(); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -1,14 +1,14 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
| 5 | - * |
|
| 6 | - * @package MyArtJaub\Webtrees |
|
| 7 | - * @subpackage Hooks |
|
| 8 | - * @author Jonathan Jaubart <[email protected]> |
|
| 9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
| 10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
| 11 | - */ |
|
| 4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
| 5 | + * |
|
| 6 | + * @package MyArtJaub\Webtrees |
|
| 7 | + * @subpackage Hooks |
|
| 8 | + * @author Jonathan Jaubart <[email protected]> |
|
| 9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
| 10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
| 11 | + */ |
|
| 12 | 12 | |
| 13 | 13 | declare(strict_types=1); |
| 14 | 14 | |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | interface SosaMissingDatatablesExtenderInterface extends HookInterface |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Get the columns to be added to missing ancestors datatables |
|
| 24 | - * |
|
| 25 | - * @param iterable<\Fisharebest\Webtrees\Individual> $records |
|
| 26 | - * @return array<string, array<string, array<string, mixed>>> |
|
| 27 | - */ |
|
| 28 | - public function sosaMissingColumns(iterable $records): array; |
|
| 22 | + /** |
|
| 23 | + * Get the columns to be added to missing ancestors datatables |
|
| 24 | + * |
|
| 25 | + * @param iterable<\Fisharebest\Webtrees\Individual> $records |
|
| 26 | + * @return array<string, array<string, array<string, mixed>>> |
|
| 27 | + */ |
|
| 28 | + public function sosaMissingColumns(iterable $records): array; |
|
| 29 | 29 | } |
@@ -1,14 +1,14 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | - * webtrees-lib: MyArtJaub library for webtrees |
|
| 5 | - * |
|
| 6 | - * @package MyArtJaub\Webtrees |
|
| 7 | - * @subpackage Hooks |
|
| 8 | - * @author Jonathan Jaubart <[email protected]> |
|
| 9 | - * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
| 10 | - * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
| 11 | - */ |
|
| 4 | + * webtrees-lib: MyArtJaub library for webtrees |
|
| 5 | + * |
|
| 6 | + * @package MyArtJaub\Webtrees |
|
| 7 | + * @subpackage Hooks |
|
| 8 | + * @author Jonathan Jaubart <[email protected]> |
|
| 9 | + * @copyright Copyright (c) 2011-2025, Jonathan Jaubart |
|
| 10 | + * @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
| 11 | + */ |
|
| 12 | 12 | |
| 13 | 13 | declare(strict_types=1); |
| 14 | 14 | |
@@ -19,12 +19,12 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | interface HookServiceInterface |
| 21 | 21 | { |
| 22 | - /** |
|
| 23 | - * Select the hook collector to use for a specific hook interface |
|
| 24 | - * |
|
| 25 | - * @template THook of HookInterface |
|
| 26 | - * @param class-string<THook> $hook_interface |
|
| 27 | - * @return HookCollectorInterface|NULL |
|
| 28 | - */ |
|
| 29 | - public function use(string $hook_interface): ?HookCollectorInterface; |
|
| 22 | + /** |
|
| 23 | + * Select the hook collector to use for a specific hook interface |
|
| 24 | + * |
|
| 25 | + * @template THook of HookInterface |
|
| 26 | + * @param class-string<THook> $hook_interface |
|
| 27 | + * @return HookCollectorInterface|NULL |
|
| 28 | + */ |
|
| 29 | + public function use(string $hook_interface): ?HookCollectorInterface; |
|
| 30 | 30 | } |