@@ -32,47 +32,47 @@ |
||
32 | 32 | */ |
33 | 33 | class GeoAnalysisViewsList implements RequestHandlerInterface |
34 | 34 | { |
35 | - use ViewResponseTrait; |
|
35 | + use ViewResponseTrait; |
|
36 | 36 | |
37 | - private ?GeoDispersionModule $module; |
|
38 | - private GeoAnalysisViewDataService $geoviewdata_service; |
|
37 | + private ?GeoDispersionModule $module; |
|
38 | + private GeoAnalysisViewDataService $geoviewdata_service; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Constructor for GeoAnalysisViewsList Request Handler |
|
42 | - * |
|
43 | - * @param ModuleService $module_service |
|
44 | - */ |
|
45 | - public function __construct( |
|
46 | - ModuleService $module_service, |
|
47 | - GeoAnalysisViewDataService $geoviewdata_service |
|
48 | - ) { |
|
49 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
50 | - $this->geoviewdata_service = $geoviewdata_service; |
|
51 | - } |
|
40 | + /** |
|
41 | + * Constructor for GeoAnalysisViewsList Request Handler |
|
42 | + * |
|
43 | + * @param ModuleService $module_service |
|
44 | + */ |
|
45 | + public function __construct( |
|
46 | + ModuleService $module_service, |
|
47 | + GeoAnalysisViewDataService $geoviewdata_service |
|
48 | + ) { |
|
49 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
50 | + $this->geoviewdata_service = $geoviewdata_service; |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * {@inheritDoc} |
|
55 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
56 | - */ |
|
57 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
58 | - { |
|
59 | - if ($this->module === null) { |
|
60 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
61 | - } |
|
53 | + /** |
|
54 | + * {@inheritDoc} |
|
55 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
56 | + */ |
|
57 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
58 | + { |
|
59 | + if ($this->module === null) { |
|
60 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
61 | + } |
|
62 | 62 | |
63 | - $tree = $request->getAttribute('tree'); |
|
64 | - assert($tree instanceof Tree); |
|
63 | + $tree = $request->getAttribute('tree'); |
|
64 | + assert($tree instanceof Tree); |
|
65 | 65 | |
66 | - $views_list = $this->geoviewdata_service |
|
67 | - ->all($tree) |
|
68 | - ->sortBy(fn(AbstractGeoAnalysisView $view) => $view->description()); |
|
66 | + $views_list = $this->geoviewdata_service |
|
67 | + ->all($tree) |
|
68 | + ->sortBy(fn(AbstractGeoAnalysisView $view) => $view->description()); |
|
69 | 69 | |
70 | - return $this->viewResponse($this->module->name() . '::geoanalysisviews-list', [ |
|
71 | - 'module' => $this->module, |
|
72 | - 'title' => I18N::translate('Geographical dispersion'), |
|
73 | - 'tree' => $tree, |
|
74 | - 'views_list' => $views_list, |
|
75 | - 'js_script_url' => $this->module->assetUrl('js/geodispersion.min.js') |
|
76 | - ]); |
|
77 | - } |
|
70 | + return $this->viewResponse($this->module->name() . '::geoanalysisviews-list', [ |
|
71 | + 'module' => $this->module, |
|
72 | + 'title' => I18N::translate('Geographical dispersion'), |
|
73 | + 'tree' => $tree, |
|
74 | + 'views_list' => $views_list, |
|
75 | + 'js_script_url' => $this->module->assetUrl('js/geodispersion.min.js') |
|
76 | + ]); |
|
77 | + } |
|
78 | 78 | } |
@@ -31,45 +31,45 @@ |
||
31 | 31 | */ |
32 | 32 | class GeoAnalysisViewPage implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
34 | + use ViewResponseTrait; |
|
35 | 35 | |
36 | - private ?GeoDispersionModule $module; |
|
37 | - private GeoAnalysisViewDataService $geoviewdata_service; |
|
36 | + private ?GeoDispersionModule $module; |
|
37 | + private GeoAnalysisViewDataService $geoviewdata_service; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor for GeoAnalysisViewPage Request Handler |
|
41 | - * |
|
42 | - * @param ModuleService $module_service |
|
43 | - */ |
|
44 | - public function __construct( |
|
45 | - ModuleService $module_service, |
|
46 | - GeoAnalysisViewDataService $geoviewdata_service |
|
47 | - ) { |
|
48 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
49 | - $this->geoviewdata_service = $geoviewdata_service; |
|
50 | - } |
|
39 | + /** |
|
40 | + * Constructor for GeoAnalysisViewPage Request Handler |
|
41 | + * |
|
42 | + * @param ModuleService $module_service |
|
43 | + */ |
|
44 | + public function __construct( |
|
45 | + ModuleService $module_service, |
|
46 | + GeoAnalysisViewDataService $geoviewdata_service |
|
47 | + ) { |
|
48 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
49 | + $this->geoviewdata_service = $geoviewdata_service; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | - */ |
|
56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | - { |
|
58 | - if ($this->module === null) { |
|
59 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | - } |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | + */ |
|
56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | + { |
|
58 | + if ($this->module === null) { |
|
59 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | + } |
|
61 | 61 | |
62 | - $tree = $request->getAttribute('tree'); |
|
63 | - assert($tree instanceof Tree); |
|
62 | + $tree = $request->getAttribute('tree'); |
|
63 | + assert($tree instanceof Tree); |
|
64 | 64 | |
65 | - $view_id = $request->getAttribute('view_id'); |
|
66 | - $view_id = is_numeric($view_id) ? (int) $view_id : 0; |
|
65 | + $view_id = $request->getAttribute('view_id'); |
|
66 | + $view_id = is_numeric($view_id) ? (int) $view_id : 0; |
|
67 | 67 | |
68 | - return $this->viewResponse($this->module->name() . '::geoanalysisview-page', [ |
|
69 | - 'module_name' => $this->module->name(), |
|
70 | - 'title' => I18N::translate('Geographical dispersion'), |
|
71 | - 'tree' => $tree, |
|
72 | - 'view' => $this->geoviewdata_service->find($tree, $view_id) |
|
73 | - ]); |
|
74 | - } |
|
68 | + return $this->viewResponse($this->module->name() . '::geoanalysisview-page', [ |
|
69 | + 'module_name' => $this->module->name(), |
|
70 | + 'title' => I18N::translate('Geographical dispersion'), |
|
71 | + 'tree' => $tree, |
|
72 | + 'view' => $this->geoviewdata_service->find($tree, $view_id) |
|
73 | + ]); |
|
74 | + } |
|
75 | 75 | } |
@@ -21,65 +21,65 @@ |
||
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 array $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) => $top_places instanceof Place |
|
50 | - )->toArray(); |
|
51 | - } |
|
39 | + /** |
|
40 | + * Set the list of defined top level places. |
|
41 | + * |
|
42 | + * @param array $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) => $top_places instanceof Place |
|
50 | + )->toArray(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * Check whether a string ($haystack) ends with another string ($needle) |
|
55 | - * |
|
56 | - * {@internal This is redundant with the function str_ends_with in PHP8} |
|
57 | - * |
|
58 | - * @param string $haystack |
|
59 | - * @param string $needle |
|
60 | - * @return bool |
|
61 | - */ |
|
62 | - private function endsWith(string $haystack, string $needle): bool |
|
63 | - { |
|
64 | - return substr_compare($haystack, $needle, -strlen($needle)) === 0; |
|
65 | - } |
|
53 | + /** |
|
54 | + * Check whether a string ($haystack) ends with another string ($needle) |
|
55 | + * |
|
56 | + * {@internal This is redundant with the function str_ends_with in PHP8} |
|
57 | + * |
|
58 | + * @param string $haystack |
|
59 | + * @param string $needle |
|
60 | + * @return bool |
|
61 | + */ |
|
62 | + private function endsWith(string $haystack, string $needle): bool |
|
63 | + { |
|
64 | + return substr_compare($haystack, $needle, -strlen($needle)) === 0; |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Check whether a Place belongs to one of the defined top places. |
|
69 | - * |
|
70 | - * @param Place $place |
|
71 | - * @return bool |
|
72 | - */ |
|
73 | - protected function belongsToTopLevels(Place $place): bool |
|
74 | - { |
|
75 | - foreach ($this->top_places as $top_place) { |
|
76 | - if ( |
|
77 | - $top_place->tree()->id() === $place->tree()->id() && |
|
78 | - $this->endsWith($place->gedcomName(), $top_place->gedcomName()) |
|
79 | - ) { |
|
80 | - return true; |
|
81 | - } |
|
82 | - } |
|
83 | - return false; |
|
84 | - } |
|
67 | + /** |
|
68 | + * Check whether a Place belongs to one of the defined top places. |
|
69 | + * |
|
70 | + * @param Place $place |
|
71 | + * @return bool |
|
72 | + */ |
|
73 | + protected function belongsToTopLevels(Place $place): bool |
|
74 | + { |
|
75 | + foreach ($this->top_places as $top_place) { |
|
76 | + if ( |
|
77 | + $top_place->tree()->id() === $place->tree()->id() && |
|
78 | + $this->endsWith($place->gedcomName(), $top_place->gedcomName()) |
|
79 | + ) { |
|
80 | + return true; |
|
81 | + } |
|
82 | + } |
|
83 | + return false; |
|
84 | + } |
|
85 | 85 | } |
@@ -24,65 +24,65 @@ |
||
24 | 24 | */ |
25 | 25 | trait PlaceMapperTrait |
26 | 26 | { |
27 | - private ?PlaceMapperConfigInterface $config = null; |
|
28 | - private array $data = []; |
|
27 | + private ?PlaceMapperConfigInterface $config = null; |
|
28 | + private array $data = []; |
|
29 | 29 | |
30 | - /** |
|
31 | - * Implementation of PlaceMapperInterface::boot |
|
32 | - * |
|
33 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
34 | - */ |
|
35 | - public function boot(): void |
|
36 | - { |
|
37 | - } |
|
30 | + /** |
|
31 | + * Implementation of PlaceMapperInterface::boot |
|
32 | + * |
|
33 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::boot() |
|
34 | + */ |
|
35 | + public function boot(): void |
|
36 | + { |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * Implementation of PlaceMapperInterface::config |
|
41 | - * |
|
42 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
43 | - * |
|
44 | - * @return PlaceMapperConfigInterface |
|
45 | - */ |
|
46 | - public function config(): PlaceMapperConfigInterface |
|
47 | - { |
|
48 | - return $this->config ?? new NullPlaceMapperConfig(); |
|
49 | - } |
|
39 | + /** |
|
40 | + * Implementation of PlaceMapperInterface::config |
|
41 | + * |
|
42 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::config() |
|
43 | + * |
|
44 | + * @return PlaceMapperConfigInterface |
|
45 | + */ |
|
46 | + public function config(): PlaceMapperConfigInterface |
|
47 | + { |
|
48 | + return $this->config ?? new NullPlaceMapperConfig(); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Implementation of PlaceMapperInterface::setConfig |
|
53 | - * |
|
54 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setConfig() |
|
55 | - * |
|
56 | - * @param PlaceMapperConfigInterface $config |
|
57 | - */ |
|
58 | - public function setConfig(PlaceMapperConfigInterface $config): void |
|
59 | - { |
|
60 | - $this->config = $config; |
|
61 | - } |
|
51 | + /** |
|
52 | + * Implementation of PlaceMapperInterface::setConfig |
|
53 | + * |
|
54 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setConfig() |
|
55 | + * |
|
56 | + * @param PlaceMapperConfigInterface $config |
|
57 | + */ |
|
58 | + public function setConfig(PlaceMapperConfigInterface $config): void |
|
59 | + { |
|
60 | + $this->config = $config; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * Implementation of PlaceMapperInterface::data |
|
65 | - * |
|
66 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::data() |
|
67 | - * |
|
68 | - * @param string $key |
|
69 | - * @return NULL|mixed |
|
70 | - */ |
|
71 | - public function data(string $key) |
|
72 | - { |
|
73 | - return $this->data[$key] ?? null; |
|
74 | - } |
|
63 | + /** |
|
64 | + * Implementation of PlaceMapperInterface::data |
|
65 | + * |
|
66 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::data() |
|
67 | + * |
|
68 | + * @param string $key |
|
69 | + * @return NULL|mixed |
|
70 | + */ |
|
71 | + public function data(string $key) |
|
72 | + { |
|
73 | + return $this->data[$key] ?? null; |
|
74 | + } |
|
75 | 75 | |
76 | - /** |
|
77 | - * Implementation of PlaceMapperInterface::setData |
|
78 | - * |
|
79 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setData() |
|
80 | - * |
|
81 | - * @param string $key |
|
82 | - * @param mixed|null $data |
|
83 | - */ |
|
84 | - public function setData(string $key, $data): void |
|
85 | - { |
|
86 | - $this->data[$key] = $data; |
|
87 | - } |
|
76 | + /** |
|
77 | + * Implementation of PlaceMapperInterface::setData |
|
78 | + * |
|
79 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\PlaceMapperInterface::setData() |
|
80 | + * |
|
81 | + * @param string $key |
|
82 | + * @param mixed|null $data |
|
83 | + */ |
|
84 | + public function setData(string $key, $data): void |
|
85 | + { |
|
86 | + $this->data[$key] = $data; |
|
87 | + } |
|
88 | 88 | } |
@@ -24,35 +24,35 @@ |
||
24 | 24 | class Migration1 implements MigrationInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritDoc} |
|
29 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
30 | - */ |
|
31 | - public function upgrade(): void |
|
32 | - { |
|
33 | - DB::schema()->create('maj_geodisp_views', static function (Blueprint $table): void { |
|
34 | - $table->integer('majgv_id')->autoIncrement(); |
|
35 | - $table->integer('majgv_gedcom_id')->index(); |
|
36 | - $table->string('majgv_view_class', 255); |
|
37 | - $table->enum('majgv_status', ['enabled', 'disabled'])->default('enabled'); |
|
38 | - $table->string('majgv_descr', 248); |
|
39 | - $table->string('majgv_analysis', 255); |
|
40 | - $table->tinyInteger('majgv_place_depth')->default(1); |
|
41 | - $table->tinyInteger('majgv_top_places')->default(0); |
|
42 | - $table->json('majgv_colors')->nullable(); |
|
43 | - |
|
44 | - $table->foreign('majgv_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); |
|
45 | - }); |
|
46 | - |
|
47 | - DB::schema()->create('maj_geodisp_mapviews', static function (Blueprint $table): void { |
|
48 | - $table->integer('majgm_id')->autoIncrement(); |
|
49 | - $table->integer('majgm_majgv_id')->index(); |
|
50 | - $table->string('majgm_map_id', 127); |
|
51 | - $table->string('majgm_mapper', 255); |
|
52 | - $table->string('majgm_feature_prop', 31); |
|
53 | - $table->json('majgm_config')->nullable(); |
|
54 | - |
|
55 | - $table->foreign('majgm_majgv_id')->references('majgv_id')->on('maj_geodisp_views')->onDelete('cascade'); |
|
56 | - }); |
|
57 | - } |
|
27 | + /** |
|
28 | + * {@inheritDoc} |
|
29 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
30 | + */ |
|
31 | + public function upgrade(): void |
|
32 | + { |
|
33 | + DB::schema()->create('maj_geodisp_views', static function (Blueprint $table): void { |
|
34 | + $table->integer('majgv_id')->autoIncrement(); |
|
35 | + $table->integer('majgv_gedcom_id')->index(); |
|
36 | + $table->string('majgv_view_class', 255); |
|
37 | + $table->enum('majgv_status', ['enabled', 'disabled'])->default('enabled'); |
|
38 | + $table->string('majgv_descr', 248); |
|
39 | + $table->string('majgv_analysis', 255); |
|
40 | + $table->tinyInteger('majgv_place_depth')->default(1); |
|
41 | + $table->tinyInteger('majgv_top_places')->default(0); |
|
42 | + $table->json('majgv_colors')->nullable(); |
|
43 | + |
|
44 | + $table->foreign('majgv_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); |
|
45 | + }); |
|
46 | + |
|
47 | + DB::schema()->create('maj_geodisp_mapviews', static function (Blueprint $table): void { |
|
48 | + $table->integer('majgm_id')->autoIncrement(); |
|
49 | + $table->integer('majgm_majgv_id')->index(); |
|
50 | + $table->string('majgm_map_id', 127); |
|
51 | + $table->string('majgm_mapper', 255); |
|
52 | + $table->string('majgm_feature_prop', 31); |
|
53 | + $table->json('majgm_config')->nullable(); |
|
54 | + |
|
55 | + $table->foreign('majgm_majgv_id')->references('majgv_id')->on('maj_geodisp_views')->onDelete('cascade'); |
|
56 | + }); |
|
57 | + } |
|
58 | 58 | } |
@@ -22,12 +22,12 @@ |
||
22 | 22 | class Migration0 implements MigrationInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritDoc} |
|
27 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | - */ |
|
29 | - public function upgrade(): void |
|
30 | - { |
|
31 | - // This migration has been superseded by migration 1. |
|
32 | - } |
|
25 | + /** |
|
26 | + * {@inheritDoc} |
|
27 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | + */ |
|
29 | + public function upgrade(): void |
|
30 | + { |
|
31 | + // This migration has been superseded by migration 1. |
|
32 | + } |
|
33 | 33 | } |
@@ -25,46 +25,46 @@ |
||
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 | - fn() => $this->module_service |
|
65 | - ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
66 | - ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
67 | - ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]) |
|
68 | - ); |
|
69 | - } |
|
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 | + fn() => $this->module_service |
|
65 | + ->findByInterface(ModuleMapDefinitionProviderInterface::class, $include_disabled) |
|
66 | + ->flatMap(fn(ModuleMapDefinitionProviderInterface $module) => $module->listMapDefinition()) |
|
67 | + ->mapWithKeys(fn(MapDefinitionInterface $map) => [ $map->id() => $map ]) |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | } |
@@ -21,102 +21,102 @@ |
||
21 | 21 | */ |
22 | 22 | class PlacesReferenceTableService |
23 | 23 | { |
24 | - /** |
|
25 | - * Mapping format placeholder tags => table column names |
|
26 | - * @var array<string, string> |
|
27 | - */ |
|
28 | - private const COLUMN_MAPPING = [ |
|
29 | - 'name' => 'majgr_place_name', |
|
30 | - 'id' => 'majgr_place_admin_id', |
|
31 | - 'zip' => 'majgr_place_zip', |
|
32 | - 'gov' => 'majgr_place_gov_id', |
|
33 | - 'mls' => 'majgr_place_mls_id' |
|
34 | - ]; |
|
24 | + /** |
|
25 | + * Mapping format placeholder tags => table column names |
|
26 | + * @var array<string, string> |
|
27 | + */ |
|
28 | + private const COLUMN_MAPPING = [ |
|
29 | + 'name' => 'majgr_place_name', |
|
30 | + 'id' => 'majgr_place_admin_id', |
|
31 | + 'zip' => 'majgr_place_zip', |
|
32 | + 'gov' => 'majgr_place_gov_id', |
|
33 | + 'mls' => 'majgr_place_mls_id' |
|
34 | + ]; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Get the formatted target mapping value of a place defined by a source format. |
|
38 | - * |
|
39 | - * @param string $source |
|
40 | - * @param string $source_format |
|
41 | - * @param string $target_format |
|
42 | - * @return string|NULL |
|
43 | - */ |
|
44 | - public function targetId(string $source, string $source_format, string $target_format): ?string |
|
45 | - { |
|
46 | - // Extract parts for the WHERE clause |
|
47 | - $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format); |
|
48 | - $source_parts = preg_split('/[{}]/i', $source_format); |
|
49 | - if ($source_parts === false) { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $source_parts = array_map(function (string $part): string { |
|
53 | - if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
|
54 | - return $this->columnName($column_id[1]); |
|
55 | - } |
|
56 | - return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
|
57 | - }, array_filter($source_parts)); |
|
58 | - $source_parts[] = "'%'"; |
|
59 | - $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
36 | + /** |
|
37 | + * Get the formatted target mapping value of a place defined by a source format. |
|
38 | + * |
|
39 | + * @param string $source |
|
40 | + * @param string $source_format |
|
41 | + * @param string $target_format |
|
42 | + * @return string|NULL |
|
43 | + */ |
|
44 | + public function targetId(string $source, string $source_format, string $target_format): ?string |
|
45 | + { |
|
46 | + // Extract parts for the WHERE clause |
|
47 | + $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format); |
|
48 | + $source_parts = preg_split('/[{}]/i', $source_format); |
|
49 | + if ($source_parts === false) { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $source_parts = array_map(function (string $part): string { |
|
53 | + if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
|
54 | + return $this->columnName($column_id[1]); |
|
55 | + } |
|
56 | + return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
|
57 | + }, array_filter($source_parts)); |
|
58 | + $source_parts[] = "'%'"; |
|
59 | + $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
60 | 60 | |
61 | - // Extract columns used in target |
|
62 | - $columns = []; |
|
63 | - if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) { |
|
64 | - $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1]))); |
|
65 | - } |
|
61 | + // Extract columns used in target |
|
62 | + $columns = []; |
|
63 | + if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) { |
|
64 | + $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1]))); |
|
65 | + } |
|
66 | 66 | |
67 | - // Get the mapping |
|
68 | - $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
|
69 | - ->select($columns) |
|
70 | - ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
71 | - ->get(); |
|
67 | + // Get the mapping |
|
68 | + $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
|
69 | + ->select($columns) |
|
70 | + ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
71 | + ->get(); |
|
72 | 72 | |
73 | - // Format the output ID |
|
74 | - if ($rows->count() === 0) { |
|
75 | - return null; |
|
76 | - } |
|
73 | + // Format the output ID |
|
74 | + if ($rows->count() === 0) { |
|
75 | + return null; |
|
76 | + } |
|
77 | 77 | |
78 | - $mapping = (array) $rows->first(); |
|
79 | - if (count($columns_select) === 0) { |
|
80 | - return $target_format; |
|
81 | - } |
|
78 | + $mapping = (array) $rows->first(); |
|
79 | + if (count($columns_select) === 0) { |
|
80 | + return $target_format; |
|
81 | + } |
|
82 | 82 | |
83 | - return str_replace( |
|
84 | - array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
85 | - array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
|
86 | - $target_format |
|
87 | - ); |
|
88 | - } |
|
83 | + return str_replace( |
|
84 | + array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
85 | + array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
|
86 | + $target_format |
|
87 | + ); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Get the column name for a format placeholder tag |
|
92 | - * |
|
93 | - * @param string $placeholder |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - private function columnName(string $placeholder): string |
|
97 | - { |
|
98 | - return self::COLUMN_MAPPING[$placeholder] ?? ''; |
|
99 | - } |
|
90 | + /** |
|
91 | + * Get the column name for a format placeholder tag |
|
92 | + * |
|
93 | + * @param string $placeholder |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + private function columnName(string $placeholder): string |
|
97 | + { |
|
98 | + return self::COLUMN_MAPPING[$placeholder] ?? ''; |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Get the placeholder tag for a column_name |
|
103 | - * |
|
104 | - * @param string $column_name |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - private function tagName(string $column_name): string |
|
108 | - { |
|
109 | - return array_flip(self::COLUMN_MAPPING)[$column_name] ?? ''; |
|
110 | - } |
|
101 | + /** |
|
102 | + * Get the placeholder tag for a column_name |
|
103 | + * |
|
104 | + * @param string $column_name |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + private function tagName(string $column_name): string |
|
108 | + { |
|
109 | + return array_flip(self::COLUMN_MAPPING)[$column_name] ?? ''; |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Sanitize string for use in a SQL query. |
|
114 | - * |
|
115 | - * @param string $string |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - private function sanitizeString(string $string): string |
|
119 | - { |
|
120 | - return DB::connection()->getPdo()->quote($string); |
|
121 | - } |
|
112 | + /** |
|
113 | + * Sanitize string for use in a SQL query. |
|
114 | + * |
|
115 | + * @param string $string |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + private function sanitizeString(string $string): string |
|
119 | + { |
|
120 | + return DB::connection()->getPdo()->quote($string); |
|
121 | + } |
|
122 | 122 | } |
@@ -31,65 +31,65 @@ |
||
31 | 31 | */ |
32 | 32 | class TaskEditPage implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var AdminTasksModule|null $module |
|
38 | - */ |
|
39 | - private $module; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var TaskScheduleService $taskschedules_service |
|
43 | - */ |
|
44 | - private $taskschedules_service; |
|
45 | - |
|
46 | - /** |
|
47 | - * Constructor for TaskEditPage Request Handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - * @param TaskScheduleService $taskschedules_service |
|
51 | - */ |
|
52 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
53 | - { |
|
54 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
55 | - $this->taskschedules_service = $taskschedules_service; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | - */ |
|
62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | - { |
|
64 | - $this->layout = 'layouts/administration'; |
|
65 | - |
|
66 | - if ($this->module === null) { |
|
67 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
68 | - } |
|
69 | - |
|
70 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
71 | - $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
72 | - |
|
73 | - if ($task_schedule === null) { |
|
74 | - throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
75 | - } |
|
76 | - |
|
77 | - $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
78 | - |
|
79 | - if ($task === null) { |
|
80 | - throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
81 | - } |
|
82 | - |
|
83 | - $has_task_config = $task instanceof ConfigurableTaskInterface; |
|
84 | - /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
85 | - |
|
86 | - return $this->viewResponse($this->module->name() . '::admin/tasks-edit', [ |
|
87 | - 'module' => $this->module, |
|
88 | - 'title' => I18N::translate('Edit the administrative task') . ' - ' . $task->name(), |
|
89 | - 'task_schedule' => $task_schedule, |
|
90 | - 'task' => $task, |
|
91 | - 'has_task_config' => $has_task_config, |
|
92 | - 'task_config_view' => $has_task_config ? $task->configView($request) : '' |
|
93 | - ]); |
|
94 | - } |
|
34 | + use ViewResponseTrait; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var AdminTasksModule|null $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var TaskScheduleService $taskschedules_service |
|
43 | + */ |
|
44 | + private $taskschedules_service; |
|
45 | + |
|
46 | + /** |
|
47 | + * Constructor for TaskEditPage Request Handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + * @param TaskScheduleService $taskschedules_service |
|
51 | + */ |
|
52 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
53 | + { |
|
54 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
55 | + $this->taskschedules_service = $taskschedules_service; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | + */ |
|
62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | + { |
|
64 | + $this->layout = 'layouts/administration'; |
|
65 | + |
|
66 | + if ($this->module === null) { |
|
67 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
68 | + } |
|
69 | + |
|
70 | + $task_sched_id = (int) $request->getAttribute('task'); |
|
71 | + $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
72 | + |
|
73 | + if ($task_schedule === null) { |
|
74 | + throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
75 | + } |
|
76 | + |
|
77 | + $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
78 | + |
|
79 | + if ($task === null) { |
|
80 | + throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
81 | + } |
|
82 | + |
|
83 | + $has_task_config = $task instanceof ConfigurableTaskInterface; |
|
84 | + /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
85 | + |
|
86 | + return $this->viewResponse($this->module->name() . '::admin/tasks-edit', [ |
|
87 | + 'module' => $this->module, |
|
88 | + 'title' => I18N::translate('Edit the administrative task') . ' - ' . $task->name(), |
|
89 | + 'task_schedule' => $task_schedule, |
|
90 | + 'task' => $task, |
|
91 | + 'has_task_config' => $has_task_config, |
|
92 | + 'task_config_view' => $has_task_config ? $task->configView($request) : '' |
|
93 | + ]); |
|
94 | + } |
|
95 | 95 | } |