@@ -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 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | // Clean up previous sosa table if it exists |
| 35 | 35 | DB::schema()->dropIfExists('maj_sosa'); |
| 36 | 36 | |
| 37 | - DB::schema()->create('maj_sosa', static function (Blueprint $table): void { |
|
| 37 | + DB::schema()->create('maj_sosa', static function(Blueprint $table): void { |
|
| 38 | 38 | |
| 39 | 39 | $table->integer('majs_gedcom_id'); |
| 40 | 40 | $table->integer('majs_user_id')->default(-1); |
@@ -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 | } |
@@ -74,8 +74,7 @@ |
||
| 74 | 74 | $this->tmp_sosa_table = array(); |
| 75 | 75 | $max_gen_setting = $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN'); |
| 76 | 76 | $this->max_generations = is_numeric($max_gen_setting) ? |
| 77 | - (int) $max_gen_setting : |
|
| 78 | - $this->sosa_records_service->maxSystemGenerations(); |
|
| 77 | + (int)$max_gen_setting : $this->sosa_records_service->maxSystemGenerations(); |
|
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | /** |
@@ -88,8 +88,8 @@ discard block |
||
| 88 | 88 | public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
| 89 | 89 | { |
| 90 | 90 | return Registry::cache()->array()->remember( |
| 91 | - 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
| 92 | - function () use ($tree, $user, $indi): Collection { |
|
| 91 | + 'sosanumbers-'.$indi->xref().'@'.$tree->id().'-'.$user->id(), |
|
| 92 | + function() use ($tree, $user, $indi): Collection { |
|
| 93 | 93 | return DB::table('maj_sosa') |
| 94 | 94 | ->select(['majs_sosa', 'majs_gen']) |
| 95 | 95 | ->where('majs_gedcom_id', '=', $tree->id()) |
@@ -149,14 +149,14 @@ discard block |
||
| 149 | 149 | { |
| 150 | 150 | $table_prefix = DB::connection()->getTablePrefix(); |
| 151 | 151 | return DB::table('families') |
| 152 | - ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
| 152 | + ->join('maj_sosa AS sosa_husb', function(JoinClause $join) use ($tree, $user): void { |
|
| 153 | 153 | // Link to family husband |
| 154 | 154 | $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
| 155 | 155 | ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
| 156 | 156 | ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
| 157 | 157 | ->where('sosa_husb.majs_user_id', '=', $user->id()); |
| 158 | 158 | }) |
| 159 | - ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
| 159 | + ->join('maj_sosa AS sosa_wife', function(JoinClause $join) use ($tree, $user): void { |
|
| 160 | 160 | // Link to family husband |
| 161 | 161 | $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
| 162 | 162 | ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | }) |
| 166 | 166 | ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
| 167 | 167 | ->where('sosa_husb.majs_gen', '=', $gen) |
| 168 | - ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
| 168 | + ->whereRaw($table_prefix.'sosa_husb.majs_sosa + 1 = '.$table_prefix.'sosa_wife.majs_sosa') |
|
| 169 | 169 | ->orderBy('sosa_husb.majs_sosa') |
| 170 | 170 | ->get(); |
| 171 | 171 | } |
@@ -188,28 +188,28 @@ discard block |
||
| 188 | 188 | $table_prefix = DB::connection()->getTablePrefix(); |
| 189 | 189 | return DB::table('maj_sosa AS sosa') |
| 190 | 190 | ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
| 191 | - ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
| 192 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 191 | + ->selectRaw('MIN('.$table_prefix.'sosa.majs_sosa) AS majs_sosa') |
|
| 192 | + ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 193 | 193 | // Link to sosa's father |
| 194 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 194 | + $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa') |
|
| 195 | 195 | ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
| 196 | 196 | ->where('sosa_fat.majs_user_id', '=', $user->id()); |
| 197 | 197 | }) |
| 198 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 198 | + ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 199 | 199 | // Link to sosa's mother |
| 200 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 200 | + $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1') |
|
| 201 | 201 | ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
| 202 | 202 | ->where('sosa_mot.majs_user_id', '=', $user->id()); |
| 203 | 203 | }) |
| 204 | 204 | ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
| 205 | 205 | ->where('sosa.majs_user_id', '=', $user->id()) |
| 206 | 206 | ->where('sosa.majs_gen', '=', $gen - 1) |
| 207 | - ->where(function (Builder $query): void { |
|
| 207 | + ->where(function(Builder $query): void { |
|
| 208 | 208 | $query->whereNull('sosa_fat.majs_i_id') |
| 209 | 209 | ->orWhereNull('sosa_mot.majs_i_id'); |
| 210 | 210 | }) |
| 211 | 211 | ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
| 212 | - ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
| 212 | + ->orderByRaw('MIN('.$table_prefix.'sosa.majs_sosa)') |
|
| 213 | 213 | ->get(); |
| 214 | 214 | } |
| 215 | 215 | |
@@ -261,29 +261,29 @@ discard block |
||
| 261 | 261 | $has_records = false; |
| 262 | 262 | foreach ($sosa_records as $i => $row) { |
| 263 | 263 | $gen = $this->generation($row['sosa']); |
| 264 | - if ($gen <= $this->maxSystemGenerations()) { |
|
| 264 | + if ($gen <= $this->maxSystemGenerations()) { |
|
| 265 | 265 | $has_records = true; |
| 266 | 266 | if ($mass_update) { |
| 267 | - $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
| 268 | - ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
| 269 | - ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
| 267 | + $bindings_placeholders[] = '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.','. |
|
| 268 | + ' :indi_id'.$i.', :gen'.$i.','. |
|
| 269 | + ' :byear'.$i.', :byearest'.$i.', :dyear'.$i.', :dyearest'.$i.')'; |
|
| 270 | 270 | $bindings_values = array_merge( |
| 271 | 271 | $bindings_values, |
| 272 | 272 | [ |
| 273 | - 'tree_id' . $i => $tree->id(), |
|
| 274 | - 'user_id' . $i => $user->id(), |
|
| 275 | - 'sosa' . $i => $row['sosa'], |
|
| 276 | - 'indi_id' . $i => $row['indi'], |
|
| 277 | - 'gen' . $i => $gen, |
|
| 278 | - 'byear' . $i => $row['birth_year'], |
|
| 279 | - 'byearest' . $i => $row['birth_year_est'], |
|
| 280 | - 'dyear' . $i => $row['death_year'], |
|
| 281 | - 'dyearest' . $i => $row['death_year_est'] |
|
| 273 | + 'tree_id'.$i => $tree->id(), |
|
| 274 | + 'user_id'.$i => $user->id(), |
|
| 275 | + 'sosa'.$i => $row['sosa'], |
|
| 276 | + 'indi_id'.$i => $row['indi'], |
|
| 277 | + 'gen'.$i => $gen, |
|
| 278 | + 'byear'.$i => $row['birth_year'], |
|
| 279 | + 'byearest'.$i => $row['birth_year_est'], |
|
| 280 | + 'dyear'.$i => $row['death_year'], |
|
| 281 | + 'dyearest'.$i => $row['death_year_est'] |
|
| 282 | 282 | ] |
| 283 | 283 | ); |
| 284 | 284 | } else { |
| 285 | 285 | DB::table('maj_sosa')->updateOrInsert( |
| 286 | - [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
| 286 | + ['majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
| 287 | 287 | [ |
| 288 | 288 | 'majs_i_id' => $row['indi'], |
| 289 | 289 | 'majs_gen' => $gen, |
@@ -299,12 +299,12 @@ discard block |
||
| 299 | 299 | |
| 300 | 300 | if ($has_records && $mass_update) { |
| 301 | 301 | DB::connection()->statement( |
| 302 | - 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
| 303 | - ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
| 304 | - ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
| 305 | - ' VALUES ' . implode(',', $bindings_placeholders) . |
|
| 306 | - ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
| 307 | - ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
| 302 | + 'INSERT INTO `'.DB::connection()->getTablePrefix().'maj_sosa`'. |
|
| 303 | + ' (majs_gedcom_id, majs_user_id, majs_sosa,'. |
|
| 304 | + ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)'. |
|
| 305 | + ' VALUES '.implode(',', $bindings_placeholders). |
|
| 306 | + ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),'. |
|
| 307 | + ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),'. |
|
| 308 | 308 | ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
| 309 | 309 | $bindings_values |
| 310 | 310 | ); |
@@ -30,294 +30,294 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | class SosaRecordsService |
| 32 | 32 | { |
| 33 | - private ?int $max_system_generations = null; |
|
| 33 | + private ?int $max_system_generations = null; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Maximum number of generation the system is able to hold. |
|
| 37 | - * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
| 38 | - * |
|
| 39 | - * @return int |
|
| 40 | - */ |
|
| 41 | - public function maxSystemGenerations(): int |
|
| 42 | - { |
|
| 43 | - if ($this->max_system_generations === null) { |
|
| 44 | - $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
| 45 | - } |
|
| 46 | - return $this->max_system_generations; |
|
| 47 | - } |
|
| 35 | + /** |
|
| 36 | + * Maximum number of generation the system is able to hold. |
|
| 37 | + * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type |
|
| 38 | + * |
|
| 39 | + * @return int |
|
| 40 | + */ |
|
| 41 | + public function maxSystemGenerations(): int |
|
| 42 | + { |
|
| 43 | + if ($this->max_system_generations === null) { |
|
| 44 | + $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX)); |
|
| 45 | + } |
|
| 46 | + return $this->max_system_generations; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Calculate the generation of a sosa |
|
| 51 | - * Sosa 1 is of generation 1. |
|
| 52 | - * |
|
| 53 | - * @param int $sosa |
|
| 54 | - * @return int |
|
| 55 | - */ |
|
| 56 | - public function generation(int $sosa): int |
|
| 57 | - { |
|
| 58 | - return BigInteger::of($sosa)->getBitLength(); |
|
| 59 | - } |
|
| 49 | + /** |
|
| 50 | + * Calculate the generation of a sosa |
|
| 51 | + * Sosa 1 is of generation 1. |
|
| 52 | + * |
|
| 53 | + * @param int $sosa |
|
| 54 | + * @return int |
|
| 55 | + */ |
|
| 56 | + public function generation(int $sosa): int |
|
| 57 | + { |
|
| 58 | + return BigInteger::of($sosa)->getBitLength(); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Calculate the descendant sosa of the given sosa, at the given generation. |
|
| 63 | - * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
| 64 | - * |
|
| 65 | - * @param int $sosa |
|
| 66 | - * @param int $gen |
|
| 67 | - * @return int |
|
| 68 | - */ |
|
| 69 | - public function sosaDescendantOf(int $sosa, int $gen): int |
|
| 70 | - { |
|
| 71 | - $gen_sosa = $this->generation($sosa); |
|
| 72 | - return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
| 73 | - ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
| 74 | - ->toInt(); |
|
| 75 | - } |
|
| 61 | + /** |
|
| 62 | + * Calculate the descendant sosa of the given sosa, at the given generation. |
|
| 63 | + * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother). |
|
| 64 | + * |
|
| 65 | + * @param int $sosa |
|
| 66 | + * @param int $gen |
|
| 67 | + * @return int |
|
| 68 | + */ |
|
| 69 | + public function sosaDescendantOf(int $sosa, int $gen): int |
|
| 70 | + { |
|
| 71 | + $gen_sosa = $this->generation($sosa); |
|
| 72 | + return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa) |
|
| 73 | + ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN) |
|
| 74 | + ->toInt(); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * Check whether an individual is a Sosa ancestor. |
|
| 79 | - * |
|
| 80 | - * @param Tree $tree |
|
| 81 | - * @param UserInterface $user |
|
| 82 | - * @param Individual $indi |
|
| 83 | - * @return bool |
|
| 84 | - */ |
|
| 85 | - public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
| 86 | - { |
|
| 87 | - return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
| 88 | - } |
|
| 77 | + /** |
|
| 78 | + * Check whether an individual is a Sosa ancestor. |
|
| 79 | + * |
|
| 80 | + * @param Tree $tree |
|
| 81 | + * @param UserInterface $user |
|
| 82 | + * @param Individual $indi |
|
| 83 | + * @return bool |
|
| 84 | + */ |
|
| 85 | + public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool |
|
| 86 | + { |
|
| 87 | + return $this->sosaNumbers($tree, $user, $indi)->count() > 0; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Returns all Sosa numbers associated to an Individual |
|
| 92 | - * |
|
| 93 | - * @param Tree $tree |
|
| 94 | - * @param UserInterface $user |
|
| 95 | - * @param Individual $indi |
|
| 96 | - * @return Collection<int, int> |
|
| 97 | - */ |
|
| 98 | - public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
| 99 | - { |
|
| 100 | - return Registry::cache()->array()->remember( |
|
| 101 | - 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
| 102 | - function () use ($tree, $user, $indi): Collection { |
|
| 103 | - return DB::table('maj_sosa') |
|
| 104 | - ->select(['majs_sosa', 'majs_gen']) |
|
| 105 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 106 | - ->where('majs_user_id', '=', $user->id()) |
|
| 107 | - ->where('majs_i_id', '=', $indi->xref()) |
|
| 108 | - ->orderBy('majs_sosa') |
|
| 109 | - ->get()->pluck('majs_gen', 'majs_sosa'); |
|
| 110 | - } |
|
| 111 | - ); |
|
| 112 | - } |
|
| 90 | + /** |
|
| 91 | + * Returns all Sosa numbers associated to an Individual |
|
| 92 | + * |
|
| 93 | + * @param Tree $tree |
|
| 94 | + * @param UserInterface $user |
|
| 95 | + * @param Individual $indi |
|
| 96 | + * @return Collection<int, int> |
|
| 97 | + */ |
|
| 98 | + public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection |
|
| 99 | + { |
|
| 100 | + return Registry::cache()->array()->remember( |
|
| 101 | + 'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(), |
|
| 102 | + function () use ($tree, $user, $indi): Collection { |
|
| 103 | + return DB::table('maj_sosa') |
|
| 104 | + ->select(['majs_sosa', 'majs_gen']) |
|
| 105 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 106 | + ->where('majs_user_id', '=', $user->id()) |
|
| 107 | + ->where('majs_i_id', '=', $indi->xref()) |
|
| 108 | + ->orderBy('majs_sosa') |
|
| 109 | + ->get()->pluck('majs_gen', 'majs_sosa'); |
|
| 110 | + } |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Return a list of the Sosa ancestors across all generation |
|
| 116 | - * |
|
| 117 | - * @param Tree $tree |
|
| 118 | - * @param UserInterface $user |
|
| 119 | - * @return Collection<\stdClass> |
|
| 120 | - */ |
|
| 121 | - public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
| 122 | - { |
|
| 123 | - return DB::table('maj_sosa') |
|
| 124 | - ->select(['majs_sosa', 'majs_i_id']) |
|
| 125 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 126 | - ->where('majs_user_id', '=', $user->id()) |
|
| 127 | - ->orderBy('majs_sosa') |
|
| 128 | - ->get(); |
|
| 129 | - } |
|
| 114 | + /** |
|
| 115 | + * Return a list of the Sosa ancestors across all generation |
|
| 116 | + * |
|
| 117 | + * @param Tree $tree |
|
| 118 | + * @param UserInterface $user |
|
| 119 | + * @return Collection<\stdClass> |
|
| 120 | + */ |
|
| 121 | + public function listAncestors(Tree $tree, UserInterface $user): Collection |
|
| 122 | + { |
|
| 123 | + return DB::table('maj_sosa') |
|
| 124 | + ->select(['majs_sosa', 'majs_i_id']) |
|
| 125 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 126 | + ->where('majs_user_id', '=', $user->id()) |
|
| 127 | + ->orderBy('majs_sosa') |
|
| 128 | + ->get(); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * Return a list of the Sosa ancestors at a given generation |
|
| 133 | - * |
|
| 134 | - * @param Tree $tree |
|
| 135 | - * @param UserInterface $user |
|
| 136 | - * @param int $gen |
|
| 137 | - * @return Collection<\stdClass> |
|
| 138 | - */ |
|
| 139 | - public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 140 | - { |
|
| 141 | - return DB::table('maj_sosa') |
|
| 142 | - ->select(['majs_sosa', 'majs_i_id']) |
|
| 143 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 144 | - ->where('majs_user_id', '=', $user->id()) |
|
| 145 | - ->where('majs_gen', '=', $gen) |
|
| 146 | - ->orderBy('majs_sosa') |
|
| 147 | - ->get(); |
|
| 148 | - } |
|
| 131 | + /** |
|
| 132 | + * Return a list of the Sosa ancestors at a given generation |
|
| 133 | + * |
|
| 134 | + * @param Tree $tree |
|
| 135 | + * @param UserInterface $user |
|
| 136 | + * @param int $gen |
|
| 137 | + * @return Collection<\stdClass> |
|
| 138 | + */ |
|
| 139 | + public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 140 | + { |
|
| 141 | + return DB::table('maj_sosa') |
|
| 142 | + ->select(['majs_sosa', 'majs_i_id']) |
|
| 143 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 144 | + ->where('majs_user_id', '=', $user->id()) |
|
| 145 | + ->where('majs_gen', '=', $gen) |
|
| 146 | + ->orderBy('majs_sosa') |
|
| 147 | + ->get(); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 151 | - * Return a list of the Sosa families at a given generation |
|
| 152 | - * |
|
| 153 | - * @param Tree $tree |
|
| 154 | - * @param UserInterface $user |
|
| 155 | - * @param int $gen |
|
| 156 | - * @return Collection<\stdClass> |
|
| 157 | - */ |
|
| 158 | - public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 159 | - { |
|
| 160 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 161 | - return DB::table('families') |
|
| 162 | - ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
| 163 | - // Link to family husband |
|
| 164 | - $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
| 165 | - ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
| 166 | - ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
| 167 | - ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
| 168 | - }) |
|
| 169 | - ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
| 170 | - // Link to family husband |
|
| 171 | - $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
| 172 | - ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
| 173 | - ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
| 174 | - ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
| 175 | - }) |
|
| 176 | - ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
| 177 | - ->where('sosa_husb.majs_gen', '=', $gen) |
|
| 178 | - ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
| 179 | - ->orderBy('sosa_husb.majs_sosa') |
|
| 180 | - ->get(); |
|
| 181 | - } |
|
| 150 | + /** |
|
| 151 | + * Return a list of the Sosa families at a given generation |
|
| 152 | + * |
|
| 153 | + * @param Tree $tree |
|
| 154 | + * @param UserInterface $user |
|
| 155 | + * @param int $gen |
|
| 156 | + * @return Collection<\stdClass> |
|
| 157 | + */ |
|
| 158 | + public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 159 | + { |
|
| 160 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 161 | + return DB::table('families') |
|
| 162 | + ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void { |
|
| 163 | + // Link to family husband |
|
| 164 | + $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id') |
|
| 165 | + ->on('families.f_husb', '=', 'sosa_husb.majs_i_id') |
|
| 166 | + ->where('sosa_husb.majs_gedcom_id', '=', $tree->id()) |
|
| 167 | + ->where('sosa_husb.majs_user_id', '=', $user->id()); |
|
| 168 | + }) |
|
| 169 | + ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void { |
|
| 170 | + // Link to family husband |
|
| 171 | + $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id') |
|
| 172 | + ->on('families.f_wife', '=', 'sosa_wife.majs_i_id') |
|
| 173 | + ->where('sosa_wife.majs_gedcom_id', '=', $tree->id()) |
|
| 174 | + ->where('sosa_wife.majs_user_id', '=', $user->id()); |
|
| 175 | + }) |
|
| 176 | + ->select(['sosa_husb.majs_sosa', 'families.f_id']) |
|
| 177 | + ->where('sosa_husb.majs_gen', '=', $gen) |
|
| 178 | + ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa') |
|
| 179 | + ->orderBy('sosa_husb.majs_sosa') |
|
| 180 | + ->get(); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Return a list of Sosa ancestors missing at a given generation. |
|
| 185 | - * It includes the reference of either parent if it is known. |
|
| 186 | - * |
|
| 187 | - * @param Tree $tree |
|
| 188 | - * @param UserInterface $user |
|
| 189 | - * @param int $gen |
|
| 190 | - * @return Collection<\stdClass> |
|
| 191 | - */ |
|
| 192 | - public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 193 | - { |
|
| 194 | - if ($gen == 1) { |
|
| 195 | - return collect(); |
|
| 196 | - } |
|
| 183 | + /** |
|
| 184 | + * Return a list of Sosa ancestors missing at a given generation. |
|
| 185 | + * It includes the reference of either parent if it is known. |
|
| 186 | + * |
|
| 187 | + * @param Tree $tree |
|
| 188 | + * @param UserInterface $user |
|
| 189 | + * @param int $gen |
|
| 190 | + * @return Collection<\stdClass> |
|
| 191 | + */ |
|
| 192 | + public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection |
|
| 193 | + { |
|
| 194 | + if ($gen == 1) { |
|
| 195 | + return collect(); |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - $table_prefix = DB::connection()->getTablePrefix(); |
|
| 199 | - return DB::table('maj_sosa AS sosa') |
|
| 200 | - ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
| 201 | - ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
| 202 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 203 | - // Link to sosa's father |
|
| 204 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 205 | - ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
| 206 | - ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
| 207 | - }) |
|
| 208 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 209 | - // Link to sosa's mother |
|
| 210 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 211 | - ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
| 212 | - ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
| 213 | - }) |
|
| 214 | - ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
| 215 | - ->where('sosa.majs_user_id', '=', $user->id()) |
|
| 216 | - ->where('sosa.majs_gen', '=', $gen - 1) |
|
| 217 | - ->where(function (Builder $query): void { |
|
| 218 | - $query->whereNull('sosa_fat.majs_i_id') |
|
| 219 | - ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 220 | - }) |
|
| 221 | - ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
| 222 | - ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
| 223 | - ->get(); |
|
| 224 | - } |
|
| 198 | + $table_prefix = DB::connection()->getTablePrefix(); |
|
| 199 | + return DB::table('maj_sosa AS sosa') |
|
| 200 | + ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id']) |
|
| 201 | + ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa') |
|
| 202 | + ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 203 | + // Link to sosa's father |
|
| 204 | + $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 205 | + ->where('sosa_fat.majs_gedcom_id', '=', $tree->id()) |
|
| 206 | + ->where('sosa_fat.majs_user_id', '=', $user->id()); |
|
| 207 | + }) |
|
| 208 | + ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void { |
|
| 209 | + // Link to sosa's mother |
|
| 210 | + $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 211 | + ->where('sosa_mot.majs_gedcom_id', '=', $tree->id()) |
|
| 212 | + ->where('sosa_mot.majs_user_id', '=', $user->id()); |
|
| 213 | + }) |
|
| 214 | + ->where('sosa.majs_gedcom_id', '=', $tree->id()) |
|
| 215 | + ->where('sosa.majs_user_id', '=', $user->id()) |
|
| 216 | + ->where('sosa.majs_gen', '=', $gen - 1) |
|
| 217 | + ->where(function (Builder $query): void { |
|
| 218 | + $query->whereNull('sosa_fat.majs_i_id') |
|
| 219 | + ->orWhereNull('sosa_mot.majs_i_id'); |
|
| 220 | + }) |
|
| 221 | + ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id') |
|
| 222 | + ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)') |
|
| 223 | + ->get(); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Remove all Sosa entries related to the gedcom file and user |
|
| 228 | - * |
|
| 229 | - * @param Tree $tree |
|
| 230 | - * @param UserInterface $user |
|
| 231 | - */ |
|
| 232 | - public function deleteAll(Tree $tree, UserInterface $user): void |
|
| 233 | - { |
|
| 234 | - DB::table('maj_sosa') |
|
| 235 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 236 | - ->where('majs_user_id', '=', $user->id()) |
|
| 237 | - ->delete(); |
|
| 238 | - } |
|
| 226 | + /** |
|
| 227 | + * Remove all Sosa entries related to the gedcom file and user |
|
| 228 | + * |
|
| 229 | + * @param Tree $tree |
|
| 230 | + * @param UserInterface $user |
|
| 231 | + */ |
|
| 232 | + public function deleteAll(Tree $tree, UserInterface $user): void |
|
| 233 | + { |
|
| 234 | + DB::table('maj_sosa') |
|
| 235 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 236 | + ->where('majs_user_id', '=', $user->id()) |
|
| 237 | + ->delete(); |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * |
|
| 242 | - * @param Tree $tree |
|
| 243 | - * @param UserInterface $user |
|
| 244 | - * @param int $sosa |
|
| 245 | - */ |
|
| 246 | - public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
| 247 | - { |
|
| 248 | - DB::table('maj_sosa') |
|
| 249 | - ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 250 | - ->where('majs_user_id', '=', $user->id()) |
|
| 251 | - ->where('majs_sosa', '>=', $sosa) |
|
| 252 | - ->whereRaw( |
|
| 253 | - 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
| 254 | - [$this->generation($sosa), $sosa] |
|
| 255 | - ) |
|
| 256 | - ->delete(); |
|
| 257 | - } |
|
| 240 | + /** |
|
| 241 | + * |
|
| 242 | + * @param Tree $tree |
|
| 243 | + * @param UserInterface $user |
|
| 244 | + * @param int $sosa |
|
| 245 | + */ |
|
| 246 | + public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void |
|
| 247 | + { |
|
| 248 | + DB::table('maj_sosa') |
|
| 249 | + ->where('majs_gedcom_id', '=', $tree->id()) |
|
| 250 | + ->where('majs_user_id', '=', $user->id()) |
|
| 251 | + ->where('majs_sosa', '>=', $sosa) |
|
| 252 | + ->whereRaw( |
|
| 253 | + 'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?', |
|
| 254 | + [$this->generation($sosa), $sosa] |
|
| 255 | + ) |
|
| 256 | + ->delete(); |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Insert (or update if already existing) a list of Sosa individuals |
|
| 261 | - * |
|
| 262 | - * @param Tree $tree |
|
| 263 | - * @param UserInterface $user |
|
| 264 | - * @param array<array<string,mixed>> $sosa_records |
|
| 265 | - */ |
|
| 266 | - public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
| 267 | - { |
|
| 268 | - $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
| 259 | + /** |
|
| 260 | + * Insert (or update if already existing) a list of Sosa individuals |
|
| 261 | + * |
|
| 262 | + * @param Tree $tree |
|
| 263 | + * @param UserInterface $user |
|
| 264 | + * @param array<array<string,mixed>> $sosa_records |
|
| 265 | + */ |
|
| 266 | + public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void |
|
| 267 | + { |
|
| 268 | + $mass_update = DB::connection()->getDriverName() === 'mysql'; |
|
| 269 | 269 | |
| 270 | - $bindings_placeholders = $bindings_values = []; |
|
| 271 | - $has_records = false; |
|
| 272 | - foreach ($sosa_records as $i => $row) { |
|
| 273 | - $gen = $this->generation($row['sosa']); |
|
| 274 | - if ($gen <= $this->maxSystemGenerations()) { |
|
| 275 | - $has_records = true; |
|
| 276 | - if ($mass_update) { |
|
| 277 | - $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
| 278 | - ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
| 279 | - ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
| 280 | - $bindings_values = array_merge( |
|
| 281 | - $bindings_values, |
|
| 282 | - [ |
|
| 283 | - 'tree_id' . $i => $tree->id(), |
|
| 284 | - 'user_id' . $i => $user->id(), |
|
| 285 | - 'sosa' . $i => $row['sosa'], |
|
| 286 | - 'indi_id' . $i => $row['indi'], |
|
| 287 | - 'gen' . $i => $gen, |
|
| 288 | - 'byear' . $i => $row['birth_year'], |
|
| 289 | - 'byearest' . $i => $row['birth_year_est'], |
|
| 290 | - 'dyear' . $i => $row['death_year'], |
|
| 291 | - 'dyearest' . $i => $row['death_year_est'] |
|
| 292 | - ] |
|
| 293 | - ); |
|
| 294 | - } else { |
|
| 295 | - DB::table('maj_sosa')->updateOrInsert( |
|
| 296 | - [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
| 297 | - [ |
|
| 298 | - 'majs_i_id' => $row['indi'], |
|
| 299 | - 'majs_gen' => $gen, |
|
| 300 | - 'majs_birth_year' => $row['birth_year'], |
|
| 301 | - 'majs_birth_year_est' => $row['birth_year_est'], |
|
| 302 | - 'majs_death_year' => $row['death_year'], |
|
| 303 | - 'majs_death_year_est' => $row['death_year_est'] |
|
| 304 | - ] |
|
| 305 | - ); |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - } |
|
| 270 | + $bindings_placeholders = $bindings_values = []; |
|
| 271 | + $has_records = false; |
|
| 272 | + foreach ($sosa_records as $i => $row) { |
|
| 273 | + $gen = $this->generation($row['sosa']); |
|
| 274 | + if ($gen <= $this->maxSystemGenerations()) { |
|
| 275 | + $has_records = true; |
|
| 276 | + if ($mass_update) { |
|
| 277 | + $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' . |
|
| 278 | + ' :indi_id' . $i . ', :gen' . $i . ',' . |
|
| 279 | + ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')'; |
|
| 280 | + $bindings_values = array_merge( |
|
| 281 | + $bindings_values, |
|
| 282 | + [ |
|
| 283 | + 'tree_id' . $i => $tree->id(), |
|
| 284 | + 'user_id' . $i => $user->id(), |
|
| 285 | + 'sosa' . $i => $row['sosa'], |
|
| 286 | + 'indi_id' . $i => $row['indi'], |
|
| 287 | + 'gen' . $i => $gen, |
|
| 288 | + 'byear' . $i => $row['birth_year'], |
|
| 289 | + 'byearest' . $i => $row['birth_year_est'], |
|
| 290 | + 'dyear' . $i => $row['death_year'], |
|
| 291 | + 'dyearest' . $i => $row['death_year_est'] |
|
| 292 | + ] |
|
| 293 | + ); |
|
| 294 | + } else { |
|
| 295 | + DB::table('maj_sosa')->updateOrInsert( |
|
| 296 | + [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']], |
|
| 297 | + [ |
|
| 298 | + 'majs_i_id' => $row['indi'], |
|
| 299 | + 'majs_gen' => $gen, |
|
| 300 | + 'majs_birth_year' => $row['birth_year'], |
|
| 301 | + 'majs_birth_year_est' => $row['birth_year_est'], |
|
| 302 | + 'majs_death_year' => $row['death_year'], |
|
| 303 | + 'majs_death_year_est' => $row['death_year_est'] |
|
| 304 | + ] |
|
| 305 | + ); |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - if ($has_records && $mass_update) { |
|
| 311 | - DB::connection()->statement( |
|
| 312 | - 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
| 313 | - ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
| 314 | - ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
| 315 | - ' VALUES ' . implode(',', $bindings_placeholders) . |
|
| 316 | - ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
| 317 | - ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
| 318 | - ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
| 319 | - $bindings_values |
|
| 320 | - ); |
|
| 321 | - } |
|
| 322 | - } |
|
| 310 | + if ($has_records && $mass_update) { |
|
| 311 | + DB::connection()->statement( |
|
| 312 | + 'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' . |
|
| 313 | + ' (majs_gedcom_id, majs_user_id, majs_sosa,' . |
|
| 314 | + ' majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
| 315 | + ' VALUES ' . implode(',', $bindings_placeholders) . |
|
| 316 | + ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' . |
|
| 317 | + ' majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' . |
|
| 318 | + ' majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)', |
|
| 319 | + $bindings_values |
|
| 320 | + ); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | 323 | } |
@@ -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 | } |
@@ -78,7 +78,7 @@ |
||
| 78 | 78 | if ($ancestor === null || !$ancestor->canShow()) { |
| 79 | 79 | continue; |
| 80 | 80 | } |
| 81 | - $generation = $this->records_service->generation((int) $item->majs_sosa); |
|
| 81 | + $generation = $this->records_service->generation((int)$item->majs_sosa); |
|
| 82 | 82 | $significantplace = new GeoAnalysisPlace($tree, null, $depth); |
| 83 | 83 | foreach ($this->significantPlaces($ancestor) as $place) { |
| 84 | 84 | $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true); |
@@ -59,186 +59,186 @@ |
||
| 59 | 59 | * Geographical Dispersion Module. |
| 60 | 60 | */ |
| 61 | 61 | class GeoDispersionModule extends AbstractModule implements |
| 62 | - ModuleMyArtJaubInterface, |
|
| 63 | - ModuleChartInterface, |
|
| 64 | - ModuleConfigInterface, |
|
| 65 | - ModuleGlobalInterface, |
|
| 66 | - ModuleGeoAnalysisProviderInterface, |
|
| 67 | - ModulePlaceMapperProviderInterface |
|
| 62 | + ModuleMyArtJaubInterface, |
|
| 63 | + ModuleChartInterface, |
|
| 64 | + ModuleConfigInterface, |
|
| 65 | + ModuleGlobalInterface, |
|
| 66 | + ModuleGeoAnalysisProviderInterface, |
|
| 67 | + ModulePlaceMapperProviderInterface |
|
| 68 | 68 | { |
| 69 | - use ModuleMyArtJaubTrait { |
|
| 70 | - boot as traitBoot; |
|
| 71 | - } |
|
| 72 | - use ModuleChartTrait; |
|
| 73 | - use ModuleConfigTrait; |
|
| 74 | - use ModuleGlobalTrait; |
|
| 75 | - |
|
| 76 | - // How to update the database schema for this module |
|
| 77 | - private const SCHEMA_TARGET_VERSION = 3; |
|
| 78 | - private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
|
| 79 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * {@inheritDoc} |
|
| 83 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 84 | - */ |
|
| 85 | - public function title(): string |
|
| 86 | - { |
|
| 87 | - return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * {@inheritDoc} |
|
| 92 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 93 | - */ |
|
| 94 | - public function description(): string |
|
| 95 | - { |
|
| 96 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 97 | - return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.'); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * {@inheritDoc} |
|
| 102 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 103 | - */ |
|
| 104 | - public function boot(): void |
|
| 105 | - { |
|
| 106 | - $this->traitBoot(); |
|
| 107 | - app(MigrationService::class)->updateSchema( |
|
| 108 | - self::SCHEMA_MIGRATION_PREFIX, |
|
| 109 | - self::SCHEMA_SETTING_NAME, |
|
| 110 | - self::SCHEMA_TARGET_VERSION |
|
| 111 | - ); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * {@inheritDoc} |
|
| 116 | - * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 117 | - */ |
|
| 118 | - public function customModuleVersion(): string |
|
| 119 | - { |
|
| 120 | - return '2.1.0-v.1'; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * {@inheritDoc} |
|
| 125 | - * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 126 | - */ |
|
| 127 | - public function loadRoutes(Map $router): void |
|
| 128 | - { |
|
| 129 | - $router->attach('', '', static function (Map $router): void { |
|
| 130 | - |
|
| 131 | - $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
| 132 | - $router->attach('', '/admin', static function (Map $router): void { |
|
| 133 | - $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
| 134 | - |
|
| 135 | - $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
| 136 | - $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
|
| 137 | - $router->extras([ |
|
| 138 | - 'middleware' => [ |
|
| 139 | - AuthManager::class, |
|
| 140 | - ], |
|
| 141 | - ]); |
|
| 142 | - $router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class); |
|
| 143 | - |
|
| 144 | - $router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class); |
|
| 145 | - $router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class); |
|
| 146 | - $router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class); |
|
| 147 | - $router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class); |
|
| 148 | - //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 149 | - $router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class); |
|
| 150 | - $router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class); |
|
| 151 | - //phpcs:enable |
|
| 152 | - }); |
|
| 153 | - |
|
| 154 | - $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
| 155 | - $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
|
| 156 | - $router->extras([ |
|
| 157 | - 'middleware' => [ |
|
| 158 | - AuthManager::class, |
|
| 159 | - ], |
|
| 160 | - ]); |
|
| 161 | - |
|
| 162 | - $router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class); |
|
| 163 | - $router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class); |
|
| 164 | - $router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class); |
|
| 165 | - $router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class); |
|
| 166 | - //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 167 | - $router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class); |
|
| 168 | - $router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class); |
|
| 169 | - $router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class); |
|
| 170 | - //phpcs:enable |
|
| 171 | - }); |
|
| 172 | - |
|
| 173 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 174 | - $router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class); |
|
| 175 | - }); |
|
| 176 | - |
|
| 177 | - $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
|
| 178 | - |
|
| 179 | - $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
| 180 | - $router->tokens(['view_id' => '\d+']); |
|
| 181 | - $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
|
| 182 | - $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
|
| 183 | - }); |
|
| 184 | - }); |
|
| 185 | - }); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - public function getConfigLink(): string |
|
| 189 | - { |
|
| 190 | - return route(AdminConfigPage::class); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * {@inheritDoc} |
|
| 195 | - * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl() |
|
| 196 | - */ |
|
| 197 | - public function chartUrl(Individual $individual, array $parameters = []): string |
|
| 198 | - { |
|
| 199 | - return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * {@inheritDoc} |
|
| 204 | - * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass() |
|
| 205 | - */ |
|
| 206 | - public function chartMenuClass(): string |
|
| 207 | - { |
|
| 208 | - return 'menu-maj-geodispersion'; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * {@inheritDoc} |
|
| 213 | - * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
| 214 | - */ |
|
| 215 | - public function headContent(): string |
|
| 216 | - { |
|
| 217 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * {@inheritDoc} |
|
| 222 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers() |
|
| 223 | - */ |
|
| 224 | - public function listPlaceMappers(): array |
|
| 225 | - { |
|
| 226 | - return [ |
|
| 227 | - CoordinatesPlaceMapper::class, |
|
| 228 | - SimplePlaceMapper::class, |
|
| 229 | - SimpleTopFilteredPlaceMapper::class |
|
| 230 | - ]; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * {@inheritDoc} |
|
| 235 | - * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
| 236 | - */ |
|
| 237 | - public function listGeoAnalyses(): array |
|
| 238 | - { |
|
| 239 | - return [ |
|
| 240 | - AllEventsByCenturyGeoAnalysis::class, |
|
| 241 | - AllEventsByTypeGeoAnalysis::class |
|
| 242 | - ]; |
|
| 243 | - } |
|
| 69 | + use ModuleMyArtJaubTrait { |
|
| 70 | + boot as traitBoot; |
|
| 71 | + } |
|
| 72 | + use ModuleChartTrait; |
|
| 73 | + use ModuleConfigTrait; |
|
| 74 | + use ModuleGlobalTrait; |
|
| 75 | + |
|
| 76 | + // How to update the database schema for this module |
|
| 77 | + private const SCHEMA_TARGET_VERSION = 3; |
|
| 78 | + private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
|
| 79 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * {@inheritDoc} |
|
| 83 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::title() |
|
| 84 | + */ |
|
| 85 | + public function title(): string |
|
| 86 | + { |
|
| 87 | + return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * {@inheritDoc} |
|
| 92 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::description() |
|
| 93 | + */ |
|
| 94 | + public function description(): string |
|
| 95 | + { |
|
| 96 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 97 | + return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.'); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * {@inheritDoc} |
|
| 102 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::boot() |
|
| 103 | + */ |
|
| 104 | + public function boot(): void |
|
| 105 | + { |
|
| 106 | + $this->traitBoot(); |
|
| 107 | + app(MigrationService::class)->updateSchema( |
|
| 108 | + self::SCHEMA_MIGRATION_PREFIX, |
|
| 109 | + self::SCHEMA_SETTING_NAME, |
|
| 110 | + self::SCHEMA_TARGET_VERSION |
|
| 111 | + ); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * {@inheritDoc} |
|
| 116 | + * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion() |
|
| 117 | + */ |
|
| 118 | + public function customModuleVersion(): string |
|
| 119 | + { |
|
| 120 | + return '2.1.0-v.1'; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * {@inheritDoc} |
|
| 125 | + * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes() |
|
| 126 | + */ |
|
| 127 | + public function loadRoutes(Map $router): void |
|
| 128 | + { |
|
| 129 | + $router->attach('', '', static function (Map $router): void { |
|
| 130 | + |
|
| 131 | + $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
| 132 | + $router->attach('', '/admin', static function (Map $router): void { |
|
| 133 | + $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
|
| 134 | + |
|
| 135 | + $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
| 136 | + $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
|
| 137 | + $router->extras([ |
|
| 138 | + 'middleware' => [ |
|
| 139 | + AuthManager::class, |
|
| 140 | + ], |
|
| 141 | + ]); |
|
| 142 | + $router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class); |
|
| 143 | + |
|
| 144 | + $router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class); |
|
| 145 | + $router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class); |
|
| 146 | + $router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class); |
|
| 147 | + $router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class); |
|
| 148 | + //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 149 | + $router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class); |
|
| 150 | + $router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class); |
|
| 151 | + //phpcs:enable |
|
| 152 | + }); |
|
| 153 | + |
|
| 154 | + $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
| 155 | + $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
|
| 156 | + $router->extras([ |
|
| 157 | + 'middleware' => [ |
|
| 158 | + AuthManager::class, |
|
| 159 | + ], |
|
| 160 | + ]); |
|
| 161 | + |
|
| 162 | + $router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class); |
|
| 163 | + $router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class); |
|
| 164 | + $router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class); |
|
| 165 | + $router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class); |
|
| 166 | + //phpcs:disable Generic.Files.LineLength.TooLong |
|
| 167 | + $router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class); |
|
| 168 | + $router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class); |
|
| 169 | + $router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class); |
|
| 170 | + //phpcs:enable |
|
| 171 | + }); |
|
| 172 | + |
|
| 173 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 174 | + $router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class); |
|
| 175 | + }); |
|
| 176 | + |
|
| 177 | + $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
|
| 178 | + |
|
| 179 | + $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
| 180 | + $router->tokens(['view_id' => '\d+']); |
|
| 181 | + $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
|
| 182 | + $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
|
| 183 | + }); |
|
| 184 | + }); |
|
| 185 | + }); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + public function getConfigLink(): string |
|
| 189 | + { |
|
| 190 | + return route(AdminConfigPage::class); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * {@inheritDoc} |
|
| 195 | + * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl() |
|
| 196 | + */ |
|
| 197 | + public function chartUrl(Individual $individual, array $parameters = []): string |
|
| 198 | + { |
|
| 199 | + return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * {@inheritDoc} |
|
| 204 | + * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass() |
|
| 205 | + */ |
|
| 206 | + public function chartMenuClass(): string |
|
| 207 | + { |
|
| 208 | + return 'menu-maj-geodispersion'; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * {@inheritDoc} |
|
| 213 | + * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent() |
|
| 214 | + */ |
|
| 215 | + public function headContent(): string |
|
| 216 | + { |
|
| 217 | + return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * {@inheritDoc} |
|
| 222 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers() |
|
| 223 | + */ |
|
| 224 | + public function listPlaceMappers(): array |
|
| 225 | + { |
|
| 226 | + return [ |
|
| 227 | + CoordinatesPlaceMapper::class, |
|
| 228 | + SimplePlaceMapper::class, |
|
| 229 | + SimpleTopFilteredPlaceMapper::class |
|
| 230 | + ]; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * {@inheritDoc} |
|
| 235 | + * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses() |
|
| 236 | + */ |
|
| 237 | + public function listGeoAnalyses(): array |
|
| 238 | + { |
|
| 239 | + return [ |
|
| 240 | + AllEventsByCenturyGeoAnalysis::class, |
|
| 241 | + AllEventsByTypeGeoAnalysis::class |
|
| 242 | + ]; |
|
| 243 | + } |
|
| 244 | 244 | } |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | // How to update the database schema for this module |
| 77 | 77 | private const SCHEMA_TARGET_VERSION = 3; |
| 78 | 78 | private const SCHEMA_SETTING_NAME = 'MAJ_GEODISP_SCHEMA_VERSION'; |
| 79 | - private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema'; |
|
| 79 | + private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema'; |
|
| 80 | 80 | |
| 81 | 81 | /** |
| 82 | 82 | * {@inheritDoc} |
@@ -126,13 +126,13 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function loadRoutes(Map $router): void |
| 128 | 128 | { |
| 129 | - $router->attach('', '', static function (Map $router): void { |
|
| 129 | + $router->attach('', '', static function(Map $router): void { |
|
| 130 | 130 | |
| 131 | - $router->attach('', '/module-maj/geodispersion', static function (Map $router): void { |
|
| 132 | - $router->attach('', '/admin', static function (Map $router): void { |
|
| 131 | + $router->attach('', '/module-maj/geodispersion', static function(Map $router): void { |
|
| 132 | + $router->attach('', '/admin', static function(Map $router): void { |
|
| 133 | 133 | $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class); |
| 134 | 134 | |
| 135 | - $router->attach('', '/analysis-views/{tree}', static function (Map $router): void { |
|
| 135 | + $router->attach('', '/analysis-views/{tree}', static function(Map $router): void { |
|
| 136 | 136 | $router->tokens(['view_id' => '\d+', 'enable' => '[01]']); |
| 137 | 137 | $router->extras([ |
| 138 | 138 | 'middleware' => [ |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | //phpcs:enable |
| 152 | 152 | }); |
| 153 | 153 | |
| 154 | - $router->attach('', '/map-adapters/{tree}', static function (Map $router): void { |
|
| 154 | + $router->attach('', '/map-adapters/{tree}', static function(Map $router): void { |
|
| 155 | 155 | $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']); |
| 156 | 156 | $router->extras([ |
| 157 | 157 | 'middleware' => [ |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class); |
| 178 | 178 | |
| 179 | - $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void { |
|
| 179 | + $router->attach('', '/analysisview/{tree}/{view_id}', static function(Map $router): void { |
|
| 180 | 180 | $router->tokens(['view_id' => '\d+']); |
| 181 | 181 | $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class); |
| 182 | 182 | $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class); |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | public function headContent(): string |
| 216 | 216 | { |
| 217 | - return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">'; |
|
| 217 | + return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">'; |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -38,64 +38,64 @@ |
||
| 38 | 38 | */ |
| 39 | 39 | class GeoAnalysisViewEditPage implements RequestHandlerInterface |
| 40 | 40 | { |
| 41 | - use ViewResponseTrait; |
|
| 41 | + use ViewResponseTrait; |
|
| 42 | 42 | |
| 43 | - private ?GeoDispersionModule $module; |
|
| 44 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
| 45 | - private GeoAnalysisService $geoanalysis_service; |
|
| 46 | - private GeoAnalysisDataService $geoanalysis_data_service; |
|
| 43 | + private ?GeoDispersionModule $module; |
|
| 44 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
| 45 | + private GeoAnalysisService $geoanalysis_service; |
|
| 46 | + private GeoAnalysisDataService $geoanalysis_data_service; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Constructor for GeoAnalysisViewEditPage Request Handler |
|
| 50 | - * |
|
| 51 | - * @param ModuleService $module_service |
|
| 52 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 53 | - * @param GeoAnalysisService $geoanalysis_service |
|
| 54 | - * @param GeoAnalysisDataService $geoanalysis_data_service |
|
| 55 | - */ |
|
| 56 | - public function __construct( |
|
| 57 | - ModuleService $module_service, |
|
| 58 | - GeoAnalysisViewDataService $geoview_data_service, |
|
| 59 | - GeoAnalysisService $geoanalysis_service, |
|
| 60 | - GeoAnalysisDataService $geoanalysis_data_service |
|
| 61 | - ) { |
|
| 62 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 63 | - $this->geoview_data_service = $geoview_data_service; |
|
| 64 | - $this->geoanalysis_service = $geoanalysis_service; |
|
| 65 | - $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
| 66 | - } |
|
| 48 | + /** |
|
| 49 | + * Constructor for GeoAnalysisViewEditPage Request Handler |
|
| 50 | + * |
|
| 51 | + * @param ModuleService $module_service |
|
| 52 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 53 | + * @param GeoAnalysisService $geoanalysis_service |
|
| 54 | + * @param GeoAnalysisDataService $geoanalysis_data_service |
|
| 55 | + */ |
|
| 56 | + public function __construct( |
|
| 57 | + ModuleService $module_service, |
|
| 58 | + GeoAnalysisViewDataService $geoview_data_service, |
|
| 59 | + GeoAnalysisService $geoanalysis_service, |
|
| 60 | + GeoAnalysisDataService $geoanalysis_data_service |
|
| 61 | + ) { |
|
| 62 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 63 | + $this->geoview_data_service = $geoview_data_service; |
|
| 64 | + $this->geoanalysis_service = $geoanalysis_service; |
|
| 65 | + $this->geoanalysis_data_service = $geoanalysis_data_service; |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * {@inheritDoc} |
|
| 70 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 71 | - */ |
|
| 72 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 73 | - { |
|
| 74 | - $this->layout = 'layouts/administration'; |
|
| 68 | + /** |
|
| 69 | + * {@inheritDoc} |
|
| 70 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 71 | + */ |
|
| 72 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 73 | + { |
|
| 74 | + $this->layout = 'layouts/administration'; |
|
| 75 | 75 | |
| 76 | - if ($this->module === null) { |
|
| 77 | - throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 78 | - } |
|
| 79 | - $tree = $request->getAttribute('tree'); |
|
| 80 | - assert($tree instanceof Tree); |
|
| 76 | + if ($this->module === null) { |
|
| 77 | + throw new HttpNotFoundException(I18N::translate('The attached module could not be found.')); |
|
| 78 | + } |
|
| 79 | + $tree = $request->getAttribute('tree'); |
|
| 80 | + assert($tree instanceof Tree); |
|
| 81 | 81 | |
| 82 | - $view_id = (int) $request->getAttribute('view_id'); |
|
| 83 | - $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
| 82 | + $view_id = (int) $request->getAttribute('view_id'); |
|
| 83 | + $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
| 84 | 84 | |
| 85 | - if ($view === null) { |
|
| 86 | - throw new HttpNotFoundException( |
|
| 87 | - I18N::translate('The geographical dispersion analysis view could not be found.') |
|
| 88 | - ); |
|
| 89 | - } |
|
| 85 | + if ($view === null) { |
|
| 86 | + throw new HttpNotFoundException( |
|
| 87 | + I18N::translate('The geographical dispersion analysis view could not be found.') |
|
| 88 | + ); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 92 | - 'module' => $this->module, |
|
| 93 | - 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
|
| 94 | - 'tree' => $tree, |
|
| 95 | - 'view' => $view, |
|
| 96 | - 'geoanalysis_list' => $this->geoanalysis_service->all(), |
|
| 97 | - 'place_example' => $this->geoanalysis_data_service->placeHierarchyExample($tree), |
|
| 98 | - 'global_settings' => $view->globalSettingsContent($this->module) |
|
| 99 | - ]); |
|
| 100 | - } |
|
| 91 | + return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 92 | + 'module' => $this->module, |
|
| 93 | + 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
|
| 94 | + 'tree' => $tree, |
|
| 95 | + 'view' => $view, |
|
| 96 | + 'geoanalysis_list' => $this->geoanalysis_service->all(), |
|
| 97 | + 'place_example' => $this->geoanalysis_data_service->placeHierarchyExample($tree), |
|
| 98 | + 'global_settings' => $view->globalSettingsContent($this->module) |
|
| 99 | + ]); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | $tree = $request->getAttribute('tree'); |
| 80 | 80 | assert($tree instanceof Tree); |
| 81 | 81 | |
| 82 | - $view_id = (int) $request->getAttribute('view_id'); |
|
| 82 | + $view_id = (int)$request->getAttribute('view_id'); |
|
| 83 | 83 | $view = $this->geoview_data_service->find($tree, $view_id, true); |
| 84 | 84 | |
| 85 | 85 | if ($view === null) { |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | ); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - return $this->viewResponse($this->module->name() . '::admin/view-edit', [ |
|
| 91 | + return $this->viewResponse($this->module->name().'::admin/view-edit', [ |
|
| 92 | 92 | 'module' => $this->module, |
| 93 | 93 | 'title' => I18N::translate('Edit the geographical dispersion analysis view - %s', $view->type()), |
| 94 | 94 | 'tree' => $tree, |
@@ -34,89 +34,89 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class GeoAnalysisViewEditAction implements RequestHandlerInterface |
| 36 | 36 | { |
| 37 | - private ?GeoDispersionModule $module; |
|
| 38 | - private GeoAnalysisViewDataService $geoview_data_service; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Constructor for GeoAnalysisViewEditAction Request Handler |
|
| 42 | - * |
|
| 43 | - * @param ModuleService $module_service |
|
| 44 | - * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 45 | - */ |
|
| 46 | - public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
| 47 | - { |
|
| 48 | - $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 49 | - $this->geoview_data_service = $geoview_data_service; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * {@inheritDoc} |
|
| 54 | - * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 55 | - */ |
|
| 56 | - public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 57 | - { |
|
| 58 | - $tree = $request->getAttribute('tree'); |
|
| 59 | - assert($tree instanceof Tree); |
|
| 60 | - |
|
| 61 | - $admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 62 | - |
|
| 63 | - if ($this->module === null) { |
|
| 64 | - FlashMessages::addMessage( |
|
| 65 | - I18N::translate('The attached module could not be found.'), |
|
| 66 | - 'danger' |
|
| 67 | - ); |
|
| 68 | - return redirect($admin_config_route); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - |
|
| 72 | - $view_id = (int) $request->getAttribute('view_id'); |
|
| 73 | - $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
| 74 | - |
|
| 75 | - $params = (array) $request->getParsedBody(); |
|
| 76 | - |
|
| 77 | - $description = $params['view_description'] ?? ''; |
|
| 78 | - $place_depth = (int) ($params['view_depth'] ?? 1); |
|
| 79 | - $top_places = (int) ($params['view_top_places'] ?? 0); |
|
| 80 | - |
|
| 81 | - $analysis = null; |
|
| 82 | - try { |
|
| 83 | - $analysis = app($params['view_analysis'] ?? ''); |
|
| 84 | - } catch (BindingResolutionException $ex) { |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if ( |
|
| 88 | - $view === null |
|
| 89 | - || $analysis === null || !($analysis instanceof GeoAnalysisInterface) |
|
| 90 | - || $place_depth <= 0 && $top_places < 0 |
|
| 91 | - ) { |
|
| 92 | - FlashMessages::addMessage( |
|
| 93 | - I18N::translate('The parameters for view with ID “%s” are not valid.', I18N::number($view_id)), |
|
| 94 | - 'danger' |
|
| 95 | - ); |
|
| 96 | - return redirect($admin_config_route); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $new_view = $view |
|
| 100 | - ->with($view->isEnabled(), $description, $analysis, $place_depth, $top_places) |
|
| 101 | - ->withGlobalSettingsUpdate($request); |
|
| 102 | - |
|
| 103 | - try { |
|
| 104 | - $this->geoview_data_service->update($new_view); |
|
| 105 | - FlashMessages::addMessage( |
|
| 106 | - I18N::translate('The geographical dispersion analysis view has been successfully updated.'), |
|
| 107 | - 'success' |
|
| 108 | - ); |
|
| 109 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 110 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
| 111 | - } catch (Throwable $ex) { |
|
| 112 | - FlashMessages::addMessage( |
|
| 113 | - I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
|
| 114 | - 'danger' |
|
| 115 | - ); |
|
| 116 | - //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 117 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return redirect($admin_config_route); |
|
| 121 | - } |
|
| 37 | + private ?GeoDispersionModule $module; |
|
| 38 | + private GeoAnalysisViewDataService $geoview_data_service; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Constructor for GeoAnalysisViewEditAction Request Handler |
|
| 42 | + * |
|
| 43 | + * @param ModuleService $module_service |
|
| 44 | + * @param GeoAnalysisViewDataService $geoview_data_service |
|
| 45 | + */ |
|
| 46 | + public function __construct(ModuleService $module_service, GeoAnalysisViewDataService $geoview_data_service) |
|
| 47 | + { |
|
| 48 | + $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first(); |
|
| 49 | + $this->geoview_data_service = $geoview_data_service; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * {@inheritDoc} |
|
| 54 | + * @see \Psr\Http\Server\RequestHandlerInterface::handle() |
|
| 55 | + */ |
|
| 56 | + public function handle(ServerRequestInterface $request): ResponseInterface |
|
| 57 | + { |
|
| 58 | + $tree = $request->getAttribute('tree'); |
|
| 59 | + assert($tree instanceof Tree); |
|
| 60 | + |
|
| 61 | + $admin_config_route = route(AdminConfigPage::class, ['tree' => $tree->name()]); |
|
| 62 | + |
|
| 63 | + if ($this->module === null) { |
|
| 64 | + FlashMessages::addMessage( |
|
| 65 | + I18N::translate('The attached module could not be found.'), |
|
| 66 | + 'danger' |
|
| 67 | + ); |
|
| 68 | + return redirect($admin_config_route); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + |
|
| 72 | + $view_id = (int) $request->getAttribute('view_id'); |
|
| 73 | + $view = $this->geoview_data_service->find($tree, $view_id, true); |
|
| 74 | + |
|
| 75 | + $params = (array) $request->getParsedBody(); |
|
| 76 | + |
|
| 77 | + $description = $params['view_description'] ?? ''; |
|
| 78 | + $place_depth = (int) ($params['view_depth'] ?? 1); |
|
| 79 | + $top_places = (int) ($params['view_top_places'] ?? 0); |
|
| 80 | + |
|
| 81 | + $analysis = null; |
|
| 82 | + try { |
|
| 83 | + $analysis = app($params['view_analysis'] ?? ''); |
|
| 84 | + } catch (BindingResolutionException $ex) { |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if ( |
|
| 88 | + $view === null |
|
| 89 | + || $analysis === null || !($analysis instanceof GeoAnalysisInterface) |
|
| 90 | + || $place_depth <= 0 && $top_places < 0 |
|
| 91 | + ) { |
|
| 92 | + FlashMessages::addMessage( |
|
| 93 | + I18N::translate('The parameters for view with ID “%s” are not valid.', I18N::number($view_id)), |
|
| 94 | + 'danger' |
|
| 95 | + ); |
|
| 96 | + return redirect($admin_config_route); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $new_view = $view |
|
| 100 | + ->with($view->isEnabled(), $description, $analysis, $place_depth, $top_places) |
|
| 101 | + ->withGlobalSettingsUpdate($request); |
|
| 102 | + |
|
| 103 | + try { |
|
| 104 | + $this->geoview_data_service->update($new_view); |
|
| 105 | + FlashMessages::addMessage( |
|
| 106 | + I18N::translate('The geographical dispersion analysis view has been successfully updated.'), |
|
| 107 | + 'success' |
|
| 108 | + ); |
|
| 109 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 110 | + Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
| 111 | + } catch (Throwable $ex) { |
|
| 112 | + FlashMessages::addMessage( |
|
| 113 | + I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
|
| 114 | + 'danger' |
|
| 115 | + ); |
|
| 116 | + //phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 117 | + Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return redirect($admin_config_route); |
|
| 121 | + } |
|
| 122 | 122 | } |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
| 72 | - $view_id = (int) $request->getAttribute('view_id'); |
|
| 72 | + $view_id = (int)$request->getAttribute('view_id'); |
|
| 73 | 73 | $view = $this->geoview_data_service->find($tree, $view_id, true); |
| 74 | 74 | |
| 75 | - $params = (array) $request->getParsedBody(); |
|
| 75 | + $params = (array)$request->getParsedBody(); |
|
| 76 | 76 | |
| 77 | 77 | $description = $params['view_description'] ?? ''; |
| 78 | - $place_depth = (int) ($params['view_depth'] ?? 1); |
|
| 79 | - $top_places = (int) ($params['view_top_places'] ?? 0); |
|
| 78 | + $place_depth = (int)($params['view_depth'] ?? 1); |
|
| 79 | + $top_places = (int)($params['view_top_places'] ?? 0); |
|
| 80 | 80 | |
| 81 | 81 | $analysis = null; |
| 82 | 82 | try { |
@@ -107,14 +107,14 @@ discard block |
||
| 107 | 107 | 'success' |
| 108 | 108 | ); |
| 109 | 109 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 110 | - Log::addConfigurationLog('Module ' . $this->module->title() . ' : View “' . $view->id() . '” has been updated.'); |
|
| 110 | + Log::addConfigurationLog('Module '.$this->module->title().' : View “'.$view->id().'” has been updated.'); |
|
| 111 | 111 | } catch (Throwable $ex) { |
| 112 | 112 | FlashMessages::addMessage( |
| 113 | 113 | I18N::translate('An error occured while updating the geographical dispersion analysis view.'), |
| 114 | 114 | 'danger' |
| 115 | 115 | ); |
| 116 | 116 | //phpcs:ignore Generic.Files.LineLength.TooLong |
| 117 | - Log::addErrorLog('Module ' . $this->module->title() . ' : Error when updating view “' . $view->id() . '”: ' . $ex->getMessage()); |
|
| 117 | + Log::addErrorLog('Module '.$this->module->title().' : Error when updating view “'.$view->id().'”: '.$ex->getMessage()); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | return redirect($admin_config_route); |