Passed
Push — feature/code-analysis ( a2ce2d...28b704 )
by Jonathan
04:31
created
app/Module/Sosa/Http/RequestHandlers/SosaStatistics.php 1 patch
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -38,142 +38,142 @@
 block discarded – undo
38 38
  */
39 39
 class SosaStatistics implements RequestHandlerInterface
40 40
 {
41
-    use ViewResponseTrait;
42
-
43
-    private ?SosaModule $module;
44
-    private RelationshipService $relationship_service;
45
-
46
-    /**
47
-     * Constructor for AncestorsList Request Handler
48
-     *
49
-     * @param ModuleService $module_service
50
-     */
51
-    public function __construct(ModuleService $module_service, RelationshipService $relationship_service)
52
-    {
53
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
54
-        $this->relationship_service = $relationship_service;
55
-    }
56
-
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
60
-     */
61
-    public function handle(ServerRequestInterface $request): ResponseInterface
62
-    {
63
-        if ($this->module === null) {
64
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
65
-        }
66
-
67
-        $tree = Validator::attributes($request)->tree();
68
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
69
-
70
-        /** @var SosaStatisticsService $sosa_stats_service */
71
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
72
-
73
-        return $this->viewResponse($this->module->name() . '::statistics-page', [
74
-            'module_name'       =>  $this->module->name(),
75
-            'title'             =>  I18N::translate('Sosa Statistics'),
76
-            'tree'              =>  $tree,
77
-            'theme'             =>  app(ModuleThemeInterface::class),
78
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
79
-            'general_stats'     =>  $this->statisticsGeneral($sosa_stats_service),
80
-            'generation_stats'  =>  $this->statisticsByGenerations($sosa_stats_service),
81
-            'generation_depth'  =>  $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(),
82
-            'multiple_sosas'    =>  $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'),
83
-            'sosa_dispersion_g2' =>  $sosa_stats_service->ancestorsDispersionForGeneration(2),
84
-            'sosa_dispersion_g3' =>  $sosa_stats_service->ancestorsDispersionForGeneration(3),
85
-            'gen_depth_g3'      =>  $sosa_stats_service->generationDepthStatsAtGeneration(3),
86
-            'relationship_service'  =>  $this->relationship_service,
87
-        ]);
88
-    }
89
-
90
-    /**
91
-     * Retrieve and compute the global statistics of ancestors for the tree.
92
-     * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse...
93
-     *
94
-     * @param SosaStatisticsService $sosa_stats_service
95
-     * @return array<string, int|float>
96
-     */
97
-    private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array
98
-    {
99
-        $ancestors_count = $sosa_stats_service->totalAncestors();
100
-        $ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors();
101
-        $individual_count = $sosa_stats_service->totalIndividuals();
102
-
103
-        return [
104
-            'sosa_count'    =>  $ancestors_count,
105
-            'distinct_count'    =>  $ancestors_distinct_count,
106
-            'sosa_rate' =>  $this->safeDivision(
107
-                BigInteger::of($ancestors_distinct_count),
108
-                BigInteger::of($individual_count)
109
-            ),
110
-            'mean_gen_time'         =>  $sosa_stats_service->meanGenerationTime()
111
-        ];
112
-    }
113
-
114
-    /**
115
-     * Retrieve and compute the statistics of ancestors by generations.
116
-     * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics...
117
-     *
118
-     * @param SosaStatisticsService $sosa_stats_service
119
-     * @return array<int, array<string, int|float>>
120
-     */
121
-    private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array
122
-    {
123
-        $stats_by_gen = $sosa_stats_service->statisticsByGenerations();
124
-
125
-        $generation_stats = array();
126
-
127
-        foreach ($stats_by_gen as $gen => $stats_gen) {
128
-            $gen_diff = $gen > 1 ?
129
-                (int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
130
-                1;
131
-            $generation_stats[$gen] = array(
132
-                'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
133
-                'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
134
-                'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(),
135
-                'known' => (int) $stats_gen['sosaCount'],
136
-                'perc_known' => $this->safeDivision(
137
-                    BigInteger::of((int) $stats_gen['sosaCount']),
138
-                    BigInteger::of(2)->power($gen - 1)
139
-                ),
140
-                'missing' => $gen > 1 ?
141
-                    2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
142
-                    0,
143
-                'perc_missing' => $gen > 1 ?
144
-                    1 - $this->safeDivision(
145
-                        BigInteger::of((int) $stats_gen['sosaCount']),
146
-                        BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount'])
147
-                    ) :
148
-                    0,
149
-                'total_known' => (int) $stats_gen['sosaTotalCount'],
150
-                'perc_total_known' => $this->safeDivision(
151
-                    BigInteger::of((int) $stats_gen['sosaTotalCount']),
152
-                    BigInteger::of(2)->power($gen)->minus(1)
153
-                ),
154
-                'different' => $gen_diff,
155
-                'perc_different' => $this->safeDivision(
156
-                    BigInteger::of($gen_diff),
157
-                    BigInteger::of((int) $stats_gen['sosaCount'])
158
-                ),
159
-                'total_different' => (int) $stats_gen['diffSosaTotalCount']
160
-            );
161
-        }
162
-
163
-        return $generation_stats;
164
-    }
165
-
166
-    /**
167
-     * Return the result of a division, and a default value if denominator is 0
168
-     *
169
-     * @param BigInteger $p Numerator
170
-     * @param BigInteger $q Denominator
171
-     * @param int $scale Rounding scale
172
-     * @param float $default Value if denominator is 0
173
-     * @return float
174
-     */
175
-    private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float
176
-    {
177
-        return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat();
178
-    }
41
+	use ViewResponseTrait;
42
+
43
+	private ?SosaModule $module;
44
+	private RelationshipService $relationship_service;
45
+
46
+	/**
47
+	 * Constructor for AncestorsList Request Handler
48
+	 *
49
+	 * @param ModuleService $module_service
50
+	 */
51
+	public function __construct(ModuleService $module_service, RelationshipService $relationship_service)
52
+	{
53
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
54
+		$this->relationship_service = $relationship_service;
55
+	}
56
+
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
60
+	 */
61
+	public function handle(ServerRequestInterface $request): ResponseInterface
62
+	{
63
+		if ($this->module === null) {
64
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
65
+		}
66
+
67
+		$tree = Validator::attributes($request)->tree();
68
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
69
+
70
+		/** @var SosaStatisticsService $sosa_stats_service */
71
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
72
+
73
+		return $this->viewResponse($this->module->name() . '::statistics-page', [
74
+			'module_name'       =>  $this->module->name(),
75
+			'title'             =>  I18N::translate('Sosa Statistics'),
76
+			'tree'              =>  $tree,
77
+			'theme'             =>  app(ModuleThemeInterface::class),
78
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
79
+			'general_stats'     =>  $this->statisticsGeneral($sosa_stats_service),
80
+			'generation_stats'  =>  $this->statisticsByGenerations($sosa_stats_service),
81
+			'generation_depth'  =>  $sosa_stats_service->generationDepthStatsAtGeneration(1)->first(),
82
+			'multiple_sosas'    =>  $sosa_stats_service->topMultipleAncestorsWithNoTies(10)->groupBy('sosa_count'),
83
+			'sosa_dispersion_g2' =>  $sosa_stats_service->ancestorsDispersionForGeneration(2),
84
+			'sosa_dispersion_g3' =>  $sosa_stats_service->ancestorsDispersionForGeneration(3),
85
+			'gen_depth_g3'      =>  $sosa_stats_service->generationDepthStatsAtGeneration(3),
86
+			'relationship_service'  =>  $this->relationship_service,
87
+		]);
88
+	}
89
+
90
+	/**
91
+	 * Retrieve and compute the global statistics of ancestors for the tree.
92
+	 * Statistics include the number of ancestors, the number of different ancestors, pedigree collapse...
93
+	 *
94
+	 * @param SosaStatisticsService $sosa_stats_service
95
+	 * @return array<string, int|float>
96
+	 */
97
+	private function statisticsGeneral(SosaStatisticsService $sosa_stats_service): array
98
+	{
99
+		$ancestors_count = $sosa_stats_service->totalAncestors();
100
+		$ancestors_distinct_count = $sosa_stats_service->totalDistinctAncestors();
101
+		$individual_count = $sosa_stats_service->totalIndividuals();
102
+
103
+		return [
104
+			'sosa_count'    =>  $ancestors_count,
105
+			'distinct_count'    =>  $ancestors_distinct_count,
106
+			'sosa_rate' =>  $this->safeDivision(
107
+				BigInteger::of($ancestors_distinct_count),
108
+				BigInteger::of($individual_count)
109
+			),
110
+			'mean_gen_time'         =>  $sosa_stats_service->meanGenerationTime()
111
+		];
112
+	}
113
+
114
+	/**
115
+	 * Retrieve and compute the statistics of ancestors by generations.
116
+	 * Statistics include the number of ancestors, the number of different ancestors, cumulative statistics...
117
+	 *
118
+	 * @param SosaStatisticsService $sosa_stats_service
119
+	 * @return array<int, array<string, int|float>>
120
+	 */
121
+	private function statisticsByGenerations(SosaStatisticsService $sosa_stats_service): array
122
+	{
123
+		$stats_by_gen = $sosa_stats_service->statisticsByGenerations();
124
+
125
+		$generation_stats = array();
126
+
127
+		foreach ($stats_by_gen as $gen => $stats_gen) {
128
+			$gen_diff = $gen > 1 ?
129
+				(int) $stats_gen['diffSosaTotalCount'] - (int) $stats_by_gen[$gen - 1]['diffSosaTotalCount'] :
130
+				1;
131
+			$generation_stats[$gen] = array(
132
+				'gen_min_birth' => $stats_gen['firstBirth'] ?? (int) $stats_gen['firstEstimatedBirth'],
133
+				'gen_max_birth' => $stats_gen['lastBirth'] ?? (int) $stats_gen['lastEstimatedBirth'],
134
+				'theoretical' => BigInteger::of(2)->power($gen - 1)->toInt(),
135
+				'known' => (int) $stats_gen['sosaCount'],
136
+				'perc_known' => $this->safeDivision(
137
+					BigInteger::of((int) $stats_gen['sosaCount']),
138
+					BigInteger::of(2)->power($gen - 1)
139
+				),
140
+				'missing' => $gen > 1 ?
141
+					2 * (int) $stats_by_gen[$gen - 1]['sosaCount'] - (int) $stats_gen['sosaCount'] :
142
+					0,
143
+				'perc_missing' => $gen > 1 ?
144
+					1 - $this->safeDivision(
145
+						BigInteger::of((int) $stats_gen['sosaCount']),
146
+						BigInteger::of(2 * (int) $stats_by_gen[$gen - 1]['sosaCount'])
147
+					) :
148
+					0,
149
+				'total_known' => (int) $stats_gen['sosaTotalCount'],
150
+				'perc_total_known' => $this->safeDivision(
151
+					BigInteger::of((int) $stats_gen['sosaTotalCount']),
152
+					BigInteger::of(2)->power($gen)->minus(1)
153
+				),
154
+				'different' => $gen_diff,
155
+				'perc_different' => $this->safeDivision(
156
+					BigInteger::of($gen_diff),
157
+					BigInteger::of((int) $stats_gen['sosaCount'])
158
+				),
159
+				'total_different' => (int) $stats_gen['diffSosaTotalCount']
160
+			);
161
+		}
162
+
163
+		return $generation_stats;
164
+	}
165
+
166
+	/**
167
+	 * Return the result of a division, and a default value if denominator is 0
168
+	 *
169
+	 * @param BigInteger $p Numerator
170
+	 * @param BigInteger $q Denominator
171
+	 * @param int $scale Rounding scale
172
+	 * @param float $default Value if denominator is 0
173
+	 * @return float
174
+	 */
175
+	private function safeDivision(BigInteger $p, BigInteger $q, int $scale = 10, float $default = 0): float
176
+	{
177
+		return $q->isZero() ? $default : $p->toBigDecimal()->dividedBy($q, $scale, RoundingMode::HALF_DOWN)->toFloat();
178
+	}
179 179
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/AncestorsListIndividual.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -36,71 +36,71 @@
 block discarded – undo
36 36
  */
37 37
 class AncestorsListIndividual implements RequestHandlerInterface
38 38
 {
39
-    use ViewResponseTrait;
40
-
41
-    /**
42
-     * @var SosaModule|null $module
43
-     */
44
-    private $module;
45
-
46
-    /**
47
-     * @var SosaRecordsService $sosa_record_service
48
-     */
49
-    private $sosa_record_service;
50
-
51
-    /**
52
-     * Constructor for AncestorsListIndividual Request Handler
53
-     *
54
-     * @param ModuleService $module_service
55
-     * @param SosaRecordsService $sosa_record_service
56
-     */
57
-    public function __construct(
58
-        ModuleService $module_service,
59
-        SosaRecordsService $sosa_record_service
60
-    ) {
61
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
62
-        $this->sosa_record_service = $sosa_record_service;
63
-    }
64
-
65
-    /**
66
-     * {@inheritDoc}
67
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
68
-     */
69
-    public function handle(ServerRequestInterface $request): ResponseInterface
70
-    {
71
-        $this->layout = 'layouts/ajax';
72
-
73
-        if ($this->module === null) {
74
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
75
-        }
76
-
77
-        $tree = Validator::attributes($request)->tree();
78
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
79
-        $current_gen = Validator::attributes($request)->integer('gen', 0);
80
-
81
-        if ($current_gen <= 0) {
82
-            return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
83
-        }
84
-
85
-        $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen);
86
-        $nb_ancestors_all = $list_ancestors->count();
87
-
88
-        /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
89
-        $list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array {
90
-                $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
91
-                return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null;
92
-        })->filter();
93
-
94
-        $nb_ancestors_shown = $list_ancestors->count();
95
-
96
-        return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
97
-            'module_name'       =>  $this->module->name(),
98
-            'title'             =>  I18N::translate('Sosa Ancestors'),
99
-            'tree'              =>  $tree,
100
-            'list_ancestors'    =>  $list_ancestors,
101
-            'nb_ancestors_all'  =>  $nb_ancestors_all,
102
-            'nb_ancestors_theor' =>  pow(2, $current_gen - 1),
103
-            'nb_ancestors_shown' =>  $nb_ancestors_shown
104
-        ]);
105
-    }
39
+	use ViewResponseTrait;
40
+
41
+	/**
42
+	 * @var SosaModule|null $module
43
+	 */
44
+	private $module;
45
+
46
+	/**
47
+	 * @var SosaRecordsService $sosa_record_service
48
+	 */
49
+	private $sosa_record_service;
50
+
51
+	/**
52
+	 * Constructor for AncestorsListIndividual Request Handler
53
+	 *
54
+	 * @param ModuleService $module_service
55
+	 * @param SosaRecordsService $sosa_record_service
56
+	 */
57
+	public function __construct(
58
+		ModuleService $module_service,
59
+		SosaRecordsService $sosa_record_service
60
+	) {
61
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
62
+		$this->sosa_record_service = $sosa_record_service;
63
+	}
64
+
65
+	/**
66
+	 * {@inheritDoc}
67
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
68
+	 */
69
+	public function handle(ServerRequestInterface $request): ResponseInterface
70
+	{
71
+		$this->layout = 'layouts/ajax';
72
+
73
+		if ($this->module === null) {
74
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
75
+		}
76
+
77
+		$tree = Validator::attributes($request)->tree();
78
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
79
+		$current_gen = Validator::attributes($request)->integer('gen', 0);
80
+
81
+		if ($current_gen <= 0) {
82
+			return response('Invalid generation', StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY);
83
+		}
84
+
85
+		$list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen);
86
+		$nb_ancestors_all = $list_ancestors->count();
87
+
88
+		/** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
89
+		$list_ancestors = $list_ancestors->mapWithKeys(function (stdClass $value) use ($tree): ?array {
90
+				$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
91
+				return ($indi !== null && $indi->canShowName()) ? [(int) $value->majs_sosa => $indi] : null;
92
+		})->filter();
93
+
94
+		$nb_ancestors_shown = $list_ancestors->count();
95
+
96
+		return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
97
+			'module_name'       =>  $this->module->name(),
98
+			'title'             =>  I18N::translate('Sosa Ancestors'),
99
+			'tree'              =>  $tree,
100
+			'list_ancestors'    =>  $list_ancestors,
101
+			'nb_ancestors_all'  =>  $nb_ancestors_all,
102
+			'nb_ancestors_theor' =>  pow(2, $current_gen - 1),
103
+			'nb_ancestors_shown' =>  $nb_ancestors_shown
104
+		]);
105
+	}
106 106
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaComputeModal.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -29,39 +29,39 @@
 block discarded – undo
29 29
  */
30 30
 class SosaComputeModal implements RequestHandlerInterface
31 31
 {
32
-    /**
33
-     * @var SosaModule|null $module
34
-     */
35
-    private $module;
32
+	/**
33
+	 * @var SosaModule|null $module
34
+	 */
35
+	private $module;
36 36
 
37
-    /**
38
-     * Constructor for SosaComputeModal Request Handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     */
42
-    public function __construct(ModuleService $module_service)
43
-    {
44
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
45
-    }
37
+	/**
38
+	 * Constructor for SosaComputeModal Request Handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 */
42
+	public function __construct(ModuleService $module_service)
43
+	{
44
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
45
+	}
46 46
 
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
-     */
51
-    public function handle(ServerRequestInterface $request): ResponseInterface
52
-    {
53
-        if ($this->module === null) {
54
-            return response(view('modals/error', [
55
-                'title' => I18N::translate('Error'),
56
-                'error' => I18N::translate('The attached module could not be found.')
57
-            ]));
58
-        }
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
50
+	 */
51
+	public function handle(ServerRequestInterface $request): ResponseInterface
52
+	{
53
+		if ($this->module === null) {
54
+			return response(view('modals/error', [
55
+				'title' => I18N::translate('Error'),
56
+				'error' => I18N::translate('The attached module could not be found.')
57
+			]));
58
+		}
59 59
 
60
-        $tree = Validator::attributes($request)->tree();
60
+		$tree = Validator::attributes($request)->tree();
61 61
 
62
-        return response(view($this->module->name() . '::modals/sosa-compute', [
63
-            'tree'          => $tree,
64
-            'xref'          => Validator::attributes($request)->isXref()->string('xref', '')
65
-        ]));
66
-    }
62
+		return response(view($this->module->name() . '::modals/sosa-compute', [
63
+			'tree'          => $tree,
64
+			'xref'          => Validator::attributes($request)->isXref()->string('xref', '')
65
+		]));
66
+	}
67 67
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/AncestorsList.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -34,48 +34,48 @@
 block discarded – undo
34 34
  */
35 35
 class AncestorsList implements RequestHandlerInterface
36 36
 {
37
-    use ViewResponseTrait;
37
+	use ViewResponseTrait;
38 38
 
39
-    private ?SosaModule $module;
39
+	private ?SosaModule $module;
40 40
 
41
-    /**
42
-     * Constructor for AncestorsList Request Handler
43
-     *
44
-     * @param ModuleService $module_service
45
-     */
46
-    public function __construct(ModuleService $module_service)
47
-    {
48
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
49
-    }
41
+	/**
42
+	 * Constructor for AncestorsList Request Handler
43
+	 *
44
+	 * @param ModuleService $module_service
45
+	 */
46
+	public function __construct(ModuleService $module_service)
47
+	{
48
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritDoc}
53
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
-     */
55
-    public function handle(ServerRequestInterface $request): ResponseInterface
56
-    {
57
-        if ($this->module === null) {
58
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
-        }
51
+	/**
52
+	 * {@inheritDoc}
53
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
+	 */
55
+	public function handle(ServerRequestInterface $request): ResponseInterface
56
+	{
57
+		if ($this->module === null) {
58
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
+		}
60 60
 
61
-        $tree = Validator::attributes($request)->tree();
62
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
61
+		$tree = Validator::attributes($request)->tree();
62
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
63 63
 
64
-        /** @var SosaStatisticsService $sosa_stats_service */
65
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
64
+		/** @var SosaStatisticsService $sosa_stats_service */
65
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
66 66
 
67
-        $current_gen = Validator::queryParams($request)->integer(
68
-            'gen',
69
-            Validator::attributes($request)->integer('gen', 0)
70
-        );
67
+		$current_gen = Validator::queryParams($request)->integer(
68
+			'gen',
69
+			Validator::attributes($request)->integer('gen', 0)
70
+		);
71 71
 
72
-        return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
73
-            'module_name'       =>  $this->module->name(),
74
-            'title'             =>  I18N::translate('Sosa Ancestors'),
75
-            'tree'              =>  $tree,
76
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
77
-            'max_gen'           =>  $sosa_stats_service->maxGeneration(),
78
-            'current_gen'       =>  $current_gen
79
-        ]);
80
-    }
72
+		return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
73
+			'module_name'       =>  $this->module->name(),
74
+			'title'             =>  I18N::translate('Sosa Ancestors'),
75
+			'tree'              =>  $tree,
76
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
77
+			'max_gen'           =>  $sosa_stats_service->maxGeneration(),
78
+			'current_gen'       =>  $current_gen
79
+		]);
80
+	}
81 81
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaConfig.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -33,71 +33,71 @@
 block discarded – undo
33 33
  */
34 34
 class SosaConfig implements RequestHandlerInterface
35 35
 {
36
-    use ViewResponseTrait;
36
+	use ViewResponseTrait;
37 37
 
38
-    /**
39
-     * @var SosaModule|null $module
40
-     */
41
-    private $module;
38
+	/**
39
+	 * @var SosaModule|null $module
40
+	 */
41
+	private $module;
42 42
 
43
-    /**
44
-     * Constructor for SosaConfig Request Handler
45
-     *
46
-     * @param ModuleService $module_service
47
-     */
48
-    public function __construct(ModuleService $module_service)
49
-    {
50
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
51
-    }
43
+	/**
44
+	 * Constructor for SosaConfig Request Handler
45
+	 *
46
+	 * @param ModuleService $module_service
47
+	 */
48
+	public function __construct(ModuleService $module_service)
49
+	{
50
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritDoc}
55
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
-     */
57
-    public function handle(ServerRequestInterface $request): ResponseInterface
58
-    {
59
-        if ($this->module === null) {
60
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
-        }
53
+	/**
54
+	 * {@inheritDoc}
55
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
+	 */
57
+	public function handle(ServerRequestInterface $request): ResponseInterface
58
+	{
59
+		if ($this->module === null) {
60
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
+		}
62 62
 
63
-        $tree = Validator::attributes($request)->tree();
63
+		$tree = Validator::attributes($request)->tree();
64 64
 
65
-        $users_root = array();
66
-        if (Auth::check()) {
67
-            /** @var \Fisharebest\Webtrees\User $user */
68
-            $user = Auth::user();
69
-            $users_root[] = [
70
-                'user'      => $user,
71
-                'root_id'   => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'),
72
-                'max_gen'   => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN')
73
-            ];
65
+		$users_root = array();
66
+		if (Auth::check()) {
67
+			/** @var \Fisharebest\Webtrees\User $user */
68
+			$user = Auth::user();
69
+			$users_root[] = [
70
+				'user'      => $user,
71
+				'root_id'   => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'),
72
+				'max_gen'   => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN')
73
+			];
74 74
 
75
-            if (Auth::isManager($tree)) {
76
-                $default_user = new DefaultUser();
77
-                $users_root[] = [
78
-                    'user' => $default_user,
79
-                    'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'),
80
-                    'max_gen'   => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN')
81
-                ];
82
-            }
83
-        }
75
+			if (Auth::isManager($tree)) {
76
+				$default_user = new DefaultUser();
77
+				$users_root[] = [
78
+					'user' => $default_user,
79
+					'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'),
80
+					'max_gen'   => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN')
81
+				];
82
+			}
83
+		}
84 84
 
85
-        // Use the system max generations if not set
86
-        $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations();
87
-        foreach ($users_root as $key => $user_root) {
88
-            $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ?
89
-                (int) $user_root['max_gen'] :
90
-                $max_gen_system;
91
-        };
85
+		// Use the system max generations if not set
86
+		$max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations();
87
+		foreach ($users_root as $key => $user_root) {
88
+			$users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ?
89
+				(int) $user_root['max_gen'] :
90
+				$max_gen_system;
91
+		};
92 92
 
93
-        return $this->viewResponse($this->module->name() . '::config-page', [
94
-            'module_name'       =>  $this->module->name(),
95
-            'title'             =>  I18N::translate('Sosa Configuration'),
96
-            'tree'              =>  $tree,
97
-            'user_id'           =>  Validator::attributes($request)->user(),
98
-            'selected_user_id'  =>  Validator::queryParams($request)->integer('user_id', 0),
99
-            'immediate_compute' =>  Validator::queryParams($request)->string('compute', '') == 'yes',
100
-            'users_root'        =>  $users_root
101
-        ]);
102
-    }
93
+		return $this->viewResponse($this->module->name() . '::config-page', [
94
+			'module_name'       =>  $this->module->name(),
95
+			'title'             =>  I18N::translate('Sosa Configuration'),
96
+			'tree'              =>  $tree,
97
+			'user_id'           =>  Validator::attributes($request)->user(),
98
+			'selected_user_id'  =>  Validator::queryParams($request)->integer('user_id', 0),
99
+			'immediate_compute' =>  Validator::queryParams($request)->string('compute', '') == 'yes',
100
+			'users_root'        =>  $users_root
101
+		]);
102
+	}
103 103
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaConfigAction.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -32,51 +32,51 @@
 block discarded – undo
32 32
  */
33 33
 class SosaConfigAction implements RequestHandlerInterface
34 34
 {
35
-    private UserService $user_service;
36
-    private SosaRecordsService $sosa_record_service;
35
+	private UserService $user_service;
36
+	private SosaRecordsService $sosa_record_service;
37 37
 
38
-    /**
39
-     * Constructor for SosaConfigAction Request Handler
40
-     *
41
-     * @param UserService $user_service
42
-     * @param SosaRecordsService $sosa_records_service
43
-     */
44
-    public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service)
45
-    {
46
-        $this->user_service = $user_service;
47
-        $this->sosa_record_service = $sosa_records_service;
48
-    }
38
+	/**
39
+	 * Constructor for SosaConfigAction Request Handler
40
+	 *
41
+	 * @param UserService $user_service
42
+	 * @param SosaRecordsService $sosa_records_service
43
+	 */
44
+	public function __construct(UserService $user_service, SosaRecordsService $sosa_records_service)
45
+	{
46
+		$this->user_service = $user_service;
47
+		$this->sosa_record_service = $sosa_records_service;
48
+	}
49 49
 
50
-    /**
51
-     * {@inheritDoc}
52
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
-     */
54
-    public function handle(ServerRequestInterface $request): ResponseInterface
55
-    {
56
-        $tree = Validator::attributes($request)->tree();
50
+	/**
51
+	 * {@inheritDoc}
52
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
53
+	 */
54
+	public function handle(ServerRequestInterface $request): ResponseInterface
55
+	{
56
+		$tree = Validator::attributes($request)->tree();
57 57
 
58
-        $user_id = Validator::parsedBody($request)->integer('sosa-userid', -1);
59
-        $root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', '');
60
-        $max_gen = Validator::parsedBody($request)->integer(
61
-            'sosa-maxgen',
62
-            $this->sosa_record_service->maxSystemGenerations()
63
-        );
58
+		$user_id = Validator::parsedBody($request)->integer('sosa-userid', -1);
59
+		$root_id = Validator::parsedBody($request)->isXref()->string('sosa-rootid', '');
60
+		$max_gen = Validator::parsedBody($request)->integer(
61
+			'sosa-maxgen',
62
+			$this->sosa_record_service->maxSystemGenerations()
63
+		);
64 64
 
65
-        if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) {
66
-            $user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
67
-            if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) {
68
-                $tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref());
69
-                $tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen);
70
-                FlashMessages::addMessage(I18N::translate('The root individual has been updated.'));
71
-                return redirect(route(SosaConfig::class, [
72
-                    'tree' => $tree->name(),
73
-                    'compute' => 'yes',
74
-                    'user_id' => $user_id
75
-                ]));
76
-            }
77
-        }
65
+		if (Auth::id() == $user_id || ($user_id == -1 && Auth::isManager($tree))) {
66
+			$user = $user_id == -1 ? new DefaultUser() : $this->user_service->find($user_id);
67
+			if ($user !== null && ($root_indi = Registry::individualFactory()->make($root_id, $tree)) !== null) {
68
+				$tree->setUserPreference($user, 'MAJ_SOSA_ROOT_ID', $root_indi->xref());
69
+				$tree->setUserPreference($user, 'MAJ_SOSA_MAX_GEN', (string) $max_gen);
70
+				FlashMessages::addMessage(I18N::translate('The root individual has been updated.'));
71
+				return redirect(route(SosaConfig::class, [
72
+					'tree' => $tree->name(),
73
+					'compute' => 'yes',
74
+					'user_id' => $user_id
75
+				]));
76
+			}
77
+		}
78 78
 
79
-        FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger');
80
-        return redirect(route(SosaConfig::class, ['tree' => $tree->name()]));
81
-    }
79
+		FlashMessages::addMessage(I18N::translate('The root individual could not be updated.'), 'danger');
80
+		return redirect(route(SosaConfig::class, ['tree' => $tree->name()]));
81
+	}
82 82
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/MissingAncestorsList.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -37,89 +37,89 @@
 block discarded – undo
37 37
  */
38 38
 class MissingAncestorsList implements RequestHandlerInterface
39 39
 {
40
-    use ViewResponseTrait;
41
-
42
-    /**
43
-     * @var SosaModule|null $module
44
-     */
45
-    private $module;
46
-
47
-    /**
48
-     * @var SosaRecordsService $sosa_record_service
49
-     */
50
-    private $sosa_record_service;
51
-
52
-    /**
53
-     * Constructor for MissingAncestorsList Request Handler
54
-     *
55
-     * @param ModuleService $module_service
56
-     * @param SosaRecordsService $sosa_record_service
57
-     */
58
-    public function __construct(
59
-        ModuleService $module_service,
60
-        SosaRecordsService $sosa_record_service
61
-    ) {
62
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
63
-        $this->sosa_record_service = $sosa_record_service;
64
-    }
65
-
66
-    /**
67
-     * {@inheritDoc}
68
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
69
-     */
70
-    public function handle(ServerRequestInterface $request): ResponseInterface
71
-    {
72
-        if ($this->module === null) {
73
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
-        }
75
-
76
-        $tree = Validator::attributes($request)->tree();
77
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
78
-
79
-        /** @var SosaStatisticsService $sosa_stats_service */
80
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
81
-
82
-        $current_gen =  Validator::queryParams($request)->integer(
83
-            'gen',
84
-            Validator::attributes($request)->integer('gen', 0)
85
-        );
86
-
87
-        $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
88
-        $nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
89
-            return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
90
-        });
91
-
92
-        $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
93
-            $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94
-            if ($indi !== null && $indi->canShowName()) {
95
-                return new MissingAncestor(
96
-                    $indi,
97
-                    (int) $value->majs_sosa,
98
-                    $value->majs_fat_id === null,
99
-                    $value->majs_mot_id === null
100
-                );
101
-            }
102
-            return null;
103
-        })->filter();
104
-
105
-        $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
106
-            return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
107
-        });
108
-
109
-        return $this->viewResponse($this->module->name() . '::list-missing-page', [
110
-            'module_name'       =>  $this->module->name(),
111
-            'title'             =>  I18N::translate('Missing Ancestors'),
112
-            'tree'              =>  $tree,
113
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
114
-            'max_gen'           =>  $sosa_stats_service->maxGeneration(),
115
-            'current_gen'       =>  $current_gen,
116
-            'list_missing'      =>  $list_missing,
117
-            'nb_missing_diff'   =>  $nb_missing_diff,
118
-            'nb_missing_shown'  =>  $nb_missing_shown,
119
-            'gen_completeness'  =>
120
-                $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1),
121
-            'gen_potential'     =>
122
-                $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2)
123
-        ]);
124
-    }
40
+	use ViewResponseTrait;
41
+
42
+	/**
43
+	 * @var SosaModule|null $module
44
+	 */
45
+	private $module;
46
+
47
+	/**
48
+	 * @var SosaRecordsService $sosa_record_service
49
+	 */
50
+	private $sosa_record_service;
51
+
52
+	/**
53
+	 * Constructor for MissingAncestorsList Request Handler
54
+	 *
55
+	 * @param ModuleService $module_service
56
+	 * @param SosaRecordsService $sosa_record_service
57
+	 */
58
+	public function __construct(
59
+		ModuleService $module_service,
60
+		SosaRecordsService $sosa_record_service
61
+	) {
62
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
63
+		$this->sosa_record_service = $sosa_record_service;
64
+	}
65
+
66
+	/**
67
+	 * {@inheritDoc}
68
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
69
+	 */
70
+	public function handle(ServerRequestInterface $request): ResponseInterface
71
+	{
72
+		if ($this->module === null) {
73
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
+		}
75
+
76
+		$tree = Validator::attributes($request)->tree();
77
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
78
+
79
+		/** @var SosaStatisticsService $sosa_stats_service */
80
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
81
+
82
+		$current_gen =  Validator::queryParams($request)->integer(
83
+			'gen',
84
+			Validator::attributes($request)->integer('gen', 0)
85
+		);
86
+
87
+		$list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
88
+		$nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
89
+			return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
90
+		});
91
+
92
+		$list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
93
+			$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94
+			if ($indi !== null && $indi->canShowName()) {
95
+				return new MissingAncestor(
96
+					$indi,
97
+					(int) $value->majs_sosa,
98
+					$value->majs_fat_id === null,
99
+					$value->majs_mot_id === null
100
+				);
101
+			}
102
+			return null;
103
+		})->filter();
104
+
105
+		$nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
106
+			return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
107
+		});
108
+
109
+		return $this->viewResponse($this->module->name() . '::list-missing-page', [
110
+			'module_name'       =>  $this->module->name(),
111
+			'title'             =>  I18N::translate('Missing Ancestors'),
112
+			'tree'              =>  $tree,
113
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
114
+			'max_gen'           =>  $sosa_stats_service->maxGeneration(),
115
+			'current_gen'       =>  $current_gen,
116
+			'list_missing'      =>  $list_missing,
117
+			'nb_missing_diff'   =>  $nb_missing_diff,
118
+			'nb_missing_shown'  =>  $nb_missing_shown,
119
+			'gen_completeness'  =>
120
+				$sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1),
121
+			'gen_potential'     =>
122
+				$sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2)
123
+		]);
124
+	}
125 125
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/PedigreeCollapseData.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -34,49 +34,49 @@
 block discarded – undo
34 34
  */
35 35
 class PedigreeCollapseData implements RequestHandlerInterface
36 36
 {
37
-    /**
38
-     * @var SosaModule|null $module
39
-     */
40
-    private $module;
37
+	/**
38
+	 * @var SosaModule|null $module
39
+	 */
40
+	private $module;
41 41
 
42
-    /**
43
-     * Constructor for PedigreeCollapseData Request Handler
44
-     *
45
-     * @param ModuleService $module_service
46
-     */
47
-    public function __construct(ModuleService $module_service)
48
-    {
49
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
50
-    }
42
+	/**
43
+	 * Constructor for PedigreeCollapseData Request Handler
44
+	 *
45
+	 * @param ModuleService $module_service
46
+	 */
47
+	public function __construct(ModuleService $module_service)
48
+	{
49
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
50
+	}
51 51
 
52
-    /**
53
-     * {@inheritDoc}
54
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
55
-     */
56
-    public function handle(ServerRequestInterface $request): ResponseInterface
57
-    {
58
-        if ($this->module === null) {
59
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
-        }
52
+	/**
53
+	 * {@inheritDoc}
54
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
55
+	 */
56
+	public function handle(ServerRequestInterface $request): ResponseInterface
57
+	{
58
+		if ($this->module === null) {
59
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
60
+		}
61 61
 
62
-        $tree = Validator::attributes($request)->tree();
63
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
62
+		$tree = Validator::attributes($request)->tree();
63
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
64 64
 
65
-        /** @var SosaStatisticsService $sosa_stats_service */
66
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
67
-        $pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData();
65
+		/** @var SosaStatisticsService $sosa_stats_service */
66
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
67
+		$pedi_collapse_data = $sosa_stats_service->pedigreeCollapseByGenerationData();
68 68
 
69
-        $response = [ 'cells' => [] ];
70
-        $last_pedi_collapse = 0;
71
-        foreach ($pedi_collapse_data as $gen => $rec) {
72
-            $response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [
73
-                'pedi_collapse_roots'   =>  $rec['pedi_collapse_roots'],
74
-                'pedi_collapse_xgen'    =>  $rec['pedi_collapse_xgen']
75
-            ]);
76
-            $last_pedi_collapse = $rec['pedi_collapse_roots'];
77
-        }
78
-        $response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2);
69
+		$response = [ 'cells' => [] ];
70
+		$last_pedi_collapse = 0;
71
+		foreach ($pedi_collapse_data as $gen => $rec) {
72
+			$response['cells'][$gen] = view($this->module->name() . '::components/pedigree-collapse-cell', [
73
+				'pedi_collapse_roots'   =>  $rec['pedi_collapse_roots'],
74
+				'pedi_collapse_xgen'    =>  $rec['pedi_collapse_xgen']
75
+			]);
76
+			$last_pedi_collapse = $rec['pedi_collapse_roots'];
77
+		}
78
+		$response['pedi_collapse'] = I18N::percentage($last_pedi_collapse, 2);
79 79
 
80
-        return response($response, StatusCodeInterface::STATUS_OK);
81
-    }
80
+		return response($response, StatusCodeInterface::STATUS_OK);
81
+	}
82 82
 }
Please login to merge, or discard this patch.
app/Module/Sosa/SosaModule.php 1 patch
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -57,261 +57,261 @@
 block discarded – undo
57 57
  * Identify and produce statistics about Sosa ancestors
58 58
  */
59 59
 class SosaModule extends AbstractModule implements
60
-    ModuleMyArtJaubInterface,
61
-    ModuleGlobalInterface,
62
-    ModuleMenuInterface,
63
-    ModuleSidebarInterface,
64
-    ModuleGeoAnalysisProviderInterface,
65
-    ModuleHookSubscriberInterface
60
+	ModuleMyArtJaubInterface,
61
+	ModuleGlobalInterface,
62
+	ModuleMenuInterface,
63
+	ModuleSidebarInterface,
64
+	ModuleGeoAnalysisProviderInterface,
65
+	ModuleHookSubscriberInterface
66 66
 {
67
-    use ModuleMyArtJaubTrait {
68
-        boot as traitBoot;
69
-    }
70
-    use ModuleGlobalTrait;
71
-    use ModuleMenuTrait;
72
-    use ModuleSidebarTrait;
73
-
74
-    // How to update the database schema for this module
75
-    private const SCHEMA_TARGET_VERSION   = 3;
76
-    private const SCHEMA_SETTING_NAME     = 'MAJ_SOSA_SCHEMA_VERSION';
77
-    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
67
+	use ModuleMyArtJaubTrait {
68
+		boot as traitBoot;
69
+	}
70
+	use ModuleGlobalTrait;
71
+	use ModuleMenuTrait;
72
+	use ModuleSidebarTrait;
73
+
74
+	// How to update the database schema for this module
75
+	private const SCHEMA_TARGET_VERSION   = 3;
76
+	private const SCHEMA_SETTING_NAME     = 'MAJ_SOSA_SCHEMA_VERSION';
77
+	private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
78 78
 /**
79
-     * {@inheritDoc}
80
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
81
-     */
82
-    public function title(): string
83
-    {
84
-        return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa');
85
-    }
86
-
87
-    /**
88
-     * {@inheritDoc}
89
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
90
-     */
91
-    public function description(): string
92
-    {
93
-        //phpcs:ignore Generic.Files.LineLength.TooLong
94
-        return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.');
95
-    }
96
-
97
-    /**
98
-     * {@inheritDoc}
99
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
100
-     */
101
-    public function boot(): void
102
-    {
103
-        $this->traitBoot();
104
-        app(MigrationService::class)->updateSchema(
105
-            self::SCHEMA_MIGRATION_PREFIX,
106
-            self::SCHEMA_SETTING_NAME,
107
-            self::SCHEMA_TARGET_VERSION
108
-        );
109
-    }
110
-
111
-    /**
112
-     * {@inheritDoc}
113
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
114
-     */
115
-    public function loadRoutes(Map $router): void
116
-    {
117
-        $router->attach('', '', static function (Map $router): void {
118
-
119
-            $router->attach('', '/module-maj/sosa', static function (Map $router): void {
120
-
121
-                $router->attach('', '/list', static function (Map $router): void {
122
-                    $router->tokens(['gen' => '\d+']);
123
-                    $router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class);
124
-                    $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class);    //phpcs:ignore Generic.Files.LineLength.TooLong
125
-                    $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class);   //phpcs:ignore Generic.Files.LineLength.TooLong
126
-                    $router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class);
127
-                });
128
-
129
-                $router->attach('', '/statistics/{tree}', static function (Map $router): void {
130
-
131
-                    $router->get(SosaStatistics::class, '', SosaStatistics::class);
132
-                    $router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class);
133
-                });
134
-
135
-                $router->attach('', '/config/{tree}', static function (Map $router): void {
136
-
137
-                    $router->get(SosaConfig::class, '', SosaConfig::class);
138
-                    $router->post(SosaConfigAction::class, '', SosaConfigAction::class);
139
-                    $router->get(SosaComputeModal::class, '/compute/{xref}', SosaComputeModal::class);
140
-                    $router->post(SosaComputeAction::class, '/compute', SosaComputeAction::class);
141
-                });
142
-            });
143
-        });
144
-    }
145
-
146
-    /**
147
-     * {@inheritDoc}
148
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
149
-     */
150
-    public function customModuleVersion(): string
151
-    {
152
-        return '2.1.1-v.1';
153
-    }
154
-
155
-    /**
156
-     * {@inheritDoc}
157
-     * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder()
158
-     */
159
-    public function defaultMenuOrder(): int
160
-    {
161
-        return 7;
162
-    }
163
-
164
-    /**
165
-     * {@inhericDoc}
166
-     * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu()
167
-     */
168
-    public function getMenu(Tree $tree): ?Menu
169
-    {
170
-        $menu = new Menu(I18N::translate('Sosa Statistics'));
171
-        $menu->setClass('menu-maj-sosa');
172
-        $menu->setSubmenus([
173
-            new Menu(
174
-                I18N::translate('Sosa Ancestors'),
175
-                route(AncestorsList::class, ['tree' => $tree->name()]),
176
-                'menu-maj-sosa-list',
177
-                ['rel' => 'nofollow']
178
-            ),
179
-            new Menu(
180
-                I18N::translate('Missing Ancestors'),
181
-                route(MissingAncestorsList::class, ['tree' => $tree->name()]),
182
-                'menu-maj-sosa-missing',
183
-                ['rel' => 'nofollow']
184
-            ),
185
-            new Menu(
186
-                I18N::translate('Sosa Statistics'),
187
-                route(SosaStatistics::class, ['tree' => $tree->name()]),
188
-                'menu-maj-sosa-stats'
189
-            )
190
-        ]);
191
-
192
-        if (Auth::check()) {
193
-            $menu->addSubmenu(new Menu(
194
-                I18N::translate('Sosa Configuration'),
195
-                route(SosaConfig::class, ['tree' => $tree->name()]),
196
-                'menu-maj-sosa-config'
197
-            ));
198
-
199
-            /** @var ServerRequestInterface $request */
200
-            $request = app(ServerRequestInterface::class);
201
-            $route = Validator::attributes($request)->route();
202
-
203
-            $root_indi_id = $tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID');
204
-
205
-            if ($route->name === IndividualPage::class && mb_strlen($root_indi_id) > 0) {
206
-                $xref = Validator::attributes($request)->isXref()->string('xref', '');
207
-
208
-                $menu->addSubmenu(new Menu(
209
-                    I18N::translate('Complete Sosas'),
210
-                    '#',
211
-                    'menu-maj-sosa-compute',
212
-                    [
213
-                        'rel'           => 'nofollow',
214
-                        'data-wt-href'  => route(SosaComputeModal::class, ['tree' => $tree->name(), 'xref' => $xref]),
215
-                        'data-bs-target'    => '#wt-ajax-modal',
216
-                        'data-bs-toggle'    => 'modal',
217
-                        'data-bs-backdrop'  => 'static'
218
-                    ]
219
-                ));
220
-            }
221
-        }
222
-
223
-        return $menu;
224
-    }
225
-
226
-    /**
227
-     * {@inheritDoc}
228
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
229
-     */
230
-    public function headContent(): string
231
-    {
232
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
233
-    }
234
-
235
-    /**
236
-     * {@inheritDoc}
237
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
238
-     */
239
-    public function bodyContent(): string
240
-    {
241
-        return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>';
242
-    }
243
-
244
-    /**
245
-     * {@inheritDoc}
246
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::sidebarTitle()
247
-     */
248
-    public function sidebarTitle(Individual $individual): string
249
-    {
250
-        $user = Auth::check() ? Auth::user() : new DefaultUser();
251
-
252
-        return view($this->name() . '::sidebar/title', [
253
-            'module_name'   =>  $this->name(),
254
-            'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
255
-        ]);
256
-    }
257
-
258
-    /**
259
-     * {@inheritDoc}
260
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
261
-     */
262
-    public function getSidebarContent(Individual $individual): string
263
-    {
264
-        $sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID');
265
-        $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree());
266
-        $user = Auth::check() ? Auth::user() : new DefaultUser();
267
-
268
-        return view($this->name() . '::sidebar/content', [
269
-            'sosa_ancestor' =>  $individual,
270
-            'sosa_root'     =>  $sosa_root,
271
-            'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
272
-        ]);
273
-    }
274
-
275
-    /**
276
-     * {@inheritDoc}
277
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
278
-     */
279
-    public function hasSidebarContent(Individual $individual): bool
280
-    {
281
-        $user = Auth::check() ? Auth::user() : new DefaultUser();
282
-
283
-        return app(SosaRecordsService::class)
284
-            ->sosaNumbers($individual->tree(), $user, $individual)->count() > 0;
285
-    }
286
-
287
-    /**
288
-     * {@inheritDoc}
289
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder()
290
-     */
291
-    public function defaultSidebarOrder(): int
292
-    {
293
-        return 1;
294
-    }
295
-
296
-    /**
297
-     * {@inheritDoc}
298
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
299
-     */
300
-    public function listGeoAnalyses(): array
301
-    {
302
-        return [
303
-            SosaByGenerationGeoAnalysis::class
304
-        ];
305
-    }
306
-
307
-    /**
308
-     * {@inheritDoc}
309
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
310
-     */
311
-    public function listSubscribedHooks(): array
312
-    {
313
-        return [
314
-            app()->makeWith(SosaIconHook::class, [ 'module' => $this ])
315
-        ];
316
-    }
79
+	 * {@inheritDoc}
80
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
81
+	 */
82
+	public function title(): string
83
+	{
84
+		return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa');
85
+	}
86
+
87
+	/**
88
+	 * {@inheritDoc}
89
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
90
+	 */
91
+	public function description(): string
92
+	{
93
+		//phpcs:ignore Generic.Files.LineLength.TooLong
94
+		return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.');
95
+	}
96
+
97
+	/**
98
+	 * {@inheritDoc}
99
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
100
+	 */
101
+	public function boot(): void
102
+	{
103
+		$this->traitBoot();
104
+		app(MigrationService::class)->updateSchema(
105
+			self::SCHEMA_MIGRATION_PREFIX,
106
+			self::SCHEMA_SETTING_NAME,
107
+			self::SCHEMA_TARGET_VERSION
108
+		);
109
+	}
110
+
111
+	/**
112
+	 * {@inheritDoc}
113
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
114
+	 */
115
+	public function loadRoutes(Map $router): void
116
+	{
117
+		$router->attach('', '', static function (Map $router): void {
118
+
119
+			$router->attach('', '/module-maj/sosa', static function (Map $router): void {
120
+
121
+				$router->attach('', '/list', static function (Map $router): void {
122
+					$router->tokens(['gen' => '\d+']);
123
+					$router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class);
124
+					$router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class);    //phpcs:ignore Generic.Files.LineLength.TooLong
125
+					$router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class);   //phpcs:ignore Generic.Files.LineLength.TooLong
126
+					$router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class);
127
+				});
128
+
129
+				$router->attach('', '/statistics/{tree}', static function (Map $router): void {
130
+
131
+					$router->get(SosaStatistics::class, '', SosaStatistics::class);
132
+					$router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class);
133
+				});
134
+
135
+				$router->attach('', '/config/{tree}', static function (Map $router): void {
136
+
137
+					$router->get(SosaConfig::class, '', SosaConfig::class);
138
+					$router->post(SosaConfigAction::class, '', SosaConfigAction::class);
139
+					$router->get(SosaComputeModal::class, '/compute/{xref}', SosaComputeModal::class);
140
+					$router->post(SosaComputeAction::class, '/compute', SosaComputeAction::class);
141
+				});
142
+			});
143
+		});
144
+	}
145
+
146
+	/**
147
+	 * {@inheritDoc}
148
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
149
+	 */
150
+	public function customModuleVersion(): string
151
+	{
152
+		return '2.1.1-v.1';
153
+	}
154
+
155
+	/**
156
+	 * {@inheritDoc}
157
+	 * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder()
158
+	 */
159
+	public function defaultMenuOrder(): int
160
+	{
161
+		return 7;
162
+	}
163
+
164
+	/**
165
+	 * {@inhericDoc}
166
+	 * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu()
167
+	 */
168
+	public function getMenu(Tree $tree): ?Menu
169
+	{
170
+		$menu = new Menu(I18N::translate('Sosa Statistics'));
171
+		$menu->setClass('menu-maj-sosa');
172
+		$menu->setSubmenus([
173
+			new Menu(
174
+				I18N::translate('Sosa Ancestors'),
175
+				route(AncestorsList::class, ['tree' => $tree->name()]),
176
+				'menu-maj-sosa-list',
177
+				['rel' => 'nofollow']
178
+			),
179
+			new Menu(
180
+				I18N::translate('Missing Ancestors'),
181
+				route(MissingAncestorsList::class, ['tree' => $tree->name()]),
182
+				'menu-maj-sosa-missing',
183
+				['rel' => 'nofollow']
184
+			),
185
+			new Menu(
186
+				I18N::translate('Sosa Statistics'),
187
+				route(SosaStatistics::class, ['tree' => $tree->name()]),
188
+				'menu-maj-sosa-stats'
189
+			)
190
+		]);
191
+
192
+		if (Auth::check()) {
193
+			$menu->addSubmenu(new Menu(
194
+				I18N::translate('Sosa Configuration'),
195
+				route(SosaConfig::class, ['tree' => $tree->name()]),
196
+				'menu-maj-sosa-config'
197
+			));
198
+
199
+			/** @var ServerRequestInterface $request */
200
+			$request = app(ServerRequestInterface::class);
201
+			$route = Validator::attributes($request)->route();
202
+
203
+			$root_indi_id = $tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID');
204
+
205
+			if ($route->name === IndividualPage::class && mb_strlen($root_indi_id) > 0) {
206
+				$xref = Validator::attributes($request)->isXref()->string('xref', '');
207
+
208
+				$menu->addSubmenu(new Menu(
209
+					I18N::translate('Complete Sosas'),
210
+					'#',
211
+					'menu-maj-sosa-compute',
212
+					[
213
+						'rel'           => 'nofollow',
214
+						'data-wt-href'  => route(SosaComputeModal::class, ['tree' => $tree->name(), 'xref' => $xref]),
215
+						'data-bs-target'    => '#wt-ajax-modal',
216
+						'data-bs-toggle'    => 'modal',
217
+						'data-bs-backdrop'  => 'static'
218
+					]
219
+				));
220
+			}
221
+		}
222
+
223
+		return $menu;
224
+	}
225
+
226
+	/**
227
+	 * {@inheritDoc}
228
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
229
+	 */
230
+	public function headContent(): string
231
+	{
232
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
233
+	}
234
+
235
+	/**
236
+	 * {@inheritDoc}
237
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
238
+	 */
239
+	public function bodyContent(): string
240
+	{
241
+		return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>';
242
+	}
243
+
244
+	/**
245
+	 * {@inheritDoc}
246
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::sidebarTitle()
247
+	 */
248
+	public function sidebarTitle(Individual $individual): string
249
+	{
250
+		$user = Auth::check() ? Auth::user() : new DefaultUser();
251
+
252
+		return view($this->name() . '::sidebar/title', [
253
+			'module_name'   =>  $this->name(),
254
+			'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
255
+		]);
256
+	}
257
+
258
+	/**
259
+	 * {@inheritDoc}
260
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
261
+	 */
262
+	public function getSidebarContent(Individual $individual): string
263
+	{
264
+		$sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID');
265
+		$sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree());
266
+		$user = Auth::check() ? Auth::user() : new DefaultUser();
267
+
268
+		return view($this->name() . '::sidebar/content', [
269
+			'sosa_ancestor' =>  $individual,
270
+			'sosa_root'     =>  $sosa_root,
271
+			'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
272
+		]);
273
+	}
274
+
275
+	/**
276
+	 * {@inheritDoc}
277
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
278
+	 */
279
+	public function hasSidebarContent(Individual $individual): bool
280
+	{
281
+		$user = Auth::check() ? Auth::user() : new DefaultUser();
282
+
283
+		return app(SosaRecordsService::class)
284
+			->sosaNumbers($individual->tree(), $user, $individual)->count() > 0;
285
+	}
286
+
287
+	/**
288
+	 * {@inheritDoc}
289
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder()
290
+	 */
291
+	public function defaultSidebarOrder(): int
292
+	{
293
+		return 1;
294
+	}
295
+
296
+	/**
297
+	 * {@inheritDoc}
298
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
299
+	 */
300
+	public function listGeoAnalyses(): array
301
+	{
302
+		return [
303
+			SosaByGenerationGeoAnalysis::class
304
+		];
305
+	}
306
+
307
+	/**
308
+	 * {@inheritDoc}
309
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
310
+	 */
311
+	public function listSubscribedHooks(): array
312
+	{
313
+		return [
314
+			app()->makeWith(SosaIconHook::class, [ 'module' => $this ])
315
+		];
316
+	}
317 317
 }
Please login to merge, or discard this patch.