@@ -35,74 +35,74 @@ |
||
35 | 35 | */ |
36 | 36 | class AncestorsListIndividual implements RequestHandlerInterface |
37 | 37 | { |
38 | - use ViewResponseTrait; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var SosaModule|null $module |
|
42 | - */ |
|
43 | - private $module; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var SosaRecordsService $sosa_record_service |
|
47 | - */ |
|
48 | - private $sosa_record_service; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for AncestorsListIndividual Request Handler |
|
52 | - * |
|
53 | - * @param ModuleService $module_service |
|
54 | - * @param SosaRecordsService $sosa_record_service |
|
55 | - */ |
|
56 | - public function __construct( |
|
57 | - ModuleService $module_service, |
|
58 | - SosaRecordsService $sosa_record_service |
|
59 | - ) { |
|
60 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
61 | - $this->sosa_record_service = $sosa_record_service; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
67 | - */ |
|
68 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
69 | - { |
|
70 | - $this->layout = 'layouts/ajax'; |
|
71 | - |
|
72 | - if ($this->module === null) { |
|
73 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
74 | - } |
|
75 | - |
|
76 | - $tree = $request->getAttribute('tree'); |
|
77 | - assert($tree instanceof Tree); |
|
78 | - |
|
79 | - $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
80 | - |
|
81 | - $current_gen = (int) ($request->getAttribute('gen') ?? 0); |
|
82 | - |
|
83 | - if ($current_gen <= 0) { |
|
84 | - return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY); |
|
85 | - } |
|
86 | - |
|
87 | - $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen); |
|
88 | - $nb_ancestors_all = $list_ancestors->count(); |
|
89 | - |
|
90 | - /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
|
91 | - $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array { |
|
92 | - $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
93 | - return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null; |
|
94 | - })->filter(); |
|
95 | - |
|
96 | - $nb_ancestors_shown = $list_ancestors->count(); |
|
97 | - |
|
98 | - return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
99 | - 'module_name' => $this->module->name(), |
|
100 | - 'title' => I18N::translate('Sosa Ancestors'), |
|
101 | - 'tree' => $tree, |
|
102 | - 'list_ancestors' => $list_ancestors, |
|
103 | - 'nb_ancestors_all' => $nb_ancestors_all, |
|
104 | - 'nb_ancestors_theor' => pow(2, $current_gen - 1), |
|
105 | - 'nb_ancestors_shown' => $nb_ancestors_shown |
|
106 | - ]); |
|
107 | - } |
|
38 | + use ViewResponseTrait; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var SosaModule|null $module |
|
42 | + */ |
|
43 | + private $module; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var SosaRecordsService $sosa_record_service |
|
47 | + */ |
|
48 | + private $sosa_record_service; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for AncestorsListIndividual Request Handler |
|
52 | + * |
|
53 | + * @param ModuleService $module_service |
|
54 | + * @param SosaRecordsService $sosa_record_service |
|
55 | + */ |
|
56 | + public function __construct( |
|
57 | + ModuleService $module_service, |
|
58 | + SosaRecordsService $sosa_record_service |
|
59 | + ) { |
|
60 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
61 | + $this->sosa_record_service = $sosa_record_service; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
67 | + */ |
|
68 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
69 | + { |
|
70 | + $this->layout = 'layouts/ajax'; |
|
71 | + |
|
72 | + if ($this->module === null) { |
|
73 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
74 | + } |
|
75 | + |
|
76 | + $tree = $request->getAttribute('tree'); |
|
77 | + assert($tree instanceof Tree); |
|
78 | + |
|
79 | + $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
80 | + |
|
81 | + $current_gen = (int) ($request->getAttribute('gen') ?? 0); |
|
82 | + |
|
83 | + if ($current_gen <= 0) { |
|
84 | + return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY); |
|
85 | + } |
|
86 | + |
|
87 | + $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen); |
|
88 | + $nb_ancestors_all = $list_ancestors->count(); |
|
89 | + |
|
90 | + /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
|
91 | + $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array { |
|
92 | + $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
93 | + return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null; |
|
94 | + })->filter(); |
|
95 | + |
|
96 | + $nb_ancestors_shown = $list_ancestors->count(); |
|
97 | + |
|
98 | + return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
99 | + 'module_name' => $this->module->name(), |
|
100 | + 'title' => I18N::translate('Sosa Ancestors'), |
|
101 | + 'tree' => $tree, |
|
102 | + 'list_ancestors' => $list_ancestors, |
|
103 | + 'nb_ancestors_all' => $nb_ancestors_all, |
|
104 | + 'nb_ancestors_theor' => pow(2, $current_gen - 1), |
|
105 | + 'nb_ancestors_shown' => $nb_ancestors_shown |
|
106 | + ]); |
|
107 | + } |
|
108 | 108 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
80 | 80 | |
81 | - $current_gen = (int) ($request->getAttribute('gen') ?? 0); |
|
81 | + $current_gen = (int)($request->getAttribute('gen') ?? 0); |
|
82 | 82 | |
83 | 83 | if ($current_gen <= 0) { |
84 | 84 | return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY); |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | $nb_ancestors_all = $list_ancestors->count(); |
89 | 89 | |
90 | 90 | /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
91 | - $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array { |
|
91 | + $list_ancestors = $list_ancestors->mapWithKeys(function(stdClass $value) use ($tree): ?array { |
|
92 | 92 | $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
93 | - return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null; |
|
93 | + return ($indi !== null && $indi->canShowName()) ? [(int)$value->majs_sosa => $indi] : null; |
|
94 | 94 | })->filter(); |
95 | 95 | |
96 | 96 | $nb_ancestors_shown = $list_ancestors->count(); |
97 | 97 | |
98 | - return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
98 | + return $this->viewResponse($this->module->name().'::list-ancestors-indi-tab', [ |
|
99 | 99 | 'module_name' => $this->module->name(), |
100 | 100 | 'title' => I18N::translate('Sosa Ancestors'), |
101 | 101 | 'tree' => $tree, |
@@ -36,88 +36,88 @@ |
||
36 | 36 | */ |
37 | 37 | class MissingAncestorsList 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 MissingAncestorsList 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 | - if ($this->module === null) { |
|
72 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
73 | - } |
|
74 | - |
|
75 | - $tree = $request->getAttribute('tree'); |
|
76 | - assert($tree instanceof Tree); |
|
77 | - |
|
78 | - $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
79 | - |
|
80 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
81 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
82 | - |
|
83 | - $current_gen = (int) ($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0); |
|
84 | - |
|
85 | - $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen); |
|
86 | - $nb_missing_diff = $list_missing->sum(function (stdClass $value): int { |
|
87 | - return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0); |
|
88 | - }); |
|
89 | - |
|
90 | - $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor { |
|
91 | - $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
92 | - if ($indi !== null && $indi->canShowName()) { |
|
93 | - return new MissingAncestor( |
|
94 | - $indi, |
|
95 | - (int) $value->majs_sosa, |
|
96 | - $value->majs_fat_id === null, |
|
97 | - $value->majs_mot_id === null |
|
98 | - ); |
|
99 | - } |
|
100 | - return null; |
|
101 | - })->filter(); |
|
102 | - |
|
103 | - $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int { |
|
104 | - return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0); |
|
105 | - }); |
|
106 | - |
|
107 | - return $this->viewResponse($this->module->name() . '::list-missing-page', [ |
|
108 | - 'module_name' => $this->module->name(), |
|
109 | - 'title' => I18N::translate('Missing Ancestors'), |
|
110 | - 'tree' => $tree, |
|
111 | - 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
112 | - 'max_gen' => $sosa_stats_service->maxGeneration(), |
|
113 | - 'current_gen' => $current_gen, |
|
114 | - 'list_missing' => $list_missing, |
|
115 | - 'nb_missing_diff' => $nb_missing_diff, |
|
116 | - 'nb_missing_shown' => $nb_missing_shown, |
|
117 | - 'gen_completeness' => |
|
118 | - $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1), |
|
119 | - 'gen_potential' => |
|
120 | - $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2) |
|
121 | - ]); |
|
122 | - } |
|
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 MissingAncestorsList 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 | + if ($this->module === null) { |
|
72 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
73 | + } |
|
74 | + |
|
75 | + $tree = $request->getAttribute('tree'); |
|
76 | + assert($tree instanceof Tree); |
|
77 | + |
|
78 | + $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
79 | + |
|
80 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
81 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
82 | + |
|
83 | + $current_gen = (int) ($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0); |
|
84 | + |
|
85 | + $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen); |
|
86 | + $nb_missing_diff = $list_missing->sum(function (stdClass $value): int { |
|
87 | + return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0); |
|
88 | + }); |
|
89 | + |
|
90 | + $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor { |
|
91 | + $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
|
92 | + if ($indi !== null && $indi->canShowName()) { |
|
93 | + return new MissingAncestor( |
|
94 | + $indi, |
|
95 | + (int) $value->majs_sosa, |
|
96 | + $value->majs_fat_id === null, |
|
97 | + $value->majs_mot_id === null |
|
98 | + ); |
|
99 | + } |
|
100 | + return null; |
|
101 | + })->filter(); |
|
102 | + |
|
103 | + $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int { |
|
104 | + return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0); |
|
105 | + }); |
|
106 | + |
|
107 | + return $this->viewResponse($this->module->name() . '::list-missing-page', [ |
|
108 | + 'module_name' => $this->module->name(), |
|
109 | + 'title' => I18N::translate('Missing Ancestors'), |
|
110 | + 'tree' => $tree, |
|
111 | + 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
112 | + 'max_gen' => $sosa_stats_service->maxGeneration(), |
|
113 | + 'current_gen' => $current_gen, |
|
114 | + 'list_missing' => $list_missing, |
|
115 | + 'nb_missing_diff' => $nb_missing_diff, |
|
116 | + 'nb_missing_shown' => $nb_missing_shown, |
|
117 | + 'gen_completeness' => |
|
118 | + $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1), |
|
119 | + 'gen_potential' => |
|
120 | + $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2) |
|
121 | + ]); |
|
122 | + } |
|
123 | 123 | } |
@@ -80,19 +80,19 @@ discard block |
||
80 | 80 | /** @var SosaStatisticsService $sosa_stats_service */ |
81 | 81 | $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
82 | 82 | |
83 | - $current_gen = (int) ($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0); |
|
83 | + $current_gen = (int)($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0); |
|
84 | 84 | |
85 | 85 | $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen); |
86 | - $nb_missing_diff = $list_missing->sum(function (stdClass $value): int { |
|
86 | + $nb_missing_diff = $list_missing->sum(function(stdClass $value): int { |
|
87 | 87 | return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0); |
88 | 88 | }); |
89 | 89 | |
90 | - $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor { |
|
90 | + $list_missing = $list_missing->map(function(stdClass $value) use ($tree): ?MissingAncestor { |
|
91 | 91 | $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
92 | 92 | if ($indi !== null && $indi->canShowName()) { |
93 | 93 | return new MissingAncestor( |
94 | 94 | $indi, |
95 | - (int) $value->majs_sosa, |
|
95 | + (int)$value->majs_sosa, |
|
96 | 96 | $value->majs_fat_id === null, |
97 | 97 | $value->majs_mot_id === null |
98 | 98 | ); |
@@ -100,11 +100,11 @@ discard block |
||
100 | 100 | return null; |
101 | 101 | })->filter(); |
102 | 102 | |
103 | - $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int { |
|
103 | + $nb_missing_shown = $list_missing->sum(function(MissingAncestor $value): int { |
|
104 | 104 | return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0); |
105 | 105 | }); |
106 | 106 | |
107 | - return $this->viewResponse($this->module->name() . '::list-missing-page', [ |
|
107 | + return $this->viewResponse($this->module->name().'::list-missing-page', [ |
|
108 | 108 | 'module_name' => $this->module->name(), |
109 | 109 | 'title' => I18N::translate('Missing Ancestors'), |
110 | 110 | 'tree' => $tree, |
@@ -35,73 +35,73 @@ |
||
35 | 35 | */ |
36 | 36 | class AncestorsListFamily implements RequestHandlerInterface |
37 | 37 | { |
38 | - use ViewResponseTrait; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var SosaModule|null $module |
|
42 | - */ |
|
43 | - private $module; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var SosaRecordsService $sosa_record_service |
|
47 | - */ |
|
48 | - private $sosa_record_service; |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor for AncestorsListFamily Request Handler |
|
52 | - * |
|
53 | - * @param ModuleService $module_service |
|
54 | - * @param SosaRecordsService $sosa_record_service |
|
55 | - */ |
|
56 | - public function __construct( |
|
57 | - ModuleService $module_service, |
|
58 | - SosaRecordsService $sosa_record_service |
|
59 | - ) { |
|
60 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
61 | - $this->sosa_record_service = $sosa_record_service; |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
67 | - */ |
|
68 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
69 | - { |
|
70 | - $this->layout = 'layouts/ajax'; |
|
71 | - |
|
72 | - if ($this->module === null) { |
|
73 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
74 | - } |
|
75 | - |
|
76 | - $tree = $request->getAttribute('tree'); |
|
77 | - assert($tree instanceof Tree); |
|
78 | - |
|
79 | - $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
80 | - |
|
81 | - $current_gen = (int) ($request->getAttribute('gen') ?? 0); |
|
82 | - |
|
83 | - if ($current_gen <= 0) { |
|
84 | - return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY); |
|
85 | - } |
|
86 | - |
|
87 | - $list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen); |
|
88 | - $nb_families_all = $list_families->count(); |
|
89 | - |
|
90 | - /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
|
91 | - $list_families = $list_families->mapWithKeys(function (stdClass $value) use ($tree): ?array { |
|
92 | - $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
93 | - return ($fam !== null && $fam->canShow()) ? [(int) $value->majs_sosa => $fam] : null; |
|
94 | - })->filter(); |
|
95 | - |
|
96 | - $nb_families_shown = $list_families->count(); |
|
97 | - |
|
98 | - return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
99 | - 'module_name' => $this->module->name(), |
|
100 | - 'title' => I18N::translate('Sosa Ancestors'), |
|
101 | - 'tree' => $tree, |
|
102 | - 'list_families' => $list_families, |
|
103 | - 'nb_families_all' => $nb_families_all, |
|
104 | - 'nb_families_shown' => $nb_families_shown |
|
105 | - ]); |
|
106 | - } |
|
38 | + use ViewResponseTrait; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var SosaModule|null $module |
|
42 | + */ |
|
43 | + private $module; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var SosaRecordsService $sosa_record_service |
|
47 | + */ |
|
48 | + private $sosa_record_service; |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor for AncestorsListFamily Request Handler |
|
52 | + * |
|
53 | + * @param ModuleService $module_service |
|
54 | + * @param SosaRecordsService $sosa_record_service |
|
55 | + */ |
|
56 | + public function __construct( |
|
57 | + ModuleService $module_service, |
|
58 | + SosaRecordsService $sosa_record_service |
|
59 | + ) { |
|
60 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
61 | + $this->sosa_record_service = $sosa_record_service; |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
67 | + */ |
|
68 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
69 | + { |
|
70 | + $this->layout = 'layouts/ajax'; |
|
71 | + |
|
72 | + if ($this->module === null) { |
|
73 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
74 | + } |
|
75 | + |
|
76 | + $tree = $request->getAttribute('tree'); |
|
77 | + assert($tree instanceof Tree); |
|
78 | + |
|
79 | + $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
80 | + |
|
81 | + $current_gen = (int) ($request->getAttribute('gen') ?? 0); |
|
82 | + |
|
83 | + if ($current_gen <= 0) { |
|
84 | + return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY); |
|
85 | + } |
|
86 | + |
|
87 | + $list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen); |
|
88 | + $nb_families_all = $list_families->count(); |
|
89 | + |
|
90 | + /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
|
91 | + $list_families = $list_families->mapWithKeys(function (stdClass $value) use ($tree): ?array { |
|
92 | + $fam = Registry::familyFactory()->make($value->f_id, $tree); |
|
93 | + return ($fam !== null && $fam->canShow()) ? [(int) $value->majs_sosa => $fam] : null; |
|
94 | + })->filter(); |
|
95 | + |
|
96 | + $nb_families_shown = $list_families->count(); |
|
97 | + |
|
98 | + return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
99 | + 'module_name' => $this->module->name(), |
|
100 | + 'title' => I18N::translate('Sosa Ancestors'), |
|
101 | + 'tree' => $tree, |
|
102 | + 'list_families' => $list_families, |
|
103 | + 'nb_families_all' => $nb_families_all, |
|
104 | + 'nb_families_shown' => $nb_families_shown |
|
105 | + ]); |
|
106 | + } |
|
107 | 107 | } |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | |
79 | 79 | $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
80 | 80 | |
81 | - $current_gen = (int) ($request->getAttribute('gen') ?? 0); |
|
81 | + $current_gen = (int)($request->getAttribute('gen') ?? 0); |
|
82 | 82 | |
83 | 83 | if ($current_gen <= 0) { |
84 | 84 | return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY); |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | $nb_families_all = $list_families->count(); |
89 | 89 | |
90 | 90 | /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
91 | - $list_families = $list_families->mapWithKeys(function (stdClass $value) use ($tree): ?array { |
|
91 | + $list_families = $list_families->mapWithKeys(function(stdClass $value) use ($tree): ?array { |
|
92 | 92 | $fam = Registry::familyFactory()->make($value->f_id, $tree); |
93 | - return ($fam !== null && $fam->canShow()) ? [(int) $value->majs_sosa => $fam] : null; |
|
93 | + return ($fam !== null && $fam->canShow()) ? [(int)$value->majs_sosa => $fam] : null; |
|
94 | 94 | })->filter(); |
95 | 95 | |
96 | 96 | $nb_families_shown = $list_families->count(); |
97 | 97 | |
98 | - return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
98 | + return $this->viewResponse($this->module->name().'::list-ancestors-fam-tab', [ |
|
99 | 99 | 'module_name' => $this->module->name(), |
100 | 100 | 'title' => I18N::translate('Sosa Ancestors'), |
101 | 101 | 'tree' => $tree, |
@@ -33,59 +33,59 @@ |
||
33 | 33 | */ |
34 | 34 | class AncestorsList 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 | - * @var SosaRecordsService $sosa_record_service |
|
45 | - */ |
|
46 | - private $sosa_record_service; |
|
43 | + /** |
|
44 | + * @var SosaRecordsService $sosa_record_service |
|
45 | + */ |
|
46 | + private $sosa_record_service; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Constructor for AncestorsList Request Handler |
|
50 | - * |
|
51 | - * @param ModuleService $module_service |
|
52 | - * @param SosaRecordsService $sosa_record_service |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - ModuleService $module_service, |
|
56 | - SosaRecordsService $sosa_record_service |
|
57 | - ) { |
|
58 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
59 | - $this->sosa_record_service = $sosa_record_service; |
|
60 | - } |
|
48 | + /** |
|
49 | + * Constructor for AncestorsList Request Handler |
|
50 | + * |
|
51 | + * @param ModuleService $module_service |
|
52 | + * @param SosaRecordsService $sosa_record_service |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + ModuleService $module_service, |
|
56 | + SosaRecordsService $sosa_record_service |
|
57 | + ) { |
|
58 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
59 | + $this->sosa_record_service = $sosa_record_service; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritDoc} |
|
64 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
65 | - */ |
|
66 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
67 | - { |
|
68 | - if ($this->module === null) { |
|
69 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
70 | - } |
|
62 | + /** |
|
63 | + * {@inheritDoc} |
|
64 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
65 | + */ |
|
66 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
67 | + { |
|
68 | + if ($this->module === null) { |
|
69 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
70 | + } |
|
71 | 71 | |
72 | - $tree = $request->getAttribute('tree'); |
|
73 | - assert($tree instanceof Tree); |
|
72 | + $tree = $request->getAttribute('tree'); |
|
73 | + assert($tree instanceof Tree); |
|
74 | 74 | |
75 | - $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
75 | + $user = Auth::check() ? $request->getAttribute('user') : new DefaultUser(); |
|
76 | 76 | |
77 | - /** @var SosaStatisticsService $sosa_stats_service */ |
|
78 | - $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
77 | + /** @var SosaStatisticsService $sosa_stats_service */ |
|
78 | + $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
|
79 | 79 | |
80 | - $current_gen = (int) ($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0); |
|
80 | + $current_gen = (int) ($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0); |
|
81 | 81 | |
82 | - return $this->viewResponse($this->module->name() . '::list-ancestors-page', [ |
|
83 | - 'module_name' => $this->module->name(), |
|
84 | - 'title' => I18N::translate('Sosa Ancestors'), |
|
85 | - 'tree' => $tree, |
|
86 | - 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
87 | - 'max_gen' => $sosa_stats_service->maxGeneration(), |
|
88 | - 'current_gen' => $current_gen |
|
89 | - ]); |
|
90 | - } |
|
82 | + return $this->viewResponse($this->module->name() . '::list-ancestors-page', [ |
|
83 | + 'module_name' => $this->module->name(), |
|
84 | + 'title' => I18N::translate('Sosa Ancestors'), |
|
85 | + 'tree' => $tree, |
|
86 | + 'root_indi' => $sosa_stats_service->rootIndividual(), |
|
87 | + 'max_gen' => $sosa_stats_service->maxGeneration(), |
|
88 | + 'current_gen' => $current_gen |
|
89 | + ]); |
|
90 | + } |
|
91 | 91 | } |
@@ -77,9 +77,9 @@ |
||
77 | 77 | /** @var SosaStatisticsService $sosa_stats_service */ |
78 | 78 | $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]); |
79 | 79 | |
80 | - $current_gen = (int) ($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0); |
|
80 | + $current_gen = (int)($request->getQueryParams()['gen'] ?? $request->getAttribute('gen') ?? 0); |
|
81 | 81 | |
82 | - return $this->viewResponse($this->module->name() . '::list-ancestors-page', [ |
|
82 | + return $this->viewResponse($this->module->name().'::list-ancestors-page', [ |
|
83 | 83 | 'module_name' => $this->module->name(), |
84 | 84 | 'title' => I18N::translate('Sosa Ancestors'), |
85 | 85 | 'tree' => $tree, |
@@ -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 |
@@ -37,144 +37,144 @@ |
||
37 | 37 | */ |
38 | 38 | class SosaStatistics implements RequestHandlerInterface |
39 | 39 | { |
40 | - use ViewResponseTrait; |
|
41 | - |
|
42 | - private ?SosaModule $module; |
|
43 | - private RelationshipService $relationship_service; |
|
44 | - |
|
45 | - /** |
|
46 | - * Constructor for AncestorsList Request Handler |
|
47 | - * |
|
48 | - * @param ModuleService $module_service |
|
49 | - */ |
|
50 | - public function __construct(ModuleService $module_service, RelationshipService $relationship_service) |
|
51 | - { |
|
52 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
53 | - $this->relationship_service = $relationship_service; |
|
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 | - 'relationship_service' => $this->relationship_service, |
|
88 | - ]); |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Retrieve and compute the global statistics of ancestors for the tree. |
|
93 | - * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse... |
|
94 | - * |
|
95 | - * @param SosaStatisticsService $sosa_stats_service |
|
96 | - * @return array<string, int|float> |
|
97 | - */ |
|
98 | - private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array |
|
99 | - { |
|
100 | - $ancestors_count = $sosa_stats_service->totalAncestors(); |
|
101 | - $ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors(); |
|
102 | - $individual_count = $sosa_stats_service->totalIndividuals(); |
|
103 | - |
|
104 | - return [ |
|
105 | - 'sosa_count' => $ancestors_count, |
|
106 | - 'distinct_count' => $ancestors_distinct_count, |
|
107 | - 'sosa_rate' => $this->safeDivision( |
|
108 | - BigInteger::of($ancestors_distinct_count), |
|
109 | - BigInteger::of($individual_count) |
|
110 | - ), |
|
111 | - 'mean_gen_time' => $sosa_stats_service->meanGenerationTime() |
|
112 | - ]; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Retrieve and compute the statistics of ancestors by generations. |
|
117 | - * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics... |
|
118 | - * |
|
119 | - * @param SosaStatisticsService $sosa_stats_service |
|
120 | - * @return array<int, array<string, int|float>> |
|
121 | - */ |
|
122 | - private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array |
|
123 | - { |
|
124 | - $stats_by_gen = $sosa_stats_service->statisticsByGenerations(); |
|
125 | - |
|
126 | - $generation_stats = array(); |
|
127 | - |
|
128 | - foreach ($stats_by_gen as $gen => $stats_gen) { |
|
129 | - $gen_diff = $gen > 1 ? |
|
130 | - (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] : |
|
131 | - 1; |
|
132 | - $generation_stats[$gen] = array( |
|
133 | - 'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'], |
|
134 | - 'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'], |
|
135 | - 'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(), |
|
136 | - 'known' => (int) $stats_gen['sosaCount'], |
|
137 | - 'perc_known' => $this->safeDivision( |
|
138 | - BigInteger::of((int) $stats_gen['sosaCount']), |
|
139 | - BigInteger::of(2)->power($gen - 1) |
|
140 | - ), |
|
141 | - 'missing' => $gen > 1 ? |
|
142 | - 2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] : |
|
143 | - 0, |
|
144 | - 'perc_missing' => $gen > 1 ? |
|
145 | - 1 - $this->safeDivision( |
|
146 | - BigInteger::of((int) $stats_gen['sosaCount']), |
|
147 | - BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount']) |
|
148 | - ) : |
|
149 | - 0, |
|
150 | - 'total_known' => (int) $stats_gen['sosaTotalCount'], |
|
151 | - 'perc_total_known' => $this->safeDivision( |
|
152 | - BigInteger::of((int) $stats_gen['sosaTotalCount']), |
|
153 | - BigInteger::of(2)->power($gen)->minus(1) |
|
154 | - ), |
|
155 | - 'different' => $gen_diff, |
|
156 | - 'perc_different' => $this->safeDivision( |
|
157 | - BigInteger::of($gen_diff), |
|
158 | - BigInteger::of((int) $stats_gen['sosaCount']) |
|
159 | - ), |
|
160 | - 'total_different' => (int) $stats_gen['diffSosaTotalCount'] |
|
161 | - ); |
|
162 | - } |
|
163 | - |
|
164 | - return $generation_stats; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Return the result of a division, and a default value if denominator is 0 |
|
169 | - * |
|
170 | - * @param BigInteger $p Numerator |
|
171 | - * @param BigInteger $q Denominator |
|
172 | - * @param int $scale Rounding scale |
|
173 | - * @param float $default Value if denominator is 0 |
|
174 | - * @return float |
|
175 | - */ |
|
176 | - private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float |
|
177 | - { |
|
178 | - return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat(); |
|
179 | - } |
|
40 | + use ViewResponseTrait; |
|
41 | + |
|
42 | + private ?SosaModule $module; |
|
43 | + private RelationshipService $relationship_service; |
|
44 | + |
|
45 | + /** |
|
46 | + * Constructor for AncestorsList Request Handler |
|
47 | + * |
|
48 | + * @param ModuleService $module_service |
|
49 | + */ |
|
50 | + public function __construct(ModuleService $module_service, RelationshipService $relationship_service) |
|
51 | + { |
|
52 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
53 | + $this->relationship_service = $relationship_service; |
|
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 | + 'relationship_service' => $this->relationship_service, |
|
88 | + ]); |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Retrieve and compute the global statistics of ancestors for the tree. |
|
93 | + * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse... |
|
94 | + * |
|
95 | + * @param SosaStatisticsService $sosa_stats_service |
|
96 | + * @return array<string, int|float> |
|
97 | + */ |
|
98 | + private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array |
|
99 | + { |
|
100 | + $ancestors_count = $sosa_stats_service->totalAncestors(); |
|
101 | + $ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors(); |
|
102 | + $individual_count = $sosa_stats_service->totalIndividuals(); |
|
103 | + |
|
104 | + return [ |
|
105 | + 'sosa_count' => $ancestors_count, |
|
106 | + 'distinct_count' => $ancestors_distinct_count, |
|
107 | + 'sosa_rate' => $this->safeDivision( |
|
108 | + BigInteger::of($ancestors_distinct_count), |
|
109 | + BigInteger::of($individual_count) |
|
110 | + ), |
|
111 | + 'mean_gen_time' => $sosa_stats_service->meanGenerationTime() |
|
112 | + ]; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Retrieve and compute the statistics of ancestors by generations. |
|
117 | + * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics... |
|
118 | + * |
|
119 | + * @param SosaStatisticsService $sosa_stats_service |
|
120 | + * @return array<int, array<string, int|float>> |
|
121 | + */ |
|
122 | + private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array |
|
123 | + { |
|
124 | + $stats_by_gen = $sosa_stats_service->statisticsByGenerations(); |
|
125 | + |
|
126 | + $generation_stats = array(); |
|
127 | + |
|
128 | + foreach ($stats_by_gen as $gen => $stats_gen) { |
|
129 | + $gen_diff = $gen > 1 ? |
|
130 | + (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] : |
|
131 | + 1; |
|
132 | + $generation_stats[$gen] = array( |
|
133 | + 'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'], |
|
134 | + 'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'], |
|
135 | + 'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(), |
|
136 | + 'known' => (int) $stats_gen['sosaCount'], |
|
137 | + 'perc_known' => $this->safeDivision( |
|
138 | + BigInteger::of((int) $stats_gen['sosaCount']), |
|
139 | + BigInteger::of(2)->power($gen - 1) |
|
140 | + ), |
|
141 | + 'missing' => $gen > 1 ? |
|
142 | + 2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] : |
|
143 | + 0, |
|
144 | + 'perc_missing' => $gen > 1 ? |
|
145 | + 1 - $this->safeDivision( |
|
146 | + BigInteger::of((int) $stats_gen['sosaCount']), |
|
147 | + BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount']) |
|
148 | + ) : |
|
149 | + 0, |
|
150 | + 'total_known' => (int) $stats_gen['sosaTotalCount'], |
|
151 | + 'perc_total_known' => $this->safeDivision( |
|
152 | + BigInteger::of((int) $stats_gen['sosaTotalCount']), |
|
153 | + BigInteger::of(2)->power($gen)->minus(1) |
|
154 | + ), |
|
155 | + 'different' => $gen_diff, |
|
156 | + 'perc_different' => $this->safeDivision( |
|
157 | + BigInteger::of($gen_diff), |
|
158 | + BigInteger::of((int) $stats_gen['sosaCount']) |
|
159 | + ), |
|
160 | + 'total_different' => (int) $stats_gen['diffSosaTotalCount'] |
|
161 | + ); |
|
162 | + } |
|
163 | + |
|
164 | + return $generation_stats; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Return the result of a division, and a default value if denominator is 0 |
|
169 | + * |
|
170 | + * @param BigInteger $p Numerator |
|
171 | + * @param BigInteger $q Denominator |
|
172 | + * @param int $scale Rounding scale |
|
173 | + * @param float $default Value if denominator is 0 |
|
174 | + * @return float |
|
175 | + */ |
|
176 | + private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float |
|
177 | + { |
|
178 | + return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat(); |
|
179 | + } |
|
180 | 180 | } |
@@ -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 | } |
@@ -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 | ]); |
@@ -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 |
@@ -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 | } |
@@ -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 | ]); |
@@ -28,40 +28,40 @@ |
||
28 | 28 | */ |
29 | 29 | class SosaComputeModal implements RequestHandlerInterface |
30 | 30 | { |
31 | - /** |
|
32 | - * @var SosaModule|null $module |
|
33 | - */ |
|
34 | - private $module; |
|
31 | + /** |
|
32 | + * @var SosaModule|null $module |
|
33 | + */ |
|
34 | + private $module; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for SosaComputeModal Request Handler |
|
38 | - * |
|
39 | - * @param ModuleService $module_service |
|
40 | - */ |
|
41 | - public function __construct(ModuleService $module_service) |
|
42 | - { |
|
43 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
44 | - } |
|
36 | + /** |
|
37 | + * Constructor for SosaComputeModal Request Handler |
|
38 | + * |
|
39 | + * @param ModuleService $module_service |
|
40 | + */ |
|
41 | + public function __construct(ModuleService $module_service) |
|
42 | + { |
|
43 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | - */ |
|
50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | - { |
|
52 | - if ($this->module === null) { |
|
53 | - return response(view('modals/error', [ |
|
54 | - 'title' => I18N::translate('Error'), |
|
55 | - 'error' => I18N::translate('The attached module could not be found.') |
|
56 | - ])); |
|
57 | - } |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | + */ |
|
50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | + { |
|
52 | + if ($this->module === null) { |
|
53 | + return response(view('modals/error', [ |
|
54 | + 'title' => I18N::translate('Error'), |
|
55 | + 'error' => I18N::translate('The attached module could not be found.') |
|
56 | + ])); |
|
57 | + } |
|
58 | 58 | |
59 | - $tree = $request->getAttribute('tree'); |
|
60 | - assert($tree instanceof Tree); |
|
59 | + $tree = $request->getAttribute('tree'); |
|
60 | + assert($tree instanceof Tree); |
|
61 | 61 | |
62 | - return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | - 'tree' => $tree, |
|
64 | - 'xref' => $request->getAttribute('xref') |
|
65 | - ])); |
|
66 | - } |
|
62 | + return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | + 'tree' => $tree, |
|
64 | + 'xref' => $request->getAttribute('xref') |
|
65 | + ])); |
|
66 | + } |
|
67 | 67 | } |
@@ -60,7 +60,7 @@ |
||
60 | 60 | $tree = $request->getAttribute('tree'); |
61 | 61 | assert($tree instanceof Tree); |
62 | 62 | |
63 | - return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | + return response(view($this->module->name().'::modals/sosa-compute', [ |
|
64 | 64 | 'tree' => $tree, |
65 | 65 | 'xref' => $request->getAttribute('xref') |
66 | 66 | ])); |