@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | // Permissions are configured |
| 48 | 48 | if (is_numeric($permission_level)) { |
| 49 | 49 | // Logged in with the correct role? |
| 50 | - if (Auth::accessLevel($tree, $user) <= (int) $permission_level) { |
|
| 50 | + if (Auth::accessLevel($tree, $user) <= (int)$permission_level) { |
|
| 51 | 51 | return $handler->handle($request); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | return Registry::responseFactory()->redirect( |
| 66 | 66 | LoginPage::class, |
| 67 | - ['tree' => $tree->name(), 'url' => (string) $request->getUri()] |
|
| 67 | + ['tree' => $tree->name(), 'url' => (string)$request->getUri()] |
|
| 68 | 68 | ); |
| 69 | 69 | } |
| 70 | 70 | } |
@@ -53,8 +53,8 @@ discard block |
||
| 53 | 53 | |
| 54 | 54 | // Cannot use Validator with negative integers issue webtrees #4408 |
| 55 | 55 | // $user_id = Validator::parsedBody($request)->integer('user_id', Auth::id() ?? 0); |
| 56 | - $parsed_body = (array) $request->getParsedBody(); |
|
| 57 | - $user_id = (int) filter_var($parsed_body['user_id'] ?? Auth::id(), FILTER_VALIDATE_INT); |
|
| 56 | + $parsed_body = (array)$request->getParsedBody(); |
|
| 57 | + $user_id = (int)filter_var($parsed_body['user_id'] ?? Auth::id(), FILTER_VALIDATE_INT); |
|
| 58 | 58 | |
| 59 | 59 | $partial_from = Validator::parsedBody($request)->isXref()->string('partial_from', ''); |
| 60 | 60 | |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
| 63 | 63 | |
| 64 | 64 | /** @var SosaCalculatorService $sosa_calc_service */ |
| 65 | - $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, [ 'tree' => $tree, 'user' => $user]); |
|
| 65 | + $sosa_calc_service = app()->makeWith(SosaCalculatorService::class, ['tree' => $tree, 'user' => $user]); |
|
| 66 | 66 | |
| 67 | 67 | if ( |
| 68 | 68 | $partial_from !== '' && |
@@ -74,8 +74,7 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | return $res ? |
| 77 | - Registry::responseFactory()->response() : |
|
| 78 | - Registry::responseFactory()->response( |
|
| 77 | + Registry::responseFactory()->response() : Registry::responseFactory()->response( |
|
| 79 | 78 | I18N::translate('An error occurred while computing Sosa ancestors.'), |
| 80 | 79 | StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR |
| 81 | 80 | ); |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | |
| 59 | 59 | $tree = Validator::attributes($request)->tree(); |
| 60 | 60 | |
| 61 | - return Registry::responseFactory()->response(view($this->module->name() . '::modals/sosa-compute', [ |
|
| 61 | + return Registry::responseFactory()->response(view($this->module->name().'::modals/sosa-compute', [ |
|
| 62 | 62 | 'tree' => $tree, |
| 63 | 63 | 'xref' => Validator::attributes($request)->isXref()->string('xref', '') |
| 64 | 64 | ])); |
@@ -86,14 +86,13 @@ |
||
| 86 | 86 | $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations(); |
| 87 | 87 | foreach ($users_root as $key => $user_root) { |
| 88 | 88 | $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ? |
| 89 | - (int) $user_root['max_gen'] : |
|
| 90 | - $max_gen_system; |
|
| 89 | + (int)$user_root['max_gen'] : $max_gen_system; |
|
| 91 | 90 | }; |
| 92 | 91 | |
| 93 | 92 | // Cannot use Validator with negative integers issue webtrees #4408 |
| 94 | - $selected_user_id = (int) filter_var($request->getQueryParams()['user_id'] ?? 0, FILTER_VALIDATE_INT); |
|
| 93 | + $selected_user_id = (int)filter_var($request->getQueryParams()['user_id'] ?? 0, FILTER_VALIDATE_INT); |
|
| 95 | 94 | |
| 96 | - return $this->viewResponse($this->module->name() . '::config-page', [ |
|
| 95 | + return $this->viewResponse($this->module->name().'::config-page', [ |
|
| 97 | 96 | 'module_name' => $this->module->name(), |
| 98 | 97 | 'title' => I18N::translate('Sosa Configuration'), |
| 99 | 98 | 'tree' => $tree, |
@@ -89,18 +89,18 @@ |
||
| 89 | 89 | |
| 90 | 90 | /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */ |
| 91 | 91 | $list_ancestors = $list_ancestors |
| 92 | - ->filter(function (stdClass $value) use ($tree): bool { |
|
| 92 | + ->filter(function(stdClass $value) use ($tree): bool { |
|
| 93 | 93 | $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
| 94 | 94 | return $indi !== null && $indi->canShowName(); |
| 95 | 95 | }) |
| 96 | - ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
| 96 | + ->mapWithKeys(function(stdClass $value) use ($tree): array { |
|
| 97 | 97 | $indi = Registry::individualFactory()->make($value->majs_i_id, $tree); |
| 98 | - return [(int) $value->majs_sosa => $indi]; |
|
| 98 | + return [(int)$value->majs_sosa => $indi]; |
|
| 99 | 99 | }); |
| 100 | 100 | |
| 101 | 101 | $nb_ancestors_shown = $list_ancestors->count(); |
| 102 | 102 | |
| 103 | - return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [ |
|
| 103 | + return $this->viewResponse($this->module->name().'::list-ancestors-indi-tab', [ |
|
| 104 | 104 | 'module_name' => $this->module->name(), |
| 105 | 105 | 'title' => I18N::translate('Sosa Ancestors'), |
| 106 | 106 | 'tree' => $tree, |
@@ -89,18 +89,18 @@ |
||
| 89 | 89 | |
| 90 | 90 | /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */ |
| 91 | 91 | $list_families = $list_families |
| 92 | - ->filter(function (stdClass $value) use ($tree): bool { |
|
| 92 | + ->filter(function(stdClass $value) use ($tree): bool { |
|
| 93 | 93 | $fam = Registry::familyFactory()->make($value->f_id, $tree); |
| 94 | 94 | return $fam !== null && $fam->canShow(); |
| 95 | 95 | }) |
| 96 | - ->mapWithKeys(function (stdClass $value) use ($tree): array { |
|
| 96 | + ->mapWithKeys(function(stdClass $value) use ($tree): array { |
|
| 97 | 97 | $fam = Registry::familyFactory()->make($value->f_id, $tree); |
| 98 | - return [(int) $value->majs_sosa => $fam]; |
|
| 98 | + return [(int)$value->majs_sosa => $fam]; |
|
| 99 | 99 | }); |
| 100 | 100 | |
| 101 | 101 | $nb_families_shown = $list_families->count(); |
| 102 | 102 | |
| 103 | - return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [ |
|
| 103 | + return $this->viewResponse($this->module->name().'::list-ancestors-fam-tab', [ |
|
| 104 | 104 | 'module_name' => $this->module->name(), |
| 105 | 105 | 'title' => I18N::translate('Sosa Ancestors'), |
| 106 | 106 | 'tree' => $tree, |
@@ -56,8 +56,8 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | // Cannot use Validator with negative integers issue webtrees #4408 |
| 58 | 58 | //$user_id = Validator::parsedBody($request)->integer('sosa-userid', -1); |
| 59 | - $parsed_body = (array) $request->getParsedBody(); |
|
| 60 | - $user_id = (int) filter_var($parsed_body['sosa-userid'] ?? 0, FILTER_VALIDATE_INT); |
|
| 59 | + $parsed_body = (array)$request->getParsedBody(); |
|
| 60 | + $user_id = (int)filter_var($parsed_body['sosa-userid'] ?? 0, FILTER_VALIDATE_INT); |
|
| 61 | 61 | $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', ''); |
| 62 | 62 | $max_gen = Validator::parsedBody($request)->integer( |
| 63 | 63 | 'sosa-maxgen', |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $user = $user_id === -1 ? new DefaultUser() : $this->user_service->find($user_id); |
| 69 | 69 | if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) { |
| 70 | 70 | $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref()); |
| 71 | - $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen); |
|
| 71 | + $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string)$max_gen); |
|
| 72 | 72 | FlashMessages::addMessage(I18N::translate('The root individual has been updated.')); |
| 73 | 73 | return Registry::responseFactory()->redirect(SosaConfig::class, [ |
| 74 | 74 | 'tree' => $tree->name(), |
@@ -72,14 +72,14 @@ |
||
| 72 | 72 | |
| 73 | 73 | $unique_ancestors = $this->records_service |
| 74 | 74 | ->listAncestors($tree, Auth::check() ? Auth::user() : new DefaultUser()) |
| 75 | - ->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id); |
|
| 75 | + ->uniqueStrict(fn(stdClass $item) : string => $item->majs_i_id); |
|
| 76 | 76 | |
| 77 | 77 | foreach ($unique_ancestors as $item) { |
| 78 | 78 | $ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree); |
| 79 | 79 | if ($ancestor === null || !$ancestor->canShow()) { |
| 80 | 80 | continue; |
| 81 | 81 | } |
| 82 | - $generation = $this->records_service->generation((int) $item->majs_sosa); |
|
| 82 | + $generation = $this->records_service->generation((int)$item->majs_sosa); |
|
| 83 | 83 | $significantplace = new GeoAnalysisPlace($tree, null, $depth); |
| 84 | 84 | foreach ($this->significantPlaces($ancestor) as $place) { |
| 85 | 85 | $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true); |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | */ |
| 75 | 75 | public function maxGeneration(): int |
| 76 | 76 | { |
| 77 | - return (int) DB::table('maj_sosa') |
|
| 77 | + return (int)DB::table('maj_sosa') |
|
| 78 | 78 | ->where('majs_gedcom_id', '=', $this->tree->id()) |
| 79 | 79 | ->where('majs_user_id', '=', $this->user->id()) |
| 80 | 80 | ->max('majs_gen'); |
@@ -151,8 +151,7 @@ discard block |
||
| 151 | 151 | ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2') |
| 152 | 152 | ->get()->first(); |
| 153 | 153 | |
| 154 | - return $row->n === 0 ? 0 : |
|
| 155 | - -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2)); |
|
| 154 | + return $row->n === 0 ? 0 : -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / ($row->n * $row->sum_x2 - pow($row->sum_x, 2)); |
|
| 156 | 155 | } |
| 157 | 156 | |
| 158 | 157 | /** |
@@ -176,10 +175,10 @@ discard block |
||
| 176 | 175 | |
| 177 | 176 | $statistics_by_gen = []; |
| 178 | 177 | foreach ($stats_by_gen as $gen => $stats_gen) { |
| 179 | - $statistics_by_gen[(int) $stats_gen->gen] = array( |
|
| 180 | - 'sosaCount' => (int) $stats_gen->total_sosa, |
|
| 181 | - 'sosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_cumul, |
|
| 182 | - 'diffSosaTotalCount' => (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
| 178 | + $statistics_by_gen[(int)$stats_gen->gen] = array( |
|
| 179 | + 'sosaCount' => (int)$stats_gen->total_sosa, |
|
| 180 | + 'sosaTotalCount' => (int)$cumul_stats_by_gen[$gen]->total_cumul, |
|
| 181 | + 'diffSosaTotalCount' => (int)$cumul_stats_by_gen[$gen]->total_distinct_cumul, |
|
| 183 | 182 | 'firstBirth' => $stats_gen->first_year, |
| 184 | 183 | 'firstEstimatedBirth' => $stats_gen->first_est_year, |
| 185 | 184 | 'lastBirth' => $stats_gen->last_year, |
@@ -223,7 +222,7 @@ discard block |
||
| 223 | 222 | ->where('majs_user_id', '=', $this->user->id()); |
| 224 | 223 | |
| 225 | 224 | return DB::table('maj_sosa') |
| 226 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 225 | + ->joinSub($list_gen, 'list_gen', function(JoinClause $join): void { |
|
| 227 | 226 | $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen') |
| 228 | 227 | ->where('majs_gedcom_id', '=', $this->tree->id()) |
| 229 | 228 | ->where('majs_user_id', '=', $this->user->id()); |
@@ -264,37 +263,37 @@ discard block |
||
| 264 | 263 | ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
| 265 | 264 | ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
| 266 | 265 | ->selectRaw( |
| 267 | - '(CASE ' . |
|
| 268 | - ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' . |
|
| 269 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 270 | - ' ELSE 0 ' . |
|
| 271 | - ' END)' . |
|
| 272 | - ' + (CASE ' . |
|
| 273 | - ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' . |
|
| 274 | - ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' . |
|
| 275 | - ' ELSE 0 ' . |
|
| 266 | + '(CASE '. |
|
| 267 | + ' WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL'. |
|
| 268 | + ' THEN POWER(2, '.$table_prefix.'list_gen.majs_gen - '.$table_prefix.'sosa.majs_gen - 1)'. |
|
| 269 | + ' ELSE 0 '. |
|
| 270 | + ' END)'. |
|
| 271 | + ' + (CASE '. |
|
| 272 | + ' WHEN '.$table_prefix.'sosa_mot.majs_i_id IS NULL'. |
|
| 273 | + ' THEN POWER(2, '.$table_prefix.'list_gen.majs_gen - '.$table_prefix.'sosa.majs_gen - 1)'. |
|
| 274 | + ' ELSE 0 '. |
|
| 276 | 275 | ' END) contrib' |
| 277 | 276 | ) |
| 278 | - ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void { |
|
| 277 | + ->joinSub($list_gen, 'list_gen', function(JoinClause $join): void { |
|
| 279 | 278 | $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen') |
| 280 | 279 | ->where('majs_gedcom_id', '=', $this->tree->id()) |
| 281 | 280 | ->where('majs_user_id', '=', $this->user->id()); |
| 282 | 281 | }) |
| 283 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 282 | + ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void { |
|
| 284 | 283 | // Link to sosa's father |
| 285 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 284 | + $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa') |
|
| 286 | 285 | ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
| 287 | 286 | ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
| 288 | 287 | }) |
| 289 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 288 | + ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void { |
|
| 290 | 289 | // Link to sosa's mother |
| 291 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 290 | + $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1') |
|
| 292 | 291 | ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
| 293 | 292 | ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
| 294 | 293 | }) |
| 295 | 294 | ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
| 296 | 295 | ->where('sosa.majs_user_id', '=', $this->user->id()) |
| 297 | - ->where(function (Builder $query): void { |
|
| 296 | + ->where(function(Builder $query): void { |
|
| 298 | 297 | $query->whereNull('sosa_fat.majs_i_id') |
| 299 | 298 | ->orWhereNull('sosa_mot.majs_i_id'); |
| 300 | 299 | }); |
@@ -304,24 +303,24 @@ discard block |
||
| 304 | 303 | */ |
| 305 | 304 | $non_roots_ancestors = DB::table('maj_sosa AS sosa') |
| 306 | 305 | ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa']) |
| 307 | - ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' . |
|
| 306 | + ->selectRaw('MAX('.$table_prefix.'sosa_anc.majs_sosa) - MIN('.$table_prefix.'sosa_anc.majs_sosa)'. |
|
| 308 | 307 | ' AS full_ancestors') |
| 309 | - ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void { |
|
| 308 | + ->join('maj_sosa AS sosa_anc', function(JoinClause $join) use ($table_prefix): void { |
|
| 310 | 309 | $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen') |
| 311 | - ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' . |
|
| 312 | - $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' . |
|
| 313 | - $table_prefix . 'sosa.majs_sosa') |
|
| 310 | + ->whereRaw('FLOOR('.$table_prefix.'sosa_anc.majs_sosa / POWER(2, '. |
|
| 311 | + $table_prefix.'sosa_anc.majs_gen - '.$table_prefix.'sosa.majs_gen)) = '. |
|
| 312 | + $table_prefix.'sosa.majs_sosa') |
|
| 314 | 313 | ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id()) |
| 315 | 314 | ->where('sosa_anc.majs_user_id', '=', $this->user->id()); |
| 316 | 315 | }) |
| 317 | 316 | ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
| 318 | 317 | ->where('sosa.majs_user_id', '=', $this->user->id()) |
| 319 | - ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void { |
|
| 318 | + ->whereIn('sosa_anc.majs_i_id', function(Builder $query) use ($table_prefix): void { |
|
| 320 | 319 | $query->from('maj_sosa AS sosa_gen') |
| 321 | 320 | ->select('sosa_gen.majs_i_id')->distinct() |
| 322 | 321 | ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id()) |
| 323 | 322 | ->where('sosa_gen.majs_user_id', '=', $this->user->id()) |
| 324 | - ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen'); |
|
| 323 | + ->whereRaw($table_prefix.'sosa_gen.majs_gen = '.$table_prefix.'sosa.majs_gen'); |
|
| 325 | 324 | }) |
| 326 | 325 | ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', |
| 327 | 326 | 'sosa.majs_sosa', 'sosa.majs_i_id']); |
@@ -334,7 +333,7 @@ discard block |
||
| 334 | 333 | ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id']) |
| 335 | 334 | ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen']) |
| 336 | 335 | ->selectRaw('1 AS contrib') |
| 337 | - ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void { |
|
| 336 | + ->leftJoinSub($non_roots_ancestors, 'nonroot', function(JoinClause $join): void { |
|
| 338 | 337 | $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen') |
| 339 | 338 | ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa') |
| 340 | 339 | ->where('nonroot.full_ancestors', '>', 0) |
@@ -352,9 +351,9 @@ discard block |
||
| 352 | 351 | ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs') |
| 353 | 352 | ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id']) |
| 354 | 353 | ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib']) |
| 355 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' . |
|
| 356 | - $table_prefix . 'sosa_contribs.contrib AS totalContrib') |
|
| 357 | - ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void { |
|
| 354 | + ->selectRaw('COUNT('.$table_prefix.'sosa_contribs.majs_i_id) * '. |
|
| 355 | + $table_prefix.'sosa_contribs.contrib AS totalContrib') |
|
| 356 | + ->leftJoin('maj_sosa AS sosa_low', function(JoinClause $join): void { |
|
| 358 | 357 | $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen') |
| 359 | 358 | ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id') |
| 360 | 359 | ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id()) |
@@ -375,9 +374,9 @@ discard block |
||
| 375 | 374 | |
| 376 | 375 | $pedi_collapse_by_gen = []; |
| 377 | 376 | foreach ($pedi_collapse_coll as $collapse_gen) { |
| 378 | - $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array( |
|
| 379 | - 'pedi_collapse_roots' => (float) $collapse_gen->pedi_collapse_roots, |
|
| 380 | - 'pedi_collapse_xgen' => (float) $collapse_gen->pedi_collapse_xgen |
|
| 377 | + $pedi_collapse_by_gen[(int)$collapse_gen->gen] = array( |
|
| 378 | + 'pedi_collapse_roots' => (float)$collapse_gen->pedi_collapse_roots, |
|
| 379 | + 'pedi_collapse_xgen' => (float)$collapse_gen->pedi_collapse_xgen |
|
| 381 | 380 | ); |
| 382 | 381 | } |
| 383 | 382 | return $pedi_collapse_by_gen; |
@@ -409,26 +408,26 @@ discard block |
||
| 409 | 408 | |
| 410 | 409 | $table_prefix = DB::connection()->getTablePrefix(); |
| 411 | 410 | $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa') |
| 412 | - ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
| 413 | - ->selectRaw('FLOOR(((' . $table_prefix . 'sosa.majs_sosa / POW(2, ' . $table_prefix . 'sosa.majs_gen -1 )) - 1) * POWER(2, ? - 1)) + POWER(2, ? - 1) AS root_ancestor', [$gen, $gen]) //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 414 | - ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 1 ELSE 0 END) AS full_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 415 | - ->selectRaw('SUM(CASE WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL AND ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL THEN 0 ELSE 1 END) As semi_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 416 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 411 | + ->selectRaw($table_prefix.'sosa.majs_gen - ? AS majs_gen_norm', [$gen]) |
|
| 412 | + ->selectRaw('FLOOR((('.$table_prefix.'sosa.majs_sosa / POW(2, '.$table_prefix.'sosa.majs_gen -1 )) - 1) * POWER(2, ? - 1)) + POWER(2, ? - 1) AS root_ancestor', [$gen, $gen]) //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 413 | + ->selectRaw('SUM(CASE WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL AND '.$table_prefix.'sosa_mot.majs_i_id IS NULL THEN 1 ELSE 0 END) AS full_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 414 | + ->selectRaw('SUM(CASE WHEN '.$table_prefix.'sosa_fat.majs_i_id IS NULL AND '.$table_prefix.'sosa_mot.majs_i_id IS NULL THEN 0 ELSE 1 END) As semi_root_count') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 415 | + ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void { |
|
| 417 | 416 | // Link to sosa's father |
| 418 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 417 | + $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa') |
|
| 419 | 418 | ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
| 420 | 419 | ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
| 421 | 420 | }) |
| 422 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 421 | + ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void { |
|
| 423 | 422 | // Link to sosa's mother |
| 424 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 423 | + $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1') |
|
| 425 | 424 | ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
| 426 | 425 | ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
| 427 | 426 | }) |
| 428 | 427 | ->where('sosa.majs_gedcom_id', '=', $this->tree->id()) |
| 429 | 428 | ->where('sosa.majs_user_id', '=', $this->user->id()) |
| 430 | 429 | ->where('sosa.majs_gen', '>=', $gen) |
| 431 | - ->where(function (Builder $query): void { |
|
| 430 | + ->where(function(Builder $query): void { |
|
| 432 | 431 | $query->whereNull('sosa_fat.majs_i_id') |
| 433 | 432 | ->orWhereNull('sosa_mot.majs_i_id'); |
| 434 | 433 | }) |
@@ -437,11 +436,11 @@ discard block |
||
| 437 | 436 | return DB::table('maj_sosa AS sosa_list') |
| 438 | 437 | ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id']) |
| 439 | 438 | ->selectRaw('1 + SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))) AS mean_gen_depth') //@phpcs:ignore Generic.Files.LineLength.TooLong |
| 440 | - ->selectRaw(' SQRT(' . |
|
| 441 | - ' SUM(POWER(majs_gen_norm, 2) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm)))' . //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 442 | - ' - POWER( SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))), 2)' . //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 439 | + ->selectRaw(' SQRT('. |
|
| 440 | + ' SUM(POWER(majs_gen_norm, 2) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm)))'.//@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 441 | + ' - POWER( SUM( (majs_gen_norm) * ( 2 * full_root_count + semi_root_count) / (2 * POWER(2, majs_gen_norm))), 2)'.//@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 443 | 442 | ' ) AS stddev_gen_depth') |
| 444 | - ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void { |
|
| 443 | + ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function(JoinClause $join): void { |
|
| 445 | 444 | $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor') |
| 446 | 445 | ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id()) |
| 447 | 446 | ->where('sosa_list.majs_user_id', '=', $this->user->id()); |
@@ -470,16 +469,16 @@ discard block |
||
| 470 | 469 | $table_prefix = DB::connection()->getTablePrefix(); |
| 471 | 470 | $multiple_ancestors = DB::table('maj_sosa AS sosa') |
| 472 | 471 | ->select('sosa.majs_i_id AS sosa_i_id') |
| 473 | - ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count') |
|
| 474 | - ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void { |
|
| 472 | + ->selectRaw('COUNT('.$table_prefix.'sosa.majs_sosa) AS sosa_count') |
|
| 473 | + ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($table_prefix): void { |
|
| 475 | 474 | // Link to sosa's father |
| 476 | - $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa') |
|
| 475 | + $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa') |
|
| 477 | 476 | ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id()) |
| 478 | 477 | ->where('sosa_fat.majs_user_id', '=', $this->user->id()); |
| 479 | 478 | }) |
| 480 | - ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void { |
|
| 479 | + ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($table_prefix): void { |
|
| 481 | 480 | // Link to sosa's mother |
| 482 | - $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1') |
|
| 481 | + $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1') |
|
| 483 | 482 | ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id()) |
| 484 | 483 | ->where('sosa_mot.majs_user_id', '=', $this->user->id()); |
| 485 | 484 | }) |
@@ -488,15 +487,15 @@ discard block |
||
| 488 | 487 | ->whereNull('sosa_fat.majs_sosa') // We keep only root individuals, i.e. those with no father or mother |
| 489 | 488 | ->whereNull('sosa_mot.majs_sosa') |
| 490 | 489 | ->groupBy('sosa.majs_i_id') |
| 491 | - ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
| 492 | - ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 490 | + ->havingRaw('COUNT('.$table_prefix.'sosa.majs_sosa) > 1') // Limit to the duplicate sosas. |
|
| 491 | + ->orderByRaw('COUNT('.$table_prefix.'sosa.majs_sosa) DESC, MIN('.$table_prefix.'sosa.majs_sosa) ASC') //@phpcs:ignore Generic.Files.LineLength.TooLong |
|
| 493 | 492 | ->limit($limit + 1) // We want to select one more than required, for ties |
| 494 | 493 | ->get(); |
| 495 | 494 | |
| 496 | 495 | if ($multiple_ancestors->count() > $limit) { |
| 497 | 496 | $last_count = $multiple_ancestors->last()->sosa_count; |
| 498 | 497 | $multiple_ancestors = $multiple_ancestors->reject( |
| 499 | - fn (stdClass $element): bool => $element->sosa_count === $last_count |
|
| 498 | + fn (stdClass $element): bool => $element->sosa_count === $last_count |
|
| 500 | 499 | ); |
| 501 | 500 | } |
| 502 | 501 | return $multiple_ancestors; |
@@ -551,7 +550,7 @@ discard block |
||
| 551 | 550 | ->rightJoinSub( |
| 552 | 551 | $consolidated_ancestors_branches, |
| 553 | 552 | 'indi_branch_consolidated', |
| 554 | - function (JoinClause $join) use ($gen): void { |
|
| 553 | + function(JoinClause $join) use ($gen): void { |
|
| 555 | 554 | $join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id()) |
| 556 | 555 | ->where('maj_sosa.majs_user_id', '=', $this->user->id()) |
| 557 | 556 | ->where('branches', '>', 0) |