@@ -31,54 +31,54 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class SosaComputeAction implements RequestHandlerInterface |
| 33 | 33 | { |
| 34 | - private UserService $user_service; |
|
| 34 | + private UserService $user_service; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Constructor for SosaConfigAction Request Handler |
|
| 38 | - * |
|
| 39 | - * @param UserService $user_service |
|
| 40 | - */ |
|
| 41 | - public function __construct(UserService $user_service) |
|
| 42 | - { |
|
| 43 | - $this->user_service = $user_service; |
|
| 44 | - } |
|
| 36 | + /** |
|
| 37 | + * Constructor for SosaConfigAction Request Handler |
|
| 38 | + * |
|
| 39 | + * @param UserService $user_service |
|
| 40 | + */ |
|
| 41 | + public function __construct(UserService $user_service) |
|
| 42 | + { |
|
| 43 | + $this->user_service = $user_service; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * {@inheritDoc} |
|
| 48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 49 | - */ |
|
| 50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 51 | - { |
|
| 52 | - $tree = Validator::attributes($request)->tree(); |
|
| 46 | + /** |
|
| 47 | + * {@inheritDoc} |
|
| 48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 49 | + */ |
|
| 50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 51 | + { |
|
| 52 | + $tree = Validator::attributes($request)->tree(); |
|
| 53 | 53 | |
| 54 | - $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
|
| 55 | - $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
|
| 54 | + $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
|
| 55 | + $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
|
| 56 | 56 | |
| 57 | - if (($user_id === -1 && Auth::isManager($tree)) || Auth::id() === $user_id) { |
|
| 58 | - $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 57 | + if (($user_id === -1 && Auth::isManager($tree)) || Auth::id() === $user_id) { |
|
| 58 | + $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 59 | 59 | |
| 60 | - /** @var SosaCalculatorService $sosa_calc_service */ |
|
| 61 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
| 60 | + /** @var SosaCalculatorService $sosa_calc_service */ |
|
| 61 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
| 62 | 62 | |
| 63 | - if ( |
|
| 64 | - $partial_from !== '' && |
|
| 65 | - ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
| 66 | - ) { |
|
| 67 | - $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
| 68 | - } else { |
|
| 69 | - $res = $sosa_calc_service->computeAll(); |
|
| 70 | - } |
|
| 63 | + if ( |
|
| 64 | + $partial_from !== '' && |
|
| 65 | + ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
| 66 | + ) { |
|
| 67 | + $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
| 68 | + } else { |
|
| 69 | + $res = $sosa_calc_service->computeAll(); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $res ? |
|
| 73 | - Registry::responseFactory()->response() : |
|
| 74 | - Registry::responseFactory()->response( |
|
| 75 | - I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
| 76 | - StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - return Registry::responseFactory()->response( |
|
| 80 | - I18N::translate('You do not have permission to modify the user.'), |
|
| 81 | - StatusCodeInterface::STATUS_FORBIDDEN |
|
| 82 | - ); |
|
| 83 | - } |
|
| 72 | + return $res ? |
|
| 73 | + Registry::responseFactory()->response() : |
|
| 74 | + Registry::responseFactory()->response( |
|
| 75 | + I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
| 76 | + StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + return Registry::responseFactory()->response( |
|
| 80 | + I18N::translate('You do not have permission to modify the user.'), |
|
| 81 | + StatusCodeInterface::STATUS_FORBIDDEN |
|
| 82 | + ); |
|
| 83 | + } |
|
| 84 | 84 | } |
@@ -33,71 +33,71 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class SosaConfig implements RequestHandlerInterface |
| 35 | 35 | { |
| 36 | - use ViewResponseTrait; |
|
| 36 | + use ViewResponseTrait; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var SosaModule|null $module |
|
| 40 | - */ |
|
| 41 | - private $module; |
|
| 38 | + /** |
|
| 39 | + * @var SosaModule|null $module |
|
| 40 | + */ |
|
| 41 | + private $module; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Constructor for SosaConfig Request Handler |
|
| 45 | - * |
|
| 46 | - * @param ModuleService $module_service |
|
| 47 | - */ |
|
| 48 | - public function __construct(ModuleService $module_service) |
|
| 49 | - { |
|
| 50 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * Constructor for SosaConfig Request Handler |
|
| 45 | + * |
|
| 46 | + * @param ModuleService $module_service |
|
| 47 | + */ |
|
| 48 | + public function __construct(ModuleService $module_service) |
|
| 49 | + { |
|
| 50 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * {@inheritDoc} |
|
| 55 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 56 | - */ |
|
| 57 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 58 | - { |
|
| 59 | - if ($this->module === null) { |
|
| 60 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 61 | - } |
|
| 53 | + /** |
|
| 54 | + * {@inheritDoc} |
|
| 55 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 56 | + */ |
|
| 57 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 58 | + { |
|
| 59 | + if ($this->module === null) { |
|
| 60 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $tree = Validator::attributes($request)->tree(); |
|
| 63 | + $tree = Validator::attributes($request)->tree(); |
|
| 64 | 64 | |
| 65 | - $users_root = array(); |
|
| 66 | - if (Auth::check()) { |
|
| 67 | - /** @var \Fisharebest\Webtrees\User $user */ |
|
| 68 | - $user = Auth::user(); |
|
| 69 | - $users_root[] = [ |
|
| 70 | - 'user' => $user, |
|
| 71 | - 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'), |
|
| 72 | - 'max_gen' => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN') |
|
| 73 | - ]; |
|
| 65 | + $users_root = array(); |
|
| 66 | + if (Auth::check()) { |
|
| 67 | + /** @var \Fisharebest\Webtrees\User $user */ |
|
| 68 | + $user = Auth::user(); |
|
| 69 | + $users_root[] = [ |
|
| 70 | + 'user' => $user, |
|
| 71 | + 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'), |
|
| 72 | + 'max_gen' => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN') |
|
| 73 | + ]; |
|
| 74 | 74 | |
| 75 | - if (Auth::isManager($tree)) { |
|
| 76 | - $default_user = new DefaultUser(); |
|
| 77 | - $users_root[] = [ |
|
| 78 | - 'user' => $default_user, |
|
| 79 | - 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'), |
|
| 80 | - 'max_gen' => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN') |
|
| 81 | - ]; |
|
| 82 | - } |
|
| 83 | - } |
|
| 75 | + if (Auth::isManager($tree)) { |
|
| 76 | + $default_user = new DefaultUser(); |
|
| 77 | + $users_root[] = [ |
|
| 78 | + 'user' => $default_user, |
|
| 79 | + 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'), |
|
| 80 | + 'max_gen' => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN') |
|
| 81 | + ]; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // Use the system max generations if not set |
|
| 86 | - $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
|
| 87 | - foreach ($users_root as $key => $user_root) { |
|
| 88 | - $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
|
| 89 | - (int) $user_root['max_gen'] : |
|
| 90 | - $max_gen_system; |
|
| 91 | - }; |
|
| 85 | + // Use the system max generations if not set |
|
| 86 | + $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
|
| 87 | + foreach ($users_root as $key => $user_root) { |
|
| 88 | + $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
|
| 89 | + (int) $user_root['max_gen'] : |
|
| 90 | + $max_gen_system; |
|
| 91 | + }; |
|
| 92 | 92 | |
| 93 | - return $this->viewResponse($this->module->name() . '::config-page', [ |
|
| 94 | - 'module_name' => $this->module->name(), |
|
| 95 | - 'title' => I18N::translate('Sosa Configuration'), |
|
| 96 | - 'tree' => $tree, |
|
| 97 | - 'user_id' => Validator::attributes($request)->user(), |
|
| 98 | - 'selected_user_id' => Validator::queryParams($request)->integer('user_id', 0), |
|
| 99 | - 'immediate_compute' => Validator::queryParams($request)->string('compute', '') === 'yes', |
|
| 100 | - 'users_root' => $users_root |
|
| 101 | - ]); |
|
| 102 | - } |
|
| 93 | + return $this->viewResponse($this->module->name() . '::config-page', [ |
|
| 94 | + 'module_name' => $this->module->name(), |
|
| 95 | + 'title' => I18N::translate('Sosa Configuration'), |
|
| 96 | + 'tree' => $tree, |
|
| 97 | + 'user_id' => Validator::attributes($request)->user(), |
|
| 98 | + 'selected_user_id' => Validator::queryParams($request)->integer('user_id', 0), |
|
| 99 | + 'immediate_compute' => Validator::queryParams($request)->string('compute', '') === 'yes', |
|
| 100 | + 'users_root' => $users_root |
|
| 101 | + ]); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -31,51 +31,51 @@ |
||
| 31 | 31 | */ |
| 32 | 32 | class SosaConfigAction implements RequestHandlerInterface |
| 33 | 33 | { |
| 34 | - private UserService $user_service; |
|
| 35 | - private SosaRecordsService $sosa_record_service; |
|
| 34 | + private UserService $user_service; |
|
| 35 | + private SosaRecordsService $sosa_record_service; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Constructor for SosaConfigAction Request Handler |
|
| 39 | - * |
|
| 40 | - * @param UserService $user_service |
|
| 41 | - * @param SosaRecordsService $sosa_records_service |
|
| 42 | - */ |
|
| 43 | - public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service) |
|
| 44 | - { |
|
| 45 | - $this->user_service = $user_service; |
|
| 46 | - $this->sosa_record_service = $sosa_records_service; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * Constructor for SosaConfigAction Request Handler |
|
| 39 | + * |
|
| 40 | + * @param UserService $user_service |
|
| 41 | + * @param SosaRecordsService $sosa_records_service |
|
| 42 | + */ |
|
| 43 | + public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service) |
|
| 44 | + { |
|
| 45 | + $this->user_service = $user_service; |
|
| 46 | + $this->sosa_record_service = $sosa_records_service; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * {@inheritDoc} |
|
| 51 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 52 | - */ |
|
| 53 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 54 | - { |
|
| 55 | - $tree = Validator::attributes($request)->tree(); |
|
| 49 | + /** |
|
| 50 | + * {@inheritDoc} |
|
| 51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 52 | + */ |
|
| 53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 54 | + { |
|
| 55 | + $tree = Validator::attributes($request)->tree(); |
|
| 56 | 56 | |
| 57 | - $user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
| 58 | - $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
| 59 | - $max_gen = Validator::parsedBody($request)->integer( |
|
| 60 | - 'sosa-maxgen', |
|
| 61 | - $this->sosa_record_service->maxSystemGenerations() |
|
| 62 | - ); |
|
| 57 | + $user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
|
| 58 | + $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
|
| 59 | + $max_gen = Validator::parsedBody($request)->integer( |
|
| 60 | + 'sosa-maxgen', |
|
| 61 | + $this->sosa_record_service->maxSystemGenerations() |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | - if (Auth::id() === $user_id || ($user_id === -1 && Auth::isManager($tree))) { |
|
| 65 | - $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 66 | - if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
| 67 | - $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
| 68 | - $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
| 69 | - FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
| 70 | - return Registry::responseFactory()->redirect(SosaConfig::class, [ |
|
| 71 | - 'tree' => $tree->name(), |
|
| 72 | - 'compute' => 'yes', |
|
| 73 | - 'user_id' => $user_id |
|
| 74 | - ]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 64 | + if (Auth::id() === $user_id || ($user_id === -1 && Auth::isManager($tree))) { |
|
| 65 | + $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
| 66 | + if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
| 67 | + $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
| 68 | + $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
| 69 | + FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
| 70 | + return Registry::responseFactory()->redirect(SosaConfig::class, [ |
|
| 71 | + 'tree' => $tree->name(), |
|
| 72 | + 'compute' => 'yes', |
|
| 73 | + 'user_id' => $user_id |
|
| 74 | + ]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
| 79 | - return Registry::responseFactory()->redirect(SosaConfig::class, ['tree' => $tree->name()]); |
|
| 80 | - } |
|
| 78 | + FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
| 79 | + return Registry::responseFactory()->redirect(SosaConfig::class, ['tree' => $tree->name()]); |
|
| 80 | + } |
|
| 81 | 81 | } |
@@ -57,261 +57,261 @@ |
||
| 57 | 57 | * Identify and produce statistics about Sosa ancestors |
| 58 | 58 | */ |
| 59 | 59 | class SosaModule extends AbstractModule implements |
| 60 | - ModuleMyArtJaubInterface, |
|
| 61 | - ModuleGlobalInterface, |
|
| 62 | - ModuleMenuInterface, |
|
| 63 | - ModuleSidebarInterface, |
|
| 64 | - ModuleGeoAnalysisProviderInterface, |
|
| 65 | - ModuleHookSubscriberInterface |
|
| 60 | + ModuleMyArtJaubInterface, |
|
| 61 | + ModuleGlobalInterface, |
|
| 62 | + ModuleMenuInterface, |
|
| 63 | + ModuleSidebarInterface, |
|
| 64 | + ModuleGeoAnalysisProviderInterface, |
|
| 65 | + ModuleHookSubscriberInterface |
|
| 66 | 66 | { |
| 67 | - use ModuleMyArtJaubTrait { |
|
| 68 | - boot as traitBoot; |
|
| 69 | - } |
|
| 70 | - use ModuleGlobalTrait; |
|
| 71 | - use ModuleMenuTrait; |
|
| 72 | - use ModuleSidebarTrait; |
|
| 73 | - |
|
| 74 | - // How to update the database schema for this module |
|
| 75 | - private const SCHEMA_TARGET_VERSION = 3; |
|
| 76 | - private const SCHEMA_SETTING_NAME = 'MAJ_SOSA_SCHEMA_VERSION'; |
|
| 77 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 67 | + use ModuleMyArtJaubTrait { |
|
| 68 | + boot as traitBoot; |
|
| 69 | + } |
|
| 70 | + use ModuleGlobalTrait; |
|
| 71 | + use ModuleMenuTrait; |
|
| 72 | + use ModuleSidebarTrait; |
|
| 73 | + |
|
| 74 | + // How to update the database schema for this module |
|
| 75 | + private const SCHEMA_TARGET_VERSION = 3; |
|
| 76 | + private const SCHEMA_SETTING_NAME = 'MAJ_SOSA_SCHEMA_VERSION'; |
|
| 77 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 78 | 78 | /** |
| 79 | - * {@inheritDoc} |
|
| 80 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 81 | - */ |
|
| 82 | - public function title(): string |
|
| 83 | - { |
|
| 84 | - return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa'); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * {@inheritDoc} |
|
| 89 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 90 | - */ |
|
| 91 | - public function description(): string |
|
| 92 | - { |
|
| 93 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 94 | - return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.'); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * {@inheritDoc} |
|
| 99 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 100 | - */ |
|
| 101 | - public function boot(): void |
|
| 102 | - { |
|
| 103 | - $this->traitBoot(); |
|
| 104 | - app(MigrationService::class)->updateSchema( |
|
| 105 | - self::SCHEMA_MIGRATION_PREFIX, |
|
| 106 | - self::SCHEMA_SETTING_NAME, |
|
| 107 | - self::SCHEMA_TARGET_VERSION |
|
| 108 | - ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * {@inheritDoc} |
|
| 113 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 114 | - */ |
|
| 115 | - public function loadRoutes(Map $router): void |
|
| 116 | - { |
|
| 117 | - $router->attach('', '', static function (Map $router): void { |
|
| 118 | - |
|
| 119 | - $router->attach('', '/module-maj/sosa', static function (Map $router): void { |
|
| 120 | - |
|
| 121 | - $router->attach('', '/list', static function (Map $router): void { |
|
| 122 | - $router->tokens(['gen' => '\d+']); |
|
| 123 | - $router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class); |
|
| 124 | - $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 125 | - $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 126 | - $router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class); |
|
| 127 | - }); |
|
| 128 | - |
|
| 129 | - $router->attach('', '/statistics/{tree}', static function (Map $router): void { |
|
| 130 | - |
|
| 131 | - $router->get(SosaStatistics::class, '', SosaStatistics::class); |
|
| 132 | - $router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class); |
|
| 133 | - }); |
|
| 134 | - |
|
| 135 | - $router->attach('', '/config/{tree}', static function (Map $router): void { |
|
| 136 | - |
|
| 137 | - $router->get(SosaConfig::class, '', SosaConfig::class); |
|
| 138 | - $router->post(SosaConfigAction::class, '', SosaConfigAction::class); |
|
| 139 | - $router->get(SosaComputeModal::class, '/compute/{xref}', SosaComputeModal::class); |
|
| 140 | - $router->post(SosaComputeAction::class, '/compute', SosaComputeAction::class); |
|
| 141 | - }); |
|
| 142 | - }); |
|
| 143 | - }); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * {@inheritDoc} |
|
| 148 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 149 | - */ |
|
| 150 | - public function customModuleVersion(): string |
|
| 151 | - { |
|
| 152 | - return '2.1.3-v.1'; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * {@inheritDoc} |
|
| 157 | - * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder() |
|
| 158 | - */ |
|
| 159 | - public function defaultMenuOrder(): int |
|
| 160 | - { |
|
| 161 | - return 7; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * {@inhericDoc} |
|
| 166 | - * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu() |
|
| 167 | - */ |
|
| 168 | - public function getMenu(Tree $tree): ?Menu |
|
| 169 | - { |
|
| 170 | - $menu = new Menu(I18N::translate('Sosa Statistics')); |
|
| 171 | - $menu->setClass('menu-maj-sosa'); |
|
| 172 | - $menu->setSubmenus([ |
|
| 173 | - new Menu( |
|
| 174 | - I18N::translate('Sosa Ancestors'), |
|
| 175 | - route(AncestorsList::class, ['tree' => $tree->name()]), |
|
| 176 | - 'menu-maj-sosa-list', |
|
| 177 | - ['rel' => 'nofollow'] |
|
| 178 | - ), |
|
| 179 | - new Menu( |
|
| 180 | - I18N::translate('Missing Ancestors'), |
|
| 181 | - route(MissingAncestorsList::class, ['tree' => $tree->name()]), |
|
| 182 | - 'menu-maj-sosa-missing', |
|
| 183 | - ['rel' => 'nofollow'] |
|
| 184 | - ), |
|
| 185 | - new Menu( |
|
| 186 | - I18N::translate('Sosa Statistics'), |
|
| 187 | - route(SosaStatistics::class, ['tree' => $tree->name()]), |
|
| 188 | - 'menu-maj-sosa-stats' |
|
| 189 | - ) |
|
| 190 | - ]); |
|
| 191 | - |
|
| 192 | - if (Auth::check()) { |
|
| 193 | - $menu->addSubmenu(new Menu( |
|
| 194 | - I18N::translate('Sosa Configuration'), |
|
| 195 | - route(SosaConfig::class, ['tree' => $tree->name()]), |
|
| 196 | - 'menu-maj-sosa-config' |
|
| 197 | - )); |
|
| 198 | - |
|
| 199 | - /** @var ServerRequestInterface $request */ |
|
| 200 | - $request = app(ServerRequestInterface::class); |
|
| 201 | - $route = Validator::attributes($request)->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 = Validator::attributes($request)->isXref()->string('xref', ''); |
|
| 207 | - |
|
| 208 | - $menu->addSubmenu(new Menu( |
|
| 209 | - I18N::translate('Complete Sosas'), |
|
| 210 | - '#', |
|
| 211 | - 'menu-maj-sosa-compute', |
|
| 212 | - [ |
|
| 213 | - 'rel' => 'nofollow', |
|
| 214 | - 'data-wt-href' => route(SosaComputeModal::class, ['tree' => $tree->name(), 'xref' => $xref]), |
|
| 215 | - 'data-bs-target' => '#wt-ajax-modal', |
|
| 216 | - 'data-bs-toggle' => 'modal', |
|
| 217 | - 'data-bs-backdrop' => 'static' |
|
| 218 | - ] |
|
| 219 | - )); |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $menu; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * {@inheritDoc} |
|
| 228 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
| 229 | - */ |
|
| 230 | - public function headContent(): string |
|
| 231 | - { |
|
| 232 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - /** |
|
| 236 | - * {@inheritDoc} |
|
| 237 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
| 238 | - */ |
|
| 239 | - public function bodyContent(): string |
|
| 240 | - { |
|
| 241 | - return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>'; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * {@inheritDoc} |
|
| 246 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::sidebarTitle() |
|
| 247 | - */ |
|
| 248 | - public function sidebarTitle(Individual $individual): string |
|
| 249 | - { |
|
| 250 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 251 | - |
|
| 252 | - return view($this->name() . '::sidebar/title', [ |
|
| 253 | - 'module_name' => $this->name(), |
|
| 254 | - 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
| 255 | - ]); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * {@inheritDoc} |
|
| 260 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent() |
|
| 261 | - */ |
|
| 262 | - public function getSidebarContent(Individual $individual): string |
|
| 263 | - { |
|
| 264 | - $sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
|
| 265 | - $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree()); |
|
| 266 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 267 | - |
|
| 268 | - return view($this->name() . '::sidebar/content', [ |
|
| 269 | - 'sosa_ancestor' => $individual, |
|
| 270 | - 'sosa_root' => $sosa_root, |
|
| 271 | - 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
| 272 | - ]); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * {@inheritDoc} |
|
| 277 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
|
| 278 | - */ |
|
| 279 | - public function hasSidebarContent(Individual $individual): bool |
|
| 280 | - { |
|
| 281 | - $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 282 | - |
|
| 283 | - return app(SosaRecordsService::class) |
|
| 284 | - ->sosaNumbers($individual->tree(), $user, $individual)->count() > 0; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * {@inheritDoc} |
|
| 289 | - * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder() |
|
| 290 | - */ |
|
| 291 | - public function defaultSidebarOrder(): int |
|
| 292 | - { |
|
| 293 | - return 1; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * {@inheritDoc} |
|
| 298 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
| 299 | - */ |
|
| 300 | - public function listGeoAnalyses(): array |
|
| 301 | - { |
|
| 302 | - return [ |
|
| 303 | - SosaByGenerationGeoAnalysis::class |
|
| 304 | - ]; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * {@inheritDoc} |
|
| 309 | - * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 310 | - */ |
|
| 311 | - public function listSubscribedHooks(): array |
|
| 312 | - { |
|
| 313 | - return [ |
|
| 314 | - app()->makeWith(SosaIconHook::class, [ 'module' => $this ]) |
|
| 315 | - ]; |
|
| 316 | - } |
|
| 79 | + * {@inheritDoc} |
|
| 80 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 81 | + */ |
|
| 82 | + public function title(): string |
|
| 83 | + { |
|
| 84 | + return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa'); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * {@inheritDoc} |
|
| 89 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 90 | + */ |
|
| 91 | + public function description(): string |
|
| 92 | + { |
|
| 93 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 94 | + return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.'); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * {@inheritDoc} |
|
| 99 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 100 | + */ |
|
| 101 | + public function boot(): void |
|
| 102 | + { |
|
| 103 | + $this->traitBoot(); |
|
| 104 | + app(MigrationService::class)->updateSchema( |
|
| 105 | + self::SCHEMA_MIGRATION_PREFIX, |
|
| 106 | + self::SCHEMA_SETTING_NAME, |
|
| 107 | + self::SCHEMA_TARGET_VERSION |
|
| 108 | + ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * {@inheritDoc} |
|
| 113 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 114 | + */ |
|
| 115 | + public function loadRoutes(Map $router): void |
|
| 116 | + { |
|
| 117 | + $router->attach('', '', static function (Map $router): void { |
|
| 118 | + |
|
| 119 | + $router->attach('', '/module-maj/sosa', static function (Map $router): void { |
|
| 120 | + |
|
| 121 | + $router->attach('', '/list', static function (Map $router): void { |
|
| 122 | + $router->tokens(['gen' => '\d+']); |
|
| 123 | + $router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class); |
|
| 124 | + $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 125 | + $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class); //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 126 | + $router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class); |
|
| 127 | + }); |
|
| 128 | + |
|
| 129 | + $router->attach('', '/statistics/{tree}', static function (Map $router): void { |
|
| 130 | + |
|
| 131 | + $router->get(SosaStatistics::class, '', SosaStatistics::class); |
|
| 132 | + $router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class); |
|
| 133 | + }); |
|
| 134 | + |
|
| 135 | + $router->attach('', '/config/{tree}', static function (Map $router): void { |
|
| 136 | + |
|
| 137 | + $router->get(SosaConfig::class, '', SosaConfig::class); |
|
| 138 | + $router->post(SosaConfigAction::class, '', SosaConfigAction::class); |
|
| 139 | + $router->get(SosaComputeModal::class, '/compute/{xref}', SosaComputeModal::class); |
|
| 140 | + $router->post(SosaComputeAction::class, '/compute', SosaComputeAction::class); |
|
| 141 | + }); |
|
| 142 | + }); |
|
| 143 | + }); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * {@inheritDoc} |
|
| 148 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 149 | + */ |
|
| 150 | + public function customModuleVersion(): string |
|
| 151 | + { |
|
| 152 | + return '2.1.3-v.1'; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * {@inheritDoc} |
|
| 157 | + * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder() |
|
| 158 | + */ |
|
| 159 | + public function defaultMenuOrder(): int |
|
| 160 | + { |
|
| 161 | + return 7; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * {@inhericDoc} |
|
| 166 | + * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu() |
|
| 167 | + */ |
|
| 168 | + public function getMenu(Tree $tree): ?Menu |
|
| 169 | + { |
|
| 170 | + $menu = new Menu(I18N::translate('Sosa Statistics')); |
|
| 171 | + $menu->setClass('menu-maj-sosa'); |
|
| 172 | + $menu->setSubmenus([ |
|
| 173 | + new Menu( |
|
| 174 | + I18N::translate('Sosa Ancestors'), |
|
| 175 | + route(AncestorsList::class, ['tree' => $tree->name()]), |
|
| 176 | + 'menu-maj-sosa-list', |
|
| 177 | + ['rel' => 'nofollow'] |
|
| 178 | + ), |
|
| 179 | + new Menu( |
|
| 180 | + I18N::translate('Missing Ancestors'), |
|
| 181 | + route(MissingAncestorsList::class, ['tree' => $tree->name()]), |
|
| 182 | + 'menu-maj-sosa-missing', |
|
| 183 | + ['rel' => 'nofollow'] |
|
| 184 | + ), |
|
| 185 | + new Menu( |
|
| 186 | + I18N::translate('Sosa Statistics'), |
|
| 187 | + route(SosaStatistics::class, ['tree' => $tree->name()]), |
|
| 188 | + 'menu-maj-sosa-stats' |
|
| 189 | + ) |
|
| 190 | + ]); |
|
| 191 | + |
|
| 192 | + if (Auth::check()) { |
|
| 193 | + $menu->addSubmenu(new Menu( |
|
| 194 | + I18N::translate('Sosa Configuration'), |
|
| 195 | + route(SosaConfig::class, ['tree' => $tree->name()]), |
|
| 196 | + 'menu-maj-sosa-config' |
|
| 197 | + )); |
|
| 198 | + |
|
| 199 | + /** @var ServerRequestInterface $request */ |
|
| 200 | + $request = app(ServerRequestInterface::class); |
|
| 201 | + $route = Validator::attributes($request)->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 = Validator::attributes($request)->isXref()->string('xref', ''); |
|
| 207 | + |
|
| 208 | + $menu->addSubmenu(new Menu( |
|
| 209 | + I18N::translate('Complete Sosas'), |
|
| 210 | + '#', |
|
| 211 | + 'menu-maj-sosa-compute', |
|
| 212 | + [ |
|
| 213 | + 'rel' => 'nofollow', |
|
| 214 | + 'data-wt-href' => route(SosaComputeModal::class, ['tree' => $tree->name(), 'xref' => $xref]), |
|
| 215 | + 'data-bs-target' => '#wt-ajax-modal', |
|
| 216 | + 'data-bs-toggle' => 'modal', |
|
| 217 | + 'data-bs-backdrop' => 'static' |
|
| 218 | + ] |
|
| 219 | + )); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $menu; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * {@inheritDoc} |
|
| 228 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
| 229 | + */ |
|
| 230 | + public function headContent(): string |
|
| 231 | + { |
|
| 232 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + /** |
|
| 236 | + * {@inheritDoc} |
|
| 237 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
| 238 | + */ |
|
| 239 | + public function bodyContent(): string |
|
| 240 | + { |
|
| 241 | + return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>'; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * {@inheritDoc} |
|
| 246 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::sidebarTitle() |
|
| 247 | + */ |
|
| 248 | + public function sidebarTitle(Individual $individual): string |
|
| 249 | + { |
|
| 250 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 251 | + |
|
| 252 | + return view($this->name() . '::sidebar/title', [ |
|
| 253 | + 'module_name' => $this->name(), |
|
| 254 | + 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
| 255 | + ]); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * {@inheritDoc} |
|
| 260 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent() |
|
| 261 | + */ |
|
| 262 | + public function getSidebarContent(Individual $individual): string |
|
| 263 | + { |
|
| 264 | + $sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID'); |
|
| 265 | + $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree()); |
|
| 266 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 267 | + |
|
| 268 | + return view($this->name() . '::sidebar/content', [ |
|
| 269 | + 'sosa_ancestor' => $individual, |
|
| 270 | + 'sosa_root' => $sosa_root, |
|
| 271 | + 'sosa_numbers' => app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual) |
|
| 272 | + ]); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * {@inheritDoc} |
|
| 277 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
|
| 278 | + */ |
|
| 279 | + public function hasSidebarContent(Individual $individual): bool |
|
| 280 | + { |
|
| 281 | + $user = Auth::check() ? Auth::user() : new DefaultUser(); |
|
| 282 | + |
|
| 283 | + return app(SosaRecordsService::class) |
|
| 284 | + ->sosaNumbers($individual->tree(), $user, $individual)->count() > 0; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * {@inheritDoc} |
|
| 289 | + * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder() |
|
| 290 | + */ |
|
| 291 | + public function defaultSidebarOrder(): int |
|
| 292 | + { |
|
| 293 | + return 1; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * {@inheritDoc} |
|
| 298 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
| 299 | + */ |
|
| 300 | + public function listGeoAnalyses(): array |
|
| 301 | + { |
|
| 302 | + return [ |
|
| 303 | + SosaByGenerationGeoAnalysis::class |
|
| 304 | + ]; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * {@inheritDoc} |
|
| 309 | + * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks() |
|
| 310 | + */ |
|
| 311 | + public function listSubscribedHooks(): array |
|
| 312 | + { |
|
| 313 | + return [ |
|
| 314 | + app()->makeWith(SosaIconHook::class, [ 'module' => $this ]) |
|
| 315 | + ]; |
|
| 316 | + } |
|
| 317 | 317 | } |
@@ -34,163 +34,163 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class WelcomeBlockModule extends AbstractModule implements ModuleMyArtJaubInterface, ModuleBlockInterface |
| 36 | 36 | { |
| 37 | - use ModuleMyArtJaubTrait; |
|
| 38 | - use ModuleBlockTrait; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * {@inheritDoc} |
|
| 42 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 43 | - */ |
|
| 44 | - public function title(): string |
|
| 45 | - { |
|
| 46 | - return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * {@inheritDoc} |
|
| 51 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 52 | - */ |
|
| 53 | - public function description(): string |
|
| 54 | - { |
|
| 55 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 56 | - return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * {@inheritDoc} |
|
| 61 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 62 | - */ |
|
| 63 | - public function loadRoutes(Map $router): void |
|
| 64 | - { |
|
| 65 | - $router->attach('', '', static function (Map $router): void { |
|
| 66 | - |
|
| 67 | - $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
| 68 | - $router->tokens(['block_id' => '\d+']); |
|
| 69 | - $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
| 70 | - }); |
|
| 71 | - }); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * {@inheritDoc} |
|
| 76 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 77 | - */ |
|
| 78 | - public function customModuleVersion(): string |
|
| 79 | - { |
|
| 80 | - return '2.1.3-v.1'; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * {@inheritDoc} |
|
| 85 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
| 86 | - * |
|
| 87 | - * @param mixed[] $config |
|
| 88 | - */ |
|
| 89 | - public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
| 90 | - { |
|
| 91 | - $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
| 92 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
| 93 | - |
|
| 94 | - $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
| 95 | - ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
| 96 | - |
|
| 97 | - $content = view($this->name() . '::block-embed', [ |
|
| 98 | - 'block_id' => $block_id, |
|
| 99 | - 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
| 100 | - 'fab_login_block_view' => $fab_login_block_view, |
|
| 101 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
| 102 | - 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
| 103 | - ]); |
|
| 104 | - |
|
| 105 | - if ($context !== self::CONTEXT_EMBED) { |
|
| 106 | - return view('modules/block-template', [ |
|
| 107 | - 'block' => Str::kebab($this->name()), |
|
| 108 | - 'id' => $block_id, |
|
| 109 | - 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
| 110 | - 'title' => e($tree->title()), |
|
| 111 | - 'content' => $content, |
|
| 112 | - ]); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - return $content; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * {@inheritDoc} |
|
| 120 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
| 121 | - */ |
|
| 122 | - public function isTreeBlock(): bool |
|
| 123 | - { |
|
| 124 | - return true; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * {@inheritDoc} |
|
| 129 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
| 130 | - */ |
|
| 131 | - public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
| 132 | - { |
|
| 133 | - return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * {@inheritDoc} |
|
| 138 | - * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
| 139 | - */ |
|
| 140 | - public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
| 141 | - { |
|
| 142 | - $matomo_enabled = Validator::parsedBody($request)->string('matomo_enabled', '') === 'yes'; |
|
| 143 | - $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
| 144 | - if (!$matomo_enabled) { |
|
| 145 | - return; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $matomo_url = trim(Validator::parsedBody($request)->string('matomo_url', '')); |
|
| 149 | - if (filter_var($matomo_url, FILTER_VALIDATE_URL) === false) { |
|
| 150 | - FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $matomo_siteid = Validator::parsedBody($request)->integer('matomo_siteid', -1); |
|
| 155 | - if ($matomo_siteid === -1) { |
|
| 156 | - FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
| 157 | - return; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - $matomo_token = trim(Validator::parsedBody($request)->string('matomo_token', '')); |
|
| 161 | - |
|
| 162 | - $this |
|
| 163 | - ->setBlockSetting($block_id, 'matomo_url', $matomo_url) |
|
| 164 | - ->setBlockSetting($block_id, 'matomo_token', $matomo_token) |
|
| 165 | - ->setBlockSetting($block_id, 'matomo_siteid', (string) $matomo_siteid); |
|
| 166 | - |
|
| 167 | - Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
| 172 | - * |
|
| 173 | - * @param int $block_id |
|
| 174 | - * @return bool |
|
| 175 | - */ |
|
| 176 | - public function isMatomoEnabled(int $block_id): bool |
|
| 177 | - { |
|
| 178 | - return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
| 183 | - * |
|
| 184 | - * @param int $block_id |
|
| 185 | - * @return array<string, mixed> |
|
| 186 | - */ |
|
| 187 | - public function matomoSettings(int $block_id): array |
|
| 188 | - { |
|
| 189 | - return [ |
|
| 190 | - 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
| 191 | - 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
| 192 | - 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
| 193 | - 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
| 194 | - ]; |
|
| 195 | - } |
|
| 37 | + use ModuleMyArtJaubTrait; |
|
| 38 | + use ModuleBlockTrait; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * {@inheritDoc} |
|
| 42 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 43 | + */ |
|
| 44 | + public function title(): string |
|
| 45 | + { |
|
| 46 | + return /* I18N: Name of the “WelcomeBlock” module */ I18N::translate('MyArtJaub Welcome Block'); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * {@inheritDoc} |
|
| 51 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 52 | + */ |
|
| 53 | + public function description(): string |
|
| 54 | + { |
|
| 55 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 56 | + return /* I18N: Description of the “WelcomeBlock” module */ I18N::translate('The MyArtJaub Welcome block welcomes the visitor to the site, allows a quick login to the site, and displays statistics on visits.'); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * {@inheritDoc} |
|
| 61 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 62 | + */ |
|
| 63 | + public function loadRoutes(Map $router): void |
|
| 64 | + { |
|
| 65 | + $router->attach('', '', static function (Map $router): void { |
|
| 66 | + |
|
| 67 | + $router->attach('', '/module-maj/welcomeblock/{block_id}', static function (Map $router): void { |
|
| 68 | + $router->tokens(['block_id' => '\d+']); |
|
| 69 | + $router->get(MatomoStats::class, '/matomostats', MatomoStats::class); |
|
| 70 | + }); |
|
| 71 | + }); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * {@inheritDoc} |
|
| 76 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 77 | + */ |
|
| 78 | + public function customModuleVersion(): string |
|
| 79 | + { |
|
| 80 | + return '2.1.3-v.1'; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * {@inheritDoc} |
|
| 85 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::getBlock() |
|
| 86 | + * |
|
| 87 | + * @param mixed[] $config |
|
| 88 | + */ |
|
| 89 | + public function getBlock(Tree $tree, int $block_id, string $context, array $config = []): string |
|
| 90 | + { |
|
| 91 | + $fab_welcome_block_view = app(\Fisharebest\Webtrees\Module\WelcomeBlockModule::class) |
|
| 92 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
| 93 | + |
|
| 94 | + $fab_login_block_view = app(\Fisharebest\Webtrees\Module\LoginBlockModule::class) |
|
| 95 | + ->getBlock($tree, $block_id, ModuleBlockInterface::CONTEXT_EMBED); |
|
| 96 | + |
|
| 97 | + $content = view($this->name() . '::block-embed', [ |
|
| 98 | + 'block_id' => $block_id, |
|
| 99 | + 'fab_welcome_block_view' => $fab_welcome_block_view, |
|
| 100 | + 'fab_login_block_view' => $fab_login_block_view, |
|
| 101 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
| 102 | + 'js_script_url' => $this->assetUrl('js/welcomeblock.min.js') |
|
| 103 | + ]); |
|
| 104 | + |
|
| 105 | + if ($context !== self::CONTEXT_EMBED) { |
|
| 106 | + return view('modules/block-template', [ |
|
| 107 | + 'block' => Str::kebab($this->name()), |
|
| 108 | + 'id' => $block_id, |
|
| 109 | + 'config_url' => $this->configUrl($tree, $context, $block_id), |
|
| 110 | + 'title' => e($tree->title()), |
|
| 111 | + 'content' => $content, |
|
| 112 | + ]); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + return $content; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * {@inheritDoc} |
|
| 120 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::isTreeBlock() |
|
| 121 | + */ |
|
| 122 | + public function isTreeBlock(): bool |
|
| 123 | + { |
|
| 124 | + return true; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * {@inheritDoc} |
|
| 129 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::editBlockConfiguration() |
|
| 130 | + */ |
|
| 131 | + public function editBlockConfiguration(Tree $tree, int $block_id): string |
|
| 132 | + { |
|
| 133 | + return view($this->name() . '::config', $this->matomoSettings($block_id)); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * {@inheritDoc} |
|
| 138 | + * @see \Fisharebest\Webtrees\Module\ModuleBlockInterface::saveBlockConfiguration() |
|
| 139 | + */ |
|
| 140 | + public function saveBlockConfiguration(ServerRequestInterface $request, int $block_id): void |
|
| 141 | + { |
|
| 142 | + $matomo_enabled = Validator::parsedBody($request)->string('matomo_enabled', '') === 'yes'; |
|
| 143 | + $this->setBlockSetting($block_id, 'matomo_enabled', $matomo_enabled ? 'yes' : 'no'); |
|
| 144 | + if (!$matomo_enabled) { |
|
| 145 | + return; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $matomo_url = trim(Validator::parsedBody($request)->string('matomo_url', '')); |
|
| 149 | + if (filter_var($matomo_url, FILTER_VALIDATE_URL) === false) { |
|
| 150 | + FlashMessages::addMessage(I18N::translate('The Matomo URL provided is not valid.'), 'danger'); |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $matomo_siteid = Validator::parsedBody($request)->integer('matomo_siteid', -1); |
|
| 155 | + if ($matomo_siteid === -1) { |
|
| 156 | + FlashMessages::addMessage(I18N::translate('The Matomo Site ID provided is not valid.'), 'danger'); |
|
| 157 | + return; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + $matomo_token = trim(Validator::parsedBody($request)->string('matomo_token', '')); |
|
| 161 | + |
|
| 162 | + $this |
|
| 163 | + ->setBlockSetting($block_id, 'matomo_url', $matomo_url) |
|
| 164 | + ->setBlockSetting($block_id, 'matomo_token', $matomo_token) |
|
| 165 | + ->setBlockSetting($block_id, 'matomo_siteid', (string) $matomo_siteid); |
|
| 166 | + |
|
| 167 | + Registry::cache()->file()->forget($this->name() . '-matomovisits-yearly-' . $block_id); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Returns whether Matomo statistics is enabled for a specific MyArtJaub WelcomeBlock block |
|
| 172 | + * |
|
| 173 | + * @param int $block_id |
|
| 174 | + * @return bool |
|
| 175 | + */ |
|
| 176 | + public function isMatomoEnabled(int $block_id): bool |
|
| 177 | + { |
|
| 178 | + return $this->getBlockSetting($block_id, 'matomo_enabled', 'no') === 'yes'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Returns settings for retrieving Matomo statistics for a specific MyArtJaub WelcomeBlock block |
|
| 183 | + * |
|
| 184 | + * @param int $block_id |
|
| 185 | + * @return array<string, mixed> |
|
| 186 | + */ |
|
| 187 | + public function matomoSettings(int $block_id): array |
|
| 188 | + { |
|
| 189 | + return [ |
|
| 190 | + 'matomo_enabled' => $this->isMatomoEnabled($block_id), |
|
| 191 | + 'matomo_url' => $this->getBlockSetting($block_id, 'matomo_url'), |
|
| 192 | + 'matomo_token' => $this->getBlockSetting($block_id, 'matomo_token'), |
|
| 193 | + 'matomo_siteid' => (int) $this->getBlockSetting($block_id, 'matomo_siteid', '0') |
|
| 194 | + ]; |
|
| 195 | + } |
|
| 196 | 196 | } |
@@ -41,127 +41,127 @@ |
||
| 41 | 41 | * Allow for tasks to be run on a (nearly-)regular schedule |
| 42 | 42 | */ |
| 43 | 43 | class AdminTasksModule extends AbstractModule implements |
| 44 | - ModuleMyArtJaubInterface, |
|
| 45 | - ModuleConfigInterface, |
|
| 46 | - ModuleGlobalInterface, |
|
| 47 | - ModuleTasksProviderInterface |
|
| 44 | + ModuleMyArtJaubInterface, |
|
| 45 | + ModuleConfigInterface, |
|
| 46 | + ModuleGlobalInterface, |
|
| 47 | + ModuleTasksProviderInterface |
|
| 48 | 48 | { |
| 49 | - use ModuleMyArtJaubTrait { |
|
| 50 | - boot as traitBoot; |
|
| 51 | - } |
|
| 52 | - use ModuleConfigTrait; |
|
| 53 | - use ModuleGlobalTrait; |
|
| 54 | - |
|
| 55 | - //How to update the database schema for this module |
|
| 56 | - private const SCHEMA_TARGET_VERSION = 2; |
|
| 57 | - private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
|
| 58 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * {@inheritDoc} |
|
| 62 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 63 | - */ |
|
| 64 | - public function title(): string |
|
| 65 | - { |
|
| 66 | - return I18N::translate('Administration Tasks'); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * {@inheritDoc} |
|
| 71 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 72 | - */ |
|
| 73 | - public function description(): string |
|
| 74 | - { |
|
| 75 | - return I18N::translate('Manage and run nearly-scheduled administration tasks.'); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * {@inheritDoc} |
|
| 80 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 81 | - */ |
|
| 82 | - public function boot(): void |
|
| 83 | - { |
|
| 84 | - $this->traitBoot(); |
|
| 85 | - app(MigrationService::class)->updateSchema( |
|
| 86 | - self::SCHEMA_MIGRATION_PREFIX, |
|
| 87 | - self::SCHEMA_SETTING_NAME, |
|
| 88 | - self::SCHEMA_TARGET_VERSION |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * {@inheritDoc} |
|
| 94 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 95 | - */ |
|
| 96 | - public function loadRoutes(Map $router): void |
|
| 97 | - { |
|
| 98 | - $router->attach('', '', static function (Map $router): void { |
|
| 99 | - |
|
| 100 | - $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
| 101 | - $router->tokens(['enable' => '[01]']); |
|
| 102 | - |
|
| 103 | - $router->attach('', '/admin', static function (Map $router): void { |
|
| 104 | - |
|
| 105 | - $router->extras([ |
|
| 106 | - 'middleware' => [ |
|
| 107 | - AuthAdministrator::class, |
|
| 108 | - ], |
|
| 109 | - ]); |
|
| 110 | - $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
| 111 | - |
|
| 112 | - $router->attach('', '/tasks', static function (Map $router): void { |
|
| 113 | - |
|
| 114 | - $router->get(TasksList::class, '', TasksList::class); |
|
| 115 | - $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
| 116 | - $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
| 117 | - $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
| 118 | - }); |
|
| 119 | - }); |
|
| 120 | - |
|
| 121 | - $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
| 122 | - ->allows(RequestMethodInterface::METHOD_POST); |
|
| 123 | - |
|
| 124 | - $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
| 125 | - ->extras(['middleware' => [AuthAdministrator::class]]); |
|
| 126 | - }); |
|
| 127 | - }); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * {@inheritDoc} |
|
| 132 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
| 133 | - */ |
|
| 134 | - public function customModuleVersion(): string |
|
| 135 | - { |
|
| 136 | - return '2.1.3-v.1'; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - /** |
|
| 140 | - * {@inheritDoc} |
|
| 141 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
| 142 | - */ |
|
| 143 | - public function getConfigLink(): string |
|
| 144 | - { |
|
| 145 | - return route(AdminConfigPage::class); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * {@inheritDoc} |
|
| 150 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
| 151 | - */ |
|
| 152 | - public function bodyContent(): string |
|
| 153 | - { |
|
| 154 | - return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * {@inheritDoc} |
|
| 159 | - * @see ModuleTasksProviderInterface::listTasks() |
|
| 160 | - */ |
|
| 161 | - public function listTasks(): array |
|
| 162 | - { |
|
| 163 | - return [ |
|
| 164 | - 'maj-healthcheck' => HealthCheckEmailTask::class |
|
| 165 | - ]; |
|
| 166 | - } |
|
| 49 | + use ModuleMyArtJaubTrait { |
|
| 50 | + boot as traitBoot; |
|
| 51 | + } |
|
| 52 | + use ModuleConfigTrait; |
|
| 53 | + use ModuleGlobalTrait; |
|
| 54 | + |
|
| 55 | + //How to update the database schema for this module |
|
| 56 | + private const SCHEMA_TARGET_VERSION = 2; |
|
| 57 | + private const SCHEMA_SETTING_NAME = 'MAJ_ADMTASKS_SCHEMA_VERSION'; |
|
| 58 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * {@inheritDoc} |
|
| 62 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 63 | + */ |
|
| 64 | + public function title(): string |
|
| 65 | + { |
|
| 66 | + return I18N::translate('Administration Tasks'); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * {@inheritDoc} |
|
| 71 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 72 | + */ |
|
| 73 | + public function description(): string |
|
| 74 | + { |
|
| 75 | + return I18N::translate('Manage and run nearly-scheduled administration tasks.'); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * {@inheritDoc} |
|
| 80 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 81 | + */ |
|
| 82 | + public function boot(): void |
|
| 83 | + { |
|
| 84 | + $this->traitBoot(); |
|
| 85 | + app(MigrationService::class)->updateSchema( |
|
| 86 | + self::SCHEMA_MIGRATION_PREFIX, |
|
| 87 | + self::SCHEMA_SETTING_NAME, |
|
| 88 | + self::SCHEMA_TARGET_VERSION |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * {@inheritDoc} |
|
| 94 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 95 | + */ |
|
| 96 | + public function loadRoutes(Map $router): void |
|
| 97 | + { |
|
| 98 | + $router->attach('', '', static function (Map $router): void { |
|
| 99 | + |
|
| 100 | + $router->attach('', '/module-maj/admintasks', static function (Map $router): void { |
|
| 101 | + $router->tokens(['enable' => '[01]']); |
|
| 102 | + |
|
| 103 | + $router->attach('', '/admin', static function (Map $router): void { |
|
| 104 | + |
|
| 105 | + $router->extras([ |
|
| 106 | + 'middleware' => [ |
|
| 107 | + AuthAdministrator::class, |
|
| 108 | + ], |
|
| 109 | + ]); |
|
| 110 | + $router->get(AdminConfigPage::class, '/config', AdminConfigPage::class); |
|
| 111 | + |
|
| 112 | + $router->attach('', '/tasks', static function (Map $router): void { |
|
| 113 | + |
|
| 114 | + $router->get(TasksList::class, '', TasksList::class); |
|
| 115 | + $router->get(TaskEditPage::class, '/{task}', TaskEditPage::class); |
|
| 116 | + $router->post(TaskEditAction::class, '/{task}', TaskEditAction::class); |
|
| 117 | + $router->get(TaskStatusAction::class, '/{task}/status/{enable}', TaskStatusAction::class); |
|
| 118 | + }); |
|
| 119 | + }); |
|
| 120 | + |
|
| 121 | + $router->get(TaskTrigger::class, '/trigger{/task}', TaskTrigger::class) |
|
| 122 | + ->allows(RequestMethodInterface::METHOD_POST); |
|
| 123 | + |
|
| 124 | + $router->post(TokenGenerate::class, '/token', TokenGenerate::class) |
|
| 125 | + ->extras(['middleware' => [AuthAdministrator::class]]); |
|
| 126 | + }); |
|
| 127 | + }); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * {@inheritDoc} |
|
| 132 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleLatestVersion() |
|
| 133 | + */ |
|
| 134 | + public function customModuleVersion(): string |
|
| 135 | + { |
|
| 136 | + return '2.1.3-v.1'; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + /** |
|
| 140 | + * {@inheritDoc} |
|
| 141 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
| 142 | + */ |
|
| 143 | + public function getConfigLink(): string |
|
| 144 | + { |
|
| 145 | + return route(AdminConfigPage::class); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * {@inheritDoc} |
|
| 150 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent() |
|
| 151 | + */ |
|
| 152 | + public function bodyContent(): string |
|
| 153 | + { |
|
| 154 | + return view($this->name() . '::snippet', [ 'url' => route(TaskTrigger::class) ]); |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * {@inheritDoc} |
|
| 159 | + * @see ModuleTasksProviderInterface::listTasks() |
|
| 160 | + */ |
|
| 161 | + public function listTasks(): array |
|
| 162 | + { |
|
| 163 | + return [ |
|
| 164 | + 'maj-healthcheck' => HealthCheckEmailTask::class |
|
| 165 | + ]; |
|
| 166 | + } |
|
| 167 | 167 | } |
@@ -28,61 +28,61 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class SourceCertificate extends AbstractElement |
| 30 | 30 | { |
| 31 | - protected CertificatesModule $module; |
|
| 32 | - protected CertificateFilesystemService $certif_filesystem; |
|
| 33 | - protected UrlObfuscatorService $url_obfuscator_service; |
|
| 31 | + protected CertificatesModule $module; |
|
| 32 | + protected CertificateFilesystemService $certif_filesystem; |
|
| 33 | + protected UrlObfuscatorService $url_obfuscator_service; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Constructor for SourceCertificate element |
|
| 37 | - * |
|
| 38 | - * @param string $label |
|
| 39 | - * @param CertificatesModule $module |
|
| 40 | - * @param CertificateFilesystemService $certif_filesystem |
|
| 41 | - * @param UrlObfuscatorService $url_obfuscator_service |
|
| 42 | - */ |
|
| 43 | - public function __construct( |
|
| 44 | - string $label, |
|
| 45 | - CertificatesModule $module, |
|
| 46 | - CertificateFilesystemService $certif_filesystem = null, |
|
| 47 | - UrlObfuscatorService $url_obfuscator_service = null |
|
| 48 | - ) { |
|
| 49 | - parent::__construct($label, null); |
|
| 50 | - $this->module = $module; |
|
| 51 | - $this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class); |
|
| 52 | - $this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
| 53 | - } |
|
| 35 | + /** |
|
| 36 | + * Constructor for SourceCertificate element |
|
| 37 | + * |
|
| 38 | + * @param string $label |
|
| 39 | + * @param CertificatesModule $module |
|
| 40 | + * @param CertificateFilesystemService $certif_filesystem |
|
| 41 | + * @param UrlObfuscatorService $url_obfuscator_service |
|
| 42 | + */ |
|
| 43 | + public function __construct( |
|
| 44 | + string $label, |
|
| 45 | + CertificatesModule $module, |
|
| 46 | + CertificateFilesystemService $certif_filesystem = null, |
|
| 47 | + UrlObfuscatorService $url_obfuscator_service = null |
|
| 48 | + ) { |
|
| 49 | + parent::__construct($label, null); |
|
| 50 | + $this->module = $module; |
|
| 51 | + $this->certif_filesystem = $certif_filesystem ?? app(CertificateFilesystemService::class); |
|
| 52 | + $this->url_obfuscator_service = $url_obfuscator_service ?? app(UrlObfuscatorService::class); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * {@inheritDoc} |
|
| 57 | - * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
|
| 58 | - */ |
|
| 59 | - public function canonical(string $value): string |
|
| 60 | - { |
|
| 61 | - return strtr($value, '\\', '/'); |
|
| 62 | - } |
|
| 55 | + /** |
|
| 56 | + * {@inheritDoc} |
|
| 57 | + * @see \Fisharebest\Webtrees\Elements\AbstractElement::canonical() |
|
| 58 | + */ |
|
| 59 | + public function canonical(string $value): string |
|
| 60 | + { |
|
| 61 | + return strtr($value, '\\', '/'); |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * {@inheritDoc} |
|
| 66 | - * @see \Fisharebest\Webtrees\Elements\AbstractElement::edit() |
|
| 67 | - */ |
|
| 68 | - public function edit(string $id, string $name, string $value, Tree $tree): string |
|
| 69 | - { |
|
| 70 | - list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
|
| 64 | + /** |
|
| 65 | + * {@inheritDoc} |
|
| 66 | + * @see \Fisharebest\Webtrees\Elements\AbstractElement::edit() |
|
| 67 | + */ |
|
| 68 | + public function edit(string $id, string $name, string $value, Tree $tree): string |
|
| 69 | + { |
|
| 70 | + list($city, $file) = explode('/', $this->canonical($value), 2) + ['', '']; |
|
| 71 | 71 | |
| 72 | - $cities = array_map(function (string $item): array { |
|
| 73 | - return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
| 74 | - }, $this->certif_filesystem->cities($tree)); |
|
| 72 | + $cities = array_map(function (string $item): array { |
|
| 73 | + return [$this->url_obfuscator_service->obfuscate($item), $item]; |
|
| 74 | + }, $this->certif_filesystem->cities($tree)); |
|
| 75 | 75 | |
| 76 | - return view($this->module->name() . '::components/edit-certificate', [ |
|
| 77 | - 'module_name' => $this->module->name(), |
|
| 78 | - 'tree' => $tree, |
|
| 79 | - 'id' => $id, |
|
| 80 | - 'name' => $name, |
|
| 81 | - 'cities' => $cities, |
|
| 82 | - 'value' => $this->canonical($value), |
|
| 83 | - 'value_city' => $city, |
|
| 84 | - 'value_file' => $file, |
|
| 85 | - 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
| 86 | - ]); |
|
| 87 | - } |
|
| 76 | + return view($this->module->name() . '::components/edit-certificate', [ |
|
| 77 | + 'module_name' => $this->module->name(), |
|
| 78 | + 'tree' => $tree, |
|
| 79 | + 'id' => $id, |
|
| 80 | + 'name' => $name, |
|
| 81 | + 'cities' => $cities, |
|
| 82 | + 'value' => $this->canonical($value), |
|
| 83 | + 'value_city' => $city, |
|
| 84 | + 'value_file' => $file, |
|
| 85 | + 'js_script_url' => $this->module->assetUrl('js/certificates.min.js') |
|
| 86 | + ]); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -29,113 +29,113 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class MatomoStatsService |
| 31 | 31 | { |
| 32 | - protected ?HandlerStack $handler = null; |
|
| 32 | + protected ?HandlerStack $handler = null; |
|
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * Set or get the http handler for the service |
|
| 36 | - * |
|
| 37 | - * @param HandlerStack $handler |
|
| 38 | - * @return HandlerStack |
|
| 39 | - */ |
|
| 40 | - public function httpHandler(HandlerStack $handler = null): HandlerStack |
|
| 41 | - { |
|
| 42 | - if ($this->handler === null) { |
|
| 43 | - $this->handler = HandlerStack::create(); |
|
| 44 | - } |
|
| 45 | - if ($handler !== null) { |
|
| 46 | - $this->handler = $handler; |
|
| 47 | - } |
|
| 48 | - return $this->handler; |
|
| 49 | - } |
|
| 34 | + /** |
|
| 35 | + * Set or get the http handler for the service |
|
| 36 | + * |
|
| 37 | + * @param HandlerStack $handler |
|
| 38 | + * @return HandlerStack |
|
| 39 | + */ |
|
| 40 | + public function httpHandler(HandlerStack $handler = null): HandlerStack |
|
| 41 | + { |
|
| 42 | + if ($this->handler === null) { |
|
| 43 | + $this->handler = HandlerStack::create(); |
|
| 44 | + } |
|
| 45 | + if ($handler !== null) { |
|
| 46 | + $this->handler = $handler; |
|
| 47 | + } |
|
| 48 | + return $this->handler; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * Returns the number of visits for the current year (up to the day before). |
|
| 53 | - * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
| 54 | - * |
|
| 55 | - * @param WelcomeBlockModule $module |
|
| 56 | - * @param int $block_id |
|
| 57 | - * @return int|NULL |
|
| 58 | - */ |
|
| 59 | - public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
| 60 | - { |
|
| 61 | - return Registry::cache()->file()->remember( |
|
| 62 | - $module->name() . '-matomovisits-yearly-' . $block_id, |
|
| 63 | - function () use ($module, $block_id): ?int { |
|
| 64 | - $visits_year = $this->visits($module, $block_id, 'year'); |
|
| 65 | - if ($visits_year === null) { |
|
| 66 | - return null; |
|
| 67 | - } |
|
| 68 | - $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
| 51 | + /** |
|
| 52 | + * Returns the number of visits for the current year (up to the day before). |
|
| 53 | + * That statistic is cached for the day, to avoid unecessary calls to Matomo API. |
|
| 54 | + * |
|
| 55 | + * @param WelcomeBlockModule $module |
|
| 56 | + * @param int $block_id |
|
| 57 | + * @return int|NULL |
|
| 58 | + */ |
|
| 59 | + public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int |
|
| 60 | + { |
|
| 61 | + return Registry::cache()->file()->remember( |
|
| 62 | + $module->name() . '-matomovisits-yearly-' . $block_id, |
|
| 63 | + function () use ($module, $block_id): ?int { |
|
| 64 | + $visits_year = $this->visits($module, $block_id, 'year'); |
|
| 65 | + if ($visits_year === null) { |
|
| 66 | + return null; |
|
| 67 | + } |
|
| 68 | + $visits_today = (int) $this->visits($module, $block_id, 'day'); |
|
| 69 | 69 | |
| 70 | - return $visits_year - $visits_today; |
|
| 71 | - }, |
|
| 72 | - Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
| 73 | - ); |
|
| 74 | - } |
|
| 70 | + return $visits_year - $visits_today; |
|
| 71 | + }, |
|
| 72 | + Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Returns the number of visits for the current day. |
|
| 78 | - * |
|
| 79 | - * @param WelcomeBlockModule $module |
|
| 80 | - * @param int $block_id |
|
| 81 | - * @return int|NULL |
|
| 82 | - */ |
|
| 83 | - public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
| 84 | - { |
|
| 85 | - return Registry::cache()->array()->remember( |
|
| 86 | - $module->name() . '-matomovisits-daily-' . $block_id, |
|
| 87 | - function () use ($module, $block_id): ?int { |
|
| 88 | - return $this->visits($module, $block_id, 'day'); |
|
| 89 | - } |
|
| 90 | - ); |
|
| 91 | - } |
|
| 76 | + /** |
|
| 77 | + * Returns the number of visits for the current day. |
|
| 78 | + * |
|
| 79 | + * @param WelcomeBlockModule $module |
|
| 80 | + * @param int $block_id |
|
| 81 | + * @return int|NULL |
|
| 82 | + */ |
|
| 83 | + public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int |
|
| 84 | + { |
|
| 85 | + return Registry::cache()->array()->remember( |
|
| 86 | + $module->name() . '-matomovisits-daily-' . $block_id, |
|
| 87 | + function () use ($module, $block_id): ?int { |
|
| 88 | + return $this->visits($module, $block_id, 'day'); |
|
| 89 | + } |
|
| 90 | + ); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - /** |
|
| 94 | - * Invoke the Matomo API to retrieve the number of visits over a period. |
|
| 95 | - * |
|
| 96 | - * @param WelcomeBlockModule $module |
|
| 97 | - * @param int $block_id |
|
| 98 | - * @param string $period |
|
| 99 | - * @return int|NULL |
|
| 100 | - */ |
|
| 101 | - protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
| 102 | - { |
|
| 103 | - $settings = $module->matomoSettings($block_id); |
|
| 93 | + /** |
|
| 94 | + * Invoke the Matomo API to retrieve the number of visits over a period. |
|
| 95 | + * |
|
| 96 | + * @param WelcomeBlockModule $module |
|
| 97 | + * @param int $block_id |
|
| 98 | + * @param string $period |
|
| 99 | + * @return int|NULL |
|
| 100 | + */ |
|
| 101 | + protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int |
|
| 102 | + { |
|
| 103 | + $settings = $module->matomoSettings($block_id); |
|
| 104 | 104 | |
| 105 | - if ( |
|
| 106 | - $settings['matomo_enabled'] === true |
|
| 107 | - && mb_strlen($settings['matomo_url']) > 0 |
|
| 108 | - && mb_strlen($settings['matomo_token']) > 0 |
|
| 109 | - && $settings['matomo_siteid'] > 0 |
|
| 110 | - ) { |
|
| 111 | - try { |
|
| 112 | - $http_client = new Client([ |
|
| 113 | - RequestOptions::TIMEOUT => 30, |
|
| 114 | - 'handler' => $this->handler |
|
| 115 | - ]); |
|
| 105 | + if ( |
|
| 106 | + $settings['matomo_enabled'] === true |
|
| 107 | + && mb_strlen($settings['matomo_url']) > 0 |
|
| 108 | + && mb_strlen($settings['matomo_token']) > 0 |
|
| 109 | + && $settings['matomo_siteid'] > 0 |
|
| 110 | + ) { |
|
| 111 | + try { |
|
| 112 | + $http_client = new Client([ |
|
| 113 | + RequestOptions::TIMEOUT => 30, |
|
| 114 | + 'handler' => $this->handler |
|
| 115 | + ]); |
|
| 116 | 116 | |
| 117 | - $response = $http_client->get($settings['matomo_url'], [ |
|
| 118 | - 'query' => [ |
|
| 119 | - 'module' => 'API', |
|
| 120 | - 'method' => 'VisitsSummary.getVisits', |
|
| 121 | - 'idSite' => $settings['matomo_siteid'], |
|
| 122 | - 'period' => $period, |
|
| 123 | - 'date' => 'today', |
|
| 124 | - 'token_auth' => $settings['matomo_token'], |
|
| 125 | - 'format' => 'json' |
|
| 126 | - ] |
|
| 127 | - ]); |
|
| 117 | + $response = $http_client->get($settings['matomo_url'], [ |
|
| 118 | + 'query' => [ |
|
| 119 | + 'module' => 'API', |
|
| 120 | + 'method' => 'VisitsSummary.getVisits', |
|
| 121 | + 'idSite' => $settings['matomo_siteid'], |
|
| 122 | + 'period' => $period, |
|
| 123 | + 'date' => 'today', |
|
| 124 | + 'token_auth' => $settings['matomo_token'], |
|
| 125 | + 'format' => 'json' |
|
| 126 | + ] |
|
| 127 | + ]); |
|
| 128 | 128 | |
| 129 | - if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
| 130 | - $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
| 131 | - if ($result !== null) { |
|
| 132 | - return (int)$result; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } catch (GuzzleException $ex) { |
|
| 136 | - } |
|
| 137 | - } |
|
| 129 | + if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) { |
|
| 130 | + $result = json_decode((string) $response->getBody(), true)['value'] ?? null; |
|
| 131 | + if ($result !== null) { |
|
| 132 | + return (int)$result; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } catch (GuzzleException $ex) { |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - return null; |
|
| 140 | - } |
|
| 139 | + return null; |
|
| 140 | + } |
|
| 141 | 141 | } |
@@ -29,539 +29,539 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class SosaStatisticsService |
| 31 | 31 | { |
| 32 | - private UserInterface $user; |
|
| 33 | - private Tree $tree; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Constructor for Sosa Statistics Service |
|
| 37 | - * |
|
| 38 | - * @param Tree $tree |
|
| 39 | - * @param UserInterface $user |
|
| 40 | - */ |
|
| 41 | - public function __construct(Tree $tree, UserInterface $user) |
|
| 42 | - { |
|
| 43 | - $this->tree = $tree; |
|
| 44 | - $this->user = $user; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Check if PDO support the queries used in Sosa statistics. |
|
| 49 | - * |
|
| 50 | - * SQLite does not support RIGHT and FULL JOIN, and POWER/SQRT require a specific compilation flag. |
|
| 51 | - * |
|
| 52 | - * @return bool |
|
| 53 | - */ |
|
| 54 | - public function isPdoSupported(): bool |
|
| 55 | - { |
|
| 56 | - return DB::connection()->getDriverName() !== 'sqlite'; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Return the root individual for the reference tree and user. |
|
| 61 | - * |
|
| 62 | - * @return Individual|NULL |
|
| 63 | - */ |
|
| 64 | - public function rootIndividual(): ?Individual |
|
| 65 | - { |
|
| 66 | - $root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
| 67 | - return Registry::individualFactory()->make($root_indi_id, $this->tree); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Get the highest generation for the reference tree and user. |
|
| 72 | - * |
|
| 73 | - * @return int |
|
| 74 | - */ |
|
| 75 | - public function maxGeneration(): int |
|
| 76 | - { |
|
| 77 | - return (int) DB::table('maj_sosa') |
|
| 78 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 79 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 80 | - ->max('majs_gen'); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * Get the total count of individuals in the tree. |
|
| 85 | - * |
|
| 86 | - * @return int |
|
| 87 | - */ |
|
| 88 | - public function totalIndividuals(): int |
|
| 89 | - { |
|
| 90 | - return DB::table('individuals') |
|
| 91 | - ->where('i_file', '=', $this->tree->id()) |
|
| 92 | - ->count(); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Get the total count of Sosa ancestors for all generations |
|
| 97 | - * |
|
| 98 | - * @return int |
|
| 99 | - */ |
|
| 100 | - public function totalAncestors(): int |
|
| 101 | - { |
|
| 102 | - return DB::table('maj_sosa') |
|
| 103 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 104 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 105 | - ->count(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Get the total count of Sosa ancestors for a generation |
|
| 110 | - * |
|
| 111 | - * @return int |
|
| 112 | - */ |
|
| 113 | - public function totalAncestorsAtGeneration(int $gen): int |
|
| 114 | - { |
|
| 115 | - return DB::table('maj_sosa') |
|
| 116 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 117 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 118 | - ->where('majs_gen', '=', $gen) |
|
| 119 | - ->count(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Get the total count of distinct Sosa ancestors for all generations |
|
| 124 | - * |
|
| 125 | - * @return int |
|
| 126 | - */ |
|
| 127 | - public function totalDistinctAncestors(): int |
|
| 128 | - { |
|
| 129 | - return DB::table('maj_sosa') |
|
| 130 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 131 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 132 | - ->distinct() |
|
| 133 | - ->count('majs_i_id'); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Get the mean generation time, as the slope of the linear regression of birth years vs generations |
|
| 138 | - * |
|
| 139 | - * @return float |
|
| 140 | - */ |
|
| 141 | - public function meanGenerationTime(): float |
|
| 142 | - { |
|
| 143 | - $row = DB::table('maj_sosa') |
|
| 144 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 145 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 146 | - ->whereNotNull('majs_birth_year') |
|
| 147 | - ->selectRaw('COUNT(majs_sosa) AS n') |
|
| 148 | - ->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy') |
|
| 149 | - ->selectRaw('SUM(majs_gen) AS sum_x') |
|
| 150 | - ->selectRaw('SUM(majs_birth_year) AS sum_y') |
|
| 151 | - ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2') |
|
| 152 | - ->get()->first(); |
|
| 153 | - |
|
| 154 | - $denom = $row->n * $row->sum_x2 - pow($row->sum_x, 2); |
|
| 155 | - return ((int) $row->n === 0 || $denom === 0) ? 0 : |
|
| 156 | - -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / $denom; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Get the statistic array detailed by generation. |
|
| 161 | - * Statistics for each generation are: |
|
| 162 | - * - The number of Sosa in generation |
|
| 163 | - * - The number of Sosa up to generation |
|
| 164 | - * - The number of distinct Sosa up to generation |
|
| 165 | - * - The year of the first birth in generation |
|
| 166 | - * - The year of the first estimated birth in generation |
|
| 167 | - * - The year of the last birth in generation |
|
| 168 | - * - The year of the last estimated birth in generation |
|
| 169 | - * - The average year of birth in generation |
|
| 170 | - * |
|
| 171 | - * @return array<int, array<string, int|null>> Statistics array |
|
| 172 | - */ |
|
| 173 | - public function statisticsByGenerations(): array |
|
| 174 | - { |
|
| 175 | - $stats_by_gen = $this->statisticsByGenerationBasicData(); |
|
| 176 | - $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData(); |
|
| 177 | - |
|
| 178 | - $statistics_by_gen = []; |
|
| 179 | - foreach ($stats_by_gen as $gen => $stats_gen) { |
|
| 180 | - $statistics_by_gen[(int) $stats_gen->gen] = array( |
|
| 181 | - 'sosaCount' => (int) $stats_gen->total_sosa, |
|
| 182 | - 'sosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_cumul, |
|
| 183 | - 'diffSosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
| 184 | - 'firstBirth' => $stats_gen->first_year, |
|
| 185 | - 'firstEstimatedBirth' => $stats_gen->first_est_year, |
|
| 186 | - 'lastBirth' => $stats_gen->last_year, |
|
| 187 | - 'lastEstimatedBirth' => $stats_gen->last_est_year |
|
| 188 | - ); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return $statistics_by_gen; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Returns the basic statistics data by generation. |
|
| 196 | - * |
|
| 197 | - * @return Collection<int, \stdClass> |
|
| 198 | - */ |
|
| 199 | - private function statisticsByGenerationBasicData(): Collection |
|
| 200 | - { |
|
| 201 | - return DB::table('maj_sosa') |
|
| 202 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 203 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 204 | - ->groupBy('majs_gen') |
|
| 205 | - ->orderBy('majs_gen', 'asc') |
|
| 206 | - ->select('majs_gen AS gen') |
|
| 207 | - ->selectRaw('COUNT(majs_sosa) AS total_sosa') |
|
| 208 | - ->selectRaw('MIN(majs_birth_year) AS first_year') |
|
| 209 | - ->selectRaw('MIN(majs_birth_year_est) AS first_est_year') |
|
| 210 | - ->selectRaw('MAX(majs_birth_year) AS last_year') |
|
| 211 | - ->selectRaw('MAX(majs_birth_year_est) AS last_est_year') |
|
| 212 | - ->get()->keyBy('gen'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Returns the cumulative statistics data by generation |
|
| 217 | - * |
|
| 218 | - * @return Collection<int, \stdClass> |
|
| 219 | - */ |
|
| 220 | - private function statisticsByGenerationCumulativeData(): Collection |
|
| 221 | - { |
|
| 222 | - $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
| 223 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 224 | - ->where('majs_user_id', '=', $this->user->id()); |
|
| 225 | - |
|
| 226 | - return DB::table('maj_sosa') |
|
| 227 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 228 | - $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen') |
|
| 229 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 230 | - ->where('majs_user_id', '=', $this->user->id()); |
|
| 231 | - }) |
|
| 232 | - ->groupBy('list_gen.majs_gen') |
|
| 233 | - ->select('list_gen.majs_gen AS gen') |
|
| 234 | - ->selectRaw('COUNT(majs_i_id) AS total_cumul') |
|
| 235 | - ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul') |
|
| 236 | - ->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple') |
|
| 237 | - ->get()->keyBy('gen'); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Returns the pedigree collapse improved calculation by generation. |
|
| 242 | - * |
|
| 243 | - * Format: |
|
| 244 | - * - key : generation |
|
| 245 | - * - values: |
|
| 246 | - * - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation |
|
| 247 | - * - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation |
|
| 248 | - * |
|
| 249 | - * @return array<int, array<string, float>> |
|
| 250 | - */ |
|
| 251 | - public function pedigreeCollapseByGenerationData(): array |
|
| 252 | - { |
|
| 253 | - if (!$this->isPdoSupported()) { |
|
| 254 | - return []; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 258 | - |
|
| 259 | - $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
| 260 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 261 | - ->where('majs_user_id', '=', $this->user->id()); |
|
| 262 | - |
|
| 263 | - /* Compute the contributions of nodes of previous generations to the current generation */ |
|
| 264 | - $root_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
| 265 | - ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
| 266 | - ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
| 267 | - ->selectRaw( |
|
| 268 | - '(CASE ' . |
|
| 269 | - ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' . |
|
| 270 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 271 | - ' ELSE 0 ' . |
|
| 272 | - ' END)' . |
|
| 273 | - ' + (CASE ' . |
|
| 274 | - ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' . |
|
| 275 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 276 | - ' ELSE 0 ' . |
|
| 277 | - ' END) contrib' |
|
| 278 | - ) |
|
| 279 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 280 | - $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen') |
|
| 281 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 282 | - ->where('majs_user_id', '=', $this->user->id()); |
|
| 283 | - }) |
|
| 284 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 285 | - // Link to sosa's father |
|
| 286 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 287 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 288 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 289 | - }) |
|
| 290 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 291 | - // Link to sosa's mother |
|
| 292 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 293 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 294 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 295 | - }) |
|
| 296 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 297 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 298 | - ->where(function (Builder $query): void { |
|
| 299 | - $query->whereNull('sosa_fat.majs_i_id') |
|
| 300 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 301 | - }); |
|
| 302 | - |
|
| 303 | - /* Identify nodes in the generations with ancestors who are also in the same generation. |
|
| 32 | + private UserInterface $user; |
|
| 33 | + private Tree $tree; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Constructor for Sosa Statistics Service |
|
| 37 | + * |
|
| 38 | + * @param Tree $tree |
|
| 39 | + * @param UserInterface $user |
|
| 40 | + */ |
|
| 41 | + public function __construct(Tree $tree, UserInterface $user) |
|
| 42 | + { |
|
| 43 | + $this->tree = $tree; |
|
| 44 | + $this->user = $user; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Check if PDO support the queries used in Sosa statistics. |
|
| 49 | + * |
|
| 50 | + * SQLite does not support RIGHT and FULL JOIN, and POWER/SQRT require a specific compilation flag. |
|
| 51 | + * |
|
| 52 | + * @return bool |
|
| 53 | + */ |
|
| 54 | + public function isPdoSupported(): bool |
|
| 55 | + { |
|
| 56 | + return DB::connection()->getDriverName() !== 'sqlite'; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Return the root individual for the reference tree and user. |
|
| 61 | + * |
|
| 62 | + * @return Individual|NULL |
|
| 63 | + */ |
|
| 64 | + public function rootIndividual(): ?Individual |
|
| 65 | + { |
|
| 66 | + $root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
| 67 | + return Registry::individualFactory()->make($root_indi_id, $this->tree); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Get the highest generation for the reference tree and user. |
|
| 72 | + * |
|
| 73 | + * @return int |
|
| 74 | + */ |
|
| 75 | + public function maxGeneration(): int |
|
| 76 | + { |
|
| 77 | + return (int) DB::table('maj_sosa') |
|
| 78 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 79 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 80 | + ->max('majs_gen'); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * Get the total count of individuals in the tree. |
|
| 85 | + * |
|
| 86 | + * @return int |
|
| 87 | + */ |
|
| 88 | + public function totalIndividuals(): int |
|
| 89 | + { |
|
| 90 | + return DB::table('individuals') |
|
| 91 | + ->where('i_file', '=', $this->tree->id()) |
|
| 92 | + ->count(); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Get the total count of Sosa ancestors for all generations |
|
| 97 | + * |
|
| 98 | + * @return int |
|
| 99 | + */ |
|
| 100 | + public function totalAncestors(): int |
|
| 101 | + { |
|
| 102 | + return DB::table('maj_sosa') |
|
| 103 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 104 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 105 | + ->count(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Get the total count of Sosa ancestors for a generation |
|
| 110 | + * |
|
| 111 | + * @return int |
|
| 112 | + */ |
|
| 113 | + public function totalAncestorsAtGeneration(int $gen): int |
|
| 114 | + { |
|
| 115 | + return DB::table('maj_sosa') |
|
| 116 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 117 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 118 | + ->where('majs_gen', '=', $gen) |
|
| 119 | + ->count(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Get the total count of distinct Sosa ancestors for all generations |
|
| 124 | + * |
|
| 125 | + * @return int |
|
| 126 | + */ |
|
| 127 | + public function totalDistinctAncestors(): int |
|
| 128 | + { |
|
| 129 | + return DB::table('maj_sosa') |
|
| 130 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 131 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 132 | + ->distinct() |
|
| 133 | + ->count('majs_i_id'); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Get the mean generation time, as the slope of the linear regression of birth years vs generations |
|
| 138 | + * |
|
| 139 | + * @return float |
|
| 140 | + */ |
|
| 141 | + public function meanGenerationTime(): float |
|
| 142 | + { |
|
| 143 | + $row = DB::table('maj_sosa') |
|
| 144 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 145 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 146 | + ->whereNotNull('majs_birth_year') |
|
| 147 | + ->selectRaw('COUNT(majs_sosa) AS n') |
|
| 148 | + ->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy') |
|
| 149 | + ->selectRaw('SUM(majs_gen) AS sum_x') |
|
| 150 | + ->selectRaw('SUM(majs_birth_year) AS sum_y') |
|
| 151 | + ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2') |
|
| 152 | + ->get()->first(); |
|
| 153 | + |
|
| 154 | + $denom = $row->n * $row->sum_x2 - pow($row->sum_x, 2); |
|
| 155 | + return ((int) $row->n === 0 || $denom === 0) ? 0 : |
|
| 156 | + -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / $denom; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Get the statistic array detailed by generation. |
|
| 161 | + * Statistics for each generation are: |
|
| 162 | + * - The number of Sosa in generation |
|
| 163 | + * - The number of Sosa up to generation |
|
| 164 | + * - The number of distinct Sosa up to generation |
|
| 165 | + * - The year of the first birth in generation |
|
| 166 | + * - The year of the first estimated birth in generation |
|
| 167 | + * - The year of the last birth in generation |
|
| 168 | + * - The year of the last estimated birth in generation |
|
| 169 | + * - The average year of birth in generation |
|
| 170 | + * |
|
| 171 | + * @return array<int, array<string, int|null>> Statistics array |
|
| 172 | + */ |
|
| 173 | + public function statisticsByGenerations(): array |
|
| 174 | + { |
|
| 175 | + $stats_by_gen = $this->statisticsByGenerationBasicData(); |
|
| 176 | + $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData(); |
|
| 177 | + |
|
| 178 | + $statistics_by_gen = []; |
|
| 179 | + foreach ($stats_by_gen as $gen => $stats_gen) { |
|
| 180 | + $statistics_by_gen[(int) $stats_gen->gen] = array( |
|
| 181 | + 'sosaCount' => (int) $stats_gen->total_sosa, |
|
| 182 | + 'sosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_cumul, |
|
| 183 | + 'diffSosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
| 184 | + 'firstBirth' => $stats_gen->first_year, |
|
| 185 | + 'firstEstimatedBirth' => $stats_gen->first_est_year, |
|
| 186 | + 'lastBirth' => $stats_gen->last_year, |
|
| 187 | + 'lastEstimatedBirth' => $stats_gen->last_est_year |
|
| 188 | + ); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return $statistics_by_gen; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Returns the basic statistics data by generation. |
|
| 196 | + * |
|
| 197 | + * @return Collection<int, \stdClass> |
|
| 198 | + */ |
|
| 199 | + private function statisticsByGenerationBasicData(): Collection |
|
| 200 | + { |
|
| 201 | + return DB::table('maj_sosa') |
|
| 202 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 203 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 204 | + ->groupBy('majs_gen') |
|
| 205 | + ->orderBy('majs_gen', 'asc') |
|
| 206 | + ->select('majs_gen AS gen') |
|
| 207 | + ->selectRaw('COUNT(majs_sosa) AS total_sosa') |
|
| 208 | + ->selectRaw('MIN(majs_birth_year) AS first_year') |
|
| 209 | + ->selectRaw('MIN(majs_birth_year_est) AS first_est_year') |
|
| 210 | + ->selectRaw('MAX(majs_birth_year) AS last_year') |
|
| 211 | + ->selectRaw('MAX(majs_birth_year_est) AS last_est_year') |
|
| 212 | + ->get()->keyBy('gen'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Returns the cumulative statistics data by generation |
|
| 217 | + * |
|
| 218 | + * @return Collection<int, \stdClass> |
|
| 219 | + */ |
|
| 220 | + private function statisticsByGenerationCumulativeData(): Collection |
|
| 221 | + { |
|
| 222 | + $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
| 223 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 224 | + ->where('majs_user_id', '=', $this->user->id()); |
|
| 225 | + |
|
| 226 | + return DB::table('maj_sosa') |
|
| 227 | + ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 228 | + $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen') |
|
| 229 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 230 | + ->where('majs_user_id', '=', $this->user->id()); |
|
| 231 | + }) |
|
| 232 | + ->groupBy('list_gen.majs_gen') |
|
| 233 | + ->select('list_gen.majs_gen AS gen') |
|
| 234 | + ->selectRaw('COUNT(majs_i_id) AS total_cumul') |
|
| 235 | + ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul') |
|
| 236 | + ->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple') |
|
| 237 | + ->get()->keyBy('gen'); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Returns the pedigree collapse improved calculation by generation. |
|
| 242 | + * |
|
| 243 | + * Format: |
|
| 244 | + * - key : generation |
|
| 245 | + * - values: |
|
| 246 | + * - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation |
|
| 247 | + * - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation |
|
| 248 | + * |
|
| 249 | + * @return array<int, array<string, float>> |
|
| 250 | + */ |
|
| 251 | + public function pedigreeCollapseByGenerationData(): array |
|
| 252 | + { |
|
| 253 | + if (!$this->isPdoSupported()) { |
|
| 254 | + return []; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 258 | + |
|
| 259 | + $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct() |
|
| 260 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 261 | + ->where('majs_user_id', '=', $this->user->id()); |
|
| 262 | + |
|
| 263 | + /* Compute the contributions of nodes of previous generations to the current generation */ |
|
| 264 | + $root_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
| 265 | + ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
| 266 | + ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
| 267 | + ->selectRaw( |
|
| 268 | + '(CASE ' . |
|
| 269 | + ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' . |
|
| 270 | + ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 271 | + ' ELSE 0 ' . |
|
| 272 | + ' END)' . |
|
| 273 | + ' + (CASE ' . |
|
| 274 | + ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' . |
|
| 275 | + ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 276 | + ' ELSE 0 ' . |
|
| 277 | + ' END) contrib' |
|
| 278 | + ) |
|
| 279 | + ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 280 | + $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen') |
|
| 281 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 282 | + ->where('majs_user_id', '=', $this->user->id()); |
|
| 283 | + }) |
|
| 284 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 285 | + // Link to sosa's father |
|
| 286 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 287 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 288 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 289 | + }) |
|
| 290 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 291 | + // Link to sosa's mother |
|
| 292 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 293 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 294 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 295 | + }) |
|
| 296 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 297 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 298 | + ->where(function (Builder $query): void { |
|
| 299 | + $query->whereNull('sosa_fat.majs_i_id') |
|
| 300 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 301 | + }); |
|
| 302 | + |
|
| 303 | + /* Identify nodes in the generations with ancestors who are also in the same generation. |
|
| 304 | 304 | * This is the vertical/generational collapse that will reduce the number or roots. |
| 305 | 305 | */ |
| 306 | - $non_roots_ancestors = DB::table('maj_sosa AS sosa') |
|
| 307 | - ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa']) |
|
| 308 | - ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' . |
|
| 309 | - ' AS full_ancestors') |
|
| 310 | - ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void { |
|
| 311 | - $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen') |
|
| 312 | - ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' . |
|
| 313 | - $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' . |
|
| 314 | - $table_prefix . 'sosa.majs_sosa') |
|
| 315 | - ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id()) |
|
| 316 | - ->where('sosa_anc.majs_user_id', '=', $this->user->id()); |
|
| 317 | - }) |
|
| 318 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 319 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 320 | - ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void { |
|
| 321 | - $query->from('maj_sosa AS sosa_gen') |
|
| 322 | - ->select('sosa_gen.majs_i_id')->distinct() |
|
| 323 | - ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id()) |
|
| 324 | - ->where('sosa_gen.majs_user_id', '=', $this->user->id()) |
|
| 325 | - ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen'); |
|
| 326 | - }) |
|
| 327 | - ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', |
|
| 328 | - 'sosa.majs_sosa', 'sosa.majs_i_id']); |
|
| 329 | - |
|
| 330 | - /* Compute the contribution of the nodes in the generation, |
|
| 306 | + $non_roots_ancestors = DB::table('maj_sosa AS sosa') |
|
| 307 | + ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa']) |
|
| 308 | + ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' . |
|
| 309 | + ' AS full_ancestors') |
|
| 310 | + ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void { |
|
| 311 | + $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen') |
|
| 312 | + ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' . |
|
| 313 | + $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' . |
|
| 314 | + $table_prefix . 'sosa.majs_sosa') |
|
| 315 | + ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id()) |
|
| 316 | + ->where('sosa_anc.majs_user_id', '=', $this->user->id()); |
|
| 317 | + }) |
|
| 318 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 319 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 320 | + ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void { |
|
| 321 | + $query->from('maj_sosa AS sosa_gen') |
|
| 322 | + ->select('sosa_gen.majs_i_id')->distinct() |
|
| 323 | + ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id()) |
|
| 324 | + ->where('sosa_gen.majs_user_id', '=', $this->user->id()) |
|
| 325 | + ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen'); |
|
| 326 | + }) |
|
| 327 | + ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', |
|
| 328 | + 'sosa.majs_sosa', 'sosa.majs_i_id']); |
|
| 329 | + |
|
| 330 | + /* Compute the contribution of the nodes in the generation, |
|
| 331 | 331 | * excluding the nodes with ancestors in the same generation. |
| 332 | 332 | * Nodes with a parent missing are not excluded to cater for the missing one. |
| 333 | 333 | */ |
| 334 | - $known_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
| 335 | - ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
| 336 | - ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
| 337 | - ->selectRaw('1 AS contrib') |
|
| 338 | - ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void { |
|
| 339 | - $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen') |
|
| 340 | - ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa') |
|
| 341 | - ->where('nonroot.full_ancestors', '>', 0) |
|
| 342 | - ->where('nonroot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 343 | - ->where('nonroot.majs_user_id', '=', $this->user->id()); |
|
| 344 | - }) |
|
| 345 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 346 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 347 | - ->whereNull('nonroot.majs_sosa'); |
|
| 348 | - |
|
| 349 | - /* Aggregate both queries, and calculate the sum of contributions by generation roots. |
|
| 334 | + $known_ancestors_contributions = DB::table('maj_sosa AS sosa') |
|
| 335 | + ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
|
| 336 | + ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
|
| 337 | + ->selectRaw('1 AS contrib') |
|
| 338 | + ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void { |
|
| 339 | + $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen') |
|
| 340 | + ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa') |
|
| 341 | + ->where('nonroot.full_ancestors', '>', 0) |
|
| 342 | + ->where('nonroot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 343 | + ->where('nonroot.majs_user_id', '=', $this->user->id()); |
|
| 344 | + }) |
|
| 345 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 346 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 347 | + ->whereNull('nonroot.majs_sosa'); |
|
| 348 | + |
|
| 349 | + /* Aggregate both queries, and calculate the sum of contributions by generation roots. |
|
| 350 | 350 | * Exclude as well nodes that already appear in lower generations, as their branche has already been reduced. |
| 351 | 351 | */ |
| 352 | - $ancestors_contributions_sum = DB::connection()->query() |
|
| 353 | - ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs') |
|
| 354 | - ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id']) |
|
| 355 | - ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib']) |
|
| 356 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' . |
|
| 357 | - $table_prefix . 'sosa_contribs.contrib AS totalContrib') |
|
| 358 | - ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void { |
|
| 359 | - $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen') |
|
| 360 | - ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id') |
|
| 361 | - ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id()) |
|
| 362 | - ->where('sosa_low.majs_user_id', '=', $this->user->id()); |
|
| 363 | - }) |
|
| 364 | - ->whereNull('sosa_low.majs_sosa') |
|
| 365 | - ->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id', |
|
| 366 | - 'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']); |
|
| 367 | - |
|
| 368 | - // Aggregate all generation roots to compute root and generation pedigree collapse |
|
| 369 | - $pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum') |
|
| 370 | - ->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)') |
|
| 371 | - ->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots') // Roots/horizontal collapse |
|
| 372 | - ->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse |
|
| 373 | - ->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id']) |
|
| 374 | - ->orderBy('gen') |
|
| 375 | - ->get(); |
|
| 376 | - |
|
| 377 | - $pedi_collapse_by_gen = []; |
|
| 378 | - foreach ($pedi_collapse_coll as $collapse_gen) { |
|
| 379 | - $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array( |
|
| 380 | - 'pedi_collapse_roots' => (float) $collapse_gen->pedi_collapse_roots, |
|
| 381 | - 'pedi_collapse_xgen' => (float) $collapse_gen->pedi_collapse_xgen |
|
| 382 | - ); |
|
| 383 | - } |
|
| 384 | - return $pedi_collapse_by_gen; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation. |
|
| 389 | - * Sosa 1 is of generation 1. |
|
| 390 | - * |
|
| 391 | - * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes, |
|
| 392 | - * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140 |
|
| 393 | - * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0 |
|
| 394 | - * |
|
| 395 | - * Format: |
|
| 396 | - * - key : sosa number of the ancestor |
|
| 397 | - * - values: |
|
| 398 | - * - root_ancestor_id : ID of the ancestor |
|
| 399 | - * - mean_gen_depth : Mean generation depth |
|
| 400 | - * - stddev_gen_depth : Standard deviation of generation depth |
|
| 401 | - * |
|
| 402 | - * @param int $gen Sosa generation |
|
| 403 | - * @return Collection<int, \stdClass> |
|
| 404 | - */ |
|
| 405 | - public function generationDepthStatsAtGeneration(int $gen): Collection |
|
| 406 | - { |
|
| 407 | - if (!$this->isPdoSupported()) { |
|
| 408 | - return collect(); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 412 | - $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa') |
|
| 413 | - ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
| 414 | - ->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 |
|
| 415 | - ->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 |
|
| 416 | - ->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 |
|
| 417 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 418 | - // Link to sosa's father |
|
| 419 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 420 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 421 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 422 | - }) |
|
| 423 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 424 | - // Link to sosa's mother |
|
| 425 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 426 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 427 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 428 | - }) |
|
| 429 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 430 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 431 | - ->where('sosa.majs_gen', '>=', $gen) |
|
| 432 | - ->where(function (Builder $query): void { |
|
| 433 | - $query->whereNull('sosa_fat.majs_i_id') |
|
| 434 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 435 | - }) |
|
| 436 | - ->groupBy(['sosa.majs_gen', 'root_ancestor']); |
|
| 437 | - |
|
| 438 | - return DB::table('maj_sosa AS sosa_list') |
|
| 439 | - ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id']) |
|
| 440 | - ->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 |
|
| 441 | - ->selectRaw(' SQRT(' . |
|
| 442 | - ' 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 |
|
| 443 | - ' - 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 |
|
| 444 | - ' ) AS stddev_gen_depth') |
|
| 445 | - ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void { |
|
| 446 | - $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor') |
|
| 447 | - ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id()) |
|
| 448 | - ->where('sosa_list.majs_user_id', '=', $this->user->id()); |
|
| 449 | - }) |
|
| 450 | - ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id']) |
|
| 451 | - ->orderBy('stats_by_gen.root_ancestor') |
|
| 452 | - ->get()->keyBy('root_ancestor_sosa'); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * Return a collection of the most duplicated root Sosa ancestors. |
|
| 457 | - * The number of ancestors to return is limited by the parameter $limit. |
|
| 458 | - * If several individuals are tied when reaching the limit, none of them are returned, |
|
| 459 | - * which means that there can be less individuals returned than requested. |
|
| 460 | - * |
|
| 461 | - * Format: |
|
| 462 | - * - value: |
|
| 463 | - * - sosa_i_id : sosa individual |
|
| 464 | - * - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
| 465 | - * |
|
| 466 | - * @param int $limit |
|
| 467 | - * @return Collection<\stdClass> |
|
| 468 | - */ |
|
| 469 | - public function topMultipleAncestorsWithNoTies(int $limit): Collection |
|
| 470 | - { |
|
| 471 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 472 | - $multiple_ancestors = DB::table('maj_sosa AS sosa') |
|
| 473 | - ->select('sosa.majs_i_id AS sosa_i_id') |
|
| 474 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count') |
|
| 475 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 476 | - // Link to sosa's father |
|
| 477 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 478 | - ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 479 | - ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 480 | - }) |
|
| 481 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 482 | - // Link to sosa's mother |
|
| 483 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 484 | - ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 485 | - ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 486 | - }) |
|
| 487 | - ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 488 | - ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 489 | - ->whereNull('sosa_fat.majs_sosa') // We keep only root individuals, i.e. those with no father or mother |
|
| 490 | - ->whereNull('sosa_mot.majs_sosa') |
|
| 491 | - ->groupBy('sosa.majs_i_id') |
|
| 492 | - ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
| 493 | - ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 494 | - ->limit($limit + 1) // We want to select one more than required, for ties |
|
| 495 | - ->get(); |
|
| 496 | - |
|
| 497 | - if ($multiple_ancestors->count() > $limit) { |
|
| 498 | - $last_count = $multiple_ancestors->last()->sosa_count; |
|
| 499 | - $multiple_ancestors = $multiple_ancestors->reject( |
|
| 500 | - fn (stdClass $element): bool => $element->sosa_count === $last_count |
|
| 501 | - ); |
|
| 502 | - } |
|
| 503 | - return $multiple_ancestors; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
| 508 | - * at a specified generation. |
|
| 509 | - * |
|
| 510 | - * Format: |
|
| 511 | - * - key : rank of the ancestor in generation G for which exclusive ancestors have been found |
|
| 512 | - * For instance 3 represent the maternal grand father |
|
| 513 | - * 0 is used for shared ancestors |
|
| 514 | - * - values: |
|
| 515 | - * - branches: same as key |
|
| 516 | - * - majs_i_id: xref of the ancestor at rank key in generation G, or null for shared ancestors |
|
| 517 | - * - count_indi: number of ancestors exclusively in the ancestors of the ancestor at rank key |
|
| 518 | - * |
|
| 519 | - * For instance a result at generation 3 could be : |
|
| 520 | - * [ |
|
| 521 | - * 0 => { branches: 0, majs_i_id: X1, count_indi: 12 } -> 12 ancestors are shared by the grand-parents |
|
| 522 | - * 1 => { branches: 1, majs_i_id: X2, count_indi: 32 } -> 32 ancestors are exclusive to the paternal grand-father |
|
| 523 | - * 2 => { branches: 2, majs_i_id: X3, count_indi: 25 } -> 25 ancestors are exclusive to the paternal grand-mother |
|
| 524 | - * 3 => { branches: 3, majs_i_id: X4, count_indi: 12 } -> 12 ancestors are exclusive to the maternal grand-father |
|
| 525 | - * 4 => { branches: 4, majs_i_id: X5, count_indi: 30 } -> 30 ancestors are exclusive to the maternal grand-mother |
|
| 526 | - * ] |
|
| 527 | - * |
|
| 528 | - * @param int $gen |
|
| 529 | - * @return Collection<int, \stdClass> |
|
| 530 | - */ |
|
| 531 | - public function ancestorsDispersionForGeneration(int $gen): Collection |
|
| 532 | - { |
|
| 533 | - if (!$this->isPdoSupported()) { |
|
| 534 | - return collect(); |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - $ancestors_branches = DB::table('maj_sosa') |
|
| 538 | - ->select('majs_i_id AS i_id') |
|
| 539 | - ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen]) |
|
| 540 | - ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 541 | - ->where('majs_user_id', '=', $this->user->id()) |
|
| 542 | - ->where('majs_gen', '>=', $gen) |
|
| 543 | - ->groupBy('majs_i_id', 'branch'); |
|
| 544 | - |
|
| 545 | - $consolidated_ancestors_branches = DB::table('maj_sosa') |
|
| 546 | - ->fromSub($ancestors_branches, 'indi_branch') |
|
| 547 | - ->select('i_id') |
|
| 548 | - ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches') |
|
| 549 | - ->groupBy('i_id'); |
|
| 550 | - |
|
| 551 | - return DB::table('maj_sosa') |
|
| 552 | - ->rightJoinSub( |
|
| 553 | - $consolidated_ancestors_branches, |
|
| 554 | - 'indi_branch_consolidated', |
|
| 555 | - function (JoinClause $join) use ($gen): void { |
|
| 556 | - $join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 557 | - ->where('maj_sosa.majs_user_id', '=', $this->user->id()) |
|
| 558 | - ->where('branches', '>', 0) |
|
| 559 | - ->whereRaw('majs_sosa = POW(2, ? - 1) + branches - 1', [$gen]); |
|
| 560 | - } |
|
| 561 | - ) |
|
| 562 | - ->select(['branches', 'majs_i_id']) |
|
| 563 | - ->selectRaw('COUNT(i_id) AS count_indi') |
|
| 564 | - ->groupBy(['branches', 'majs_i_id']) |
|
| 565 | - ->get()->keyBy('branches'); |
|
| 566 | - } |
|
| 352 | + $ancestors_contributions_sum = DB::connection()->query() |
|
| 353 | + ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs') |
|
| 354 | + ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id']) |
|
| 355 | + ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib']) |
|
| 356 | + ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' . |
|
| 357 | + $table_prefix . 'sosa_contribs.contrib AS totalContrib') |
|
| 358 | + ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void { |
|
| 359 | + $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen') |
|
| 360 | + ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id') |
|
| 361 | + ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id()) |
|
| 362 | + ->where('sosa_low.majs_user_id', '=', $this->user->id()); |
|
| 363 | + }) |
|
| 364 | + ->whereNull('sosa_low.majs_sosa') |
|
| 365 | + ->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id', |
|
| 366 | + 'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']); |
|
| 367 | + |
|
| 368 | + // Aggregate all generation roots to compute root and generation pedigree collapse |
|
| 369 | + $pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum') |
|
| 370 | + ->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)') |
|
| 371 | + ->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots') // Roots/horizontal collapse |
|
| 372 | + ->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse |
|
| 373 | + ->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id']) |
|
| 374 | + ->orderBy('gen') |
|
| 375 | + ->get(); |
|
| 376 | + |
|
| 377 | + $pedi_collapse_by_gen = []; |
|
| 378 | + foreach ($pedi_collapse_coll as $collapse_gen) { |
|
| 379 | + $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array( |
|
| 380 | + 'pedi_collapse_roots' => (float) $collapse_gen->pedi_collapse_roots, |
|
| 381 | + 'pedi_collapse_xgen' => (float) $collapse_gen->pedi_collapse_xgen |
|
| 382 | + ); |
|
| 383 | + } |
|
| 384 | + return $pedi_collapse_by_gen; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation. |
|
| 389 | + * Sosa 1 is of generation 1. |
|
| 390 | + * |
|
| 391 | + * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes, |
|
| 392 | + * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140 |
|
| 393 | + * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0 |
|
| 394 | + * |
|
| 395 | + * Format: |
|
| 396 | + * - key : sosa number of the ancestor |
|
| 397 | + * - values: |
|
| 398 | + * - root_ancestor_id : ID of the ancestor |
|
| 399 | + * - mean_gen_depth : Mean generation depth |
|
| 400 | + * - stddev_gen_depth : Standard deviation of generation depth |
|
| 401 | + * |
|
| 402 | + * @param int $gen Sosa generation |
|
| 403 | + * @return Collection<int, \stdClass> |
|
| 404 | + */ |
|
| 405 | + public function generationDepthStatsAtGeneration(int $gen): Collection |
|
| 406 | + { |
|
| 407 | + if (!$this->isPdoSupported()) { |
|
| 408 | + return collect(); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 412 | + $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa') |
|
| 413 | + ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
| 414 | + ->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 |
|
| 415 | + ->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 |
|
| 416 | + ->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 |
|
| 417 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 418 | + // Link to sosa's father |
|
| 419 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 420 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 421 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 422 | + }) |
|
| 423 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 424 | + // Link to sosa's mother |
|
| 425 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 426 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 427 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 428 | + }) |
|
| 429 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 430 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 431 | + ->where('sosa.majs_gen', '>=', $gen) |
|
| 432 | + ->where(function (Builder $query): void { |
|
| 433 | + $query->whereNull('sosa_fat.majs_i_id') |
|
| 434 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 435 | + }) |
|
| 436 | + ->groupBy(['sosa.majs_gen', 'root_ancestor']); |
|
| 437 | + |
|
| 438 | + return DB::table('maj_sosa AS sosa_list') |
|
| 439 | + ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id']) |
|
| 440 | + ->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 |
|
| 441 | + ->selectRaw(' SQRT(' . |
|
| 442 | + ' 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 |
|
| 443 | + ' - 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 |
|
| 444 | + ' ) AS stddev_gen_depth') |
|
| 445 | + ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void { |
|
| 446 | + $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor') |
|
| 447 | + ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id()) |
|
| 448 | + ->where('sosa_list.majs_user_id', '=', $this->user->id()); |
|
| 449 | + }) |
|
| 450 | + ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id']) |
|
| 451 | + ->orderBy('stats_by_gen.root_ancestor') |
|
| 452 | + ->get()->keyBy('root_ancestor_sosa'); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * Return a collection of the most duplicated root Sosa ancestors. |
|
| 457 | + * The number of ancestors to return is limited by the parameter $limit. |
|
| 458 | + * If several individuals are tied when reaching the limit, none of them are returned, |
|
| 459 | + * which means that there can be less individuals returned than requested. |
|
| 460 | + * |
|
| 461 | + * Format: |
|
| 462 | + * - value: |
|
| 463 | + * - sosa_i_id : sosa individual |
|
| 464 | + * - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
| 465 | + * |
|
| 466 | + * @param int $limit |
|
| 467 | + * @return Collection<\stdClass> |
|
| 468 | + */ |
|
| 469 | + public function topMultipleAncestorsWithNoTies(int $limit): Collection |
|
| 470 | + { |
|
| 471 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 472 | + $multiple_ancestors = DB::table('maj_sosa AS sosa') |
|
| 473 | + ->select('sosa.majs_i_id AS sosa_i_id') |
|
| 474 | + ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count') |
|
| 475 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 476 | + // Link to sosa's father |
|
| 477 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 478 | + ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
|
| 479 | + ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
|
| 480 | + }) |
|
| 481 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 482 | + // Link to sosa's mother |
|
| 483 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 484 | + ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
|
| 485 | + ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
|
| 486 | + }) |
|
| 487 | + ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 488 | + ->where('sosa.majs_user_id', '=', $this->user->id()) |
|
| 489 | + ->whereNull('sosa_fat.majs_sosa') // We keep only root individuals, i.e. those with no father or mother |
|
| 490 | + ->whereNull('sosa_mot.majs_sosa') |
|
| 491 | + ->groupBy('sosa.majs_i_id') |
|
| 492 | + ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
| 493 | + ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 494 | + ->limit($limit + 1) // We want to select one more than required, for ties |
|
| 495 | + ->get(); |
|
| 496 | + |
|
| 497 | + if ($multiple_ancestors->count() > $limit) { |
|
| 498 | + $last_count = $multiple_ancestors->last()->sosa_count; |
|
| 499 | + $multiple_ancestors = $multiple_ancestors->reject( |
|
| 500 | + fn (stdClass $element): bool => $element->sosa_count === $last_count |
|
| 501 | + ); |
|
| 502 | + } |
|
| 503 | + return $multiple_ancestors; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
| 508 | + * at a specified generation. |
|
| 509 | + * |
|
| 510 | + * Format: |
|
| 511 | + * - key : rank of the ancestor in generation G for which exclusive ancestors have been found |
|
| 512 | + * For instance 3 represent the maternal grand father |
|
| 513 | + * 0 is used for shared ancestors |
|
| 514 | + * - values: |
|
| 515 | + * - branches: same as key |
|
| 516 | + * - majs_i_id: xref of the ancestor at rank key in generation G, or null for shared ancestors |
|
| 517 | + * - count_indi: number of ancestors exclusively in the ancestors of the ancestor at rank key |
|
| 518 | + * |
|
| 519 | + * For instance a result at generation 3 could be : |
|
| 520 | + * [ |
|
| 521 | + * 0 => { branches: 0, majs_i_id: X1, count_indi: 12 } -> 12 ancestors are shared by the grand-parents |
|
| 522 | + * 1 => { branches: 1, majs_i_id: X2, count_indi: 32 } -> 32 ancestors are exclusive to the paternal grand-father |
|
| 523 | + * 2 => { branches: 2, majs_i_id: X3, count_indi: 25 } -> 25 ancestors are exclusive to the paternal grand-mother |
|
| 524 | + * 3 => { branches: 3, majs_i_id: X4, count_indi: 12 } -> 12 ancestors are exclusive to the maternal grand-father |
|
| 525 | + * 4 => { branches: 4, majs_i_id: X5, count_indi: 30 } -> 30 ancestors are exclusive to the maternal grand-mother |
|
| 526 | + * ] |
|
| 527 | + * |
|
| 528 | + * @param int $gen |
|
| 529 | + * @return Collection<int, \stdClass> |
|
| 530 | + */ |
|
| 531 | + public function ancestorsDispersionForGeneration(int $gen): Collection |
|
| 532 | + { |
|
| 533 | + if (!$this->isPdoSupported()) { |
|
| 534 | + return collect(); |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + $ancestors_branches = DB::table('maj_sosa') |
|
| 538 | + ->select('majs_i_id AS i_id') |
|
| 539 | + ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen]) |
|
| 540 | + ->where('majs_gedcom_id', '=', $this->tree->id()) |
|
| 541 | + ->where('majs_user_id', '=', $this->user->id()) |
|
| 542 | + ->where('majs_gen', '>=', $gen) |
|
| 543 | + ->groupBy('majs_i_id', 'branch'); |
|
| 544 | + |
|
| 545 | + $consolidated_ancestors_branches = DB::table('maj_sosa') |
|
| 546 | + ->fromSub($ancestors_branches, 'indi_branch') |
|
| 547 | + ->select('i_id') |
|
| 548 | + ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches') |
|
| 549 | + ->groupBy('i_id'); |
|
| 550 | + |
|
| 551 | + return DB::table('maj_sosa') |
|
| 552 | + ->rightJoinSub( |
|
| 553 | + $consolidated_ancestors_branches, |
|
| 554 | + 'indi_branch_consolidated', |
|
| 555 | + function (JoinClause $join) use ($gen): void { |
|
| 556 | + $join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id()) |
|
| 557 | + ->where('maj_sosa.majs_user_id', '=', $this->user->id()) |
|
| 558 | + ->where('branches', '>', 0) |
|
| 559 | + ->whereRaw('majs_sosa = POW(2, ? - 1) + branches - 1', [$gen]); |
|
| 560 | + } |
|
| 561 | + ) |
|
| 562 | + ->select(['branches', 'majs_i_id']) |
|
| 563 | + ->selectRaw('COUNT(i_id) AS count_indi') |
|
| 564 | + ->groupBy(['branches', 'majs_i_id']) |
|
| 565 | + ->get()->keyBy('branches'); |
|
| 566 | + } |
|
| 567 | 567 | } |