@@ -32,64 +32,64 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | class GeoAnalysisViewEditPage implements RequestHandlerInterface |
| 34 | 34 | { |
| 35 | - use ViewResponseTrait; |
|
| 35 | + use ViewResponseTrait; |
|
| 36 | 36 | |
| 37 | - private ?GeoDispersionModule $module; |
|
| 38 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
| 39 | - private GeoAnalysisService $geoanalysis_service; |
|
| 40 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
| 37 | + private ?GeoDispersionModule $module; |
|
| 38 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
| 39 | + private GeoAnalysisService $geoanalysis_service; |
|
| 40 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Constructor for GeoAnalysisViewEditPage Request Handler |
|
| 44 | - * |
|
| 45 | - * @param ModuleService $module_service |
|
| 46 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 47 | - * @param GeoAnalysisService $geoanalysis_service |
|
| 48 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
| 49 | - */ |
|
| 50 | - public function __construct( |
|
| 51 | - ModuleService $module_service, |
|
| 52 | - GeoAnalysisViewDataService $geoview_data_service, |
|
| 53 | - GeoAnalysisService $geoanalysis_service, |
|
| 54 | - GeoAnalysisDataService $geoanalysis_data_service |
|
| 55 | - ) { |
|
| 56 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 57 | - $this->geoview_data_service = $geoview_data_service; |
|
| 58 | - $this->geoanalysis_service = $geoanalysis_service; |
|
| 59 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
| 60 | - } |
|
| 42 | + /** |
|
| 43 | + * Constructor for GeoAnalysisViewEditPage Request Handler |
|
| 44 | + * |
|
| 45 | + * @param ModuleService $module_service |
|
| 46 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 47 | + * @param GeoAnalysisService $geoanalysis_service |
|
| 48 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
| 49 | + */ |
|
| 50 | + public function __construct( |
|
| 51 | + ModuleService $module_service, |
|
| 52 | + GeoAnalysisViewDataService $geoview_data_service, |
|
| 53 | + GeoAnalysisService $geoanalysis_service, |
|
| 54 | + GeoAnalysisDataService $geoanalysis_data_service |
|
| 55 | + ) { |
|
| 56 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 57 | + $this->geoview_data_service = $geoview_data_service; |
|
| 58 | + $this->geoanalysis_service = $geoanalysis_service; |
|
| 59 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * {@inheritDoc} |
|
| 64 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 65 | - */ |
|
| 66 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 67 | - { |
|
| 68 | - $this->layout = 'layouts/administration'; |
|
| 62 | + /** |
|
| 63 | + * {@inheritDoc} |
|
| 64 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 65 | + */ |
|
| 66 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 67 | + { |
|
| 68 | + $this->layout = 'layouts/administration'; |
|
| 69 | 69 | |
| 70 | - if ($this->module === null) { |
|
| 71 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 72 | - } |
|
| 70 | + if ($this->module === null) { |
|
| 71 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $tree = Validator::attributes($request)->tree(); |
|
| 74 | + $tree = Validator::attributes($request)->tree(); |
|
| 75 | 75 | |
| 76 | - $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
| 77 | - $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
| 76 | + $view_id = Validator::attributes($request)->integer('view_id', -1); |
|
| 77 | + $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
| 78 | 78 | |
| 79 | - if ($view === null) { |
|
| 80 | - throw new HttpNotFoundException( |
|
| 81 | - I18N::translate('The geographical dispersion analysis view could not be found.') |
|
| 82 | - ); |
|
| 83 | - } |
|
| 79 | + if ($view === null) { |
|
| 80 | + throw new HttpNotFoundException( |
|
| 81 | + I18N::translate('The geographical dispersion analysis view could not be found.') |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 86 | - 'module' => $this->module, |
|
| 87 | - 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
|
| 88 | - 'tree' => $tree, |
|
| 89 | - 'view' => $view, |
|
| 90 | - 'geoanalysis_list' => $this->geoanalysis_service->all(), |
|
| 91 | - 'place_example' => $this->geoanalysis_data_service->placeHierarchyExample($tree), |
|
| 92 | - 'global_settings' => $view->globalSettingsContent($this->module) |
|
| 93 | - ]); |
|
| 94 | - } |
|
| 85 | + return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 86 | + 'module' => $this->module, |
|
| 87 | + 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
|
| 88 | + 'tree' => $tree, |
|
| 89 | + 'view' => $view, |
|
| 90 | + 'geoanalysis_list' => $this->geoanalysis_service->all(), |
|
| 91 | + 'place_example' => $this->geoanalysis_data_service->placeHierarchyExample($tree), |
|
| 92 | + 'global_settings' => $view->globalSettingsContent($this->module) |
|
| 93 | + ]); |
|
| 94 | + } |
|
| 95 | 95 | } |
@@ -82,7 +82,7 @@ |
||
| 82 | 82 | ); |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 85 | + return $this->viewResponse($this->module->name().'::admin/view-edit', [ |
|
| 86 | 86 | 'module' => $this->module, |
| 87 | 87 | 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
| 88 | 88 | 'tree' => $tree, |
@@ -21,51 +21,51 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | trait TopFilteredPlaceMapperTrait |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * @var Place[] $top_places |
|
| 26 | - */ |
|
| 27 | - private array $top_places = []; |
|
| 24 | + /** |
|
| 25 | + * @var Place[] $top_places |
|
| 26 | + */ |
|
| 27 | + private array $top_places = []; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Get the list of top level places. |
|
| 31 | - * |
|
| 32 | - * @return Place[] |
|
| 33 | - */ |
|
| 34 | - public function topPlaces(): array |
|
| 35 | - { |
|
| 36 | - return $this->top_places; |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Get the list of top level places. |
|
| 31 | + * |
|
| 32 | + * @return Place[] |
|
| 33 | + */ |
|
| 34 | + public function topPlaces(): array |
|
| 35 | + { |
|
| 36 | + return $this->top_places; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Set the list of defined top level places. |
|
| 41 | - * |
|
| 42 | - * @param Place[] $top_places |
|
| 43 | - */ |
|
| 44 | - public function setTopPlaces(array $top_places): void |
|
| 45 | - { |
|
| 46 | - $this->top_places = collect($top_places) |
|
| 47 | - ->filter( |
|
| 48 | - /** @psalm-suppress MissingClosureParamType */ |
|
| 49 | - fn($top_places): bool => $top_places instanceof Place |
|
| 50 | - )->toArray(); |
|
| 51 | - } |
|
| 39 | + /** |
|
| 40 | + * Set the list of defined top level places. |
|
| 41 | + * |
|
| 42 | + * @param Place[] $top_places |
|
| 43 | + */ |
|
| 44 | + public function setTopPlaces(array $top_places): void |
|
| 45 | + { |
|
| 46 | + $this->top_places = collect($top_places) |
|
| 47 | + ->filter( |
|
| 48 | + /** @psalm-suppress MissingClosureParamType */ |
|
| 49 | + fn($top_places): bool => $top_places instanceof Place |
|
| 50 | + )->toArray(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Check whether a Place belongs to one of the defined top places. |
|
| 55 | - * |
|
| 56 | - * @param Place $place |
|
| 57 | - * @return bool |
|
| 58 | - */ |
|
| 59 | - protected function belongsToTopLevels(Place $place): bool |
|
| 60 | - { |
|
| 61 | - foreach ($this->top_places as $top_place) { |
|
| 62 | - if ( |
|
| 63 | - $top_place->tree()->id() === $place->tree()->id() && |
|
| 64 | - str_ends_with($place->gedcomName(), $top_place->gedcomName()) |
|
| 65 | - ) { |
|
| 66 | - return true; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 53 | + /** |
|
| 54 | + * Check whether a Place belongs to one of the defined top places. |
|
| 55 | + * |
|
| 56 | + * @param Place $place |
|
| 57 | + * @return bool |
|
| 58 | + */ |
|
| 59 | + protected function belongsToTopLevels(Place $place): bool |
|
| 60 | + { |
|
| 61 | + foreach ($this->top_places as $top_place) { |
|
| 62 | + if ( |
|
| 63 | + $top_place->tree()->id() === $place->tree()->id() && |
|
| 64 | + str_ends_with($place->gedcomName(), $top_place->gedcomName()) |
|
| 65 | + ) { |
|
| 66 | + return true; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | 71 | } |
@@ -25,51 +25,51 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class MapDefinitionsService |
| 27 | 27 | { |
| 28 | - private ModuleService $module_service; |
|
| 28 | + private ModuleService $module_service; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor for MapDefinitionsService |
|
| 32 | - * |
|
| 33 | - * @param ModuleService $module_service |
|
| 34 | - */ |
|
| 35 | - public function __construct(ModuleService $module_service) |
|
| 36 | - { |
|
| 37 | - $this->module_service = $module_service; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor for MapDefinitionsService |
|
| 32 | + * |
|
| 33 | + * @param ModuleService $module_service |
|
| 34 | + */ |
|
| 35 | + public function __construct(ModuleService $module_service) |
|
| 36 | + { |
|
| 37 | + $this->module_service = $module_service; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Find a map definition by ID. |
|
| 42 | - * |
|
| 43 | - * @param string $id |
|
| 44 | - * @return MapDefinitionInterface|NULL |
|
| 45 | - */ |
|
| 46 | - public function find(string $id): ?MapDefinitionInterface |
|
| 47 | - { |
|
| 48 | - return $this->all()->get($id); |
|
| 49 | - } |
|
| 40 | + /** |
|
| 41 | + * Find a map definition by ID. |
|
| 42 | + * |
|
| 43 | + * @param string $id |
|
| 44 | + * @return MapDefinitionInterface|NULL |
|
| 45 | + */ |
|
| 46 | + public function find(string $id): ?MapDefinitionInterface |
|
| 47 | + { |
|
| 48 | + return $this->all()->get($id); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Get all map definitions available. |
|
| 53 | - * |
|
| 54 | - * {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface, |
|
| 55 | - * and the result is cached} |
|
| 56 | - * |
|
| 57 | - * @param bool $include_disabled |
|
| 58 | - * @return Collection<string, MapDefinitionInterface> |
|
| 59 | - */ |
|
| 60 | - public function all(bool $include_disabled = false): Collection |
|
| 61 | - { |
|
| 62 | - return Registry::cache()->array()->remember( |
|
| 63 | - 'maj-geodisp-maps-all', |
|
| 64 | - function () use ($include_disabled): Collection { |
|
| 65 | - /** @var Collection<string, MapDefinitionInterface> $map_definitions */ |
|
| 66 | - $map_definitions = $this->module_service |
|
| 67 | - ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
| 68 | - ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
| 69 | - ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]); |
|
| 51 | + /** |
|
| 52 | + * Get all map definitions available. |
|
| 53 | + * |
|
| 54 | + * {@internal The list is generated based on the modules exposing ModuleMapDefinitionProviderInterface, |
|
| 55 | + * and the result is cached} |
|
| 56 | + * |
|
| 57 | + * @param bool $include_disabled |
|
| 58 | + * @return Collection<string, MapDefinitionInterface> |
|
| 59 | + */ |
|
| 60 | + public function all(bool $include_disabled = false): Collection |
|
| 61 | + { |
|
| 62 | + return Registry::cache()->array()->remember( |
|
| 63 | + 'maj-geodisp-maps-all', |
|
| 64 | + function () use ($include_disabled): Collection { |
|
| 65 | + /** @var Collection<string, MapDefinitionInterface> $map_definitions */ |
|
| 66 | + $map_definitions = $this->module_service |
|
| 67 | + ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
| 68 | + ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
| 69 | + ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]); |
|
| 70 | 70 | |
| 71 | - return $map_definitions; |
|
| 72 | - } |
|
| 73 | - ); |
|
| 74 | - } |
|
| 71 | + return $map_definitions; |
|
| 72 | + } |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -61,12 +61,12 @@ |
||
| 61 | 61 | { |
| 62 | 62 | return Registry::cache()->array()->remember( |
| 63 | 63 | 'maj-geodisp-maps-all', |
| 64 | - function () use ($include_disabled): Collection { |
|
| 64 | + function() use ($include_disabled): Collection { |
|
| 65 | 65 | /** @var Collection<string, MapDefinitionInterface> $map_definitions */ |
| 66 | 66 | $map_definitions = $this->module_service |
| 67 | 67 | ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
| 68 | 68 | ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
| 69 | - ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]); |
|
| 69 | + ->mapWithKeys(fn(MapDefinitionInterface $map) => [$map->id() => $map]); |
|
| 70 | 70 | |
| 71 | 71 | return $map_definitions; |
| 72 | 72 | } |
@@ -22,77 +22,77 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class MapFeatureAnalysisData |
| 24 | 24 | { |
| 25 | - private int $count; |
|
| 26 | - private bool $in_map; |
|
| 27 | - /** |
|
| 28 | - * @var Collection<GeoAnalysisPlace> $places |
|
| 29 | - */ |
|
| 30 | - private Collection $places; |
|
| 25 | + private int $count; |
|
| 26 | + private bool $in_map; |
|
| 27 | + /** |
|
| 28 | + * @var Collection<GeoAnalysisPlace> $places |
|
| 29 | + */ |
|
| 30 | + private Collection $places; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Constructor for MapFeatureAnalysisData |
|
| 34 | - */ |
|
| 35 | - public function __construct() |
|
| 36 | - { |
|
| 37 | - $this->count = 0; |
|
| 38 | - $this->places = new Collection(); |
|
| 39 | - $this->in_map = false; |
|
| 40 | - } |
|
| 32 | + /** |
|
| 33 | + * Constructor for MapFeatureAnalysisData |
|
| 34 | + */ |
|
| 35 | + public function __construct() |
|
| 36 | + { |
|
| 37 | + $this->count = 0; |
|
| 38 | + $this->places = new Collection(); |
|
| 39 | + $this->in_map = false; |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Get the list of places mapped to the feature |
|
| 44 | - * |
|
| 45 | - * @return Collection<GeoAnalysisPlace> |
|
| 46 | - */ |
|
| 47 | - public function places(): Collection |
|
| 48 | - { |
|
| 49 | - return $this->places; |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * Get the list of places mapped to the feature |
|
| 44 | + * |
|
| 45 | + * @return Collection<GeoAnalysisPlace> |
|
| 46 | + */ |
|
| 47 | + public function places(): Collection |
|
| 48 | + { |
|
| 49 | + return $this->places; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Get the count of analysis items occurring in the feature |
|
| 54 | - * |
|
| 55 | - * @return int |
|
| 56 | - */ |
|
| 57 | - public function count(): int |
|
| 58 | - { |
|
| 59 | - return $this->count; |
|
| 60 | - } |
|
| 52 | + /** |
|
| 53 | + * Get the count of analysis items occurring in the feature |
|
| 54 | + * |
|
| 55 | + * @return int |
|
| 56 | + */ |
|
| 57 | + public function count(): int |
|
| 58 | + { |
|
| 59 | + return $this->count; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * Check whether the feature exist in the target map |
|
| 64 | - * |
|
| 65 | - * @return bool |
|
| 66 | - */ |
|
| 67 | - public function existsInMap(): bool |
|
| 68 | - { |
|
| 69 | - return $this->in_map; |
|
| 70 | - } |
|
| 62 | + /** |
|
| 63 | + * Check whether the feature exist in the target map |
|
| 64 | + * |
|
| 65 | + * @return bool |
|
| 66 | + */ |
|
| 67 | + public function existsInMap(): bool |
|
| 68 | + { |
|
| 69 | + return $this->in_map; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * Confirm that the feature exist in the target map |
|
| 74 | - * |
|
| 75 | - * @return $this |
|
| 76 | - */ |
|
| 77 | - public function tagAsExisting(): self |
|
| 78 | - { |
|
| 79 | - $this->in_map = true; |
|
| 80 | - return $this; |
|
| 81 | - } |
|
| 72 | + /** |
|
| 73 | + * Confirm that the feature exist in the target map |
|
| 74 | + * |
|
| 75 | + * @return $this |
|
| 76 | + */ |
|
| 77 | + public function tagAsExisting(): self |
|
| 78 | + { |
|
| 79 | + $this->in_map = true; |
|
| 80 | + return $this; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - /** |
|
| 84 | - * Add a GeoAnalysisPlace to the feature |
|
| 85 | - * |
|
| 86 | - * @param GeoAnalysisPlace $place |
|
| 87 | - * @param int $count |
|
| 88 | - * @return $this |
|
| 89 | - */ |
|
| 90 | - public function add(GeoAnalysisPlace $place, int $count): self |
|
| 91 | - { |
|
| 92 | - if (!$place->isExcluded()) { |
|
| 93 | - $this->places->add($place); |
|
| 94 | - $this->count += $count; |
|
| 95 | - } |
|
| 96 | - return $this; |
|
| 97 | - } |
|
| 83 | + /** |
|
| 84 | + * Add a GeoAnalysisPlace to the feature |
|
| 85 | + * |
|
| 86 | + * @param GeoAnalysisPlace $place |
|
| 87 | + * @param int $count |
|
| 88 | + * @return $this |
|
| 89 | + */ |
|
| 90 | + public function add(GeoAnalysisPlace $place, int $count): self |
|
| 91 | + { |
|
| 92 | + if (!$place->isExcluded()) { |
|
| 93 | + $this->places->add($place); |
|
| 94 | + $this->count += $count; |
|
| 95 | + } |
|
| 96 | + return $this; |
|
| 97 | + } |
|
| 98 | 98 | } |
@@ -24,57 +24,57 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class MapAdapterResult |
| 26 | 26 | { |
| 27 | - private GeoAnalysisResult $result; |
|
| 27 | + private GeoAnalysisResult $result; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var array<int, \Brick\Geo\IO\GeoJSON\Feature> $features |
|
| 31 | - */ |
|
| 32 | - private array $features; |
|
| 29 | + /** |
|
| 30 | + * @var array<int, \Brick\Geo\IO\GeoJSON\Feature> $features |
|
| 31 | + */ |
|
| 32 | + private array $features; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Constructor for MapAdapterResult |
|
| 36 | - * |
|
| 37 | - * @param GeoAnalysisResult $result |
|
| 38 | - * @param \Brick\Geo\IO\GeoJSON\Feature[] $features |
|
| 39 | - */ |
|
| 40 | - final public function __construct(GeoAnalysisResult $result, array $features) |
|
| 41 | - { |
|
| 42 | - $this->result = $result; |
|
| 43 | - $this->features = $features; |
|
| 44 | - } |
|
| 34 | + /** |
|
| 35 | + * Constructor for MapAdapterResult |
|
| 36 | + * |
|
| 37 | + * @param GeoAnalysisResult $result |
|
| 38 | + * @param \Brick\Geo\IO\GeoJSON\Feature[] $features |
|
| 39 | + */ |
|
| 40 | + final public function __construct(GeoAnalysisResult $result, array $features) |
|
| 41 | + { |
|
| 42 | + $this->result = $result; |
|
| 43 | + $this->features = $features; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Get the GeoAnalysisResult after mapping of the places |
|
| 48 | - * |
|
| 49 | - * @return GeoAnalysisResult |
|
| 50 | - */ |
|
| 51 | - public function geoAnalysisResult(): GeoAnalysisResult |
|
| 52 | - { |
|
| 53 | - return $this->result; |
|
| 54 | - } |
|
| 46 | + /** |
|
| 47 | + * Get the GeoAnalysisResult after mapping of the places |
|
| 48 | + * |
|
| 49 | + * @return GeoAnalysisResult |
|
| 50 | + */ |
|
| 51 | + public function geoAnalysisResult(): GeoAnalysisResult |
|
| 52 | + { |
|
| 53 | + return $this->result; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Get the list of features to display on the map |
|
| 58 | - * |
|
| 59 | - * @return array<int, \Brick\Geo\IO\GeoJSON\Feature> |
|
| 60 | - */ |
|
| 61 | - public function features(): array |
|
| 62 | - { |
|
| 63 | - return $this->features; |
|
| 64 | - } |
|
| 56 | + /** |
|
| 57 | + * Get the list of features to display on the map |
|
| 58 | + * |
|
| 59 | + * @return array<int, \Brick\Geo\IO\GeoJSON\Feature> |
|
| 60 | + */ |
|
| 61 | + public function features(): array |
|
| 62 | + { |
|
| 63 | + return $this->features; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Merge the current MapAdapter with another. |
|
| 68 | - * The current object is modified, not the second one. |
|
| 69 | - * |
|
| 70 | - * @param MapAdapterResult $other |
|
| 71 | - * @return static |
|
| 72 | - */ |
|
| 73 | - public function merge(MapAdapterResult $other): self |
|
| 74 | - { |
|
| 75 | - return new static( |
|
| 76 | - $this->result->merge($other->result), |
|
| 77 | - [...$this->features, ...$other->features] |
|
| 78 | - ); |
|
| 79 | - } |
|
| 66 | + /** |
|
| 67 | + * Merge the current MapAdapter with another. |
|
| 68 | + * The current object is modified, not the second one. |
|
| 69 | + * |
|
| 70 | + * @param MapAdapterResult $other |
|
| 71 | + * @return static |
|
| 72 | + */ |
|
| 73 | + public function merge(MapAdapterResult $other): self |
|
| 74 | + { |
|
| 75 | + return new static( |
|
| 76 | + $this->result->merge($other->result), |
|
| 77 | + [...$this->features, ...$other->features] |
|
| 78 | + ); |
|
| 79 | + } |
|
| 80 | 80 | } |
@@ -25,68 +25,68 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class TitlesCardHook implements NameAccordionExtenderInterface |
| 27 | 27 | { |
| 28 | - private ModuleInterface $module; |
|
| 28 | + private ModuleInterface $module; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Constructor for TitlesCardHook |
|
| 32 | - * |
|
| 33 | - * @param ModuleInterface $module |
|
| 34 | - */ |
|
| 35 | - public function __construct(ModuleInterface $module) |
|
| 36 | - { |
|
| 37 | - $this->module = $module; |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Constructor for TitlesCardHook |
|
| 32 | + * |
|
| 33 | + * @param ModuleInterface $module |
|
| 34 | + */ |
|
| 35 | + public function __construct(ModuleInterface $module) |
|
| 36 | + { |
|
| 37 | + $this->module = $module; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * {@inheritDoc} |
|
| 42 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 43 | - */ |
|
| 44 | - public function module(): ModuleInterface |
|
| 45 | - { |
|
| 46 | - return $this->module; |
|
| 47 | - } |
|
| 40 | + /** |
|
| 41 | + * {@inheritDoc} |
|
| 42 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 43 | + */ |
|
| 44 | + public function module(): ModuleInterface |
|
| 45 | + { |
|
| 46 | + return $this->module; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * {@inheritDoc} |
|
| 51 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\NameAccordionExtenderInterface::accordionCard() |
|
| 52 | - */ |
|
| 53 | - public function accordionCard(Individual $individual): string |
|
| 54 | - { |
|
| 55 | - $title_separator = $this->module->getPreference('MAJ_TITLE_PREFIX'); |
|
| 56 | - if ($title_separator === '') { |
|
| 57 | - return ''; |
|
| 58 | - } |
|
| 49 | + /** |
|
| 50 | + * {@inheritDoc} |
|
| 51 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\NameAccordionExtenderInterface::accordionCard() |
|
| 52 | + */ |
|
| 53 | + public function accordionCard(Individual $individual): string |
|
| 54 | + { |
|
| 55 | + $title_separator = $this->module->getPreference('MAJ_TITLE_PREFIX'); |
|
| 56 | + if ($title_separator === '') { |
|
| 57 | + return ''; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - $titles = $this->individualTitles($individual, '/(.*?) ((' . $title_separator . ')(.*))/i'); |
|
| 60 | + $titles = $this->individualTitles($individual, '/(.*?) ((' . $title_separator . ')(.*))/i'); |
|
| 61 | 61 | |
| 62 | - return count($titles) === 0 ? '' : |
|
| 63 | - view($this->module()->name() . '::components/accordion-item-titles', [ 'titles' => $titles ]); |
|
| 64 | - } |
|
| 62 | + return count($titles) === 0 ? '' : |
|
| 63 | + view($this->module()->name() . '::components/accordion-item-titles', [ 'titles' => $titles ]); |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Extract the individual titles from the TITL tags. |
|
| 68 | - * Split the title based on a pattern to identify the title and the land it refers to. |
|
| 69 | - * |
|
| 70 | - * @param Individual $individual |
|
| 71 | - * @param string $pattern |
|
| 72 | - * @return array<string, string[]> |
|
| 73 | - */ |
|
| 74 | - protected function individualTitles(Individual $individual, string $pattern): array |
|
| 75 | - { |
|
| 76 | - $titles_list = []; |
|
| 77 | - /** @var \Illuminate\Support\Collection<string> $titles */ |
|
| 78 | - $titles = $individual->facts(['TITL']) |
|
| 79 | - ->sortByDesc(fn(Fact $fact) => $fact->date()->julianDay()) |
|
| 80 | - ->map(fn(Fact $fact) => $fact->value()); |
|
| 66 | + /** |
|
| 67 | + * Extract the individual titles from the TITL tags. |
|
| 68 | + * Split the title based on a pattern to identify the title and the land it refers to. |
|
| 69 | + * |
|
| 70 | + * @param Individual $individual |
|
| 71 | + * @param string $pattern |
|
| 72 | + * @return array<string, string[]> |
|
| 73 | + */ |
|
| 74 | + protected function individualTitles(Individual $individual, string $pattern): array |
|
| 75 | + { |
|
| 76 | + $titles_list = []; |
|
| 77 | + /** @var \Illuminate\Support\Collection<string> $titles */ |
|
| 78 | + $titles = $individual->facts(['TITL']) |
|
| 79 | + ->sortByDesc(fn(Fact $fact) => $fact->date()->julianDay()) |
|
| 80 | + ->map(fn(Fact $fact) => $fact->value()); |
|
| 81 | 81 | |
| 82 | - foreach ($titles as $title) { |
|
| 83 | - if (preg_match($pattern, $title, $match) === 1) { |
|
| 84 | - /** @var array<int, string> $match */ |
|
| 85 | - $titles_list[$match[1]][] = trim($match[2]); |
|
| 86 | - } else { |
|
| 87 | - $titles_list[$title][] = ''; |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - return $titles_list; |
|
| 91 | - } |
|
| 82 | + foreach ($titles as $title) { |
|
| 83 | + if (preg_match($pattern, $title, $match) === 1) { |
|
| 84 | + /** @var array<int, string> $match */ |
|
| 85 | + $titles_list[$match[1]][] = trim($match[2]); |
|
| 86 | + } else { |
|
| 87 | + $titles_list[$title][] = ''; |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + return $titles_list; |
|
| 91 | + } |
|
| 92 | 92 | } |
@@ -57,10 +57,9 @@ |
||
| 57 | 57 | return ''; |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | - $titles = $this->individualTitles($individual, '/(.*?) ((' . $title_separator . ')(.*))/i'); |
|
| 60 | + $titles = $this->individualTitles($individual, '/(.*?) (('.$title_separator.')(.*))/i'); |
|
| 61 | 61 | |
| 62 | - return count($titles) === 0 ? '' : |
|
| 63 | - view($this->module()->name() . '::components/accordion-item-titles', [ 'titles' => $titles ]); |
|
| 62 | + return count($titles) === 0 ? '' : view($this->module()->name().'::components/accordion-item-titles', ['titles' => $titles]); |
|
| 64 | 63 | } |
| 65 | 64 | |
| 66 | 65 | /** |
@@ -61,12 +61,12 @@ |
||
| 61 | 61 | public function factSourcePrepend(Tree $tree, $fact): string |
| 62 | 62 | { |
| 63 | 63 | $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
| 64 | - if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
| 64 | + if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int)$permission_level) { |
|
| 65 | 65 | $path = $this->extractPath($fact); |
| 66 | 66 | |
| 67 | 67 | if ($path !== '') { |
| 68 | 68 | $certificate = new Certificate($tree, $path); |
| 69 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
| 69 | + return view($this->module->name().'::components/certificate-icon', [ |
|
| 70 | 70 | 'module_name' => $this->module->name(), |
| 71 | 71 | 'certificate' => $certificate, |
| 72 | 72 | 'url_obfuscator_service' => $this->url_obfuscator_service, |
@@ -30,87 +30,87 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SourceCertificateIconHook implements FactSourceTextExtenderInterface |
| 32 | 32 | { |
| 33 | - private CertificatesModule $module; |
|
| 34 | - private UrlObfuscatorService $url_obfuscator_service; |
|
| 33 | + private CertificatesModule $module; |
|
| 34 | + private UrlObfuscatorService $url_obfuscator_service; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for SourceCertificateIconHook |
|
| 38 | - * |
|
| 39 | - * @param CertificatesModule $module |
|
| 40 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
| 41 | - */ |
|
| 42 | - public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
| 43 | - { |
|
| 44 | - $this->module = $module; |
|
| 45 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 46 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for SourceCertificateIconHook |
|
| 38 | + * |
|
| 39 | + * @param CertificatesModule $module |
|
| 40 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
| 41 | + */ |
|
| 42 | + public function __construct(CertificatesModule $module, UrlObfuscatorService $url_obfuscator_service) |
|
| 43 | + { |
|
| 44 | + $this->module = $module; |
|
| 45 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * {@inheritDoc} |
|
| 50 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 51 | - */ |
|
| 52 | - public function module(): ModuleInterface |
|
| 53 | - { |
|
| 54 | - return $this->module; |
|
| 55 | - } |
|
| 48 | + /** |
|
| 49 | + * {@inheritDoc} |
|
| 50 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 51 | + */ |
|
| 52 | + public function module(): ModuleInterface |
|
| 53 | + { |
|
| 54 | + return $this->module; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * {@inheritDoc} |
|
| 59 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
| 60 | - */ |
|
| 61 | - public function factSourcePrepend(Tree $tree, $fact): string |
|
| 62 | - { |
|
| 63 | - $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
| 64 | - if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
| 65 | - $path = $this->extractPath($fact); |
|
| 57 | + /** |
|
| 58 | + * {@inheritDoc} |
|
| 59 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourcePrepend() |
|
| 60 | + */ |
|
| 61 | + public function factSourcePrepend(Tree $tree, $fact): string |
|
| 62 | + { |
|
| 63 | + $permission_level = $tree->getPreference('MAJ_CERTIF_SHOW_CERT'); |
|
| 64 | + if (is_numeric($permission_level) && Auth::accessLevel($tree) <= (int) $permission_level) { |
|
| 65 | + $path = $this->extractPath($fact); |
|
| 66 | 66 | |
| 67 | - if ($path !== '') { |
|
| 68 | - $certificate = new Certificate($tree, $path); |
|
| 69 | - return view($this->module->name() . '::components/certificate-icon', [ |
|
| 70 | - 'module_name' => $this->module->name(), |
|
| 71 | - 'certificate' => $certificate, |
|
| 72 | - 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
| 73 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
| 74 | - ]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - return ''; |
|
| 78 | - } |
|
| 67 | + if ($path !== '') { |
|
| 68 | + $certificate = new Certificate($tree, $path); |
|
| 69 | + return view($this->module->name() . '::components/certificate-icon', [ |
|
| 70 | + 'module_name' => $this->module->name(), |
|
| 71 | + 'certificate' => $certificate, |
|
| 72 | + 'url_obfuscator_service' => $this->url_obfuscator_service, |
|
| 73 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
| 74 | + ]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + return ''; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Extract path from the provided fact objet. |
|
| 82 | - * |
|
| 83 | - * @param \Fisharebest\Webtrees\Fact|array<array<\Fisharebest\Webtrees\Contracts\ElementInterface|string>> $fact |
|
| 84 | - * @return string |
|
| 85 | - * @psalm-suppress RedundantConditionGivenDocblockType |
|
| 86 | - */ |
|
| 87 | - private function extractPath($fact): string |
|
| 88 | - { |
|
| 89 | - if ($fact instanceof Fact && $fact->target() instanceof Source) { |
|
| 90 | - return $fact->attribute('_ACT'); |
|
| 91 | - } elseif ( |
|
| 92 | - is_array($fact) && count($fact) === 2 |
|
| 93 | - && null !== ($source_elements = $fact[0]) && is_array($source_elements) // @phpstan-ignore-line |
|
| 94 | - && null !== ($source_values = $fact[1]) && is_array($source_values) // @phpstan-ignore-line |
|
| 95 | - ) { |
|
| 96 | - foreach ($source_elements as $key => $element) { |
|
| 97 | - if ( |
|
| 98 | - $element instanceof SourceCertificate |
|
| 99 | - && isset($source_values[$key]) && is_string($source_values[$key]) |
|
| 100 | - ) { |
|
| 101 | - return $element->canonical($source_values[$key]); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - return ''; |
|
| 106 | - } |
|
| 80 | + /** |
|
| 81 | + * Extract path from the provided fact objet. |
|
| 82 | + * |
|
| 83 | + * @param \Fisharebest\Webtrees\Fact|array<array<\Fisharebest\Webtrees\Contracts\ElementInterface|string>> $fact |
|
| 84 | + * @return string |
|
| 85 | + * @psalm-suppress RedundantConditionGivenDocblockType |
|
| 86 | + */ |
|
| 87 | + private function extractPath($fact): string |
|
| 88 | + { |
|
| 89 | + if ($fact instanceof Fact && $fact->target() instanceof Source) { |
|
| 90 | + return $fact->attribute('_ACT'); |
|
| 91 | + } elseif ( |
|
| 92 | + is_array($fact) && count($fact) === 2 |
|
| 93 | + && null !== ($source_elements = $fact[0]) && is_array($source_elements) // @phpstan-ignore-line |
|
| 94 | + && null !== ($source_values = $fact[1]) && is_array($source_values) // @phpstan-ignore-line |
|
| 95 | + ) { |
|
| 96 | + foreach ($source_elements as $key => $element) { |
|
| 97 | + if ( |
|
| 98 | + $element instanceof SourceCertificate |
|
| 99 | + && isset($source_values[$key]) && is_string($source_values[$key]) |
|
| 100 | + ) { |
|
| 101 | + return $element->canonical($source_values[$key]); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + return ''; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * {@inheritDoc} |
|
| 110 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
| 111 | - */ |
|
| 112 | - public function factSourceAppend(Tree $tree, $fact): string |
|
| 113 | - { |
|
| 114 | - return ''; |
|
| 115 | - } |
|
| 108 | + /** |
|
| 109 | + * {@inheritDoc} |
|
| 110 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\FactSourceTextExtenderInterface::factSourceAppend() |
|
| 111 | + */ |
|
| 112 | + public function factSourceAppend(Tree $tree, $fact): string |
|
| 113 | + { |
|
| 114 | + return ''; |
|
| 115 | + } |
|
| 116 | 116 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | bool $add_watermark = false, |
| 80 | 80 | Watermark $watermark = null |
| 81 | 81 | ): ResponseInterface { |
| 82 | - $filesystem = $this->filesystem_service->filesystem($certificate->tree()); |
|
| 82 | + $filesystem = $this->filesystem_service->filesystem($certificate->tree()); |
|
| 83 | 83 | $filename = $certificate->path(); |
| 84 | 84 | |
| 85 | 85 | if (!$add_watermark) { |
@@ -98,34 +98,34 @@ discard block |
||
| 98 | 98 | $height = $image->height(); |
| 99 | 99 | |
| 100 | 100 | $watermark->adjustSize($width); |
| 101 | - $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5); |
|
| 101 | + $watermark_x = (int)ceil($watermark->textLengthEstimate() * 1.5); |
|
| 102 | 102 | $watermark_y = $watermark->size() * 12 + 1; |
| 103 | 103 | |
| 104 | - $font_definition = function (AbstractFont $font) use ($watermark): void { |
|
| 105 | - $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf'); |
|
| 104 | + $font_definition = function(AbstractFont $font) use ($watermark): void { |
|
| 105 | + $font->file(Webtrees::ROOT_DIR.'resources/fonts/DejaVuSans.ttf'); |
|
| 106 | 106 | $font->color($watermark->color()); |
| 107 | 107 | $font->size($watermark->size()); |
| 108 | 108 | $font->valign('top'); |
| 109 | 109 | }; |
| 110 | 110 | |
| 111 | - for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) { |
|
| 112 | - for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) { |
|
| 111 | + for ($i = min((int)ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) { |
|
| 112 | + for ($j = min((int)ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) { |
|
| 113 | 113 | $image = $image->text($watermark->text(), $i, $j, $font_definition); |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | $format = static::SUPPORTED_FORMATS[$image->mime()] ?? 'jpg'; |
| 118 | 118 | $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY); |
| 119 | - $data = (string) $image->encode($format, $quality); |
|
| 119 | + $data = (string)$image->encode($format, $quality); |
|
| 120 | 120 | |
| 121 | 121 | return $this->imageResponse($data, $image->mime(), ''); |
| 122 | 122 | } catch (NotReadableException $ex) { |
| 123 | 123 | return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION)) |
| 124 | 124 | ->withHeader('X-Image-Exception', $ex->getMessage()); |
| 125 | 125 | } catch (FilesystemException | UnableToReadFile $ex) { |
| 126 | - return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND); |
|
| 126 | + return $this->replacementImageResponse((string)StatusCodeInterface::STATUS_NOT_FOUND); |
|
| 127 | 127 | } catch (Throwable $ex) { |
| 128 | - return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR) |
|
| 128 | + return $this->replacementImageResponse((string)StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR) |
|
| 129 | 129 | ->withHeader('X-Image-Exception', $ex->getMessage()); |
| 130 | 130 | } |
| 131 | 131 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool |
| 141 | 141 | { |
| 142 | 142 | $tree = $certificate->tree(); |
| 143 | - $watermark_level = (int) ($tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK', (string) Auth::PRIV_HIDE)); |
|
| 143 | + $watermark_level = (int)($tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK', (string)Auth::PRIV_HIDE)); |
|
| 144 | 144 | |
| 145 | 145 | return Auth::accessLevel($tree, $user) > $watermark_level; |
| 146 | 146 | } |
@@ -39,164 +39,164 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class CertificateImageFactory extends ImageFactory implements ImageFactoryInterface |
| 41 | 41 | { |
| 42 | - /** |
|
| 43 | - * @var CertificateFilesystemService $filesystem_service |
|
| 44 | - */ |
|
| 45 | - private $filesystem_service; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Constructor for the Certificate Image Factory |
|
| 49 | - * |
|
| 50 | - * @param CertificateFilesystemService $filesystem_service |
|
| 51 | - */ |
|
| 52 | - public function __construct(CertificateFilesystemService $filesystem_service) |
|
| 53 | - { |
|
| 54 | - $this->filesystem_service = $filesystem_service; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Check is a file MIME type is supported by the system. |
|
| 59 | - * |
|
| 60 | - * @param string $mime |
|
| 61 | - * @return bool |
|
| 62 | - */ |
|
| 63 | - public function isMimeTypeSupported(string $mime): bool |
|
| 64 | - { |
|
| 65 | - return array_key_exists($mime, self::SUPPORTED_FORMATS); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Create a full-size version of a certificate. |
|
| 70 | - * |
|
| 71 | - * @param Certificate $certificate |
|
| 72 | - * @param bool $add_watermark |
|
| 73 | - * @param Watermark $watermark |
|
| 74 | - * @throws InvalidArgumentException |
|
| 75 | - * @return ResponseInterface |
|
| 76 | - */ |
|
| 77 | - public function certificateFileResponse( |
|
| 78 | - Certificate $certificate, |
|
| 79 | - bool $add_watermark = false, |
|
| 80 | - Watermark $watermark = null |
|
| 81 | - ): ResponseInterface { |
|
| 82 | - $filesystem = $this->filesystem_service->filesystem($certificate->tree()); |
|
| 83 | - $filename = $certificate->path(); |
|
| 84 | - |
|
| 85 | - if (!$add_watermark) { |
|
| 86 | - return $this->fileResponse($filesystem, $filename, false); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - try { |
|
| 90 | - $image = $this->imageManager()->make($filesystem->readStream($filename)); |
|
| 91 | - $image = $this->autorotateImage($image); |
|
| 92 | - |
|
| 93 | - if ($watermark === null) { |
|
| 94 | - throw new InvalidArgumentException('Watermark data not defined'); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $width = $image->width(); |
|
| 98 | - $height = $image->height(); |
|
| 99 | - |
|
| 100 | - $watermark->adjustSize($width); |
|
| 101 | - $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5); |
|
| 102 | - $watermark_y = $watermark->size() * 12 + 1; |
|
| 103 | - |
|
| 104 | - $font_definition = function (AbstractFont $font) use ($watermark): void { |
|
| 105 | - $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf'); |
|
| 106 | - $font->color($watermark->color()); |
|
| 107 | - $font->size($watermark->size()); |
|
| 108 | - $font->valign('top'); |
|
| 109 | - }; |
|
| 110 | - |
|
| 111 | - for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) { |
|
| 112 | - for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) { |
|
| 113 | - $image = $image->text($watermark->text(), $i, $j, $font_definition); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $format = static::SUPPORTED_FORMATS[$image->mime()] ?? 'jpg'; |
|
| 118 | - $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY); |
|
| 119 | - $data = (string) $image->encode($format, $quality); |
|
| 120 | - |
|
| 121 | - return $this->imageResponse($data, $image->mime(), ''); |
|
| 122 | - } catch (NotReadableException $ex) { |
|
| 123 | - return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION)) |
|
| 124 | - ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
| 125 | - } catch (FilesystemException | UnableToReadFile $ex) { |
|
| 126 | - return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND); |
|
| 127 | - } catch (Throwable $ex) { |
|
| 128 | - return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR) |
|
| 129 | - ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Does a full-sized certificate need a watermark? |
|
| 135 | - * |
|
| 136 | - * @param Certificate $certificate |
|
| 137 | - * @param UserInterface $user |
|
| 138 | - * @return bool |
|
| 139 | - */ |
|
| 140 | - public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool |
|
| 141 | - { |
|
| 142 | - $tree = $certificate->tree(); |
|
| 143 | - $watermark_level = (int) ($tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK', (string) Auth::PRIV_HIDE)); |
|
| 144 | - |
|
| 145 | - return Auth::accessLevel($tree, $user) > $watermark_level; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Neutralise the methods associated with MediaFile. |
|
| 150 | - */ |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * {@inheritDoc} |
|
| 154 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileResponse() |
|
| 155 | - */ |
|
| 156 | - public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface |
|
| 157 | - { |
|
| 158 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - /** |
|
| 162 | - * {@inheritDoc} |
|
| 163 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileThumbnailResponse() |
|
| 164 | - */ |
|
| 165 | - public function mediaFileThumbnailResponse( |
|
| 166 | - MediaFile $media_file, |
|
| 167 | - int $width, |
|
| 168 | - int $height, |
|
| 169 | - string $fit, |
|
| 170 | - bool $add_watermark |
|
| 171 | - ): ResponseInterface { |
|
| 172 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * {@inheritDoc} |
|
| 177 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::createWatermark() |
|
| 178 | - */ |
|
| 179 | - public function createWatermark(int $width, int $height, MediaFile $media_file): Image |
|
| 180 | - { |
|
| 181 | - |
|
| 182 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * {@inheritDoc} |
|
| 187 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::fileNeedsWatermark() |
|
| 188 | - */ |
|
| 189 | - public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
| 190 | - { |
|
| 191 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * {@inheritDoc} |
|
| 196 | - * @see \Fisharebest\Webtrees\Factories\ImageFactory::thumbnailNeedsWatermark() |
|
| 197 | - */ |
|
| 198 | - public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
| 199 | - { |
|
| 200 | - throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 201 | - } |
|
| 42 | + /** |
|
| 43 | + * @var CertificateFilesystemService $filesystem_service |
|
| 44 | + */ |
|
| 45 | + private $filesystem_service; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Constructor for the Certificate Image Factory |
|
| 49 | + * |
|
| 50 | + * @param CertificateFilesystemService $filesystem_service |
|
| 51 | + */ |
|
| 52 | + public function __construct(CertificateFilesystemService $filesystem_service) |
|
| 53 | + { |
|
| 54 | + $this->filesystem_service = $filesystem_service; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Check is a file MIME type is supported by the system. |
|
| 59 | + * |
|
| 60 | + * @param string $mime |
|
| 61 | + * @return bool |
|
| 62 | + */ |
|
| 63 | + public function isMimeTypeSupported(string $mime): bool |
|
| 64 | + { |
|
| 65 | + return array_key_exists($mime, self::SUPPORTED_FORMATS); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Create a full-size version of a certificate. |
|
| 70 | + * |
|
| 71 | + * @param Certificate $certificate |
|
| 72 | + * @param bool $add_watermark |
|
| 73 | + * @param Watermark $watermark |
|
| 74 | + * @throws InvalidArgumentException |
|
| 75 | + * @return ResponseInterface |
|
| 76 | + */ |
|
| 77 | + public function certificateFileResponse( |
|
| 78 | + Certificate $certificate, |
|
| 79 | + bool $add_watermark = false, |
|
| 80 | + Watermark $watermark = null |
|
| 81 | + ): ResponseInterface { |
|
| 82 | + $filesystem = $this->filesystem_service->filesystem($certificate->tree()); |
|
| 83 | + $filename = $certificate->path(); |
|
| 84 | + |
|
| 85 | + if (!$add_watermark) { |
|
| 86 | + return $this->fileResponse($filesystem, $filename, false); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + try { |
|
| 90 | + $image = $this->imageManager()->make($filesystem->readStream($filename)); |
|
| 91 | + $image = $this->autorotateImage($image); |
|
| 92 | + |
|
| 93 | + if ($watermark === null) { |
|
| 94 | + throw new InvalidArgumentException('Watermark data not defined'); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $width = $image->width(); |
|
| 98 | + $height = $image->height(); |
|
| 99 | + |
|
| 100 | + $watermark->adjustSize($width); |
|
| 101 | + $watermark_x = (int) ceil($watermark->textLengthEstimate() * 1.5); |
|
| 102 | + $watermark_y = $watermark->size() * 12 + 1; |
|
| 103 | + |
|
| 104 | + $font_definition = function (AbstractFont $font) use ($watermark): void { |
|
| 105 | + $font->file(Webtrees::ROOT_DIR . 'resources/fonts/DejaVuSans.ttf'); |
|
| 106 | + $font->color($watermark->color()); |
|
| 107 | + $font->size($watermark->size()); |
|
| 108 | + $font->valign('top'); |
|
| 109 | + }; |
|
| 110 | + |
|
| 111 | + for ($i = min((int) ceil($width * 0.1), $watermark_x); $i < $width; $i += $watermark_x) { |
|
| 112 | + for ($j = min((int) ceil($height * 0.1), $watermark_y); $j < $height; $j += $watermark_y) { |
|
| 113 | + $image = $image->text($watermark->text(), $i, $j, $font_definition); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $format = static::SUPPORTED_FORMATS[$image->mime()] ?? 'jpg'; |
|
| 118 | + $quality = $this->extractImageQuality($image, static::GD_DEFAULT_IMAGE_QUALITY); |
|
| 119 | + $data = (string) $image->encode($format, $quality); |
|
| 120 | + |
|
| 121 | + return $this->imageResponse($data, $image->mime(), ''); |
|
| 122 | + } catch (NotReadableException $ex) { |
|
| 123 | + return $this->replacementImageResponse(pathinfo($filename, PATHINFO_EXTENSION)) |
|
| 124 | + ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
| 125 | + } catch (FilesystemException | UnableToReadFile $ex) { |
|
| 126 | + return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND); |
|
| 127 | + } catch (Throwable $ex) { |
|
| 128 | + return $this->replacementImageResponse((string) StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR) |
|
| 129 | + ->withHeader('X-Image-Exception', $ex->getMessage()); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Does a full-sized certificate need a watermark? |
|
| 135 | + * |
|
| 136 | + * @param Certificate $certificate |
|
| 137 | + * @param UserInterface $user |
|
| 138 | + * @return bool |
|
| 139 | + */ |
|
| 140 | + public function certificateNeedsWatermark(Certificate $certificate, UserInterface $user): bool |
|
| 141 | + { |
|
| 142 | + $tree = $certificate->tree(); |
|
| 143 | + $watermark_level = (int) ($tree->getPreference('MAJ_CERTIF_SHOW_NO_WATERMARK', (string) Auth::PRIV_HIDE)); |
|
| 144 | + |
|
| 145 | + return Auth::accessLevel($tree, $user) > $watermark_level; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Neutralise the methods associated with MediaFile. |
|
| 150 | + */ |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * {@inheritDoc} |
|
| 154 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileResponse() |
|
| 155 | + */ |
|
| 156 | + public function mediaFileResponse(MediaFile $media_file, bool $add_watermark, bool $download): ResponseInterface |
|
| 157 | + { |
|
| 158 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + /** |
|
| 162 | + * {@inheritDoc} |
|
| 163 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::mediaFileThumbnailResponse() |
|
| 164 | + */ |
|
| 165 | + public function mediaFileThumbnailResponse( |
|
| 166 | + MediaFile $media_file, |
|
| 167 | + int $width, |
|
| 168 | + int $height, |
|
| 169 | + string $fit, |
|
| 170 | + bool $add_watermark |
|
| 171 | + ): ResponseInterface { |
|
| 172 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * {@inheritDoc} |
|
| 177 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::createWatermark() |
|
| 178 | + */ |
|
| 179 | + public function createWatermark(int $width, int $height, MediaFile $media_file): Image |
|
| 180 | + { |
|
| 181 | + |
|
| 182 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * {@inheritDoc} |
|
| 187 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::fileNeedsWatermark() |
|
| 188 | + */ |
|
| 189 | + public function fileNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
| 190 | + { |
|
| 191 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * {@inheritDoc} |
|
| 196 | + * @see \Fisharebest\Webtrees\Factories\ImageFactory::thumbnailNeedsWatermark() |
|
| 197 | + */ |
|
| 198 | + public function thumbnailNeedsWatermark(MediaFile $media_file, UserInterface $user): bool |
|
| 199 | + { |
|
| 200 | + throw new BadMethodCallException("Invalid method for Certificates"); |
|
| 201 | + } |
|
| 202 | 202 | } |
@@ -31,53 +31,53 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class AutoCompleteFile extends AbstractAutocompleteHandler |
| 33 | 33 | { |
| 34 | - // Tell the browser to cache the results |
|
| 35 | - protected const CACHE_LIFE = 10; |
|
| 34 | + // Tell the browser to cache the results |
|
| 35 | + protected const CACHE_LIFE = 10; |
|
| 36 | 36 | |
| 37 | - private ?CertificatesModule $module; |
|
| 38 | - private CertificateFilesystemService $certif_filesystem; |
|
| 39 | - private UrlObfuscatorService $url_obfuscator_service; |
|
| 37 | + private ?CertificatesModule $module; |
|
| 38 | + private CertificateFilesystemService $certif_filesystem; |
|
| 39 | + private UrlObfuscatorService $url_obfuscator_service; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Constructor for AutoCompleteFile Request Handler |
|
| 43 | - * |
|
| 44 | - * @param ModuleService $module_service |
|
| 45 | - * @param CertificateFilesystemService $certif_filesystem |
|
| 46 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
| 47 | - * @param SearchService $search_service |
|
| 48 | - */ |
|
| 49 | - public function __construct( |
|
| 50 | - ModuleService $module_service, |
|
| 51 | - CertificateFilesystemService $certif_filesystem, |
|
| 52 | - UrlObfuscatorService $url_obfuscator_service, |
|
| 53 | - SearchService $search_service |
|
| 54 | - ) { |
|
| 55 | - parent::__construct($search_service); |
|
| 56 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 57 | - $this->certif_filesystem = $certif_filesystem; |
|
| 58 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 59 | - } |
|
| 41 | + /** |
|
| 42 | + * Constructor for AutoCompleteFile Request Handler |
|
| 43 | + * |
|
| 44 | + * @param ModuleService $module_service |
|
| 45 | + * @param CertificateFilesystemService $certif_filesystem |
|
| 46 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
| 47 | + * @param SearchService $search_service |
|
| 48 | + */ |
|
| 49 | + public function __construct( |
|
| 50 | + ModuleService $module_service, |
|
| 51 | + CertificateFilesystemService $certif_filesystem, |
|
| 52 | + UrlObfuscatorService $url_obfuscator_service, |
|
| 53 | + SearchService $search_service |
|
| 54 | + ) { |
|
| 55 | + parent::__construct($search_service); |
|
| 56 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
| 57 | + $this->certif_filesystem = $certif_filesystem; |
|
| 58 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * {@inheritDoc} |
|
| 63 | - * @see \Fisharebest\Webtrees\Http\RequestHandlers\AbstractAutocompleteHandler::search() |
|
| 64 | - */ |
|
| 65 | - protected function search(ServerRequestInterface $request): Collection |
|
| 66 | - { |
|
| 67 | - $tree = Validator::attributes($request)->tree(); |
|
| 68 | - $city = Validator::queryParams($request)->string('cityobf', ''); |
|
| 61 | + /** |
|
| 62 | + * {@inheritDoc} |
|
| 63 | + * @see \Fisharebest\Webtrees\Http\RequestHandlers\AbstractAutocompleteHandler::search() |
|
| 64 | + */ |
|
| 65 | + protected function search(ServerRequestInterface $request): Collection |
|
| 66 | + { |
|
| 67 | + $tree = Validator::attributes($request)->tree(); |
|
| 68 | + $city = Validator::queryParams($request)->string('cityobf', ''); |
|
| 69 | 69 | |
| 70 | - if ($this->module === null || $city === '' || !$this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
| 71 | - return collect(); |
|
| 72 | - } |
|
| 70 | + if ($this->module === null || $city === '' || !$this->url_obfuscator_service->tryDeobfuscate($city)) { |
|
| 71 | + return collect(); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - $query = Validator::attributes($request)->string('query', ''); |
|
| 74 | + $query = Validator::attributes($request)->string('query', ''); |
|
| 75 | 75 | |
| 76 | - /** @var Collection<int, string> $results */ |
|
| 77 | - $results = $this->certif_filesystem |
|
| 78 | - ->certificatesForCityContaining($tree, $city, $query) |
|
| 79 | - ->map(fn(Certificate $certificate): string => $certificate->filename()); |
|
| 76 | + /** @var Collection<int, string> $results */ |
|
| 77 | + $results = $this->certif_filesystem |
|
| 78 | + ->certificatesForCityContaining($tree, $city, $query) |
|
| 79 | + ->map(fn(Certificate $certificate): string => $certificate->filename()); |
|
| 80 | 80 | |
| 81 | - return $results; |
|
| 82 | - } |
|
| 81 | + return $results; |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -71,10 +71,10 @@ |
||
| 71 | 71 | return collect(); |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - $query = Validator::attributes($request)->string('query', ''); |
|
| 74 | + $query = Validator::attributes($request)->string('query', ''); |
|
| 75 | 75 | |
| 76 | 76 | /** @var Collection<int, string> $results */ |
| 77 | - $results = $this->certif_filesystem |
|
| 77 | + $results = $this->certif_filesystem |
|
| 78 | 78 | ->certificatesForCityContaining($tree, $city, $query) |
| 79 | 79 | ->map(fn(Certificate $certificate): string => $certificate->filename()); |
| 80 | 80 | |