@@ -19,21 +19,21 @@ |
||
19 | 19 | */ |
20 | 20 | class NullFactSourceStatus extends FactSourceStatus |
21 | 21 | { |
22 | - /** |
|
23 | - * {@inheritDoc} |
|
24 | - * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isSet() |
|
25 | - */ |
|
26 | - public function isSet(): bool |
|
27 | - { |
|
28 | - return false; |
|
29 | - } |
|
22 | + /** |
|
23 | + * {@inheritDoc} |
|
24 | + * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isSet() |
|
25 | + */ |
|
26 | + public function isSet(): bool |
|
27 | + { |
|
28 | + return false; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * {@inheritDoc} |
|
33 | - * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\FactSourceStatus::combineWith() |
|
34 | - */ |
|
35 | - public function combineWith(SourceStatus $other) |
|
36 | - { |
|
37 | - return $other; |
|
38 | - } |
|
31 | + /** |
|
32 | + * {@inheritDoc} |
|
33 | + * @see \MyArtJaub\Webtrees\Module\IsSourced\Data\FactSourceStatus::combineWith() |
|
34 | + */ |
|
35 | + public function combineWith(SourceStatus $other) |
|
36 | + { |
|
37 | + return $other; |
|
38 | + } |
|
39 | 39 | } |
@@ -27,52 +27,52 @@ |
||
27 | 27 | */ |
28 | 28 | class RecordNameTextExtenderCollector extends AbstractHookCollector implements RecordNameTextExtenderInterface |
29 | 29 | { |
30 | - /** |
|
31 | - * {@inheritDoc} |
|
32 | - * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title() |
|
33 | - */ |
|
34 | - public function title(): string |
|
35 | - { |
|
36 | - return I18N::translate('Text extender for records’ name'); |
|
37 | - } |
|
30 | + /** |
|
31 | + * {@inheritDoc} |
|
32 | + * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title() |
|
33 | + */ |
|
34 | + public function title(): string |
|
35 | + { |
|
36 | + return I18N::translate('Text extender for records’ name'); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description() |
|
42 | - */ |
|
43 | - public function description(): string |
|
44 | - { |
|
45 | - return I18N::translate('Extends the full name of GEDCOM records with additional text or icons.'); |
|
46 | - } |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description() |
|
42 | + */ |
|
43 | + public function description(): string |
|
44 | + { |
|
45 | + return I18N::translate('Extends the full name of GEDCOM records with additional text or icons.'); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface() |
|
51 | - */ |
|
52 | - public function hookInterface(): string |
|
53 | - { |
|
54 | - return RecordNameTextExtenderInterface::class; |
|
55 | - } |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface() |
|
51 | + */ |
|
52 | + public function hookInterface(): string |
|
53 | + { |
|
54 | + return RecordNameTextExtenderInterface::class; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
60 | - */ |
|
61 | - public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
62 | - { |
|
63 | - return $this->hooks() |
|
64 | - ->map(fn(RecordNameTextExtenderInterface $hook) => $hook->recordNamePrepend($record, $use_long, $size)) |
|
65 | - ->implode(''); |
|
66 | - } |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
60 | + */ |
|
61 | + public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
62 | + { |
|
63 | + return $this->hooks() |
|
64 | + ->map(fn(RecordNameTextExtenderInterface $hook) => $hook->recordNamePrepend($record, $use_long, $size)) |
|
65 | + ->implode(''); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * {@inheritDoc} |
|
70 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
71 | - */ |
|
72 | - public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
73 | - { |
|
74 | - return $this->hooks() |
|
75 | - ->map(fn(RecordNameTextExtenderInterface $hook) => $hook->recordNameAppend($record, $use_long, $size)) |
|
76 | - ->implode(''); |
|
77 | - } |
|
68 | + /** |
|
69 | + * {@inheritDoc} |
|
70 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
71 | + */ |
|
72 | + public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
73 | + { |
|
74 | + return $this->hooks() |
|
75 | + ->map(fn(RecordNameTextExtenderInterface $hook) => $hook->recordNameAppend($record, $use_long, $size)) |
|
76 | + ->implode(''); |
|
77 | + } |
|
78 | 78 | } |
@@ -27,41 +27,41 @@ |
||
27 | 27 | */ |
28 | 28 | class NameAccordionExtenderCollector extends AbstractHookCollector implements NameAccordionExtenderInterface |
29 | 29 | { |
30 | - /** |
|
31 | - * {@inheritDoc} |
|
32 | - * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title() |
|
33 | - */ |
|
34 | - public function title(): string |
|
35 | - { |
|
36 | - return I18N::translate('Individual names accordion extender'); |
|
37 | - } |
|
30 | + /** |
|
31 | + * {@inheritDoc} |
|
32 | + * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title() |
|
33 | + */ |
|
34 | + public function title(): string |
|
35 | + { |
|
36 | + return I18N::translate('Individual names accordion extender'); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * {@inheritDoc} |
|
41 | - * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description() |
|
42 | - */ |
|
43 | - public function description(): string |
|
44 | - { |
|
45 | - return I18N::translate('Extends the names accordion of on an individual’s page.'); |
|
46 | - } |
|
39 | + /** |
|
40 | + * {@inheritDoc} |
|
41 | + * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description() |
|
42 | + */ |
|
43 | + public function description(): string |
|
44 | + { |
|
45 | + return I18N::translate('Extends the names accordion of on an individual’s page.'); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface() |
|
51 | - */ |
|
52 | - public function hookInterface(): string |
|
53 | - { |
|
54 | - return NameAccordionExtenderInterface::class; |
|
55 | - } |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface() |
|
51 | + */ |
|
52 | + public function hookInterface(): string |
|
53 | + { |
|
54 | + return NameAccordionExtenderInterface::class; |
|
55 | + } |
|
56 | 56 | |
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\NameAccordionExtenderInterface::accordionCard() |
|
60 | - */ |
|
61 | - public function accordionCard(Individual $individual): string |
|
62 | - { |
|
63 | - return $this->hooks() |
|
64 | - ->map(fn(NameAccordionExtenderInterface $hook) => $hook->accordionCard($individual)) |
|
65 | - ->implode(''); |
|
66 | - } |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\NameAccordionExtenderInterface::accordionCard() |
|
60 | + */ |
|
61 | + public function accordionCard(Individual $individual): string |
|
62 | + { |
|
63 | + return $this->hooks() |
|
64 | + ->map(fn(NameAccordionExtenderInterface $hook) => $hook->accordionCard($individual)) |
|
65 | + ->implode(''); |
|
66 | + } |
|
67 | 67 | } |
@@ -29,38 +29,38 @@ |
||
29 | 29 | */ |
30 | 30 | class AdminConfigPage implements RequestHandlerInterface |
31 | 31 | { |
32 | - use ViewResponseTrait; |
|
32 | + use ViewResponseTrait; |
|
33 | 33 | |
34 | - private ?HooksModule $module; |
|
35 | - private HookService $hook_service; |
|
34 | + private ?HooksModule $module; |
|
35 | + private HookService $hook_service; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for AdminConfigPage Request Handler |
|
39 | - * |
|
40 | - * @param ModuleService $module_service |
|
41 | - * @param HookService $hook_service |
|
42 | - */ |
|
43 | - public function __construct(ModuleService $module_service, HookService $hook_service) |
|
44 | - { |
|
45 | - $this->module = $module_service->findByInterface(HooksModule::class)->first(); |
|
46 | - $this->hook_service = $hook_service; |
|
47 | - } |
|
37 | + /** |
|
38 | + * Constructor for AdminConfigPage Request Handler |
|
39 | + * |
|
40 | + * @param ModuleService $module_service |
|
41 | + * @param HookService $hook_service |
|
42 | + */ |
|
43 | + public function __construct(ModuleService $module_service, HookService $hook_service) |
|
44 | + { |
|
45 | + $this->module = $module_service->findByInterface(HooksModule::class)->first(); |
|
46 | + $this->hook_service = $hook_service; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * {@inheritDoc} |
|
51 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | - */ |
|
53 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | - { |
|
55 | - $this->layout = 'layouts/administration'; |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | + */ |
|
53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | + { |
|
55 | + $this->layout = 'layouts/administration'; |
|
56 | 56 | |
57 | - if ($this->module === null) { |
|
58 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
59 | - } |
|
57 | + if ($this->module === null) { |
|
58 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
59 | + } |
|
60 | 60 | |
61 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
62 | - 'title' => $this->module->title(), |
|
63 | - 'hook_interfaces_list' => $this->hook_service->all(true) |
|
64 | - ]); |
|
65 | - } |
|
61 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
62 | + 'title' => $this->module->title(), |
|
63 | + 'hook_interfaces_list' => $this->hook_service->all(true) |
|
64 | + ]); |
|
65 | + } |
|
66 | 66 | } |
@@ -28,35 +28,35 @@ |
||
28 | 28 | */ |
29 | 29 | class AdminConfigPage implements RequestHandlerInterface |
30 | 30 | { |
31 | - use ViewResponseTrait; |
|
32 | - |
|
33 | - private ?MiscExtensionsModule $module; |
|
34 | - |
|
35 | - /** |
|
36 | - * Constructor for AdminConfigPage Request Handler |
|
37 | - * |
|
38 | - * @param ModuleService $module_service |
|
39 | - */ |
|
40 | - public function __construct(ModuleService $module_service) |
|
41 | - { |
|
42 | - $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first(); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * {@inheritDoc} |
|
47 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
48 | - */ |
|
49 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
50 | - { |
|
51 | - $this->layout = 'layouts/administration'; |
|
52 | - |
|
53 | - if ($this->module === null) { |
|
54 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
55 | - } |
|
56 | - |
|
57 | - return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
58 | - 'module' => $this->module, |
|
59 | - 'title' => $this->module->title() |
|
60 | - ]); |
|
61 | - } |
|
31 | + use ViewResponseTrait; |
|
32 | + |
|
33 | + private ?MiscExtensionsModule $module; |
|
34 | + |
|
35 | + /** |
|
36 | + * Constructor for AdminConfigPage Request Handler |
|
37 | + * |
|
38 | + * @param ModuleService $module_service |
|
39 | + */ |
|
40 | + public function __construct(ModuleService $module_service) |
|
41 | + { |
|
42 | + $this->module = $module_service->findByInterface(MiscExtensionsModule::class)->first(); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * {@inheritDoc} |
|
47 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
48 | + */ |
|
49 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
50 | + { |
|
51 | + $this->layout = 'layouts/administration'; |
|
52 | + |
|
53 | + if ($this->module === null) { |
|
54 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
55 | + } |
|
56 | + |
|
57 | + return $this->viewResponse($this->module->name() . '::admin/config', [ |
|
58 | + 'module' => $this->module, |
|
59 | + 'title' => $this->module->title() |
|
60 | + ]); |
|
61 | + } |
|
62 | 62 | } |
@@ -21,79 +21,79 @@ |
||
21 | 21 | */ |
22 | 22 | class MissingAncestor |
23 | 23 | { |
24 | - /** |
|
25 | - * @var Individual $individual |
|
26 | - */ |
|
27 | - private $individual; |
|
24 | + /** |
|
25 | + * @var Individual $individual |
|
26 | + */ |
|
27 | + private $individual; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var int $sosa |
|
31 | - */ |
|
32 | - private $sosa; |
|
29 | + /** |
|
30 | + * @var int $sosa |
|
31 | + */ |
|
32 | + private $sosa; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var bool $missing_father |
|
36 | - */ |
|
37 | - private $missing_father; |
|
34 | + /** |
|
35 | + * @var bool $missing_father |
|
36 | + */ |
|
37 | + private $missing_father; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var bool $missing_mother |
|
41 | - */ |
|
42 | - private $missing_mother; |
|
39 | + /** |
|
40 | + * @var bool $missing_mother |
|
41 | + */ |
|
42 | + private $missing_mother; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Constructor for MissingAncestor data class |
|
46 | - * |
|
47 | - * @param Individual $ancestor |
|
48 | - * @param int $sosa |
|
49 | - * @param bool $missing_father |
|
50 | - * @param bool $missing_mother |
|
51 | - */ |
|
52 | - public function __construct(Individual $ancestor, int $sosa, bool $missing_father, bool $missing_mother) |
|
53 | - { |
|
54 | - $this->individual = $ancestor; |
|
55 | - $this->sosa = $sosa; |
|
56 | - $this->missing_father = $missing_father; |
|
57 | - $this->missing_mother = $missing_mother; |
|
58 | - } |
|
44 | + /** |
|
45 | + * Constructor for MissingAncestor data class |
|
46 | + * |
|
47 | + * @param Individual $ancestor |
|
48 | + * @param int $sosa |
|
49 | + * @param bool $missing_father |
|
50 | + * @param bool $missing_mother |
|
51 | + */ |
|
52 | + public function __construct(Individual $ancestor, int $sosa, bool $missing_father, bool $missing_mother) |
|
53 | + { |
|
54 | + $this->individual = $ancestor; |
|
55 | + $this->sosa = $sosa; |
|
56 | + $this->missing_father = $missing_father; |
|
57 | + $this->missing_mother = $missing_mother; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Reference individual of the row |
|
62 | - * |
|
63 | - * @return Individual |
|
64 | - */ |
|
65 | - public function individual(): Individual |
|
66 | - { |
|
67 | - return $this->individual; |
|
68 | - } |
|
60 | + /** |
|
61 | + * Reference individual of the row |
|
62 | + * |
|
63 | + * @return Individual |
|
64 | + */ |
|
65 | + public function individual(): Individual |
|
66 | + { |
|
67 | + return $this->individual; |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * Minimum sosa of the reference individual |
|
72 | - * |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - public function sosa(): int |
|
76 | - { |
|
77 | - return $this->sosa; |
|
78 | - } |
|
70 | + /** |
|
71 | + * Minimum sosa of the reference individual |
|
72 | + * |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + public function sosa(): int |
|
76 | + { |
|
77 | + return $this->sosa; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Indicate whether the reference individual does not have a father |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - */ |
|
85 | - public function isFatherMissing(): bool |
|
86 | - { |
|
87 | - return $this->missing_father; |
|
88 | - } |
|
80 | + /** |
|
81 | + * Indicate whether the reference individual does not have a father |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + */ |
|
85 | + public function isFatherMissing(): bool |
|
86 | + { |
|
87 | + return $this->missing_father; |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Indicate whether the reference individual does not have a mother |
|
92 | - * |
|
93 | - * @return bool |
|
94 | - */ |
|
95 | - public function isMotherMissing(): bool |
|
96 | - { |
|
97 | - return $this->missing_mother; |
|
98 | - } |
|
90 | + /** |
|
91 | + * Indicate whether the reference individual does not have a mother |
|
92 | + * |
|
93 | + * @return bool |
|
94 | + */ |
|
95 | + public function isMotherMissing(): bool |
|
96 | + { |
|
97 | + return $this->missing_mother; |
|
98 | + } |
|
99 | 99 | } |
@@ -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 | } |
@@ -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 | } |
@@ -26,55 +26,55 @@ |
||
26 | 26 | */ |
27 | 27 | class AllEventsByTypeGeoAnalysis implements GeoAnalysisInterface |
28 | 28 | { |
29 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
29 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor for AllEventsByTypeGeoAnalysis |
|
33 | - * |
|
34 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
35 | - */ |
|
36 | - public function __construct(GeoAnalysisDataService $geoanalysis_data_service) |
|
37 | - { |
|
38 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
39 | - } |
|
31 | + /** |
|
32 | + * Constructor for AllEventsByTypeGeoAnalysis |
|
33 | + * |
|
34 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
35 | + */ |
|
36 | + public function __construct(GeoAnalysisDataService $geoanalysis_data_service) |
|
37 | + { |
|
38 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * {@inheritDoc} |
|
43 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
44 | - */ |
|
45 | - public function title(): string |
|
46 | - { |
|
47 | - return I18N::translate('All events places by event type'); |
|
48 | - } |
|
41 | + /** |
|
42 | + * {@inheritDoc} |
|
43 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
44 | + */ |
|
45 | + public function title(): string |
|
46 | + { |
|
47 | + return I18N::translate('All events places by event type'); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
53 | - */ |
|
54 | - public function itemsDescription(): callable |
|
55 | - { |
|
56 | - return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
57 | - } |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
53 | + */ |
|
54 | + public function itemsDescription(): callable |
|
55 | + { |
|
56 | + return fn(int $count): string => I18N::plural('event', 'events', $count); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
62 | - */ |
|
63 | - public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
64 | - { |
|
65 | - $results = new GeoAnalysisResults(); |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
62 | + */ |
|
63 | + public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
64 | + { |
|
65 | + $results = new GeoAnalysisResults(); |
|
66 | 66 | |
67 | - foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
68 | - foreach ($record->facts([]) as $fact) { |
|
69 | - $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
70 | - if ($place->isUnknown()) { |
|
71 | - continue; |
|
72 | - } |
|
73 | - $results->addPlace($place); |
|
74 | - $results->addPlaceInCategory($fact->label(), 0, $place); |
|
75 | - } |
|
76 | - } |
|
67 | + foreach ($this->geoanalysis_data_service->individualsAndFamilies($tree) as $record) { |
|
68 | + foreach ($record->facts([]) as $fact) { |
|
69 | + $place = new GeoAnalysisPlace($tree, $fact->place(), $depth); |
|
70 | + if ($place->isUnknown()) { |
|
71 | + continue; |
|
72 | + } |
|
73 | + $results->addPlace($place); |
|
74 | + $results->addPlaceInCategory($fact->label(), 0, $place); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - return $results; |
|
79 | - } |
|
78 | + return $results; |
|
79 | + } |
|
80 | 80 | } |