@@ -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 | } |
@@ -26,55 +26,55 @@ |
||
26 | 26 | */ |
27 | 27 | class AllEventsByTypeGeoAnalysis implements GeoAnalysisInterface |
28 | 28 | { |
29 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
29 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor for AllEventsByTypeGeoAnalysis |
|
33 | - * |
|
34 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
35 | - */ |
|
36 | - public function __construct(GeoAnalysisDataService $geoanalysis_data_service) |
|
37 | - { |
|
38 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
39 | - } |
|
31 | + /** |
|
32 | + * Constructor for AllEventsByTypeGeoAnalysis |
|
33 | + * |
|
34 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
35 | + */ |
|
36 | + public function __construct(GeoAnalysisDataService $geoanalysis_data_service) |
|
37 | + { |
|
38 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritDoc} |
|
43 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
44 | - */ |
|
45 | - public function title(): string |
|
46 | - { |
|
47 | - return I18N::translate('All events places'); |
|
48 | - } |
|
41 | + /** |
|
42 | + * {@inheritDoc} |
|
43 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
44 | + */ |
|
45 | + public function title(): string |
|
46 | + { |
|
47 | + return I18N::translate('All events places'); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
53 | - */ |
|
54 | - public function itemsDescription(): callable |
|
55 | - { |
|
56 | - return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
57 | - } |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
53 | + */ |
|
54 | + public function itemsDescription(): callable |
|
55 | + { |
|
56 | + return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
62 | - */ |
|
63 | - public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
64 | - { |
|
65 | - $results = new GeoAnalysisResults(); |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
62 | + */ |
|
63 | + public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
64 | + { |
|
65 | + $results = new GeoAnalysisResults(); |
|
66 | 66 | |
67 | - foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
68 | - foreach ($record->facts([]) as $fact) { |
|
69 | - $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
70 | - if ($place->isUnknown()) { |
|
71 | - continue; |
|
72 | - } |
|
73 | - $results->addPlace($place); |
|
74 | - $results->addPlaceInCategory($fact->label(), 0, $place); |
|
75 | - } |
|
76 | - } |
|
67 | + foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
68 | + foreach ($record->facts([]) as $fact) { |
|
69 | + $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
70 | + if ($place->isUnknown()) { |
|
71 | + continue; |
|
72 | + } |
|
73 | + $results->addPlace($place); |
|
74 | + $results->addPlaceInCategory($fact->label(), 0, $place); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - return $results; |
|
79 | - } |
|
78 | + return $results; |
|
79 | + } |
|
80 | 80 | } |
@@ -28,66 +28,66 @@ |
||
28 | 28 | */ |
29 | 29 | class AllEventsByCenturyGeoAnalysis implements GeoAnalysisInterface |
30 | 30 | { |
31 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
32 | - private CenturyService $century_service; |
|
31 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
32 | + private CenturyService $century_service; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Constructor for AllEventsByCenturyGeoAnalysis |
|
36 | - * |
|
37 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
38 | - * @param CenturyService $century_service |
|
39 | - */ |
|
40 | - public function __construct(GeoAnalysisDataService $geoanalysis_data_service, CenturyService $century_service) |
|
41 | - { |
|
42 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
43 | - $this->century_service = $century_service; |
|
44 | - } |
|
34 | + /** |
|
35 | + * Constructor for AllEventsByCenturyGeoAnalysis |
|
36 | + * |
|
37 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
38 | + * @param CenturyService $century_service |
|
39 | + */ |
|
40 | + public function __construct(GeoAnalysisDataService $geoanalysis_data_service, CenturyService $century_service) |
|
41 | + { |
|
42 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
43 | + $this->century_service = $century_service; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
49 | - */ |
|
50 | - public function title(): string |
|
51 | - { |
|
52 | - return I18N::translate('All events places'); |
|
53 | - } |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
49 | + */ |
|
50 | + public function title(): string |
|
51 | + { |
|
52 | + return I18N::translate('All events places'); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
58 | - */ |
|
59 | - public function itemsDescription(): callable |
|
60 | - { |
|
61 | - return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
62 | - } |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
58 | + */ |
|
59 | + public function itemsDescription(): callable |
|
60 | + { |
|
61 | + return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
67 | - */ |
|
68 | - public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
69 | - { |
|
70 | - $results = new GeoAnalysisResults(); |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
67 | + */ |
|
68 | + public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
69 | + { |
|
70 | + $results = new GeoAnalysisResults(); |
|
71 | 71 | |
72 | - foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
73 | - foreach ($record->facts([]) as $fact) { |
|
74 | - $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
75 | - if ($place->isUnknown()) { |
|
76 | - continue; |
|
77 | - } |
|
78 | - $results->addPlace($place); |
|
79 | - $date = $fact->date(); |
|
80 | - if ($date->isOK()) { |
|
81 | - $century = intdiv($date->gregorianYear(), 100); |
|
82 | - $results->addPlaceInCategory( |
|
83 | - I18N::translate('%s century', $this->century_service->centuryName($century)), |
|
84 | - $century, |
|
85 | - $place |
|
86 | - ); |
|
87 | - } |
|
88 | - } |
|
89 | - } |
|
72 | + foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
73 | + foreach ($record->facts([]) as $fact) { |
|
74 | + $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
75 | + if ($place->isUnknown()) { |
|
76 | + continue; |
|
77 | + } |
|
78 | + $results->addPlace($place); |
|
79 | + $date = $fact->date(); |
|
80 | + if ($date->isOK()) { |
|
81 | + $century = intdiv($date->gregorianYear(), 100); |
|
82 | + $results->addPlaceInCategory( |
|
83 | + I18N::translate('%s century', $this->century_service->centuryName($century)), |
|
84 | + $century, |
|
85 | + $place |
|
86 | + ); |
|
87 | + } |
|
88 | + } |
|
89 | + } |
|
90 | 90 | |
91 | - return $results; |
|
92 | - } |
|
91 | + return $results; |
|
92 | + } |
|
93 | 93 | } |
@@ -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 | } |
@@ -25,28 +25,28 @@ |
||
25 | 25 | */ |
26 | 26 | class GeoAnalysisDataService |
27 | 27 | { |
28 | - /** |
|
29 | - * Yields indviduals and family records for a specified tree. |
|
30 | - * |
|
31 | - * @param Tree $tree |
|
32 | - * @return \Generator<\Fisharebest\Webtrees\GedcomRecord> |
|
33 | - */ |
|
34 | - public function individualsAndFamilies(Tree $tree): Generator |
|
35 | - { |
|
36 | - yield from DB::table('individuals') |
|
37 | - ->where('i_file', '=', $tree->id()) |
|
38 | - ->select(['individuals.*']) |
|
39 | - ->get() |
|
40 | - ->map(Registry::individualFactory()->mapper($tree)) |
|
41 | - ->filter(GedcomRecord::accessFilter()) |
|
42 | - ->all(); |
|
28 | + /** |
|
29 | + * Yields indviduals and family records for a specified tree. |
|
30 | + * |
|
31 | + * @param Tree $tree |
|
32 | + * @return \Generator<\Fisharebest\Webtrees\GedcomRecord> |
|
33 | + */ |
|
34 | + public function individualsAndFamilies(Tree $tree): Generator |
|
35 | + { |
|
36 | + yield from DB::table('individuals') |
|
37 | + ->where('i_file', '=', $tree->id()) |
|
38 | + ->select(['individuals.*']) |
|
39 | + ->get() |
|
40 | + ->map(Registry::individualFactory()->mapper($tree)) |
|
41 | + ->filter(GedcomRecord::accessFilter()) |
|
42 | + ->all(); |
|
43 | 43 | |
44 | - yield from DB::table('families') |
|
45 | - ->where('f_file', '=', $tree->id()) |
|
46 | - ->select(['families.*']) |
|
47 | - ->get() |
|
48 | - ->map(Registry::familyFactory()->mapper($tree)) |
|
49 | - ->filter(GedcomRecord::accessFilter()) |
|
50 | - ->all(); |
|
51 | - } |
|
44 | + yield from DB::table('families') |
|
45 | + ->where('f_file', '=', $tree->id()) |
|
46 | + ->select(['families.*']) |
|
47 | + ->get() |
|
48 | + ->map(Registry::familyFactory()->mapper($tree)) |
|
49 | + ->filter(GedcomRecord::accessFilter()) |
|
50 | + ->all(); |
|
51 | + } |
|
52 | 52 | } |
@@ -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 | } |
@@ -36,203 +36,203 @@ |
||
36 | 36 | */ |
37 | 37 | class GeoAnalysisViewDataService |
38 | 38 | { |
39 | - private MapDefinitionsService $mapdefinition_service; |
|
40 | - |
|
41 | - /** |
|
42 | - * Constructor for GeoAnalysisViewDataService |
|
43 | - * |
|
44 | - * @param MapDefinitionsService $mapdefinition_service |
|
45 | - */ |
|
46 | - public function __construct(MapDefinitionsService $mapdefinition_service) |
|
47 | - { |
|
48 | - $this->mapdefinition_service = $mapdefinition_service; |
|
49 | - } |
|
50 | - |
|
51 | - /** |
|
52 | - * Find a Geographical dispersion analysis view by ID |
|
53 | - * |
|
54 | - * @param Tree $tree |
|
55 | - * @param int $id |
|
56 | - * @return AbstractGeoAnalysisView|NULL |
|
57 | - */ |
|
58 | - public function find(Tree $tree, int $id): ?AbstractGeoAnalysisView |
|
59 | - { |
|
60 | - return $this->all($tree)->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id); |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Get all Geographical dispersion analysis views, with or without the disabled ones. |
|
65 | - * |
|
66 | - * {@internal It would ignore any view for which the class could not be loaded by the container} |
|
67 | - * |
|
68 | - * @param Tree $tree |
|
69 | - * @param bool $include_disabled |
|
70 | - * @return Collection<AbstractGeoAnalysisView> |
|
71 | - */ |
|
72 | - public function all(Tree $tree, bool $include_disabled = false): Collection |
|
73 | - { |
|
74 | - return Registry::cache()->array()->remember( |
|
75 | - 'all-geodispersion-views', |
|
76 | - function () use ($tree, $include_disabled): Collection { |
|
77 | - return DB::table('maj_geodisp_views') |
|
78 | - ->select('maj_geodisp_views.*') |
|
79 | - ->where('majgv_gedcom_id', '=', $tree->id()) |
|
80 | - ->get() |
|
81 | - ->map($this->viewMapper($tree)) |
|
82 | - ->filter() |
|
83 | - ->filter($this->enabledFilter($include_disabled)); |
|
84 | - } |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
90 | - * |
|
91 | - * @param GeoAnalysisMap $map_view |
|
92 | - * @return Collection<GeoAnalysisMapAdapter> |
|
93 | - */ |
|
94 | - public function mapAdapters(GeoAnalysisMap $map_view): Collection |
|
95 | - { |
|
96 | - return DB::table('maj_geodisp_mapviews') |
|
97 | - ->select('maj_geodisp_mapviews.*') |
|
98 | - ->where('majgm_majgv_id', '=', $map_view->id()) |
|
99 | - ->get() |
|
100 | - ->map($this->mapAdapterMapper()) |
|
101 | - ->filter(); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Get the closure to create a AbstractGeoAnalysisView object from a row in the database. |
|
106 | - * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
107 | - * or if the types do not match with the ones expected. |
|
108 | - * |
|
109 | - * @param Tree $tree |
|
110 | - * @return Closure(\stdClass $row):?AbstractGeoAnalysisView |
|
111 | - */ |
|
112 | - private function viewMapper(Tree $tree): Closure |
|
113 | - { |
|
114 | - return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
115 | - try { |
|
116 | - $geoanalysis = app($row->majgv_analysis); |
|
117 | - if (!($geoanalysis instanceof GeoAnalysisInterface)) { |
|
118 | - return null; |
|
119 | - } |
|
120 | - |
|
121 | - $view = app()->makeWith($row->majgv_view_class, [ |
|
122 | - 'id' => (int) $row->majgv_id, |
|
123 | - 'tree' => $tree, |
|
124 | - 'enabled' => $row->majgv_status === 'enabled', |
|
125 | - 'description' => $row->majgv_descr, |
|
126 | - 'geoanalysis' => $geoanalysis, |
|
127 | - 'depth' => (int) $row->majgv_place_depth, |
|
128 | - 'detailed_top_places' => (int) $row->majgv_top_places |
|
129 | - ]); |
|
130 | - |
|
131 | - if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) { |
|
132 | - $view->setColors($this->colorsDecoder($row->majgv_colors)); |
|
133 | - } |
|
134 | - |
|
135 | - return $view instanceof AbstractGeoAnalysisView ? $view : null; |
|
136 | - } catch (BindingResolutionException $ex) { |
|
137 | - return null; |
|
138 | - } |
|
139 | - }; |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
144 | - * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
145 | - * or if the types do not match with the ones expected. |
|
146 | - * |
|
147 | - * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
148 | - */ |
|
149 | - private function mapAdapterMapper(): Closure |
|
150 | - { |
|
151 | - return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
152 | - if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
153 | - return null; |
|
154 | - } |
|
155 | - try { |
|
156 | - $mapper = app($row->majgm_mapper); |
|
157 | - if (!($mapper instanceof PlaceMapperInterface)) { |
|
158 | - return null; |
|
159 | - } |
|
160 | - |
|
161 | - return new GeoAnalysisMapAdapter( |
|
162 | - (int) $row->majgm_id, |
|
163 | - $map, |
|
164 | - app($row->majgm_mapper), |
|
165 | - new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
166 | - ); |
|
167 | - } catch (BindingResolutionException $ex) { |
|
168 | - return null; |
|
169 | - } |
|
170 | - }; |
|
171 | - } |
|
172 | - |
|
173 | - /** |
|
174 | - * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
175 | - * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
176 | - * through the Laravel container or if the type do not match with the one expected. |
|
177 | - * |
|
178 | - * @param string $json_config |
|
179 | - * @return PlaceMapperConfigInterface|NULL |
|
180 | - */ |
|
181 | - private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
182 | - { |
|
183 | - $config = $json_config === null ? [] : json_decode($json_config, true); |
|
184 | - $class = $config['class'] ?? null; |
|
185 | - $json_mapper_config = $config['config'] ?? null; |
|
186 | - if ($class === null || $json_mapper_config === null) { |
|
187 | - return null; |
|
188 | - } |
|
189 | - try { |
|
190 | - $mapper_config = app($class); |
|
191 | - if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
192 | - return null; |
|
193 | - } |
|
194 | - return $mapper_config->jsonDeserialize($json_mapper_config); |
|
195 | - } catch (BindingResolutionException $ex) { |
|
196 | - return null; |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Create a MapColorsConfig object from a JSON column value. |
|
202 | - * Returns null if the JSON string is invalid, or if the colors are not valid. |
|
203 | - * |
|
204 | - * @param string $colors_config |
|
205 | - * @return MapColorsConfig|NULL |
|
206 | - */ |
|
207 | - private function colorsDecoder(string $colors_config): ?MapColorsConfig |
|
208 | - { |
|
209 | - $colors = json_decode($colors_config, true); |
|
210 | - if (!is_array($colors) && count($colors) !== 4) { |
|
211 | - return null; |
|
212 | - } |
|
213 | - try { |
|
214 | - return new MapColorsConfig( |
|
215 | - \Spatie\Color\Factory::fromString($colors['default'] ?? ''), |
|
216 | - \Spatie\Color\Factory::fromString($colors['stroke'] ?? ''), |
|
217 | - \Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''), |
|
218 | - \Spatie\Color\Factory::fromString($colors['hover'] ?? '') |
|
219 | - ); |
|
220 | - } catch (InvalidColorValue $ex) { |
|
221 | - return null; |
|
222 | - } |
|
223 | - } |
|
224 | - |
|
225 | - /** |
|
226 | - * Get a closure to filter views by enabled/disabled status |
|
227 | - * |
|
228 | - * @param bool $include_disabled |
|
229 | - * |
|
230 | - * @return Closure(AbstractGeoAnalysisView $view):bool |
|
231 | - */ |
|
232 | - private function enabledFilter(bool $include_disabled): Closure |
|
233 | - { |
|
234 | - return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
235 | - return $include_disabled || $view->isEnabled(); |
|
236 | - }; |
|
237 | - } |
|
39 | + private MapDefinitionsService $mapdefinition_service; |
|
40 | + |
|
41 | + /** |
|
42 | + * Constructor for GeoAnalysisViewDataService |
|
43 | + * |
|
44 | + * @param MapDefinitionsService $mapdefinition_service |
|
45 | + */ |
|
46 | + public function __construct(MapDefinitionsService $mapdefinition_service) |
|
47 | + { |
|
48 | + $this->mapdefinition_service = $mapdefinition_service; |
|
49 | + } |
|
50 | + |
|
51 | + /** |
|
52 | + * Find a Geographical dispersion analysis view by ID |
|
53 | + * |
|
54 | + * @param Tree $tree |
|
55 | + * @param int $id |
|
56 | + * @return AbstractGeoAnalysisView|NULL |
|
57 | + */ |
|
58 | + public function find(Tree $tree, int $id): ?AbstractGeoAnalysisView |
|
59 | + { |
|
60 | + return $this->all($tree)->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id); |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Get all Geographical dispersion analysis views, with or without the disabled ones. |
|
65 | + * |
|
66 | + * {@internal It would ignore any view for which the class could not be loaded by the container} |
|
67 | + * |
|
68 | + * @param Tree $tree |
|
69 | + * @param bool $include_disabled |
|
70 | + * @return Collection<AbstractGeoAnalysisView> |
|
71 | + */ |
|
72 | + public function all(Tree $tree, bool $include_disabled = false): Collection |
|
73 | + { |
|
74 | + return Registry::cache()->array()->remember( |
|
75 | + 'all-geodispersion-views', |
|
76 | + function () use ($tree, $include_disabled): Collection { |
|
77 | + return DB::table('maj_geodisp_views') |
|
78 | + ->select('maj_geodisp_views.*') |
|
79 | + ->where('majgv_gedcom_id', '=', $tree->id()) |
|
80 | + ->get() |
|
81 | + ->map($this->viewMapper($tree)) |
|
82 | + ->filter() |
|
83 | + ->filter($this->enabledFilter($include_disabled)); |
|
84 | + } |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Get all GeoAnalysisMapAdapters linked to a Map View. |
|
90 | + * |
|
91 | + * @param GeoAnalysisMap $map_view |
|
92 | + * @return Collection<GeoAnalysisMapAdapter> |
|
93 | + */ |
|
94 | + public function mapAdapters(GeoAnalysisMap $map_view): Collection |
|
95 | + { |
|
96 | + return DB::table('maj_geodisp_mapviews') |
|
97 | + ->select('maj_geodisp_mapviews.*') |
|
98 | + ->where('majgm_majgv_id', '=', $map_view->id()) |
|
99 | + ->get() |
|
100 | + ->map($this->mapAdapterMapper()) |
|
101 | + ->filter(); |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Get the closure to create a AbstractGeoAnalysisView object from a row in the database. |
|
106 | + * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
107 | + * or if the types do not match with the ones expected. |
|
108 | + * |
|
109 | + * @param Tree $tree |
|
110 | + * @return Closure(\stdClass $row):?AbstractGeoAnalysisView |
|
111 | + */ |
|
112 | + private function viewMapper(Tree $tree): Closure |
|
113 | + { |
|
114 | + return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
115 | + try { |
|
116 | + $geoanalysis = app($row->majgv_analysis); |
|
117 | + if (!($geoanalysis instanceof GeoAnalysisInterface)) { |
|
118 | + return null; |
|
119 | + } |
|
120 | + |
|
121 | + $view = app()->makeWith($row->majgv_view_class, [ |
|
122 | + 'id' => (int) $row->majgv_id, |
|
123 | + 'tree' => $tree, |
|
124 | + 'enabled' => $row->majgv_status === 'enabled', |
|
125 | + 'description' => $row->majgv_descr, |
|
126 | + 'geoanalysis' => $geoanalysis, |
|
127 | + 'depth' => (int) $row->majgv_place_depth, |
|
128 | + 'detailed_top_places' => (int) $row->majgv_top_places |
|
129 | + ]); |
|
130 | + |
|
131 | + if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) { |
|
132 | + $view->setColors($this->colorsDecoder($row->majgv_colors)); |
|
133 | + } |
|
134 | + |
|
135 | + return $view instanceof AbstractGeoAnalysisView ? $view : null; |
|
136 | + } catch (BindingResolutionException $ex) { |
|
137 | + return null; |
|
138 | + } |
|
139 | + }; |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Get the closure to create a GeoAnalysisMapAdapter object from a row in the database. |
|
144 | + * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
145 | + * or if the types do not match with the ones expected. |
|
146 | + * |
|
147 | + * @return Closure(\stdClass $row):?GeoAnalysisMapAdapter |
|
148 | + */ |
|
149 | + private function mapAdapterMapper(): Closure |
|
150 | + { |
|
151 | + return function (stdClass $row): ?GeoAnalysisMapAdapter { |
|
152 | + if (null === $map = $this->mapdefinition_service->find($row->majgm_map_id)) { |
|
153 | + return null; |
|
154 | + } |
|
155 | + try { |
|
156 | + $mapper = app($row->majgm_mapper); |
|
157 | + if (!($mapper instanceof PlaceMapperInterface)) { |
|
158 | + return null; |
|
159 | + } |
|
160 | + |
|
161 | + return new GeoAnalysisMapAdapter( |
|
162 | + (int) $row->majgm_id, |
|
163 | + $map, |
|
164 | + app($row->majgm_mapper), |
|
165 | + new MapViewConfig($row->majgm_feature_prop, $this->mapperConfigDecoder($row->majgm_config)) |
|
166 | + ); |
|
167 | + } catch (BindingResolutionException $ex) { |
|
168 | + return null; |
|
169 | + } |
|
170 | + }; |
|
171 | + } |
|
172 | + |
|
173 | + /** |
|
174 | + * Create a PlaceMapperConfigInterface object from a JSON column value. |
|
175 | + * Returns null if the JSON string is invalid/empty or if the extracted mapper class cannot be loaded |
|
176 | + * through the Laravel container or if the type do not match with the one expected. |
|
177 | + * |
|
178 | + * @param string $json_config |
|
179 | + * @return PlaceMapperConfigInterface|NULL |
|
180 | + */ |
|
181 | + private function mapperConfigDecoder(?string $json_config): ?PlaceMapperConfigInterface |
|
182 | + { |
|
183 | + $config = $json_config === null ? [] : json_decode($json_config, true); |
|
184 | + $class = $config['class'] ?? null; |
|
185 | + $json_mapper_config = $config['config'] ?? null; |
|
186 | + if ($class === null || $json_mapper_config === null) { |
|
187 | + return null; |
|
188 | + } |
|
189 | + try { |
|
190 | + $mapper_config = app($class); |
|
191 | + if (!$mapper_config instanceof PlaceMapperConfigInterface) { |
|
192 | + return null; |
|
193 | + } |
|
194 | + return $mapper_config->jsonDeserialize($json_mapper_config); |
|
195 | + } catch (BindingResolutionException $ex) { |
|
196 | + return null; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Create a MapColorsConfig object from a JSON column value. |
|
202 | + * Returns null if the JSON string is invalid, or if the colors are not valid. |
|
203 | + * |
|
204 | + * @param string $colors_config |
|
205 | + * @return MapColorsConfig|NULL |
|
206 | + */ |
|
207 | + private function colorsDecoder(string $colors_config): ?MapColorsConfig |
|
208 | + { |
|
209 | + $colors = json_decode($colors_config, true); |
|
210 | + if (!is_array($colors) && count($colors) !== 4) { |
|
211 | + return null; |
|
212 | + } |
|
213 | + try { |
|
214 | + return new MapColorsConfig( |
|
215 | + \Spatie\Color\Factory::fromString($colors['default'] ?? ''), |
|
216 | + \Spatie\Color\Factory::fromString($colors['stroke'] ?? ''), |
|
217 | + \Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''), |
|
218 | + \Spatie\Color\Factory::fromString($colors['hover'] ?? '') |
|
219 | + ); |
|
220 | + } catch (InvalidColorValue $ex) { |
|
221 | + return null; |
|
222 | + } |
|
223 | + } |
|
224 | + |
|
225 | + /** |
|
226 | + * Get a closure to filter views by enabled/disabled status |
|
227 | + * |
|
228 | + * @param bool $include_disabled |
|
229 | + * |
|
230 | + * @return Closure(AbstractGeoAnalysisView $view):bool |
|
231 | + */ |
|
232 | + private function enabledFilter(bool $include_disabled): Closure |
|
233 | + { |
|
234 | + return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
235 | + return $include_disabled || $view->isEnabled(); |
|
236 | + }; |
|
237 | + } |
|
238 | 238 | } |