@@ -37,128 +37,128 @@ |
||
37 | 37 | */ |
38 | 38 | class CertificateImage implements RequestHandlerInterface |
39 | 39 | { |
40 | - /** |
|
41 | - * @var CertificatesModule|null $module |
|
42 | - */ |
|
43 | - private $module; |
|
44 | - |
|
45 | - /** |
|
46 | - * @var CertificateFilesystemService $certif_filesystem |
|
47 | - */ |
|
48 | - private $certif_filesystem; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var CertificateImageFactory $certif_image_factory |
|
52 | - */ |
|
53 | - private $certif_image_factory; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var CertificateDataService $certif_data_service |
|
57 | - */ |
|
58 | - private $certif_data_service; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var UrlObfuscatorService $url_obfuscator_service |
|
62 | - */ |
|
63 | - private $url_obfuscator_service; |
|
64 | - |
|
65 | - /** |
|
66 | - * Constructor for Certificate Image Request Handler |
|
67 | - * |
|
68 | - * @param ModuleService $module_service |
|
69 | - */ |
|
70 | - public function __construct( |
|
71 | - ModuleService $module_service, |
|
72 | - CertificateFilesystemService $certif_filesystem, |
|
73 | - CertificateDataService $certif_data_service, |
|
74 | - UrlObfuscatorService $url_obfuscator_service |
|
75 | - ) { |
|
76 | - $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
77 | - $this->certif_filesystem = $certif_filesystem; |
|
78 | - $this->certif_image_factory = new CertificateImageFactory($this->certif_filesystem); |
|
79 | - $this->certif_data_service = $certif_data_service; |
|
80 | - $this->url_obfuscator_service = $url_obfuscator_service; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * {@inheritDoc} |
|
85 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
86 | - */ |
|
87 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
88 | - { |
|
89 | - if ($this->module === null) { |
|
90 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
91 | - } |
|
92 | - |
|
93 | - $tree = $request->getAttribute('tree'); |
|
94 | - assert($tree instanceof Tree); |
|
95 | - |
|
96 | - $user = $request->getAttribute('user'); |
|
97 | - assert($user instanceof UserInterface); |
|
98 | - |
|
99 | - $certif_path = $request->getAttribute('cid'); |
|
100 | - $certificate = null; |
|
101 | - if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
102 | - $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
103 | - } |
|
104 | - |
|
105 | - if ($certificate === null) { |
|
106 | - return $this->certif_image_factory |
|
107 | - ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND) |
|
108 | - ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.')) |
|
109 | - ; |
|
110 | - } |
|
111 | - |
|
112 | - $use_watermark = $this->certif_image_factory->certificateNeedsWatermark($certificate, $user); |
|
113 | - $watermark = $use_watermark ? $this->watermark($request, $certificate) : null; |
|
114 | - |
|
115 | - return $this->certif_image_factory->certificateFileResponse( |
|
116 | - $certificate, |
|
117 | - $use_watermark, |
|
118 | - $watermark |
|
119 | - ); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Get watermark data for a certificate. |
|
124 | - * |
|
125 | - * @param ServerRequestInterface $request |
|
126 | - * @param Certificate $certificate |
|
127 | - * @return Watermark |
|
128 | - */ |
|
129 | - private function watermark(ServerRequestInterface $request, Certificate $certificate): Watermark |
|
130 | - { |
|
131 | - $color = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_COLOR', Watermark::DEFAULT_COLOR); |
|
132 | - $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE'); |
|
133 | - $text = $this->watermarkText($request, $certificate); |
|
134 | - |
|
135 | - return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Get the text to be watermarked for a certificate. |
|
140 | - * |
|
141 | - * @param ServerRequestInterface $request |
|
142 | - * @param Certificate $certificate |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - private function watermarkText(ServerRequestInterface $request, Certificate $certificate): string |
|
146 | - { |
|
147 | - $sid = $request->getQueryParams()['sid'] ?? ''; |
|
148 | - if ($sid !== '') { |
|
149 | - $source = Registry::sourceFactory()->make($sid, $certificate->tree()); |
|
150 | - } else { |
|
151 | - $source = $this->certif_data_service->oneLinkedSource($certificate); |
|
152 | - } |
|
153 | - |
|
154 | - if ($source !== null && $source->canShowName()) { |
|
155 | - $repo = $source->facts(['REPO'])->first(); |
|
156 | - if ($repo !== null && ($repo = $repo->target()) !== null && $repo->canShowName()) { |
|
157 | - return I18N::translate('© %s - %s', strip_tags($repo->fullName()), strip_tags($source->fullName())); |
|
158 | - } |
|
159 | - return strip_tags($source->fullName()); |
|
160 | - } |
|
161 | - $default_text = $certificate->tree()->getPreference('MAJ_CERTIF_WM_DEFAULT'); |
|
162 | - return $default_text !== '' ? $default_text : I18N::translate('This image is protected under copyright law.'); |
|
163 | - } |
|
40 | + /** |
|
41 | + * @var CertificatesModule|null $module |
|
42 | + */ |
|
43 | + private $module; |
|
44 | + |
|
45 | + /** |
|
46 | + * @var CertificateFilesystemService $certif_filesystem |
|
47 | + */ |
|
48 | + private $certif_filesystem; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var CertificateImageFactory $certif_image_factory |
|
52 | + */ |
|
53 | + private $certif_image_factory; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var CertificateDataService $certif_data_service |
|
57 | + */ |
|
58 | + private $certif_data_service; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var UrlObfuscatorService $url_obfuscator_service |
|
62 | + */ |
|
63 | + private $url_obfuscator_service; |
|
64 | + |
|
65 | + /** |
|
66 | + * Constructor for Certificate Image Request Handler |
|
67 | + * |
|
68 | + * @param ModuleService $module_service |
|
69 | + */ |
|
70 | + public function __construct( |
|
71 | + ModuleService $module_service, |
|
72 | + CertificateFilesystemService $certif_filesystem, |
|
73 | + CertificateDataService $certif_data_service, |
|
74 | + UrlObfuscatorService $url_obfuscator_service |
|
75 | + ) { |
|
76 | + $this->module = $module_service->findByInterface(CertificatesModule::class)->first(); |
|
77 | + $this->certif_filesystem = $certif_filesystem; |
|
78 | + $this->certif_image_factory = new CertificateImageFactory($this->certif_filesystem); |
|
79 | + $this->certif_data_service = $certif_data_service; |
|
80 | + $this->url_obfuscator_service = $url_obfuscator_service; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * {@inheritDoc} |
|
85 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
86 | + */ |
|
87 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
88 | + { |
|
89 | + if ($this->module === null) { |
|
90 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
91 | + } |
|
92 | + |
|
93 | + $tree = $request->getAttribute('tree'); |
|
94 | + assert($tree instanceof Tree); |
|
95 | + |
|
96 | + $user = $request->getAttribute('user'); |
|
97 | + assert($user instanceof UserInterface); |
|
98 | + |
|
99 | + $certif_path = $request->getAttribute('cid'); |
|
100 | + $certificate = null; |
|
101 | + if ($certif_path !== '' && $this->url_obfuscator_service->tryDeobfuscate($certif_path)) { |
|
102 | + $certificate = $this->certif_filesystem->certificate($tree, $certif_path); |
|
103 | + } |
|
104 | + |
|
105 | + if ($certificate === null) { |
|
106 | + return $this->certif_image_factory |
|
107 | + ->replacementImageResponse((string) StatusCodeInterface::STATUS_NOT_FOUND) |
|
108 | + ->withHeader('X-Image-Exception', I18N::translate('The certificate was not found in this family tree.')) |
|
109 | + ; |
|
110 | + } |
|
111 | + |
|
112 | + $use_watermark = $this->certif_image_factory->certificateNeedsWatermark($certificate, $user); |
|
113 | + $watermark = $use_watermark ? $this->watermark($request, $certificate) : null; |
|
114 | + |
|
115 | + return $this->certif_image_factory->certificateFileResponse( |
|
116 | + $certificate, |
|
117 | + $use_watermark, |
|
118 | + $watermark |
|
119 | + ); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Get watermark data for a certificate. |
|
124 | + * |
|
125 | + * @param ServerRequestInterface $request |
|
126 | + * @param Certificate $certificate |
|
127 | + * @return Watermark |
|
128 | + */ |
|
129 | + private function watermark(ServerRequestInterface $request, Certificate $certificate): Watermark |
|
130 | + { |
|
131 | + $color = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_COLOR', Watermark::DEFAULT_COLOR); |
|
132 | + $size = $certificate->tree()->getPreference('MAJ_CERTIF_WM_FONT_MAXSIZE'); |
|
133 | + $text = $this->watermarkText($request, $certificate); |
|
134 | + |
|
135 | + return new Watermark($text, $color, is_numeric($size) ? (int) $size : Watermark::DEFAULT_SIZE); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Get the text to be watermarked for a certificate. |
|
140 | + * |
|
141 | + * @param ServerRequestInterface $request |
|
142 | + * @param Certificate $certificate |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + private function watermarkText(ServerRequestInterface $request, Certificate $certificate): string |
|
146 | + { |
|
147 | + $sid = $request->getQueryParams()['sid'] ?? ''; |
|
148 | + if ($sid !== '') { |
|
149 | + $source = Registry::sourceFactory()->make($sid, $certificate->tree()); |
|
150 | + } else { |
|
151 | + $source = $this->certif_data_service->oneLinkedSource($certificate); |
|
152 | + } |
|
153 | + |
|
154 | + if ($source !== null && $source->canShowName()) { |
|
155 | + $repo = $source->facts(['REPO'])->first(); |
|
156 | + if ($repo !== null && ($repo = $repo->target()) !== null && $repo->canShowName()) { |
|
157 | + return I18N::translate('© %s - %s', strip_tags($repo->fullName()), strip_tags($source->fullName())); |
|
158 | + } |
|
159 | + return strip_tags($source->fullName()); |
|
160 | + } |
|
161 | + $default_text = $certificate->tree()->getPreference('MAJ_CERTIF_WM_DEFAULT'); |
|
162 | + return $default_text !== '' ? $default_text : I18N::translate('This image is protected under copyright law.'); |
|
163 | + } |
|
164 | 164 | } |
@@ -46,197 +46,197 @@ |
||
46 | 46 | * Certificates Module. |
47 | 47 | */ |
48 | 48 | class CertificatesModule extends AbstractModule implements |
49 | - ModuleMyArtJaubInterface, |
|
50 | - ModuleConfigInterface, |
|
51 | - ModuleCustomTagsInterface, |
|
52 | - ModuleGlobalInterface, |
|
53 | - ModuleListInterface, |
|
54 | - ModuleHookSubscriberInterface |
|
49 | + ModuleMyArtJaubInterface, |
|
50 | + ModuleConfigInterface, |
|
51 | + ModuleCustomTagsInterface, |
|
52 | + ModuleGlobalInterface, |
|
53 | + ModuleListInterface, |
|
54 | + ModuleHookSubscriberInterface |
|
55 | 55 | { |
56 | - use ModuleMyArtJaubTrait { |
|
57 | - ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
58 | - } |
|
59 | - use ModuleCustomTagsTrait { |
|
60 | - ModuleCustomTagsTrait::boot as traitCustomTagsBoot; |
|
61 | - } |
|
62 | - use ModuleConfigTrait; |
|
63 | - use ModuleGlobalTrait; |
|
64 | - use ModuleListTrait; |
|
65 | - |
|
66 | - /** |
|
67 | - * {@inheritDoc} |
|
68 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
69 | - */ |
|
70 | - public function title(): string |
|
71 | - { |
|
72 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * {@inheritDoc} |
|
77 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
78 | - */ |
|
79 | - public function description(): string |
|
80 | - { |
|
81 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
82 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * {@inheritDoc} |
|
87 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
88 | - */ |
|
89 | - public function boot(): void |
|
90 | - { |
|
91 | - $this->traitMajBoot(); |
|
92 | - $this->traitCustomTagsBoot(); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * {@inheritDoc} |
|
97 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
98 | - */ |
|
99 | - public function loadRoutes($router): void |
|
100 | - { |
|
101 | - $router->attach('', '', static function (Map $router): void { |
|
102 | - |
|
103 | - $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
104 | - |
|
105 | - $router->attach('', '/admin', static function (Map $router): void { |
|
106 | - |
|
107 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
108 | - $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
109 | - ->extras([ |
|
110 | - 'middleware' => [ |
|
111 | - AuthManager::class, |
|
112 | - ], |
|
113 | - ]); |
|
114 | - }); |
|
115 | - |
|
116 | - $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
117 | - ->extras([ |
|
118 | - 'middleware' => [AuthTreePreference::class], |
|
119 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
120 | - ]); |
|
121 | - |
|
122 | - $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
123 | - ->extras([ |
|
124 | - 'middleware' => [AuthTreePreference::class], |
|
125 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
126 | - ]); |
|
127 | - |
|
128 | - $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
129 | - |
|
130 | - $router->extras([ |
|
131 | - 'middleware' => [AuthTreePreference::class], |
|
132 | - 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
133 | - ]); |
|
134 | - |
|
135 | - $router->get(CertificatePage::class, '', CertificatePage::class); |
|
136 | - $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
137 | - }); |
|
138 | - }); |
|
139 | - }); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * {@inheritDoc} |
|
144 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
145 | - */ |
|
146 | - public function customModuleVersion(): string |
|
147 | - { |
|
148 | - return '2.1.0-v.1'; |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * {@inheritDoc} |
|
153 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
154 | - */ |
|
155 | - public function getConfigLink(): string |
|
156 | - { |
|
157 | - return route(AdminConfigPage::class); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * {@inheritDoc} |
|
162 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customSubTags() |
|
163 | - */ |
|
164 | - public function customSubTags(): array |
|
165 | - { |
|
166 | - return [ |
|
167 | - 'FAM:SOUR' => [['_ACT', '0:1']], |
|
168 | - 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
169 | - 'INDI:SOUR' => [['_ACT', '0:1']], |
|
170 | - 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
171 | - 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
172 | - 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
173 | - 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
174 | - 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
175 | - ]; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * {@inheritDoc} |
|
180 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customTags() |
|
181 | - */ |
|
182 | - public function customTags(): array |
|
183 | - { |
|
184 | - return [ |
|
185 | - 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
186 | - 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
187 | - 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
188 | - 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
189 | - 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
190 | - 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
191 | - 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
192 | - 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
193 | - ]; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * {@inheritDoc} |
|
198 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
199 | - */ |
|
200 | - public function headContent(): string |
|
201 | - { |
|
202 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
203 | - } |
|
204 | - |
|
205 | - /** |
|
206 | - * {@inheritDoc} |
|
207 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
208 | - */ |
|
209 | - public function listUrl(Tree $tree, array $parameters = []): string |
|
210 | - { |
|
211 | - return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
212 | - } |
|
213 | - |
|
214 | - /** |
|
215 | - * {@inheritDoc} |
|
216 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
217 | - */ |
|
218 | - public function listMenuClass(): string |
|
219 | - { |
|
220 | - return 'menu-maj-certificates'; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * {@inheritDoc} |
|
225 | - * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
226 | - */ |
|
227 | - public function listIsEmpty(Tree $tree): bool |
|
228 | - { |
|
229 | - return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
230 | - } |
|
231 | - |
|
232 | - /** |
|
233 | - * {@inheritDoc} |
|
234 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
235 | - */ |
|
236 | - public function listSubscribedHooks(): array |
|
237 | - { |
|
238 | - return [ |
|
239 | - app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
240 | - ]; |
|
241 | - } |
|
56 | + use ModuleMyArtJaubTrait { |
|
57 | + ModuleMyArtJaubTrait::boot as traitMajBoot; |
|
58 | + } |
|
59 | + use ModuleCustomTagsTrait { |
|
60 | + ModuleCustomTagsTrait::boot as traitCustomTagsBoot; |
|
61 | + } |
|
62 | + use ModuleConfigTrait; |
|
63 | + use ModuleGlobalTrait; |
|
64 | + use ModuleListTrait; |
|
65 | + |
|
66 | + /** |
|
67 | + * {@inheritDoc} |
|
68 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
69 | + */ |
|
70 | + public function title(): string |
|
71 | + { |
|
72 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * {@inheritDoc} |
|
77 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
78 | + */ |
|
79 | + public function description(): string |
|
80 | + { |
|
81 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
82 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * {@inheritDoc} |
|
87 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
88 | + */ |
|
89 | + public function boot(): void |
|
90 | + { |
|
91 | + $this->traitMajBoot(); |
|
92 | + $this->traitCustomTagsBoot(); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * {@inheritDoc} |
|
97 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
98 | + */ |
|
99 | + public function loadRoutes($router): void |
|
100 | + { |
|
101 | + $router->attach('', '', static function (Map $router): void { |
|
102 | + |
|
103 | + $router->attach('', '/module-maj/certificates', static function (Map $router): void { |
|
104 | + |
|
105 | + $router->attach('', '/admin', static function (Map $router): void { |
|
106 | + |
|
107 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
108 | + $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class) |
|
109 | + ->extras([ |
|
110 | + 'middleware' => [ |
|
111 | + AuthManager::class, |
|
112 | + ], |
|
113 | + ]); |
|
114 | + }); |
|
115 | + |
|
116 | + $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class) |
|
117 | + ->extras([ |
|
118 | + 'middleware' => [AuthTreePreference::class], |
|
119 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
120 | + ]); |
|
121 | + |
|
122 | + $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class) |
|
123 | + ->extras([ |
|
124 | + 'middleware' => [AuthTreePreference::class], |
|
125 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
126 | + ]); |
|
127 | + |
|
128 | + $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void { |
|
129 | + |
|
130 | + $router->extras([ |
|
131 | + 'middleware' => [AuthTreePreference::class], |
|
132 | + 'permission_preference' => 'MAJ_CERTIF_SHOW_CERT' |
|
133 | + ]); |
|
134 | + |
|
135 | + $router->get(CertificatePage::class, '', CertificatePage::class); |
|
136 | + $router->get(CertificateImage::class, '/image', CertificateImage::class); |
|
137 | + }); |
|
138 | + }); |
|
139 | + }); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * {@inheritDoc} |
|
144 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
145 | + */ |
|
146 | + public function customModuleVersion(): string |
|
147 | + { |
|
148 | + return '2.1.0-v.1'; |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * {@inheritDoc} |
|
153 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
154 | + */ |
|
155 | + public function getConfigLink(): string |
|
156 | + { |
|
157 | + return route(AdminConfigPage::class); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * {@inheritDoc} |
|
162 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customSubTags() |
|
163 | + */ |
|
164 | + public function customSubTags(): array |
|
165 | + { |
|
166 | + return [ |
|
167 | + 'FAM:SOUR' => [['_ACT', '0:1']], |
|
168 | + 'FAM:*:SOUR' => [['_ACT', '0:1']], |
|
169 | + 'INDI:SOUR' => [['_ACT', '0:1']], |
|
170 | + 'INDI:*:SOUR' => [['_ACT', '0:1']], |
|
171 | + 'OBJE:SOUR' => [['_ACT', '0:1']], |
|
172 | + 'OBJE:*:SOUR' => [['_ACT', '0:1']], |
|
173 | + 'NOTE:SOUR' => [['_ACT', '0:1']], |
|
174 | + 'NOTE:*:SOUR' => [['_ACT', '0:1']] |
|
175 | + ]; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * {@inheritDoc} |
|
180 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomTagsInterface::customTags() |
|
181 | + */ |
|
182 | + public function customTags(): array |
|
183 | + { |
|
184 | + return [ |
|
185 | + 'FAM:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
186 | + 'FAM:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
187 | + 'INDI:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
188 | + 'INDI:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
189 | + 'OBJE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
190 | + 'OBJE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
191 | + 'NOTE:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this), |
|
192 | + 'NOTE:*:SOUR:_ACT' => new SourceCertificate(I18N::translate('Certificate'), $this) |
|
193 | + ]; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * {@inheritDoc} |
|
198 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
199 | + */ |
|
200 | + public function headContent(): string |
|
201 | + { |
|
202 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
203 | + } |
|
204 | + |
|
205 | + /** |
|
206 | + * {@inheritDoc} |
|
207 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl() |
|
208 | + */ |
|
209 | + public function listUrl(Tree $tree, array $parameters = []): string |
|
210 | + { |
|
211 | + return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters); |
|
212 | + } |
|
213 | + |
|
214 | + /** |
|
215 | + * {@inheritDoc} |
|
216 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass() |
|
217 | + */ |
|
218 | + public function listMenuClass(): string |
|
219 | + { |
|
220 | + return 'menu-maj-certificates'; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * {@inheritDoc} |
|
225 | + * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty() |
|
226 | + */ |
|
227 | + public function listIsEmpty(Tree $tree): bool |
|
228 | + { |
|
229 | + return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE); |
|
230 | + } |
|
231 | + |
|
232 | + /** |
|
233 | + * {@inheritDoc} |
|
234 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
235 | + */ |
|
236 | + public function listSubscribedHooks(): array |
|
237 | + { |
|
238 | + return [ |
|
239 | + app()->makeWith(SourceCertificateIconHook::class, ['module' => $this]) |
|
240 | + ]; |
|
241 | + } |
|
242 | 242 | } |
@@ -22,51 +22,51 @@ |
||
22 | 22 | |
23 | 23 | class GeoAnalysisTable extends AbstractGeoAnalysisView |
24 | 24 | { |
25 | - /** |
|
26 | - * {@inheritDoc} |
|
27 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::type() |
|
28 | - */ |
|
29 | - public function type(): string |
|
30 | - { |
|
31 | - return I18N::translateContext('GEODISPERSION', 'Table'); |
|
32 | - } |
|
25 | + /** |
|
26 | + * {@inheritDoc} |
|
27 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::type() |
|
28 | + */ |
|
29 | + public function type(): string |
|
30 | + { |
|
31 | + return I18N::translateContext('GEODISPERSION', 'Table'); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * {@inheritDoc} |
|
36 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
37 | - */ |
|
38 | - public function icon(ModuleInterface $module): string |
|
39 | - { |
|
40 | - return view($module->name() . '::icons/view-table', ['type' => $this->type()]); |
|
41 | - } |
|
34 | + /** |
|
35 | + * {@inheritDoc} |
|
36 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
37 | + */ |
|
38 | + public function icon(ModuleInterface $module): string |
|
39 | + { |
|
40 | + return view($module->name() . '::icons/view-table', ['type' => $this->type()]); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * {@inheritDoc} |
|
45 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent() |
|
46 | - */ |
|
47 | - public function globalSettingsContent(ModuleInterface $module): string |
|
48 | - { |
|
49 | - return ''; |
|
50 | - } |
|
43 | + /** |
|
44 | + * {@inheritDoc} |
|
45 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent() |
|
46 | + */ |
|
47 | + public function globalSettingsContent(ModuleInterface $module): string |
|
48 | + { |
|
49 | + return ''; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate() |
|
55 | - * @return $this |
|
56 | - */ |
|
57 | - public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
|
58 | - { |
|
59 | - return $this; |
|
60 | - } |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate() |
|
55 | + * @return $this |
|
56 | + */ |
|
57 | + public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
|
58 | + { |
|
59 | + return $this; |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * {@inheritDoc} |
|
64 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
65 | - */ |
|
66 | - public function globalTabContent(GeoDispersionModule $module, GeoAnalysisResult $result, array $params): string |
|
67 | - { |
|
68 | - return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [ |
|
69 | - 'result' => $result |
|
70 | - ]); |
|
71 | - } |
|
62 | + /** |
|
63 | + * {@inheritDoc} |
|
64 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
65 | + */ |
|
66 | + public function globalTabContent(GeoDispersionModule $module, GeoAnalysisResult $result, array $params): string |
|
67 | + { |
|
68 | + return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [ |
|
69 | + 'result' => $result |
|
70 | + ]); |
|
71 | + } |
|
72 | 72 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | */ |
38 | 38 | public function icon(ModuleInterface $module): string |
39 | 39 | { |
40 | - return view($module->name() . '::icons/view-table', ['type' => $this->type()]); |
|
40 | + return view($module->name().'::icons/view-table', ['type' => $this->type()]); |
|
41 | 41 | } |
42 | 42 | |
43 | 43 | /** |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function globalTabContent(GeoDispersionModule $module, GeoAnalysisResult $result, array $params): string |
67 | 67 | { |
68 | - return view($module->name() . '::geoanalysisview-tab-glb-table', $params + [ |
|
68 | + return view($module->name().'::geoanalysisview-tab-glb-table', $params + [ |
|
69 | 69 | 'result' => $result |
70 | 70 | ]); |
71 | 71 | } |
@@ -27,224 +27,224 @@ |
||
27 | 27 | */ |
28 | 28 | abstract class AbstractGeoAnalysisView |
29 | 29 | { |
30 | - private int $id; |
|
31 | - private Tree $tree; |
|
32 | - private bool $enabled; |
|
33 | - private string $description; |
|
34 | - private GeoAnalysisInterface $geoanalysis; |
|
35 | - private int $depth; |
|
36 | - private int $detailed_top_places; |
|
37 | - private bool $use_flags; |
|
38 | - |
|
39 | - /** |
|
40 | - * Constructor for AbstractGeoAnalysisView |
|
41 | - * |
|
42 | - * @param int $id |
|
43 | - * @param Tree $tree |
|
44 | - * @param bool $enabled |
|
45 | - * @param string $description |
|
46 | - * @param GeoAnalysisInterface $geoanalysis |
|
47 | - * @param int $depth |
|
48 | - * @param int $detailed_top_places |
|
49 | - * @param bool $use_flags |
|
50 | - */ |
|
51 | - final public function __construct( |
|
52 | - int $id, |
|
53 | - Tree $tree, |
|
54 | - bool $enabled, |
|
55 | - string $description, |
|
56 | - GeoAnalysisInterface $geoanalysis, |
|
57 | - int $depth, |
|
58 | - int $detailed_top_places = 0, |
|
59 | - bool $use_flags = false |
|
60 | - ) { |
|
61 | - $this->id = $id; |
|
62 | - $this->tree = $tree; |
|
63 | - $this->enabled = $enabled; |
|
64 | - $this->description = $description; |
|
65 | - $this->geoanalysis = $geoanalysis; |
|
66 | - $this->depth = $depth; |
|
67 | - $this->detailed_top_places = $detailed_top_places; |
|
68 | - $this->use_flags = $use_flags; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Create a copy of the view with a new ID. |
|
73 | - * |
|
74 | - * @param int $id |
|
75 | - * @return static |
|
76 | - */ |
|
77 | - public function withId(int $id): self |
|
78 | - { |
|
79 | - $new = clone $this; |
|
80 | - $new->id = $id; |
|
81 | - return $new; |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * Create a copy of the view with new properties. |
|
86 | - * |
|
87 | - * @param bool $enabled |
|
88 | - * @param string $description |
|
89 | - * @param GeoAnalysisInterface $geoanalysis |
|
90 | - * @param int $depth |
|
91 | - * @param int $detailed_top_places |
|
92 | - * @param bool $use_flags |
|
93 | - * @return static |
|
94 | - */ |
|
95 | - public function with( |
|
96 | - bool $enabled, |
|
97 | - string $description, |
|
98 | - GeoAnalysisInterface $geoanalysis, |
|
99 | - int $depth, |
|
100 | - int $detailed_top_places = 0, |
|
101 | - bool $use_flags = false |
|
102 | - ): self { |
|
103 | - $new = clone $this; |
|
104 | - $new->enabled = $enabled; |
|
105 | - $new->description = $description; |
|
106 | - $new->geoanalysis = $geoanalysis; |
|
107 | - $new->depth = $depth; |
|
108 | - $new->detailed_top_places = $detailed_top_places; |
|
109 | - $new->use_flags = $use_flags; |
|
110 | - return $new; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Get the view ID |
|
115 | - * |
|
116 | - * @return int |
|
117 | - */ |
|
118 | - public function id(): int |
|
119 | - { |
|
120 | - return $this->id; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Get the view type for display |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - abstract public function type(): string; |
|
129 | - |
|
130 | - /** |
|
131 | - * Get the icon for the view type |
|
132 | - * |
|
133 | - * @param ModuleInterface $module |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - abstract public function icon(ModuleInterface $module): string; |
|
137 | - |
|
138 | - /** |
|
139 | - * Return the content of the global settings section of the config page |
|
140 | - * |
|
141 | - * @param ModuleInterface $module |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - abstract public function globalSettingsContent(ModuleInterface $module): string; |
|
145 | - |
|
146 | - /** |
|
147 | - * Return a view with global settings updated according to the view rules |
|
148 | - * |
|
149 | - * @param ServerRequestInterface $request |
|
150 | - * @return static |
|
151 | - */ |
|
152 | - abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self; |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the content of the view global tab |
|
156 | - * |
|
157 | - * @param GeoDispersionModule $module |
|
158 | - * @param GeoAnalysisResult $result |
|
159 | - * @param array<string, mixed> $params |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - abstract public function globalTabContent( |
|
163 | - GeoDispersionModule $module, |
|
164 | - GeoAnalysisResult $result, |
|
165 | - array $params |
|
166 | - ): string; |
|
167 | - |
|
168 | - /** |
|
169 | - * Returns the content of the view detailed tab |
|
170 | - * |
|
171 | - * @param ModuleInterface $module |
|
172 | - * @param Collection<string, GeoAnalysisResult> $results |
|
173 | - * @param array<string, mixed> $params |
|
174 | - * @return string |
|
175 | - */ |
|
176 | - public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
|
177 | - { |
|
178 | - return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Get the tree to which the view belongs |
|
183 | - * |
|
184 | - * @return Tree |
|
185 | - */ |
|
186 | - public function tree(): Tree |
|
187 | - { |
|
188 | - return $this->tree; |
|
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get the description of the view |
|
193 | - * |
|
194 | - * @return string |
|
195 | - */ |
|
196 | - public function description(): string |
|
197 | - { |
|
198 | - return $this->description; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * Get whether the view is enabled |
|
203 | - * |
|
204 | - * @return bool |
|
205 | - */ |
|
206 | - public function isEnabled(): bool |
|
207 | - { |
|
208 | - return $this->enabled; |
|
209 | - } |
|
210 | - |
|
211 | - /** |
|
212 | - * Get the geographical dispersion analysis for the view |
|
213 | - * |
|
214 | - * @return GeoAnalysisInterface |
|
215 | - */ |
|
216 | - public function analysis(): GeoAnalysisInterface |
|
217 | - { |
|
218 | - return $this->geoanalysis; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Get the place hierarchy depth for the view |
|
223 | - * |
|
224 | - * @return int |
|
225 | - */ |
|
226 | - public function placesDepth(): int |
|
227 | - { |
|
228 | - return $this->depth; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * Get the number of places to display in the detailed tab |
|
233 | - * |
|
234 | - * @return int |
|
235 | - */ |
|
236 | - public function numberTopPlaces(): int |
|
237 | - { |
|
238 | - return $this->detailed_top_places; |
|
239 | - } |
|
240 | - |
|
241 | - /** |
|
242 | - * Get whether flags should be used in the detailed tab |
|
243 | - * |
|
244 | - * @return bool |
|
245 | - */ |
|
246 | - public function useFlags(): bool |
|
247 | - { |
|
248 | - return $this->use_flags; |
|
249 | - } |
|
30 | + private int $id; |
|
31 | + private Tree $tree; |
|
32 | + private bool $enabled; |
|
33 | + private string $description; |
|
34 | + private GeoAnalysisInterface $geoanalysis; |
|
35 | + private int $depth; |
|
36 | + private int $detailed_top_places; |
|
37 | + private bool $use_flags; |
|
38 | + |
|
39 | + /** |
|
40 | + * Constructor for AbstractGeoAnalysisView |
|
41 | + * |
|
42 | + * @param int $id |
|
43 | + * @param Tree $tree |
|
44 | + * @param bool $enabled |
|
45 | + * @param string $description |
|
46 | + * @param GeoAnalysisInterface $geoanalysis |
|
47 | + * @param int $depth |
|
48 | + * @param int $detailed_top_places |
|
49 | + * @param bool $use_flags |
|
50 | + */ |
|
51 | + final public function __construct( |
|
52 | + int $id, |
|
53 | + Tree $tree, |
|
54 | + bool $enabled, |
|
55 | + string $description, |
|
56 | + GeoAnalysisInterface $geoanalysis, |
|
57 | + int $depth, |
|
58 | + int $detailed_top_places = 0, |
|
59 | + bool $use_flags = false |
|
60 | + ) { |
|
61 | + $this->id = $id; |
|
62 | + $this->tree = $tree; |
|
63 | + $this->enabled = $enabled; |
|
64 | + $this->description = $description; |
|
65 | + $this->geoanalysis = $geoanalysis; |
|
66 | + $this->depth = $depth; |
|
67 | + $this->detailed_top_places = $detailed_top_places; |
|
68 | + $this->use_flags = $use_flags; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Create a copy of the view with a new ID. |
|
73 | + * |
|
74 | + * @param int $id |
|
75 | + * @return static |
|
76 | + */ |
|
77 | + public function withId(int $id): self |
|
78 | + { |
|
79 | + $new = clone $this; |
|
80 | + $new->id = $id; |
|
81 | + return $new; |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * Create a copy of the view with new properties. |
|
86 | + * |
|
87 | + * @param bool $enabled |
|
88 | + * @param string $description |
|
89 | + * @param GeoAnalysisInterface $geoanalysis |
|
90 | + * @param int $depth |
|
91 | + * @param int $detailed_top_places |
|
92 | + * @param bool $use_flags |
|
93 | + * @return static |
|
94 | + */ |
|
95 | + public function with( |
|
96 | + bool $enabled, |
|
97 | + string $description, |
|
98 | + GeoAnalysisInterface $geoanalysis, |
|
99 | + int $depth, |
|
100 | + int $detailed_top_places = 0, |
|
101 | + bool $use_flags = false |
|
102 | + ): self { |
|
103 | + $new = clone $this; |
|
104 | + $new->enabled = $enabled; |
|
105 | + $new->description = $description; |
|
106 | + $new->geoanalysis = $geoanalysis; |
|
107 | + $new->depth = $depth; |
|
108 | + $new->detailed_top_places = $detailed_top_places; |
|
109 | + $new->use_flags = $use_flags; |
|
110 | + return $new; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Get the view ID |
|
115 | + * |
|
116 | + * @return int |
|
117 | + */ |
|
118 | + public function id(): int |
|
119 | + { |
|
120 | + return $this->id; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Get the view type for display |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + abstract public function type(): string; |
|
129 | + |
|
130 | + /** |
|
131 | + * Get the icon for the view type |
|
132 | + * |
|
133 | + * @param ModuleInterface $module |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + abstract public function icon(ModuleInterface $module): string; |
|
137 | + |
|
138 | + /** |
|
139 | + * Return the content of the global settings section of the config page |
|
140 | + * |
|
141 | + * @param ModuleInterface $module |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + abstract public function globalSettingsContent(ModuleInterface $module): string; |
|
145 | + |
|
146 | + /** |
|
147 | + * Return a view with global settings updated according to the view rules |
|
148 | + * |
|
149 | + * @param ServerRequestInterface $request |
|
150 | + * @return static |
|
151 | + */ |
|
152 | + abstract public function withGlobalSettingsUpdate(ServerRequestInterface $request): self; |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the content of the view global tab |
|
156 | + * |
|
157 | + * @param GeoDispersionModule $module |
|
158 | + * @param GeoAnalysisResult $result |
|
159 | + * @param array<string, mixed> $params |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + abstract public function globalTabContent( |
|
163 | + GeoDispersionModule $module, |
|
164 | + GeoAnalysisResult $result, |
|
165 | + array $params |
|
166 | + ): string; |
|
167 | + |
|
168 | + /** |
|
169 | + * Returns the content of the view detailed tab |
|
170 | + * |
|
171 | + * @param ModuleInterface $module |
|
172 | + * @param Collection<string, GeoAnalysisResult> $results |
|
173 | + * @param array<string, mixed> $params |
|
174 | + * @return string |
|
175 | + */ |
|
176 | + public function detailedTabContent(ModuleInterface $module, Collection $results, array $params): string |
|
177 | + { |
|
178 | + return view($module->name() . '::geoanalysisview-tab-detailed', $params + [ 'results' => $results ]); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Get the tree to which the view belongs |
|
183 | + * |
|
184 | + * @return Tree |
|
185 | + */ |
|
186 | + public function tree(): Tree |
|
187 | + { |
|
188 | + return $this->tree; |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get the description of the view |
|
193 | + * |
|
194 | + * @return string |
|
195 | + */ |
|
196 | + public function description(): string |
|
197 | + { |
|
198 | + return $this->description; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * Get whether the view is enabled |
|
203 | + * |
|
204 | + * @return bool |
|
205 | + */ |
|
206 | + public function isEnabled(): bool |
|
207 | + { |
|
208 | + return $this->enabled; |
|
209 | + } |
|
210 | + |
|
211 | + /** |
|
212 | + * Get the geographical dispersion analysis for the view |
|
213 | + * |
|
214 | + * @return GeoAnalysisInterface |
|
215 | + */ |
|
216 | + public function analysis(): GeoAnalysisInterface |
|
217 | + { |
|
218 | + return $this->geoanalysis; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Get the place hierarchy depth for the view |
|
223 | + * |
|
224 | + * @return int |
|
225 | + */ |
|
226 | + public function placesDepth(): int |
|
227 | + { |
|
228 | + return $this->depth; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * Get the number of places to display in the detailed tab |
|
233 | + * |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + public function numberTopPlaces(): int |
|
237 | + { |
|
238 | + return $this->detailed_top_places; |
|
239 | + } |
|
240 | + |
|
241 | + /** |
|
242 | + * Get whether flags should be used in the detailed tab |
|
243 | + * |
|
244 | + * @return bool |
|
245 | + */ |
|
246 | + public function useFlags(): bool |
|
247 | + { |
|
248 | + return $this->use_flags; |
|
249 | + } |
|
250 | 250 | } |
@@ -31,119 +31,119 @@ |
||
31 | 31 | */ |
32 | 32 | class GeoAnalysisMap extends AbstractGeoAnalysisView |
33 | 33 | { |
34 | - private ?MapColorsConfig $colors_config = null; |
|
35 | - |
|
36 | - public function type(): string |
|
37 | - { |
|
38 | - return I18N::translateContext('GEODISPERSION', 'Map'); |
|
39 | - } |
|
40 | - |
|
41 | - /** |
|
42 | - * {@inheritDoc} |
|
43 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
44 | - */ |
|
45 | - public function icon(ModuleInterface $module): string |
|
46 | - { |
|
47 | - return view($module->name() . '::icons/view-map', ['type' => $this->type()]); |
|
48 | - } |
|
49 | - |
|
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent() |
|
53 | - */ |
|
54 | - public function globalSettingsContent(ModuleInterface $module): string |
|
55 | - { |
|
56 | - return view($module->name() . '::admin/view-edit-map', [ |
|
57 | - 'module_name' => $module->name(), |
|
58 | - 'view' => $this, |
|
59 | - 'colors' => $this->colors(), |
|
60 | - 'map_adapters' => app(MapAdapterDataService::class)->allForView($this, true) |
|
61 | - ]); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate() |
|
67 | - * @return static |
|
68 | - */ |
|
69 | - public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
|
70 | - { |
|
71 | - $params = (array) $request->getParsedBody(); |
|
72 | - |
|
73 | - $default_color = $params['view_map_color_default'] ?? ''; |
|
74 | - $stroke_color = $params['view_map_color_stroke'] ?? ''; |
|
75 | - $maxvalue_color = $params['view_map_color_maxvalue'] ?? ''; |
|
76 | - $hover_color = $params['view_map_color_hover'] ?? ''; |
|
77 | - |
|
78 | - try { |
|
79 | - return $this->withColors(new MapColorsConfig( |
|
80 | - Hex::fromString($default_color), |
|
81 | - Hex::fromString($stroke_color), |
|
82 | - Hex::fromString($maxvalue_color), |
|
83 | - Hex::fromString($hover_color) |
|
84 | - )); |
|
85 | - } catch (InvalidColorValue $ex) { |
|
86 | - } |
|
87 | - |
|
88 | - return $this; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * {@inheritDoc} |
|
93 | - * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
94 | - */ |
|
95 | - public function globalTabContent(GeoDispersionModule $module, GeoAnalysisResult $result, array $params): string |
|
96 | - { |
|
97 | - $map_adapters = app(MapAdapterDataService::class)->allForView($this); |
|
98 | - |
|
99 | - $adapter_result = null; |
|
100 | - foreach ($map_adapters as $map_adapter) { |
|
101 | - $adapter_result_tmp = $map_adapter->convert($result); |
|
102 | - $adapter_result = $adapter_result === null ? |
|
103 | - $adapter_result_tmp : |
|
104 | - $adapter_result->merge($adapter_result_tmp); |
|
105 | - } |
|
106 | - |
|
107 | - if ($adapter_result === null) { |
|
108 | - return view($module->name() . '::errors/tab-error', [ |
|
109 | - 'message' => I18N::translate('The map could not be loaded.'), |
|
110 | - ]); |
|
111 | - } |
|
112 | - |
|
113 | - return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [ |
|
114 | - 'result' => $adapter_result->geoAnalysisResult(), |
|
115 | - 'features' => $adapter_result->features(), |
|
116 | - 'colors' => $this->colors(), |
|
117 | - 'leaflet_config' => app(LeafletJsService::class)->config(), |
|
118 | - 'js_script_url' => $module->assetUrl('js/geodispersion.min.js') |
|
119 | - ]); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Get the color scheme configuration for the map view |
|
124 | - * |
|
125 | - * @return MapColorsConfig |
|
126 | - */ |
|
127 | - public function colors(): MapColorsConfig |
|
128 | - { |
|
129 | - return $this->colors_config ?? new MapColorsConfig( |
|
130 | - new Rgb(245, 245, 245), |
|
131 | - new Rgb(213, 213, 213), |
|
132 | - new Rgb(4, 147, 171), |
|
133 | - new Rgb(255, 102, 0) |
|
134 | - ); |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Returns a map view with a new color scheme configuration |
|
139 | - * |
|
140 | - * @param MapColorsConfig $config |
|
141 | - * @return static |
|
142 | - */ |
|
143 | - public function withColors(?MapColorsConfig $config): self |
|
144 | - { |
|
145 | - $new = clone $this; |
|
146 | - $new->colors_config = $config; |
|
147 | - return $new; |
|
148 | - } |
|
34 | + private ?MapColorsConfig $colors_config = null; |
|
35 | + |
|
36 | + public function type(): string |
|
37 | + { |
|
38 | + return I18N::translateContext('GEODISPERSION', 'Map'); |
|
39 | + } |
|
40 | + |
|
41 | + /** |
|
42 | + * {@inheritDoc} |
|
43 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::icon() |
|
44 | + */ |
|
45 | + public function icon(ModuleInterface $module): string |
|
46 | + { |
|
47 | + return view($module->name() . '::icons/view-map', ['type' => $this->type()]); |
|
48 | + } |
|
49 | + |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalSettingsContent() |
|
53 | + */ |
|
54 | + public function globalSettingsContent(ModuleInterface $module): string |
|
55 | + { |
|
56 | + return view($module->name() . '::admin/view-edit-map', [ |
|
57 | + 'module_name' => $module->name(), |
|
58 | + 'view' => $this, |
|
59 | + 'colors' => $this->colors(), |
|
60 | + 'map_adapters' => app(MapAdapterDataService::class)->allForView($this, true) |
|
61 | + ]); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::withGlobalSettingsUpdate() |
|
67 | + * @return static |
|
68 | + */ |
|
69 | + public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
|
70 | + { |
|
71 | + $params = (array) $request->getParsedBody(); |
|
72 | + |
|
73 | + $default_color = $params['view_map_color_default'] ?? ''; |
|
74 | + $stroke_color = $params['view_map_color_stroke'] ?? ''; |
|
75 | + $maxvalue_color = $params['view_map_color_maxvalue'] ?? ''; |
|
76 | + $hover_color = $params['view_map_color_hover'] ?? ''; |
|
77 | + |
|
78 | + try { |
|
79 | + return $this->withColors(new MapColorsConfig( |
|
80 | + Hex::fromString($default_color), |
|
81 | + Hex::fromString($stroke_color), |
|
82 | + Hex::fromString($maxvalue_color), |
|
83 | + Hex::fromString($hover_color) |
|
84 | + )); |
|
85 | + } catch (InvalidColorValue $ex) { |
|
86 | + } |
|
87 | + |
|
88 | + return $this; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * {@inheritDoc} |
|
93 | + * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisView::globalTabContent() |
|
94 | + */ |
|
95 | + public function globalTabContent(GeoDispersionModule $module, GeoAnalysisResult $result, array $params): string |
|
96 | + { |
|
97 | + $map_adapters = app(MapAdapterDataService::class)->allForView($this); |
|
98 | + |
|
99 | + $adapter_result = null; |
|
100 | + foreach ($map_adapters as $map_adapter) { |
|
101 | + $adapter_result_tmp = $map_adapter->convert($result); |
|
102 | + $adapter_result = $adapter_result === null ? |
|
103 | + $adapter_result_tmp : |
|
104 | + $adapter_result->merge($adapter_result_tmp); |
|
105 | + } |
|
106 | + |
|
107 | + if ($adapter_result === null) { |
|
108 | + return view($module->name() . '::errors/tab-error', [ |
|
109 | + 'message' => I18N::translate('The map could not be loaded.'), |
|
110 | + ]); |
|
111 | + } |
|
112 | + |
|
113 | + return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [ |
|
114 | + 'result' => $adapter_result->geoAnalysisResult(), |
|
115 | + 'features' => $adapter_result->features(), |
|
116 | + 'colors' => $this->colors(), |
|
117 | + 'leaflet_config' => app(LeafletJsService::class)->config(), |
|
118 | + 'js_script_url' => $module->assetUrl('js/geodispersion.min.js') |
|
119 | + ]); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Get the color scheme configuration for the map view |
|
124 | + * |
|
125 | + * @return MapColorsConfig |
|
126 | + */ |
|
127 | + public function colors(): MapColorsConfig |
|
128 | + { |
|
129 | + return $this->colors_config ?? new MapColorsConfig( |
|
130 | + new Rgb(245, 245, 245), |
|
131 | + new Rgb(213, 213, 213), |
|
132 | + new Rgb(4, 147, 171), |
|
133 | + new Rgb(255, 102, 0) |
|
134 | + ); |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Returns a map view with a new color scheme configuration |
|
139 | + * |
|
140 | + * @param MapColorsConfig $config |
|
141 | + * @return static |
|
142 | + */ |
|
143 | + public function withColors(?MapColorsConfig $config): self |
|
144 | + { |
|
145 | + $new = clone $this; |
|
146 | + $new->colors_config = $config; |
|
147 | + return $new; |
|
148 | + } |
|
149 | 149 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public function icon(ModuleInterface $module): string |
46 | 46 | { |
47 | - return view($module->name() . '::icons/view-map', ['type' => $this->type()]); |
|
47 | + return view($module->name().'::icons/view-map', ['type' => $this->type()]); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | public function globalSettingsContent(ModuleInterface $module): string |
55 | 55 | { |
56 | - return view($module->name() . '::admin/view-edit-map', [ |
|
56 | + return view($module->name().'::admin/view-edit-map', [ |
|
57 | 57 | 'module_name' => $module->name(), |
58 | 58 | 'view' => $this, |
59 | 59 | 'colors' => $this->colors(), |
@@ -68,12 +68,12 @@ discard block |
||
68 | 68 | */ |
69 | 69 | public function withGlobalSettingsUpdate(ServerRequestInterface $request): self |
70 | 70 | { |
71 | - $params = (array) $request->getParsedBody(); |
|
71 | + $params = (array)$request->getParsedBody(); |
|
72 | 72 | |
73 | 73 | $default_color = $params['view_map_color_default'] ?? ''; |
74 | 74 | $stroke_color = $params['view_map_color_stroke'] ?? ''; |
75 | - $maxvalue_color = $params['view_map_color_maxvalue'] ?? ''; |
|
76 | - $hover_color = $params['view_map_color_hover'] ?? ''; |
|
75 | + $maxvalue_color = $params['view_map_color_maxvalue'] ?? ''; |
|
76 | + $hover_color = $params['view_map_color_hover'] ?? ''; |
|
77 | 77 | |
78 | 78 | try { |
79 | 79 | return $this->withColors(new MapColorsConfig( |
@@ -100,17 +100,16 @@ discard block |
||
100 | 100 | foreach ($map_adapters as $map_adapter) { |
101 | 101 | $adapter_result_tmp = $map_adapter->convert($result); |
102 | 102 | $adapter_result = $adapter_result === null ? |
103 | - $adapter_result_tmp : |
|
104 | - $adapter_result->merge($adapter_result_tmp); |
|
103 | + $adapter_result_tmp : $adapter_result->merge($adapter_result_tmp); |
|
105 | 104 | } |
106 | 105 | |
107 | 106 | if ($adapter_result === null) { |
108 | - return view($module->name() . '::errors/tab-error', [ |
|
107 | + return view($module->name().'::errors/tab-error', [ |
|
109 | 108 | 'message' => I18N::translate('The map could not be loaded.'), |
110 | 109 | ]); |
111 | 110 | } |
112 | 111 | |
113 | - return view($module->name() . '::geoanalysisview-tab-glb-map', $params + [ |
|
112 | + return view($module->name().'::geoanalysisview-tab-glb-map', $params + [ |
|
114 | 113 | 'result' => $adapter_result->geoAnalysisResult(), |
115 | 114 | 'features' => $adapter_result->features(), |
116 | 115 | 'colors' => $this->colors(), |
@@ -42,106 +42,106 @@ |
||
42 | 42 | * Provide entry points to extend core webtrees code. |
43 | 43 | */ |
44 | 44 | class HooksModule extends AbstractModule implements |
45 | - ModuleMyArtJaubInterface, |
|
46 | - ModuleConfigInterface, |
|
47 | - ModuleHookSubscriberInterface |
|
45 | + ModuleMyArtJaubInterface, |
|
46 | + ModuleConfigInterface, |
|
47 | + ModuleHookSubscriberInterface |
|
48 | 48 | { |
49 | - use ModuleMyArtJaubTrait { |
|
50 | - boot as traitBoot; |
|
51 | - } |
|
52 | - use ModuleConfigTrait; |
|
53 | - |
|
54 | - // How to update the database schema for this module |
|
55 | - private const SCHEMA_TARGET_VERSION = 2; |
|
56 | - private const SCHEMA_SETTING_NAME = 'MAJ_HOOKS_SCHEMA_VERSION'; |
|
57 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
58 | - |
|
59 | - /** |
|
60 | - * {@inheritDoc} |
|
61 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
62 | - */ |
|
63 | - public function title(): string |
|
64 | - { |
|
65 | - return /* I18N: Name of the “Hooks” module */ I18N::translate('Hooks'); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * {@inheritDoc} |
|
70 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
71 | - */ |
|
72 | - public function description(): string |
|
73 | - { |
|
74 | - return /* I18N: Description of the “Hooks” module */ I18N::translate('Implements hooks management.'); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * {@inheritDoc} |
|
79 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
80 | - */ |
|
81 | - public function boot(): void |
|
82 | - { |
|
83 | - $this->traitBoot(); |
|
84 | - app()->bind(HookServiceInterface::class, HookService::class); |
|
85 | - app(MigrationService::class)->updateSchema( |
|
86 | - self::SCHEMA_MIGRATION_PREFIX, |
|
87 | - self::SCHEMA_SETTING_NAME, |
|
88 | - self::SCHEMA_TARGET_VERSION |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * {@inheritDoc} |
|
94 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
95 | - */ |
|
96 | - public function loadRoutes(Map $router): void |
|
97 | - { |
|
98 | - $router->attach('', '', static function (Map $router): void { |
|
99 | - |
|
100 | - $router->attach('', '/module-maj/hooks', static function (Map $router): void { |
|
101 | - |
|
102 | - $router->attach('', '/config/admin', static function (Map $router): void { |
|
103 | - |
|
104 | - $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
|
105 | - $router->get(ModulesHooksPage::class, '/{hook_name}', ModulesHooksPage::class); |
|
106 | - $router->post(ModulesHooksAction::class, '/{hook_name}', ModulesHooksAction::class); |
|
107 | - }); |
|
108 | - }); |
|
109 | - }); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * {@inheritDoc} |
|
114 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
115 | - */ |
|
116 | - public function customModuleVersion(): string |
|
117 | - { |
|
118 | - return '2.1.0-v.1'; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * {@inheritDoc} |
|
123 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
124 | - */ |
|
125 | - public function getConfigLink(): string |
|
126 | - { |
|
127 | - return route(AdminConfigPage::class); |
|
128 | - } |
|
129 | - |
|
130 | - /** |
|
131 | - * {@inheritDoc} |
|
132 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
133 | - */ |
|
134 | - public function listSubscribedHooks(): array |
|
135 | - { |
|
136 | - return [ |
|
137 | - app()->makeWith(FactSourceTextExtenderCollector::class, ['module' => $this]), |
|
138 | - app()->makeWith(FamilyDatatablesExtenderCollector::class, ['module' => $this]), |
|
139 | - app()->makeWith(IndividualDatatablesExtenderCollector::class, ['module' => $this]), |
|
140 | - app()->makeWith(NameAccordionExtenderCollector::class, ['module' => $this]), |
|
141 | - app()->makeWith(RecordNameTextExtenderCollector::class, ['module' => $this]), |
|
142 | - app()->makeWith(SosaFamilyDatatablesExtenderCollector::class, ['module' => $this]), |
|
143 | - app()->makeWith(SosaIndividualDatatablesExtenderCollector::class, ['module' => $this]), |
|
144 | - app()->makeWith(SosaMissingDatatablesExtenderCollector::class, ['module' => $this]) |
|
145 | - ]; |
|
146 | - } |
|
49 | + use ModuleMyArtJaubTrait { |
|
50 | + boot as traitBoot; |
|
51 | + } |
|
52 | + use ModuleConfigTrait; |
|
53 | + |
|
54 | + // How to update the database schema for this module |
|
55 | + private const SCHEMA_TARGET_VERSION = 2; |
|
56 | + private const SCHEMA_SETTING_NAME = 'MAJ_HOOKS_SCHEMA_VERSION'; |
|
57 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
58 | + |
|
59 | + /** |
|
60 | + * {@inheritDoc} |
|
61 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
62 | + */ |
|
63 | + public function title(): string |
|
64 | + { |
|
65 | + return /* I18N: Name of the “Hooks” module */ I18N::translate('Hooks'); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * {@inheritDoc} |
|
70 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
71 | + */ |
|
72 | + public function description(): string |
|
73 | + { |
|
74 | + return /* I18N: Description of the “Hooks” module */ I18N::translate('Implements hooks management.'); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * {@inheritDoc} |
|
79 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
80 | + */ |
|
81 | + public function boot(): void |
|
82 | + { |
|
83 | + $this->traitBoot(); |
|
84 | + app()->bind(HookServiceInterface::class, HookService::class); |
|
85 | + app(MigrationService::class)->updateSchema( |
|
86 | + self::SCHEMA_MIGRATION_PREFIX, |
|
87 | + self::SCHEMA_SETTING_NAME, |
|
88 | + self::SCHEMA_TARGET_VERSION |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * {@inheritDoc} |
|
94 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
95 | + */ |
|
96 | + public function loadRoutes(Map $router): void |
|
97 | + { |
|
98 | + $router->attach('', '', static function (Map $router): void { |
|
99 | + |
|
100 | + $router->attach('', '/module-maj/hooks', static function (Map $router): void { |
|
101 | + |
|
102 | + $router->attach('', '/config/admin', static function (Map $router): void { |
|
103 | + |
|
104 | + $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
|
105 | + $router->get(ModulesHooksPage::class, '/{hook_name}', ModulesHooksPage::class); |
|
106 | + $router->post(ModulesHooksAction::class, '/{hook_name}', ModulesHooksAction::class); |
|
107 | + }); |
|
108 | + }); |
|
109 | + }); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * {@inheritDoc} |
|
114 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
115 | + */ |
|
116 | + public function customModuleVersion(): string |
|
117 | + { |
|
118 | + return '2.1.0-v.1'; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * {@inheritDoc} |
|
123 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
124 | + */ |
|
125 | + public function getConfigLink(): string |
|
126 | + { |
|
127 | + return route(AdminConfigPage::class); |
|
128 | + } |
|
129 | + |
|
130 | + /** |
|
131 | + * {@inheritDoc} |
|
132 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
133 | + */ |
|
134 | + public function listSubscribedHooks(): array |
|
135 | + { |
|
136 | + return [ |
|
137 | + app()->makeWith(FactSourceTextExtenderCollector::class, ['module' => $this]), |
|
138 | + app()->makeWith(FamilyDatatablesExtenderCollector::class, ['module' => $this]), |
|
139 | + app()->makeWith(IndividualDatatablesExtenderCollector::class, ['module' => $this]), |
|
140 | + app()->makeWith(NameAccordionExtenderCollector::class, ['module' => $this]), |
|
141 | + app()->makeWith(RecordNameTextExtenderCollector::class, ['module' => $this]), |
|
142 | + app()->makeWith(SosaFamilyDatatablesExtenderCollector::class, ['module' => $this]), |
|
143 | + app()->makeWith(SosaIndividualDatatablesExtenderCollector::class, ['module' => $this]), |
|
144 | + app()->makeWith(SosaMissingDatatablesExtenderCollector::class, ['module' => $this]) |
|
145 | + ]; |
|
146 | + } |
|
147 | 147 | } |
@@ -56,263 +56,263 @@ |
||
56 | 56 | * Identify and produce statistics about Sosa ancestors |
57 | 57 | */ |
58 | 58 | class SosaModule extends AbstractModule implements |
59 | - ModuleMyArtJaubInterface, |
|
60 | - ModuleGlobalInterface, |
|
61 | - ModuleMenuInterface, |
|
62 | - ModuleSidebarInterface, |
|
63 | - ModuleGeoAnalysisProviderInterface, |
|
64 | - ModuleHookSubscriberInterface |
|
59 | + ModuleMyArtJaubInterface, |
|
60 | + ModuleGlobalInterface, |
|
61 | + ModuleMenuInterface, |
|
62 | + ModuleSidebarInterface, |
|
63 | + ModuleGeoAnalysisProviderInterface, |
|
64 | + ModuleHookSubscriberInterface |
|
65 | 65 | { |
66 | - use ModuleMyArtJaubTrait { |
|
67 | - boot as traitBoot; |
|
68 | - } |
|
69 | - use ModuleGlobalTrait; |
|
70 | - use ModuleMenuTrait; |
|
71 | - use ModuleSidebarTrait; |
|
72 | - |
|
73 | - // How to update the database schema for this module |
|
74 | - private const SCHEMA_TARGET_VERSION = 3; |
|
75 | - private const SCHEMA_SETTING_NAME = 'MAJ_SOSA_SCHEMA_VERSION'; |
|
76 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
66 | + use ModuleMyArtJaubTrait { |
|
67 | + boot as traitBoot; |
|
68 | + } |
|
69 | + use ModuleGlobalTrait; |
|
70 | + use ModuleMenuTrait; |
|
71 | + use ModuleSidebarTrait; |
|
72 | + |
|
73 | + // How to update the database schema for this module |
|
74 | + private const SCHEMA_TARGET_VERSION = 3; |
|
75 | + private const SCHEMA_SETTING_NAME = 'MAJ_SOSA_SCHEMA_VERSION'; |
|
76 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
77 | 77 | /** |
78 | - * {@inheritDoc} |
|
79 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
80 | - */ |
|
81 | - public function title(): string |
|
82 | - { |
|
83 | - return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa'); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * {@inheritDoc} |
|
88 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
89 | - */ |
|
90 | - public function description(): string |
|
91 | - { |
|
92 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
93 | - return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.'); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * {@inheritDoc} |
|
98 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
99 | - */ |
|
100 | - public function boot(): void |
|
101 | - { |
|
102 | - $this->traitBoot(); |
|
103 | - app(MigrationService::class)->updateSchema( |
|
104 | - self::SCHEMA_MIGRATION_PREFIX, |
|
105 | - self::SCHEMA_SETTING_NAME, |
|
106 | - self::SCHEMA_TARGET_VERSION |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * {@inheritDoc} |
|
112 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
113 | - */ |
|
114 | - public function loadRoutes(Map $router): void |
|
115 | - { |
|
116 | - $router->attach('', '', static function (Map $router): void { |
|
117 | - |
|
118 | - $router->attach('', '/module-maj/sosa', static function (Map $router): void { |
|
119 | - |
|
120 | - $router->attach('', '/list', static function (Map $router): void { |
|
121 | - $router->tokens(['gen' => '\d+']); |
|
122 | - $router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class); |
|
123 | - $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
124 | - $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
125 | - $router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class); |
|
126 | - }); |
|
127 | - |
|
128 | - $router->attach('', '/statistics/{tree}', static function (Map $router): void { |
|
129 | - |
|
130 | - $router->get(SosaStatistics::class, '', SosaStatistics::class); |
|
131 | - $router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class); |
|
132 | - }); |
|
133 | - |
|
134 | - $router->attach('', '/config/{tree}', static function (Map $router): void { |
|
135 | - |
|
136 | - $router->get(SosaConfig::class, '', SosaConfig::class); |
|
137 | - $router->post(SosaConfigAction::class, '', SosaConfigAction::class); |
|
138 | - $router->get(SosaComputeModal::class, '/compute/{xref}', SosaComputeModal::class); |
|
139 | - $router->post(SosaComputeAction::class, '/compute', SosaComputeAction::class); |
|
140 | - }); |
|
141 | - }); |
|
142 | - }); |
|
143 | - } |
|
144 | - |
|
145 | - /** |
|
146 | - * {@inheritDoc} |
|
147 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
148 | - */ |
|
149 | - public function customModuleVersion(): string |
|
150 | - { |
|
151 | - return '2.1.0-v.1'; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * {@inheritDoc} |
|
156 | - * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder() |
|
157 | - */ |
|
158 | - public function defaultMenuOrder(): int |
|
159 | - { |
|
160 | - return 7; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * {@inhericDoc} |
|
165 | - * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu() |
|
166 | - */ |
|
167 | - public function getMenu(Tree $tree): ?Menu |
|
168 | - { |
|
169 | - $menu = new Menu(I18N::translate('Sosa Statistics')); |
|
170 | - $menu->setClass('menu-maj-sosa'); |
|
171 | - $menu->setSubmenus([ |
|
172 | - new Menu( |
|
173 | - I18N::translate('Sosa Ancestors'), |
|
174 | - route(AncestorsList::class, ['tree' => $tree->name()]), |
|
175 | - 'menu-maj-sosa-list', |
|
176 | - ['rel' => 'nofollow'] |
|
177 | - ), |
|
178 | - new Menu( |
|
179 | - I18N::translate('Missing Ancestors'), |
|
180 | - route(MissingAncestorsList::class, ['tree' => $tree->name()]), |
|
181 | - 'menu-maj-sosa-missing', |
|
182 | - ['rel' => 'nofollow'] |
|
183 | - ), |
|
184 | - new Menu( |
|
185 | - I18N::translate('Sosa Statistics'), |
|
186 | - route(SosaStatistics::class, ['tree' => $tree->name()]), |
|
187 | - 'menu-maj-sosa-stats' |
|
188 | - ) |
|
189 | - ]); |
|
190 | - |
|
191 | - if (Auth::check()) { |
|
192 | - $menu->addSubmenu(new Menu( |
|
193 | - I18N::translate('Sosa Configuration'), |
|
194 | - route(SosaConfig::class, ['tree' => $tree->name()]), |
|
195 | - 'menu-maj-sosa-config' |
|
196 | - )); |
|
197 | - |
|
198 | - /** @var ServerRequestInterface $request */ |
|
199 | - $request = app(ServerRequestInterface::class); |
|
200 | - $route = $request->getAttribute('route'); |
|
201 | - assert($route instanceof Route); |
|
202 | - |
|
203 | - $root_indi_id = $tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
|
204 | - |
|
205 | - if ($route->name === IndividualPage::class && mb_strlen($root_indi_id) > 0) { |
|
206 | - $xref = $request->getAttribute('xref'); |
|
207 | - assert(is_string($xref)); |
|
208 | - |
|
209 | - $menu->addSubmenu(new Menu( |
|
210 | - I18N::translate('Complete Sosas'), |
|
211 | - '#', |
|
212 | - 'menu-maj-sosa-compute', |
|
213 | - [ |
|
214 | - 'rel' => 'nofollow', |
|
215 | - 'data-href' => route(SosaComputeModal::class, ['tree' => $tree->name(), 'xref' => $xref]), |
|
216 | - 'data-target' => '#wt-ajax-modal', |
|
217 | - 'data-toggle' => 'modal', |
|
218 | - 'data-backdrop' => 'static' |
|
219 | - ] |
|
220 | - )); |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - return $menu; |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * {@inheritDoc} |
|
229 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
230 | - */ |
|
231 | - public function headContent(): string |
|
232 | - { |
|
233 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * {@inheritDoc} |
|
238 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
239 | - */ |
|
240 | - public function bodyContent(): string |
|
241 | - { |
|
242 | - return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>'; |
|
243 | - } |
|
244 | - |
|
245 | - /** |
|
246 | - * {@inheritDoc} |
|
247 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::sidebarTitle() |
|
248 | - */ |
|
249 | - public function sidebarTitle(Individual $individual): string |
|
250 | - { |
|
251 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
252 | - |
|
253 | - return view($this->name() . '::sidebar/title', [ |
|
254 | - 'module_name' => $this->name(), |
|
255 | - 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
256 | - ]); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * {@inheritDoc} |
|
261 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent() |
|
262 | - */ |
|
263 | - public function getSidebarContent(Individual $individual): string |
|
264 | - { |
|
265 | - $sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
|
266 | - $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree()); |
|
267 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
268 | - |
|
269 | - return view($this->name() . '::sidebar/content', [ |
|
270 | - 'sosa_ancestor' => $individual, |
|
271 | - 'sosa_root' => $sosa_root, |
|
272 | - 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
273 | - ]); |
|
274 | - } |
|
275 | - |
|
276 | - /** |
|
277 | - * {@inheritDoc} |
|
278 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
|
279 | - */ |
|
280 | - public function hasSidebarContent(Individual $individual): bool |
|
281 | - { |
|
282 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
283 | - |
|
284 | - return app(SosaRecordsService::class) |
|
285 | - ->sosaNumbers($individual->tree(), $user, $individual)->count() > 0; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * {@inheritDoc} |
|
290 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder() |
|
291 | - */ |
|
292 | - public function defaultSidebarOrder(): int |
|
293 | - { |
|
294 | - return 1; |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * {@inheritDoc} |
|
299 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
300 | - */ |
|
301 | - public function listGeoAnalyses(): array |
|
302 | - { |
|
303 | - return [ |
|
304 | - SosaByGenerationGeoAnalysis::class |
|
305 | - ]; |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * {@inheritDoc} |
|
310 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
311 | - */ |
|
312 | - public function listSubscribedHooks(): array |
|
313 | - { |
|
314 | - return [ |
|
315 | - app()->makeWith(SosaIconHook::class, [ 'module' => $this ]) |
|
316 | - ]; |
|
317 | - } |
|
78 | + * {@inheritDoc} |
|
79 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
80 | + */ |
|
81 | + public function title(): string |
|
82 | + { |
|
83 | + return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa'); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * {@inheritDoc} |
|
88 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
89 | + */ |
|
90 | + public function description(): string |
|
91 | + { |
|
92 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
93 | + return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.'); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * {@inheritDoc} |
|
98 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
99 | + */ |
|
100 | + public function boot(): void |
|
101 | + { |
|
102 | + $this->traitBoot(); |
|
103 | + app(MigrationService::class)->updateSchema( |
|
104 | + self::SCHEMA_MIGRATION_PREFIX, |
|
105 | + self::SCHEMA_SETTING_NAME, |
|
106 | + self::SCHEMA_TARGET_VERSION |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * {@inheritDoc} |
|
112 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
113 | + */ |
|
114 | + public function loadRoutes(Map $router): void |
|
115 | + { |
|
116 | + $router->attach('', '', static function (Map $router): void { |
|
117 | + |
|
118 | + $router->attach('', '/module-maj/sosa', static function (Map $router): void { |
|
119 | + |
|
120 | + $router->attach('', '/list', static function (Map $router): void { |
|
121 | + $router->tokens(['gen' => '\d+']); |
|
122 | + $router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class); |
|
123 | + $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
124 | + $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
125 | + $router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class); |
|
126 | + }); |
|
127 | + |
|
128 | + $router->attach('', '/statistics/{tree}', static function (Map $router): void { |
|
129 | + |
|
130 | + $router->get(SosaStatistics::class, '', SosaStatistics::class); |
|
131 | + $router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class); |
|
132 | + }); |
|
133 | + |
|
134 | + $router->attach('', '/config/{tree}', static function (Map $router): void { |
|
135 | + |
|
136 | + $router->get(SosaConfig::class, '', SosaConfig::class); |
|
137 | + $router->post(SosaConfigAction::class, '', SosaConfigAction::class); |
|
138 | + $router->get(SosaComputeModal::class, '/compute/{xref}', SosaComputeModal::class); |
|
139 | + $router->post(SosaComputeAction::class, '/compute', SosaComputeAction::class); |
|
140 | + }); |
|
141 | + }); |
|
142 | + }); |
|
143 | + } |
|
144 | + |
|
145 | + /** |
|
146 | + * {@inheritDoc} |
|
147 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
148 | + */ |
|
149 | + public function customModuleVersion(): string |
|
150 | + { |
|
151 | + return '2.1.0-v.1'; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * {@inheritDoc} |
|
156 | + * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder() |
|
157 | + */ |
|
158 | + public function defaultMenuOrder(): int |
|
159 | + { |
|
160 | + return 7; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * {@inhericDoc} |
|
165 | + * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu() |
|
166 | + */ |
|
167 | + public function getMenu(Tree $tree): ?Menu |
|
168 | + { |
|
169 | + $menu = new Menu(I18N::translate('Sosa Statistics')); |
|
170 | + $menu->setClass('menu-maj-sosa'); |
|
171 | + $menu->setSubmenus([ |
|
172 | + new Menu( |
|
173 | + I18N::translate('Sosa Ancestors'), |
|
174 | + route(AncestorsList::class, ['tree' => $tree->name()]), |
|
175 | + 'menu-maj-sosa-list', |
|
176 | + ['rel' => 'nofollow'] |
|
177 | + ), |
|
178 | + new Menu( |
|
179 | + I18N::translate('Missing Ancestors'), |
|
180 | + route(MissingAncestorsList::class, ['tree' => $tree->name()]), |
|
181 | + 'menu-maj-sosa-missing', |
|
182 | + ['rel' => 'nofollow'] |
|
183 | + ), |
|
184 | + new Menu( |
|
185 | + I18N::translate('Sosa Statistics'), |
|
186 | + route(SosaStatistics::class, ['tree' => $tree->name()]), |
|
187 | + 'menu-maj-sosa-stats' |
|
188 | + ) |
|
189 | + ]); |
|
190 | + |
|
191 | + if (Auth::check()) { |
|
192 | + $menu->addSubmenu(new Menu( |
|
193 | + I18N::translate('Sosa Configuration'), |
|
194 | + route(SosaConfig::class, ['tree' => $tree->name()]), |
|
195 | + 'menu-maj-sosa-config' |
|
196 | + )); |
|
197 | + |
|
198 | + /** @var ServerRequestInterface $request */ |
|
199 | + $request = app(ServerRequestInterface::class); |
|
200 | + $route = $request->getAttribute('route'); |
|
201 | + assert($route instanceof Route); |
|
202 | + |
|
203 | + $root_indi_id = $tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
|
204 | + |
|
205 | + if ($route->name === IndividualPage::class && mb_strlen($root_indi_id) > 0) { |
|
206 | + $xref = $request->getAttribute('xref'); |
|
207 | + assert(is_string($xref)); |
|
208 | + |
|
209 | + $menu->addSubmenu(new Menu( |
|
210 | + I18N::translate('Complete Sosas'), |
|
211 | + '#', |
|
212 | + 'menu-maj-sosa-compute', |
|
213 | + [ |
|
214 | + 'rel' => 'nofollow', |
|
215 | + 'data-href' => route(SosaComputeModal::class, ['tree' => $tree->name(), 'xref' => $xref]), |
|
216 | + 'data-target' => '#wt-ajax-modal', |
|
217 | + 'data-toggle' => 'modal', |
|
218 | + 'data-backdrop' => 'static' |
|
219 | + ] |
|
220 | + )); |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + return $menu; |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * {@inheritDoc} |
|
229 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
230 | + */ |
|
231 | + public function headContent(): string |
|
232 | + { |
|
233 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * {@inheritDoc} |
|
238 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
239 | + */ |
|
240 | + public function bodyContent(): string |
|
241 | + { |
|
242 | + return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>'; |
|
243 | + } |
|
244 | + |
|
245 | + /** |
|
246 | + * {@inheritDoc} |
|
247 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::sidebarTitle() |
|
248 | + */ |
|
249 | + public function sidebarTitle(Individual $individual): string |
|
250 | + { |
|
251 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
252 | + |
|
253 | + return view($this->name() . '::sidebar/title', [ |
|
254 | + 'module_name' => $this->name(), |
|
255 | + 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
256 | + ]); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * {@inheritDoc} |
|
261 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent() |
|
262 | + */ |
|
263 | + public function getSidebarContent(Individual $individual): string |
|
264 | + { |
|
265 | + $sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
|
266 | + $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree()); |
|
267 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
268 | + |
|
269 | + return view($this->name() . '::sidebar/content', [ |
|
270 | + 'sosa_ancestor' => $individual, |
|
271 | + 'sosa_root' => $sosa_root, |
|
272 | + 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
273 | + ]); |
|
274 | + } |
|
275 | + |
|
276 | + /** |
|
277 | + * {@inheritDoc} |
|
278 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
|
279 | + */ |
|
280 | + public function hasSidebarContent(Individual $individual): bool |
|
281 | + { |
|
282 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
283 | + |
|
284 | + return app(SosaRecordsService::class) |
|
285 | + ->sosaNumbers($individual->tree(), $user, $individual)->count() > 0; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * {@inheritDoc} |
|
290 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder() |
|
291 | + */ |
|
292 | + public function defaultSidebarOrder(): int |
|
293 | + { |
|
294 | + return 1; |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * {@inheritDoc} |
|
299 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
300 | + */ |
|
301 | + public function listGeoAnalyses(): array |
|
302 | + { |
|
303 | + return [ |
|
304 | + SosaByGenerationGeoAnalysis::class |
|
305 | + ]; |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * {@inheritDoc} |
|
310 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
311 | + */ |
|
312 | + public function listSubscribedHooks(): array |
|
313 | + { |
|
314 | + return [ |
|
315 | + app()->makeWith(SosaIconHook::class, [ 'module' => $this ]) |
|
316 | + ]; |
|
317 | + } |
|
318 | 318 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | // How to update the database schema for this module |
74 | 74 | private const SCHEMA_TARGET_VERSION = 3; |
75 | 75 | private const SCHEMA_SETTING_NAME = 'MAJ_SOSA_SCHEMA_VERSION'; |
76 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
76 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema'; |
|
77 | 77 | /** |
78 | 78 | * {@inheritDoc} |
79 | 79 | * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
@@ -113,25 +113,25 @@ discard block |
||
113 | 113 | */ |
114 | 114 | public function loadRoutes(Map $router): void |
115 | 115 | { |
116 | - $router->attach('', '', static function (Map $router): void { |
|
116 | + $router->attach('', '', static function(Map $router): void { |
|
117 | 117 | |
118 | - $router->attach('', '/module-maj/sosa', static function (Map $router): void { |
|
118 | + $router->attach('', '/module-maj/sosa', static function(Map $router): void { |
|
119 | 119 | |
120 | - $router->attach('', '/list', static function (Map $router): void { |
|
120 | + $router->attach('', '/list', static function(Map $router): void { |
|
121 | 121 | $router->tokens(['gen' => '\d+']); |
122 | 122 | $router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class); |
123 | - $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
124 | - $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
123 | + $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
124 | + $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
125 | 125 | $router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class); |
126 | 126 | }); |
127 | 127 | |
128 | - $router->attach('', '/statistics/{tree}', static function (Map $router): void { |
|
128 | + $router->attach('', '/statistics/{tree}', static function(Map $router): void { |
|
129 | 129 | |
130 | 130 | $router->get(SosaStatistics::class, '', SosaStatistics::class); |
131 | 131 | $router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class); |
132 | 132 | }); |
133 | 133 | |
134 | - $router->attach('', '/config/{tree}', static function (Map $router): void { |
|
134 | + $router->attach('', '/config/{tree}', static function(Map $router): void { |
|
135 | 135 | |
136 | 136 | $router->get(SosaConfig::class, '', SosaConfig::class); |
137 | 137 | $router->post(SosaConfigAction::class, '', SosaConfigAction::class); |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | */ |
231 | 231 | public function headContent(): string |
232 | 232 | { |
233 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
233 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
234 | 234 | } |
235 | 235 | |
236 | 236 | /** |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | */ |
240 | 240 | public function bodyContent(): string |
241 | 241 | { |
242 | - return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>'; |
|
242 | + return '<script src="'.$this->assetUrl('js/sosa.min.js').'"></script>'; |
|
243 | 243 | } |
244 | 244 | |
245 | 245 | /** |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | { |
251 | 251 | $user = Auth::check() ? Auth::user() : new DefaultUser(); |
252 | 252 | |
253 | - return view($this->name() . '::sidebar/title', [ |
|
253 | + return view($this->name().'::sidebar/title', [ |
|
254 | 254 | 'module_name' => $this->name(), |
255 | 255 | 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
256 | 256 | ]); |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree()); |
267 | 267 | $user = Auth::check() ? Auth::user() : new DefaultUser(); |
268 | 268 | |
269 | - return view($this->name() . '::sidebar/content', [ |
|
269 | + return view($this->name().'::sidebar/content', [ |
|
270 | 270 | 'sosa_ancestor' => $individual, |
271 | 271 | 'sosa_root' => $sosa_root, |
272 | 272 | 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | public function listSubscribedHooks(): array |
313 | 313 | { |
314 | 314 | return [ |
315 | - app()->makeWith(SosaIconHook::class, [ 'module' => $this ]) |
|
315 | + app()->makeWith(SosaIconHook::class, ['module' => $this]) |
|
316 | 316 | ]; |
317 | 317 | } |
318 | 318 | } |
@@ -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 | } |
@@ -29,514 +29,514 @@ |
||
29 | 29 | */ |
30 | 30 | class SosaStatisticsService |
31 | 31 | { |
32 | - private UserInterface $user; |
|
33 | - private Tree $tree; |
|
34 | - |
|
35 | - /** |
|
36 | - * Constructor for Sosa Statistics Service |
|
37 | - * |
|
38 | - * @param Tree $tree |
|
39 | - * @param UserInterface $user |
|
40 | - */ |
|
41 | - public function __construct(Tree $tree, UserInterface $user) |
|
42 | - { |
|
43 | - $this->tree = $tree; |
|
44 | - $this->user = $user; |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Return the root individual for the reference tree and user. |
|
49 | - * |
|
50 | - * @return Individual|NULL |
|
51 | - */ |
|
52 | - public function rootIndividual(): ?Individual |
|
53 | - { |
|
54 | - $root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
55 | - return Registry::individualFactory()->make($root_indi_id, $this->tree); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * Get the highest generation for the reference tree and user. |
|
60 | - * |
|
61 | - * @return int |
|
62 | - */ |
|
63 | - public function maxGeneration(): int |
|
64 | - { |
|
65 | - return (int) DB::table('maj_sosa') |
|
66 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
67 | - ->where('majs_user_id', '=', $this->user->id()) |
|
68 | - ->max('majs_gen'); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Get the total count of individuals in the tree. |
|
73 | - * |
|
74 | - * @return int |
|
75 | - */ |
|
76 | - public function totalIndividuals(): int |
|
77 | - { |
|
78 | - return DB::table('individuals') |
|
79 | - ->where('i_file', '=', $this->tree->id()) |
|
80 | - ->count(); |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Get the total count of Sosa ancestors for all generations |
|
85 | - * |
|
86 | - * @return int |
|
87 | - */ |
|
88 | - public function totalAncestors(): int |
|
89 | - { |
|
90 | - return DB::table('maj_sosa') |
|
91 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
92 | - ->where('majs_user_id', '=', $this->user->id()) |
|
93 | - ->count(); |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * Get the total count of Sosa ancestors for a generation |
|
98 | - * |
|
99 | - * @return int |
|
100 | - */ |
|
101 | - public function totalAncestorsAtGeneration(int $gen): int |
|
102 | - { |
|
103 | - return DB::table('maj_sosa') |
|
104 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
105 | - ->where('majs_user_id', '=', $this->user->id()) |
|
106 | - ->where('majs_gen', '=', $gen) |
|
107 | - ->count(); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * Get the total count of distinct Sosa ancestors for all generations |
|
112 | - * |
|
113 | - * @return int |
|
114 | - */ |
|
115 | - public function totalDistinctAncestors(): int |
|
116 | - { |
|
117 | - return DB::table('maj_sosa') |
|
118 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
119 | - ->where('majs_user_id', '=', $this->user->id()) |
|
120 | - ->distinct() |
|
121 | - ->count('majs_i_id'); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Get the mean generation time, as the slope of the linear regression of birth years vs generations |
|
126 | - * |
|
127 | - * @return float |
|
128 | - */ |
|
129 | - public function meanGenerationTime(): float |
|
130 | - { |
|
131 | - $row = DB::table('maj_sosa') |
|
132 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
133 | - ->where('majs_user_id', '=', $this->user->id()) |
|
134 | - ->whereNotNull('majs_birth_year') |
|
135 | - ->selectRaw('COUNT(majs_sosa) AS n') |
|
136 | - ->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy') |
|
137 | - ->selectRaw('SUM(majs_gen) AS sum_x') |
|
138 | - ->selectRaw('SUM(majs_birth_year) AS sum_y') |
|
139 | - ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2') |
|
140 | - ->get()->first(); |
|
141 | - |
|
142 | - return $row->n == 0 ? 0 : |
|
143 | - -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2)); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * Get the statistic array detailed by generation. |
|
148 | - * Statistics for each generation are: |
|
149 | - * - The number of Sosa in generation |
|
150 | - * - The number of Sosa up to generation |
|
151 | - * - The number of distinct Sosa up to generation |
|
152 | - * - The year of the first birth in generation |
|
153 | - * - The year of the first estimated birth in generation |
|
154 | - * - The year of the last birth in generation |
|
155 | - * - The year of the last estimated birth in generation |
|
156 | - * - The average year of birth in generation |
|
157 | - * |
|
158 | - * @return array<int, array<string, int|null>> Statistics array |
|
159 | - */ |
|
160 | - public function statisticsByGenerations(): array |
|
161 | - { |
|
162 | - $stats_by_gen = $this->statisticsByGenerationBasicData(); |
|
163 | - $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData(); |
|
164 | - |
|
165 | - $statistics_by_gen = []; |
|
166 | - foreach ($stats_by_gen as $gen => $stats_gen) { |
|
167 | - $statistics_by_gen[(int) $stats_gen->gen] = array( |
|
168 | - 'sosaCount' => (int) $stats_gen->total_sosa, |
|
169 | - 'sosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_cumul, |
|
170 | - 'diffSosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
171 | - 'firstBirth' => $stats_gen->first_year, |
|
172 | - 'firstEstimatedBirth' => $stats_gen->first_est_year, |
|
173 | - 'lastBirth' => $stats_gen->last_year, |
|
174 | - 'lastEstimatedBirth' => $stats_gen->last_est_year |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - return $statistics_by_gen; |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Returns the basic statistics data by generation. |
|
183 | - * |
|
184 | - * @return Collection<int, \stdClass> |
|
185 | - */ |
|
186 | - private function statisticsByGenerationBasicData(): Collection |
|
187 | - { |
|
188 | - return DB::table('maj_sosa') |
|
189 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
190 | - ->where('majs_user_id', '=', $this->user->id()) |
|
191 | - ->groupBy('majs_gen') |
|
192 | - ->orderBy('majs_gen', 'asc') |
|
193 | - ->select('majs_gen AS gen') |
|
194 | - ->selectRaw('COUNT(majs_sosa) AS total_sosa') |
|
195 | - ->selectRaw('MIN(majs_birth_year) AS first_year') |
|
196 | - ->selectRaw('MIN(majs_birth_year_est) AS first_est_year') |
|
197 | - ->selectRaw('MAX(majs_birth_year) AS last_year') |
|
198 | - ->selectRaw('MAX(majs_birth_year_est) AS last_est_year') |
|
199 | - ->get()->keyBy('gen'); |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Returns the cumulative statistics data by generation |
|
204 | - * |
|
205 | - * @return Collection<int, \stdClass> |
|
206 | - */ |
|
207 | - private function statisticsByGenerationCumulativeData(): Collection |
|
208 | - { |
|
209 | - $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
210 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
211 | - ->where('majs_user_id', '=', $this->user->id()); |
|
212 | - |
|
213 | - return DB::table('maj_sosa') |
|
214 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
215 | - $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen') |
|
216 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
217 | - ->where('majs_user_id', '=', $this->user->id()); |
|
218 | - }) |
|
219 | - ->groupBy('list_gen.majs_gen') |
|
220 | - ->select('list_gen.majs_gen AS gen') |
|
221 | - ->selectRaw('COUNT(majs_i_id) AS total_cumul') |
|
222 | - ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul') |
|
223 | - ->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple') |
|
224 | - ->get()->keyBy('gen'); |
|
225 | - } |
|
226 | - |
|
227 | - /** |
|
228 | - * Returns the pedigree collapse improved calculation by generation. |
|
229 | - * |
|
230 | - * Format: |
|
231 | - * - key : generation |
|
232 | - * - values: |
|
233 | - * - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation |
|
234 | - * - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation |
|
235 | - * |
|
236 | - * @return array<int, array<string, float>> |
|
237 | - */ |
|
238 | - public function pedigreeCollapseByGenerationData(): array |
|
239 | - { |
|
240 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
241 | - |
|
242 | - $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
243 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
244 | - ->where('majs_user_id', '=', $this->user->id()); |
|
245 | - |
|
246 | - /* Compute the contributions of nodes of previous generations to the current generation */ |
|
247 | - $root_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
248 | - ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
249 | - ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
250 | - ->selectRaw( |
|
251 | - '(CASE ' . |
|
252 | - ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' . |
|
253 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
254 | - ' ELSE 0 ' . |
|
255 | - ' END)' . |
|
256 | - ' + (CASE ' . |
|
257 | - ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' . |
|
258 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
259 | - ' ELSE 0 ' . |
|
260 | - ' END) contrib' |
|
261 | - ) |
|
262 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
263 | - $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen') |
|
264 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
265 | - ->where('majs_user_id', '=', $this->user->id()); |
|
266 | - }) |
|
267 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
268 | - // Link to sosa's father |
|
269 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
270 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
271 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
272 | - }) |
|
273 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
274 | - // Link to sosa's mother |
|
275 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
276 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
277 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
278 | - }) |
|
279 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
280 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
281 | - ->where(function (Builder $query): void { |
|
282 | - $query->whereNull('sosa_fat.majs_i_id') |
|
283 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
284 | - }); |
|
285 | - |
|
286 | - /* Identify nodes in the generations with ancestors who are also in the same generation. |
|
32 | + private UserInterface $user; |
|
33 | + private Tree $tree; |
|
34 | + |
|
35 | + /** |
|
36 | + * Constructor for Sosa Statistics Service |
|
37 | + * |
|
38 | + * @param Tree $tree |
|
39 | + * @param UserInterface $user |
|
40 | + */ |
|
41 | + public function __construct(Tree $tree, UserInterface $user) |
|
42 | + { |
|
43 | + $this->tree = $tree; |
|
44 | + $this->user = $user; |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Return the root individual for the reference tree and user. |
|
49 | + * |
|
50 | + * @return Individual|NULL |
|
51 | + */ |
|
52 | + public function rootIndividual(): ?Individual |
|
53 | + { |
|
54 | + $root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
55 | + return Registry::individualFactory()->make($root_indi_id, $this->tree); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * Get the highest generation for the reference tree and user. |
|
60 | + * |
|
61 | + * @return int |
|
62 | + */ |
|
63 | + public function maxGeneration(): int |
|
64 | + { |
|
65 | + return (int) DB::table('maj_sosa') |
|
66 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
67 | + ->where('majs_user_id', '=', $this->user->id()) |
|
68 | + ->max('majs_gen'); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Get the total count of individuals in the tree. |
|
73 | + * |
|
74 | + * @return int |
|
75 | + */ |
|
76 | + public function totalIndividuals(): int |
|
77 | + { |
|
78 | + return DB::table('individuals') |
|
79 | + ->where('i_file', '=', $this->tree->id()) |
|
80 | + ->count(); |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Get the total count of Sosa ancestors for all generations |
|
85 | + * |
|
86 | + * @return int |
|
87 | + */ |
|
88 | + public function totalAncestors(): int |
|
89 | + { |
|
90 | + return DB::table('maj_sosa') |
|
91 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
92 | + ->where('majs_user_id', '=', $this->user->id()) |
|
93 | + ->count(); |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * Get the total count of Sosa ancestors for a generation |
|
98 | + * |
|
99 | + * @return int |
|
100 | + */ |
|
101 | + public function totalAncestorsAtGeneration(int $gen): int |
|
102 | + { |
|
103 | + return DB::table('maj_sosa') |
|
104 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
105 | + ->where('majs_user_id', '=', $this->user->id()) |
|
106 | + ->where('majs_gen', '=', $gen) |
|
107 | + ->count(); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * Get the total count of distinct Sosa ancestors for all generations |
|
112 | + * |
|
113 | + * @return int |
|
114 | + */ |
|
115 | + public function totalDistinctAncestors(): int |
|
116 | + { |
|
117 | + return DB::table('maj_sosa') |
|
118 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
119 | + ->where('majs_user_id', '=', $this->user->id()) |
|
120 | + ->distinct() |
|
121 | + ->count('majs_i_id'); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Get the mean generation time, as the slope of the linear regression of birth years vs generations |
|
126 | + * |
|
127 | + * @return float |
|
128 | + */ |
|
129 | + public function meanGenerationTime(): float |
|
130 | + { |
|
131 | + $row = DB::table('maj_sosa') |
|
132 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
133 | + ->where('majs_user_id', '=', $this->user->id()) |
|
134 | + ->whereNotNull('majs_birth_year') |
|
135 | + ->selectRaw('COUNT(majs_sosa) AS n') |
|
136 | + ->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy') |
|
137 | + ->selectRaw('SUM(majs_gen) AS sum_x') |
|
138 | + ->selectRaw('SUM(majs_birth_year) AS sum_y') |
|
139 | + ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2') |
|
140 | + ->get()->first(); |
|
141 | + |
|
142 | + return $row->n == 0 ? 0 : |
|
143 | + -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2)); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * Get the statistic array detailed by generation. |
|
148 | + * Statistics for each generation are: |
|
149 | + * - The number of Sosa in generation |
|
150 | + * - The number of Sosa up to generation |
|
151 | + * - The number of distinct Sosa up to generation |
|
152 | + * - The year of the first birth in generation |
|
153 | + * - The year of the first estimated birth in generation |
|
154 | + * - The year of the last birth in generation |
|
155 | + * - The year of the last estimated birth in generation |
|
156 | + * - The average year of birth in generation |
|
157 | + * |
|
158 | + * @return array<int, array<string, int|null>> Statistics array |
|
159 | + */ |
|
160 | + public function statisticsByGenerations(): array |
|
161 | + { |
|
162 | + $stats_by_gen = $this->statisticsByGenerationBasicData(); |
|
163 | + $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData(); |
|
164 | + |
|
165 | + $statistics_by_gen = []; |
|
166 | + foreach ($stats_by_gen as $gen => $stats_gen) { |
|
167 | + $statistics_by_gen[(int) $stats_gen->gen] = array( |
|
168 | + 'sosaCount' => (int) $stats_gen->total_sosa, |
|
169 | + 'sosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_cumul, |
|
170 | + 'diffSosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
171 | + 'firstBirth' => $stats_gen->first_year, |
|
172 | + 'firstEstimatedBirth' => $stats_gen->first_est_year, |
|
173 | + 'lastBirth' => $stats_gen->last_year, |
|
174 | + 'lastEstimatedBirth' => $stats_gen->last_est_year |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + return $statistics_by_gen; |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Returns the basic statistics data by generation. |
|
183 | + * |
|
184 | + * @return Collection<int, \stdClass> |
|
185 | + */ |
|
186 | + private function statisticsByGenerationBasicData(): Collection |
|
187 | + { |
|
188 | + return DB::table('maj_sosa') |
|
189 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
190 | + ->where('majs_user_id', '=', $this->user->id()) |
|
191 | + ->groupBy('majs_gen') |
|
192 | + ->orderBy('majs_gen', 'asc') |
|
193 | + ->select('majs_gen AS gen') |
|
194 | + ->selectRaw('COUNT(majs_sosa) AS total_sosa') |
|
195 | + ->selectRaw('MIN(majs_birth_year) AS first_year') |
|
196 | + ->selectRaw('MIN(majs_birth_year_est) AS first_est_year') |
|
197 | + ->selectRaw('MAX(majs_birth_year) AS last_year') |
|
198 | + ->selectRaw('MAX(majs_birth_year_est) AS last_est_year') |
|
199 | + ->get()->keyBy('gen'); |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Returns the cumulative statistics data by generation |
|
204 | + * |
|
205 | + * @return Collection<int, \stdClass> |
|
206 | + */ |
|
207 | + private function statisticsByGenerationCumulativeData(): Collection |
|
208 | + { |
|
209 | + $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
210 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
211 | + ->where('majs_user_id', '=', $this->user->id()); |
|
212 | + |
|
213 | + return DB::table('maj_sosa') |
|
214 | + ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
215 | + $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen') |
|
216 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
217 | + ->where('majs_user_id', '=', $this->user->id()); |
|
218 | + }) |
|
219 | + ->groupBy('list_gen.majs_gen') |
|
220 | + ->select('list_gen.majs_gen AS gen') |
|
221 | + ->selectRaw('COUNT(majs_i_id) AS total_cumul') |
|
222 | + ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul') |
|
223 | + ->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple') |
|
224 | + ->get()->keyBy('gen'); |
|
225 | + } |
|
226 | + |
|
227 | + /** |
|
228 | + * Returns the pedigree collapse improved calculation by generation. |
|
229 | + * |
|
230 | + * Format: |
|
231 | + * - key : generation |
|
232 | + * - values: |
|
233 | + * - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation |
|
234 | + * - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation |
|
235 | + * |
|
236 | + * @return array<int, array<string, float>> |
|
237 | + */ |
|
238 | + public function pedigreeCollapseByGenerationData(): array |
|
239 | + { |
|
240 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
241 | + |
|
242 | + $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
243 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
244 | + ->where('majs_user_id', '=', $this->user->id()); |
|
245 | + |
|
246 | + /* Compute the contributions of nodes of previous generations to the current generation */ |
|
247 | + $root_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
248 | + ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
249 | + ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
250 | + ->selectRaw( |
|
251 | + '(CASE ' . |
|
252 | + ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' . |
|
253 | + ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
254 | + ' ELSE 0 ' . |
|
255 | + ' END)' . |
|
256 | + ' + (CASE ' . |
|
257 | + ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' . |
|
258 | + ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
259 | + ' ELSE 0 ' . |
|
260 | + ' END) contrib' |
|
261 | + ) |
|
262 | + ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
263 | + $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen') |
|
264 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
265 | + ->where('majs_user_id', '=', $this->user->id()); |
|
266 | + }) |
|
267 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
268 | + // Link to sosa's father |
|
269 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
270 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
271 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
272 | + }) |
|
273 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
274 | + // Link to sosa's mother |
|
275 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
276 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
277 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
278 | + }) |
|
279 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
280 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
281 | + ->where(function (Builder $query): void { |
|
282 | + $query->whereNull('sosa_fat.majs_i_id') |
|
283 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
284 | + }); |
|
285 | + |
|
286 | + /* Identify nodes in the generations with ancestors who are also in the same generation. |
|
287 | 287 | * This is the vertical/generational collapse that will reduce the number or roots. |
288 | 288 | */ |
289 | - $non_roots_ancestors = DB::table('maj_sosa AS sosa') |
|
290 | - ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa']) |
|
291 | - ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' . |
|
292 | - ' AS full_ancestors') |
|
293 | - ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void { |
|
294 | - $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen') |
|
295 | - ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' . |
|
296 | - $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' . |
|
297 | - $table_prefix . 'sosa.majs_sosa') |
|
298 | - ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id()) |
|
299 | - ->where('sosa_anc.majs_user_id', '=', $this->user->id()); |
|
300 | - }) |
|
301 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
302 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
303 | - ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void { |
|
304 | - $query->from('maj_sosa AS sosa_gen') |
|
305 | - ->select('sosa_gen.majs_i_id')->distinct() |
|
306 | - ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id()) |
|
307 | - ->where('sosa_gen.majs_user_id', '=', $this->user->id()) |
|
308 | - ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen'); |
|
309 | - }) |
|
310 | - ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', |
|
311 | - 'sosa.majs_sosa', 'sosa.majs_i_id']); |
|
312 | - |
|
313 | - /* Compute the contribution of the nodes in the generation, |
|
289 | + $non_roots_ancestors = DB::table('maj_sosa AS sosa') |
|
290 | + ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa']) |
|
291 | + ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' . |
|
292 | + ' AS full_ancestors') |
|
293 | + ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void { |
|
294 | + $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen') |
|
295 | + ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' . |
|
296 | + $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' . |
|
297 | + $table_prefix . 'sosa.majs_sosa') |
|
298 | + ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id()) |
|
299 | + ->where('sosa_anc.majs_user_id', '=', $this->user->id()); |
|
300 | + }) |
|
301 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
302 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
303 | + ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void { |
|
304 | + $query->from('maj_sosa AS sosa_gen') |
|
305 | + ->select('sosa_gen.majs_i_id')->distinct() |
|
306 | + ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id()) |
|
307 | + ->where('sosa_gen.majs_user_id', '=', $this->user->id()) |
|
308 | + ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen'); |
|
309 | + }) |
|
310 | + ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', |
|
311 | + 'sosa.majs_sosa', 'sosa.majs_i_id']); |
|
312 | + |
|
313 | + /* Compute the contribution of the nodes in the generation, |
|
314 | 314 | * excluding the nodes with ancestors in the same generation. |
315 | 315 | * Nodes with a parent missing are not excluded to cater for the missing one. |
316 | 316 | */ |
317 | - $known_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
318 | - ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
319 | - ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
320 | - ->selectRaw('1 AS contrib') |
|
321 | - ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void { |
|
322 | - $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen') |
|
323 | - ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa') |
|
324 | - ->where('nonroot.full_ancestors', '>', 0) |
|
325 | - ->where('nonroot.majs_gedcom_id', '=', $this->tree->id()) |
|
326 | - ->where('nonroot.majs_user_id', '=', $this->user->id()); |
|
327 | - }) |
|
328 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
329 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
330 | - ->whereNull('nonroot.majs_sosa'); |
|
331 | - |
|
332 | - /* Aggregate both queries, and calculate the sum of contributions by generation roots. |
|
317 | + $known_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
318 | + ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
319 | + ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
320 | + ->selectRaw('1 AS contrib') |
|
321 | + ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void { |
|
322 | + $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen') |
|
323 | + ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa') |
|
324 | + ->where('nonroot.full_ancestors', '>', 0) |
|
325 | + ->where('nonroot.majs_gedcom_id', '=', $this->tree->id()) |
|
326 | + ->where('nonroot.majs_user_id', '=', $this->user->id()); |
|
327 | + }) |
|
328 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
329 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
330 | + ->whereNull('nonroot.majs_sosa'); |
|
331 | + |
|
332 | + /* Aggregate both queries, and calculate the sum of contributions by generation roots. |
|
333 | 333 | * Exclude as well nodes that already appear in lower generations, as their branche has already been reduced. |
334 | 334 | */ |
335 | - $ancestors_contributions_sum = DB::connection()->query() |
|
336 | - ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs') |
|
337 | - ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id']) |
|
338 | - ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib']) |
|
339 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' . |
|
340 | - $table_prefix . 'sosa_contribs.contrib AS totalContrib') |
|
341 | - ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void { |
|
342 | - $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen') |
|
343 | - ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id') |
|
344 | - ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id()) |
|
345 | - ->where('sosa_low.majs_user_id', '=', $this->user->id()); |
|
346 | - }) |
|
347 | - ->whereNull('sosa_low.majs_sosa') |
|
348 | - ->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id', |
|
349 | - 'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']); |
|
350 | - |
|
351 | - // Aggregate all generation roots to compute root and generation pedigree collapse |
|
352 | - $pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum') |
|
353 | - ->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)') |
|
354 | - ->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots') // Roots/horizontal collapse |
|
355 | - ->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse |
|
356 | - ->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id']) |
|
357 | - ->orderBy('gen') |
|
358 | - ->get(); |
|
359 | - |
|
360 | - $pedi_collapse_by_gen = []; |
|
361 | - foreach ($pedi_collapse_coll as $collapse_gen) { |
|
362 | - $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array( |
|
363 | - 'pedi_collapse_roots' => (float) $collapse_gen->pedi_collapse_roots, |
|
364 | - 'pedi_collapse_xgen' => (float) $collapse_gen->pedi_collapse_xgen |
|
365 | - ); |
|
366 | - } |
|
367 | - return $pedi_collapse_by_gen; |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation. |
|
372 | - * Sosa 1 is of generation 1. |
|
373 | - * |
|
374 | - * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes, |
|
375 | - * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140 |
|
376 | - * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0 |
|
377 | - * |
|
378 | - * Format: |
|
379 | - * - key : sosa number of the ancestor |
|
380 | - * - values: |
|
381 | - * - root_ancestor_id : ID of the ancestor |
|
382 | - * - mean_gen_depth : Mean generation depth |
|
383 | - * - stddev_gen_depth : Standard deviation of generation depth |
|
384 | - * |
|
385 | - * @param int $gen Sosa generation |
|
386 | - * @return Collection<int, \stdClass> |
|
387 | - */ |
|
388 | - public function generationDepthStatsAtGeneration(int $gen): Collection |
|
389 | - { |
|
390 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
391 | - $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa') |
|
392 | - ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
393 | - ->selectRaw('FLOOR(((' . $table_prefix . 'sosa.majs_sosa / POW(2, ' . $table_prefix . 'sosa.majs_gen -1 )) - 1) * POWER(2, ? - 1)) + POWER(2, ? - 1) AS root_ancestor', [$gen, $gen]) //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
394 | - ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 1 ELSE 0 END) AS full_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
395 | - ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 0 ELSE 1 END) As semi_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
396 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
397 | - // Link to sosa's father |
|
398 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
399 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
400 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
401 | - }) |
|
402 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
403 | - // Link to sosa's mother |
|
404 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
405 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
406 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
407 | - }) |
|
408 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
409 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
410 | - ->where('sosa.majs_gen', '>=', $gen) |
|
411 | - ->where(function (Builder $query): void { |
|
412 | - $query->whereNull('sosa_fat.majs_i_id') |
|
413 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
414 | - }) |
|
415 | - ->groupBy(['sosa.majs_gen', 'root_ancestor']); |
|
416 | - |
|
417 | - return DB::table('maj_sosa AS sosa_list') |
|
418 | - ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id']) |
|
419 | - ->selectRaw('1 + SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))) AS mean_gen_depth') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
420 | - ->selectRaw(' SQRT(' . |
|
421 | - ' SUM(POWER(majs_gen_norm, 2) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm)))' . //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
422 | - ' - POWER( SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))), 2)' . //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
423 | - ' ) AS stddev_gen_depth') |
|
424 | - ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void { |
|
425 | - $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor') |
|
426 | - ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id()) |
|
427 | - ->where('sosa_list.majs_user_id', '=', $this->user->id()); |
|
428 | - }) |
|
429 | - ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id']) |
|
430 | - ->orderBy('stats_by_gen.root_ancestor') |
|
431 | - ->get()->keyBy('root_ancestor_sosa'); |
|
432 | - } |
|
433 | - |
|
434 | - /** |
|
435 | - * Return a collection of the most duplicated root Sosa ancestors. |
|
436 | - * The number of ancestors to return is limited by the parameter $limit. |
|
437 | - * If several individuals are tied when reaching the limit, none of them are returned, |
|
438 | - * which means that there can be less individuals returned than requested. |
|
439 | - * |
|
440 | - * Format: |
|
441 | - * - value: |
|
442 | - * - sosa_i_id : sosa individual |
|
443 | - * - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
444 | - * |
|
445 | - * @param int $limit |
|
446 | - * @return Collection<\stdClass> |
|
447 | - */ |
|
448 | - public function topMultipleAncestorsWithNoTies(int $limit): Collection |
|
449 | - { |
|
450 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
451 | - $multiple_ancestors = DB::table('maj_sosa AS sosa') |
|
452 | - ->select('sosa.majs_i_id AS sosa_i_id') |
|
453 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count') |
|
454 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
455 | - // Link to sosa's father |
|
456 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
457 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
458 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
459 | - }) |
|
460 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
461 | - // Link to sosa's mother |
|
462 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
463 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
464 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
465 | - }) |
|
466 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
467 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
468 | - ->whereNull('sosa_fat.majs_sosa') // We keep only root individuals, i.e. those with no father or mother |
|
469 | - ->whereNull('sosa_mot.majs_sosa') |
|
470 | - ->groupBy('sosa.majs_i_id') |
|
471 | - ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
472 | - ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
473 | - ->limit($limit + 1) // We want to select one more than required, for ties |
|
474 | - ->get(); |
|
475 | - |
|
476 | - if ($multiple_ancestors->count() > $limit) { |
|
477 | - $last_count = $multiple_ancestors->last()->sosa_count; |
|
478 | - $multiple_ancestors = $multiple_ancestors->reject( |
|
479 | - fn (stdClass $element): bool => $element->sosa_count === $last_count |
|
480 | - ); |
|
481 | - } |
|
482 | - return $multiple_ancestors; |
|
483 | - } |
|
484 | - |
|
485 | - /** |
|
486 | - * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
487 | - * at a specified generation. |
|
488 | - * |
|
489 | - * Format: |
|
490 | - * - key : rank of the ancestor in generation G for which exclusive ancestors have been found |
|
491 | - * For instance 3 represent the maternal grand father |
|
492 | - * 0 is used for shared ancestors |
|
493 | - * - values: |
|
494 | - * - branches: same as key |
|
495 | - * - majs_i_id: xref of the ancestor at rank key in generation G, or null for shared ancestors |
|
496 | - * - count_indi: number of ancestors exclusively in the ancestors of the ancestor at rank key |
|
497 | - * |
|
498 | - * For instance a result at generation 3 could be : |
|
499 | - * [ |
|
500 | - * 0 => { branches: 0, majs_i_id: X1, count_indi: 12 } -> 12 ancestors are shared by the grand-parents |
|
501 | - * 1 => { branches: 1, majs_i_id: X2, count_indi: 32 } -> 32 ancestors are exclusive to the paternal grand-father |
|
502 | - * 2 => { branches: 2, majs_i_id: X3, count_indi: 25 } -> 25 ancestors are exclusive to the paternal grand-mother |
|
503 | - * 3 => { branches: 3, majs_i_id: X4, count_indi: 12 } -> 12 ancestors are exclusive to the maternal grand-father |
|
504 | - * 4 => { branches: 4, majs_i_id: X5, count_indi: 30 } -> 30 ancestors are exclusive to the maternal grand-mother |
|
505 | - * ] |
|
506 | - * |
|
507 | - * @param int $gen |
|
508 | - * @return Collection<int, \stdClass> |
|
509 | - */ |
|
510 | - public function ancestorsDispersionForGeneration(int $gen): Collection |
|
511 | - { |
|
512 | - $ancestors_branches = DB::table('maj_sosa') |
|
513 | - ->select('majs_i_id AS i_id') |
|
514 | - ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen]) |
|
515 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
516 | - ->where('majs_user_id', '=', $this->user->id()) |
|
517 | - ->where('majs_gen', '>=', $gen) |
|
518 | - ->groupBy('majs_i_id', 'branch'); |
|
519 | - |
|
520 | - $consolidated_ancestors_branches = DB::table('maj_sosa') |
|
521 | - ->fromSub($ancestors_branches, 'indi_branch') |
|
522 | - ->select('i_id') |
|
523 | - ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches') |
|
524 | - ->groupBy('i_id'); |
|
525 | - |
|
526 | - return DB::table('maj_sosa') |
|
527 | - ->rightJoinSub( |
|
528 | - $consolidated_ancestors_branches, |
|
529 | - 'indi_branch_consolidated', |
|
530 | - function (JoinClause $join) use ($gen): void { |
|
531 | - $join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
532 | - ->where('maj_sosa.majs_user_id', '=', $this->user->id()) |
|
533 | - ->where('branches', '>', 0) |
|
534 | - ->whereRaw('majs_sosa = POW(2, ? - 1) + branches - 1', [$gen]); |
|
535 | - } |
|
536 | - ) |
|
537 | - ->select(['branches', 'majs_i_id']) |
|
538 | - ->selectRaw('COUNT(i_id) AS count_indi') |
|
539 | - ->groupBy(['branches', 'majs_i_id']) |
|
540 | - ->get()->keyBy('branches'); |
|
541 | - } |
|
335 | + $ancestors_contributions_sum = DB::connection()->query() |
|
336 | + ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs') |
|
337 | + ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id']) |
|
338 | + ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib']) |
|
339 | + ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' . |
|
340 | + $table_prefix . 'sosa_contribs.contrib AS totalContrib') |
|
341 | + ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void { |
|
342 | + $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen') |
|
343 | + ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id') |
|
344 | + ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id()) |
|
345 | + ->where('sosa_low.majs_user_id', '=', $this->user->id()); |
|
346 | + }) |
|
347 | + ->whereNull('sosa_low.majs_sosa') |
|
348 | + ->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id', |
|
349 | + 'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']); |
|
350 | + |
|
351 | + // Aggregate all generation roots to compute root and generation pedigree collapse |
|
352 | + $pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum') |
|
353 | + ->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)') |
|
354 | + ->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots') // Roots/horizontal collapse |
|
355 | + ->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse |
|
356 | + ->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id']) |
|
357 | + ->orderBy('gen') |
|
358 | + ->get(); |
|
359 | + |
|
360 | + $pedi_collapse_by_gen = []; |
|
361 | + foreach ($pedi_collapse_coll as $collapse_gen) { |
|
362 | + $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array( |
|
363 | + 'pedi_collapse_roots' => (float) $collapse_gen->pedi_collapse_roots, |
|
364 | + 'pedi_collapse_xgen' => (float) $collapse_gen->pedi_collapse_xgen |
|
365 | + ); |
|
366 | + } |
|
367 | + return $pedi_collapse_by_gen; |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation. |
|
372 | + * Sosa 1 is of generation 1. |
|
373 | + * |
|
374 | + * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes, |
|
375 | + * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140 |
|
376 | + * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0 |
|
377 | + * |
|
378 | + * Format: |
|
379 | + * - key : sosa number of the ancestor |
|
380 | + * - values: |
|
381 | + * - root_ancestor_id : ID of the ancestor |
|
382 | + * - mean_gen_depth : Mean generation depth |
|
383 | + * - stddev_gen_depth : Standard deviation of generation depth |
|
384 | + * |
|
385 | + * @param int $gen Sosa generation |
|
386 | + * @return Collection<int, \stdClass> |
|
387 | + */ |
|
388 | + public function generationDepthStatsAtGeneration(int $gen): Collection |
|
389 | + { |
|
390 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
391 | + $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa') |
|
392 | + ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
393 | + ->selectRaw('FLOOR(((' . $table_prefix . 'sosa.majs_sosa / POW(2, ' . $table_prefix . 'sosa.majs_gen -1 )) - 1) * POWER(2, ? - 1)) + POWER(2, ? - 1) AS root_ancestor', [$gen, $gen]) //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
394 | + ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 1 ELSE 0 END) AS full_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
395 | + ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 0 ELSE 1 END) As semi_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
396 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
397 | + // Link to sosa's father |
|
398 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
399 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
400 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
401 | + }) |
|
402 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
403 | + // Link to sosa's mother |
|
404 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
405 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
406 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
407 | + }) |
|
408 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
409 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
410 | + ->where('sosa.majs_gen', '>=', $gen) |
|
411 | + ->where(function (Builder $query): void { |
|
412 | + $query->whereNull('sosa_fat.majs_i_id') |
|
413 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
414 | + }) |
|
415 | + ->groupBy(['sosa.majs_gen', 'root_ancestor']); |
|
416 | + |
|
417 | + return DB::table('maj_sosa AS sosa_list') |
|
418 | + ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id']) |
|
419 | + ->selectRaw('1 + SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))) AS mean_gen_depth') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
420 | + ->selectRaw(' SQRT(' . |
|
421 | + ' SUM(POWER(majs_gen_norm, 2) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm)))' . //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
422 | + ' - POWER( SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))), 2)' . //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
423 | + ' ) AS stddev_gen_depth') |
|
424 | + ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void { |
|
425 | + $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor') |
|
426 | + ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id()) |
|
427 | + ->where('sosa_list.majs_user_id', '=', $this->user->id()); |
|
428 | + }) |
|
429 | + ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id']) |
|
430 | + ->orderBy('stats_by_gen.root_ancestor') |
|
431 | + ->get()->keyBy('root_ancestor_sosa'); |
|
432 | + } |
|
433 | + |
|
434 | + /** |
|
435 | + * Return a collection of the most duplicated root Sosa ancestors. |
|
436 | + * The number of ancestors to return is limited by the parameter $limit. |
|
437 | + * If several individuals are tied when reaching the limit, none of them are returned, |
|
438 | + * which means that there can be less individuals returned than requested. |
|
439 | + * |
|
440 | + * Format: |
|
441 | + * - value: |
|
442 | + * - sosa_i_id : sosa individual |
|
443 | + * - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
444 | + * |
|
445 | + * @param int $limit |
|
446 | + * @return Collection<\stdClass> |
|
447 | + */ |
|
448 | + public function topMultipleAncestorsWithNoTies(int $limit): Collection |
|
449 | + { |
|
450 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
451 | + $multiple_ancestors = DB::table('maj_sosa AS sosa') |
|
452 | + ->select('sosa.majs_i_id AS sosa_i_id') |
|
453 | + ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count') |
|
454 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
455 | + // Link to sosa's father |
|
456 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
457 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
458 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
459 | + }) |
|
460 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
461 | + // Link to sosa's mother |
|
462 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
463 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
464 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
465 | + }) |
|
466 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
467 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
468 | + ->whereNull('sosa_fat.majs_sosa') // We keep only root individuals, i.e. those with no father or mother |
|
469 | + ->whereNull('sosa_mot.majs_sosa') |
|
470 | + ->groupBy('sosa.majs_i_id') |
|
471 | + ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
472 | + ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
473 | + ->limit($limit + 1) // We want to select one more than required, for ties |
|
474 | + ->get(); |
|
475 | + |
|
476 | + if ($multiple_ancestors->count() > $limit) { |
|
477 | + $last_count = $multiple_ancestors->last()->sosa_count; |
|
478 | + $multiple_ancestors = $multiple_ancestors->reject( |
|
479 | + fn (stdClass $element): bool => $element->sosa_count === $last_count |
|
480 | + ); |
|
481 | + } |
|
482 | + return $multiple_ancestors; |
|
483 | + } |
|
484 | + |
|
485 | + /** |
|
486 | + * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
487 | + * at a specified generation. |
|
488 | + * |
|
489 | + * Format: |
|
490 | + * - key : rank of the ancestor in generation G for which exclusive ancestors have been found |
|
491 | + * For instance 3 represent the maternal grand father |
|
492 | + * 0 is used for shared ancestors |
|
493 | + * - values: |
|
494 | + * - branches: same as key |
|
495 | + * - majs_i_id: xref of the ancestor at rank key in generation G, or null for shared ancestors |
|
496 | + * - count_indi: number of ancestors exclusively in the ancestors of the ancestor at rank key |
|
497 | + * |
|
498 | + * For instance a result at generation 3 could be : |
|
499 | + * [ |
|
500 | + * 0 => { branches: 0, majs_i_id: X1, count_indi: 12 } -> 12 ancestors are shared by the grand-parents |
|
501 | + * 1 => { branches: 1, majs_i_id: X2, count_indi: 32 } -> 32 ancestors are exclusive to the paternal grand-father |
|
502 | + * 2 => { branches: 2, majs_i_id: X3, count_indi: 25 } -> 25 ancestors are exclusive to the paternal grand-mother |
|
503 | + * 3 => { branches: 3, majs_i_id: X4, count_indi: 12 } -> 12 ancestors are exclusive to the maternal grand-father |
|
504 | + * 4 => { branches: 4, majs_i_id: X5, count_indi: 30 } -> 30 ancestors are exclusive to the maternal grand-mother |
|
505 | + * ] |
|
506 | + * |
|
507 | + * @param int $gen |
|
508 | + * @return Collection<int, \stdClass> |
|
509 | + */ |
|
510 | + public function ancestorsDispersionForGeneration(int $gen): Collection |
|
511 | + { |
|
512 | + $ancestors_branches = DB::table('maj_sosa') |
|
513 | + ->select('majs_i_id AS i_id') |
|
514 | + ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen]) |
|
515 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
516 | + ->where('majs_user_id', '=', $this->user->id()) |
|
517 | + ->where('majs_gen', '>=', $gen) |
|
518 | + ->groupBy('majs_i_id', 'branch'); |
|
519 | + |
|
520 | + $consolidated_ancestors_branches = DB::table('maj_sosa') |
|
521 | + ->fromSub($ancestors_branches, 'indi_branch') |
|
522 | + ->select('i_id') |
|
523 | + ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches') |
|
524 | + ->groupBy('i_id'); |
|
525 | + |
|
526 | + return DB::table('maj_sosa') |
|
527 | + ->rightJoinSub( |
|
528 | + $consolidated_ancestors_branches, |
|
529 | + 'indi_branch_consolidated', |
|
530 | + function (JoinClause $join) use ($gen): void { |
|
531 | + $join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
532 | + ->where('maj_sosa.majs_user_id', '=', $this->user->id()) |
|
533 | + ->where('branches', '>', 0) |
|
534 | + ->whereRaw('majs_sosa = POW(2, ? - 1) + branches - 1', [$gen]); |
|
535 | + } |
|
536 | + ) |
|
537 | + ->select(['branches', 'majs_i_id']) |
|
538 | + ->selectRaw('COUNT(i_id) AS count_indi') |
|
539 | + ->groupBy(['branches', 'majs_i_id']) |
|
540 | + ->get()->keyBy('branches'); |
|
541 | + } |
|
542 | 542 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | */ |
63 | 63 | public function maxGeneration(): int |
64 | 64 | { |
65 | - return (int) DB::table('maj_sosa') |
|
65 | + return (int)DB::table('maj_sosa') |
|
66 | 66 | ->where('majs_gedcom_id', '=', $this->tree->id()) |
67 | 67 | ->where('majs_user_id', '=', $this->user->id()) |
68 | 68 | ->max('majs_gen'); |
@@ -139,8 +139,7 @@ discard block |
||
139 | 139 | ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2') |
140 | 140 | ->get()->first(); |
141 | 141 | |
142 | - return $row->n == 0 ? 0 : |
|
143 | - -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2)); |
|
142 | + return $row->n == 0 ? 0 : -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2)); |
|
144 | 143 | } |
145 | 144 | |
146 | 145 | /** |
@@ -164,10 +163,10 @@ discard block |
||
164 | 163 | |
165 | 164 | $statistics_by_gen = []; |
166 | 165 | foreach ($stats_by_gen as $gen => $stats_gen) { |
167 | - $statistics_by_gen[(int) $stats_gen->gen] = array( |
|
168 | - 'sosaCount' => (int) $stats_gen->total_sosa, |
|
169 | - 'sosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_cumul, |
|
170 | - 'diffSosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
166 | + $statistics_by_gen[(int)$stats_gen->gen] = array( |
|
167 | + 'sosaCount' => (int)$stats_gen->total_sosa, |
|
168 | + 'sosaTotalCount' => (int)$cumul_stats_by_gen[$gen]->total_cumul, |
|
169 | + 'diffSosaTotalCount' => (int)$cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
171 | 170 | 'firstBirth' => $stats_gen->first_year, |
172 | 171 | 'firstEstimatedBirth' => $stats_gen->first_est_year, |
173 | 172 | 'lastBirth' => $stats_gen->last_year, |
@@ -211,7 +210,7 @@ discard block |
||
211 | 210 | ->where('majs_user_id', '=', $this->user->id()); |
212 | 211 | |
213 | 212 | return DB::table('maj_sosa') |
214 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
213 | + ->joinSub($list_gen, 'list_gen', function(JoinClause $join): void { |
|
215 | 214 | $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen') |
216 | 215 | ->where('majs_gedcom_id', '=', $this->tree->id()) |
217 | 216 | ->where('majs_user_id', '=', $this->user->id()); |
@@ -248,37 +247,37 @@ discard block |
||
248 | 247 | ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
249 | 248 | ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
250 | 249 | ->selectRaw( |
251 | - '(CASE ' . |
|
252 | - ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' . |
|
253 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
254 | - ' ELSE 0 ' . |
|
255 | - ' END)' . |
|
256 | - ' + (CASE ' . |
|
257 | - ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' . |
|
258 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
259 | - ' ELSE 0 ' . |
|
250 | + '(CASE '. |
|
251 | + ' WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL'. |
|
252 | + ' THEN POWER(2, '.$table_prefix.'list_gen.majs_gen - '.$table_prefix.'sosa.majs_gen - 1)'. |
|
253 | + ' ELSE 0 '. |
|
254 | + ' END)'. |
|
255 | + ' + (CASE '. |
|
256 | + ' WHEN '.$table_prefix.'sosa_mot.majs_i_id IS NULL'. |
|
257 | + ' THEN POWER(2, '.$table_prefix.'list_gen.majs_gen - '.$table_prefix.'sosa.majs_gen - 1)'. |
|
258 | + ' ELSE 0 '. |
|
260 | 259 | ' END) contrib' |
261 | 260 | ) |
262 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
261 | + ->joinSub($list_gen, 'list_gen', function(JoinClause $join): void { |
|
263 | 262 | $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen') |
264 | 263 | ->where('majs_gedcom_id', '=', $this->tree->id()) |
265 | 264 | ->where('majs_user_id', '=', $this->user->id()); |
266 | 265 | }) |
267 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
266 | + ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void { |
|
268 | 267 | // Link to sosa's father |
269 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
268 | + $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa') |
|
270 | 269 | ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
271 | 270 | ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
272 | 271 | }) |
273 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
272 | + ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void { |
|
274 | 273 | // Link to sosa's mother |
275 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
274 | + $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1') |
|
276 | 275 | ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
277 | 276 | ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
278 | 277 | }) |
279 | 278 | ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
280 | 279 | ->where('sosa.majs_user_id', '=', $this->user->id()) |
281 | - ->where(function (Builder $query): void { |
|
280 | + ->where(function(Builder $query): void { |
|
282 | 281 | $query->whereNull('sosa_fat.majs_i_id') |
283 | 282 | ->orWhereNull('sosa_mot.majs_i_id'); |
284 | 283 | }); |
@@ -288,24 +287,24 @@ discard block |
||
288 | 287 | */ |
289 | 288 | $non_roots_ancestors = DB::table('maj_sosa AS sosa') |
290 | 289 | ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa']) |
291 | - ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' . |
|
290 | + ->selectRaw('MAX('.$table_prefix.'sosa_anc.majs_sosa) - MIN('.$table_prefix.'sosa_anc.majs_sosa)'. |
|
292 | 291 | ' AS full_ancestors') |
293 | - ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void { |
|
292 | + ->join('maj_sosa AS sosa_anc', function(JoinClause $join) use ($table_prefix): void { |
|
294 | 293 | $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen') |
295 | - ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' . |
|
296 | - $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' . |
|
297 | - $table_prefix . 'sosa.majs_sosa') |
|
294 | + ->whereRaw('FLOOR('.$table_prefix.'sosa_anc.majs_sosa / POWER(2, '. |
|
295 | + $table_prefix.'sosa_anc.majs_gen - '.$table_prefix.'sosa.majs_gen)) = '. |
|
296 | + $table_prefix.'sosa.majs_sosa') |
|
298 | 297 | ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id()) |
299 | 298 | ->where('sosa_anc.majs_user_id', '=', $this->user->id()); |
300 | 299 | }) |
301 | 300 | ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
302 | 301 | ->where('sosa.majs_user_id', '=', $this->user->id()) |
303 | - ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void { |
|
302 | + ->whereIn('sosa_anc.majs_i_id', function(Builder $query) use ($table_prefix): void { |
|
304 | 303 | $query->from('maj_sosa AS sosa_gen') |
305 | 304 | ->select('sosa_gen.majs_i_id')->distinct() |
306 | 305 | ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id()) |
307 | 306 | ->where('sosa_gen.majs_user_id', '=', $this->user->id()) |
308 | - ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen'); |
|
307 | + ->whereRaw($table_prefix.'sosa_gen.majs_gen = '.$table_prefix.'sosa.majs_gen'); |
|
309 | 308 | }) |
310 | 309 | ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', |
311 | 310 | 'sosa.majs_sosa', 'sosa.majs_i_id']); |
@@ -318,7 +317,7 @@ discard block |
||
318 | 317 | ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
319 | 318 | ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
320 | 319 | ->selectRaw('1 AS contrib') |
321 | - ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void { |
|
320 | + ->leftJoinSub($non_roots_ancestors, 'nonroot', function(JoinClause $join): void { |
|
322 | 321 | $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen') |
323 | 322 | ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa') |
324 | 323 | ->where('nonroot.full_ancestors', '>', 0) |
@@ -336,9 +335,9 @@ discard block |
||
336 | 335 | ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs') |
337 | 336 | ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id']) |
338 | 337 | ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib']) |
339 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' . |
|
340 | - $table_prefix . 'sosa_contribs.contrib AS totalContrib') |
|
341 | - ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void { |
|
338 | + ->selectRaw('COUNT('.$table_prefix.'sosa_contribs.majs_i_id) * '. |
|
339 | + $table_prefix.'sosa_contribs.contrib AS totalContrib') |
|
340 | + ->leftJoin('maj_sosa AS sosa_low', function(JoinClause $join): void { |
|
342 | 341 | $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen') |
343 | 342 | ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id') |
344 | 343 | ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id()) |
@@ -359,9 +358,9 @@ discard block |
||
359 | 358 | |
360 | 359 | $pedi_collapse_by_gen = []; |
361 | 360 | foreach ($pedi_collapse_coll as $collapse_gen) { |
362 | - $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array( |
|
363 | - 'pedi_collapse_roots' => (float) $collapse_gen->pedi_collapse_roots, |
|
364 | - 'pedi_collapse_xgen' => (float) $collapse_gen->pedi_collapse_xgen |
|
361 | + $pedi_collapse_by_gen[(int)$collapse_gen->gen] = array( |
|
362 | + 'pedi_collapse_roots' => (float)$collapse_gen->pedi_collapse_roots, |
|
363 | + 'pedi_collapse_xgen' => (float)$collapse_gen->pedi_collapse_xgen |
|
365 | 364 | ); |
366 | 365 | } |
367 | 366 | return $pedi_collapse_by_gen; |
@@ -389,26 +388,26 @@ discard block |
||
389 | 388 | { |
390 | 389 | $table_prefix = DB::connection()->getTablePrefix(); |
391 | 390 | $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa') |
392 | - ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
393 | - ->selectRaw('FLOOR(((' . $table_prefix . 'sosa.majs_sosa / POW(2, ' . $table_prefix . 'sosa.majs_gen -1 )) - 1) * POWER(2, ? - 1)) + POWER(2, ? - 1) AS root_ancestor', [$gen, $gen]) //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
394 | - ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 1 ELSE 0 END) AS full_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
395 | - ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 0 ELSE 1 END) As semi_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
396 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
391 | + ->selectRaw($table_prefix.'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
392 | + ->selectRaw('FLOOR((('.$table_prefix.'sosa.majs_sosa / POW(2, '.$table_prefix.'sosa.majs_gen -1 )) - 1) * POWER(2, ? - 1)) + POWER(2, ? - 1) AS root_ancestor', [$gen, $gen]) //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
393 | + ->selectRaw('SUM(CASE WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL AND '.$table_prefix.'sosa_mot.majs_i_id IS NULL THEN 1 ELSE 0 END) AS full_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
394 | + ->selectRaw('SUM(CASE WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL AND '.$table_prefix.'sosa_mot.majs_i_id IS NULL THEN 0 ELSE 1 END) As semi_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
395 | + ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void { |
|
397 | 396 | // Link to sosa's father |
398 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
397 | + $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa') |
|
399 | 398 | ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
400 | 399 | ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
401 | 400 | }) |
402 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
401 | + ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void { |
|
403 | 402 | // Link to sosa's mother |
404 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
403 | + $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1') |
|
405 | 404 | ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
406 | 405 | ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
407 | 406 | }) |
408 | 407 | ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
409 | 408 | ->where('sosa.majs_user_id', '=', $this->user->id()) |
410 | 409 | ->where('sosa.majs_gen', '>=', $gen) |
411 | - ->where(function (Builder $query): void { |
|
410 | + ->where(function(Builder $query): void { |
|
412 | 411 | $query->whereNull('sosa_fat.majs_i_id') |
413 | 412 | ->orWhereNull('sosa_mot.majs_i_id'); |
414 | 413 | }) |
@@ -417,11 +416,11 @@ discard block |
||
417 | 416 | return DB::table('maj_sosa AS sosa_list') |
418 | 417 | ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id']) |
419 | 418 | ->selectRaw('1 + SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))) AS mean_gen_depth') //@phpcs:ignore Generic.Files.LineLength.TooLong |
420 | - ->selectRaw(' SQRT(' . |
|
421 | - ' SUM(POWER(majs_gen_norm, 2) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm)))' . //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
422 | - ' - POWER( SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))), 2)' . //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
419 | + ->selectRaw(' SQRT('. |
|
420 | + ' SUM(POWER(majs_gen_norm, 2) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm)))'.//@phpcs:ignore Generic.Files.LineLength.TooLong |
|
421 | + ' - POWER( SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))), 2)'.//@phpcs:ignore Generic.Files.LineLength.TooLong |
|
423 | 422 | ' ) AS stddev_gen_depth') |
424 | - ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void { |
|
423 | + ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function(JoinClause $join): void { |
|
425 | 424 | $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor') |
426 | 425 | ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id()) |
427 | 426 | ->where('sosa_list.majs_user_id', '=', $this->user->id()); |
@@ -450,16 +449,16 @@ discard block |
||
450 | 449 | $table_prefix = DB::connection()->getTablePrefix(); |
451 | 450 | $multiple_ancestors = DB::table('maj_sosa AS sosa') |
452 | 451 | ->select('sosa.majs_i_id AS sosa_i_id') |
453 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count') |
|
454 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
452 | + ->selectRaw('COUNT('.$table_prefix.'sosa.majs_sosa) AS sosa_count') |
|
453 | + ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void { |
|
455 | 454 | // Link to sosa's father |
456 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
455 | + $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa') |
|
457 | 456 | ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
458 | 457 | ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
459 | 458 | }) |
460 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
459 | + ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void { |
|
461 | 460 | // Link to sosa's mother |
462 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
461 | + $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1') |
|
463 | 462 | ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
464 | 463 | ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
465 | 464 | }) |
@@ -468,15 +467,15 @@ discard block |
||
468 | 467 | ->whereNull('sosa_fat.majs_sosa') // We keep only root individuals, i.e. those with no father or mother |
469 | 468 | ->whereNull('sosa_mot.majs_sosa') |
470 | 469 | ->groupBy('sosa.majs_i_id') |
471 | - ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
472 | - ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
470 | + ->havingRaw('COUNT('.$table_prefix.'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
471 | + ->orderByRaw('COUNT('.$table_prefix.'sosa.majs_sosa) DESC, MIN('.$table_prefix.'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
473 | 472 | ->limit($limit + 1) // We want to select one more than required, for ties |
474 | 473 | ->get(); |
475 | 474 | |
476 | 475 | if ($multiple_ancestors->count() > $limit) { |
477 | 476 | $last_count = $multiple_ancestors->last()->sosa_count; |
478 | 477 | $multiple_ancestors = $multiple_ancestors->reject( |
479 | - fn (stdClass $element): bool => $element->sosa_count === $last_count |
|
478 | + fn(stdClass $element): bool => $element->sosa_count === $last_count |
|
480 | 479 | ); |
481 | 480 | } |
482 | 481 | return $multiple_ancestors; |
@@ -527,7 +526,7 @@ discard block |
||
527 | 526 | ->rightJoinSub( |
528 | 527 | $consolidated_ancestors_branches, |
529 | 528 | 'indi_branch_consolidated', |
530 | - function (JoinClause $join) use ($gen): void { |
|
529 | + function(JoinClause $join) use ($gen): void { |
|
531 | 530 | $join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id()) |
532 | 531 | ->where('maj_sosa.majs_user_id', '=', $this->user->id()) |
533 | 532 | ->where('branches', '>', 0) |