@@ -32,54 +32,54 @@ |
||
32 | 32 | */ |
33 | 33 | class SosaComputeAction implements RequestHandlerInterface |
34 | 34 | { |
35 | - private UserService $user_service; |
|
35 | + private UserService $user_service; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for SosaConfigAction Request Handler |
|
39 | - * |
|
40 | - * @param UserService $user_service |
|
41 | - */ |
|
42 | - public function __construct(UserService $user_service) |
|
43 | - { |
|
44 | - $this->user_service = $user_service; |
|
45 | - } |
|
37 | + /** |
|
38 | + * Constructor for SosaConfigAction Request Handler |
|
39 | + * |
|
40 | + * @param UserService $user_service |
|
41 | + */ |
|
42 | + public function __construct(UserService $user_service) |
|
43 | + { |
|
44 | + $this->user_service = $user_service; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | - */ |
|
51 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | - { |
|
53 | - $tree = Validator::attributes($request)->tree(); |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | + */ |
|
51 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | + { |
|
53 | + $tree = Validator::attributes($request)->tree(); |
|
54 | 54 | |
55 | - $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
|
56 | - $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
|
55 | + $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
|
56 | + $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
|
57 | 57 | |
58 | - if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) { |
|
59 | - $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
58 | + if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) { |
|
59 | + $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
60 | 60 | |
61 | - /** @var SosaCalculatorService $sosa_calc_service */ |
|
62 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
61 | + /** @var SosaCalculatorService $sosa_calc_service */ |
|
62 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
63 | 63 | |
64 | - if ( |
|
65 | - $partial_from !== '' && |
|
66 | - ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
67 | - ) { |
|
68 | - $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
69 | - } else { |
|
70 | - $res = $sosa_calc_service->computeAll(); |
|
71 | - } |
|
64 | + if ( |
|
65 | + $partial_from !== '' && |
|
66 | + ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
67 | + ) { |
|
68 | + $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
69 | + } else { |
|
70 | + $res = $sosa_calc_service->computeAll(); |
|
71 | + } |
|
72 | 72 | |
73 | - return $res ? |
|
74 | - response('', 200) : |
|
75 | - response( |
|
76 | - I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
77 | - StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
78 | - ); |
|
79 | - } |
|
80 | - return response( |
|
81 | - I18N::translate('You do not have permission to modify the user.'), |
|
82 | - StatusCodeInterface::STATUS_FORBIDDEN |
|
83 | - ); |
|
84 | - } |
|
73 | + return $res ? |
|
74 | + response('', 200) : |
|
75 | + response( |
|
76 | + I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
77 | + StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
78 | + ); |
|
79 | + } |
|
80 | + return response( |
|
81 | + I18N::translate('You do not have permission to modify the user.'), |
|
82 | + StatusCodeInterface::STATUS_FORBIDDEN |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | } |
@@ -38,142 +38,142 @@ |
||
38 | 38 | */ |
39 | 39 | class SosaStatistics implements RequestHandlerInterface |
40 | 40 | { |
41 | - use ViewResponseTrait; |
|
42 | - |
|
43 | - private ?SosaModule $module; |
|
44 | - private RelationshipService $relationship_service; |
|
45 | - |
|
46 | - /** |
|
47 | - * Constructor for AncestorsList Request Handler |
|
48 | - * |
|
49 | - * @param ModuleService $module_service |
|
50 | - */ |
|
51 | - public function __construct(ModuleService $module_service, RelationshipService $relationship_service) |
|
52 | - { |
|
53 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
54 | - $this->relationship_service = $relationship_service; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * {@inheritDoc} |
|
59 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
60 | - */ |
|
61 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
62 | - { |
|
63 | - if ($this->module === null) { |
|
64 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
65 | - } |
|
66 | - |
|
67 | - $tree = Validator::attributes($request)->tree(); |
|
68 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
69 | - |
|
70 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
71 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
72 | - |
|
73 | - return $this->viewResponse($this->module->name() . '::statistics-page', [ |
|
74 | - 'module_name' => $this->module->name(), |
|
75 | - 'title' => I18N::translate('Sosa Statistics'), |
|
76 | - 'tree' => $tree, |
|
77 | - 'theme' => app(ModuleThemeInterface::class), |
|
78 | - 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
79 | - 'general_stats' => $this->statisticsGeneral($sosa_stats_service), |
|
80 | - 'generation_stats' => $this->statisticsByGenerations($sosa_stats_service), |
|
81 | - 'generation_depth' => $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(), |
|
82 | - 'multiple_sosas' => $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'), |
|
83 | - 'sosa_dispersion_g2' => $sosa_stats_service->ancestorsDispersionForGeneration(2), |
|
84 | - 'sosa_dispersion_g3' => $sosa_stats_service->ancestorsDispersionForGeneration(3), |
|
85 | - 'gen_depth_g3' => $sosa_stats_service->generationDepthStatsAtGeneration(3), |
|
86 | - 'relationship_service' => $this->relationship_service, |
|
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 | - } |
|
41 | + use ViewResponseTrait; |
|
42 | + |
|
43 | + private ?SosaModule $module; |
|
44 | + private RelationshipService $relationship_service; |
|
45 | + |
|
46 | + /** |
|
47 | + * Constructor for AncestorsList Request Handler |
|
48 | + * |
|
49 | + * @param ModuleService $module_service |
|
50 | + */ |
|
51 | + public function __construct(ModuleService $module_service, RelationshipService $relationship_service) |
|
52 | + { |
|
53 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
54 | + $this->relationship_service = $relationship_service; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * {@inheritDoc} |
|
59 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
60 | + */ |
|
61 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
62 | + { |
|
63 | + if ($this->module === null) { |
|
64 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
65 | + } |
|
66 | + |
|
67 | + $tree = Validator::attributes($request)->tree(); |
|
68 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
69 | + |
|
70 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
71 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
72 | + |
|
73 | + return $this->viewResponse($this->module->name() . '::statistics-page', [ |
|
74 | + 'module_name' => $this->module->name(), |
|
75 | + 'title' => I18N::translate('Sosa Statistics'), |
|
76 | + 'tree' => $tree, |
|
77 | + 'theme' => app(ModuleThemeInterface::class), |
|
78 | + 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
79 | + 'general_stats' => $this->statisticsGeneral($sosa_stats_service), |
|
80 | + 'generation_stats' => $this->statisticsByGenerations($sosa_stats_service), |
|
81 | + 'generation_depth' => $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(), |
|
82 | + 'multiple_sosas' => $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'), |
|
83 | + 'sosa_dispersion_g2' => $sosa_stats_service->ancestorsDispersionForGeneration(2), |
|
84 | + 'sosa_dispersion_g3' => $sosa_stats_service->ancestorsDispersionForGeneration(3), |
|
85 | + 'gen_depth_g3' => $sosa_stats_service->generationDepthStatsAtGeneration(3), |
|
86 | + 'relationship_service' => $this->relationship_service, |
|
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 | } |
@@ -36,71 +36,71 @@ |
||
36 | 36 | */ |
37 | 37 | class AncestorsListIndividual implements RequestHandlerInterface |
38 | 38 | { |
39 | - use ViewResponseTrait; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var SosaModule|null $module |
|
43 | - */ |
|
44 | - private $module; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var SosaRecordsService $sosa_record_service |
|
48 | - */ |
|
49 | - private $sosa_record_service; |
|
50 | - |
|
51 | - /** |
|
52 | - * Constructor for AncestorsListIndividual Request Handler |
|
53 | - * |
|
54 | - * @param ModuleService $module_service |
|
55 | - * @param SosaRecordsService $sosa_record_service |
|
56 | - */ |
|
57 | - public function __construct( |
|
58 | - ModuleService $module_service, |
|
59 | - SosaRecordsService $sosa_record_service |
|
60 | - ) { |
|
61 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
62 | - $this->sosa_record_service = $sosa_record_service; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * {@inheritDoc} |
|
67 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
68 | - */ |
|
69 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
70 | - { |
|
71 | - $this->layout = 'layouts/ajax'; |
|
72 | - |
|
73 | - if ($this->module === null) { |
|
74 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
75 | - } |
|
76 | - |
|
77 | - $tree = Validator::attributes($request)->tree(); |
|
78 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
79 | - $current_gen = Validator::attributes($request)->integer('gen', 0); |
|
80 | - |
|
81 | - if ($current_gen <= 0) { |
|
82 | - return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY); |
|
83 | - } |
|
84 | - |
|
85 | - $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen); |
|
86 | - $nb_ancestors_all = $list_ancestors->count(); |
|
87 | - |
|
88 | - /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
|
89 | - $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array { |
|
90 | - $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
91 | - return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null; |
|
92 | - })->filter(); |
|
93 | - |
|
94 | - $nb_ancestors_shown = $list_ancestors->count(); |
|
95 | - |
|
96 | - return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
97 | - 'module_name' => $this->module->name(), |
|
98 | - 'title' => I18N::translate('Sosa Ancestors'), |
|
99 | - 'tree' => $tree, |
|
100 | - 'list_ancestors' => $list_ancestors, |
|
101 | - 'nb_ancestors_all' => $nb_ancestors_all, |
|
102 | - 'nb_ancestors_theor' => pow(2, $current_gen - 1), |
|
103 | - 'nb_ancestors_shown' => $nb_ancestors_shown |
|
104 | - ]); |
|
105 | - } |
|
39 | + use ViewResponseTrait; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var SosaModule|null $module |
|
43 | + */ |
|
44 | + private $module; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var SosaRecordsService $sosa_record_service |
|
48 | + */ |
|
49 | + private $sosa_record_service; |
|
50 | + |
|
51 | + /** |
|
52 | + * Constructor for AncestorsListIndividual Request Handler |
|
53 | + * |
|
54 | + * @param ModuleService $module_service |
|
55 | + * @param SosaRecordsService $sosa_record_service |
|
56 | + */ |
|
57 | + public function __construct( |
|
58 | + ModuleService $module_service, |
|
59 | + SosaRecordsService $sosa_record_service |
|
60 | + ) { |
|
61 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
62 | + $this->sosa_record_service = $sosa_record_service; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * {@inheritDoc} |
|
67 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
68 | + */ |
|
69 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
70 | + { |
|
71 | + $this->layout = 'layouts/ajax'; |
|
72 | + |
|
73 | + if ($this->module === null) { |
|
74 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
75 | + } |
|
76 | + |
|
77 | + $tree = Validator::attributes($request)->tree(); |
|
78 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
79 | + $current_gen = Validator::attributes($request)->integer('gen', 0); |
|
80 | + |
|
81 | + if ($current_gen <= 0) { |
|
82 | + return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY); |
|
83 | + } |
|
84 | + |
|
85 | + $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen); |
|
86 | + $nb_ancestors_all = $list_ancestors->count(); |
|
87 | + |
|
88 | + /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
|
89 | + $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array { |
|
90 | + $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
91 | + return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null; |
|
92 | + })->filter(); |
|
93 | + |
|
94 | + $nb_ancestors_shown = $list_ancestors->count(); |
|
95 | + |
|
96 | + return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
97 | + 'module_name' => $this->module->name(), |
|
98 | + 'title' => I18N::translate('Sosa Ancestors'), |
|
99 | + 'tree' => $tree, |
|
100 | + 'list_ancestors' => $list_ancestors, |
|
101 | + 'nb_ancestors_all' => $nb_ancestors_all, |
|
102 | + 'nb_ancestors_theor' => pow(2, $current_gen - 1), |
|
103 | + 'nb_ancestors_shown' => $nb_ancestors_shown |
|
104 | + ]); |
|
105 | + } |
|
106 | 106 | } |
@@ -29,39 +29,39 @@ |
||
29 | 29 | */ |
30 | 30 | class SosaComputeModal implements RequestHandlerInterface |
31 | 31 | { |
32 | - /** |
|
33 | - * @var SosaModule|null $module |
|
34 | - */ |
|
35 | - private $module; |
|
32 | + /** |
|
33 | + * @var SosaModule|null $module |
|
34 | + */ |
|
35 | + private $module; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Constructor for SosaComputeModal Request Handler |
|
39 | - * |
|
40 | - * @param ModuleService $module_service |
|
41 | - */ |
|
42 | - public function __construct(ModuleService $module_service) |
|
43 | - { |
|
44 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
45 | - } |
|
37 | + /** |
|
38 | + * Constructor for SosaComputeModal Request Handler |
|
39 | + * |
|
40 | + * @param ModuleService $module_service |
|
41 | + */ |
|
42 | + public function __construct(ModuleService $module_service) |
|
43 | + { |
|
44 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * {@inheritDoc} |
|
49 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | - */ |
|
51 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | - { |
|
53 | - if ($this->module === null) { |
|
54 | - return response(view('modals/error', [ |
|
55 | - 'title' => I18N::translate('Error'), |
|
56 | - 'error' => I18N::translate('The attached module could not be found.') |
|
57 | - ])); |
|
58 | - } |
|
47 | + /** |
|
48 | + * {@inheritDoc} |
|
49 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
50 | + */ |
|
51 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
52 | + { |
|
53 | + if ($this->module === null) { |
|
54 | + return response(view('modals/error', [ |
|
55 | + 'title' => I18N::translate('Error'), |
|
56 | + 'error' => I18N::translate('The attached module could not be found.') |
|
57 | + ])); |
|
58 | + } |
|
59 | 59 | |
60 | - $tree = Validator::attributes($request)->tree(); |
|
60 | + $tree = Validator::attributes($request)->tree(); |
|
61 | 61 | |
62 | - return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | - 'tree' => $tree, |
|
64 | - 'xref' => Validator::attributes($request)->isXref()->string('xref', '') |
|
65 | - ])); |
|
66 | - } |
|
62 | + return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | + 'tree' => $tree, |
|
64 | + 'xref' => Validator::attributes($request)->isXref()->string('xref', '') |
|
65 | + ])); |
|
66 | + } |
|
67 | 67 | } |
@@ -34,48 +34,48 @@ |
||
34 | 34 | */ |
35 | 35 | class AncestorsList implements RequestHandlerInterface |
36 | 36 | { |
37 | - use ViewResponseTrait; |
|
37 | + use ViewResponseTrait; |
|
38 | 38 | |
39 | - private ?SosaModule $module; |
|
39 | + private ?SosaModule $module; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Constructor for AncestorsList 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 AncestorsList 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 = Validator::attributes($request)->tree(); |
|
62 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
61 | + $tree = Validator::attributes($request)->tree(); |
|
62 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
63 | 63 | |
64 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
65 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
64 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
65 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
66 | 66 | |
67 | - $current_gen = Validator::queryParams($request)->integer( |
|
68 | - 'gen', |
|
69 | - Validator::attributes($request)->integer('gen', 0) |
|
70 | - ); |
|
67 | + $current_gen = Validator::queryParams($request)->integer( |
|
68 | + 'gen', |
|
69 | + Validator::attributes($request)->integer('gen', 0) |
|
70 | + ); |
|
71 | 71 | |
72 | - return $this->viewResponse($this->module->name() . '::list-ancestors-page', [ |
|
73 | - 'module_name' => $this->module->name(), |
|
74 | - 'title' => I18N::translate('Sosa Ancestors'), |
|
75 | - 'tree' => $tree, |
|
76 | - 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
77 | - 'max_gen' => $sosa_stats_service->maxGeneration(), |
|
78 | - 'current_gen' => $current_gen |
|
79 | - ]); |
|
80 | - } |
|
72 | + return $this->viewResponse($this->module->name() . '::list-ancestors-page', [ |
|
73 | + 'module_name' => $this->module->name(), |
|
74 | + 'title' => I18N::translate('Sosa Ancestors'), |
|
75 | + 'tree' => $tree, |
|
76 | + 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
77 | + 'max_gen' => $sosa_stats_service->maxGeneration(), |
|
78 | + 'current_gen' => $current_gen |
|
79 | + ]); |
|
80 | + } |
|
81 | 81 | } |
@@ -33,71 +33,71 @@ |
||
33 | 33 | */ |
34 | 34 | class SosaConfig implements RequestHandlerInterface |
35 | 35 | { |
36 | - use ViewResponseTrait; |
|
36 | + use ViewResponseTrait; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @var SosaModule|null $module |
|
40 | - */ |
|
41 | - private $module; |
|
38 | + /** |
|
39 | + * @var SosaModule|null $module |
|
40 | + */ |
|
41 | + private $module; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Constructor for SosaConfig Request Handler |
|
45 | - * |
|
46 | - * @param ModuleService $module_service |
|
47 | - */ |
|
48 | - public function __construct(ModuleService $module_service) |
|
49 | - { |
|
50 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
51 | - } |
|
43 | + /** |
|
44 | + * Constructor for SosaConfig Request Handler |
|
45 | + * |
|
46 | + * @param ModuleService $module_service |
|
47 | + */ |
|
48 | + public function __construct(ModuleService $module_service) |
|
49 | + { |
|
50 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * {@inheritDoc} |
|
55 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
56 | - */ |
|
57 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
58 | - { |
|
59 | - if ($this->module === null) { |
|
60 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
61 | - } |
|
53 | + /** |
|
54 | + * {@inheritDoc} |
|
55 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
56 | + */ |
|
57 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
58 | + { |
|
59 | + if ($this->module === null) { |
|
60 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
61 | + } |
|
62 | 62 | |
63 | - $tree = Validator::attributes($request)->tree(); |
|
63 | + $tree = Validator::attributes($request)->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' => Validator::attributes($request)->user(), |
|
98 | - 'selected_user_id' => Validator::queryParams($request)->integer('user_id', 0), |
|
99 | - 'immediate_compute' => Validator::queryParams($request)->string('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' => Validator::attributes($request)->user(), |
|
98 | + 'selected_user_id' => Validator::queryParams($request)->integer('user_id', 0), |
|
99 | + 'immediate_compute' => Validator::queryParams($request)->string('compute', '') == 'yes', |
|
100 | + 'users_root' => $users_root |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | } |
@@ -32,51 +32,51 @@ |
||
32 | 32 | */ |
33 | 33 | class SosaConfigAction implements RequestHandlerInterface |
34 | 34 | { |
35 | - private UserService $user_service; |
|
36 | - private SosaRecordsService $sosa_record_service; |
|
35 | + private UserService $user_service; |
|
36 | + private SosaRecordsService $sosa_record_service; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor for SosaConfigAction Request Handler |
|
40 | - * |
|
41 | - * @param UserService $user_service |
|
42 | - * @param SosaRecordsService $sosa_records_service |
|
43 | - */ |
|
44 | - public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service) |
|
45 | - { |
|
46 | - $this->user_service = $user_service; |
|
47 | - $this->sosa_record_service = $sosa_records_service; |
|
48 | - } |
|
38 | + /** |
|
39 | + * Constructor for SosaConfigAction Request Handler |
|
40 | + * |
|
41 | + * @param UserService $user_service |
|
42 | + * @param SosaRecordsService $sosa_records_service |
|
43 | + */ |
|
44 | + public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service) |
|
45 | + { |
|
46 | + $this->user_service = $user_service; |
|
47 | + $this->sosa_record_service = $sosa_records_service; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
53 | - */ |
|
54 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
55 | - { |
|
56 | - $tree = Validator::attributes($request)->tree(); |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
53 | + */ |
|
54 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
55 | + { |
|
56 | + $tree = Validator::attributes($request)->tree(); |
|
57 | 57 | |
58 | - $user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
59 | - $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
60 | - $max_gen = Validator::parsedBody($request)->integer( |
|
61 | - 'sosa-maxgen', |
|
62 | - $this->sosa_record_service->maxSystemGenerations() |
|
63 | - ); |
|
58 | + $user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
59 | + $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
60 | + $max_gen = Validator::parsedBody($request)->integer( |
|
61 | + 'sosa-maxgen', |
|
62 | + $this->sosa_record_service->maxSystemGenerations() |
|
63 | + ); |
|
64 | 64 | |
65 | - if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) { |
|
66 | - $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
67 | - if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
68 | - $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
69 | - $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
70 | - FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
71 | - return redirect(route(SosaConfig::class, [ |
|
72 | - 'tree' => $tree->name(), |
|
73 | - 'compute' => 'yes', |
|
74 | - 'user_id' => $user_id |
|
75 | - ])); |
|
76 | - } |
|
77 | - } |
|
65 | + if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) { |
|
66 | + $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
67 | + if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
68 | + $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
69 | + $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
70 | + FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
71 | + return redirect(route(SosaConfig::class, [ |
|
72 | + 'tree' => $tree->name(), |
|
73 | + 'compute' => 'yes', |
|
74 | + 'user_id' => $user_id |
|
75 | + ])); |
|
76 | + } |
|
77 | + } |
|
78 | 78 | |
79 | - FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
80 | - return redirect(route(SosaConfig::class, ['tree' => $tree->name()])); |
|
81 | - } |
|
79 | + FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
80 | + return redirect(route(SosaConfig::class, ['tree' => $tree->name()])); |
|
81 | + } |
|
82 | 82 | } |
@@ -37,89 +37,89 @@ |
||
37 | 37 | */ |
38 | 38 | class MissingAncestorsList implements RequestHandlerInterface |
39 | 39 | { |
40 | - use ViewResponseTrait; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var SosaModule|null $module |
|
44 | - */ |
|
45 | - private $module; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var SosaRecordsService $sosa_record_service |
|
49 | - */ |
|
50 | - private $sosa_record_service; |
|
51 | - |
|
52 | - /** |
|
53 | - * Constructor for MissingAncestorsList Request Handler |
|
54 | - * |
|
55 | - * @param ModuleService $module_service |
|
56 | - * @param SosaRecordsService $sosa_record_service |
|
57 | - */ |
|
58 | - public function __construct( |
|
59 | - ModuleService $module_service, |
|
60 | - SosaRecordsService $sosa_record_service |
|
61 | - ) { |
|
62 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
63 | - $this->sosa_record_service = $sosa_record_service; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * {@inheritDoc} |
|
68 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
69 | - */ |
|
70 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
71 | - { |
|
72 | - if ($this->module === null) { |
|
73 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
74 | - } |
|
75 | - |
|
76 | - $tree = Validator::attributes($request)->tree(); |
|
77 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
78 | - |
|
79 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
80 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
81 | - |
|
82 | - $current_gen = Validator::queryParams($request)->integer( |
|
83 | - 'gen', |
|
84 | - Validator::attributes($request)->integer('gen', 0) |
|
85 | - ); |
|
86 | - |
|
87 | - $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen); |
|
88 | - $nb_missing_diff = $list_missing->sum(function (stdClass $value): int { |
|
89 | - return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0); |
|
90 | - }); |
|
91 | - |
|
92 | - $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor { |
|
93 | - $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
94 | - if ($indi !== null && $indi->canShowName()) { |
|
95 | - return new MissingAncestor( |
|
96 | - $indi, |
|
97 | - (int) $value->majs_sosa, |
|
98 | - $value->majs_fat_id === null, |
|
99 | - $value->majs_mot_id === null |
|
100 | - ); |
|
101 | - } |
|
102 | - return null; |
|
103 | - })->filter(); |
|
104 | - |
|
105 | - $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int { |
|
106 | - return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0); |
|
107 | - }); |
|
108 | - |
|
109 | - return $this->viewResponse($this->module->name() . '::list-missing-page', [ |
|
110 | - 'module_name' => $this->module->name(), |
|
111 | - 'title' => I18N::translate('Missing Ancestors'), |
|
112 | - 'tree' => $tree, |
|
113 | - 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
114 | - 'max_gen' => $sosa_stats_service->maxGeneration(), |
|
115 | - 'current_gen' => $current_gen, |
|
116 | - 'list_missing' => $list_missing, |
|
117 | - 'nb_missing_diff' => $nb_missing_diff, |
|
118 | - 'nb_missing_shown' => $nb_missing_shown, |
|
119 | - 'gen_completeness' => |
|
120 | - $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1), |
|
121 | - 'gen_potential' => |
|
122 | - $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2) |
|
123 | - ]); |
|
124 | - } |
|
40 | + use ViewResponseTrait; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var SosaModule|null $module |
|
44 | + */ |
|
45 | + private $module; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var SosaRecordsService $sosa_record_service |
|
49 | + */ |
|
50 | + private $sosa_record_service; |
|
51 | + |
|
52 | + /** |
|
53 | + * Constructor for MissingAncestorsList Request Handler |
|
54 | + * |
|
55 | + * @param ModuleService $module_service |
|
56 | + * @param SosaRecordsService $sosa_record_service |
|
57 | + */ |
|
58 | + public function __construct( |
|
59 | + ModuleService $module_service, |
|
60 | + SosaRecordsService $sosa_record_service |
|
61 | + ) { |
|
62 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
63 | + $this->sosa_record_service = $sosa_record_service; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * {@inheritDoc} |
|
68 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
69 | + */ |
|
70 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
71 | + { |
|
72 | + if ($this->module === null) { |
|
73 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
74 | + } |
|
75 | + |
|
76 | + $tree = Validator::attributes($request)->tree(); |
|
77 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
78 | + |
|
79 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
80 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
81 | + |
|
82 | + $current_gen = Validator::queryParams($request)->integer( |
|
83 | + 'gen', |
|
84 | + Validator::attributes($request)->integer('gen', 0) |
|
85 | + ); |
|
86 | + |
|
87 | + $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen); |
|
88 | + $nb_missing_diff = $list_missing->sum(function (stdClass $value): int { |
|
89 | + return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0); |
|
90 | + }); |
|
91 | + |
|
92 | + $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor { |
|
93 | + $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
94 | + if ($indi !== null && $indi->canShowName()) { |
|
95 | + return new MissingAncestor( |
|
96 | + $indi, |
|
97 | + (int) $value->majs_sosa, |
|
98 | + $value->majs_fat_id === null, |
|
99 | + $value->majs_mot_id === null |
|
100 | + ); |
|
101 | + } |
|
102 | + return null; |
|
103 | + })->filter(); |
|
104 | + |
|
105 | + $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int { |
|
106 | + return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0); |
|
107 | + }); |
|
108 | + |
|
109 | + return $this->viewResponse($this->module->name() . '::list-missing-page', [ |
|
110 | + 'module_name' => $this->module->name(), |
|
111 | + 'title' => I18N::translate('Missing Ancestors'), |
|
112 | + 'tree' => $tree, |
|
113 | + 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
114 | + 'max_gen' => $sosa_stats_service->maxGeneration(), |
|
115 | + 'current_gen' => $current_gen, |
|
116 | + 'list_missing' => $list_missing, |
|
117 | + 'nb_missing_diff' => $nb_missing_diff, |
|
118 | + 'nb_missing_shown' => $nb_missing_shown, |
|
119 | + 'gen_completeness' => |
|
120 | + $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1), |
|
121 | + 'gen_potential' => |
|
122 | + $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2) |
|
123 | + ]); |
|
124 | + } |
|
125 | 125 | } |
@@ -34,49 +34,49 @@ |
||
34 | 34 | */ |
35 | 35 | class PedigreeCollapseData implements RequestHandlerInterface |
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 PedigreeCollapseData 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 PedigreeCollapseData 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 = Validator::attributes($request)->tree(); |
|
63 | - $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
62 | + $tree = Validator::attributes($request)->tree(); |
|
63 | + $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser(); |
|
64 | 64 | |
65 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
66 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
67 | - $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
|
65 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
66 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
67 | + $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData(); |
|
68 | 68 | |
69 | - $response = [ 'cells' => [] ]; |
|
70 | - $last_pedi_collapse = 0; |
|
71 | - foreach ($pedi_collapse_data as $gen => $rec) { |
|
72 | - $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
73 | - 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
|
74 | - 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
|
75 | - ]); |
|
76 | - $last_pedi_collapse = $rec['pedi_collapse_roots']; |
|
77 | - } |
|
78 | - $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2); |
|
69 | + $response = [ 'cells' => [] ]; |
|
70 | + $last_pedi_collapse = 0; |
|
71 | + foreach ($pedi_collapse_data as $gen => $rec) { |
|
72 | + $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [ |
|
73 | + 'pedi_collapse_roots' => $rec['pedi_collapse_roots'], |
|
74 | + 'pedi_collapse_xgen' => $rec['pedi_collapse_xgen'] |
|
75 | + ]); |
|
76 | + $last_pedi_collapse = $rec['pedi_collapse_roots']; |
|
77 | + } |
|
78 | + $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2); |
|
79 | 79 | |
80 | - return response($response, StatusCodeInterface::STATUS_OK); |
|
81 | - } |
|
80 | + return response($response, StatusCodeInterface::STATUS_OK); |
|
81 | + } |
|
82 | 82 | } |