@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
68 | 68 | } |
69 | 69 | |
70 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
70 | + $task_sched_id = (int)$request->getAttribute('task'); |
|
71 | 71 | $task_schedule = $this->taskschedules_service->find($task_sched_id); |
72 | 72 | |
73 | 73 | if ($task_schedule === null) { |
@@ -83,9 +83,9 @@ discard block |
||
83 | 83 | $has_task_config = $task instanceof ConfigurableTaskInterface; |
84 | 84 | /** @var TaskInterface&ConfigurableTaskInterface $task */ |
85 | 85 | |
86 | - return $this->viewResponse($this->module->name() . '::admin/tasks-edit', [ |
|
86 | + return $this->viewResponse($this->module->name().'::admin/tasks-edit', [ |
|
87 | 87 | 'module' => $this->module, |
88 | - 'title' => I18N::translate('Edit the administrative task') . ' - ' . $task->name(), |
|
88 | + 'title' => I18N::translate('Edit the administrative task').' - '.$task->name(), |
|
89 | 89 | 'task_schedule' => $task_schedule, |
90 | 90 | 'task' => $task, |
91 | 91 | 'has_task_config' => $has_task_config, |
@@ -31,65 +31,65 @@ |
||
31 | 31 | */ |
32 | 32 | class TaskEditPage implements RequestHandlerInterface |
33 | 33 | { |
34 | - use ViewResponseTrait; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var AdminTasksModule|null $module |
|
38 | - */ |
|
39 | - private $module; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var TaskScheduleService $taskschedules_service |
|
43 | - */ |
|
44 | - private $taskschedules_service; |
|
45 | - |
|
46 | - /** |
|
47 | - * Constructor for TaskEditPage Request Handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - * @param TaskScheduleService $taskschedules_service |
|
51 | - */ |
|
52 | - public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
53 | - { |
|
54 | - $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
55 | - $this->taskschedules_service = $taskschedules_service; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * {@inheritDoc} |
|
60 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | - */ |
|
62 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | - { |
|
64 | - $this->layout = 'layouts/administration'; |
|
65 | - |
|
66 | - if ($this->module === null) { |
|
67 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
68 | - } |
|
69 | - |
|
70 | - $task_sched_id = (int) $request->getAttribute('task'); |
|
71 | - $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
72 | - |
|
73 | - if ($task_schedule === null) { |
|
74 | - throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
75 | - } |
|
76 | - |
|
77 | - $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
78 | - |
|
79 | - if ($task === null) { |
|
80 | - throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
81 | - } |
|
82 | - |
|
83 | - $has_task_config = $task instanceof ConfigurableTaskInterface; |
|
84 | - /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
85 | - |
|
86 | - return $this->viewResponse($this->module->name() . '::admin/tasks-edit', [ |
|
87 | - 'module' => $this->module, |
|
88 | - 'title' => I18N::translate('Edit the administrative task') . ' - ' . $task->name(), |
|
89 | - 'task_schedule' => $task_schedule, |
|
90 | - 'task' => $task, |
|
91 | - 'has_task_config' => $has_task_config, |
|
92 | - 'task_config_view' => $has_task_config ? $task->configView($request) : '' |
|
93 | - ]); |
|
94 | - } |
|
34 | + use ViewResponseTrait; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var AdminTasksModule|null $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var TaskScheduleService $taskschedules_service |
|
43 | + */ |
|
44 | + private $taskschedules_service; |
|
45 | + |
|
46 | + /** |
|
47 | + * Constructor for TaskEditPage Request Handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + * @param TaskScheduleService $taskschedules_service |
|
51 | + */ |
|
52 | + public function __construct(ModuleService $module_service, TaskScheduleService $taskschedules_service) |
|
53 | + { |
|
54 | + $this->module = $module_service->findByInterface(AdminTasksModule::class)->first(); |
|
55 | + $this->taskschedules_service = $taskschedules_service; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * {@inheritDoc} |
|
60 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
61 | + */ |
|
62 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
63 | + { |
|
64 | + $this->layout = 'layouts/administration'; |
|
65 | + |
|
66 | + if ($this->module === null) { |
|
67 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
68 | + } |
|
69 | + |
|
70 | + $task_sched_id = (int) $request->getAttribute('task'); |
|
71 | + $task_schedule = $this->taskschedules_service->find($task_sched_id); |
|
72 | + |
|
73 | + if ($task_schedule === null) { |
|
74 | + throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
75 | + } |
|
76 | + |
|
77 | + $task = $this->taskschedules_service->findTask($task_schedule->taskId()); |
|
78 | + |
|
79 | + if ($task === null) { |
|
80 | + throw new HttpNotFoundException(I18N::translate('The Task schedule could not be found.')); |
|
81 | + } |
|
82 | + |
|
83 | + $has_task_config = $task instanceof ConfigurableTaskInterface; |
|
84 | + /** @var TaskInterface&ConfigurableTaskInterface $task */ |
|
85 | + |
|
86 | + return $this->viewResponse($this->module->name() . '::admin/tasks-edit', [ |
|
87 | + 'module' => $this->module, |
|
88 | + 'title' => I18N::translate('Edit the administrative task') . ' - ' . $task->name(), |
|
89 | + 'task_schedule' => $task_schedule, |
|
90 | + 'task' => $task, |
|
91 | + 'has_task_config' => $has_task_config, |
|
92 | + 'task_config_view' => $has_task_config ? $task->configView($request) : '' |
|
93 | + ]); |
|
94 | + } |
|
95 | 95 | } |
@@ -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 | /** |
@@ -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 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | /** @var SosaStatisticsService $sosa_stats_service */ |
72 | 72 | $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
73 | 73 | |
74 | - return $this->viewResponse($this->module->name() . '::statistics-page', [ |
|
74 | + return $this->viewResponse($this->module->name().'::statistics-page', [ |
|
75 | 75 | 'module_name' => $this->module->name(), |
76 | 76 | 'title' => I18N::translate('Sosa Statistics'), |
77 | 77 | 'tree' => $tree, |
@@ -126,37 +126,34 @@ discard block |
||
126 | 126 | |
127 | 127 | foreach ($stats_by_gen as $gen => $stats_gen) { |
128 | 128 | $gen_diff = $gen > 1 ? |
129 | - (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] : |
|
130 | - 1; |
|
129 | + (int)$stats_gen['diffSosaTotalCount'] - (int)$stats_by_gen[$gen - 1]['diffSosaTotalCount'] : 1; |
|
131 | 130 | $generation_stats[$gen] = array( |
132 | - 'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'], |
|
133 | - 'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'], |
|
131 | + 'gen_min_birth' => $stats_gen['firstBirth'] ?? (int)$stats_gen['firstEstimatedBirth'], |
|
132 | + 'gen_max_birth' => $stats_gen['lastBirth'] ?? (int)$stats_gen['lastEstimatedBirth'], |
|
134 | 133 | 'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(), |
135 | - 'known' => (int) $stats_gen['sosaCount'], |
|
134 | + 'known' => (int)$stats_gen['sosaCount'], |
|
136 | 135 | 'perc_known' => $this->safeDivision( |
137 | - BigInteger::of((int) $stats_gen['sosaCount']), |
|
136 | + BigInteger::of((int)$stats_gen['sosaCount']), |
|
138 | 137 | BigInteger::of(2)->power($gen - 1) |
139 | 138 | ), |
140 | 139 | 'missing' => $gen > 1 ? |
141 | - 2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] : |
|
142 | - 0, |
|
140 | + 2 * (int)$stats_by_gen[$gen - 1]['sosaCount'] - (int)$stats_gen['sosaCount'] : 0, |
|
143 | 141 | 'perc_missing' => $gen > 1 ? |
144 | 142 | 1 - $this->safeDivision( |
145 | - BigInteger::of((int) $stats_gen['sosaCount']), |
|
146 | - BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount']) |
|
147 | - ) : |
|
148 | - 0, |
|
149 | - 'total_known' => (int) $stats_gen['sosaTotalCount'], |
|
143 | + BigInteger::of((int)$stats_gen['sosaCount']), |
|
144 | + BigInteger::of(2 * (int)$stats_by_gen[$gen - 1]['sosaCount']) |
|
145 | + ) : 0, |
|
146 | + 'total_known' => (int)$stats_gen['sosaTotalCount'], |
|
150 | 147 | 'perc_total_known' => $this->safeDivision( |
151 | - BigInteger::of((int) $stats_gen['sosaTotalCount']), |
|
148 | + BigInteger::of((int)$stats_gen['sosaTotalCount']), |
|
152 | 149 | BigInteger::of(2)->power($gen)->minus(1) |
153 | 150 | ), |
154 | 151 | 'different' => $gen_diff, |
155 | 152 | 'perc_different' => $this->safeDivision( |
156 | 153 | BigInteger::of($gen_diff), |
157 | - BigInteger::of((int) $stats_gen['sosaCount']) |
|
154 | + BigInteger::of((int)$stats_gen['sosaCount']) |
|
158 | 155 | ), |
159 | - 'total_different' => (int) $stats_gen['diffSosaTotalCount'] |
|
156 | + 'total_different' => (int)$stats_gen['diffSosaTotalCount'] |
|
160 | 157 | ); |
161 | 158 | } |
162 | 159 |
@@ -36,144 +36,144 @@ |
||
36 | 36 | */ |
37 | 37 | class SosaStatistics implements RequestHandlerInterface |
38 | 38 | { |
39 | - use ViewResponseTrait; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var SosaModule|null $module |
|
43 | - */ |
|
44 | - private $module; |
|
45 | - |
|
46 | - /** |
|
47 | - * Constructor for AncestorsList Request Handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - */ |
|
51 | - public function __construct(ModuleService $module_service) |
|
52 | - { |
|
53 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * {@inheritDoc} |
|
58 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | - */ |
|
60 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | - { |
|
62 | - if ($this->module === null) { |
|
63 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | - } |
|
65 | - |
|
66 | - $tree = $request->getAttribute('tree'); |
|
67 | - assert($tree instanceof Tree); |
|
68 | - |
|
69 | - $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
70 | - |
|
71 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
72 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
73 | - |
|
74 | - return $this->viewResponse($this->module->name() . '::statistics-page', [ |
|
75 | - 'module_name' => $this->module->name(), |
|
76 | - 'title' => I18N::translate('Sosa Statistics'), |
|
77 | - 'tree' => $tree, |
|
78 | - 'theme' => app(ModuleThemeInterface::class), |
|
79 | - 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
80 | - 'general_stats' => $this->statisticsGeneral($sosa_stats_service), |
|
81 | - 'generation_stats' => $this->statisticsByGenerations($sosa_stats_service), |
|
82 | - 'generation_depth' => $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(), |
|
83 | - 'multiple_sosas' => $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'), |
|
84 | - 'sosa_dispersion_g2' => $sosa_stats_service->ancestorsDispersionForGeneration(2), |
|
85 | - 'sosa_dispersion_g3' => $sosa_stats_service->ancestorsDispersionForGeneration(3), |
|
86 | - 'gen_depth_g3' => $sosa_stats_service->generationDepthStatsAtGeneration(3) |
|
87 | - ]); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Retrieve and compute the global statistics of ancestors for the tree. |
|
92 | - * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse... |
|
93 | - * |
|
94 | - * @param SosaStatisticsService $sosa_stats_service |
|
95 | - * @return array<string, int|float> |
|
96 | - */ |
|
97 | - private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array |
|
98 | - { |
|
99 | - $ancestors_count = $sosa_stats_service->totalAncestors(); |
|
100 | - $ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors(); |
|
101 | - $individual_count = $sosa_stats_service->totalIndividuals(); |
|
102 | - |
|
103 | - return [ |
|
104 | - 'sosa_count' => $ancestors_count, |
|
105 | - 'distinct_count' => $ancestors_distinct_count, |
|
106 | - 'sosa_rate' => $this->safeDivision( |
|
107 | - BigInteger::of($ancestors_distinct_count), |
|
108 | - BigInteger::of($individual_count) |
|
109 | - ), |
|
110 | - 'mean_gen_time' => $sosa_stats_service->meanGenerationTime() |
|
111 | - ]; |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * Retrieve and compute the statistics of ancestors by generations. |
|
116 | - * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics... |
|
117 | - * |
|
118 | - * @param SosaStatisticsService $sosa_stats_service |
|
119 | - * @return array<int, array<string, int|float>> |
|
120 | - */ |
|
121 | - private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array |
|
122 | - { |
|
123 | - $stats_by_gen = $sosa_stats_service->statisticsByGenerations(); |
|
124 | - |
|
125 | - $generation_stats = array(); |
|
126 | - |
|
127 | - foreach ($stats_by_gen as $gen => $stats_gen) { |
|
128 | - $gen_diff = $gen > 1 ? |
|
129 | - (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] : |
|
130 | - 1; |
|
131 | - $generation_stats[$gen] = array( |
|
132 | - 'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'], |
|
133 | - 'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'], |
|
134 | - 'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(), |
|
135 | - 'known' => (int) $stats_gen['sosaCount'], |
|
136 | - 'perc_known' => $this->safeDivision( |
|
137 | - BigInteger::of((int) $stats_gen['sosaCount']), |
|
138 | - BigInteger::of(2)->power($gen - 1) |
|
139 | - ), |
|
140 | - 'missing' => $gen > 1 ? |
|
141 | - 2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] : |
|
142 | - 0, |
|
143 | - 'perc_missing' => $gen > 1 ? |
|
144 | - 1 - $this->safeDivision( |
|
145 | - BigInteger::of((int) $stats_gen['sosaCount']), |
|
146 | - BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount']) |
|
147 | - ) : |
|
148 | - 0, |
|
149 | - 'total_known' => (int) $stats_gen['sosaTotalCount'], |
|
150 | - 'perc_total_known' => $this->safeDivision( |
|
151 | - BigInteger::of((int) $stats_gen['sosaTotalCount']), |
|
152 | - BigInteger::of(2)->power($gen)->minus(1) |
|
153 | - ), |
|
154 | - 'different' => $gen_diff, |
|
155 | - 'perc_different' => $this->safeDivision( |
|
156 | - BigInteger::of($gen_diff), |
|
157 | - BigInteger::of((int) $stats_gen['sosaCount']) |
|
158 | - ), |
|
159 | - 'total_different' => (int) $stats_gen['diffSosaTotalCount'] |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - return $generation_stats; |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * Return the result of a division, and a default value if denominator is 0 |
|
168 | - * |
|
169 | - * @param BigInteger $p Numerator |
|
170 | - * @param BigInteger $q Denominator |
|
171 | - * @param int $scale Rounding scale |
|
172 | - * @param float $default Value if denominator is 0 |
|
173 | - * @return float |
|
174 | - */ |
|
175 | - private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float |
|
176 | - { |
|
177 | - return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat(); |
|
178 | - } |
|
39 | + use ViewResponseTrait; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var SosaModule|null $module |
|
43 | + */ |
|
44 | + private $module; |
|
45 | + |
|
46 | + /** |
|
47 | + * Constructor for AncestorsList Request Handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + */ |
|
51 | + public function __construct(ModuleService $module_service) |
|
52 | + { |
|
53 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * {@inheritDoc} |
|
58 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
59 | + */ |
|
60 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
61 | + { |
|
62 | + if ($this->module === null) { |
|
63 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
64 | + } |
|
65 | + |
|
66 | + $tree = $request->getAttribute('tree'); |
|
67 | + assert($tree instanceof Tree); |
|
68 | + |
|
69 | + $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
70 | + |
|
71 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
72 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
73 | + |
|
74 | + return $this->viewResponse($this->module->name() . '::statistics-page', [ |
|
75 | + 'module_name' => $this->module->name(), |
|
76 | + 'title' => I18N::translate('Sosa Statistics'), |
|
77 | + 'tree' => $tree, |
|
78 | + 'theme' => app(ModuleThemeInterface::class), |
|
79 | + 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
80 | + 'general_stats' => $this->statisticsGeneral($sosa_stats_service), |
|
81 | + 'generation_stats' => $this->statisticsByGenerations($sosa_stats_service), |
|
82 | + 'generation_depth' => $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(), |
|
83 | + 'multiple_sosas' => $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'), |
|
84 | + 'sosa_dispersion_g2' => $sosa_stats_service->ancestorsDispersionForGeneration(2), |
|
85 | + 'sosa_dispersion_g3' => $sosa_stats_service->ancestorsDispersionForGeneration(3), |
|
86 | + 'gen_depth_g3' => $sosa_stats_service->generationDepthStatsAtGeneration(3) |
|
87 | + ]); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Retrieve and compute the global statistics of ancestors for the tree. |
|
92 | + * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse... |
|
93 | + * |
|
94 | + * @param SosaStatisticsService $sosa_stats_service |
|
95 | + * @return array<string, int|float> |
|
96 | + */ |
|
97 | + private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array |
|
98 | + { |
|
99 | + $ancestors_count = $sosa_stats_service->totalAncestors(); |
|
100 | + $ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors(); |
|
101 | + $individual_count = $sosa_stats_service->totalIndividuals(); |
|
102 | + |
|
103 | + return [ |
|
104 | + 'sosa_count' => $ancestors_count, |
|
105 | + 'distinct_count' => $ancestors_distinct_count, |
|
106 | + 'sosa_rate' => $this->safeDivision( |
|
107 | + BigInteger::of($ancestors_distinct_count), |
|
108 | + BigInteger::of($individual_count) |
|
109 | + ), |
|
110 | + 'mean_gen_time' => $sosa_stats_service->meanGenerationTime() |
|
111 | + ]; |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * Retrieve and compute the statistics of ancestors by generations. |
|
116 | + * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics... |
|
117 | + * |
|
118 | + * @param SosaStatisticsService $sosa_stats_service |
|
119 | + * @return array<int, array<string, int|float>> |
|
120 | + */ |
|
121 | + private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array |
|
122 | + { |
|
123 | + $stats_by_gen = $sosa_stats_service->statisticsByGenerations(); |
|
124 | + |
|
125 | + $generation_stats = array(); |
|
126 | + |
|
127 | + foreach ($stats_by_gen as $gen => $stats_gen) { |
|
128 | + $gen_diff = $gen > 1 ? |
|
129 | + (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] : |
|
130 | + 1; |
|
131 | + $generation_stats[$gen] = array( |
|
132 | + 'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'], |
|
133 | + 'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'], |
|
134 | + 'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(), |
|
135 | + 'known' => (int) $stats_gen['sosaCount'], |
|
136 | + 'perc_known' => $this->safeDivision( |
|
137 | + BigInteger::of((int) $stats_gen['sosaCount']), |
|
138 | + BigInteger::of(2)->power($gen - 1) |
|
139 | + ), |
|
140 | + 'missing' => $gen > 1 ? |
|
141 | + 2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] : |
|
142 | + 0, |
|
143 | + 'perc_missing' => $gen > 1 ? |
|
144 | + 1 - $this->safeDivision( |
|
145 | + BigInteger::of((int) $stats_gen['sosaCount']), |
|
146 | + BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount']) |
|
147 | + ) : |
|
148 | + 0, |
|
149 | + 'total_known' => (int) $stats_gen['sosaTotalCount'], |
|
150 | + 'perc_total_known' => $this->safeDivision( |
|
151 | + BigInteger::of((int) $stats_gen['sosaTotalCount']), |
|
152 | + BigInteger::of(2)->power($gen)->minus(1) |
|
153 | + ), |
|
154 | + 'different' => $gen_diff, |
|
155 | + 'perc_different' => $this->safeDivision( |
|
156 | + BigInteger::of($gen_diff), |
|
157 | + BigInteger::of((int) $stats_gen['sosaCount']) |
|
158 | + ), |
|
159 | + 'total_different' => (int) $stats_gen['diffSosaTotalCount'] |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + return $generation_stats; |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * Return the result of a division, and a default value if denominator is 0 |
|
168 | + * |
|
169 | + * @param BigInteger $p Numerator |
|
170 | + * @param BigInteger $q Denominator |
|
171 | + * @param int $scale Rounding scale |
|
172 | + * @param float $default Value if denominator is 0 |
|
173 | + * @return float |
|
174 | + */ |
|
175 | + private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float |
|
176 | + { |
|
177 | + return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat(); |
|
178 | + } |
|
179 | 179 | } |
@@ -67,10 +67,10 @@ |
||
67 | 67 | $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
68 | 68 | $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
69 | 69 | |
70 | - $response = [ 'cells' => [] ]; |
|
70 | + $response = ['cells' => []]; |
|
71 | 71 | $last_pedi_collapse = 0; |
72 | 72 | foreach ($pedi_collapse_data as $gen => $rec) { |
73 | - $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
73 | + $response['cells'][$gen] = view($this->module->name().'::components/pedigree-collapse-cell', [ |
|
74 | 74 | 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
75 | 75 | 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
76 | 76 | ]); |
@@ -33,51 +33,51 @@ |
||
33 | 33 | */ |
34 | 34 | class PedigreeCollapseData implements RequestHandlerInterface |
35 | 35 | { |
36 | - /** |
|
37 | - * @var SosaModule|null $module |
|
38 | - */ |
|
39 | - private $module; |
|
36 | + /** |
|
37 | + * @var SosaModule|null $module |
|
38 | + */ |
|
39 | + private $module; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor for PedigreeCollapseData Request Handler |
|
43 | - * |
|
44 | - * @param ModuleService $module_service |
|
45 | - */ |
|
46 | - public function __construct(ModuleService $module_service) |
|
47 | - { |
|
48 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
49 | - } |
|
41 | + /** |
|
42 | + * Constructor for PedigreeCollapseData Request Handler |
|
43 | + * |
|
44 | + * @param ModuleService $module_service |
|
45 | + */ |
|
46 | + public function __construct(ModuleService $module_service) |
|
47 | + { |
|
48 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * {@inheritDoc} |
|
53 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
54 | - */ |
|
55 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
56 | - { |
|
57 | - if ($this->module === null) { |
|
58 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
59 | - } |
|
51 | + /** |
|
52 | + * {@inheritDoc} |
|
53 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
54 | + */ |
|
55 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
56 | + { |
|
57 | + if ($this->module === null) { |
|
58 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
59 | + } |
|
60 | 60 | |
61 | - $tree = $request->getAttribute('tree'); |
|
62 | - assert($tree instanceof Tree); |
|
61 | + $tree = $request->getAttribute('tree'); |
|
62 | + assert($tree instanceof Tree); |
|
63 | 63 | |
64 | - $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
64 | + $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
65 | 65 | |
66 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
67 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
68 | - $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
|
66 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
67 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
68 | + $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
|
69 | 69 | |
70 | - $response = [ 'cells' => [] ]; |
|
71 | - $last_pedi_collapse = 0; |
|
72 | - foreach ($pedi_collapse_data as $gen => $rec) { |
|
73 | - $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
74 | - 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
|
75 | - 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
|
76 | - ]); |
|
77 | - $last_pedi_collapse = $rec['pedi_collapse_roots']; |
|
78 | - } |
|
79 | - $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2); |
|
70 | + $response = [ 'cells' => [] ]; |
|
71 | + $last_pedi_collapse = 0; |
|
72 | + foreach ($pedi_collapse_data as $gen => $rec) { |
|
73 | + $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
74 | + 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
|
75 | + 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
|
76 | + ]); |
|
77 | + $last_pedi_collapse = $rec['pedi_collapse_roots']; |
|
78 | + } |
|
79 | + $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2); |
|
80 | 80 | |
81 | - return response($response, StatusCodeInterface::STATUS_OK); |
|
82 | - } |
|
81 | + return response($response, StatusCodeInterface::STATUS_OK); |
|
82 | + } |
|
83 | 83 | } |
@@ -30,52 +30,52 @@ |
||
30 | 30 | */ |
31 | 31 | class SosaConfigAction implements RequestHandlerInterface |
32 | 32 | { |
33 | - /** |
|
34 | - * @var UserService $user_service |
|
35 | - */ |
|
36 | - private $user_service; |
|
33 | + /** |
|
34 | + * @var UserService $user_service |
|
35 | + */ |
|
36 | + private $user_service; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor for SosaConfigAction Request Handler |
|
40 | - * |
|
41 | - * @param UserService $user_service |
|
42 | - */ |
|
43 | - public function __construct(UserService $user_service) |
|
44 | - { |
|
45 | - $this->user_service = $user_service; |
|
46 | - } |
|
38 | + /** |
|
39 | + * Constructor for SosaConfigAction Request Handler |
|
40 | + * |
|
41 | + * @param UserService $user_service |
|
42 | + */ |
|
43 | + public function __construct(UserService $user_service) |
|
44 | + { |
|
45 | + $this->user_service = $user_service; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
51 | - */ |
|
52 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
53 | - { |
|
54 | - $tree = $request->getAttribute('tree'); |
|
55 | - assert($tree instanceof Tree); |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
51 | + */ |
|
52 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
53 | + { |
|
54 | + $tree = $request->getAttribute('tree'); |
|
55 | + assert($tree instanceof Tree); |
|
56 | 56 | |
57 | - $params = $request->getParsedBody(); |
|
58 | - assert(is_array($params)); |
|
57 | + $params = $request->getParsedBody(); |
|
58 | + assert(is_array($params)); |
|
59 | 59 | |
60 | - $user_id = (int) $params['sosa-userid']; |
|
61 | - $root_id = $params['sosa-rootid'] ?? ''; |
|
62 | - $max_gen = $params['sosa-maxgen'] ?? ''; |
|
60 | + $user_id = (int) $params['sosa-userid']; |
|
61 | + $root_id = $params['sosa-rootid'] ?? ''; |
|
62 | + $max_gen = $params['sosa-maxgen'] ?? ''; |
|
63 | 63 | |
64 | - if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) { |
|
65 | - $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
66 | - if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
67 | - $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
68 | - $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', $max_gen); |
|
69 | - FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
70 | - return redirect(route(SosaConfig::class, [ |
|
71 | - 'tree' => $tree->name(), |
|
72 | - 'compute' => 'yes', |
|
73 | - 'user_id' => $user_id |
|
74 | - ])); |
|
75 | - } |
|
76 | - } |
|
64 | + if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) { |
|
65 | + $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
66 | + if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
67 | + $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
68 | + $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', $max_gen); |
|
69 | + FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
70 | + return redirect(route(SosaConfig::class, [ |
|
71 | + 'tree' => $tree->name(), |
|
72 | + 'compute' => 'yes', |
|
73 | + 'user_id' => $user_id |
|
74 | + ])); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
79 | - return redirect(route(SosaConfig::class, ['tree' => $tree->name()])); |
|
80 | - } |
|
78 | + FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
79 | + return redirect(route(SosaConfig::class, ['tree' => $tree->name()])); |
|
80 | + } |
|
81 | 81 | } |
@@ -57,7 +57,7 @@ |
||
57 | 57 | $params = $request->getParsedBody(); |
58 | 58 | assert(is_array($params)); |
59 | 59 | |
60 | - $user_id = (int) $params['sosa-userid']; |
|
60 | + $user_id = (int)$params['sosa-userid']; |
|
61 | 61 | $root_id = $params['sosa-rootid'] ?? ''; |
62 | 62 | $max_gen = $params['sosa-maxgen'] ?? ''; |
63 | 63 |
@@ -86,16 +86,15 @@ |
||
86 | 86 | $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
87 | 87 | foreach ($users_root as $key => $user_root) { |
88 | 88 | $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
89 | - (int) $user_root['max_gen'] : |
|
90 | - $max_gen_system; |
|
89 | + (int)$user_root['max_gen'] : $max_gen_system; |
|
91 | 90 | }; |
92 | 91 | |
93 | - return $this->viewResponse($this->module->name() . '::config-page', [ |
|
92 | + return $this->viewResponse($this->module->name().'::config-page', [ |
|
94 | 93 | 'module_name' => $this->module->name(), |
95 | 94 | 'title' => I18N::translate('Sosa Configuration'), |
96 | 95 | 'tree' => $tree, |
97 | 96 | 'user_id' => $request->getAttribute('user'), |
98 | - 'selected_user_id' => (int) ($request->getQueryParams()['user_id'] ?? 0), |
|
97 | + 'selected_user_id' => (int)($request->getQueryParams()['user_id'] ?? 0), |
|
99 | 98 | 'immediate_compute' => ($request->getQueryParams()['compute'] ?? '') == 'yes', |
100 | 99 | 'users_root' => $users_root |
101 | 100 | ]); |
@@ -32,72 +32,72 @@ |
||
32 | 32 | */ |
33 | 33 | class SosaConfig implements RequestHandlerInterface |
34 | 34 | { |
35 | - use ViewResponseTrait; |
|
35 | + use ViewResponseTrait; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var SosaModule|null $module |
|
39 | - */ |
|
40 | - private $module; |
|
37 | + /** |
|
38 | + * @var SosaModule|null $module |
|
39 | + */ |
|
40 | + private $module; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor for SosaConfig Request Handler |
|
44 | - * |
|
45 | - * @param ModuleService $module_service |
|
46 | - */ |
|
47 | - public function __construct(ModuleService $module_service) |
|
48 | - { |
|
49 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Constructor for SosaConfig Request Handler |
|
44 | + * |
|
45 | + * @param ModuleService $module_service |
|
46 | + */ |
|
47 | + public function __construct(ModuleService $module_service) |
|
48 | + { |
|
49 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | - */ |
|
56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | - { |
|
58 | - if ($this->module === null) { |
|
59 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | - } |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | + */ |
|
56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | + { |
|
58 | + if ($this->module === null) { |
|
59 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | + } |
|
61 | 61 | |
62 | - $tree = $request->getAttribute('tree'); |
|
63 | - assert($tree instanceof Tree); |
|
62 | + $tree = $request->getAttribute('tree'); |
|
63 | + assert($tree instanceof Tree); |
|
64 | 64 | |
65 | - $users_root = array(); |
|
66 | - if (Auth::check()) { |
|
67 | - /** @var \Fisharebest\Webtrees\User $user */ |
|
68 | - $user = Auth::user(); |
|
69 | - $users_root[] = [ |
|
70 | - 'user' => $user, |
|
71 | - 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'), |
|
72 | - 'max_gen' => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN') |
|
73 | - ]; |
|
65 | + $users_root = array(); |
|
66 | + if (Auth::check()) { |
|
67 | + /** @var \Fisharebest\Webtrees\User $user */ |
|
68 | + $user = Auth::user(); |
|
69 | + $users_root[] = [ |
|
70 | + 'user' => $user, |
|
71 | + 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'), |
|
72 | + 'max_gen' => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN') |
|
73 | + ]; |
|
74 | 74 | |
75 | - if (Auth::isManager($tree)) { |
|
76 | - $default_user = new DefaultUser(); |
|
77 | - $users_root[] = [ |
|
78 | - 'user' => $default_user, |
|
79 | - 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'), |
|
80 | - 'max_gen' => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN') |
|
81 | - ]; |
|
82 | - } |
|
83 | - } |
|
75 | + if (Auth::isManager($tree)) { |
|
76 | + $default_user = new DefaultUser(); |
|
77 | + $users_root[] = [ |
|
78 | + 'user' => $default_user, |
|
79 | + 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'), |
|
80 | + 'max_gen' => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN') |
|
81 | + ]; |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - // Use the system max generations if not set |
|
86 | - $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
|
87 | - foreach ($users_root as $key => $user_root) { |
|
88 | - $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
|
89 | - (int) $user_root['max_gen'] : |
|
90 | - $max_gen_system; |
|
91 | - }; |
|
85 | + // Use the system max generations if not set |
|
86 | + $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
|
87 | + foreach ($users_root as $key => $user_root) { |
|
88 | + $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
|
89 | + (int) $user_root['max_gen'] : |
|
90 | + $max_gen_system; |
|
91 | + }; |
|
92 | 92 | |
93 | - return $this->viewResponse($this->module->name() . '::config-page', [ |
|
94 | - 'module_name' => $this->module->name(), |
|
95 | - 'title' => I18N::translate('Sosa Configuration'), |
|
96 | - 'tree' => $tree, |
|
97 | - 'user_id' => $request->getAttribute('user'), |
|
98 | - 'selected_user_id' => (int) ($request->getQueryParams()['user_id'] ?? 0), |
|
99 | - 'immediate_compute' => ($request->getQueryParams()['compute'] ?? '') == 'yes', |
|
100 | - 'users_root' => $users_root |
|
101 | - ]); |
|
102 | - } |
|
93 | + return $this->viewResponse($this->module->name() . '::config-page', [ |
|
94 | + 'module_name' => $this->module->name(), |
|
95 | + 'title' => I18N::translate('Sosa Configuration'), |
|
96 | + 'tree' => $tree, |
|
97 | + 'user_id' => $request->getAttribute('user'), |
|
98 | + 'selected_user_id' => (int) ($request->getQueryParams()['user_id'] ?? 0), |
|
99 | + 'immediate_compute' => ($request->getQueryParams()['compute'] ?? '') == 'yes', |
|
100 | + 'users_root' => $users_root |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function boot() : void |
36 | 36 | { |
37 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
37 | + View::registerNamespace($this->name(), $this->resourcesFolder().'views/'); |
|
38 | 38 | |
39 | 39 | $this->loadRoutes(app(RouterContainer::class)->getMap()); |
40 | 40 | } |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | */ |
46 | 46 | public function resourcesFolder(): string |
47 | 47 | { |
48 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
48 | + return Webtrees::MODULES_DIR.trim($this->name(), '_').'/resources/'; |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | /** |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | */ |
73 | 73 | public function customTranslations(string $language) : array |
74 | 74 | { |
75 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
75 | + $translation_file = $this->resourcesFolder().'lang/'.$language.'/messages.php'; |
|
76 | 76 | |
77 | 77 | try { |
78 | 78 | $translation = new Translation($translation_file); |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | { |
101 | 101 | /** @var ModuleThemeInterface $theme */ |
102 | 102 | $theme = app(ModuleThemeInterface::class); |
103 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
103 | + $css_file = $this->resourcesFolder().'css/'.$theme->name().'.min.css'; |
|
104 | 104 | |
105 | - if(file_exists($css_file)) { |
|
106 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
105 | + if (file_exists($css_file)) { |
|
106 | + return $this->assetUrl('css/'.$theme->name().'.min.css'); |
|
107 | 107 | } |
108 | 108 | else { |
109 | 109 | return $this->assetUrl('css/default.min.css'); |
@@ -104,8 +104,7 @@ |
||
104 | 104 | |
105 | 105 | if(file_exists($css_file)) { |
106 | 106 | return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
107 | - } |
|
108 | - else { |
|
107 | + } else { |
|
109 | 108 | return $this->assetUrl('css/default.min.css'); |
110 | 109 | } |
111 | 110 | } |
@@ -24,80 +24,80 @@ |
||
24 | 24 | */ |
25 | 25 | trait ModuleMyArtJaubTrait |
26 | 26 | { |
27 | - use ModuleCustomTrait; |
|
27 | + use ModuleCustomTrait; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
31 | - */ |
|
32 | - public function boot() : void |
|
33 | - { |
|
34 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
29 | + /** |
|
30 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
31 | + */ |
|
32 | + public function boot() : void |
|
33 | + { |
|
34 | + View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
35 | 35 | |
36 | - $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
37 | - } |
|
36 | + $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
41 | - */ |
|
42 | - public function resourcesFolder(): string |
|
43 | - { |
|
44 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
45 | - } |
|
39 | + /** |
|
40 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
41 | + */ |
|
42 | + public function resourcesFolder(): string |
|
43 | + { |
|
44 | + return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
49 | - */ |
|
50 | - public function customModuleAuthorName() : string |
|
51 | - { |
|
52 | - return 'Jonathan Jaubart'; |
|
53 | - } |
|
47 | + /** |
|
48 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
49 | + */ |
|
50 | + public function customModuleAuthorName() : string |
|
51 | + { |
|
52 | + return 'Jonathan Jaubart'; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
57 | - */ |
|
58 | - public function customModuleSupportUrl() : string |
|
59 | - { |
|
60 | - return 'https://github.com/jon48/webtrees-lib'; |
|
61 | - } |
|
55 | + /** |
|
56 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
57 | + */ |
|
58 | + public function customModuleSupportUrl() : string |
|
59 | + { |
|
60 | + return 'https://github.com/jon48/webtrees-lib'; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
65 | - * |
|
66 | - * @return array<string, string> |
|
67 | - */ |
|
68 | - public function customTranslations(string $language) : array |
|
69 | - { |
|
70 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
63 | + /** |
|
64 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
65 | + * |
|
66 | + * @return array<string, string> |
|
67 | + */ |
|
68 | + public function customTranslations(string $language) : array |
|
69 | + { |
|
70 | + $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
71 | 71 | |
72 | - try { |
|
73 | - $translation = new Translation($translation_file); |
|
74 | - return $translation->asArray(); |
|
75 | - } catch (\Exception $e) { } |
|
72 | + try { |
|
73 | + $translation = new Translation($translation_file); |
|
74 | + return $translation->asArray(); |
|
75 | + } catch (\Exception $e) { } |
|
76 | 76 | |
77 | - return []; |
|
78 | - } |
|
77 | + return []; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes |
|
82 | - */ |
|
83 | - public function loadRoutes(Map $router): void { } |
|
80 | + /** |
|
81 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes |
|
82 | + */ |
|
83 | + public function loadRoutes(Map $router): void { } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl |
|
87 | - */ |
|
88 | - public function moduleCssUrl() : string |
|
89 | - { |
|
90 | - /** @var ModuleThemeInterface $theme */ |
|
91 | - $theme = app(ModuleThemeInterface::class); |
|
92 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
85 | + /** |
|
86 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl |
|
87 | + */ |
|
88 | + public function moduleCssUrl() : string |
|
89 | + { |
|
90 | + /** @var ModuleThemeInterface $theme */ |
|
91 | + $theme = app(ModuleThemeInterface::class); |
|
92 | + $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
93 | 93 | |
94 | - if(file_exists($css_file)) { |
|
95 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
96 | - } |
|
97 | - else { |
|
98 | - return $this->assetUrl('css/default.min.css'); |
|
99 | - } |
|
100 | - } |
|
94 | + if(file_exists($css_file)) { |
|
95 | + return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
96 | + } |
|
97 | + else { |
|
98 | + return $this->assetUrl('css/default.min.css'); |
|
99 | + } |
|
100 | + } |
|
101 | 101 | |
102 | 102 | } |
103 | 103 | |
104 | 104 | \ No newline at end of file |
@@ -30,10 +30,10 @@ |
||
30 | 30 | * @param string $gedcom |
31 | 31 | * @return NULL|\MyArtJaub\Webtrees\Family |
32 | 32 | */ |
33 | - public static function getIntance($xref, Tree $tree, $gedcom = null){ |
|
33 | + public static function getIntance($xref, Tree $tree, $gedcom = null) { |
|
34 | 34 | $dfam = null; |
35 | 35 | $fam = fw\Family::getInstance($xref, $tree, $gedcom); |
36 | - if($fam){ |
|
36 | + if ($fam) { |
|
37 | 37 | $dfam = new Family($fam); |
38 | 38 | } |
39 | 39 | return $dfam; |
@@ -67,7 +67,7 @@ |
||
67 | 67 | if (($fact->getDate() || $fact->getPlace()) && $fact->canShow()) { |
68 | 68 | switch ($style) { |
69 | 69 | case 10: |
70 | - return '<i>'.$fact->getLabel().' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactDateShort($fact) .' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactPlaceShort($fact, '%1') .'</i>'; |
|
70 | + return '<i>'.$fact->getLabel().' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactDateShort($fact) .' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactPlaceShort($fact, '%1') .'</i>'; |
|
71 | 71 | default: |
72 | 72 | return $this->gedcomrecord->formatFirstMajorFact($facts, $style); |
73 | 73 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @param \Fisharebest\Webtrees\GedcomRecord $gedcomrecord_in The GedcomRecord to extend |
29 | 29 | */ |
30 | - public function __construct(\Fisharebest\Webtrees\GedcomRecord $gedcomrecord_in){ |
|
30 | + public function __construct(\Fisharebest\Webtrees\GedcomRecord $gedcomrecord_in) { |
|
31 | 31 | $this->gedcomrecord = $gedcomrecord_in; |
32 | 32 | } |
33 | 33 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * |
37 | 37 | * @return \Fisharebest\Webtrees\GedcomRecord Embedded gedcom record |
38 | 38 | */ |
39 | - public function getDerivedRecord(){ |
|
39 | + public function getDerivedRecord() { |
|
40 | 40 | return $this->gedcomrecord; |
41 | 41 | } |
42 | 42 | |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | if (($fact->getDate() || $fact->getPlace()) && $fact->canShow()) { |
68 | 68 | switch ($style) { |
69 | 69 | case 10: |
70 | - return '<i>'.$fact->getLabel().' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactDateShort($fact) .' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactPlaceShort($fact, '%1') .'</i>'; |
|
70 | + return '<i>'.$fact->getLabel().' '.\MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactDateShort($fact).' '.\MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactPlaceShort($fact, '%1').'</i>'; |
|
71 | 71 | default: |
72 | 72 | return $this->gedcomrecord->formatFirstMajorFact($facts, $style); |
73 | 73 | } |