@@ -32,89 +32,89 @@ |
||
| 32 | 32 | * Provide miscellaneous improvements to webtrees. |
| 33 | 33 | */ |
| 34 | 34 | class MiscExtensionsModule extends AbstractModule implements |
| 35 | - ModuleMyArtJaubInterface, |
|
| 36 | - ModuleConfigInterface, |
|
| 37 | - ModuleHookSubscriberInterface |
|
| 35 | + ModuleMyArtJaubInterface, |
|
| 36 | + ModuleConfigInterface, |
|
| 37 | + ModuleHookSubscriberInterface |
|
| 38 | 38 | { |
| 39 | - use ModuleMyArtJaubTrait { |
|
| 40 | - boot as traitBoot; |
|
| 41 | - } |
|
| 42 | - use ModuleConfigTrait; |
|
| 39 | + use ModuleMyArtJaubTrait { |
|
| 40 | + boot as traitBoot; |
|
| 41 | + } |
|
| 42 | + use ModuleConfigTrait; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * {@inheritDoc} |
|
| 46 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 47 | - */ |
|
| 48 | - public function title(): string |
|
| 49 | - { |
|
| 50 | - return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions'); |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * {@inheritDoc} |
|
| 46 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 47 | + */ |
|
| 48 | + public function title(): string |
|
| 49 | + { |
|
| 50 | + return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions'); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 56 | - */ |
|
| 57 | - public function description(): string |
|
| 58 | - { |
|
| 59 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 60 | - return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.'); |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 56 | + */ |
|
| 57 | + public function description(): string |
|
| 58 | + { |
|
| 59 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 60 | + return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.'); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * {@inheritDoc} |
|
| 65 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 66 | - */ |
|
| 67 | - public function boot(): void |
|
| 68 | - { |
|
| 69 | - $this->traitBoot(); |
|
| 70 | - View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy'); |
|
| 71 | - } |
|
| 63 | + /** |
|
| 64 | + * {@inheritDoc} |
|
| 65 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 66 | + */ |
|
| 67 | + public function boot(): void |
|
| 68 | + { |
|
| 69 | + $this->traitBoot(); |
|
| 70 | + View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy'); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * {@inheritDoc} |
|
| 75 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 76 | - */ |
|
| 77 | - public function loadRoutes(Map $router): void |
|
| 78 | - { |
|
| 79 | - $router->attach('', '', static function (Map $router): void { |
|
| 73 | + /** |
|
| 74 | + * {@inheritDoc} |
|
| 75 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 76 | + */ |
|
| 77 | + public function loadRoutes(Map $router): void |
|
| 78 | + { |
|
| 79 | + $router->attach('', '', static function (Map $router): void { |
|
| 80 | 80 | |
| 81 | - $router->attach('', '/module-maj/misc', static function (Map $router): void { |
|
| 81 | + $router->attach('', '/module-maj/misc', static function (Map $router): void { |
|
| 82 | 82 | |
| 83 | - $router->attach('', '/config/admin', static function (Map $router): void { |
|
| 83 | + $router->attach('', '/config/admin', static function (Map $router): void { |
|
| 84 | 84 | |
| 85 | - $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
|
| 86 | - $router->post(AdminConfigAction::class, '', AdminConfigAction::class); |
|
| 87 | - }); |
|
| 88 | - }); |
|
| 89 | - }); |
|
| 90 | - } |
|
| 85 | + $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
|
| 86 | + $router->post(AdminConfigAction::class, '', AdminConfigAction::class); |
|
| 87 | + }); |
|
| 88 | + }); |
|
| 89 | + }); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * {@inheritDoc} |
|
| 94 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 95 | - */ |
|
| 96 | - public function customModuleVersion(): string |
|
| 97 | - { |
|
| 98 | - return '2.1.0-v.1'; |
|
| 99 | - } |
|
| 92 | + /** |
|
| 93 | + * {@inheritDoc} |
|
| 94 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 95 | + */ |
|
| 96 | + public function customModuleVersion(): string |
|
| 97 | + { |
|
| 98 | + return '2.1.0-v.1'; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * {@inheritDoc} |
|
| 103 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
| 104 | - */ |
|
| 105 | - public function getConfigLink(): string |
|
| 106 | - { |
|
| 107 | - return route(AdminConfigPage::class); |
|
| 108 | - } |
|
| 101 | + /** |
|
| 102 | + * {@inheritDoc} |
|
| 103 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
| 104 | + */ |
|
| 105 | + public function getConfigLink(): string |
|
| 106 | + { |
|
| 107 | + return route(AdminConfigPage::class); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * {@inheritDoc} |
|
| 112 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 113 | - */ |
|
| 114 | - public function listSubscribedHooks(): array |
|
| 115 | - { |
|
| 116 | - return [ |
|
| 117 | - app()->makeWith(TitlesCardHook::class, [ 'module' => $this ]) |
|
| 118 | - ]; |
|
| 119 | - } |
|
| 110 | + /** |
|
| 111 | + * {@inheritDoc} |
|
| 112 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 113 | + */ |
|
| 114 | + public function listSubscribedHooks(): array |
|
| 115 | + { |
|
| 116 | + return [ |
|
| 117 | + app()->makeWith(TitlesCardHook::class, [ 'module' => $this ]) |
|
| 118 | + ]; |
|
| 119 | + } |
|
| 120 | 120 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | public function boot(): void |
| 68 | 68 | { |
| 69 | 69 | $this->traitBoot(); |
| 70 | - View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy'); |
|
| 70 | + View::registerCustomView('::modules/privacy-policy/page', $this->name().'::privacy-policy'); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -76,11 +76,11 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | public function loadRoutes(Map $router): void |
| 78 | 78 | { |
| 79 | - $router->attach('', '', static function (Map $router): void { |
|
| 79 | + $router->attach('', '', static function(Map $router): void { |
|
| 80 | 80 | |
| 81 | - $router->attach('', '/module-maj/misc', static function (Map $router): void { |
|
| 81 | + $router->attach('', '/module-maj/misc', static function(Map $router): void { |
|
| 82 | 82 | |
| 83 | - $router->attach('', '/config/admin', static function (Map $router): void { |
|
| 83 | + $router->attach('', '/config/admin', static function(Map $router): void { |
|
| 84 | 84 | |
| 85 | 85 | $router->get(AdminConfigPage::class, '', AdminConfigPage::class); |
| 86 | 86 | $router->post(AdminConfigAction::class, '', AdminConfigAction::class); |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | public function listSubscribedHooks(): array |
| 115 | 115 | { |
| 116 | 116 | return [ |
| 117 | - app()->makeWith(TitlesCardHook::class, [ 'module' => $this ]) |
|
| 117 | + app()->makeWith(TitlesCardHook::class, ['module' => $this]) |
|
| 118 | 118 | ]; |
| 119 | 119 | } |
| 120 | 120 | } |
@@ -26,80 +26,80 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | trait ModuleMyArtJaubTrait |
| 28 | 28 | { |
| 29 | - use ModuleCustomTrait; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 33 | - */ |
|
| 34 | - public function boot(): void |
|
| 35 | - { |
|
| 36 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
| 37 | - |
|
| 38 | - $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
| 43 | - */ |
|
| 44 | - public function resourcesFolder(): string |
|
| 45 | - { |
|
| 46 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
| 51 | - */ |
|
| 52 | - public function customModuleAuthorName(): string |
|
| 53 | - { |
|
| 54 | - return 'Jonathan Jaubart'; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
| 59 | - */ |
|
| 60 | - public function customModuleSupportUrl(): string |
|
| 61 | - { |
|
| 62 | - return 'https://github.com/jon48/webtrees-lib'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
| 67 | - * |
|
| 68 | - * @return array<string, string> |
|
| 69 | - */ |
|
| 70 | - public function customTranslations(string $language): array |
|
| 71 | - { |
|
| 72 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
| 73 | - |
|
| 74 | - try { |
|
| 75 | - $translation = new Translation($translation_file); |
|
| 76 | - return $translation->asArray(); |
|
| 77 | - } catch (\Exception $e) { |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - return []; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes |
|
| 85 | - */ |
|
| 86 | - public function loadRoutes(Map $router): void |
|
| 87 | - { |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl |
|
| 92 | - */ |
|
| 93 | - public function moduleCssUrl(): string |
|
| 94 | - { |
|
| 95 | - /** @var ModuleThemeInterface $theme */ |
|
| 96 | - $theme = app(ModuleThemeInterface::class); |
|
| 97 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
| 98 | - |
|
| 99 | - if (file_exists($css_file)) { |
|
| 100 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
| 101 | - } else { |
|
| 102 | - return $this->assetUrl('css/default.min.css'); |
|
| 103 | - } |
|
| 104 | - } |
|
| 29 | + use ModuleCustomTrait; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 33 | + */ |
|
| 34 | + public function boot(): void |
|
| 35 | + { |
|
| 36 | + View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
| 37 | + |
|
| 38 | + $this->loadRoutes(app(RouterContainer::class)->getMap()); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::resourcesFolder() |
|
| 43 | + */ |
|
| 44 | + public function resourcesFolder(): string |
|
| 45 | + { |
|
| 46 | + return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleAuthorName() |
|
| 51 | + */ |
|
| 52 | + public function customModuleAuthorName(): string |
|
| 53 | + { |
|
| 54 | + return 'Jonathan Jaubart'; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleSupportUrl() |
|
| 59 | + */ |
|
| 60 | + public function customModuleSupportUrl(): string |
|
| 61 | + { |
|
| 62 | + return 'https://github.com/jon48/webtrees-lib'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customTranslations() |
|
| 67 | + * |
|
| 68 | + * @return array<string, string> |
|
| 69 | + */ |
|
| 70 | + public function customTranslations(string $language): array |
|
| 71 | + { |
|
| 72 | + $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
| 73 | + |
|
| 74 | + try { |
|
| 75 | + $translation = new Translation($translation_file); |
|
| 76 | + return $translation->asArray(); |
|
| 77 | + } catch (\Exception $e) { |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + return []; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes |
|
| 85 | + */ |
|
| 86 | + public function loadRoutes(Map $router): void |
|
| 87 | + { |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::moduleCssUrl |
|
| 92 | + */ |
|
| 93 | + public function moduleCssUrl(): string |
|
| 94 | + { |
|
| 95 | + /** @var ModuleThemeInterface $theme */ |
|
| 96 | + $theme = app(ModuleThemeInterface::class); |
|
| 97 | + $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
| 98 | + |
|
| 99 | + if (file_exists($css_file)) { |
|
| 100 | + return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
| 101 | + } else { |
|
| 102 | + return $this->assetUrl('css/default.min.css'); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function boot(): void |
| 35 | 35 | { |
| 36 | - View::registerNamespace($this->name(), $this->resourcesFolder() . 'views/'); |
|
| 36 | + View::registerNamespace($this->name(), $this->resourcesFolder().'views/'); |
|
| 37 | 37 | |
| 38 | 38 | $this->loadRoutes(app(RouterContainer::class)->getMap()); |
| 39 | 39 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function resourcesFolder(): string |
| 45 | 45 | { |
| 46 | - return Webtrees::MODULES_DIR . trim($this->name(), '_') . '/resources/'; |
|
| 46 | + return Webtrees::MODULES_DIR.trim($this->name(), '_').'/resources/'; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | */ |
| 70 | 70 | public function customTranslations(string $language): array |
| 71 | 71 | { |
| 72 | - $translation_file = $this->resourcesFolder() . 'lang/' . $language . '/messages.php'; |
|
| 72 | + $translation_file = $this->resourcesFolder().'lang/'.$language.'/messages.php'; |
|
| 73 | 73 | |
| 74 | 74 | try { |
| 75 | 75 | $translation = new Translation($translation_file); |
@@ -94,10 +94,10 @@ discard block |
||
| 94 | 94 | { |
| 95 | 95 | /** @var ModuleThemeInterface $theme */ |
| 96 | 96 | $theme = app(ModuleThemeInterface::class); |
| 97 | - $css_file = $this->resourcesFolder() . 'css/' . $theme->name() . '.min.css'; |
|
| 97 | + $css_file = $this->resourcesFolder().'css/'.$theme->name().'.min.css'; |
|
| 98 | 98 | |
| 99 | 99 | if (file_exists($css_file)) { |
| 100 | - return $this->assetUrl('css/' . $theme->name() . '.min.css'); |
|
| 100 | + return $this->assetUrl('css/'.$theme->name().'.min.css'); |
|
| 101 | 101 | } else { |
| 102 | 102 | return $this->assetUrl('css/default.min.css'); |
| 103 | 103 | } |
@@ -56,268 +56,268 @@ |
||
| 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(): string |
|
| 250 | - { |
|
| 251 | - $request = app(ServerRequestInterface::class); |
|
| 252 | - $xref = $request->getAttribute('xref'); |
|
| 253 | - $tree = $request->getAttribute('tree'); |
|
| 254 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 255 | - |
|
| 256 | - $individual = Registry::individualFactory()->make($xref, $tree); |
|
| 257 | - |
|
| 258 | - return view($this->name() . '::sidebar/title', [ |
|
| 259 | - 'module_name' => $this->name(), |
|
| 260 | - 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($tree, $user, $individual) |
|
| 261 | - ]); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * {@inheritDoc} |
|
| 266 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent() |
|
| 267 | - */ |
|
| 268 | - public function getSidebarContent(Individual $individual): string |
|
| 269 | - { |
|
| 270 | - $sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
|
| 271 | - $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree()); |
|
| 272 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 273 | - |
|
| 274 | - return view($this->name() . '::sidebar/content', [ |
|
| 275 | - 'sosa_ancestor' => $individual, |
|
| 276 | - 'sosa_root' => $sosa_root, |
|
| 277 | - 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
| 278 | - ]); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - /** |
|
| 282 | - * {@inheritDoc} |
|
| 283 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
|
| 284 | - */ |
|
| 285 | - public function hasSidebarContent(Individual $individual): bool |
|
| 286 | - { |
|
| 287 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 288 | - |
|
| 289 | - return app(SosaRecordsService::class) |
|
| 290 | - ->sosaNumbers($individual->tree(), $user, $individual)->count() > 0; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * {@inheritDoc} |
|
| 295 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder() |
|
| 296 | - */ |
|
| 297 | - public function defaultSidebarOrder(): int |
|
| 298 | - { |
|
| 299 | - return 1; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * {@inheritDoc} |
|
| 304 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
| 305 | - */ |
|
| 306 | - public function listGeoAnalyses(): array |
|
| 307 | - { |
|
| 308 | - return [ |
|
| 309 | - SosaByGenerationGeoAnalysis::class |
|
| 310 | - ]; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * {@inheritDoc} |
|
| 315 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 316 | - */ |
|
| 317 | - public function listSubscribedHooks(): array |
|
| 318 | - { |
|
| 319 | - return [ |
|
| 320 | - app()->makeWith(SosaIconHook::class, [ 'module' => $this ]) |
|
| 321 | - ]; |
|
| 322 | - } |
|
| 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(): string |
|
| 250 | + { |
|
| 251 | + $request = app(ServerRequestInterface::class); |
|
| 252 | + $xref = $request->getAttribute('xref'); |
|
| 253 | + $tree = $request->getAttribute('tree'); |
|
| 254 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 255 | + |
|
| 256 | + $individual = Registry::individualFactory()->make($xref, $tree); |
|
| 257 | + |
|
| 258 | + return view($this->name() . '::sidebar/title', [ |
|
| 259 | + 'module_name' => $this->name(), |
|
| 260 | + 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($tree, $user, $individual) |
|
| 261 | + ]); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * {@inheritDoc} |
|
| 266 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent() |
|
| 267 | + */ |
|
| 268 | + public function getSidebarContent(Individual $individual): string |
|
| 269 | + { |
|
| 270 | + $sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
|
| 271 | + $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree()); |
|
| 272 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 273 | + |
|
| 274 | + return view($this->name() . '::sidebar/content', [ |
|
| 275 | + 'sosa_ancestor' => $individual, |
|
| 276 | + 'sosa_root' => $sosa_root, |
|
| 277 | + 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
| 278 | + ]); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + /** |
|
| 282 | + * {@inheritDoc} |
|
| 283 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
|
| 284 | + */ |
|
| 285 | + public function hasSidebarContent(Individual $individual): bool |
|
| 286 | + { |
|
| 287 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 288 | + |
|
| 289 | + return app(SosaRecordsService::class) |
|
| 290 | + ->sosaNumbers($individual->tree(), $user, $individual)->count() > 0; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * {@inheritDoc} |
|
| 295 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder() |
|
| 296 | + */ |
|
| 297 | + public function defaultSidebarOrder(): int |
|
| 298 | + { |
|
| 299 | + return 1; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * {@inheritDoc} |
|
| 304 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
| 305 | + */ |
|
| 306 | + public function listGeoAnalyses(): array |
|
| 307 | + { |
|
| 308 | + return [ |
|
| 309 | + SosaByGenerationGeoAnalysis::class |
|
| 310 | + ]; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * {@inheritDoc} |
|
| 315 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 316 | + */ |
|
| 317 | + public function listSubscribedHooks(): array |
|
| 318 | + { |
|
| 319 | + return [ |
|
| 320 | + app()->makeWith(SosaIconHook::class, [ 'module' => $this ]) |
|
| 321 | + ]; |
|
| 322 | + } |
|
| 323 | 323 | } |
@@ -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 | /** |
@@ -255,7 +255,7 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | $individual = Registry::individualFactory()->make($xref, $tree); |
| 257 | 257 | |
| 258 | - return view($this->name() . '::sidebar/title', [ |
|
| 258 | + return view($this->name().'::sidebar/title', [ |
|
| 259 | 259 | 'module_name' => $this->name(), |
| 260 | 260 | 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($tree, $user, $individual) |
| 261 | 261 | ]); |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree()); |
| 272 | 272 | $user = Auth::check() ? Auth::user() : new DefaultUser(); |
| 273 | 273 | |
| 274 | - return view($this->name() . '::sidebar/content', [ |
|
| 274 | + return view($this->name().'::sidebar/content', [ |
|
| 275 | 275 | 'sosa_ancestor' => $individual, |
| 276 | 276 | 'sosa_root' => $sosa_root, |
| 277 | 277 | 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | public function listSubscribedHooks(): array |
| 318 | 318 | { |
| 319 | 319 | return [ |
| 320 | - app()->makeWith(SosaIconHook::class, [ 'module' => $this ]) |
|
| 320 | + app()->makeWith(SosaIconHook::class, ['module' => $this]) |
|
| 321 | 321 | ]; |
| 322 | 322 | } |
| 323 | 323 | } |
@@ -26,51 +26,51 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class SosaIconHook implements RecordNameTextExtenderInterface |
| 28 | 28 | { |
| 29 | - private ModuleInterface $module; |
|
| 30 | - private SosaRecordsService $sosa_records_service; |
|
| 29 | + private ModuleInterface $module; |
|
| 30 | + private SosaRecordsService $sosa_records_service; |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Constructor for SosaIconHook |
|
| 34 | - * |
|
| 35 | - * @param ModuleInterface $module |
|
| 36 | - * @param SosaRecordsService $sosa_records_service |
|
| 37 | - */ |
|
| 38 | - public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service) |
|
| 39 | - { |
|
| 40 | - $this->module = $module; |
|
| 41 | - $this->sosa_records_service = $sosa_records_service; |
|
| 42 | - } |
|
| 32 | + /** |
|
| 33 | + * Constructor for SosaIconHook |
|
| 34 | + * |
|
| 35 | + * @param ModuleInterface $module |
|
| 36 | + * @param SosaRecordsService $sosa_records_service |
|
| 37 | + */ |
|
| 38 | + public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service) |
|
| 39 | + { |
|
| 40 | + $this->module = $module; |
|
| 41 | + $this->sosa_records_service = $sosa_records_service; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * {@inheritDoc} |
|
| 46 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 47 | - */ |
|
| 48 | - public function module(): ModuleInterface |
|
| 49 | - { |
|
| 50 | - return $this->module; |
|
| 51 | - } |
|
| 44 | + /** |
|
| 45 | + * {@inheritDoc} |
|
| 46 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module() |
|
| 47 | + */ |
|
| 48 | + public function module(): ModuleInterface |
|
| 49 | + { |
|
| 50 | + return $this->module; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
| 56 | - */ |
|
| 57 | - public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 58 | - { |
|
| 59 | - return ''; |
|
| 60 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend() |
|
| 56 | + */ |
|
| 57 | + public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 58 | + { |
|
| 59 | + return ''; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * {@inheritDoc} |
|
| 64 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
| 65 | - */ |
|
| 66 | - public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 67 | - { |
|
| 68 | - if ( |
|
| 69 | - $record instanceof Individual && |
|
| 70 | - $this->sosa_records_service->isSosa($record->tree(), Auth::user(), $record) |
|
| 71 | - ) { |
|
| 72 | - return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]); |
|
| 73 | - } |
|
| 74 | - return ''; |
|
| 75 | - } |
|
| 62 | + /** |
|
| 63 | + * {@inheritDoc} |
|
| 64 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend() |
|
| 65 | + */ |
|
| 66 | + public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string |
|
| 67 | + { |
|
| 68 | + if ( |
|
| 69 | + $record instanceof Individual && |
|
| 70 | + $this->sosa_records_service->isSosa($record->tree(), Auth::user(), $record) |
|
| 71 | + ) { |
|
| 72 | + return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]); |
|
| 73 | + } |
|
| 74 | + return ''; |
|
| 75 | + } |
|
| 76 | 76 | } |
@@ -69,7 +69,7 @@ |
||
| 69 | 69 | $record instanceof Individual && |
| 70 | 70 | $this->sosa_records_service->isSosa($record->tree(), Auth::user(), $record) |
| 71 | 71 | ) { |
| 72 | - return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]); |
|
| 72 | + return view($this->module->name().'::icons/sosa', ['size_style' => $size]); |
|
| 73 | 73 | } |
| 74 | 74 | return ''; |
| 75 | 75 | } |
@@ -30,297 +30,297 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SosaRecordsService |
| 32 | 32 | { |
| 33 | - /** |
|
| 34 | - * @var int|null $max_system_generations |
|
| 35 | - */ |
|
| 36 | - private $max_system_generations; |
|
| 33 | + /** |
|
| 34 | + * @var int|null $max_system_generations |
|
| 35 | + */ |
|
| 36 | + private $max_system_generations; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Maximum number of generation the system is able to hold. |
|
| 40 | - * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
| 41 | - * |
|
| 42 | - * @return int |
|
| 43 | - */ |
|
| 44 | - public function maxSystemGenerations(): int |
|
| 45 | - { |
|
| 46 | - if ($this->max_system_generations === null) { |
|
| 47 | - $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
| 48 | - } |
|
| 49 | - return $this->max_system_generations; |
|
| 50 | - } |
|
| 38 | + /** |
|
| 39 | + * Maximum number of generation the system is able to hold. |
|
| 40 | + * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
| 41 | + * |
|
| 42 | + * @return int |
|
| 43 | + */ |
|
| 44 | + public function maxSystemGenerations(): int |
|
| 45 | + { |
|
| 46 | + if ($this->max_system_generations === null) { |
|
| 47 | + $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
| 48 | + } |
|
| 49 | + return $this->max_system_generations; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Calculate the generation of a sosa |
|
| 54 | - * Sosa 1 is of generation 1. |
|
| 55 | - * |
|
| 56 | - * @param int $sosa |
|
| 57 | - * @return int |
|
| 58 | - */ |
|
| 59 | - public function generation(int $sosa): int |
|
| 60 | - { |
|
| 61 | - return BigInteger::of($sosa)->getBitLength(); |
|
| 62 | - } |
|
| 52 | + /** |
|
| 53 | + * Calculate the generation of a sosa |
|
| 54 | + * Sosa 1 is of generation 1. |
|
| 55 | + * |
|
| 56 | + * @param int $sosa |
|
| 57 | + * @return int |
|
| 58 | + */ |
|
| 59 | + public function generation(int $sosa): int |
|
| 60 | + { |
|
| 61 | + return BigInteger::of($sosa)->getBitLength(); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Calculate the descendant sosa of the given sosa, at the given generation. |
|
| 66 | - * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
| 67 | - * |
|
| 68 | - * @param int $sosa |
|
| 69 | - * @param int $gen |
|
| 70 | - * @return int |
|
| 71 | - */ |
|
| 72 | - public function sosaDescendantOf(int $sosa, int $gen): int |
|
| 73 | - { |
|
| 74 | - $gen_sosa = $this->generation($sosa); |
|
| 75 | - return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
| 76 | - ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
| 77 | - ->toInt(); |
|
| 78 | - } |
|
| 64 | + /** |
|
| 65 | + * Calculate the descendant sosa of the given sosa, at the given generation. |
|
| 66 | + * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
| 67 | + * |
|
| 68 | + * @param int $sosa |
|
| 69 | + * @param int $gen |
|
| 70 | + * @return int |
|
| 71 | + */ |
|
| 72 | + public function sosaDescendantOf(int $sosa, int $gen): int |
|
| 73 | + { |
|
| 74 | + $gen_sosa = $this->generation($sosa); |
|
| 75 | + return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
| 76 | + ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
| 77 | + ->toInt(); |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Check whether an individual is a Sosa ancestor. |
|
| 82 | - * |
|
| 83 | - * @param Tree $tree |
|
| 84 | - * @param UserInterface $user |
|
| 85 | - * @param Individual $indi |
|
| 86 | - * @return bool |
|
| 87 | - */ |
|
| 88 | - public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
| 89 | - { |
|
| 90 | - return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
| 91 | - } |
|
| 80 | + /** |
|
| 81 | + * Check whether an individual is a Sosa ancestor. |
|
| 82 | + * |
|
| 83 | + * @param Tree $tree |
|
| 84 | + * @param UserInterface $user |
|
| 85 | + * @param Individual $indi |
|
| 86 | + * @return bool |
|
| 87 | + */ |
|
| 88 | + public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
| 89 | + { |
|
| 90 | + return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Returns all Sosa numbers associated to an Individual |
|
| 95 | - * |
|
| 96 | - * @param Tree $tree |
|
| 97 | - * @param UserInterface $user |
|
| 98 | - * @param Individual $indi |
|
| 99 | - * @return Collection<int, int> |
|
| 100 | - */ |
|
| 101 | - public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
| 102 | - { |
|
| 103 | - return Registry::cache()->array()->remember( |
|
| 104 | - 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
| 105 | - function () use ($tree, $user, $indi): Collection { |
|
| 106 | - return DB::table('maj_sosa') |
|
| 107 | - ->select(['majs_sosa', 'majs_gen']) |
|
| 108 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 109 | - ->where('majs_user_id', '=', $user->id()) |
|
| 110 | - ->where('majs_i_id', '=', $indi->xref()) |
|
| 111 | - ->orderBy('majs_sosa') |
|
| 112 | - ->get()->pluck('majs_gen', 'majs_sosa'); |
|
| 113 | - } |
|
| 114 | - ); |
|
| 115 | - } |
|
| 93 | + /** |
|
| 94 | + * Returns all Sosa numbers associated to an Individual |
|
| 95 | + * |
|
| 96 | + * @param Tree $tree |
|
| 97 | + * @param UserInterface $user |
|
| 98 | + * @param Individual $indi |
|
| 99 | + * @return Collection<int, int> |
|
| 100 | + */ |
|
| 101 | + public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
| 102 | + { |
|
| 103 | + return Registry::cache()->array()->remember( |
|
| 104 | + 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
| 105 | + function () use ($tree, $user, $indi): Collection { |
|
| 106 | + return DB::table('maj_sosa') |
|
| 107 | + ->select(['majs_sosa', 'majs_gen']) |
|
| 108 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 109 | + ->where('majs_user_id', '=', $user->id()) |
|
| 110 | + ->where('majs_i_id', '=', $indi->xref()) |
|
| 111 | + ->orderBy('majs_sosa') |
|
| 112 | + ->get()->pluck('majs_gen', 'majs_sosa'); |
|
| 113 | + } |
|
| 114 | + ); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Return a list of the Sosa ancestors across all generation |
|
| 119 | - * |
|
| 120 | - * @param Tree $tree |
|
| 121 | - * @param UserInterface $user |
|
| 122 | - * @return Collection<\stdClass> |
|
| 123 | - */ |
|
| 124 | - public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
| 125 | - { |
|
| 126 | - return DB::table('maj_sosa') |
|
| 127 | - ->select(['majs_sosa', 'majs_i_id']) |
|
| 128 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 129 | - ->where('majs_user_id', '=', $user->id()) |
|
| 130 | - ->orderBy('majs_sosa') |
|
| 131 | - ->get(); |
|
| 132 | - } |
|
| 117 | + /** |
|
| 118 | + * Return a list of the Sosa ancestors across all generation |
|
| 119 | + * |
|
| 120 | + * @param Tree $tree |
|
| 121 | + * @param UserInterface $user |
|
| 122 | + * @return Collection<\stdClass> |
|
| 123 | + */ |
|
| 124 | + public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
| 125 | + { |
|
| 126 | + return DB::table('maj_sosa') |
|
| 127 | + ->select(['majs_sosa', 'majs_i_id']) |
|
| 128 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 129 | + ->where('majs_user_id', '=', $user->id()) |
|
| 130 | + ->orderBy('majs_sosa') |
|
| 131 | + ->get(); |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Return a list of the Sosa ancestors at a given generation |
|
| 136 | - * |
|
| 137 | - * @param Tree $tree |
|
| 138 | - * @param UserInterface $user |
|
| 139 | - * @param int $gen |
|
| 140 | - * @return Collection<\stdClass> |
|
| 141 | - */ |
|
| 142 | - public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 143 | - { |
|
| 144 | - return DB::table('maj_sosa') |
|
| 145 | - ->select(['majs_sosa', 'majs_i_id']) |
|
| 146 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 147 | - ->where('majs_user_id', '=', $user->id()) |
|
| 148 | - ->where('majs_gen', '=', $gen) |
|
| 149 | - ->orderBy('majs_sosa') |
|
| 150 | - ->get(); |
|
| 151 | - } |
|
| 134 | + /** |
|
| 135 | + * Return a list of the Sosa ancestors at a given generation |
|
| 136 | + * |
|
| 137 | + * @param Tree $tree |
|
| 138 | + * @param UserInterface $user |
|
| 139 | + * @param int $gen |
|
| 140 | + * @return Collection<\stdClass> |
|
| 141 | + */ |
|
| 142 | + public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 143 | + { |
|
| 144 | + return DB::table('maj_sosa') |
|
| 145 | + ->select(['majs_sosa', 'majs_i_id']) |
|
| 146 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 147 | + ->where('majs_user_id', '=', $user->id()) |
|
| 148 | + ->where('majs_gen', '=', $gen) |
|
| 149 | + ->orderBy('majs_sosa') |
|
| 150 | + ->get(); |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - /** |
|
| 154 | - * Return a list of the Sosa families at a given generation |
|
| 155 | - * |
|
| 156 | - * @param Tree $tree |
|
| 157 | - * @param UserInterface $user |
|
| 158 | - * @param int $gen |
|
| 159 | - * @return Collection<\stdClass> |
|
| 160 | - */ |
|
| 161 | - public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 162 | - { |
|
| 163 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 164 | - return DB::table('families') |
|
| 165 | - ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
| 166 | - // Link to family husband |
|
| 167 | - $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
| 168 | - ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
| 169 | - ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
| 170 | - ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
| 171 | - }) |
|
| 172 | - ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
| 173 | - // Link to family husband |
|
| 174 | - $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
| 175 | - ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
| 176 | - ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
| 177 | - ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
| 178 | - }) |
|
| 179 | - ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
| 180 | - ->where('sosa_husb.majs_gen', '=', $gen) |
|
| 181 | - ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
| 182 | - ->orderBy('sosa_husb.majs_sosa') |
|
| 183 | - ->get(); |
|
| 184 | - } |
|
| 153 | + /** |
|
| 154 | + * Return a list of the Sosa families at a given generation |
|
| 155 | + * |
|
| 156 | + * @param Tree $tree |
|
| 157 | + * @param UserInterface $user |
|
| 158 | + * @param int $gen |
|
| 159 | + * @return Collection<\stdClass> |
|
| 160 | + */ |
|
| 161 | + public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 162 | + { |
|
| 163 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 164 | + return DB::table('families') |
|
| 165 | + ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
| 166 | + // Link to family husband |
|
| 167 | + $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
| 168 | + ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
| 169 | + ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
| 170 | + ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
| 171 | + }) |
|
| 172 | + ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
| 173 | + // Link to family husband |
|
| 174 | + $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
| 175 | + ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
| 176 | + ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
| 177 | + ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
| 178 | + }) |
|
| 179 | + ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
| 180 | + ->where('sosa_husb.majs_gen', '=', $gen) |
|
| 181 | + ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
| 182 | + ->orderBy('sosa_husb.majs_sosa') |
|
| 183 | + ->get(); |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * Return a list of Sosa ancestors missing at a given generation. |
|
| 188 | - * It includes the reference of either parent if it is known. |
|
| 189 | - * |
|
| 190 | - * @param Tree $tree |
|
| 191 | - * @param UserInterface $user |
|
| 192 | - * @param int $gen |
|
| 193 | - * @return Collection<\stdClass> |
|
| 194 | - */ |
|
| 195 | - public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 196 | - { |
|
| 197 | - if ($gen == 1) { |
|
| 198 | - return collect(); |
|
| 199 | - } |
|
| 186 | + /** |
|
| 187 | + * Return a list of Sosa ancestors missing at a given generation. |
|
| 188 | + * It includes the reference of either parent if it is known. |
|
| 189 | + * |
|
| 190 | + * @param Tree $tree |
|
| 191 | + * @param UserInterface $user |
|
| 192 | + * @param int $gen |
|
| 193 | + * @return Collection<\stdClass> |
|
| 194 | + */ |
|
| 195 | + public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 196 | + { |
|
| 197 | + if ($gen == 1) { |
|
| 198 | + return collect(); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 202 | - return DB::table('maj_sosa AS sosa') |
|
| 203 | - ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
| 204 | - ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
| 205 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 206 | - // Link to sosa's father |
|
| 207 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 208 | - ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
| 209 | - ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
| 210 | - }) |
|
| 211 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 212 | - // Link to sosa's mother |
|
| 213 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 214 | - ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
| 215 | - ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
| 216 | - }) |
|
| 217 | - ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
| 218 | - ->where('sosa.majs_user_id', '=', $user->id()) |
|
| 219 | - ->where('sosa.majs_gen', '=', $gen - 1) |
|
| 220 | - ->where(function (Builder $query): void { |
|
| 221 | - $query->whereNull('sosa_fat.majs_i_id') |
|
| 222 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 223 | - }) |
|
| 224 | - ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
| 225 | - ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
| 226 | - ->get(); |
|
| 227 | - } |
|
| 201 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 202 | + return DB::table('maj_sosa AS sosa') |
|
| 203 | + ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
| 204 | + ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
| 205 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 206 | + // Link to sosa's father |
|
| 207 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 208 | + ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
| 209 | + ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
| 210 | + }) |
|
| 211 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 212 | + // Link to sosa's mother |
|
| 213 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 214 | + ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
| 215 | + ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
| 216 | + }) |
|
| 217 | + ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
| 218 | + ->where('sosa.majs_user_id', '=', $user->id()) |
|
| 219 | + ->where('sosa.majs_gen', '=', $gen - 1) |
|
| 220 | + ->where(function (Builder $query): void { |
|
| 221 | + $query->whereNull('sosa_fat.majs_i_id') |
|
| 222 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 223 | + }) |
|
| 224 | + ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
| 225 | + ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
| 226 | + ->get(); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * Remove all Sosa entries related to the gedcom file and user |
|
| 231 | - * |
|
| 232 | - * @param Tree $tree |
|
| 233 | - * @param UserInterface $user |
|
| 234 | - */ |
|
| 235 | - public function deleteAll(Tree $tree, UserInterface $user): void |
|
| 236 | - { |
|
| 237 | - DB::table('maj_sosa') |
|
| 238 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 239 | - ->where('majs_user_id', '=', $user->id()) |
|
| 240 | - ->delete(); |
|
| 241 | - } |
|
| 229 | + /** |
|
| 230 | + * Remove all Sosa entries related to the gedcom file and user |
|
| 231 | + * |
|
| 232 | + * @param Tree $tree |
|
| 233 | + * @param UserInterface $user |
|
| 234 | + */ |
|
| 235 | + public function deleteAll(Tree $tree, UserInterface $user): void |
|
| 236 | + { |
|
| 237 | + DB::table('maj_sosa') |
|
| 238 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 239 | + ->where('majs_user_id', '=', $user->id()) |
|
| 240 | + ->delete(); |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * |
|
| 245 | - * @param Tree $tree |
|
| 246 | - * @param UserInterface $user |
|
| 247 | - * @param int $sosa |
|
| 248 | - */ |
|
| 249 | - public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
| 250 | - { |
|
| 251 | - DB::table('maj_sosa') |
|
| 252 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 253 | - ->where('majs_user_id', '=', $user->id()) |
|
| 254 | - ->where('majs_sosa', '>=', $sosa) |
|
| 255 | - ->whereRaw( |
|
| 256 | - 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
| 257 | - [$this->generation($sosa), $sosa] |
|
| 258 | - ) |
|
| 259 | - ->delete(); |
|
| 260 | - } |
|
| 243 | + /** |
|
| 244 | + * |
|
| 245 | + * @param Tree $tree |
|
| 246 | + * @param UserInterface $user |
|
| 247 | + * @param int $sosa |
|
| 248 | + */ |
|
| 249 | + public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
| 250 | + { |
|
| 251 | + DB::table('maj_sosa') |
|
| 252 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 253 | + ->where('majs_user_id', '=', $user->id()) |
|
| 254 | + ->where('majs_sosa', '>=', $sosa) |
|
| 255 | + ->whereRaw( |
|
| 256 | + 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
| 257 | + [$this->generation($sosa), $sosa] |
|
| 258 | + ) |
|
| 259 | + ->delete(); |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - /** |
|
| 263 | - * Insert (or update if already existing) a list of Sosa individuals |
|
| 264 | - * |
|
| 265 | - * @param Tree $tree |
|
| 266 | - * @param UserInterface $user |
|
| 267 | - * @param array $sosa_records |
|
| 268 | - */ |
|
| 269 | - public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
| 270 | - { |
|
| 271 | - $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
| 262 | + /** |
|
| 263 | + * Insert (or update if already existing) a list of Sosa individuals |
|
| 264 | + * |
|
| 265 | + * @param Tree $tree |
|
| 266 | + * @param UserInterface $user |
|
| 267 | + * @param array $sosa_records |
|
| 268 | + */ |
|
| 269 | + public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
| 270 | + { |
|
| 271 | + $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
| 272 | 272 | |
| 273 | - $bindings_placeholders = $bindings_values = []; |
|
| 274 | - $has_records = false; |
|
| 275 | - foreach ($sosa_records as $i => $row) { |
|
| 276 | - $gen = $this->generation($row['sosa']); |
|
| 277 | - if ($gen <= $this->maxSystemGenerations()) { |
|
| 278 | - $has_records = true; |
|
| 279 | - if ($mass_update) { |
|
| 280 | - $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
| 281 | - ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
| 282 | - ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
| 283 | - $bindings_values = array_merge( |
|
| 284 | - $bindings_values, |
|
| 285 | - [ |
|
| 286 | - 'tree_id' . $i => $tree->id(), |
|
| 287 | - 'user_id' . $i => $user->id(), |
|
| 288 | - 'sosa' . $i => $row['sosa'], |
|
| 289 | - 'indi_id' . $i => $row['indi'], |
|
| 290 | - 'gen' . $i => $gen, |
|
| 291 | - 'byear' . $i => $row['birth_year'], |
|
| 292 | - 'byearest' . $i => $row['birth_year_est'], |
|
| 293 | - 'dyear' . $i => $row['death_year'], |
|
| 294 | - 'dyearest' . $i => $row['death_year_est'] |
|
| 295 | - ] |
|
| 296 | - ); |
|
| 297 | - } else { |
|
| 298 | - DB::table('maj_sosa')->updateOrInsert( |
|
| 299 | - [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
| 300 | - [ |
|
| 301 | - 'majs_i_id' => $row['indi'], |
|
| 302 | - 'majs_gen' => $gen, |
|
| 303 | - 'majs_birth_year' => $row['birth_year'], |
|
| 304 | - 'majs_birth_year_est' => $row['birth_year_est'], |
|
| 305 | - 'majs_death_year' => $row['death_year'], |
|
| 306 | - 'majs_death_year_est' => $row['death_year_est'] |
|
| 307 | - ] |
|
| 308 | - ); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - } |
|
| 273 | + $bindings_placeholders = $bindings_values = []; |
|
| 274 | + $has_records = false; |
|
| 275 | + foreach ($sosa_records as $i => $row) { |
|
| 276 | + $gen = $this->generation($row['sosa']); |
|
| 277 | + if ($gen <= $this->maxSystemGenerations()) { |
|
| 278 | + $has_records = true; |
|
| 279 | + if ($mass_update) { |
|
| 280 | + $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
| 281 | + ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
| 282 | + ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
| 283 | + $bindings_values = array_merge( |
|
| 284 | + $bindings_values, |
|
| 285 | + [ |
|
| 286 | + 'tree_id' . $i => $tree->id(), |
|
| 287 | + 'user_id' . $i => $user->id(), |
|
| 288 | + 'sosa' . $i => $row['sosa'], |
|
| 289 | + 'indi_id' . $i => $row['indi'], |
|
| 290 | + 'gen' . $i => $gen, |
|
| 291 | + 'byear' . $i => $row['birth_year'], |
|
| 292 | + 'byearest' . $i => $row['birth_year_est'], |
|
| 293 | + 'dyear' . $i => $row['death_year'], |
|
| 294 | + 'dyearest' . $i => $row['death_year_est'] |
|
| 295 | + ] |
|
| 296 | + ); |
|
| 297 | + } else { |
|
| 298 | + DB::table('maj_sosa')->updateOrInsert( |
|
| 299 | + [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
| 300 | + [ |
|
| 301 | + 'majs_i_id' => $row['indi'], |
|
| 302 | + 'majs_gen' => $gen, |
|
| 303 | + 'majs_birth_year' => $row['birth_year'], |
|
| 304 | + 'majs_birth_year_est' => $row['birth_year_est'], |
|
| 305 | + 'majs_death_year' => $row['death_year'], |
|
| 306 | + 'majs_death_year_est' => $row['death_year_est'] |
|
| 307 | + ] |
|
| 308 | + ); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | 312 | |
| 313 | - if ($has_records && $mass_update) { |
|
| 314 | - DB::connection()->statement( |
|
| 315 | - 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
| 316 | - ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
| 317 | - ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
| 318 | - ' VALUES ' . implode(',', $bindings_placeholders) . |
|
| 319 | - ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
| 320 | - ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
| 321 | - ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
| 322 | - $bindings_values |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - } |
|
| 313 | + if ($has_records && $mass_update) { |
|
| 314 | + DB::connection()->statement( |
|
| 315 | + 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
| 316 | + ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
| 317 | + ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
| 318 | + ' VALUES ' . implode(',', $bindings_placeholders) . |
|
| 319 | + ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
| 320 | + ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
| 321 | + ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
| 322 | + $bindings_values |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | 326 | } |
@@ -30,511 +30,511 @@ |
||
| 30 | 30 | class SosaStatisticsService |
| 31 | 31 | { |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Reference user |
|
| 35 | - * @var UserInterface $user |
|
| 36 | - */ |
|
| 37 | - private $user; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Reference tree |
|
| 41 | - * @var Tree $tree |
|
| 42 | - */ |
|
| 43 | - private $tree; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Constructor for Sosa Statistics Service |
|
| 47 | - * |
|
| 48 | - * @param Tree $tree |
|
| 49 | - * @param UserInterface $user |
|
| 50 | - */ |
|
| 51 | - public function __construct(Tree $tree, UserInterface $user) |
|
| 52 | - { |
|
| 53 | - $this->tree = $tree; |
|
| 54 | - $this->user = $user; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Return the root individual for the reference tree and user. |
|
| 59 | - * |
|
| 60 | - * @return Individual|NULL |
|
| 61 | - */ |
|
| 62 | - public function rootIndividual(): ?Individual |
|
| 63 | - { |
|
| 64 | - $root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
| 65 | - return Registry::individualFactory()->make($root_indi_id, $this->tree); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Get the highest generation for the reference tree and user. |
|
| 70 | - * |
|
| 71 | - * @return int |
|
| 72 | - */ |
|
| 73 | - public function maxGeneration(): int |
|
| 74 | - { |
|
| 75 | - return (int) DB::table('maj_sosa') |
|
| 76 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 77 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 78 | - ->max('majs_gen'); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Get the total count of individuals in the tree. |
|
| 83 | - * |
|
| 84 | - * @return int |
|
| 85 | - */ |
|
| 86 | - public function totalIndividuals(): int |
|
| 87 | - { |
|
| 88 | - return DB::table('individuals') |
|
| 89 | - ->where('i_file', '=', $this->tree->id()) |
|
| 90 | - ->count(); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Get the total count of Sosa ancestors for all generations |
|
| 95 | - * |
|
| 96 | - * @return int |
|
| 97 | - */ |
|
| 98 | - public function totalAncestors(): int |
|
| 99 | - { |
|
| 100 | - return DB::table('maj_sosa') |
|
| 101 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 102 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 103 | - ->count(); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Get the total count of Sosa ancestors for a generation |
|
| 108 | - * |
|
| 109 | - * @return int |
|
| 110 | - */ |
|
| 111 | - public function totalAncestorsAtGeneration(int $gen): int |
|
| 112 | - { |
|
| 113 | - return DB::table('maj_sosa') |
|
| 114 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 115 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 116 | - ->where('majs_gen', '=', $gen) |
|
| 117 | - ->count(); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Get the total count of distinct Sosa ancestors for all generations |
|
| 122 | - * |
|
| 123 | - * @return int |
|
| 124 | - */ |
|
| 125 | - public function totalDistinctAncestors(): int |
|
| 126 | - { |
|
| 127 | - return DB::table('maj_sosa') |
|
| 128 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 129 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 130 | - ->distinct() |
|
| 131 | - ->count('majs_i_id'); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Get the mean generation time, as the slope of the linear regression of birth years vs generations |
|
| 136 | - * |
|
| 137 | - * @return float |
|
| 138 | - */ |
|
| 139 | - public function meanGenerationTime(): float |
|
| 140 | - { |
|
| 141 | - $row = DB::table('maj_sosa') |
|
| 142 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 143 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 144 | - ->whereNotNull('majs_birth_year') |
|
| 145 | - ->selectRaw('COUNT(majs_sosa) AS n') |
|
| 146 | - ->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy') |
|
| 147 | - ->selectRaw('SUM(majs_gen) AS sum_x') |
|
| 148 | - ->selectRaw('SUM(majs_birth_year) AS sum_y') |
|
| 149 | - ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2') |
|
| 150 | - ->get()->first(); |
|
| 151 | - |
|
| 152 | - return $row->n == 0 ? 0 : |
|
| 153 | - -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2)); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Get the statistic array detailed by generation. |
|
| 158 | - * Statistics for each generation are: |
|
| 159 | - * - The number of Sosa in generation |
|
| 160 | - * - The number of Sosa up to generation |
|
| 161 | - * - The number of distinct Sosa up to generation |
|
| 162 | - * - The year of the first birth in generation |
|
| 163 | - * - The year of the first estimated birth in generation |
|
| 164 | - * - The year of the last birth in generation |
|
| 165 | - * - The year of the last estimated birth in generation |
|
| 166 | - * - The average year of birth in generation |
|
| 167 | - * |
|
| 168 | - * @return array<int, array<string, int|null>> Statistics array |
|
| 169 | - */ |
|
| 170 | - public function statisticsByGenerations(): array |
|
| 171 | - { |
|
| 172 | - $stats_by_gen = $this->statisticsByGenerationBasicData(); |
|
| 173 | - $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData(); |
|
| 174 | - |
|
| 175 | - $statistics_by_gen = []; |
|
| 176 | - foreach ($stats_by_gen as $gen => $stats_gen) { |
|
| 177 | - $statistics_by_gen[(int) $stats_gen->gen] = array( |
|
| 178 | - 'sosaCount' => (int) $stats_gen->total_sosa, |
|
| 179 | - 'sosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_cumul, |
|
| 180 | - 'diffSosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
| 181 | - 'firstBirth' => $stats_gen->first_year, |
|
| 182 | - 'firstEstimatedBirth' => $stats_gen->first_est_year, |
|
| 183 | - 'lastBirth' => $stats_gen->last_year, |
|
| 184 | - 'lastEstimatedBirth' => $stats_gen->last_est_year |
|
| 185 | - ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $statistics_by_gen; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Returns the basic statistics data by generation. |
|
| 193 | - * |
|
| 194 | - * @return Collection<int, \stdClass> |
|
| 195 | - */ |
|
| 196 | - private function statisticsByGenerationBasicData(): Collection |
|
| 197 | - { |
|
| 198 | - return DB::table('maj_sosa') |
|
| 199 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 200 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 201 | - ->groupBy('majs_gen') |
|
| 202 | - ->orderBy('majs_gen', 'asc') |
|
| 203 | - ->select('majs_gen AS gen') |
|
| 204 | - ->selectRaw('COUNT(majs_sosa) AS total_sosa') |
|
| 205 | - ->selectRaw('MIN(majs_birth_year) AS first_year') |
|
| 206 | - ->selectRaw('MIN(majs_birth_year_est) AS first_est_year') |
|
| 207 | - ->selectRaw('MAX(majs_birth_year) AS last_year') |
|
| 208 | - ->selectRaw('MAX(majs_birth_year_est) AS last_est_year') |
|
| 209 | - ->get()->keyBy('gen'); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Returns the cumulative statistics data by generation |
|
| 214 | - * |
|
| 215 | - * @return Collection<int, \stdClass> |
|
| 216 | - */ |
|
| 217 | - private function statisticsByGenerationCumulativeData(): Collection |
|
| 218 | - { |
|
| 219 | - $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
| 220 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 221 | - ->where('majs_user_id', '=', $this->user->id()); |
|
| 222 | - |
|
| 223 | - return DB::table('maj_sosa') |
|
| 224 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 225 | - $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen') |
|
| 226 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 227 | - ->where('majs_user_id', '=', $this->user->id()); |
|
| 228 | - }) |
|
| 229 | - ->groupBy('list_gen.majs_gen') |
|
| 230 | - ->select('list_gen.majs_gen AS gen') |
|
| 231 | - ->selectRaw('COUNT(majs_i_id) AS total_cumul') |
|
| 232 | - ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul') |
|
| 233 | - ->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple') |
|
| 234 | - ->get()->keyBy('gen'); |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Returns the pedigree collapse improved calculation by generation. |
|
| 239 | - * |
|
| 240 | - * Format: |
|
| 241 | - * - key : generation |
|
| 242 | - * - values: |
|
| 243 | - * - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation |
|
| 244 | - * - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation |
|
| 245 | - * |
|
| 246 | - * @return array<int, array<string, float>> |
|
| 247 | - */ |
|
| 248 | - public function pedigreeCollapseByGenerationData(): array |
|
| 249 | - { |
|
| 250 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 251 | - |
|
| 252 | - $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
| 253 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 254 | - ->where('majs_user_id', '=', $this->user->id()); |
|
| 255 | - |
|
| 256 | - /* Compute the contributions of nodes of previous generations to the current generation */ |
|
| 257 | - $root_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
| 258 | - ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
| 259 | - ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
| 260 | - ->selectRaw( |
|
| 261 | - '(CASE ' . |
|
| 262 | - ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' . |
|
| 263 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 264 | - ' ELSE 0 ' . |
|
| 265 | - ' END)' . |
|
| 266 | - ' + (CASE ' . |
|
| 267 | - ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' . |
|
| 268 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 269 | - ' ELSE 0 ' . |
|
| 270 | - ' END) contrib' |
|
| 271 | - ) |
|
| 272 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 273 | - $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen') |
|
| 274 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 275 | - ->where('majs_user_id', '=', $this->user->id()); |
|
| 276 | - }) |
|
| 277 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 278 | - // Link to sosa's father |
|
| 279 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 280 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 281 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 282 | - }) |
|
| 283 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 284 | - // Link to sosa's mother |
|
| 285 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 286 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 287 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 288 | - }) |
|
| 289 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 290 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 291 | - ->where(function (Builder $query): void { |
|
| 292 | - $query->whereNull('sosa_fat.majs_i_id') |
|
| 293 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 294 | - }); |
|
| 295 | - |
|
| 296 | - /* Identify nodes in the generations with ancestors who are also in the same generation. |
|
| 33 | + /** |
|
| 34 | + * Reference user |
|
| 35 | + * @var UserInterface $user |
|
| 36 | + */ |
|
| 37 | + private $user; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Reference tree |
|
| 41 | + * @var Tree $tree |
|
| 42 | + */ |
|
| 43 | + private $tree; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Constructor for Sosa Statistics Service |
|
| 47 | + * |
|
| 48 | + * @param Tree $tree |
|
| 49 | + * @param UserInterface $user |
|
| 50 | + */ |
|
| 51 | + public function __construct(Tree $tree, UserInterface $user) |
|
| 52 | + { |
|
| 53 | + $this->tree = $tree; |
|
| 54 | + $this->user = $user; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Return the root individual for the reference tree and user. |
|
| 59 | + * |
|
| 60 | + * @return Individual|NULL |
|
| 61 | + */ |
|
| 62 | + public function rootIndividual(): ?Individual |
|
| 63 | + { |
|
| 64 | + $root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
| 65 | + return Registry::individualFactory()->make($root_indi_id, $this->tree); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Get the highest generation for the reference tree and user. |
|
| 70 | + * |
|
| 71 | + * @return int |
|
| 72 | + */ |
|
| 73 | + public function maxGeneration(): int |
|
| 74 | + { |
|
| 75 | + return (int) DB::table('maj_sosa') |
|
| 76 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 77 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 78 | + ->max('majs_gen'); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Get the total count of individuals in the tree. |
|
| 83 | + * |
|
| 84 | + * @return int |
|
| 85 | + */ |
|
| 86 | + public function totalIndividuals(): int |
|
| 87 | + { |
|
| 88 | + return DB::table('individuals') |
|
| 89 | + ->where('i_file', '=', $this->tree->id()) |
|
| 90 | + ->count(); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Get the total count of Sosa ancestors for all generations |
|
| 95 | + * |
|
| 96 | + * @return int |
|
| 97 | + */ |
|
| 98 | + public function totalAncestors(): int |
|
| 99 | + { |
|
| 100 | + return DB::table('maj_sosa') |
|
| 101 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 102 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 103 | + ->count(); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Get the total count of Sosa ancestors for a generation |
|
| 108 | + * |
|
| 109 | + * @return int |
|
| 110 | + */ |
|
| 111 | + public function totalAncestorsAtGeneration(int $gen): int |
|
| 112 | + { |
|
| 113 | + return DB::table('maj_sosa') |
|
| 114 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 115 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 116 | + ->where('majs_gen', '=', $gen) |
|
| 117 | + ->count(); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Get the total count of distinct Sosa ancestors for all generations |
|
| 122 | + * |
|
| 123 | + * @return int |
|
| 124 | + */ |
|
| 125 | + public function totalDistinctAncestors(): int |
|
| 126 | + { |
|
| 127 | + return DB::table('maj_sosa') |
|
| 128 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 129 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 130 | + ->distinct() |
|
| 131 | + ->count('majs_i_id'); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Get the mean generation time, as the slope of the linear regression of birth years vs generations |
|
| 136 | + * |
|
| 137 | + * @return float |
|
| 138 | + */ |
|
| 139 | + public function meanGenerationTime(): float |
|
| 140 | + { |
|
| 141 | + $row = DB::table('maj_sosa') |
|
| 142 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 143 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 144 | + ->whereNotNull('majs_birth_year') |
|
| 145 | + ->selectRaw('COUNT(majs_sosa) AS n') |
|
| 146 | + ->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy') |
|
| 147 | + ->selectRaw('SUM(majs_gen) AS sum_x') |
|
| 148 | + ->selectRaw('SUM(majs_birth_year) AS sum_y') |
|
| 149 | + ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2') |
|
| 150 | + ->get()->first(); |
|
| 151 | + |
|
| 152 | + return $row->n == 0 ? 0 : |
|
| 153 | + -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2)); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Get the statistic array detailed by generation. |
|
| 158 | + * Statistics for each generation are: |
|
| 159 | + * - The number of Sosa in generation |
|
| 160 | + * - The number of Sosa up to generation |
|
| 161 | + * - The number of distinct Sosa up to generation |
|
| 162 | + * - The year of the first birth in generation |
|
| 163 | + * - The year of the first estimated birth in generation |
|
| 164 | + * - The year of the last birth in generation |
|
| 165 | + * - The year of the last estimated birth in generation |
|
| 166 | + * - The average year of birth in generation |
|
| 167 | + * |
|
| 168 | + * @return array<int, array<string, int|null>> Statistics array |
|
| 169 | + */ |
|
| 170 | + public function statisticsByGenerations(): array |
|
| 171 | + { |
|
| 172 | + $stats_by_gen = $this->statisticsByGenerationBasicData(); |
|
| 173 | + $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData(); |
|
| 174 | + |
|
| 175 | + $statistics_by_gen = []; |
|
| 176 | + foreach ($stats_by_gen as $gen => $stats_gen) { |
|
| 177 | + $statistics_by_gen[(int) $stats_gen->gen] = array( |
|
| 178 | + 'sosaCount' => (int) $stats_gen->total_sosa, |
|
| 179 | + 'sosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_cumul, |
|
| 180 | + 'diffSosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
| 181 | + 'firstBirth' => $stats_gen->first_year, |
|
| 182 | + 'firstEstimatedBirth' => $stats_gen->first_est_year, |
|
| 183 | + 'lastBirth' => $stats_gen->last_year, |
|
| 184 | + 'lastEstimatedBirth' => $stats_gen->last_est_year |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $statistics_by_gen; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Returns the basic statistics data by generation. |
|
| 193 | + * |
|
| 194 | + * @return Collection<int, \stdClass> |
|
| 195 | + */ |
|
| 196 | + private function statisticsByGenerationBasicData(): Collection |
|
| 197 | + { |
|
| 198 | + return DB::table('maj_sosa') |
|
| 199 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 200 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 201 | + ->groupBy('majs_gen') |
|
| 202 | + ->orderBy('majs_gen', 'asc') |
|
| 203 | + ->select('majs_gen AS gen') |
|
| 204 | + ->selectRaw('COUNT(majs_sosa) AS total_sosa') |
|
| 205 | + ->selectRaw('MIN(majs_birth_year) AS first_year') |
|
| 206 | + ->selectRaw('MIN(majs_birth_year_est) AS first_est_year') |
|
| 207 | + ->selectRaw('MAX(majs_birth_year) AS last_year') |
|
| 208 | + ->selectRaw('MAX(majs_birth_year_est) AS last_est_year') |
|
| 209 | + ->get()->keyBy('gen'); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Returns the cumulative statistics data by generation |
|
| 214 | + * |
|
| 215 | + * @return Collection<int, \stdClass> |
|
| 216 | + */ |
|
| 217 | + private function statisticsByGenerationCumulativeData(): Collection |
|
| 218 | + { |
|
| 219 | + $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
| 220 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 221 | + ->where('majs_user_id', '=', $this->user->id()); |
|
| 222 | + |
|
| 223 | + return DB::table('maj_sosa') |
|
| 224 | + ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 225 | + $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen') |
|
| 226 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 227 | + ->where('majs_user_id', '=', $this->user->id()); |
|
| 228 | + }) |
|
| 229 | + ->groupBy('list_gen.majs_gen') |
|
| 230 | + ->select('list_gen.majs_gen AS gen') |
|
| 231 | + ->selectRaw('COUNT(majs_i_id) AS total_cumul') |
|
| 232 | + ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul') |
|
| 233 | + ->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple') |
|
| 234 | + ->get()->keyBy('gen'); |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Returns the pedigree collapse improved calculation by generation. |
|
| 239 | + * |
|
| 240 | + * Format: |
|
| 241 | + * - key : generation |
|
| 242 | + * - values: |
|
| 243 | + * - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation |
|
| 244 | + * - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation |
|
| 245 | + * |
|
| 246 | + * @return array<int, array<string, float>> |
|
| 247 | + */ |
|
| 248 | + public function pedigreeCollapseByGenerationData(): array |
|
| 249 | + { |
|
| 250 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 251 | + |
|
| 252 | + $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
| 253 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 254 | + ->where('majs_user_id', '=', $this->user->id()); |
|
| 255 | + |
|
| 256 | + /* Compute the contributions of nodes of previous generations to the current generation */ |
|
| 257 | + $root_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
| 258 | + ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
| 259 | + ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
| 260 | + ->selectRaw( |
|
| 261 | + '(CASE ' . |
|
| 262 | + ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' . |
|
| 263 | + ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 264 | + ' ELSE 0 ' . |
|
| 265 | + ' END)' . |
|
| 266 | + ' + (CASE ' . |
|
| 267 | + ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' . |
|
| 268 | + ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 269 | + ' ELSE 0 ' . |
|
| 270 | + ' END) contrib' |
|
| 271 | + ) |
|
| 272 | + ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 273 | + $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen') |
|
| 274 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 275 | + ->where('majs_user_id', '=', $this->user->id()); |
|
| 276 | + }) |
|
| 277 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 278 | + // Link to sosa's father |
|
| 279 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 280 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 281 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 282 | + }) |
|
| 283 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 284 | + // Link to sosa's mother |
|
| 285 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 286 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 287 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 288 | + }) |
|
| 289 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 290 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 291 | + ->where(function (Builder $query): void { |
|
| 292 | + $query->whereNull('sosa_fat.majs_i_id') |
|
| 293 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 294 | + }); |
|
| 295 | + |
|
| 296 | + /* Identify nodes in the generations with ancestors who are also in the same generation. |
|
| 297 | 297 | * This is the vertical/generational collapse that will reduce the number or roots. |
| 298 | 298 | */ |
| 299 | - $non_roots_ancestors = DB::table('maj_sosa AS sosa') |
|
| 300 | - ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa']) |
|
| 301 | - ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' . |
|
| 302 | - ' AS full_ancestors') |
|
| 303 | - ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void { |
|
| 304 | - $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen') |
|
| 305 | - ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' . |
|
| 306 | - $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' . |
|
| 307 | - $table_prefix . 'sosa.majs_sosa') |
|
| 308 | - ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id()) |
|
| 309 | - ->where('sosa_anc.majs_user_id', '=', $this->user->id()); |
|
| 310 | - }) |
|
| 311 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 312 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 313 | - ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void { |
|
| 314 | - $query->from('maj_sosa AS sosa_gen') |
|
| 315 | - ->select('sosa_gen.majs_i_id')->distinct() |
|
| 316 | - ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id()) |
|
| 317 | - ->where('sosa_gen.majs_user_id', '=', $this->user->id()) |
|
| 318 | - ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen'); |
|
| 319 | - }) |
|
| 320 | - ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', |
|
| 321 | - 'sosa.majs_sosa', 'sosa.majs_i_id']); |
|
| 322 | - |
|
| 323 | - /* Compute the contribution of the nodes in the generation, |
|
| 299 | + $non_roots_ancestors = DB::table('maj_sosa AS sosa') |
|
| 300 | + ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa']) |
|
| 301 | + ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' . |
|
| 302 | + ' AS full_ancestors') |
|
| 303 | + ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void { |
|
| 304 | + $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen') |
|
| 305 | + ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' . |
|
| 306 | + $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' . |
|
| 307 | + $table_prefix . 'sosa.majs_sosa') |
|
| 308 | + ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id()) |
|
| 309 | + ->where('sosa_anc.majs_user_id', '=', $this->user->id()); |
|
| 310 | + }) |
|
| 311 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 312 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 313 | + ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void { |
|
| 314 | + $query->from('maj_sosa AS sosa_gen') |
|
| 315 | + ->select('sosa_gen.majs_i_id')->distinct() |
|
| 316 | + ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id()) |
|
| 317 | + ->where('sosa_gen.majs_user_id', '=', $this->user->id()) |
|
| 318 | + ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen'); |
|
| 319 | + }) |
|
| 320 | + ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', |
|
| 321 | + 'sosa.majs_sosa', 'sosa.majs_i_id']); |
|
| 322 | + |
|
| 323 | + /* Compute the contribution of the nodes in the generation, |
|
| 324 | 324 | * excluding the nodes with ancestors in the same generation. |
| 325 | 325 | * Nodes with a parent missing are not excluded to cater for the missing one. |
| 326 | 326 | */ |
| 327 | - $known_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
| 328 | - ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
| 329 | - ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
| 330 | - ->selectRaw('1 AS contrib') |
|
| 331 | - ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void { |
|
| 332 | - $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen') |
|
| 333 | - ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa') |
|
| 334 | - ->where('nonroot.full_ancestors', '>', 0) |
|
| 335 | - ->where('nonroot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 336 | - ->where('nonroot.majs_user_id', '=', $this->user->id()); |
|
| 337 | - }) |
|
| 338 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 339 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 340 | - ->whereNull('nonroot.majs_sosa'); |
|
| 341 | - |
|
| 342 | - /* Aggregate both queries, and calculate the sum of contributions by generation roots. |
|
| 327 | + $known_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
| 328 | + ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
| 329 | + ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
| 330 | + ->selectRaw('1 AS contrib') |
|
| 331 | + ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void { |
|
| 332 | + $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen') |
|
| 333 | + ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa') |
|
| 334 | + ->where('nonroot.full_ancestors', '>', 0) |
|
| 335 | + ->where('nonroot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 336 | + ->where('nonroot.majs_user_id', '=', $this->user->id()); |
|
| 337 | + }) |
|
| 338 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 339 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 340 | + ->whereNull('nonroot.majs_sosa'); |
|
| 341 | + |
|
| 342 | + /* Aggregate both queries, and calculate the sum of contributions by generation roots. |
|
| 343 | 343 | * Exclude as well nodes that already appear in lower generations, as their branche has already been reduced. |
| 344 | 344 | */ |
| 345 | - $ancestors_contributions_sum = DB::connection()->query() |
|
| 346 | - ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs') |
|
| 347 | - ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id']) |
|
| 348 | - ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib']) |
|
| 349 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' . |
|
| 350 | - $table_prefix . 'sosa_contribs.contrib AS totalContrib') |
|
| 351 | - ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void { |
|
| 352 | - $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen') |
|
| 353 | - ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id') |
|
| 354 | - ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id()) |
|
| 355 | - ->where('sosa_low.majs_user_id', '=', $this->user->id()); |
|
| 356 | - }) |
|
| 357 | - ->whereNull('sosa_low.majs_sosa') |
|
| 358 | - ->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id', |
|
| 359 | - 'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']); |
|
| 360 | - |
|
| 361 | - // Aggregate all generation roots to compute root and generation pedigree collapse |
|
| 362 | - $pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum') |
|
| 363 | - ->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)') |
|
| 364 | - ->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots') // Roots/horizontal collapse |
|
| 365 | - ->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse |
|
| 366 | - ->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id']) |
|
| 367 | - ->orderBy('gen') |
|
| 368 | - ->get(); |
|
| 369 | - |
|
| 370 | - $pedi_collapse_by_gen = []; |
|
| 371 | - foreach ($pedi_collapse_coll as $collapse_gen) { |
|
| 372 | - $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array( |
|
| 373 | - 'pedi_collapse_roots' => (float) $collapse_gen->pedi_collapse_roots, |
|
| 374 | - 'pedi_collapse_xgen' => (float) $collapse_gen->pedi_collapse_xgen |
|
| 375 | - ); |
|
| 376 | - } |
|
| 377 | - return $pedi_collapse_by_gen; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation. |
|
| 382 | - * Sosa 1 is of generation 1. |
|
| 383 | - * |
|
| 384 | - * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes, |
|
| 385 | - * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140 |
|
| 386 | - * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0 |
|
| 387 | - * |
|
| 388 | - * Format: |
|
| 389 | - * - key : sosa number of the ancestor |
|
| 390 | - * - values: |
|
| 391 | - * - root_ancestor_id : ID of the ancestor |
|
| 392 | - * - mean_gen_depth : Mean generation depth |
|
| 393 | - * - stddev_gen_depth : Standard deviation of generation depth |
|
| 394 | - * |
|
| 395 | - * @param int $gen Sosa generation |
|
| 396 | - * @return Collection<int, \stdClass> |
|
| 397 | - */ |
|
| 398 | - public function generationDepthStatsAtGeneration(int $gen): Collection |
|
| 399 | - { |
|
| 400 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 401 | - $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa') |
|
| 402 | - ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
| 403 | - ->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 |
|
| 404 | - ->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 |
|
| 405 | - ->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 |
|
| 406 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 407 | - // Link to sosa's father |
|
| 408 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 409 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 410 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 411 | - }) |
|
| 412 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 413 | - // Link to sosa's mother |
|
| 414 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 415 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 416 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 417 | - }) |
|
| 418 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 419 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 420 | - ->where('sosa.majs_gen', '>=', $gen) |
|
| 421 | - ->where(function (Builder $query): void { |
|
| 422 | - $query->whereNull('sosa_fat.majs_i_id') |
|
| 423 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 424 | - }) |
|
| 425 | - ->groupBy(['sosa.majs_gen', 'root_ancestor']); |
|
| 426 | - |
|
| 427 | - return DB::table('maj_sosa AS sosa_list') |
|
| 428 | - ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id']) |
|
| 429 | - ->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 |
|
| 430 | - ->selectRaw(' SQRT(' . |
|
| 431 | - ' 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 |
|
| 432 | - ' - 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 |
|
| 433 | - ' ) AS stddev_gen_depth') |
|
| 434 | - ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void { |
|
| 435 | - $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor') |
|
| 436 | - ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id()) |
|
| 437 | - ->where('sosa_list.majs_user_id', '=', $this->user->id()); |
|
| 438 | - }) |
|
| 439 | - ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id']) |
|
| 440 | - ->orderBy('stats_by_gen.root_ancestor') |
|
| 441 | - ->get()->keyBy('root_ancestor_sosa'); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - /** |
|
| 445 | - * Return a collection of the most duplicated root Sosa ancestors. |
|
| 446 | - * The number of ancestors to return is limited by the parameter $limit. |
|
| 447 | - * If several individuals are tied when reaching the limit, none of them are returned, |
|
| 448 | - * which means that there can be less individuals returned than requested. |
|
| 449 | - * |
|
| 450 | - * Format: |
|
| 451 | - * - value: |
|
| 452 | - * - sosa_i_id : sosa individual |
|
| 453 | - * - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
| 454 | - * |
|
| 455 | - * @param int $limit |
|
| 456 | - * @return Collection<\stdClass> |
|
| 457 | - */ |
|
| 458 | - public function topMultipleAncestorsWithNoTies(int $limit): Collection |
|
| 459 | - { |
|
| 460 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 461 | - $multiple_ancestors = DB::table('maj_sosa AS sosa') |
|
| 462 | - ->select('sosa.majs_i_id AS sosa_i_id') |
|
| 463 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count') |
|
| 464 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 465 | - // Link to sosa's father |
|
| 466 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 467 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 468 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 469 | - }) |
|
| 470 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 471 | - // Link to sosa's mother |
|
| 472 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 473 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 474 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 475 | - }) |
|
| 476 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 477 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 478 | - ->whereNull('sosa_fat.majs_sosa') // We keep only root individuals, i.e. those with no father or mother |
|
| 479 | - ->whereNull('sosa_mot.majs_sosa') |
|
| 480 | - ->groupBy('sosa.majs_i_id') |
|
| 481 | - ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
| 482 | - ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 483 | - ->limit($limit + 1) // We want to select one more than required, for ties |
|
| 484 | - ->get(); |
|
| 485 | - |
|
| 486 | - if ($multiple_ancestors->count() > $limit) { |
|
| 487 | - $last_count = $multiple_ancestors->last()->sosa_count; |
|
| 488 | - $multiple_ancestors = $multiple_ancestors->reject(function (stdClass $element) use ($last_count): bool { |
|
| 489 | - return $element->sosa_count == $last_count; |
|
| 490 | - }); |
|
| 491 | - } |
|
| 492 | - return $multiple_ancestors; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - /** |
|
| 496 | - * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
| 497 | - * at a specified generation. |
|
| 498 | - * |
|
| 499 | - * Format: |
|
| 500 | - * - key : rank of the ancestor in generation G for which exclusive ancestors have been found |
|
| 501 | - * For instance 3 represent the maternal grand father |
|
| 502 | - * 0 is used for shared ancestors |
|
| 503 | - * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
| 504 | - * |
|
| 505 | - * For instance a result at generation 3 could be : |
|
| 506 | - * array ( 0 => 12 -> 12 ancestors are shared by the grand-parents |
|
| 507 | - * 1 => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
| 508 | - * 2 => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
| 509 | - * 3 => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
| 510 | - * 4 => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
| 511 | - * ) |
|
| 512 | - * |
|
| 513 | - * @param int $gen |
|
| 514 | - * @return Collection<int, int> |
|
| 515 | - */ |
|
| 516 | - public function ancestorsDispersionForGeneration(int $gen): Collection |
|
| 517 | - { |
|
| 518 | - $ancestors_branches = DB::table('maj_sosa') |
|
| 519 | - ->select('majs_i_id AS i_id') |
|
| 520 | - ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen]) |
|
| 521 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 522 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 523 | - ->where('majs_gen', '>=', $gen) |
|
| 524 | - ->groupBy('majs_i_id', 'branch'); |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - $consolidated_ancestors_branches = DB::table('maj_sosa') |
|
| 528 | - ->fromSub($ancestors_branches, 'indi_branch') |
|
| 529 | - ->select('i_id') |
|
| 530 | - ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches') |
|
| 531 | - ->groupBy('i_id'); |
|
| 532 | - |
|
| 533 | - return DB::table('maj_sosa') |
|
| 534 | - ->fromSub($consolidated_ancestors_branches, 'indi_branch_consolidated') |
|
| 535 | - ->select('branches') |
|
| 536 | - ->selectRaw('COUNT(i_id) AS count_indi') |
|
| 537 | - ->groupBy('branches') |
|
| 538 | - ->get()->pluck('count_indi', 'branches'); |
|
| 539 | - } |
|
| 345 | + $ancestors_contributions_sum = DB::connection()->query() |
|
| 346 | + ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs') |
|
| 347 | + ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id']) |
|
| 348 | + ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib']) |
|
| 349 | + ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' . |
|
| 350 | + $table_prefix . 'sosa_contribs.contrib AS totalContrib') |
|
| 351 | + ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void { |
|
| 352 | + $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen') |
|
| 353 | + ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id') |
|
| 354 | + ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id()) |
|
| 355 | + ->where('sosa_low.majs_user_id', '=', $this->user->id()); |
|
| 356 | + }) |
|
| 357 | + ->whereNull('sosa_low.majs_sosa') |
|
| 358 | + ->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id', |
|
| 359 | + 'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']); |
|
| 360 | + |
|
| 361 | + // Aggregate all generation roots to compute root and generation pedigree collapse |
|
| 362 | + $pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum') |
|
| 363 | + ->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)') |
|
| 364 | + ->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots') // Roots/horizontal collapse |
|
| 365 | + ->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse |
|
| 366 | + ->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id']) |
|
| 367 | + ->orderBy('gen') |
|
| 368 | + ->get(); |
|
| 369 | + |
|
| 370 | + $pedi_collapse_by_gen = []; |
|
| 371 | + foreach ($pedi_collapse_coll as $collapse_gen) { |
|
| 372 | + $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array( |
|
| 373 | + 'pedi_collapse_roots' => (float) $collapse_gen->pedi_collapse_roots, |
|
| 374 | + 'pedi_collapse_xgen' => (float) $collapse_gen->pedi_collapse_xgen |
|
| 375 | + ); |
|
| 376 | + } |
|
| 377 | + return $pedi_collapse_by_gen; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation. |
|
| 382 | + * Sosa 1 is of generation 1. |
|
| 383 | + * |
|
| 384 | + * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes, |
|
| 385 | + * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140 |
|
| 386 | + * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0 |
|
| 387 | + * |
|
| 388 | + * Format: |
|
| 389 | + * - key : sosa number of the ancestor |
|
| 390 | + * - values: |
|
| 391 | + * - root_ancestor_id : ID of the ancestor |
|
| 392 | + * - mean_gen_depth : Mean generation depth |
|
| 393 | + * - stddev_gen_depth : Standard deviation of generation depth |
|
| 394 | + * |
|
| 395 | + * @param int $gen Sosa generation |
|
| 396 | + * @return Collection<int, \stdClass> |
|
| 397 | + */ |
|
| 398 | + public function generationDepthStatsAtGeneration(int $gen): Collection |
|
| 399 | + { |
|
| 400 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 401 | + $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa') |
|
| 402 | + ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
| 403 | + ->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 |
|
| 404 | + ->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 |
|
| 405 | + ->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 |
|
| 406 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 407 | + // Link to sosa's father |
|
| 408 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 409 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 410 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 411 | + }) |
|
| 412 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 413 | + // Link to sosa's mother |
|
| 414 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 415 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 416 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 417 | + }) |
|
| 418 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 419 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 420 | + ->where('sosa.majs_gen', '>=', $gen) |
|
| 421 | + ->where(function (Builder $query): void { |
|
| 422 | + $query->whereNull('sosa_fat.majs_i_id') |
|
| 423 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 424 | + }) |
|
| 425 | + ->groupBy(['sosa.majs_gen', 'root_ancestor']); |
|
| 426 | + |
|
| 427 | + return DB::table('maj_sosa AS sosa_list') |
|
| 428 | + ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id']) |
|
| 429 | + ->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 |
|
| 430 | + ->selectRaw(' SQRT(' . |
|
| 431 | + ' 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 |
|
| 432 | + ' - 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 |
|
| 433 | + ' ) AS stddev_gen_depth') |
|
| 434 | + ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void { |
|
| 435 | + $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor') |
|
| 436 | + ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id()) |
|
| 437 | + ->where('sosa_list.majs_user_id', '=', $this->user->id()); |
|
| 438 | + }) |
|
| 439 | + ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id']) |
|
| 440 | + ->orderBy('stats_by_gen.root_ancestor') |
|
| 441 | + ->get()->keyBy('root_ancestor_sosa'); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + /** |
|
| 445 | + * Return a collection of the most duplicated root Sosa ancestors. |
|
| 446 | + * The number of ancestors to return is limited by the parameter $limit. |
|
| 447 | + * If several individuals are tied when reaching the limit, none of them are returned, |
|
| 448 | + * which means that there can be less individuals returned than requested. |
|
| 449 | + * |
|
| 450 | + * Format: |
|
| 451 | + * - value: |
|
| 452 | + * - sosa_i_id : sosa individual |
|
| 453 | + * - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
| 454 | + * |
|
| 455 | + * @param int $limit |
|
| 456 | + * @return Collection<\stdClass> |
|
| 457 | + */ |
|
| 458 | + public function topMultipleAncestorsWithNoTies(int $limit): Collection |
|
| 459 | + { |
|
| 460 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 461 | + $multiple_ancestors = DB::table('maj_sosa AS sosa') |
|
| 462 | + ->select('sosa.majs_i_id AS sosa_i_id') |
|
| 463 | + ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count') |
|
| 464 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 465 | + // Link to sosa's father |
|
| 466 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 467 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 468 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 469 | + }) |
|
| 470 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 471 | + // Link to sosa's mother |
|
| 472 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 473 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 474 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 475 | + }) |
|
| 476 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 477 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 478 | + ->whereNull('sosa_fat.majs_sosa') // We keep only root individuals, i.e. those with no father or mother |
|
| 479 | + ->whereNull('sosa_mot.majs_sosa') |
|
| 480 | + ->groupBy('sosa.majs_i_id') |
|
| 481 | + ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
| 482 | + ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 483 | + ->limit($limit + 1) // We want to select one more than required, for ties |
|
| 484 | + ->get(); |
|
| 485 | + |
|
| 486 | + if ($multiple_ancestors->count() > $limit) { |
|
| 487 | + $last_count = $multiple_ancestors->last()->sosa_count; |
|
| 488 | + $multiple_ancestors = $multiple_ancestors->reject(function (stdClass $element) use ($last_count): bool { |
|
| 489 | + return $element->sosa_count == $last_count; |
|
| 490 | + }); |
|
| 491 | + } |
|
| 492 | + return $multiple_ancestors; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + /** |
|
| 496 | + * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
| 497 | + * at a specified generation. |
|
| 498 | + * |
|
| 499 | + * Format: |
|
| 500 | + * - key : rank of the ancestor in generation G for which exclusive ancestors have been found |
|
| 501 | + * For instance 3 represent the maternal grand father |
|
| 502 | + * 0 is used for shared ancestors |
|
| 503 | + * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
| 504 | + * |
|
| 505 | + * For instance a result at generation 3 could be : |
|
| 506 | + * array ( 0 => 12 -> 12 ancestors are shared by the grand-parents |
|
| 507 | + * 1 => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
| 508 | + * 2 => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
| 509 | + * 3 => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
| 510 | + * 4 => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
| 511 | + * ) |
|
| 512 | + * |
|
| 513 | + * @param int $gen |
|
| 514 | + * @return Collection<int, int> |
|
| 515 | + */ |
|
| 516 | + public function ancestorsDispersionForGeneration(int $gen): Collection |
|
| 517 | + { |
|
| 518 | + $ancestors_branches = DB::table('maj_sosa') |
|
| 519 | + ->select('majs_i_id AS i_id') |
|
| 520 | + ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen]) |
|
| 521 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 522 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 523 | + ->where('majs_gen', '>=', $gen) |
|
| 524 | + ->groupBy('majs_i_id', 'branch'); |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + $consolidated_ancestors_branches = DB::table('maj_sosa') |
|
| 528 | + ->fromSub($ancestors_branches, 'indi_branch') |
|
| 529 | + ->select('i_id') |
|
| 530 | + ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches') |
|
| 531 | + ->groupBy('i_id'); |
|
| 532 | + |
|
| 533 | + return DB::table('maj_sosa') |
|
| 534 | + ->fromSub($consolidated_ancestors_branches, 'indi_branch_consolidated') |
|
| 535 | + ->select('branches') |
|
| 536 | + ->selectRaw('COUNT(i_id) AS count_indi') |
|
| 537 | + ->groupBy('branches') |
|
| 538 | + ->get()->pluck('count_indi', 'branches'); |
|
| 539 | + } |
|
| 540 | 540 | } |
@@ -31,101 +31,101 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class SosaByGenerationGeoAnalysis implements GeoAnalysisInterface |
| 33 | 33 | { |
| 34 | - private SosaRecordsService $records_service; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Constructor for SosaByGenerationGeoAnalysis |
|
| 38 | - * |
|
| 39 | - * @param SosaRecordsService $records_service |
|
| 40 | - */ |
|
| 41 | - public function __construct(SosaRecordsService $records_service) |
|
| 42 | - { |
|
| 43 | - $this->records_service = $records_service; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * {@inheritDoc} |
|
| 48 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
| 49 | - */ |
|
| 50 | - public function title(): string |
|
| 51 | - { |
|
| 52 | - return I18N::translate('Sosa ancestors places by generation'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * {@inheritDoc} |
|
| 57 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
| 58 | - */ |
|
| 59 | - public function itemsDescription(): callable |
|
| 60 | - { |
|
| 61 | - return fn(int $count): string => I18N::plural('ancestor', 'ancestors', $count); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * {@inheritDoc} |
|
| 66 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
| 67 | - */ |
|
| 68 | - public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
| 69 | - { |
|
| 70 | - $results = new GeoAnalysisResults(); |
|
| 71 | - |
|
| 72 | - $unique_ancestors = $this->records_service |
|
| 73 | - ->listAncestors($tree, Auth::user()) |
|
| 74 | - ->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id); |
|
| 75 | - |
|
| 76 | - foreach ($unique_ancestors as $item) { |
|
| 77 | - $ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree); |
|
| 78 | - if ($ancestor === null || !$ancestor->canShow()) { |
|
| 79 | - continue; |
|
| 80 | - } |
|
| 81 | - $generation = $this->records_service->generation((int) $item->majs_sosa); |
|
| 82 | - $significantplace = new GeoAnalysisPlace($tree, null, $depth); |
|
| 83 | - foreach ($this->significantPlaces($ancestor) as $place) { |
|
| 84 | - $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true); |
|
| 85 | - if ($significantplace->isKnown()) { |
|
| 86 | - break; |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - $results->addPlace($significantplace); |
|
| 90 | - $results->addPlaceInCategory( |
|
| 91 | - I18N::translate('Generation %s', I18N::number($generation)), |
|
| 92 | - $generation, |
|
| 93 | - $significantplace |
|
| 94 | - ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $results; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Returns significant places in order of priority for an individual |
|
| 102 | - * |
|
| 103 | - * @param Individual $individual |
|
| 104 | - * @return Generator<\Fisharebest\Webtrees\Place> |
|
| 105 | - */ |
|
| 106 | - protected function significantPlaces(Individual $individual): Generator |
|
| 107 | - { |
|
| 108 | - yield $individual->getBirthPlace(); |
|
| 109 | - |
|
| 110 | - /** @var \Fisharebest\Webtrees\Fact $fact */ |
|
| 111 | - foreach ($individual->facts(['RESI']) as $fact) { |
|
| 112 | - yield $fact->place(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - yield $individual->getDeathPlace(); |
|
| 116 | - |
|
| 117 | - /** @var \Fisharebest\Webtrees\Family $family */ |
|
| 118 | - foreach ($individual->childFamilies() as $family) { |
|
| 119 | - foreach ($family->facts(['RESI']) as $fact) { |
|
| 120 | - yield $fact->place(); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** @var \Fisharebest\Webtrees\Family $family */ |
|
| 125 | - foreach ($individual->spouseFamilies() as $family) { |
|
| 126 | - foreach ($family->facts(['RESI']) as $fact) { |
|
| 127 | - yield $fact->place(); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 34 | + private SosaRecordsService $records_service; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Constructor for SosaByGenerationGeoAnalysis |
|
| 38 | + * |
|
| 39 | + * @param SosaRecordsService $records_service |
|
| 40 | + */ |
|
| 41 | + public function __construct(SosaRecordsService $records_service) |
|
| 42 | + { |
|
| 43 | + $this->records_service = $records_service; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * {@inheritDoc} |
|
| 48 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
| 49 | + */ |
|
| 50 | + public function title(): string |
|
| 51 | + { |
|
| 52 | + return I18N::translate('Sosa ancestors places by generation'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * {@inheritDoc} |
|
| 57 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
| 58 | + */ |
|
| 59 | + public function itemsDescription(): callable |
|
| 60 | + { |
|
| 61 | + return fn(int $count): string => I18N::plural('ancestor', 'ancestors', $count); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * {@inheritDoc} |
|
| 66 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
| 67 | + */ |
|
| 68 | + public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
| 69 | + { |
|
| 70 | + $results = new GeoAnalysisResults(); |
|
| 71 | + |
|
| 72 | + $unique_ancestors = $this->records_service |
|
| 73 | + ->listAncestors($tree, Auth::user()) |
|
| 74 | + ->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id); |
|
| 75 | + |
|
| 76 | + foreach ($unique_ancestors as $item) { |
|
| 77 | + $ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree); |
|
| 78 | + if ($ancestor === null || !$ancestor->canShow()) { |
|
| 79 | + continue; |
|
| 80 | + } |
|
| 81 | + $generation = $this->records_service->generation((int) $item->majs_sosa); |
|
| 82 | + $significantplace = new GeoAnalysisPlace($tree, null, $depth); |
|
| 83 | + foreach ($this->significantPlaces($ancestor) as $place) { |
|
| 84 | + $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true); |
|
| 85 | + if ($significantplace->isKnown()) { |
|
| 86 | + break; |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + $results->addPlace($significantplace); |
|
| 90 | + $results->addPlaceInCategory( |
|
| 91 | + I18N::translate('Generation %s', I18N::number($generation)), |
|
| 92 | + $generation, |
|
| 93 | + $significantplace |
|
| 94 | + ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $results; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Returns significant places in order of priority for an individual |
|
| 102 | + * |
|
| 103 | + * @param Individual $individual |
|
| 104 | + * @return Generator<\Fisharebest\Webtrees\Place> |
|
| 105 | + */ |
|
| 106 | + protected function significantPlaces(Individual $individual): Generator |
|
| 107 | + { |
|
| 108 | + yield $individual->getBirthPlace(); |
|
| 109 | + |
|
| 110 | + /** @var \Fisharebest\Webtrees\Fact $fact */ |
|
| 111 | + foreach ($individual->facts(['RESI']) as $fact) { |
|
| 112 | + yield $fact->place(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + yield $individual->getDeathPlace(); |
|
| 116 | + |
|
| 117 | + /** @var \Fisharebest\Webtrees\Family $family */ |
|
| 118 | + foreach ($individual->childFamilies() as $family) { |
|
| 119 | + foreach ($family->facts(['RESI']) as $fact) { |
|
| 120 | + yield $fact->place(); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** @var \Fisharebest\Webtrees\Family $family */ |
|
| 125 | + foreach ($individual->spouseFamilies() as $family) { |
|
| 126 | + foreach ($family->facts(['RESI']) as $fact) { |
|
| 127 | + yield $fact->place(); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | 131 | } |
@@ -59,186 +59,186 @@ |
||
| 59 | 59 | * Geographical Dispersion Module. |
| 60 | 60 | */ |
| 61 | 61 | class GeoDispersionModule extends AbstractModule implements |
| 62 | - ModuleMyArtJaubInterface, |
|
| 63 | - ModuleChartInterface, |
|
| 64 | - ModuleConfigInterface, |
|
| 65 | - ModuleGlobalInterface, |
|
| 66 | - ModuleGeoAnalysisProviderInterface, |
|
| 67 | - ModulePlaceMapperProviderInterface |
|
| 62 | + ModuleMyArtJaubInterface, |
|
| 63 | + ModuleChartInterface, |
|
| 64 | + ModuleConfigInterface, |
|
| 65 | + ModuleGlobalInterface, |
|
| 66 | + ModuleGeoAnalysisProviderInterface, |
|
| 67 | + ModulePlaceMapperProviderInterface |
|
| 68 | 68 | { |
| 69 | - use ModuleMyArtJaubTrait { |
|
| 70 | - boot as traitBoot; |
|
| 71 | - } |
|
| 72 | - use ModuleChartTrait; |
|
| 73 | - use ModuleConfigTrait; |
|
| 74 | - use ModuleGlobalTrait; |
|
| 75 | - |
|
| 76 | - // How to update the database schema for this module |
|
| 77 | - private const SCHEMA_TARGET_VERSION = 3; |
|
| 78 | - private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
|
| 79 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * {@inheritDoc} |
|
| 83 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 84 | - */ |
|
| 85 | - public function title(): string |
|
| 86 | - { |
|
| 87 | - return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * {@inheritDoc} |
|
| 92 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 93 | - */ |
|
| 94 | - public function description(): string |
|
| 95 | - { |
|
| 96 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 97 | - return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * {@inheritDoc} |
|
| 102 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 103 | - */ |
|
| 104 | - public function boot(): void |
|
| 105 | - { |
|
| 106 | - $this->traitBoot(); |
|
| 107 | - app(MigrationService::class)->updateSchema( |
|
| 108 | - self::SCHEMA_MIGRATION_PREFIX, |
|
| 109 | - self::SCHEMA_SETTING_NAME, |
|
| 110 | - self::SCHEMA_TARGET_VERSION |
|
| 111 | - ); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * {@inheritDoc} |
|
| 116 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 117 | - */ |
|
| 118 | - public function customModuleVersion(): string |
|
| 119 | - { |
|
| 120 | - return '2.1.0-v.1'; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * {@inheritDoc} |
|
| 125 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 126 | - */ |
|
| 127 | - public function loadRoutes(Map $router): void |
|
| 128 | - { |
|
| 129 | - $router->attach('', '', static function (Map $router): void { |
|
| 130 | - |
|
| 131 | - $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
| 132 | - $router->attach('', '/admin', static function (Map $router): void { |
|
| 133 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
| 134 | - |
|
| 135 | - $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
| 136 | - $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
|
| 137 | - $router->extras([ |
|
| 138 | - 'middleware' => [ |
|
| 139 | - AuthManager::class, |
|
| 140 | - ], |
|
| 141 | - ]); |
|
| 142 | - $router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class); |
|
| 143 | - |
|
| 144 | - $router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class); |
|
| 145 | - $router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class); |
|
| 146 | - $router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class); |
|
| 147 | - $router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class); |
|
| 148 | - //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 149 | - $router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class); |
|
| 150 | - $router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class); |
|
| 151 | - //phpcs:enable |
|
| 152 | - }); |
|
| 153 | - |
|
| 154 | - $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
| 155 | - $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
|
| 156 | - $router->extras([ |
|
| 157 | - 'middleware' => [ |
|
| 158 | - AuthManager::class, |
|
| 159 | - ], |
|
| 160 | - ]); |
|
| 161 | - |
|
| 162 | - $router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class); |
|
| 163 | - $router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class); |
|
| 164 | - $router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class); |
|
| 165 | - $router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class); |
|
| 166 | - //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 167 | - $router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class); |
|
| 168 | - $router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class); |
|
| 169 | - $router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class); |
|
| 170 | - //phpcs:enable |
|
| 171 | - }); |
|
| 172 | - |
|
| 173 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 174 | - $router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class); |
|
| 175 | - }); |
|
| 176 | - |
|
| 177 | - $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
|
| 178 | - |
|
| 179 | - $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
| 180 | - $router->tokens(['view_id' => '\d+']); |
|
| 181 | - $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
|
| 182 | - $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
|
| 183 | - }); |
|
| 184 | - }); |
|
| 185 | - }); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - public function getConfigLink(): string |
|
| 189 | - { |
|
| 190 | - return route(AdminConfigPage::class); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * {@inheritDoc} |
|
| 195 | - * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl() |
|
| 196 | - */ |
|
| 197 | - public function chartUrl(Individual $individual, array $parameters = []): string |
|
| 198 | - { |
|
| 199 | - return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * {@inheritDoc} |
|
| 204 | - * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass() |
|
| 205 | - */ |
|
| 206 | - public function chartMenuClass(): string |
|
| 207 | - { |
|
| 208 | - return 'menu-maj-geodispersion'; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * {@inheritDoc} |
|
| 213 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
| 214 | - */ |
|
| 215 | - public function headContent(): string |
|
| 216 | - { |
|
| 217 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * {@inheritDoc} |
|
| 222 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers() |
|
| 223 | - */ |
|
| 224 | - public function listPlaceMappers(): array |
|
| 225 | - { |
|
| 226 | - return [ |
|
| 227 | - CoordinatesPlaceMapper::class, |
|
| 228 | - SimplePlaceMapper::class, |
|
| 229 | - SimpleTopFilteredPlaceMapper::class |
|
| 230 | - ]; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * {@inheritDoc} |
|
| 235 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
| 236 | - */ |
|
| 237 | - public function listGeoAnalyses(): array |
|
| 238 | - { |
|
| 239 | - return [ |
|
| 240 | - AllEventsByCenturyGeoAnalysis::class, |
|
| 241 | - AllEventsByTypeGeoAnalysis::class |
|
| 242 | - ]; |
|
| 243 | - } |
|
| 69 | + use ModuleMyArtJaubTrait { |
|
| 70 | + boot as traitBoot; |
|
| 71 | + } |
|
| 72 | + use ModuleChartTrait; |
|
| 73 | + use ModuleConfigTrait; |
|
| 74 | + use ModuleGlobalTrait; |
|
| 75 | + |
|
| 76 | + // How to update the database schema for this module |
|
| 77 | + private const SCHEMA_TARGET_VERSION = 3; |
|
| 78 | + private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
|
| 79 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * {@inheritDoc} |
|
| 83 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 84 | + */ |
|
| 85 | + public function title(): string |
|
| 86 | + { |
|
| 87 | + return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * {@inheritDoc} |
|
| 92 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 93 | + */ |
|
| 94 | + public function description(): string |
|
| 95 | + { |
|
| 96 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 97 | + return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * {@inheritDoc} |
|
| 102 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 103 | + */ |
|
| 104 | + public function boot(): void |
|
| 105 | + { |
|
| 106 | + $this->traitBoot(); |
|
| 107 | + app(MigrationService::class)->updateSchema( |
|
| 108 | + self::SCHEMA_MIGRATION_PREFIX, |
|
| 109 | + self::SCHEMA_SETTING_NAME, |
|
| 110 | + self::SCHEMA_TARGET_VERSION |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * {@inheritDoc} |
|
| 116 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 117 | + */ |
|
| 118 | + public function customModuleVersion(): string |
|
| 119 | + { |
|
| 120 | + return '2.1.0-v.1'; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * {@inheritDoc} |
|
| 125 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 126 | + */ |
|
| 127 | + public function loadRoutes(Map $router): void |
|
| 128 | + { |
|
| 129 | + $router->attach('', '', static function (Map $router): void { |
|
| 130 | + |
|
| 131 | + $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
| 132 | + $router->attach('', '/admin', static function (Map $router): void { |
|
| 133 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
| 134 | + |
|
| 135 | + $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
| 136 | + $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
|
| 137 | + $router->extras([ |
|
| 138 | + 'middleware' => [ |
|
| 139 | + AuthManager::class, |
|
| 140 | + ], |
|
| 141 | + ]); |
|
| 142 | + $router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class); |
|
| 143 | + |
|
| 144 | + $router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class); |
|
| 145 | + $router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class); |
|
| 146 | + $router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class); |
|
| 147 | + $router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class); |
|
| 148 | + //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 149 | + $router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class); |
|
| 150 | + $router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class); |
|
| 151 | + //phpcs:enable |
|
| 152 | + }); |
|
| 153 | + |
|
| 154 | + $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
| 155 | + $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
|
| 156 | + $router->extras([ |
|
| 157 | + 'middleware' => [ |
|
| 158 | + AuthManager::class, |
|
| 159 | + ], |
|
| 160 | + ]); |
|
| 161 | + |
|
| 162 | + $router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class); |
|
| 163 | + $router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class); |
|
| 164 | + $router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class); |
|
| 165 | + $router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class); |
|
| 166 | + //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 167 | + $router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class); |
|
| 168 | + $router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class); |
|
| 169 | + $router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class); |
|
| 170 | + //phpcs:enable |
|
| 171 | + }); |
|
| 172 | + |
|
| 173 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 174 | + $router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class); |
|
| 175 | + }); |
|
| 176 | + |
|
| 177 | + $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
|
| 178 | + |
|
| 179 | + $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
| 180 | + $router->tokens(['view_id' => '\d+']); |
|
| 181 | + $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
|
| 182 | + $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
|
| 183 | + }); |
|
| 184 | + }); |
|
| 185 | + }); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + public function getConfigLink(): string |
|
| 189 | + { |
|
| 190 | + return route(AdminConfigPage::class); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * {@inheritDoc} |
|
| 195 | + * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl() |
|
| 196 | + */ |
|
| 197 | + public function chartUrl(Individual $individual, array $parameters = []): string |
|
| 198 | + { |
|
| 199 | + return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * {@inheritDoc} |
|
| 204 | + * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass() |
|
| 205 | + */ |
|
| 206 | + public function chartMenuClass(): string |
|
| 207 | + { |
|
| 208 | + return 'menu-maj-geodispersion'; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * {@inheritDoc} |
|
| 213 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
| 214 | + */ |
|
| 215 | + public function headContent(): string |
|
| 216 | + { |
|
| 217 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * {@inheritDoc} |
|
| 222 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers() |
|
| 223 | + */ |
|
| 224 | + public function listPlaceMappers(): array |
|
| 225 | + { |
|
| 226 | + return [ |
|
| 227 | + CoordinatesPlaceMapper::class, |
|
| 228 | + SimplePlaceMapper::class, |
|
| 229 | + SimpleTopFilteredPlaceMapper::class |
|
| 230 | + ]; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * {@inheritDoc} |
|
| 235 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
| 236 | + */ |
|
| 237 | + public function listGeoAnalyses(): array |
|
| 238 | + { |
|
| 239 | + return [ |
|
| 240 | + AllEventsByCenturyGeoAnalysis::class, |
|
| 241 | + AllEventsByTypeGeoAnalysis::class |
|
| 242 | + ]; |
|
| 243 | + } |
|
| 244 | 244 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | // How to update the database schema for this module |
| 77 | 77 | private const SCHEMA_TARGET_VERSION = 3; |
| 78 | 78 | private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
| 79 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 79 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema'; |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * {@inheritDoc} |
@@ -126,13 +126,13 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function loadRoutes(Map $router): void |
| 128 | 128 | { |
| 129 | - $router->attach('', '', static function (Map $router): void { |
|
| 129 | + $router->attach('', '', static function(Map $router): void { |
|
| 130 | 130 | |
| 131 | - $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
| 132 | - $router->attach('', '/admin', static function (Map $router): void { |
|
| 131 | + $router->attach('', '/module-maj/geodispersion', static function(Map $router): void { |
|
| 132 | + $router->attach('', '/admin', static function(Map $router): void { |
|
| 133 | 133 | $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
| 134 | 134 | |
| 135 | - $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
| 135 | + $router->attach('', '/analysis-views/{tree}', static function(Map $router): void { |
|
| 136 | 136 | $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
| 137 | 137 | $router->extras([ |
| 138 | 138 | 'middleware' => [ |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | //phpcs:enable |
| 152 | 152 | }); |
| 153 | 153 | |
| 154 | - $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
| 154 | + $router->attach('', '/map-adapters/{tree}', static function(Map $router): void { |
|
| 155 | 155 | $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
| 156 | 156 | $router->extras([ |
| 157 | 157 | 'middleware' => [ |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
| 178 | 178 | |
| 179 | - $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
| 179 | + $router->attach('', '/analysisview/{tree}/{view_id}', static function(Map $router): void { |
|
| 180 | 180 | $router->tokens(['view_id' => '\d+']); |
| 181 | 181 | $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
| 182 | 182 | $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function headContent(): string |
| 216 | 216 | { |
| 217 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 217 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -38,64 +38,64 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class GeoAnalysisViewEditPage implements RequestHandlerInterface |
| 40 | 40 | { |
| 41 | - use ViewResponseTrait; |
|
| 41 | + use ViewResponseTrait; |
|
| 42 | 42 | |
| 43 | - private ?GeoDispersionModule $module; |
|
| 44 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
| 45 | - private GeoAnalysisService $geoanalysis_service; |
|
| 46 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
| 43 | + private ?GeoDispersionModule $module; |
|
| 44 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
| 45 | + private GeoAnalysisService $geoanalysis_service; |
|
| 46 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Constructor for GeoAnalysisViewEditPage Request Handler |
|
| 50 | - * |
|
| 51 | - * @param ModuleService $module_service |
|
| 52 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 53 | - * @param GeoAnalysisService $geoanalysis_service |
|
| 54 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
| 55 | - */ |
|
| 56 | - public function __construct( |
|
| 57 | - ModuleService $module_service, |
|
| 58 | - GeoAnalysisViewDataService $geoview_data_service, |
|
| 59 | - GeoAnalysisService $geoanalysis_service, |
|
| 60 | - GeoAnalysisDataService $geoanalysis_data_service |
|
| 61 | - ) { |
|
| 62 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 63 | - $this->geoview_data_service = $geoview_data_service; |
|
| 64 | - $this->geoanalysis_service = $geoanalysis_service; |
|
| 65 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
| 66 | - } |
|
| 48 | + /** |
|
| 49 | + * Constructor for GeoAnalysisViewEditPage Request Handler |
|
| 50 | + * |
|
| 51 | + * @param ModuleService $module_service |
|
| 52 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 53 | + * @param GeoAnalysisService $geoanalysis_service |
|
| 54 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
| 55 | + */ |
|
| 56 | + public function __construct( |
|
| 57 | + ModuleService $module_service, |
|
| 58 | + GeoAnalysisViewDataService $geoview_data_service, |
|
| 59 | + GeoAnalysisService $geoanalysis_service, |
|
| 60 | + GeoAnalysisDataService $geoanalysis_data_service |
|
| 61 | + ) { |
|
| 62 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 63 | + $this->geoview_data_service = $geoview_data_service; |
|
| 64 | + $this->geoanalysis_service = $geoanalysis_service; |
|
| 65 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * {@inheritDoc} |
|
| 70 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 71 | - */ |
|
| 72 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 73 | - { |
|
| 74 | - $this->layout = 'layouts/administration'; |
|
| 68 | + /** |
|
| 69 | + * {@inheritDoc} |
|
| 70 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 71 | + */ |
|
| 72 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 73 | + { |
|
| 74 | + $this->layout = 'layouts/administration'; |
|
| 75 | 75 | |
| 76 | - if ($this->module === null) { |
|
| 77 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 78 | - } |
|
| 79 | - $tree = $request->getAttribute('tree'); |
|
| 80 | - assert($tree instanceof Tree); |
|
| 76 | + if ($this->module === null) { |
|
| 77 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 78 | + } |
|
| 79 | + $tree = $request->getAttribute('tree'); |
|
| 80 | + assert($tree instanceof Tree); |
|
| 81 | 81 | |
| 82 | - $view_id = (int) $request->getAttribute('view_id'); |
|
| 83 | - $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
| 82 | + $view_id = (int) $request->getAttribute('view_id'); |
|
| 83 | + $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
| 84 | 84 | |
| 85 | - if ($view === null) { |
|
| 86 | - throw new HttpNotFoundException( |
|
| 87 | - I18N::translate('The geographical dispersion analysis view could not be found.') |
|
| 88 | - ); |
|
| 89 | - } |
|
| 85 | + if ($view === null) { |
|
| 86 | + throw new HttpNotFoundException( |
|
| 87 | + I18N::translate('The geographical dispersion analysis view could not be found.') |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 92 | - 'module' => $this->module, |
|
| 93 | - 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
|
| 94 | - 'tree' => $tree, |
|
| 95 | - 'view' => $view, |
|
| 96 | - 'geoanalysis_list' => $this->geoanalysis_service->all(), |
|
| 97 | - 'place_example' => $this->geoanalysis_data_service->placeHierarchyExample($tree), |
|
| 98 | - 'global_settings' => $view->globalSettingsContent($this->module) |
|
| 99 | - ]); |
|
| 100 | - } |
|
| 91 | + return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 92 | + 'module' => $this->module, |
|
| 93 | + 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
|
| 94 | + 'tree' => $tree, |
|
| 95 | + 'view' => $view, |
|
| 96 | + 'geoanalysis_list' => $this->geoanalysis_service->all(), |
|
| 97 | + 'place_example' => $this->geoanalysis_data_service->placeHierarchyExample($tree), |
|
| 98 | + 'global_settings' => $view->globalSettingsContent($this->module) |
|
| 99 | + ]); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $tree = $request->getAttribute('tree'); |
| 80 | 80 | assert($tree instanceof Tree); |
| 81 | 81 | |
| 82 | - $view_id = (int) $request->getAttribute('view_id'); |
|
| 82 | + $view_id = (int)$request->getAttribute('view_id'); |
|
| 83 | 83 | $view = $this->geoview_data_service->find($tree, $view_id, true); |
| 84 | 84 | |
| 85 | 85 | if ($view === null) { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 91 | + return $this->viewResponse($this->module->name().'::admin/view-edit', [ |
|
| 92 | 92 | 'module' => $this->module, |
| 93 | 93 | 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
| 94 | 94 | 'tree' => $tree, |