@@ -24,143 +24,143 @@ |
||
24 | 24 | */ |
25 | 25 | class SosaCalculatorService |
26 | 26 | { |
27 | - /** |
|
28 | - * Maximium size for the temporary Sosa table |
|
29 | - * @var int TMP_SOSA_TABLE_LIMIT |
|
30 | - */ |
|
31 | - private const TMP_SOSA_TABLE_LIMIT = 1000; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var SosaRecordsService $sosa_records_service |
|
35 | - */ |
|
36 | - private $sosa_records_service; |
|
37 | - |
|
38 | - /** |
|
39 | - * Reference user |
|
40 | - * @var UserInterface $user |
|
41 | - */ |
|
42 | - private $user; |
|
43 | - |
|
44 | - /** |
|
45 | - * Reference tree |
|
46 | - * @var Tree $tree |
|
47 | - */ |
|
48 | - private $tree; |
|
49 | - |
|
50 | - /** |
|
51 | - * Temporary Sosa table, used during construction |
|
52 | - * @var array<array<string,mixed>> $tmp_sosa_table |
|
53 | - */ |
|
54 | - private $tmp_sosa_table; |
|
55 | - |
|
56 | - /** |
|
57 | - * Maximum number of generations to calculate |
|
58 | - * @var int $max_generations |
|
59 | - */ |
|
60 | - private $max_generations; |
|
61 | - |
|
62 | - /** |
|
63 | - * Constructor for the Sosa Calculator |
|
64 | - * |
|
65 | - * @param SosaRecordsService $sosa_records_service |
|
66 | - * @param Tree $tree |
|
67 | - * @param UserInterface $user |
|
68 | - */ |
|
69 | - public function __construct(SosaRecordsService $sosa_records_service, Tree $tree, UserInterface $user) |
|
70 | - { |
|
71 | - $this->sosa_records_service = $sosa_records_service; |
|
72 | - $this->tree = $tree; |
|
73 | - $this->user = $user; |
|
74 | - $this->tmp_sosa_table = array(); |
|
75 | - $max_gen_setting = $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN'); |
|
76 | - $this->max_generations = is_numeric($max_gen_setting) ? |
|
77 | - (int) $max_gen_setting : |
|
78 | - $this->sosa_records_service->maxSystemGenerations(); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Compute all Sosa ancestors from the user's root individual. |
|
83 | - * |
|
84 | - * @return bool Result of the computation |
|
85 | - */ |
|
86 | - public function computeAll(): bool |
|
87 | - { |
|
88 | - $root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
89 | - if (($indi = Registry::individualFactory()->make($root_id, $this->tree)) !== null) { |
|
90 | - $this->sosa_records_service->deleteAll($this->tree, $this->user); |
|
91 | - $this->addNode($indi, 1); |
|
92 | - $this->flushTmpSosaTable(true); |
|
93 | - return true; |
|
94 | - } |
|
95 | - return false; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Compute all Sosa Ancestors from a specified Individual |
|
100 | - * |
|
101 | - * @param Individual $indi |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function computeFromIndividual(Individual $indi): bool |
|
105 | - { |
|
106 | - $current_sosas = $this->sosa_records_service->sosaNumbers($this->tree, $this->user, $indi); |
|
107 | - foreach ($current_sosas->keys() as $sosa) { |
|
108 | - $this->sosa_records_service->deleteAncestorsFrom($this->tree, $this->user, $sosa); |
|
109 | - $this->addNode($indi, $sosa); |
|
110 | - } |
|
111 | - $this->flushTmpSosaTable(true); |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Recursive method to add individual to the Sosa table, and flush it regularly |
|
117 | - * |
|
118 | - * @param Individual $indi Individual to add |
|
119 | - * @param int $sosa Individual's sosa |
|
120 | - */ |
|
121 | - private function addNode(Individual $indi, int $sosa): void |
|
122 | - { |
|
123 | - $birth_year = $indi->getBirthDate()->gregorianYear(); |
|
124 | - $birth_year_est = $birth_year === 0 ? $indi->getEstimatedBirthDate()->gregorianYear() : $birth_year; |
|
125 | - |
|
126 | - $death_year = $indi->getDeathDate()->gregorianYear(); |
|
127 | - $death_year_est = $death_year === 0 ? $indi->getEstimatedDeathDate()->gregorianYear() : $death_year; |
|
128 | - |
|
129 | - $this->tmp_sosa_table[] = [ |
|
130 | - 'indi' => $indi->xref(), |
|
131 | - 'sosa' => $sosa, |
|
132 | - 'birth_year' => $birth_year === 0 ? null : $birth_year, |
|
133 | - 'birth_year_est' => $birth_year_est === 0 ? null : $birth_year_est, |
|
134 | - 'death_year' => $death_year === 0 ? null : $death_year, |
|
135 | - 'death_year_est' => $death_year_est === 0 ? null : $death_year_est |
|
136 | - ]; |
|
137 | - |
|
138 | - $this->flushTmpSosaTable(); |
|
139 | - |
|
140 | - if ( |
|
141 | - ($fam = $indi->childFamilies()->first()) !== null |
|
142 | - && $this->sosa_records_service->generation($sosa) < $this->max_generations |
|
143 | - ) { |
|
144 | - /** @var \Fisharebest\Webtrees\Family $fam */ |
|
145 | - if (($husb = $fam->husband()) !== null) { |
|
146 | - $this->addNode($husb, 2 * $sosa); |
|
147 | - } |
|
148 | - if (($wife = $fam->wife()) !== null) { |
|
149 | - $this->addNode($wife, 2 * $sosa + 1); |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Write sosas in the table, if the number of items is superior to the limit, or if forced. |
|
156 | - * |
|
157 | - * @param bool $force Should the flush be forced |
|
158 | - */ |
|
159 | - private function flushTmpSosaTable($force = false): void |
|
160 | - { |
|
161 | - if ($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT) { |
|
162 | - $this->sosa_records_service->insertOrUpdate($this->tree, $this->user, $this->tmp_sosa_table); |
|
163 | - $this->tmp_sosa_table = array(); |
|
164 | - } |
|
165 | - } |
|
27 | + /** |
|
28 | + * Maximium size for the temporary Sosa table |
|
29 | + * @var int TMP_SOSA_TABLE_LIMIT |
|
30 | + */ |
|
31 | + private const TMP_SOSA_TABLE_LIMIT = 1000; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var SosaRecordsService $sosa_records_service |
|
35 | + */ |
|
36 | + private $sosa_records_service; |
|
37 | + |
|
38 | + /** |
|
39 | + * Reference user |
|
40 | + * @var UserInterface $user |
|
41 | + */ |
|
42 | + private $user; |
|
43 | + |
|
44 | + /** |
|
45 | + * Reference tree |
|
46 | + * @var Tree $tree |
|
47 | + */ |
|
48 | + private $tree; |
|
49 | + |
|
50 | + /** |
|
51 | + * Temporary Sosa table, used during construction |
|
52 | + * @var array<array<string,mixed>> $tmp_sosa_table |
|
53 | + */ |
|
54 | + private $tmp_sosa_table; |
|
55 | + |
|
56 | + /** |
|
57 | + * Maximum number of generations to calculate |
|
58 | + * @var int $max_generations |
|
59 | + */ |
|
60 | + private $max_generations; |
|
61 | + |
|
62 | + /** |
|
63 | + * Constructor for the Sosa Calculator |
|
64 | + * |
|
65 | + * @param SosaRecordsService $sosa_records_service |
|
66 | + * @param Tree $tree |
|
67 | + * @param UserInterface $user |
|
68 | + */ |
|
69 | + public function __construct(SosaRecordsService $sosa_records_service, Tree $tree, UserInterface $user) |
|
70 | + { |
|
71 | + $this->sosa_records_service = $sosa_records_service; |
|
72 | + $this->tree = $tree; |
|
73 | + $this->user = $user; |
|
74 | + $this->tmp_sosa_table = array(); |
|
75 | + $max_gen_setting = $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN'); |
|
76 | + $this->max_generations = is_numeric($max_gen_setting) ? |
|
77 | + (int) $max_gen_setting : |
|
78 | + $this->sosa_records_service->maxSystemGenerations(); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Compute all Sosa ancestors from the user's root individual. |
|
83 | + * |
|
84 | + * @return bool Result of the computation |
|
85 | + */ |
|
86 | + public function computeAll(): bool |
|
87 | + { |
|
88 | + $root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
89 | + if (($indi = Registry::individualFactory()->make($root_id, $this->tree)) !== null) { |
|
90 | + $this->sosa_records_service->deleteAll($this->tree, $this->user); |
|
91 | + $this->addNode($indi, 1); |
|
92 | + $this->flushTmpSosaTable(true); |
|
93 | + return true; |
|
94 | + } |
|
95 | + return false; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Compute all Sosa Ancestors from a specified Individual |
|
100 | + * |
|
101 | + * @param Individual $indi |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function computeFromIndividual(Individual $indi): bool |
|
105 | + { |
|
106 | + $current_sosas = $this->sosa_records_service->sosaNumbers($this->tree, $this->user, $indi); |
|
107 | + foreach ($current_sosas->keys() as $sosa) { |
|
108 | + $this->sosa_records_service->deleteAncestorsFrom($this->tree, $this->user, $sosa); |
|
109 | + $this->addNode($indi, $sosa); |
|
110 | + } |
|
111 | + $this->flushTmpSosaTable(true); |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Recursive method to add individual to the Sosa table, and flush it regularly |
|
117 | + * |
|
118 | + * @param Individual $indi Individual to add |
|
119 | + * @param int $sosa Individual's sosa |
|
120 | + */ |
|
121 | + private function addNode(Individual $indi, int $sosa): void |
|
122 | + { |
|
123 | + $birth_year = $indi->getBirthDate()->gregorianYear(); |
|
124 | + $birth_year_est = $birth_year === 0 ? $indi->getEstimatedBirthDate()->gregorianYear() : $birth_year; |
|
125 | + |
|
126 | + $death_year = $indi->getDeathDate()->gregorianYear(); |
|
127 | + $death_year_est = $death_year === 0 ? $indi->getEstimatedDeathDate()->gregorianYear() : $death_year; |
|
128 | + |
|
129 | + $this->tmp_sosa_table[] = [ |
|
130 | + 'indi' => $indi->xref(), |
|
131 | + 'sosa' => $sosa, |
|
132 | + 'birth_year' => $birth_year === 0 ? null : $birth_year, |
|
133 | + 'birth_year_est' => $birth_year_est === 0 ? null : $birth_year_est, |
|
134 | + 'death_year' => $death_year === 0 ? null : $death_year, |
|
135 | + 'death_year_est' => $death_year_est === 0 ? null : $death_year_est |
|
136 | + ]; |
|
137 | + |
|
138 | + $this->flushTmpSosaTable(); |
|
139 | + |
|
140 | + if ( |
|
141 | + ($fam = $indi->childFamilies()->first()) !== null |
|
142 | + && $this->sosa_records_service->generation($sosa) < $this->max_generations |
|
143 | + ) { |
|
144 | + /** @var \Fisharebest\Webtrees\Family $fam */ |
|
145 | + if (($husb = $fam->husband()) !== null) { |
|
146 | + $this->addNode($husb, 2 * $sosa); |
|
147 | + } |
|
148 | + if (($wife = $fam->wife()) !== null) { |
|
149 | + $this->addNode($wife, 2 * $sosa + 1); |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Write sosas in the table, if the number of items is superior to the limit, or if forced. |
|
156 | + * |
|
157 | + * @param bool $force Should the flush be forced |
|
158 | + */ |
|
159 | + private function flushTmpSosaTable($force = false): void |
|
160 | + { |
|
161 | + if ($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT) { |
|
162 | + $this->sosa_records_service->insertOrUpdate($this->tree, $this->user, $this->tmp_sosa_table); |
|
163 | + $this->tmp_sosa_table = array(); |
|
164 | + } |
|
165 | + } |
|
166 | 166 | } |
@@ -74,8 +74,7 @@ |
||
74 | 74 | $this->tmp_sosa_table = array(); |
75 | 75 | $max_gen_setting = $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN'); |
76 | 76 | $this->max_generations = is_numeric($max_gen_setting) ? |
77 | - (int) $max_gen_setting : |
|
78 | - $this->sosa_records_service->maxSystemGenerations(); |
|
77 | + (int)$max_gen_setting : $this->sosa_records_service->maxSystemGenerations(); |
|
79 | 78 | } |
80 | 79 | |
81 | 80 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | // How to update the database schema for this module |
77 | 77 | private const SCHEMA_TARGET_VERSION = 3; |
78 | 78 | private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
79 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
79 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema'; |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * {@inheritDoc} |
@@ -126,13 +126,13 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public function loadRoutes(Map $router): void |
128 | 128 | { |
129 | - $router->attach('', '', static function (Map $router): void { |
|
129 | + $router->attach('', '', static function(Map $router): void { |
|
130 | 130 | |
131 | - $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
132 | - $router->attach('', '/admin', static function (Map $router): void { |
|
131 | + $router->attach('', '/module-maj/geodispersion', static function(Map $router): void { |
|
132 | + $router->attach('', '/admin', static function(Map $router): void { |
|
133 | 133 | $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
134 | 134 | |
135 | - $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
135 | + $router->attach('', '/analysis-views/{tree}', static function(Map $router): void { |
|
136 | 136 | $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
137 | 137 | $router->extras([ |
138 | 138 | 'middleware' => [ |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | //phpcs:enable |
152 | 152 | }); |
153 | 153 | |
154 | - $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
154 | + $router->attach('', '/map-adapters/{tree}', static function(Map $router): void { |
|
155 | 155 | $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
156 | 156 | $router->extras([ |
157 | 157 | 'middleware' => [ |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | |
177 | 177 | $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
178 | 178 | |
179 | - $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
179 | + $router->attach('', '/analysisview/{tree}/{view_id}', static function(Map $router): void { |
|
180 | 180 | $router->tokens(['view_id' => '\d+']); |
181 | 181 | $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
182 | 182 | $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | */ |
215 | 215 | public function headContent(): string |
216 | 216 | { |
217 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
217 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | /** |
@@ -59,188 +59,188 @@ |
||
59 | 59 | * Geographical Dispersion Module. |
60 | 60 | */ |
61 | 61 | class GeoDispersionModule extends AbstractModule implements |
62 | - ModuleMyArtJaubInterface, |
|
63 | - ModuleChartInterface, |
|
64 | - ModuleConfigInterface, |
|
65 | - ModuleGlobalInterface, |
|
66 | - ModuleGeoAnalysisProviderInterface, |
|
67 | - ModulePlaceMapperProviderInterface |
|
62 | + ModuleMyArtJaubInterface, |
|
63 | + ModuleChartInterface, |
|
64 | + ModuleConfigInterface, |
|
65 | + ModuleGlobalInterface, |
|
66 | + ModuleGeoAnalysisProviderInterface, |
|
67 | + ModulePlaceMapperProviderInterface |
|
68 | 68 | { |
69 | - use ModuleMyArtJaubTrait { |
|
70 | - boot as traitBoot; |
|
71 | - } |
|
72 | - use ModuleChartTrait; |
|
73 | - use ModuleConfigTrait; |
|
74 | - use ModuleGlobalTrait; |
|
75 | - |
|
76 | - // How to update the database schema for this module |
|
77 | - private const SCHEMA_TARGET_VERSION = 3; |
|
78 | - private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
|
79 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
80 | - |
|
81 | - /** |
|
82 | - * {@inheritDoc} |
|
83 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
84 | - */ |
|
85 | - public function title(): string |
|
86 | - { |
|
87 | - return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion'); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * {@inheritDoc} |
|
92 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
93 | - */ |
|
94 | - public function description(): string |
|
95 | - { |
|
96 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
97 | - return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.'); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * {@inheritDoc} |
|
102 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
103 | - */ |
|
104 | - public function boot(): void |
|
105 | - { |
|
106 | - $this->traitBoot(); |
|
107 | - app(MigrationService::class)->updateSchema( |
|
108 | - self::SCHEMA_MIGRATION_PREFIX, |
|
109 | - self::SCHEMA_SETTING_NAME, |
|
110 | - self::SCHEMA_TARGET_VERSION |
|
111 | - ); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * {@inheritDoc} |
|
116 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
117 | - */ |
|
118 | - public function customModuleVersion(): string |
|
119 | - { |
|
120 | - return '2.1.1-v.1'; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * {@inheritDoc} |
|
125 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
126 | - */ |
|
127 | - public function loadRoutes(Map $router): void |
|
128 | - { |
|
129 | - $router->attach('', '', static function (Map $router): void { |
|
130 | - |
|
131 | - $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
132 | - $router->attach('', '/admin', static function (Map $router): void { |
|
133 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
134 | - |
|
135 | - $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
136 | - $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
|
137 | - $router->extras([ |
|
138 | - 'middleware' => [ |
|
139 | - AuthManager::class, |
|
140 | - ], |
|
141 | - ]); |
|
142 | - $router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class); |
|
143 | - |
|
144 | - $router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class); |
|
145 | - $router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class); |
|
146 | - $router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class); |
|
147 | - $router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class); |
|
148 | - //phpcs:disable Generic.Files.LineLength.TooLong |
|
149 | - $router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class); |
|
150 | - $router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class); |
|
151 | - //phpcs:enable |
|
152 | - }); |
|
153 | - |
|
154 | - $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
155 | - $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
|
156 | - $router->extras([ |
|
157 | - 'middleware' => [ |
|
158 | - AuthManager::class, |
|
159 | - ], |
|
160 | - ]); |
|
161 | - |
|
162 | - $router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class); |
|
163 | - $router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class); |
|
164 | - $router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class); |
|
165 | - $router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class); |
|
166 | - //phpcs:disable Generic.Files.LineLength.TooLong |
|
167 | - $router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class); |
|
168 | - $router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class); |
|
169 | - $router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class); |
|
170 | - //phpcs:enable |
|
171 | - }); |
|
172 | - |
|
173 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
174 | - $router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class); |
|
175 | - }); |
|
176 | - |
|
177 | - $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
|
178 | - |
|
179 | - $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
180 | - $router->tokens(['view_id' => '\d+']); |
|
181 | - $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
|
182 | - $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
|
183 | - }); |
|
184 | - }); |
|
185 | - }); |
|
186 | - } |
|
187 | - |
|
188 | - public function getConfigLink(): string |
|
189 | - { |
|
190 | - return route(AdminConfigPage::class); |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * {@inheritDoc} |
|
195 | - * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl() |
|
196 | - * |
|
197 | - * @param array<bool|int|string|array<mixed>|null> $parameters |
|
198 | - */ |
|
199 | - public function chartUrl(Individual $individual, array $parameters = []): string |
|
200 | - { |
|
201 | - return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * {@inheritDoc} |
|
206 | - * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass() |
|
207 | - */ |
|
208 | - public function chartMenuClass(): string |
|
209 | - { |
|
210 | - return 'menu-maj-geodispersion'; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * {@inheritDoc} |
|
215 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
216 | - */ |
|
217 | - public function headContent(): string |
|
218 | - { |
|
219 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * {@inheritDoc} |
|
224 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers() |
|
225 | - */ |
|
226 | - public function listPlaceMappers(): array |
|
227 | - { |
|
228 | - return [ |
|
229 | - CoordinatesPlaceMapper::class, |
|
230 | - SimplePlaceMapper::class, |
|
231 | - SimpleTopFilteredPlaceMapper::class |
|
232 | - ]; |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * {@inheritDoc} |
|
237 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
238 | - */ |
|
239 | - public function listGeoAnalyses(): array |
|
240 | - { |
|
241 | - return [ |
|
242 | - AllEventsByCenturyGeoAnalysis::class, |
|
243 | - AllEventsByTypeGeoAnalysis::class |
|
244 | - ]; |
|
245 | - } |
|
69 | + use ModuleMyArtJaubTrait { |
|
70 | + boot as traitBoot; |
|
71 | + } |
|
72 | + use ModuleChartTrait; |
|
73 | + use ModuleConfigTrait; |
|
74 | + use ModuleGlobalTrait; |
|
75 | + |
|
76 | + // How to update the database schema for this module |
|
77 | + private const SCHEMA_TARGET_VERSION = 3; |
|
78 | + private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
|
79 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
80 | + |
|
81 | + /** |
|
82 | + * {@inheritDoc} |
|
83 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
84 | + */ |
|
85 | + public function title(): string |
|
86 | + { |
|
87 | + return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion'); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * {@inheritDoc} |
|
92 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
93 | + */ |
|
94 | + public function description(): string |
|
95 | + { |
|
96 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
97 | + return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.'); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * {@inheritDoc} |
|
102 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
103 | + */ |
|
104 | + public function boot(): void |
|
105 | + { |
|
106 | + $this->traitBoot(); |
|
107 | + app(MigrationService::class)->updateSchema( |
|
108 | + self::SCHEMA_MIGRATION_PREFIX, |
|
109 | + self::SCHEMA_SETTING_NAME, |
|
110 | + self::SCHEMA_TARGET_VERSION |
|
111 | + ); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * {@inheritDoc} |
|
116 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
117 | + */ |
|
118 | + public function customModuleVersion(): string |
|
119 | + { |
|
120 | + return '2.1.1-v.1'; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * {@inheritDoc} |
|
125 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
126 | + */ |
|
127 | + public function loadRoutes(Map $router): void |
|
128 | + { |
|
129 | + $router->attach('', '', static function (Map $router): void { |
|
130 | + |
|
131 | + $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
132 | + $router->attach('', '/admin', static function (Map $router): void { |
|
133 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
134 | + |
|
135 | + $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
136 | + $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
|
137 | + $router->extras([ |
|
138 | + 'middleware' => [ |
|
139 | + AuthManager::class, |
|
140 | + ], |
|
141 | + ]); |
|
142 | + $router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class); |
|
143 | + |
|
144 | + $router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class); |
|
145 | + $router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class); |
|
146 | + $router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class); |
|
147 | + $router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class); |
|
148 | + //phpcs:disable Generic.Files.LineLength.TooLong |
|
149 | + $router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class); |
|
150 | + $router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class); |
|
151 | + //phpcs:enable |
|
152 | + }); |
|
153 | + |
|
154 | + $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
155 | + $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
|
156 | + $router->extras([ |
|
157 | + 'middleware' => [ |
|
158 | + AuthManager::class, |
|
159 | + ], |
|
160 | + ]); |
|
161 | + |
|
162 | + $router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class); |
|
163 | + $router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class); |
|
164 | + $router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class); |
|
165 | + $router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class); |
|
166 | + //phpcs:disable Generic.Files.LineLength.TooLong |
|
167 | + $router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class); |
|
168 | + $router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class); |
|
169 | + $router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class); |
|
170 | + //phpcs:enable |
|
171 | + }); |
|
172 | + |
|
173 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
174 | + $router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class); |
|
175 | + }); |
|
176 | + |
|
177 | + $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
|
178 | + |
|
179 | + $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
180 | + $router->tokens(['view_id' => '\d+']); |
|
181 | + $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
|
182 | + $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
|
183 | + }); |
|
184 | + }); |
|
185 | + }); |
|
186 | + } |
|
187 | + |
|
188 | + public function getConfigLink(): string |
|
189 | + { |
|
190 | + return route(AdminConfigPage::class); |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * {@inheritDoc} |
|
195 | + * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl() |
|
196 | + * |
|
197 | + * @param array<bool|int|string|array<mixed>|null> $parameters |
|
198 | + */ |
|
199 | + public function chartUrl(Individual $individual, array $parameters = []): string |
|
200 | + { |
|
201 | + return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * {@inheritDoc} |
|
206 | + * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass() |
|
207 | + */ |
|
208 | + public function chartMenuClass(): string |
|
209 | + { |
|
210 | + return 'menu-maj-geodispersion'; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * {@inheritDoc} |
|
215 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
216 | + */ |
|
217 | + public function headContent(): string |
|
218 | + { |
|
219 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * {@inheritDoc} |
|
224 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers() |
|
225 | + */ |
|
226 | + public function listPlaceMappers(): array |
|
227 | + { |
|
228 | + return [ |
|
229 | + CoordinatesPlaceMapper::class, |
|
230 | + SimplePlaceMapper::class, |
|
231 | + SimpleTopFilteredPlaceMapper::class |
|
232 | + ]; |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * {@inheritDoc} |
|
237 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
238 | + */ |
|
239 | + public function listGeoAnalyses(): array |
|
240 | + { |
|
241 | + return [ |
|
242 | + AllEventsByCenturyGeoAnalysis::class, |
|
243 | + AllEventsByTypeGeoAnalysis::class |
|
244 | + ]; |
|
245 | + } |
|
246 | 246 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | ->all($tree) |
68 | 68 | ->sortBy(fn(AbstractGeoAnalysisView $view) => $view->description()); |
69 | 69 | |
70 | - return $this->viewResponse($this->module->name() . '::geoanalysisviews-list', [ |
|
70 | + return $this->viewResponse($this->module->name().'::geoanalysisviews-list', [ |
|
71 | 71 | 'module' => $this->module, |
72 | 72 | 'title' => I18N::translate('Geographical dispersion'), |
73 | 73 | 'tree' => $tree, |
@@ -33,46 +33,46 @@ |
||
33 | 33 | */ |
34 | 34 | class GeoAnalysisViewsList implements RequestHandlerInterface |
35 | 35 | { |
36 | - use ViewResponseTrait; |
|
36 | + use ViewResponseTrait; |
|
37 | 37 | |
38 | - private ?GeoDispersionModule $module; |
|
39 | - private GeoAnalysisViewDataService $geoviewdata_service; |
|
38 | + private ?GeoDispersionModule $module; |
|
39 | + private GeoAnalysisViewDataService $geoviewdata_service; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor for GeoAnalysisViewsList Request Handler |
|
43 | - * |
|
44 | - * @param ModuleService $module_service |
|
45 | - */ |
|
46 | - public function __construct( |
|
47 | - ModuleService $module_service, |
|
48 | - GeoAnalysisViewDataService $geoviewdata_service |
|
49 | - ) { |
|
50 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
51 | - $this->geoviewdata_service = $geoviewdata_service; |
|
52 | - } |
|
41 | + /** |
|
42 | + * Constructor for GeoAnalysisViewsList Request Handler |
|
43 | + * |
|
44 | + * @param ModuleService $module_service |
|
45 | + */ |
|
46 | + public function __construct( |
|
47 | + ModuleService $module_service, |
|
48 | + GeoAnalysisViewDataService $geoviewdata_service |
|
49 | + ) { |
|
50 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
51 | + $this->geoviewdata_service = $geoviewdata_service; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
57 | - */ |
|
58 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
59 | - { |
|
60 | - if ($this->module === null) { |
|
61 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
62 | - } |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
57 | + */ |
|
58 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
59 | + { |
|
60 | + if ($this->module === null) { |
|
61 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
62 | + } |
|
63 | 63 | |
64 | - $tree = Validator::attributes($request)->tree(); |
|
64 | + $tree = Validator::attributes($request)->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 | } |
@@ -87,7 +87,7 @@ |
||
87 | 87 | throw new HttpAccessDeniedException(); |
88 | 88 | } |
89 | 89 | |
90 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
90 | + return $this->viewResponse($this->module->name().'::admin/config', [ |
|
91 | 91 | 'module_name' => $this->module->name(), |
92 | 92 | 'title' => $this->module->title(), |
93 | 93 | 'tree' => $tree, |
@@ -35,64 +35,64 @@ |
||
35 | 35 | */ |
36 | 36 | class AdminConfigPage implements RequestHandlerInterface |
37 | 37 | { |
38 | - use ViewResponseTrait; |
|
39 | - |
|
40 | - private ?GeoDispersionModule $module; |
|
41 | - |
|
42 | - private TreeService $tree_service; |
|
43 | - |
|
44 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
45 | - |
|
46 | - /** |
|
47 | - * Constructor for the AdminConfigPage Request Handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - * @param TreeService $tree_service |
|
51 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
52 | - */ |
|
53 | - public function __construct( |
|
54 | - ModuleService $module_service, |
|
55 | - TreeService $tree_service, |
|
56 | - GeoAnalysisDataService $geoanalysis_data_service |
|
57 | - ) { |
|
58 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
59 | - $this->tree_service = $tree_service; |
|
60 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * {@inheritDoc} |
|
65 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
66 | - */ |
|
67 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
68 | - { |
|
69 | - $this->layout = 'layouts/administration'; |
|
70 | - |
|
71 | - if ($this->module === null) { |
|
72 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
73 | - } |
|
74 | - |
|
75 | - $user = Validator::attributes($request)->user(); |
|
76 | - |
|
77 | - $all_trees = $this->tree_service->all()->filter(fn(Tree $tree) => Auth::isManager($tree, $user)); |
|
78 | - if ($all_trees->count() === 0) { |
|
79 | - throw new HttpAccessDeniedException(); |
|
80 | - } |
|
81 | - |
|
82 | - $tree = Validator::attributes($request)->treeOptional() ?? $all_trees->first(); |
|
83 | - |
|
84 | - $same_tree = fn(Tree $tree_collection): bool => $tree->id() === $tree_collection->id(); |
|
85 | - if (!$all_trees->contains($same_tree)) { |
|
86 | - throw new HttpAccessDeniedException(); |
|
87 | - } |
|
88 | - |
|
89 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
90 | - 'module_name' => $this->module->name(), |
|
91 | - 'title' => $this->module->title(), |
|
92 | - 'tree' => $tree, |
|
93 | - 'other_trees' => $all_trees->reject($same_tree), |
|
94 | - 'place_example' => $this->geoanalysis_data_service->placeHierarchyExample($tree), |
|
95 | - 'js_script_url' => $this->module->assetUrl('js/geodispersion.min.js') |
|
96 | - ]); |
|
97 | - } |
|
38 | + use ViewResponseTrait; |
|
39 | + |
|
40 | + private ?GeoDispersionModule $module; |
|
41 | + |
|
42 | + private TreeService $tree_service; |
|
43 | + |
|
44 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
45 | + |
|
46 | + /** |
|
47 | + * Constructor for the AdminConfigPage Request Handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + * @param TreeService $tree_service |
|
51 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
52 | + */ |
|
53 | + public function __construct( |
|
54 | + ModuleService $module_service, |
|
55 | + TreeService $tree_service, |
|
56 | + GeoAnalysisDataService $geoanalysis_data_service |
|
57 | + ) { |
|
58 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
59 | + $this->tree_service = $tree_service; |
|
60 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * {@inheritDoc} |
|
65 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
66 | + */ |
|
67 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
68 | + { |
|
69 | + $this->layout = 'layouts/administration'; |
|
70 | + |
|
71 | + if ($this->module === null) { |
|
72 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
73 | + } |
|
74 | + |
|
75 | + $user = Validator::attributes($request)->user(); |
|
76 | + |
|
77 | + $all_trees = $this->tree_service->all()->filter(fn(Tree $tree) => Auth::isManager($tree, $user)); |
|
78 | + if ($all_trees->count() === 0) { |
|
79 | + throw new HttpAccessDeniedException(); |
|
80 | + } |
|
81 | + |
|
82 | + $tree = Validator::attributes($request)->treeOptional() ?? $all_trees->first(); |
|
83 | + |
|
84 | + $same_tree = fn(Tree $tree_collection): bool => $tree->id() === $tree_collection->id(); |
|
85 | + if (!$all_trees->contains($same_tree)) { |
|
86 | + throw new HttpAccessDeniedException(); |
|
87 | + } |
|
88 | + |
|
89 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
90 | + 'module_name' => $this->module->name(), |
|
91 | + 'title' => $this->module->title(), |
|
92 | + 'tree' => $tree, |
|
93 | + 'other_trees' => $all_trees->reject($same_tree), |
|
94 | + 'place_example' => $this->geoanalysis_data_service->placeHierarchyExample($tree), |
|
95 | + 'js_script_url' => $this->module->assetUrl('js/geodispersion.min.js') |
|
96 | + ]); |
|
97 | + } |
|
98 | 98 | } |
@@ -111,7 +111,7 @@ |
||
111 | 111 | */ |
112 | 112 | public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
113 | 113 | { |
114 | - return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
114 | + return view($module->name().'::geoanalysisview-tab-detailed', $params + ['results' => $results]); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | /** |
@@ -27,224 +27,224 @@ |
||
27 | 27 | */ |
28 | 28 | abstract class AbstractGeoAnalysisView |
29 | 29 | { |
30 | - private int $id; |
|
31 | - private Tree $tree; |
|
32 | - private bool $enabled; |
|
33 | - private string $description; |
|
34 | - private GeoAnalysisInterface $geoanalysis; |
|
35 | - private int $depth; |
|
36 | - private int $detailed_top_places; |
|
37 | - private bool $use_flags; |
|
38 | - |
|
39 | - /** |
|
40 | - * Constructor for AbstractGeoAnalysisView |
|
41 | - * |
|
42 | - * @param int $id |
|
43 | - * @param Tree $tree |
|
44 | - * @param bool $enabled |
|
45 | - * @param string $description |
|
46 | - * @param GeoAnalysisInterface $geoanalysis |
|
47 | - * @param int $depth |
|
48 | - * @param int $detailed_top_places |
|
49 | - * @param bool $use_flags |
|
50 | - */ |
|
51 | - final public function __construct( |
|
52 | - int $id, |
|
53 | - Tree $tree, |
|
54 | - bool $enabled, |
|
55 | - string $description, |
|
56 | - GeoAnalysisInterface $geoanalysis, |
|
57 | - int $depth, |
|
58 | - int $detailed_top_places = 0, |
|
59 | - bool $use_flags = false |
|
60 | - ) { |
|
61 | - $this->id = $id; |
|
62 | - $this->tree = $tree; |
|
63 | - $this->enabled = $enabled; |
|
64 | - $this->description = $description; |
|
65 | - $this->geoanalysis = $geoanalysis; |
|
66 | - $this->depth = $depth; |
|
67 | - $this->detailed_top_places = $detailed_top_places; |
|
68 | - $this->use_flags = $use_flags; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Create a copy of the view with a new ID. |
|
73 | - * |
|
74 | - * @param int $id |
|
75 | - * @return static |
|
76 | - */ |
|
77 | - public function withId(int $id): self |
|
78 | - { |
|
79 | - $new = clone $this; |
|
80 | - $new->id = $id; |
|
81 | - return $new; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Create a copy of the view with new properties. |
|
86 | - * |
|
87 | - * @param bool $enabled |
|
88 | - * @param string $description |
|
89 | - * @param GeoAnalysisInterface $geoanalysis |
|
90 | - * @param int $depth |
|
91 | - * @param int $detailed_top_places |
|
92 | - * @param bool $use_flags |
|
93 | - * @return static |
|
94 | - */ |
|
95 | - public function with( |
|
96 | - bool $enabled, |
|
97 | - string $description, |
|
98 | - GeoAnalysisInterface $geoanalysis, |
|
99 | - int $depth, |
|
100 | - int $detailed_top_places = 0, |
|
101 | - bool $use_flags = false |
|
102 | - ): self { |
|
103 | - $new = clone $this; |
|
104 | - $new->enabled = $enabled; |
|
105 | - $new->description = $description; |
|
106 | - $new->geoanalysis = $geoanalysis; |
|
107 | - $new->depth = $depth; |
|
108 | - $new->detailed_top_places = $detailed_top_places; |
|
109 | - $new->use_flags = $use_flags; |
|
110 | - return $new; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the view ID |
|
115 | - * |
|
116 | - * @return int |
|
117 | - */ |
|
118 | - public function id(): int |
|
119 | - { |
|
120 | - return $this->id; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Get the view type for display |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - abstract public function type(): string; |
|
129 | - |
|
130 | - /** |
|
131 | - * Get the icon for the view type |
|
132 | - * |
|
133 | - * @param ModuleInterface $module |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - abstract public function icon(ModuleInterface $module): string; |
|
137 | - |
|
138 | - /** |
|
139 | - * Return the content of the global settings section of the config page |
|
140 | - * |
|
141 | - * @param ModuleInterface $module |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - abstract public function globalSettingsContent(ModuleInterface $module): string; |
|
145 | - |
|
146 | - /** |
|
147 | - * Return a view with global settings updated according to the view rules |
|
148 | - * |
|
149 | - * @param ServerRequestInterface $request |
|
150 | - * @return static |
|
151 | - */ |
|
152 | - abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self; |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the content of the view global tab |
|
156 | - * |
|
157 | - * @param GeoDispersionModule $module |
|
158 | - * @param GeoAnalysisResult $result |
|
159 | - * @param array<string, mixed> $params |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - abstract public function globalTabContent( |
|
163 | - GeoDispersionModule $module, |
|
164 | - GeoAnalysisResult $result, |
|
165 | - array $params |
|
166 | - ): string; |
|
167 | - |
|
168 | - /** |
|
169 | - * Returns the content of the view detailed tab |
|
170 | - * |
|
171 | - * @param ModuleInterface $module |
|
172 | - * @param Collection<string, GeoAnalysisResult> $results |
|
173 | - * @param array<string, mixed> $params |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
|
177 | - { |
|
178 | - return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Get the tree to which the view belongs |
|
183 | - * |
|
184 | - * @return Tree |
|
185 | - */ |
|
186 | - public function tree(): Tree |
|
187 | - { |
|
188 | - return $this->tree; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get the description of the view |
|
193 | - * |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public function description(): string |
|
197 | - { |
|
198 | - return $this->description; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Get whether the view is enabled |
|
203 | - * |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public function isEnabled(): bool |
|
207 | - { |
|
208 | - return $this->enabled; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Get the geographical dispersion analysis for the view |
|
213 | - * |
|
214 | - * @return GeoAnalysisInterface |
|
215 | - */ |
|
216 | - public function analysis(): GeoAnalysisInterface |
|
217 | - { |
|
218 | - return $this->geoanalysis; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Get the place hierarchy depth for the view |
|
223 | - * |
|
224 | - * @return int |
|
225 | - */ |
|
226 | - public function placesDepth(): int |
|
227 | - { |
|
228 | - return $this->depth; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Get the number of places to display in the detailed tab |
|
233 | - * |
|
234 | - * @return int |
|
235 | - */ |
|
236 | - public function numberTopPlaces(): int |
|
237 | - { |
|
238 | - return $this->detailed_top_places; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Get whether flags should be used in the detailed tab |
|
243 | - * |
|
244 | - * @return bool |
|
245 | - */ |
|
246 | - public function useFlags(): bool |
|
247 | - { |
|
248 | - return $this->use_flags; |
|
249 | - } |
|
30 | + private int $id; |
|
31 | + private Tree $tree; |
|
32 | + private bool $enabled; |
|
33 | + private string $description; |
|
34 | + private GeoAnalysisInterface $geoanalysis; |
|
35 | + private int $depth; |
|
36 | + private int $detailed_top_places; |
|
37 | + private bool $use_flags; |
|
38 | + |
|
39 | + /** |
|
40 | + * Constructor for AbstractGeoAnalysisView |
|
41 | + * |
|
42 | + * @param int $id |
|
43 | + * @param Tree $tree |
|
44 | + * @param bool $enabled |
|
45 | + * @param string $description |
|
46 | + * @param GeoAnalysisInterface $geoanalysis |
|
47 | + * @param int $depth |
|
48 | + * @param int $detailed_top_places |
|
49 | + * @param bool $use_flags |
|
50 | + */ |
|
51 | + final public function __construct( |
|
52 | + int $id, |
|
53 | + Tree $tree, |
|
54 | + bool $enabled, |
|
55 | + string $description, |
|
56 | + GeoAnalysisInterface $geoanalysis, |
|
57 | + int $depth, |
|
58 | + int $detailed_top_places = 0, |
|
59 | + bool $use_flags = false |
|
60 | + ) { |
|
61 | + $this->id = $id; |
|
62 | + $this->tree = $tree; |
|
63 | + $this->enabled = $enabled; |
|
64 | + $this->description = $description; |
|
65 | + $this->geoanalysis = $geoanalysis; |
|
66 | + $this->depth = $depth; |
|
67 | + $this->detailed_top_places = $detailed_top_places; |
|
68 | + $this->use_flags = $use_flags; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Create a copy of the view with a new ID. |
|
73 | + * |
|
74 | + * @param int $id |
|
75 | + * @return static |
|
76 | + */ |
|
77 | + public function withId(int $id): self |
|
78 | + { |
|
79 | + $new = clone $this; |
|
80 | + $new->id = $id; |
|
81 | + return $new; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Create a copy of the view with new properties. |
|
86 | + * |
|
87 | + * @param bool $enabled |
|
88 | + * @param string $description |
|
89 | + * @param GeoAnalysisInterface $geoanalysis |
|
90 | + * @param int $depth |
|
91 | + * @param int $detailed_top_places |
|
92 | + * @param bool $use_flags |
|
93 | + * @return static |
|
94 | + */ |
|
95 | + public function with( |
|
96 | + bool $enabled, |
|
97 | + string $description, |
|
98 | + GeoAnalysisInterface $geoanalysis, |
|
99 | + int $depth, |
|
100 | + int $detailed_top_places = 0, |
|
101 | + bool $use_flags = false |
|
102 | + ): self { |
|
103 | + $new = clone $this; |
|
104 | + $new->enabled = $enabled; |
|
105 | + $new->description = $description; |
|
106 | + $new->geoanalysis = $geoanalysis; |
|
107 | + $new->depth = $depth; |
|
108 | + $new->detailed_top_places = $detailed_top_places; |
|
109 | + $new->use_flags = $use_flags; |
|
110 | + return $new; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the view ID |
|
115 | + * |
|
116 | + * @return int |
|
117 | + */ |
|
118 | + public function id(): int |
|
119 | + { |
|
120 | + return $this->id; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Get the view type for display |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + abstract public function type(): string; |
|
129 | + |
|
130 | + /** |
|
131 | + * Get the icon for the view type |
|
132 | + * |
|
133 | + * @param ModuleInterface $module |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + abstract public function icon(ModuleInterface $module): string; |
|
137 | + |
|
138 | + /** |
|
139 | + * Return the content of the global settings section of the config page |
|
140 | + * |
|
141 | + * @param ModuleInterface $module |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + abstract public function globalSettingsContent(ModuleInterface $module): string; |
|
145 | + |
|
146 | + /** |
|
147 | + * Return a view with global settings updated according to the view rules |
|
148 | + * |
|
149 | + * @param ServerRequestInterface $request |
|
150 | + * @return static |
|
151 | + */ |
|
152 | + abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self; |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the content of the view global tab |
|
156 | + * |
|
157 | + * @param GeoDispersionModule $module |
|
158 | + * @param GeoAnalysisResult $result |
|
159 | + * @param array<string, mixed> $params |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + abstract public function globalTabContent( |
|
163 | + GeoDispersionModule $module, |
|
164 | + GeoAnalysisResult $result, |
|
165 | + array $params |
|
166 | + ): string; |
|
167 | + |
|
168 | + /** |
|
169 | + * Returns the content of the view detailed tab |
|
170 | + * |
|
171 | + * @param ModuleInterface $module |
|
172 | + * @param Collection<string, GeoAnalysisResult> $results |
|
173 | + * @param array<string, mixed> $params |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
|
177 | + { |
|
178 | + return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Get the tree to which the view belongs |
|
183 | + * |
|
184 | + * @return Tree |
|
185 | + */ |
|
186 | + public function tree(): Tree |
|
187 | + { |
|
188 | + return $this->tree; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get the description of the view |
|
193 | + * |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public function description(): string |
|
197 | + { |
|
198 | + return $this->description; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Get whether the view is enabled |
|
203 | + * |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public function isEnabled(): bool |
|
207 | + { |
|
208 | + return $this->enabled; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Get the geographical dispersion analysis for the view |
|
213 | + * |
|
214 | + * @return GeoAnalysisInterface |
|
215 | + */ |
|
216 | + public function analysis(): GeoAnalysisInterface |
|
217 | + { |
|
218 | + return $this->geoanalysis; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Get the place hierarchy depth for the view |
|
223 | + * |
|
224 | + * @return int |
|
225 | + */ |
|
226 | + public function placesDepth(): int |
|
227 | + { |
|
228 | + return $this->depth; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Get the number of places to display in the detailed tab |
|
233 | + * |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + public function numberTopPlaces(): int |
|
237 | + { |
|
238 | + return $this->detailed_top_places; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Get whether flags should be used in the detailed tab |
|
243 | + * |
|
244 | + * @return bool |
|
245 | + */ |
|
246 | + public function useFlags(): bool |
|
247 | + { |
|
248 | + return $this->use_flags; |
|
249 | + } |
|
250 | 250 | } |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | |
92 | 92 | foreach ($existing_views as $old_view) { |
93 | 93 | try { |
94 | - $tree = $tree_service->find((int) $old_view->majgd_file); |
|
94 | + $tree = $tree_service->find((int)$old_view->majgd_file); |
|
95 | 95 | } catch (RuntimeException $ex) { |
96 | 96 | continue; |
97 | 97 | } |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | $old_view->majgd_status === 'enabled', |
135 | 135 | $old_view->majgd_descr, |
136 | 136 | app(SosaByGenerationGeoAnalysis::class), |
137 | - (int) $old_view->majgd_sublevel, |
|
138 | - (int) $old_view->majgd_detailsgen |
|
137 | + (int)$old_view->majgd_sublevel, |
|
138 | + (int)$old_view->majgd_detailsgen |
|
139 | 139 | ); |
140 | 140 | |
141 | 141 | return $geoview_data_service->insertGetId($new_view) > 0; |
@@ -165,8 +165,8 @@ discard block |
||
165 | 165 | $old_view->majgd_status === 'enabled', |
166 | 166 | $old_view->majgd_descr, |
167 | 167 | app(SosaByGenerationGeoAnalysis::class), |
168 | - (int) $old_view->majgd_sublevel, |
|
169 | - (int) $old_view->majgd_detailsgen |
|
168 | + (int)$old_view->majgd_sublevel, |
|
169 | + (int)$old_view->majgd_detailsgen |
|
170 | 170 | ); |
171 | 171 | |
172 | 172 | $view_id = $geoview_data_service->insertGetId($new_view); |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | private function mapIdsFromOld(string $map_xml): array |
204 | 204 | { |
205 | 205 | $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? []; |
206 | - return is_array($mapping) ? $mapping : [ $mapping ]; |
|
206 | + return is_array($mapping) ? $mapping : [$mapping]; |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -39,219 +39,219 @@ |
||
39 | 39 | */ |
40 | 40 | class Migration2 implements MigrationInterface |
41 | 41 | { |
42 | - /** |
|
43 | - * Mapping from old map definitions to new ones |
|
44 | - * @var array<string,mixed> MAPS_XML_MAPPING |
|
45 | - */ |
|
46 | - private const MAPS_XML_MAPPING = [ |
|
47 | - 'aubracmargeridebycommunes.xml' => 'fr-area-aubrac-lot-margeride-planeze-communes', |
|
48 | - 'calvadosbycommunes.xml' => 'fr-dpt-14-communes', |
|
49 | - 'cantalbycommunes.xml' => 'fr-dpt-15-communes', |
|
50 | - 'cotesdarmorbycommunes.xml' => 'fr-dpt-22-communes', |
|
51 | - 'essonnebycommunes.xml' => 'fr-dpt-91-communes', |
|
52 | - 'eurebycommunes.xml' => 'fr-dpt-27-communes', |
|
53 | - 'eureetloirbycommunes.xml' => 'fr-dpt-28-communes', |
|
54 | - 'francebydepartements.xml' => 'fr-metropole-departements', |
|
55 | - 'francebyregions1970.xml' => 'fr-metropole-regions-1970', |
|
56 | - 'francebyregions2016.xml' => 'fr-metropole-regions-2016', |
|
57 | - 'hauteloirebycommunes.xml' => 'fr-dpt-43-communes', |
|
58 | - 'illeetvilainebycommunes.xml' => 'fr-dpt-35-communes', |
|
59 | - 'loiretbycommunes.xml' => 'fr-dpt-45-communes', |
|
60 | - 'lozerebycodepostaux.xml' => 'fr-dpt-48-codespostaux', |
|
61 | - 'lozerebycommunes.xml' => 'fr-dpt-48-communes', |
|
62 | - 'mayennebycommunes.xml' => 'fr-dpt-53-communes', |
|
63 | - 'oisebycommunes.xml' => 'fr-dpt-60-communes', |
|
64 | - 'ornebycommunes.xml' => 'fr-dpt-61-communes', |
|
65 | - 'puydedomebycommunes.xml' => 'fr-dpt-63-communes', |
|
66 | - 'sarthebycommunes.xml' => 'fr-dpt-72-communes', |
|
67 | - 'seinemaritimebycommunes.xml' => 'fr-dpt-76-communes', |
|
68 | - 'seinesommeoisebycommunes.xml' => ['fr-dpt-60-communes', 'fr-dpt-76-communes', 'fr-dpt-80-communes'], |
|
69 | - 'valdoisebycommunes.xml' => 'fr-dpt-95-communes', |
|
70 | - 'yvelinesbycommunes.xml' => 'fr-dpt-78-communes' |
|
71 | - ]; |
|
42 | + /** |
|
43 | + * Mapping from old map definitions to new ones |
|
44 | + * @var array<string,mixed> MAPS_XML_MAPPING |
|
45 | + */ |
|
46 | + private const MAPS_XML_MAPPING = [ |
|
47 | + 'aubracmargeridebycommunes.xml' => 'fr-area-aubrac-lot-margeride-planeze-communes', |
|
48 | + 'calvadosbycommunes.xml' => 'fr-dpt-14-communes', |
|
49 | + 'cantalbycommunes.xml' => 'fr-dpt-15-communes', |
|
50 | + 'cotesdarmorbycommunes.xml' => 'fr-dpt-22-communes', |
|
51 | + 'essonnebycommunes.xml' => 'fr-dpt-91-communes', |
|
52 | + 'eurebycommunes.xml' => 'fr-dpt-27-communes', |
|
53 | + 'eureetloirbycommunes.xml' => 'fr-dpt-28-communes', |
|
54 | + 'francebydepartements.xml' => 'fr-metropole-departements', |
|
55 | + 'francebyregions1970.xml' => 'fr-metropole-regions-1970', |
|
56 | + 'francebyregions2016.xml' => 'fr-metropole-regions-2016', |
|
57 | + 'hauteloirebycommunes.xml' => 'fr-dpt-43-communes', |
|
58 | + 'illeetvilainebycommunes.xml' => 'fr-dpt-35-communes', |
|
59 | + 'loiretbycommunes.xml' => 'fr-dpt-45-communes', |
|
60 | + 'lozerebycodepostaux.xml' => 'fr-dpt-48-codespostaux', |
|
61 | + 'lozerebycommunes.xml' => 'fr-dpt-48-communes', |
|
62 | + 'mayennebycommunes.xml' => 'fr-dpt-53-communes', |
|
63 | + 'oisebycommunes.xml' => 'fr-dpt-60-communes', |
|
64 | + 'ornebycommunes.xml' => 'fr-dpt-61-communes', |
|
65 | + 'puydedomebycommunes.xml' => 'fr-dpt-63-communes', |
|
66 | + 'sarthebycommunes.xml' => 'fr-dpt-72-communes', |
|
67 | + 'seinemaritimebycommunes.xml' => 'fr-dpt-76-communes', |
|
68 | + 'seinesommeoisebycommunes.xml' => ['fr-dpt-60-communes', 'fr-dpt-76-communes', 'fr-dpt-80-communes'], |
|
69 | + 'valdoisebycommunes.xml' => 'fr-dpt-95-communes', |
|
70 | + 'yvelinesbycommunes.xml' => 'fr-dpt-78-communes' |
|
71 | + ]; |
|
72 | 72 | |
73 | - /** |
|
74 | - * {@inheritDoc} |
|
75 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
76 | - */ |
|
77 | - public function upgrade(): void |
|
78 | - { |
|
79 | - if (!DB::schema()->hasTable('maj_geodispersion')) { |
|
80 | - return; |
|
81 | - } |
|
73 | + /** |
|
74 | + * {@inheritDoc} |
|
75 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
76 | + */ |
|
77 | + public function upgrade(): void |
|
78 | + { |
|
79 | + if (!DB::schema()->hasTable('maj_geodispersion')) { |
|
80 | + return; |
|
81 | + } |
|
82 | 82 | |
83 | - /** @var TreeService $tree_service */ |
|
84 | - $tree_service = app(TreeService::class); |
|
85 | - /** @var GeoAnalysisViewDataService $geoview_data_service */ |
|
86 | - $geoview_data_service = app(GeoAnalysisViewDataService::class); |
|
83 | + /** @var TreeService $tree_service */ |
|
84 | + $tree_service = app(TreeService::class); |
|
85 | + /** @var GeoAnalysisViewDataService $geoview_data_service */ |
|
86 | + $geoview_data_service = app(GeoAnalysisViewDataService::class); |
|
87 | 87 | |
88 | - $existing_views = DB::table('maj_geodispersion') |
|
89 | - ->select() |
|
90 | - ->get(); |
|
88 | + $existing_views = DB::table('maj_geodispersion') |
|
89 | + ->select() |
|
90 | + ->get(); |
|
91 | 91 | |
92 | - foreach ($existing_views as $old_view) { |
|
93 | - try { |
|
94 | - $tree = $tree_service->find((int) $old_view->majgd_file); |
|
95 | - } catch (RuntimeException $ex) { |
|
96 | - continue; |
|
97 | - } |
|
92 | + foreach ($existing_views as $old_view) { |
|
93 | + try { |
|
94 | + $tree = $tree_service->find((int) $old_view->majgd_file); |
|
95 | + } catch (RuntimeException $ex) { |
|
96 | + continue; |
|
97 | + } |
|
98 | 98 | |
99 | - if ($old_view->majgd_map === null) { |
|
100 | - $this->migrateGeoAnalysisTable($old_view, $tree, $geoview_data_service); |
|
101 | - } else { |
|
102 | - DB::connection()->beginTransaction(); |
|
103 | - if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) { |
|
104 | - DB::connection()->commit(); |
|
105 | - } else { |
|
106 | - DB::connection()->rollBack(); |
|
107 | - } |
|
108 | - } |
|
109 | - } |
|
99 | + if ($old_view->majgd_map === null) { |
|
100 | + $this->migrateGeoAnalysisTable($old_view, $tree, $geoview_data_service); |
|
101 | + } else { |
|
102 | + DB::connection()->beginTransaction(); |
|
103 | + if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) { |
|
104 | + DB::connection()->commit(); |
|
105 | + } else { |
|
106 | + DB::connection()->rollBack(); |
|
107 | + } |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - $in_transaction = DB::connection()->getPdo()->inTransaction(); |
|
111 | + $in_transaction = DB::connection()->getPdo()->inTransaction(); |
|
112 | 112 | |
113 | - DB::schema()->drop('maj_geodispersion'); |
|
113 | + DB::schema()->drop('maj_geodispersion'); |
|
114 | 114 | |
115 | - if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) { |
|
116 | - DB::connection()->beginTransaction(); |
|
117 | - } |
|
115 | + if ($in_transaction && !DB::connection()->getPdo()->inTransaction()) { |
|
116 | + DB::connection()->beginTransaction(); |
|
117 | + } |
|
118 | 118 | |
119 | - FlashMessages::addMessage(I18N::translate( |
|
120 | - 'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.' |
|
121 | - )); |
|
122 | - } |
|
119 | + FlashMessages::addMessage(I18N::translate( |
|
120 | + 'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.' |
|
121 | + )); |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * Create a Table geographical analysis view from a migrated item. |
|
126 | - * |
|
127 | - * @param stdClass $old_view |
|
128 | - * @param Tree $tree |
|
129 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - private function migrateGeoAnalysisTable( |
|
133 | - stdClass $old_view, |
|
134 | - Tree $tree, |
|
135 | - GeoAnalysisViewDataService $geoview_data_service |
|
136 | - ): bool { |
|
137 | - $new_view = new GeoAnalysisTable( |
|
138 | - 0, |
|
139 | - $tree, |
|
140 | - $old_view->majgd_status === 'enabled', |
|
141 | - $old_view->majgd_descr, |
|
142 | - app(SosaByGenerationGeoAnalysis::class), |
|
143 | - (int) $old_view->majgd_sublevel, |
|
144 | - (int) $old_view->majgd_detailsgen |
|
145 | - ); |
|
124 | + /** |
|
125 | + * Create a Table geographical analysis view from a migrated item. |
|
126 | + * |
|
127 | + * @param stdClass $old_view |
|
128 | + * @param Tree $tree |
|
129 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + private function migrateGeoAnalysisTable( |
|
133 | + stdClass $old_view, |
|
134 | + Tree $tree, |
|
135 | + GeoAnalysisViewDataService $geoview_data_service |
|
136 | + ): bool { |
|
137 | + $new_view = new GeoAnalysisTable( |
|
138 | + 0, |
|
139 | + $tree, |
|
140 | + $old_view->majgd_status === 'enabled', |
|
141 | + $old_view->majgd_descr, |
|
142 | + app(SosaByGenerationGeoAnalysis::class), |
|
143 | + (int) $old_view->majgd_sublevel, |
|
144 | + (int) $old_view->majgd_detailsgen |
|
145 | + ); |
|
146 | 146 | |
147 | - return $geoview_data_service->insertGetId($new_view) > 0; |
|
148 | - } |
|
147 | + return $geoview_data_service->insertGetId($new_view) > 0; |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Create a Map geographical analysis view from a migrated item. |
|
152 | - * |
|
153 | - * @param stdClass $old_view |
|
154 | - * @param Tree $tree |
|
155 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
156 | - * @return bool |
|
157 | - */ |
|
158 | - private function migrateGeoAnalysisMap( |
|
159 | - stdClass $old_view, |
|
160 | - Tree $tree, |
|
161 | - GeoAnalysisViewDataService $geoview_data_service |
|
162 | - ): bool { |
|
163 | - /** @var MapDefinitionsService $map_definition_service */ |
|
164 | - $map_definition_service = app(MapDefinitionsService::class); |
|
165 | - /** @var MapAdapterDataService $mapadapter_data_service */ |
|
166 | - $mapadapter_data_service = app(MapAdapterDataService::class); |
|
150 | + /** |
|
151 | + * Create a Map geographical analysis view from a migrated item. |
|
152 | + * |
|
153 | + * @param stdClass $old_view |
|
154 | + * @param Tree $tree |
|
155 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
156 | + * @return bool |
|
157 | + */ |
|
158 | + private function migrateGeoAnalysisMap( |
|
159 | + stdClass $old_view, |
|
160 | + Tree $tree, |
|
161 | + GeoAnalysisViewDataService $geoview_data_service |
|
162 | + ): bool { |
|
163 | + /** @var MapDefinitionsService $map_definition_service */ |
|
164 | + $map_definition_service = app(MapDefinitionsService::class); |
|
165 | + /** @var MapAdapterDataService $mapadapter_data_service */ |
|
166 | + $mapadapter_data_service = app(MapAdapterDataService::class); |
|
167 | 167 | |
168 | - $new_view = new GeoAnalysisMap( |
|
169 | - 0, |
|
170 | - $tree, |
|
171 | - $old_view->majgd_status === 'enabled', |
|
172 | - $old_view->majgd_descr, |
|
173 | - app(SosaByGenerationGeoAnalysis::class), |
|
174 | - (int) $old_view->majgd_sublevel, |
|
175 | - (int) $old_view->majgd_detailsgen |
|
176 | - ); |
|
168 | + $new_view = new GeoAnalysisMap( |
|
169 | + 0, |
|
170 | + $tree, |
|
171 | + $old_view->majgd_status === 'enabled', |
|
172 | + $old_view->majgd_descr, |
|
173 | + app(SosaByGenerationGeoAnalysis::class), |
|
174 | + (int) $old_view->majgd_sublevel, |
|
175 | + (int) $old_view->majgd_detailsgen |
|
176 | + ); |
|
177 | 177 | |
178 | - $view_id = $geoview_data_service->insertGetId($new_view); |
|
179 | - if ($view_id === 0) { |
|
180 | - return false; |
|
181 | - } |
|
182 | - $new_view = $new_view->withId($view_id); |
|
178 | + $view_id = $geoview_data_service->insertGetId($new_view); |
|
179 | + if ($view_id === 0) { |
|
180 | + return false; |
|
181 | + } |
|
182 | + $new_view = $new_view->withId($view_id); |
|
183 | 183 | |
184 | - $colors = $new_view->colors(); |
|
185 | - foreach ($this->mapIdsFromOld($old_view->majgd_map) as $new_map_id) { |
|
186 | - $map = $map_definition_service->find($new_map_id); |
|
187 | - if ($map === null) { |
|
188 | - return false; |
|
189 | - } |
|
190 | - $colors = $this->colorsFromMap($new_map_id); |
|
184 | + $colors = $new_view->colors(); |
|
185 | + foreach ($this->mapIdsFromOld($old_view->majgd_map) as $new_map_id) { |
|
186 | + $map = $map_definition_service->find($new_map_id); |
|
187 | + if ($map === null) { |
|
188 | + return false; |
|
189 | + } |
|
190 | + $colors = $this->colorsFromMap($new_map_id); |
|
191 | 191 | |
192 | - /** @var SimplePlaceMapper $mapper */ |
|
193 | - $mapper = app(SimplePlaceMapper::class); |
|
194 | - $mapview_config = new MapViewConfig($this->mappingPropertyForMap($new_map_id), $mapper->config()); |
|
195 | - $map_adapter = new GeoAnalysisMapAdapter(0, $view_id, $map, $mapper, $mapview_config); |
|
192 | + /** @var SimplePlaceMapper $mapper */ |
|
193 | + $mapper = app(SimplePlaceMapper::class); |
|
194 | + $mapview_config = new MapViewConfig($this->mappingPropertyForMap($new_map_id), $mapper->config()); |
|
195 | + $map_adapter = new GeoAnalysisMapAdapter(0, $view_id, $map, $mapper, $mapview_config); |
|
196 | 196 | |
197 | - $mapadapter_data_service->insertGetId($map_adapter); |
|
198 | - } |
|
197 | + $mapadapter_data_service->insertGetId($map_adapter); |
|
198 | + } |
|
199 | 199 | |
200 | - return $geoview_data_service->update($new_view->withColors($colors)) > 0; |
|
201 | - } |
|
200 | + return $geoview_data_service->update($new_view->withColors($colors)) > 0; |
|
201 | + } |
|
202 | 202 | |
203 | - /** |
|
204 | - * Get all new map definitions IDs representing an old map definition |
|
205 | - * |
|
206 | - * @param string $map_xml |
|
207 | - * @return string[] |
|
208 | - */ |
|
209 | - private function mapIdsFromOld(string $map_xml): array |
|
210 | - { |
|
211 | - $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? []; |
|
212 | - return is_array($mapping) ? $mapping : [ $mapping ]; |
|
213 | - } |
|
203 | + /** |
|
204 | + * Get all new map definitions IDs representing an old map definition |
|
205 | + * |
|
206 | + * @param string $map_xml |
|
207 | + * @return string[] |
|
208 | + */ |
|
209 | + private function mapIdsFromOld(string $map_xml): array |
|
210 | + { |
|
211 | + $mapping = self::MAPS_XML_MAPPING[$map_xml] ?? []; |
|
212 | + return is_array($mapping) ? $mapping : [ $mapping ]; |
|
213 | + } |
|
214 | 214 | |
215 | - /** |
|
216 | - * Get the mapping property to be used for the migrated map adapter |
|
217 | - * |
|
218 | - * @param string $map_id |
|
219 | - * @return string |
|
220 | - */ |
|
221 | - private function mappingPropertyForMap(string $map_id): string |
|
222 | - { |
|
223 | - switch ($map_id) { |
|
224 | - case 'fr-metropole-regions-1970': |
|
225 | - case 'fr-metropole-regions-2016': |
|
226 | - return 'region_insee_libelle'; |
|
227 | - case 'fr-metropole-departements': |
|
228 | - return 'dpt_insee_libelle'; |
|
229 | - case 'fr-dpt-48-codespostaux': |
|
230 | - return 'code_postal'; |
|
231 | - default: |
|
232 | - return 'commune_insee_libelle'; |
|
233 | - } |
|
234 | - } |
|
215 | + /** |
|
216 | + * Get the mapping property to be used for the migrated map adapter |
|
217 | + * |
|
218 | + * @param string $map_id |
|
219 | + * @return string |
|
220 | + */ |
|
221 | + private function mappingPropertyForMap(string $map_id): string |
|
222 | + { |
|
223 | + switch ($map_id) { |
|
224 | + case 'fr-metropole-regions-1970': |
|
225 | + case 'fr-metropole-regions-2016': |
|
226 | + return 'region_insee_libelle'; |
|
227 | + case 'fr-metropole-departements': |
|
228 | + return 'dpt_insee_libelle'; |
|
229 | + case 'fr-dpt-48-codespostaux': |
|
230 | + return 'code_postal'; |
|
231 | + default: |
|
232 | + return 'commune_insee_libelle'; |
|
233 | + } |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Get the color configuration to be used for the migrated map view |
|
238 | - * |
|
239 | - * @param string $map_id |
|
240 | - * @return MapColorsConfig |
|
241 | - */ |
|
242 | - private function colorsFromMap(string $map_id): MapColorsConfig |
|
243 | - { |
|
244 | - $default = Hex::fromString('#f5f5f5'); |
|
245 | - $stroke = Hex::fromString('#d5d5d5'); |
|
246 | - $hover = Hex::fromString('#ff6600'); |
|
236 | + /** |
|
237 | + * Get the color configuration to be used for the migrated map view |
|
238 | + * |
|
239 | + * @param string $map_id |
|
240 | + * @return MapColorsConfig |
|
241 | + */ |
|
242 | + private function colorsFromMap(string $map_id): MapColorsConfig |
|
243 | + { |
|
244 | + $default = Hex::fromString('#f5f5f5'); |
|
245 | + $stroke = Hex::fromString('#d5d5d5'); |
|
246 | + $hover = Hex::fromString('#ff6600'); |
|
247 | 247 | |
248 | - switch ($map_id) { |
|
249 | - case 'fr-metropole-departements': |
|
250 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover); |
|
251 | - case 'fr-dpt-48-codespostaux': |
|
252 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover); |
|
253 | - default: |
|
254 | - return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover); |
|
255 | - } |
|
256 | - } |
|
248 | + switch ($map_id) { |
|
249 | + case 'fr-metropole-departements': |
|
250 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover); |
|
251 | + case 'fr-dpt-48-codespostaux': |
|
252 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover); |
|
253 | + default: |
|
254 | + return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover); |
|
255 | + } |
|
256 | + } |
|
257 | 257 | } |
@@ -32,186 +32,186 @@ |
||
32 | 32 | */ |
33 | 33 | class GeoAnalysisViewDataService |
34 | 34 | { |
35 | - /** |
|
36 | - * Find a Geographical dispersion analysis view by ID |
|
37 | - * |
|
38 | - * @param Tree $tree |
|
39 | - * @param int $id |
|
40 | - * @return AbstractGeoAnalysisView|NULL |
|
41 | - */ |
|
42 | - public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView |
|
43 | - { |
|
44 | - return $this->all($tree, $include_disabled) |
|
45 | - ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id); |
|
46 | - } |
|
47 | - |
|
48 | - /** |
|
49 | - * Get all Geographical dispersion analysis views, with or without the disabled ones. |
|
50 | - * |
|
51 | - * {@internal It would ignore any view for which the class could not be loaded by the container} |
|
52 | - * |
|
53 | - * @param Tree $tree |
|
54 | - * @param bool $include_disabled |
|
55 | - * @return Collection<AbstractGeoAnalysisView> |
|
56 | - */ |
|
57 | - public function all(Tree $tree, bool $include_disabled = false): Collection |
|
58 | - { |
|
59 | - return Registry::cache()->array()->remember( |
|
60 | - 'all-geodispersion-views', |
|
61 | - function () use ($tree, $include_disabled): Collection { |
|
62 | - return DB::table('maj_geodisp_views') |
|
63 | - ->select('maj_geodisp_views.*') |
|
64 | - ->where('majgv_gedcom_id', '=', $tree->id()) |
|
65 | - ->get() |
|
66 | - ->map($this->viewMapper($tree)) |
|
67 | - ->filter() |
|
68 | - ->filter($this->enabledFilter($include_disabled)); |
|
69 | - } |
|
70 | - ); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Insert a geographical dispersion analysis view object in the database. |
|
75 | - * |
|
76 | - * @param AbstractGeoAnalysisView $view |
|
77 | - * @return int |
|
78 | - */ |
|
79 | - public function insertGetId(AbstractGeoAnalysisView $view): int |
|
80 | - { |
|
81 | - return DB::table('maj_geodisp_views') |
|
82 | - ->insertGetId([ |
|
83 | - 'majgv_gedcom_id' => $view->tree()->id(), |
|
84 | - 'majgv_view_class' => get_class($view), |
|
85 | - 'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled', |
|
86 | - 'majgv_descr' => mb_substr($view->description(), 0, 248), |
|
87 | - 'majgv_analysis' => get_class($view->analysis()), |
|
88 | - 'majgv_place_depth' => $view->placesDepth() |
|
89 | - ]); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Update a geographical dispersion analysis view object in the database. |
|
94 | - * |
|
95 | - * @param AbstractGeoAnalysisView $view |
|
96 | - * @return int |
|
97 | - */ |
|
98 | - public function update(AbstractGeoAnalysisView $view): int |
|
99 | - { |
|
100 | - return DB::table('maj_geodisp_views') |
|
101 | - ->where('majgv_id', '=', $view->id()) |
|
102 | - ->update([ |
|
103 | - 'majgv_gedcom_id' => $view->tree()->id(), |
|
104 | - 'majgv_view_class' => get_class($view), |
|
105 | - 'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled', |
|
106 | - 'majgv_descr' => mb_substr($view->description(), 0, 248), |
|
107 | - 'majgv_analysis' => get_class($view->analysis()), |
|
108 | - 'majgv_place_depth' => $view->placesDepth(), |
|
109 | - 'majgv_top_places' => $view->numberTopPlaces(), |
|
110 | - 'majgv_colors' => $view instanceof GeoAnalysisMap ? json_encode($view->colors()) : null |
|
111 | - ]); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Update the status of a geographical dispersion analysis view object in the database. |
|
116 | - * |
|
117 | - * @param AbstractGeoAnalysisView $view |
|
118 | - * @param bool $status |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function updateStatus(AbstractGeoAnalysisView $view, bool $status): int |
|
122 | - { |
|
123 | - return DB::table('maj_geodisp_views') |
|
124 | - ->where('majgv_id', '=', $view->id()) |
|
125 | - ->update(['majgv_status' => $status ? 'enabled' : 'disabled']); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Delete a geographical dispersion analysis view object from the database. |
|
130 | - * |
|
131 | - * @param AbstractGeoAnalysisView $view |
|
132 | - * @return int |
|
133 | - */ |
|
134 | - public function delete(AbstractGeoAnalysisView $view): int |
|
135 | - { |
|
136 | - return DB::table('maj_geodisp_views') |
|
137 | - ->where('majgv_id', '=', $view->id()) |
|
138 | - ->delete(); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Get the closure to create a AbstractGeoAnalysisView object from a row in the database. |
|
143 | - * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
144 | - * or if the types do not match with the ones expected. |
|
145 | - * |
|
146 | - * @param Tree $tree |
|
147 | - * @return Closure(\stdClass $row):?AbstractGeoAnalysisView |
|
148 | - */ |
|
149 | - private function viewMapper(Tree $tree): Closure |
|
150 | - { |
|
151 | - return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
152 | - try { |
|
153 | - $geoanalysis = app($row->majgv_analysis); |
|
154 | - if (!($geoanalysis instanceof GeoAnalysisInterface)) { |
|
155 | - return null; |
|
156 | - } |
|
157 | - |
|
158 | - $view = app()->makeWith($row->majgv_view_class, [ |
|
159 | - 'id' => (int) $row->majgv_id, |
|
160 | - 'tree' => $tree, |
|
161 | - 'enabled' => $row->majgv_status === 'enabled', |
|
162 | - 'description' => $row->majgv_descr, |
|
163 | - 'geoanalysis' => $geoanalysis, |
|
164 | - 'depth' => (int) $row->majgv_place_depth, |
|
165 | - 'detailed_top_places' => (int) $row->majgv_top_places |
|
166 | - ]); |
|
167 | - |
|
168 | - if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) { |
|
169 | - $view = $view->withColors($this->colorsDecoder($row->majgv_colors)); |
|
170 | - } |
|
171 | - |
|
172 | - return $view instanceof AbstractGeoAnalysisView ? $view : null; |
|
173 | - } catch (BindingResolutionException $ex) { |
|
174 | - return null; |
|
175 | - } |
|
176 | - }; |
|
177 | - } |
|
178 | - |
|
179 | - /** |
|
180 | - * Create a MapColorsConfig object from a JSON column value. |
|
181 | - * Returns null if the JSON string is invalid, or if the colors are not valid. |
|
182 | - * |
|
183 | - * @param string $colors_config |
|
184 | - * @return MapColorsConfig|NULL |
|
185 | - */ |
|
186 | - private function colorsDecoder(string $colors_config): ?MapColorsConfig |
|
187 | - { |
|
188 | - $colors = json_decode($colors_config, true); |
|
189 | - if (!is_array($colors) && count($colors) !== 4) { |
|
190 | - return null; |
|
191 | - } |
|
192 | - try { |
|
193 | - return new MapColorsConfig( |
|
194 | - \Spatie\Color\Factory::fromString($colors['default'] ?? ''), |
|
195 | - \Spatie\Color\Factory::fromString($colors['stroke'] ?? ''), |
|
196 | - \Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''), |
|
197 | - \Spatie\Color\Factory::fromString($colors['hover'] ?? '') |
|
198 | - ); |
|
199 | - } catch (InvalidColorValue $ex) { |
|
200 | - return null; |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Get a closure to filter views by enabled/disabled status |
|
206 | - * |
|
207 | - * @param bool $include_disabled |
|
208 | - * |
|
209 | - * @return Closure(AbstractGeoAnalysisView $view):bool |
|
210 | - */ |
|
211 | - private function enabledFilter(bool $include_disabled): Closure |
|
212 | - { |
|
213 | - return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
214 | - return $include_disabled || $view->isEnabled(); |
|
215 | - }; |
|
216 | - } |
|
35 | + /** |
|
36 | + * Find a Geographical dispersion analysis view by ID |
|
37 | + * |
|
38 | + * @param Tree $tree |
|
39 | + * @param int $id |
|
40 | + * @return AbstractGeoAnalysisView|NULL |
|
41 | + */ |
|
42 | + public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView |
|
43 | + { |
|
44 | + return $this->all($tree, $include_disabled) |
|
45 | + ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id); |
|
46 | + } |
|
47 | + |
|
48 | + /** |
|
49 | + * Get all Geographical dispersion analysis views, with or without the disabled ones. |
|
50 | + * |
|
51 | + * {@internal It would ignore any view for which the class could not be loaded by the container} |
|
52 | + * |
|
53 | + * @param Tree $tree |
|
54 | + * @param bool $include_disabled |
|
55 | + * @return Collection<AbstractGeoAnalysisView> |
|
56 | + */ |
|
57 | + public function all(Tree $tree, bool $include_disabled = false): Collection |
|
58 | + { |
|
59 | + return Registry::cache()->array()->remember( |
|
60 | + 'all-geodispersion-views', |
|
61 | + function () use ($tree, $include_disabled): Collection { |
|
62 | + return DB::table('maj_geodisp_views') |
|
63 | + ->select('maj_geodisp_views.*') |
|
64 | + ->where('majgv_gedcom_id', '=', $tree->id()) |
|
65 | + ->get() |
|
66 | + ->map($this->viewMapper($tree)) |
|
67 | + ->filter() |
|
68 | + ->filter($this->enabledFilter($include_disabled)); |
|
69 | + } |
|
70 | + ); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Insert a geographical dispersion analysis view object in the database. |
|
75 | + * |
|
76 | + * @param AbstractGeoAnalysisView $view |
|
77 | + * @return int |
|
78 | + */ |
|
79 | + public function insertGetId(AbstractGeoAnalysisView $view): int |
|
80 | + { |
|
81 | + return DB::table('maj_geodisp_views') |
|
82 | + ->insertGetId([ |
|
83 | + 'majgv_gedcom_id' => $view->tree()->id(), |
|
84 | + 'majgv_view_class' => get_class($view), |
|
85 | + 'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled', |
|
86 | + 'majgv_descr' => mb_substr($view->description(), 0, 248), |
|
87 | + 'majgv_analysis' => get_class($view->analysis()), |
|
88 | + 'majgv_place_depth' => $view->placesDepth() |
|
89 | + ]); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Update a geographical dispersion analysis view object in the database. |
|
94 | + * |
|
95 | + * @param AbstractGeoAnalysisView $view |
|
96 | + * @return int |
|
97 | + */ |
|
98 | + public function update(AbstractGeoAnalysisView $view): int |
|
99 | + { |
|
100 | + return DB::table('maj_geodisp_views') |
|
101 | + ->where('majgv_id', '=', $view->id()) |
|
102 | + ->update([ |
|
103 | + 'majgv_gedcom_id' => $view->tree()->id(), |
|
104 | + 'majgv_view_class' => get_class($view), |
|
105 | + 'majgv_status' => $view->isEnabled() ? 'enabled' : 'disabled', |
|
106 | + 'majgv_descr' => mb_substr($view->description(), 0, 248), |
|
107 | + 'majgv_analysis' => get_class($view->analysis()), |
|
108 | + 'majgv_place_depth' => $view->placesDepth(), |
|
109 | + 'majgv_top_places' => $view->numberTopPlaces(), |
|
110 | + 'majgv_colors' => $view instanceof GeoAnalysisMap ? json_encode($view->colors()) : null |
|
111 | + ]); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Update the status of a geographical dispersion analysis view object in the database. |
|
116 | + * |
|
117 | + * @param AbstractGeoAnalysisView $view |
|
118 | + * @param bool $status |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function updateStatus(AbstractGeoAnalysisView $view, bool $status): int |
|
122 | + { |
|
123 | + return DB::table('maj_geodisp_views') |
|
124 | + ->where('majgv_id', '=', $view->id()) |
|
125 | + ->update(['majgv_status' => $status ? 'enabled' : 'disabled']); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Delete a geographical dispersion analysis view object from the database. |
|
130 | + * |
|
131 | + * @param AbstractGeoAnalysisView $view |
|
132 | + * @return int |
|
133 | + */ |
|
134 | + public function delete(AbstractGeoAnalysisView $view): int |
|
135 | + { |
|
136 | + return DB::table('maj_geodisp_views') |
|
137 | + ->where('majgv_id', '=', $view->id()) |
|
138 | + ->delete(); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Get the closure to create a AbstractGeoAnalysisView object from a row in the database. |
|
143 | + * It returns null if the classes stored in the DB cannot be loaded through the Laravel container, |
|
144 | + * or if the types do not match with the ones expected. |
|
145 | + * |
|
146 | + * @param Tree $tree |
|
147 | + * @return Closure(\stdClass $row):?AbstractGeoAnalysisView |
|
148 | + */ |
|
149 | + private function viewMapper(Tree $tree): Closure |
|
150 | + { |
|
151 | + return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
152 | + try { |
|
153 | + $geoanalysis = app($row->majgv_analysis); |
|
154 | + if (!($geoanalysis instanceof GeoAnalysisInterface)) { |
|
155 | + return null; |
|
156 | + } |
|
157 | + |
|
158 | + $view = app()->makeWith($row->majgv_view_class, [ |
|
159 | + 'id' => (int) $row->majgv_id, |
|
160 | + 'tree' => $tree, |
|
161 | + 'enabled' => $row->majgv_status === 'enabled', |
|
162 | + 'description' => $row->majgv_descr, |
|
163 | + 'geoanalysis' => $geoanalysis, |
|
164 | + 'depth' => (int) $row->majgv_place_depth, |
|
165 | + 'detailed_top_places' => (int) $row->majgv_top_places |
|
166 | + ]); |
|
167 | + |
|
168 | + if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) { |
|
169 | + $view = $view->withColors($this->colorsDecoder($row->majgv_colors)); |
|
170 | + } |
|
171 | + |
|
172 | + return $view instanceof AbstractGeoAnalysisView ? $view : null; |
|
173 | + } catch (BindingResolutionException $ex) { |
|
174 | + return null; |
|
175 | + } |
|
176 | + }; |
|
177 | + } |
|
178 | + |
|
179 | + /** |
|
180 | + * Create a MapColorsConfig object from a JSON column value. |
|
181 | + * Returns null if the JSON string is invalid, or if the colors are not valid. |
|
182 | + * |
|
183 | + * @param string $colors_config |
|
184 | + * @return MapColorsConfig|NULL |
|
185 | + */ |
|
186 | + private function colorsDecoder(string $colors_config): ?MapColorsConfig |
|
187 | + { |
|
188 | + $colors = json_decode($colors_config, true); |
|
189 | + if (!is_array($colors) && count($colors) !== 4) { |
|
190 | + return null; |
|
191 | + } |
|
192 | + try { |
|
193 | + return new MapColorsConfig( |
|
194 | + \Spatie\Color\Factory::fromString($colors['default'] ?? ''), |
|
195 | + \Spatie\Color\Factory::fromString($colors['stroke'] ?? ''), |
|
196 | + \Spatie\Color\Factory::fromString($colors['maxvalue'] ?? ''), |
|
197 | + \Spatie\Color\Factory::fromString($colors['hover'] ?? '') |
|
198 | + ); |
|
199 | + } catch (InvalidColorValue $ex) { |
|
200 | + return null; |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Get a closure to filter views by enabled/disabled status |
|
206 | + * |
|
207 | + * @param bool $include_disabled |
|
208 | + * |
|
209 | + * @return Closure(AbstractGeoAnalysisView $view):bool |
|
210 | + */ |
|
211 | + private function enabledFilter(bool $include_disabled): Closure |
|
212 | + { |
|
213 | + return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
214 | + return $include_disabled || $view->isEnabled(); |
|
215 | + }; |
|
216 | + } |
|
217 | 217 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | public function find(Tree $tree, int $id, bool $include_disabled = false): ?AbstractGeoAnalysisView |
43 | 43 | { |
44 | 44 | return $this->all($tree, $include_disabled) |
45 | - ->first(fn(AbstractGeoAnalysisView $view): bool => $view->id() === $id); |
|
45 | + ->first(fn(AbstractGeoAnalysisView $view) : bool => $view->id() === $id); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | return Registry::cache()->array()->remember( |
60 | 60 | 'all-geodispersion-views', |
61 | - function () use ($tree, $include_disabled): Collection { |
|
61 | + function() use ($tree, $include_disabled): Collection { |
|
62 | 62 | return DB::table('maj_geodisp_views') |
63 | 63 | ->select('maj_geodisp_views.*') |
64 | 64 | ->where('majgv_gedcom_id', '=', $tree->id()) |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | */ |
149 | 149 | private function viewMapper(Tree $tree): Closure |
150 | 150 | { |
151 | - return function (stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
151 | + return function(stdClass $row) use ($tree): ?AbstractGeoAnalysisView { |
|
152 | 152 | try { |
153 | 153 | $geoanalysis = app($row->majgv_analysis); |
154 | 154 | if (!($geoanalysis instanceof GeoAnalysisInterface)) { |
@@ -156,13 +156,13 @@ discard block |
||
156 | 156 | } |
157 | 157 | |
158 | 158 | $view = app()->makeWith($row->majgv_view_class, [ |
159 | - 'id' => (int) $row->majgv_id, |
|
159 | + 'id' => (int)$row->majgv_id, |
|
160 | 160 | 'tree' => $tree, |
161 | 161 | 'enabled' => $row->majgv_status === 'enabled', |
162 | 162 | 'description' => $row->majgv_descr, |
163 | 163 | 'geoanalysis' => $geoanalysis, |
164 | - 'depth' => (int) $row->majgv_place_depth, |
|
165 | - 'detailed_top_places' => (int) $row->majgv_top_places |
|
164 | + 'depth' => (int)$row->majgv_place_depth, |
|
165 | + 'detailed_top_places' => (int)$row->majgv_top_places |
|
166 | 166 | ]); |
167 | 167 | |
168 | 168 | if ($row->majgv_colors !== null && $view instanceof GeoAnalysisMap) { |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | */ |
211 | 211 | private function enabledFilter(bool $include_disabled): Closure |
212 | 212 | { |
213 | - return function (AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
213 | + return function(AbstractGeoAnalysisView $view) use ($include_disabled): bool { |
|
214 | 214 | return $include_disabled || $view->isEnabled(); |
215 | 215 | }; |
216 | 216 | } |
@@ -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 | } |
@@ -49,14 +49,14 @@ discard block |
||
49 | 49 | if ($source_parts === false) { |
50 | 50 | return null; |
51 | 51 | } |
52 | - $source_parts = array_map(function (string $part): string { |
|
52 | + $source_parts = array_map(function(string $part): string { |
|
53 | 53 | if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) { |
54 | 54 | return $this->columnName($column_id[1]); |
55 | 55 | } |
56 | 56 | return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part)); |
57 | 57 | }, array_filter($source_parts)); |
58 | 58 | $source_parts[] = "'%'"; |
59 | - $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')'; |
|
59 | + $concat_statement = 'CONCAT('.implode(', ', $source_parts).')'; |
|
60 | 60 | |
61 | 61 | // Extract columns used in target |
62 | 62 | $columns = []; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | // Get the mapping |
68 | 68 | $rows = DB::table('maj_geodata_ref') //DB::table('maj_geodata_ref') |
69 | 69 | ->select($columns) |
70 | - ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement) |
|
70 | + ->whereRaw($this->sanitizeString($source)." LIKE ".$concat_statement) |
|
71 | 71 | ->get(); |
72 | 72 | |
73 | 73 | // Format the output ID |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | return null; |
76 | 76 | } |
77 | 77 | |
78 | - $mapping = (array) $rows->first(); |
|
78 | + $mapping = (array)$rows->first(); |
|
79 | 79 | if (count($columns_select) === 0) { |
80 | 80 | return $target_format; |
81 | 81 | } |
82 | 82 | |
83 | 83 | return str_replace( |
84 | - array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]), |
|
84 | + array_map(fn($tag) => '{'.$tag.'}', $columns_select[1]), |
|
85 | 85 | array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]), |
86 | 86 | $target_format |
87 | 87 | ); |
@@ -74,14 +74,14 @@ |
||
74 | 74 | |
75 | 75 | return $query_individuals->unionAll($query_families) |
76 | 76 | ->get()->pluck('g_gedcom') |
77 | - ->flatMap(static function (string $gedcom): array { |
|
77 | + ->flatMap(static function(string $gedcom): array { |
|
78 | 78 | preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches); |
79 | 79 | return $matches[1] ?? []; |
80 | 80 | }) |
81 | 81 | ->sort(I18N::comparator())->reverse() |
82 | - ->mapWithKeys(static function (string $place): array { |
|
82 | + ->mapWithKeys(static function(string $place): array { |
|
83 | 83 | $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place)))); |
84 | - return [ count($place_array) => $place_array ]; |
|
84 | + return [count($place_array) => $place_array]; |
|
85 | 85 | }) |
86 | 86 | ->sortKeys() |
87 | 87 | ->last(); |
@@ -26,64 +26,64 @@ |
||
26 | 26 | */ |
27 | 27 | class GeoAnalysisDataService |
28 | 28 | { |
29 | - /** |
|
30 | - * Yields indviduals and family records for a specified tree. |
|
31 | - * |
|
32 | - * @param Tree $tree |
|
33 | - * @return \Generator<\Fisharebest\Webtrees\GedcomRecord> |
|
34 | - */ |
|
35 | - public function individualsAndFamilies(Tree $tree): Generator |
|
36 | - { |
|
37 | - yield from DB::table('individuals') |
|
38 | - ->where('i_file', '=', $tree->id()) |
|
39 | - ->select(['individuals.*']) |
|
40 | - ->get() |
|
41 | - ->map(Registry::individualFactory()->mapper($tree)) |
|
42 | - ->filter(GedcomRecord::accessFilter()) |
|
43 | - ->all(); |
|
29 | + /** |
|
30 | + * Yields indviduals and family records for a specified tree. |
|
31 | + * |
|
32 | + * @param Tree $tree |
|
33 | + * @return \Generator<\Fisharebest\Webtrees\GedcomRecord> |
|
34 | + */ |
|
35 | + public function individualsAndFamilies(Tree $tree): Generator |
|
36 | + { |
|
37 | + yield from DB::table('individuals') |
|
38 | + ->where('i_file', '=', $tree->id()) |
|
39 | + ->select(['individuals.*']) |
|
40 | + ->get() |
|
41 | + ->map(Registry::individualFactory()->mapper($tree)) |
|
42 | + ->filter(GedcomRecord::accessFilter()) |
|
43 | + ->all(); |
|
44 | 44 | |
45 | - yield from DB::table('families') |
|
46 | - ->where('f_file', '=', $tree->id()) |
|
47 | - ->select(['families.*']) |
|
48 | - ->get() |
|
49 | - ->map(Registry::familyFactory()->mapper($tree)) |
|
50 | - ->filter(GedcomRecord::accessFilter()) |
|
51 | - ->all(); |
|
52 | - } |
|
45 | + yield from DB::table('families') |
|
46 | + ->where('f_file', '=', $tree->id()) |
|
47 | + ->select(['families.*']) |
|
48 | + ->get() |
|
49 | + ->map(Registry::familyFactory()->mapper($tree)) |
|
50 | + ->filter(GedcomRecord::accessFilter()) |
|
51 | + ->all(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest |
|
56 | - * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first). |
|
57 | - * |
|
58 | - * {@internal The places are taken only from the individuals and families records.} |
|
59 | - * |
|
60 | - * @param Tree $tree |
|
61 | - * @return array<int, string[]> |
|
62 | - */ |
|
63 | - public function placeHierarchyExample(Tree $tree): array |
|
64 | - { |
|
65 | - $query_individuals = DB::table('individuals') |
|
66 | - ->select(['i_gedcom AS g_gedcom']) |
|
67 | - ->where('i_file', '=', $tree->id()) |
|
68 | - ->where('i_gedcom', 'like', '%2 PLAC %'); |
|
54 | + /** |
|
55 | + * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest |
|
56 | + * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first). |
|
57 | + * |
|
58 | + * {@internal The places are taken only from the individuals and families records.} |
|
59 | + * |
|
60 | + * @param Tree $tree |
|
61 | + * @return array<int, string[]> |
|
62 | + */ |
|
63 | + public function placeHierarchyExample(Tree $tree): array |
|
64 | + { |
|
65 | + $query_individuals = DB::table('individuals') |
|
66 | + ->select(['i_gedcom AS g_gedcom']) |
|
67 | + ->where('i_file', '=', $tree->id()) |
|
68 | + ->where('i_gedcom', 'like', '%2 PLAC %'); |
|
69 | 69 | |
70 | - $query_families = DB::table('families') |
|
71 | - ->select(['f_gedcom AS g_gedcom']) |
|
72 | - ->where('f_file', '=', $tree->id()) |
|
73 | - ->where('f_gedcom', 'like', '%2 PLAC %'); |
|
70 | + $query_families = DB::table('families') |
|
71 | + ->select(['f_gedcom AS g_gedcom']) |
|
72 | + ->where('f_file', '=', $tree->id()) |
|
73 | + ->where('f_gedcom', 'like', '%2 PLAC %'); |
|
74 | 74 | |
75 | - return $query_individuals->unionAll($query_families) |
|
76 | - ->get()->pluck('g_gedcom') |
|
77 | - ->flatMap(static function (string $gedcom): array { |
|
78 | - preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches); |
|
79 | - return $matches[1] ?? []; |
|
80 | - }) |
|
81 | - ->sort(I18N::comparator())->reverse() |
|
82 | - ->mapWithKeys(static function (string $place): array { |
|
83 | - $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place)))); |
|
84 | - return [ count($place_array) => $place_array ]; |
|
85 | - }) |
|
86 | - ->sortKeys() |
|
87 | - ->last(); |
|
88 | - } |
|
75 | + return $query_individuals->unionAll($query_families) |
|
76 | + ->get()->pluck('g_gedcom') |
|
77 | + ->flatMap(static function (string $gedcom): array { |
|
78 | + preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches); |
|
79 | + return $matches[1] ?? []; |
|
80 | + }) |
|
81 | + ->sort(I18N::comparator())->reverse() |
|
82 | + ->mapWithKeys(static function (string $place): array { |
|
83 | + $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place)))); |
|
84 | + return [ count($place_array) => $place_array ]; |
|
85 | + }) |
|
86 | + ->sortKeys() |
|
87 | + ->last(); |
|
88 | + } |
|
89 | 89 | } |