@@ -30,52 +30,52 @@ |
||
30 | 30 | */ |
31 | 31 | class SosaConfigAction implements RequestHandlerInterface |
32 | 32 | { |
33 | - /** |
|
34 | - * @var UserService $user_service |
|
35 | - */ |
|
36 | - private $user_service; |
|
33 | + /** |
|
34 | + * @var UserService $user_service |
|
35 | + */ |
|
36 | + private $user_service; |
|
37 | 37 | |
38 | - /** |
|
39 | - * Constructor for SosaConfigAction Request Handler |
|
40 | - * |
|
41 | - * @param UserService $user_service |
|
42 | - */ |
|
43 | - public function __construct(UserService $user_service) |
|
44 | - { |
|
45 | - $this->user_service = $user_service; |
|
46 | - } |
|
38 | + /** |
|
39 | + * Constructor for SosaConfigAction Request Handler |
|
40 | + * |
|
41 | + * @param UserService $user_service |
|
42 | + */ |
|
43 | + public function __construct(UserService $user_service) |
|
44 | + { |
|
45 | + $this->user_service = $user_service; |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * {@inheritDoc} |
|
50 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
51 | - */ |
|
52 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
53 | - { |
|
54 | - $tree = $request->getAttribute('tree'); |
|
55 | - assert($tree instanceof Tree); |
|
48 | + /** |
|
49 | + * {@inheritDoc} |
|
50 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
51 | + */ |
|
52 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
53 | + { |
|
54 | + $tree = $request->getAttribute('tree'); |
|
55 | + assert($tree instanceof Tree); |
|
56 | 56 | |
57 | - $params = $request->getParsedBody(); |
|
58 | - assert(is_array($params)); |
|
57 | + $params = $request->getParsedBody(); |
|
58 | + assert(is_array($params)); |
|
59 | 59 | |
60 | - $user_id = (int) $params['sosa-userid']; |
|
61 | - $root_id = $params['sosa-rootid'] ?? ''; |
|
62 | - $max_gen = $params['sosa-maxgen'] ?? ''; |
|
60 | + $user_id = (int) $params['sosa-userid']; |
|
61 | + $root_id = $params['sosa-rootid'] ?? ''; |
|
62 | + $max_gen = $params['sosa-maxgen'] ?? ''; |
|
63 | 63 | |
64 | - if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) { |
|
65 | - $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
66 | - if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
67 | - $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
68 | - $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', $max_gen); |
|
69 | - FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
70 | - return redirect(route(SosaConfig::class, [ |
|
71 | - 'tree' => $tree->name(), |
|
72 | - 'compute' => 'yes', |
|
73 | - 'user_id' => $user_id |
|
74 | - ])); |
|
75 | - } |
|
76 | - } |
|
64 | + if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) { |
|
65 | + $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
66 | + if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
|
67 | + $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
|
68 | + $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', $max_gen); |
|
69 | + FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
|
70 | + return redirect(route(SosaConfig::class, [ |
|
71 | + 'tree' => $tree->name(), |
|
72 | + 'compute' => 'yes', |
|
73 | + 'user_id' => $user_id |
|
74 | + ])); |
|
75 | + } |
|
76 | + } |
|
77 | 77 | |
78 | - FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
79 | - return redirect(route(SosaConfig::class, ['tree' => $tree->name()])); |
|
80 | - } |
|
78 | + FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger'); |
|
79 | + return redirect(route(SosaConfig::class, ['tree' => $tree->name()])); |
|
80 | + } |
|
81 | 81 | } |
@@ -32,72 +32,72 @@ |
||
32 | 32 | */ |
33 | 33 | class SosaConfig implements RequestHandlerInterface |
34 | 34 | { |
35 | - use ViewResponseTrait; |
|
35 | + use ViewResponseTrait; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var SosaModule|null $module |
|
39 | - */ |
|
40 | - private $module; |
|
37 | + /** |
|
38 | + * @var SosaModule|null $module |
|
39 | + */ |
|
40 | + private $module; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Constructor for SosaConfig Request Handler |
|
44 | - * |
|
45 | - * @param ModuleService $module_service |
|
46 | - */ |
|
47 | - public function __construct(ModuleService $module_service) |
|
48 | - { |
|
49 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
50 | - } |
|
42 | + /** |
|
43 | + * Constructor for SosaConfig Request Handler |
|
44 | + * |
|
45 | + * @param ModuleService $module_service |
|
46 | + */ |
|
47 | + public function __construct(ModuleService $module_service) |
|
48 | + { |
|
49 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * {@inheritDoc} |
|
54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | - */ |
|
56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | - { |
|
58 | - if ($this->module === null) { |
|
59 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | - } |
|
52 | + /** |
|
53 | + * {@inheritDoc} |
|
54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
55 | + */ |
|
56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
57 | + { |
|
58 | + if ($this->module === null) { |
|
59 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
60 | + } |
|
61 | 61 | |
62 | - $tree = $request->getAttribute('tree'); |
|
63 | - assert($tree instanceof Tree); |
|
62 | + $tree = $request->getAttribute('tree'); |
|
63 | + assert($tree instanceof Tree); |
|
64 | 64 | |
65 | - $users_root = array(); |
|
66 | - if (Auth::check()) { |
|
67 | - /** @var \Fisharebest\Webtrees\User $user */ |
|
68 | - $user = Auth::user(); |
|
69 | - $users_root[] = [ |
|
70 | - 'user' => $user, |
|
71 | - 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'), |
|
72 | - 'max_gen' => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN') |
|
73 | - ]; |
|
65 | + $users_root = array(); |
|
66 | + if (Auth::check()) { |
|
67 | + /** @var \Fisharebest\Webtrees\User $user */ |
|
68 | + $user = Auth::user(); |
|
69 | + $users_root[] = [ |
|
70 | + 'user' => $user, |
|
71 | + 'root_id' => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'), |
|
72 | + 'max_gen' => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN') |
|
73 | + ]; |
|
74 | 74 | |
75 | - if (Auth::isManager($tree)) { |
|
76 | - $default_user = new DefaultUser(); |
|
77 | - $users_root[] = [ |
|
78 | - 'user' => $default_user, |
|
79 | - 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'), |
|
80 | - 'max_gen' => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN') |
|
81 | - ]; |
|
82 | - } |
|
83 | - } |
|
75 | + if (Auth::isManager($tree)) { |
|
76 | + $default_user = new DefaultUser(); |
|
77 | + $users_root[] = [ |
|
78 | + 'user' => $default_user, |
|
79 | + 'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'), |
|
80 | + 'max_gen' => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN') |
|
81 | + ]; |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | - // Use the system max generations if not set |
|
86 | - $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
|
87 | - foreach ($users_root as $key => $user_root) { |
|
88 | - $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
|
89 | - (int) $user_root['max_gen'] : |
|
90 | - $max_gen_system; |
|
91 | - }; |
|
85 | + // Use the system max generations if not set |
|
86 | + $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
|
87 | + foreach ($users_root as $key => $user_root) { |
|
88 | + $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
|
89 | + (int) $user_root['max_gen'] : |
|
90 | + $max_gen_system; |
|
91 | + }; |
|
92 | 92 | |
93 | - return $this->viewResponse($this->module->name() . '::config-page', [ |
|
94 | - 'module_name' => $this->module->name(), |
|
95 | - 'title' => I18N::translate('Sosa Configuration'), |
|
96 | - 'tree' => $tree, |
|
97 | - 'user_id' => $request->getAttribute('user'), |
|
98 | - 'selected_user_id' => (int) ($request->getQueryParams()['user_id'] ?? 0), |
|
99 | - 'immediate_compute' => ($request->getQueryParams()['compute'] ?? '') == 'yes', |
|
100 | - 'users_root' => $users_root |
|
101 | - ]); |
|
102 | - } |
|
93 | + return $this->viewResponse($this->module->name() . '::config-page', [ |
|
94 | + 'module_name' => $this->module->name(), |
|
95 | + 'title' => I18N::translate('Sosa Configuration'), |
|
96 | + 'tree' => $tree, |
|
97 | + 'user_id' => $request->getAttribute('user'), |
|
98 | + 'selected_user_id' => (int) ($request->getQueryParams()['user_id'] ?? 0), |
|
99 | + 'immediate_compute' => ($request->getQueryParams()['compute'] ?? '') == 'yes', |
|
100 | + 'users_root' => $users_root |
|
101 | + ]); |
|
102 | + } |
|
103 | 103 | } |
@@ -28,40 +28,40 @@ |
||
28 | 28 | */ |
29 | 29 | class SosaComputeModal implements RequestHandlerInterface |
30 | 30 | { |
31 | - /** |
|
32 | - * @var SosaModule|null $module |
|
33 | - */ |
|
34 | - private $module; |
|
31 | + /** |
|
32 | + * @var SosaModule|null $module |
|
33 | + */ |
|
34 | + private $module; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for SosaComputeModal Request Handler |
|
38 | - * |
|
39 | - * @param ModuleService $module_service |
|
40 | - */ |
|
41 | - public function __construct(ModuleService $module_service) |
|
42 | - { |
|
43 | - $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
44 | - } |
|
36 | + /** |
|
37 | + * Constructor for SosaComputeModal Request Handler |
|
38 | + * |
|
39 | + * @param ModuleService $module_service |
|
40 | + */ |
|
41 | + public function __construct(ModuleService $module_service) |
|
42 | + { |
|
43 | + $this->module = $module_service->findByInterface(SosaModule::class)->first(); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | - */ |
|
50 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | - { |
|
52 | - if ($this->module === null) { |
|
53 | - return response(view('modals/error', [ |
|
54 | - 'title' => I18N::translate('Error'), |
|
55 | - 'error' => I18N::translate('The attached module could not be found.') |
|
56 | - ])); |
|
57 | - } |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
49 | + */ |
|
50 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
51 | + { |
|
52 | + if ($this->module === null) { |
|
53 | + return response(view('modals/error', [ |
|
54 | + 'title' => I18N::translate('Error'), |
|
55 | + 'error' => I18N::translate('The attached module could not be found.') |
|
56 | + ])); |
|
57 | + } |
|
58 | 58 | |
59 | - $tree = $request->getAttribute('tree'); |
|
60 | - assert($tree instanceof Tree); |
|
59 | + $tree = $request->getAttribute('tree'); |
|
60 | + assert($tree instanceof Tree); |
|
61 | 61 | |
62 | - return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | - 'tree' => $tree, |
|
64 | - 'xref' => $request->getAttribute('xref') |
|
65 | - ])); |
|
66 | - } |
|
62 | + return response(view($this->module->name() . '::modals/sosa-compute', [ |
|
63 | + 'tree' => $tree, |
|
64 | + 'xref' => $request->getAttribute('xref') |
|
65 | + ])); |
|
66 | + } |
|
67 | 67 | } |
@@ -31,61 +31,61 @@ |
||
31 | 31 | */ |
32 | 32 | class SosaComputeAction implements RequestHandlerInterface |
33 | 33 | { |
34 | - /** |
|
35 | - * @var UserService $user_service |
|
36 | - */ |
|
37 | - private $user_service; |
|
34 | + /** |
|
35 | + * @var UserService $user_service |
|
36 | + */ |
|
37 | + private $user_service; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor for SosaConfigAction Request Handler |
|
41 | - * |
|
42 | - * @param UserService $user_service |
|
43 | - */ |
|
44 | - public function __construct(UserService $user_service) |
|
45 | - { |
|
46 | - $this->user_service = $user_service; |
|
47 | - } |
|
39 | + /** |
|
40 | + * Constructor for SosaConfigAction Request Handler |
|
41 | + * |
|
42 | + * @param UserService $user_service |
|
43 | + */ |
|
44 | + public function __construct(UserService $user_service) |
|
45 | + { |
|
46 | + $this->user_service = $user_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 = $request->getAttribute('tree'); |
|
56 | - assert($tree instanceof Tree); |
|
49 | + /** |
|
50 | + * {@inheritDoc} |
|
51 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
52 | + */ |
|
53 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
54 | + { |
|
55 | + $tree = $request->getAttribute('tree'); |
|
56 | + assert($tree instanceof Tree); |
|
57 | 57 | |
58 | - $params = $request->getParsedBody(); |
|
59 | - assert(is_array($params)); |
|
58 | + $params = $request->getParsedBody(); |
|
59 | + assert(is_array($params)); |
|
60 | 60 | |
61 | - $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0); |
|
62 | - $partial_from = $params['partial_from'] ?? null; |
|
61 | + $user_id = (int) ($params['user_id'] ?? Auth::id() ?? 0); |
|
62 | + $partial_from = $params['partial_from'] ?? null; |
|
63 | 63 | |
64 | - if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) { |
|
65 | - $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
64 | + if (($user_id == -1 && Auth::isManager($tree)) || Auth::id() == $user_id) { |
|
65 | + $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id); |
|
66 | 66 | |
67 | - /** @var SosaCalculatorService $sosa_calc_service */ |
|
68 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
67 | + /** @var SosaCalculatorService $sosa_calc_service */ |
|
68 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
69 | 69 | |
70 | - if ( |
|
71 | - $partial_from !== null && |
|
72 | - ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
73 | - ) { |
|
74 | - $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
75 | - } else { |
|
76 | - $res = $sosa_calc_service->computeAll(); |
|
77 | - } |
|
70 | + if ( |
|
71 | + $partial_from !== null && |
|
72 | + ($sosa_from = Registry::individualFactory()->make($partial_from, $tree)) !== null |
|
73 | + ) { |
|
74 | + $res = $sosa_calc_service->computeFromIndividual($sosa_from); |
|
75 | + } else { |
|
76 | + $res = $sosa_calc_service->computeAll(); |
|
77 | + } |
|
78 | 78 | |
79 | - return $res ? |
|
80 | - response('', 200) : |
|
81 | - response( |
|
82 | - I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
83 | - StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
84 | - ); |
|
85 | - } |
|
86 | - return response( |
|
87 | - I18N::translate('You do not have permission to modify the user.'), |
|
88 | - StatusCodeInterface::STATUS_FORBIDDEN |
|
89 | - ); |
|
90 | - } |
|
79 | + return $res ? |
|
80 | + response('', 200) : |
|
81 | + response( |
|
82 | + I18N::translate('An error occurred while computing Sosa ancestors.'), |
|
83 | + StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
|
84 | + ); |
|
85 | + } |
|
86 | + return response( |
|
87 | + I18N::translate('You do not have permission to modify the user.'), |
|
88 | + StatusCodeInterface::STATUS_FORBIDDEN |
|
89 | + ); |
|
90 | + } |
|
91 | 91 | } |
@@ -22,12 +22,12 @@ |
||
22 | 22 | class Migration1 implements MigrationInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritDoc} |
|
27 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | - */ |
|
29 | - public function upgrade(): void |
|
30 | - { |
|
31 | - // These migrations have been merged into migration 2. |
|
32 | - } |
|
25 | + /** |
|
26 | + * {@inheritDoc} |
|
27 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | + */ |
|
29 | + public function upgrade(): void |
|
30 | + { |
|
31 | + // These migrations have been merged into migration 2. |
|
32 | + } |
|
33 | 33 | } |
@@ -24,36 +24,36 @@ |
||
24 | 24 | class Migration2 implements MigrationInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritDoc} |
|
29 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
30 | - */ |
|
31 | - public function upgrade(): void |
|
32 | - { |
|
33 | - |
|
34 | - // Clean up previous sosa table if it exists |
|
35 | - DB::schema()->dropIfExists('maj_sosa'); |
|
36 | - |
|
37 | - DB::schema()->create('maj_sosa', static function (Blueprint $table): void { |
|
38 | - |
|
39 | - $table->integer('majs_gedcom_id'); |
|
40 | - $table->integer('majs_user_id')->default(-1); |
|
41 | - $table->bigInteger('majs_sosa')->unsigned(); // Allow to calculate sosa on 64 generations |
|
42 | - $table->string('majs_i_id', 20); |
|
43 | - $table->tinyInteger('majs_gen')->nullable(); |
|
44 | - $table->smallInteger('majs_birth_year')->nullable(); |
|
45 | - $table->smallInteger('majs_birth_year_est')->nullable(); |
|
46 | - $table->smallInteger('majs_death_year')->nullable(); |
|
47 | - $table->smallInteger('majs_death_year_est')->nullable(); |
|
48 | - |
|
49 | - $table->primary(['majs_gedcom_id', 'majs_user_id', 'majs_sosa']); |
|
50 | - |
|
51 | - $table->index(['majs_gedcom_id', 'majs_user_id']); |
|
52 | - $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_i_id']); |
|
53 | - $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_gen']); |
|
54 | - |
|
55 | - $table->foreign('majs_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); |
|
56 | - $table->foreign('majs_user_id')->references('user_id')->on('user')->onDelete('cascade'); |
|
57 | - }); |
|
58 | - } |
|
27 | + /** |
|
28 | + * {@inheritDoc} |
|
29 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
30 | + */ |
|
31 | + public function upgrade(): void |
|
32 | + { |
|
33 | + |
|
34 | + // Clean up previous sosa table if it exists |
|
35 | + DB::schema()->dropIfExists('maj_sosa'); |
|
36 | + |
|
37 | + DB::schema()->create('maj_sosa', static function (Blueprint $table): void { |
|
38 | + |
|
39 | + $table->integer('majs_gedcom_id'); |
|
40 | + $table->integer('majs_user_id')->default(-1); |
|
41 | + $table->bigInteger('majs_sosa')->unsigned(); // Allow to calculate sosa on 64 generations |
|
42 | + $table->string('majs_i_id', 20); |
|
43 | + $table->tinyInteger('majs_gen')->nullable(); |
|
44 | + $table->smallInteger('majs_birth_year')->nullable(); |
|
45 | + $table->smallInteger('majs_birth_year_est')->nullable(); |
|
46 | + $table->smallInteger('majs_death_year')->nullable(); |
|
47 | + $table->smallInteger('majs_death_year_est')->nullable(); |
|
48 | + |
|
49 | + $table->primary(['majs_gedcom_id', 'majs_user_id', 'majs_sosa']); |
|
50 | + |
|
51 | + $table->index(['majs_gedcom_id', 'majs_user_id']); |
|
52 | + $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_i_id']); |
|
53 | + $table->index(['majs_gedcom_id', 'majs_user_id', 'majs_gen']); |
|
54 | + |
|
55 | + $table->foreign('majs_gedcom_id')->references('gedcom_id')->on('gedcom')->onDelete('cascade'); |
|
56 | + $table->foreign('majs_user_id')->references('user_id')->on('user')->onDelete('cascade'); |
|
57 | + }); |
|
58 | + } |
|
59 | 59 | } |
@@ -22,12 +22,12 @@ |
||
22 | 22 | class Migration0 implements MigrationInterface |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * {@inheritDoc} |
|
27 | - * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | - */ |
|
29 | - public function upgrade(): void |
|
30 | - { |
|
31 | - // These migrations have been merged into migration 2. |
|
32 | - } |
|
25 | + /** |
|
26 | + * {@inheritDoc} |
|
27 | + * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade() |
|
28 | + */ |
|
29 | + public function upgrade(): void |
|
30 | + { |
|
31 | + // These migrations have been merged into migration 2. |
|
32 | + } |
|
33 | 33 | } |
@@ -24,143 +24,143 @@ |
||
24 | 24 | */ |
25 | 25 | class SosaCalculatorService |
26 | 26 | { |
27 | - /** |
|
28 | - * Maximium size for the temporary Sosa table |
|
29 | - * @var int TMP_SOSA_TABLE_LIMIT |
|
30 | - */ |
|
31 | - private const TMP_SOSA_TABLE_LIMIT = 1000; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var SosaRecordsService $sosa_records_service |
|
35 | - */ |
|
36 | - private $sosa_records_service; |
|
37 | - |
|
38 | - /** |
|
39 | - * Reference user |
|
40 | - * @var UserInterface $user |
|
41 | - */ |
|
42 | - private $user; |
|
43 | - |
|
44 | - /** |
|
45 | - * Reference tree |
|
46 | - * @var Tree $tree |
|
47 | - */ |
|
48 | - private $tree; |
|
49 | - |
|
50 | - /** |
|
51 | - * Temporary Sosa table, used during construction |
|
52 | - * @var array<array<string,mixed>> $tmp_sosa_table |
|
53 | - */ |
|
54 | - private $tmp_sosa_table; |
|
55 | - |
|
56 | - /** |
|
57 | - * Maximum number of generations to calculate |
|
58 | - * @var int $max_generations |
|
59 | - */ |
|
60 | - private $max_generations; |
|
61 | - |
|
62 | - /** |
|
63 | - * Constructor for the Sosa Calculator |
|
64 | - * |
|
65 | - * @param SosaRecordsService $sosa_records_service |
|
66 | - * @param Tree $tree |
|
67 | - * @param UserInterface $user |
|
68 | - */ |
|
69 | - public function __construct(SosaRecordsService $sosa_records_service, Tree $tree, UserInterface $user) |
|
70 | - { |
|
71 | - $this->sosa_records_service = $sosa_records_service; |
|
72 | - $this->tree = $tree; |
|
73 | - $this->user = $user; |
|
74 | - $this->tmp_sosa_table = array(); |
|
75 | - $max_gen_setting = $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN'); |
|
76 | - $this->max_generations = is_numeric($max_gen_setting) ? |
|
77 | - (int) $max_gen_setting : |
|
78 | - $this->sosa_records_service->maxSystemGenerations(); |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Compute all Sosa ancestors from the user's root individual. |
|
83 | - * |
|
84 | - * @return bool Result of the computation |
|
85 | - */ |
|
86 | - public function computeAll(): bool |
|
87 | - { |
|
88 | - $root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
89 | - if (($indi = Registry::individualFactory()->make($root_id, $this->tree)) !== null) { |
|
90 | - $this->sosa_records_service->deleteAll($this->tree, $this->user); |
|
91 | - $this->addNode($indi, 1); |
|
92 | - $this->flushTmpSosaTable(true); |
|
93 | - return true; |
|
94 | - } |
|
95 | - return false; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * Compute all Sosa Ancestors from a specified Individual |
|
100 | - * |
|
101 | - * @param Individual $indi |
|
102 | - * @return bool |
|
103 | - */ |
|
104 | - public function computeFromIndividual(Individual $indi): bool |
|
105 | - { |
|
106 | - $current_sosas = $this->sosa_records_service->sosaNumbers($this->tree, $this->user, $indi); |
|
107 | - foreach ($current_sosas->keys() as $sosa) { |
|
108 | - $this->sosa_records_service->deleteAncestorsFrom($this->tree, $this->user, $sosa); |
|
109 | - $this->addNode($indi, $sosa); |
|
110 | - } |
|
111 | - $this->flushTmpSosaTable(true); |
|
112 | - return true; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * Recursive method to add individual to the Sosa table, and flush it regularly |
|
117 | - * |
|
118 | - * @param Individual $indi Individual to add |
|
119 | - * @param int $sosa Individual's sosa |
|
120 | - */ |
|
121 | - private function addNode(Individual $indi, int $sosa): void |
|
122 | - { |
|
123 | - $birth_year = $indi->getBirthDate()->gregorianYear(); |
|
124 | - $birth_year_est = $birth_year === 0 ? $indi->getEstimatedBirthDate()->gregorianYear() : $birth_year; |
|
125 | - |
|
126 | - $death_year = $indi->getDeathDate()->gregorianYear(); |
|
127 | - $death_year_est = $death_year === 0 ? $indi->getEstimatedDeathDate()->gregorianYear() : $death_year; |
|
128 | - |
|
129 | - $this->tmp_sosa_table[] = [ |
|
130 | - 'indi' => $indi->xref(), |
|
131 | - 'sosa' => $sosa, |
|
132 | - 'birth_year' => $birth_year === 0 ? null : $birth_year, |
|
133 | - 'birth_year_est' => $birth_year_est === 0 ? null : $birth_year_est, |
|
134 | - 'death_year' => $death_year === 0 ? null : $death_year, |
|
135 | - 'death_year_est' => $death_year_est === 0 ? null : $death_year_est |
|
136 | - ]; |
|
137 | - |
|
138 | - $this->flushTmpSosaTable(); |
|
139 | - |
|
140 | - if ( |
|
141 | - ($fam = $indi->childFamilies()->first()) !== null |
|
142 | - && $this->sosa_records_service->generation($sosa) < $this->max_generations |
|
143 | - ) { |
|
144 | - /** @var \Fisharebest\Webtrees\Family $fam */ |
|
145 | - if (($husb = $fam->husband()) !== null) { |
|
146 | - $this->addNode($husb, 2 * $sosa); |
|
147 | - } |
|
148 | - if (($wife = $fam->wife()) !== null) { |
|
149 | - $this->addNode($wife, 2 * $sosa + 1); |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Write sosas in the table, if the number of items is superior to the limit, or if forced. |
|
156 | - * |
|
157 | - * @param bool $force Should the flush be forced |
|
158 | - */ |
|
159 | - private function flushTmpSosaTable($force = false): void |
|
160 | - { |
|
161 | - if ($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT) { |
|
162 | - $this->sosa_records_service->insertOrUpdate($this->tree, $this->user, $this->tmp_sosa_table); |
|
163 | - $this->tmp_sosa_table = array(); |
|
164 | - } |
|
165 | - } |
|
27 | + /** |
|
28 | + * Maximium size for the temporary Sosa table |
|
29 | + * @var int TMP_SOSA_TABLE_LIMIT |
|
30 | + */ |
|
31 | + private const TMP_SOSA_TABLE_LIMIT = 1000; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var SosaRecordsService $sosa_records_service |
|
35 | + */ |
|
36 | + private $sosa_records_service; |
|
37 | + |
|
38 | + /** |
|
39 | + * Reference user |
|
40 | + * @var UserInterface $user |
|
41 | + */ |
|
42 | + private $user; |
|
43 | + |
|
44 | + /** |
|
45 | + * Reference tree |
|
46 | + * @var Tree $tree |
|
47 | + */ |
|
48 | + private $tree; |
|
49 | + |
|
50 | + /** |
|
51 | + * Temporary Sosa table, used during construction |
|
52 | + * @var array<array<string,mixed>> $tmp_sosa_table |
|
53 | + */ |
|
54 | + private $tmp_sosa_table; |
|
55 | + |
|
56 | + /** |
|
57 | + * Maximum number of generations to calculate |
|
58 | + * @var int $max_generations |
|
59 | + */ |
|
60 | + private $max_generations; |
|
61 | + |
|
62 | + /** |
|
63 | + * Constructor for the Sosa Calculator |
|
64 | + * |
|
65 | + * @param SosaRecordsService $sosa_records_service |
|
66 | + * @param Tree $tree |
|
67 | + * @param UserInterface $user |
|
68 | + */ |
|
69 | + public function __construct(SosaRecordsService $sosa_records_service, Tree $tree, UserInterface $user) |
|
70 | + { |
|
71 | + $this->sosa_records_service = $sosa_records_service; |
|
72 | + $this->tree = $tree; |
|
73 | + $this->user = $user; |
|
74 | + $this->tmp_sosa_table = array(); |
|
75 | + $max_gen_setting = $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN'); |
|
76 | + $this->max_generations = is_numeric($max_gen_setting) ? |
|
77 | + (int) $max_gen_setting : |
|
78 | + $this->sosa_records_service->maxSystemGenerations(); |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Compute all Sosa ancestors from the user's root individual. |
|
83 | + * |
|
84 | + * @return bool Result of the computation |
|
85 | + */ |
|
86 | + public function computeAll(): bool |
|
87 | + { |
|
88 | + $root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
89 | + if (($indi = Registry::individualFactory()->make($root_id, $this->tree)) !== null) { |
|
90 | + $this->sosa_records_service->deleteAll($this->tree, $this->user); |
|
91 | + $this->addNode($indi, 1); |
|
92 | + $this->flushTmpSosaTable(true); |
|
93 | + return true; |
|
94 | + } |
|
95 | + return false; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * Compute all Sosa Ancestors from a specified Individual |
|
100 | + * |
|
101 | + * @param Individual $indi |
|
102 | + * @return bool |
|
103 | + */ |
|
104 | + public function computeFromIndividual(Individual $indi): bool |
|
105 | + { |
|
106 | + $current_sosas = $this->sosa_records_service->sosaNumbers($this->tree, $this->user, $indi); |
|
107 | + foreach ($current_sosas->keys() as $sosa) { |
|
108 | + $this->sosa_records_service->deleteAncestorsFrom($this->tree, $this->user, $sosa); |
|
109 | + $this->addNode($indi, $sosa); |
|
110 | + } |
|
111 | + $this->flushTmpSosaTable(true); |
|
112 | + return true; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * Recursive method to add individual to the Sosa table, and flush it regularly |
|
117 | + * |
|
118 | + * @param Individual $indi Individual to add |
|
119 | + * @param int $sosa Individual's sosa |
|
120 | + */ |
|
121 | + private function addNode(Individual $indi, int $sosa): void |
|
122 | + { |
|
123 | + $birth_year = $indi->getBirthDate()->gregorianYear(); |
|
124 | + $birth_year_est = $birth_year === 0 ? $indi->getEstimatedBirthDate()->gregorianYear() : $birth_year; |
|
125 | + |
|
126 | + $death_year = $indi->getDeathDate()->gregorianYear(); |
|
127 | + $death_year_est = $death_year === 0 ? $indi->getEstimatedDeathDate()->gregorianYear() : $death_year; |
|
128 | + |
|
129 | + $this->tmp_sosa_table[] = [ |
|
130 | + 'indi' => $indi->xref(), |
|
131 | + 'sosa' => $sosa, |
|
132 | + 'birth_year' => $birth_year === 0 ? null : $birth_year, |
|
133 | + 'birth_year_est' => $birth_year_est === 0 ? null : $birth_year_est, |
|
134 | + 'death_year' => $death_year === 0 ? null : $death_year, |
|
135 | + 'death_year_est' => $death_year_est === 0 ? null : $death_year_est |
|
136 | + ]; |
|
137 | + |
|
138 | + $this->flushTmpSosaTable(); |
|
139 | + |
|
140 | + if ( |
|
141 | + ($fam = $indi->childFamilies()->first()) !== null |
|
142 | + && $this->sosa_records_service->generation($sosa) < $this->max_generations |
|
143 | + ) { |
|
144 | + /** @var \Fisharebest\Webtrees\Family $fam */ |
|
145 | + if (($husb = $fam->husband()) !== null) { |
|
146 | + $this->addNode($husb, 2 * $sosa); |
|
147 | + } |
|
148 | + if (($wife = $fam->wife()) !== null) { |
|
149 | + $this->addNode($wife, 2 * $sosa + 1); |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Write sosas in the table, if the number of items is superior to the limit, or if forced. |
|
156 | + * |
|
157 | + * @param bool $force Should the flush be forced |
|
158 | + */ |
|
159 | + private function flushTmpSosaTable($force = false): void |
|
160 | + { |
|
161 | + if ($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT) { |
|
162 | + $this->sosa_records_service->insertOrUpdate($this->tree, $this->user, $this->tmp_sosa_table); |
|
163 | + $this->tmp_sosa_table = array(); |
|
164 | + } |
|
165 | + } |
|
166 | 166 | } |
@@ -31,101 +31,101 @@ |
||
31 | 31 | */ |
32 | 32 | class SosaByGenerationGeoAnalysis implements GeoAnalysisInterface |
33 | 33 | { |
34 | - private SosaRecordsService $records_service; |
|
35 | - |
|
36 | - /** |
|
37 | - * Constructor for SosaByGenerationGeoAnalysis |
|
38 | - * |
|
39 | - * @param SosaRecordsService $records_service |
|
40 | - */ |
|
41 | - public function __construct(SosaRecordsService $records_service) |
|
42 | - { |
|
43 | - $this->records_service = $records_service; |
|
44 | - } |
|
45 | - |
|
46 | - /** |
|
47 | - * {@inheritDoc} |
|
48 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
49 | - */ |
|
50 | - public function title(): string |
|
51 | - { |
|
52 | - return I18N::translate('Sosa ancestors places by generation'); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
58 | - */ |
|
59 | - public function itemsDescription(): callable |
|
60 | - { |
|
61 | - return fn(int $count): string => I18N::plural('ancestor', 'ancestors', $count); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inheritDoc} |
|
66 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
67 | - */ |
|
68 | - public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
69 | - { |
|
70 | - $results = new GeoAnalysisResults(); |
|
71 | - |
|
72 | - $unique_ancestors = $this->records_service |
|
73 | - ->listAncestors($tree, Auth::user()) |
|
74 | - ->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id); |
|
75 | - |
|
76 | - foreach ($unique_ancestors as $item) { |
|
77 | - $ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree); |
|
78 | - if ($ancestor === null || !$ancestor->canShow()) { |
|
79 | - continue; |
|
80 | - } |
|
81 | - $generation = $this->records_service->generation((int) $item->majs_sosa); |
|
82 | - $significantplace = new GeoAnalysisPlace($tree, null, $depth); |
|
83 | - foreach ($this->significantPlaces($ancestor) as $place) { |
|
84 | - $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true); |
|
85 | - if ($significantplace->isKnown()) { |
|
86 | - break; |
|
87 | - } |
|
88 | - } |
|
89 | - $results->addPlace($significantplace); |
|
90 | - $results->addPlaceInCategory( |
|
91 | - I18N::translate('Generation %s', I18N::number($generation)), |
|
92 | - $generation, |
|
93 | - $significantplace |
|
94 | - ); |
|
95 | - } |
|
96 | - |
|
97 | - return $results; |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Returns significant places in order of priority for an individual |
|
102 | - * |
|
103 | - * @param Individual $individual |
|
104 | - * @return Generator<\Fisharebest\Webtrees\Place> |
|
105 | - */ |
|
106 | - protected function significantPlaces(Individual $individual): Generator |
|
107 | - { |
|
108 | - yield $individual->getBirthPlace(); |
|
109 | - |
|
110 | - /** @var \Fisharebest\Webtrees\Fact $fact */ |
|
111 | - foreach ($individual->facts(['RESI']) as $fact) { |
|
112 | - yield $fact->place(); |
|
113 | - } |
|
114 | - |
|
115 | - yield $individual->getDeathPlace(); |
|
116 | - |
|
117 | - /** @var \Fisharebest\Webtrees\Family $family */ |
|
118 | - foreach ($individual->childFamilies() as $family) { |
|
119 | - foreach ($family->facts(['RESI']) as $fact) { |
|
120 | - yield $fact->place(); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - /** @var \Fisharebest\Webtrees\Family $family */ |
|
125 | - foreach ($individual->spouseFamilies() as $family) { |
|
126 | - foreach ($family->facts(['RESI']) as $fact) { |
|
127 | - yield $fact->place(); |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
34 | + private SosaRecordsService $records_service; |
|
35 | + |
|
36 | + /** |
|
37 | + * Constructor for SosaByGenerationGeoAnalysis |
|
38 | + * |
|
39 | + * @param SosaRecordsService $records_service |
|
40 | + */ |
|
41 | + public function __construct(SosaRecordsService $records_service) |
|
42 | + { |
|
43 | + $this->records_service = $records_service; |
|
44 | + } |
|
45 | + |
|
46 | + /** |
|
47 | + * {@inheritDoc} |
|
48 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title() |
|
49 | + */ |
|
50 | + public function title(): string |
|
51 | + { |
|
52 | + return I18N::translate('Sosa ancestors places by generation'); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription() |
|
58 | + */ |
|
59 | + public function itemsDescription(): callable |
|
60 | + { |
|
61 | + return fn(int $count): string => I18N::plural('ancestor', 'ancestors', $count); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inheritDoc} |
|
66 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results() |
|
67 | + */ |
|
68 | + public function results(Tree $tree, int $depth): GeoAnalysisResults |
|
69 | + { |
|
70 | + $results = new GeoAnalysisResults(); |
|
71 | + |
|
72 | + $unique_ancestors = $this->records_service |
|
73 | + ->listAncestors($tree, Auth::user()) |
|
74 | + ->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id); |
|
75 | + |
|
76 | + foreach ($unique_ancestors as $item) { |
|
77 | + $ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree); |
|
78 | + if ($ancestor === null || !$ancestor->canShow()) { |
|
79 | + continue; |
|
80 | + } |
|
81 | + $generation = $this->records_service->generation((int) $item->majs_sosa); |
|
82 | + $significantplace = new GeoAnalysisPlace($tree, null, $depth); |
|
83 | + foreach ($this->significantPlaces($ancestor) as $place) { |
|
84 | + $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true); |
|
85 | + if ($significantplace->isKnown()) { |
|
86 | + break; |
|
87 | + } |
|
88 | + } |
|
89 | + $results->addPlace($significantplace); |
|
90 | + $results->addPlaceInCategory( |
|
91 | + I18N::translate('Generation %s', I18N::number($generation)), |
|
92 | + $generation, |
|
93 | + $significantplace |
|
94 | + ); |
|
95 | + } |
|
96 | + |
|
97 | + return $results; |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Returns significant places in order of priority for an individual |
|
102 | + * |
|
103 | + * @param Individual $individual |
|
104 | + * @return Generator<\Fisharebest\Webtrees\Place> |
|
105 | + */ |
|
106 | + protected function significantPlaces(Individual $individual): Generator |
|
107 | + { |
|
108 | + yield $individual->getBirthPlace(); |
|
109 | + |
|
110 | + /** @var \Fisharebest\Webtrees\Fact $fact */ |
|
111 | + foreach ($individual->facts(['RESI']) as $fact) { |
|
112 | + yield $fact->place(); |
|
113 | + } |
|
114 | + |
|
115 | + yield $individual->getDeathPlace(); |
|
116 | + |
|
117 | + /** @var \Fisharebest\Webtrees\Family $family */ |
|
118 | + foreach ($individual->childFamilies() as $family) { |
|
119 | + foreach ($family->facts(['RESI']) as $fact) { |
|
120 | + yield $fact->place(); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + /** @var \Fisharebest\Webtrees\Family $family */ |
|
125 | + foreach ($individual->spouseFamilies() as $family) { |
|
126 | + foreach ($family->facts(['RESI']) as $fact) { |
|
127 | + yield $fact->place(); |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | 131 | } |