Passed
Push — main ( 00c5b4...fe37d7 )
by Jonathan
03:49
created
app/Common/GeoDispersion/GeoAnalysis/GeoAnalysisResultItem.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -20,67 +20,67 @@
 block discarded – undo
20 20
  */
21 21
 class GeoAnalysisResultItem
22 22
 {
23
-    private GeoAnalysisPlace $place;
24
-    private int $count;
23
+	private GeoAnalysisPlace $place;
24
+	private int $count;
25 25
 
26
-    /**
27
-     * Constructor for GeoAnalysisResultItem
28
-     *
29
-     * @param GeoAnalysisPlace $place
30
-     * @param int $count
31
-     */
32
-    public function __construct(GeoAnalysisPlace $place, int $count = 0)
33
-    {
34
-        $this->place = $place;
35
-        $this->count = $count;
36
-    }
26
+	/**
27
+	 * Constructor for GeoAnalysisResultItem
28
+	 *
29
+	 * @param GeoAnalysisPlace $place
30
+	 * @param int $count
31
+	 */
32
+	public function __construct(GeoAnalysisPlace $place, int $count = 0)
33
+	{
34
+		$this->place = $place;
35
+		$this->count = $count;
36
+	}
37 37
 
38
-    /**
39
-     * Get the item key.
40
-     *
41
-     * @return string
42
-     */
43
-    public function key(): string
44
-    {
45
-        return $this->place->key();
46
-    }
38
+	/**
39
+	 * Get the item key.
40
+	 *
41
+	 * @return string
42
+	 */
43
+	public function key(): string
44
+	{
45
+		return $this->place->key();
46
+	}
47 47
 
48
-    /**
49
-     * Get the referenced GeoAnalysis Place
50
-     *
51
-     * @return GeoAnalysisPlace
52
-     */
53
-    public function place(): GeoAnalysisPlace
54
-    {
55
-        return $this->place;
56
-    }
48
+	/**
49
+	 * Get the referenced GeoAnalysis Place
50
+	 *
51
+	 * @return GeoAnalysisPlace
52
+	 */
53
+	public function place(): GeoAnalysisPlace
54
+	{
55
+		return $this->place;
56
+	}
57 57
 
58
-    /**
59
-     * Get the count of occurrences of the GeoAnalysis Place in the analysis
60
-     *
61
-     * @return int
62
-     */
63
-    public function count(): int
64
-    {
65
-        return $this->count;
66
-    }
58
+	/**
59
+	 * Get the count of occurrences of the GeoAnalysis Place in the analysis
60
+	 *
61
+	 * @return int
62
+	 */
63
+	public function count(): int
64
+	{
65
+		return $this->count;
66
+	}
67 67
 
68
-    /**
69
-     * Increment the count of occurrences of the GeoAnalysis Place in the analysis
70
-     *
71
-     * @return $this
72
-     */
73
-    public function increment(): self
74
-    {
75
-        $this->count++;
76
-        return $this;
77
-    }
68
+	/**
69
+	 * Increment the count of occurrences of the GeoAnalysis Place in the analysis
70
+	 *
71
+	 * @return $this
72
+	 */
73
+	public function increment(): self
74
+	{
75
+		$this->count++;
76
+		return $this;
77
+	}
78 78
 
79
-    /**
80
-     * Clone the item object
81
-     */
82
-    public function __clone()
83
-    {
84
-        $this->place = clone $this->place;
85
-    }
79
+	/**
80
+	 * Clone the item object
81
+	 */
82
+	public function __clone()
83
+	{
84
+		$this->place = clone $this->place;
85
+	}
86 86
 }
Please login to merge, or discard this patch.
app/Http/Middleware/AuthTreePreference.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -31,40 +31,40 @@
 block discarded – undo
31 31
  */
32 32
 class AuthTreePreference implements MiddlewareInterface
33 33
 {
34
-    /**
35
-     * {@inheritDoc}
36
-     * @see \Psr\Http\Server\MiddlewareInterface::process()
37
-     */
38
-    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
39
-    {
40
-        $tree = Validator::attributes($request)->tree();
41
-        $route = Validator::attributes($request)->route();
42
-        $user = Validator::attributes($request)->user();
34
+	/**
35
+	 * {@inheritDoc}
36
+	 * @see \Psr\Http\Server\MiddlewareInterface::process()
37
+	 */
38
+	public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
39
+	{
40
+		$tree = Validator::attributes($request)->tree();
41
+		$route = Validator::attributes($request)->route();
42
+		$user = Validator::attributes($request)->user();
43 43
 
44
-        $permission_preference = $route->extras['permission_preference'] ?? '';
45
-        $permission_level = $permission_preference === '' ? '' : $tree->getPreference($permission_preference);
44
+		$permission_preference = $route->extras['permission_preference'] ?? '';
45
+		$permission_level = $permission_preference === '' ? '' : $tree->getPreference($permission_preference);
46 46
 
47
-        // Permissions are configured
48
-        if (is_numeric($permission_level)) {
49
-            // Logged in with the correct role?
50
-            if (Auth::accessLevel($tree, $user) <= (int) $permission_level) {
51
-                    return $handler->handle($request);
52
-            }
47
+		// Permissions are configured
48
+		if (is_numeric($permission_level)) {
49
+			// Logged in with the correct role?
50
+			if (Auth::accessLevel($tree, $user) <= (int) $permission_level) {
51
+					return $handler->handle($request);
52
+			}
53 53
 
54
-            // Logged in, but without the correct role?
55
-            if ($user instanceof User) {
56
-                throw new HttpAccessDeniedException();
57
-            }
58
-        }
54
+			// Logged in, but without the correct role?
55
+			if ($user instanceof User) {
56
+				throw new HttpAccessDeniedException();
57
+			}
58
+		}
59 59
 
60
-        // Permissions no configured, or not logged in
61
-        if ($request->getMethod() === RequestMethodInterface::METHOD_POST) {
62
-            throw new HttpAccessDeniedException();
63
-        }
60
+		// Permissions no configured, or not logged in
61
+		if ($request->getMethod() === RequestMethodInterface::METHOD_POST) {
62
+			throw new HttpAccessDeniedException();
63
+		}
64 64
 
65
-        return Registry::responseFactory()->redirect(
66
-            LoginPage::class,
67
-            ['tree' => $tree->name(), 'url' => (string) $request->getUri()]
68
-        );
69
-    }
65
+		return Registry::responseFactory()->redirect(
66
+			LoginPage::class,
67
+			['tree' => $tree->name(), 'url' => (string) $request->getUri()]
68
+		);
69
+	}
70 70
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
app/Common/Tasks/TaskSchedule.php 1 patch
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -23,252 +23,252 @@
 block discarded – undo
23 23
  */
24 24
 class TaskSchedule
25 25
 {
26
-    private int $id;
27
-    private bool $enabled;
28
-    private string $task_id;
29
-    private CarbonInterface $last_run;
30
-    private bool $last_result;
31
-    private int $frequency;
32
-    private int $nb_occurrences;
33
-    private bool $is_running;
26
+	private int $id;
27
+	private bool $enabled;
28
+	private string $task_id;
29
+	private CarbonInterface $last_run;
30
+	private bool $last_result;
31
+	private int $frequency;
32
+	private int $nb_occurrences;
33
+	private bool $is_running;
34 34
 
35
-    /**
36
-     * Constructor for TaskSchedule
37
-     *
38
-     * @param int $id Schedule ID
39
-     * @param string $task_id Task ID
40
-     * @param bool $enabled Is the schedule enabled
41
-     * @param CarbonInterface $last_run Last successful run date/time
42
-     * @param bool $last_result Result of the last run
43
-     * @param int $frequency Schedule frequency in minutes
44
-     * @param int $nb_occurrences Number of remaining occurrences to be run
45
-     * @param bool $is_running Is the task currently running
46
-     */
47
-    public function __construct(
48
-        int $id,
49
-        string $task_id,
50
-        bool $enabled,
51
-        CarbonInterface $last_run,
52
-        bool $last_result,
53
-        int $frequency,
54
-        int $nb_occurrences,
55
-        bool $is_running
56
-    ) {
57
-        $this->id = $id;
58
-        $this->task_id = $task_id;
59
-        $this->enabled = $enabled;
60
-        $this->last_run = $last_run;
61
-        $this->last_result = $last_result;
62
-        $this->frequency = $frequency;
63
-        $this->nb_occurrences = $nb_occurrences;
64
-        $this->is_running = $is_running;
65
-    }
35
+	/**
36
+	 * Constructor for TaskSchedule
37
+	 *
38
+	 * @param int $id Schedule ID
39
+	 * @param string $task_id Task ID
40
+	 * @param bool $enabled Is the schedule enabled
41
+	 * @param CarbonInterface $last_run Last successful run date/time
42
+	 * @param bool $last_result Result of the last run
43
+	 * @param int $frequency Schedule frequency in minutes
44
+	 * @param int $nb_occurrences Number of remaining occurrences to be run
45
+	 * @param bool $is_running Is the task currently running
46
+	 */
47
+	public function __construct(
48
+		int $id,
49
+		string $task_id,
50
+		bool $enabled,
51
+		CarbonInterface $last_run,
52
+		bool $last_result,
53
+		int $frequency,
54
+		int $nb_occurrences,
55
+		bool $is_running
56
+	) {
57
+		$this->id = $id;
58
+		$this->task_id = $task_id;
59
+		$this->enabled = $enabled;
60
+		$this->last_run = $last_run;
61
+		$this->last_result = $last_result;
62
+		$this->frequency = $frequency;
63
+		$this->nb_occurrences = $nb_occurrences;
64
+		$this->is_running = $is_running;
65
+	}
66 66
 
67
-    /**
68
-     * Get the schedule ID.
69
-     *
70
-     * @return int
71
-     */
72
-    public function id(): int
73
-    {
74
-        return $this->id;
75
-    }
67
+	/**
68
+	 * Get the schedule ID.
69
+	 *
70
+	 * @return int
71
+	 */
72
+	public function id(): int
73
+	{
74
+		return $this->id;
75
+	}
76 76
 
77
-    /**
78
-     * Get the task ID.
79
-     *
80
-     * @return string
81
-     */
82
-    public function taskId(): string
83
-    {
84
-        return $this->task_id;
85
-    }
77
+	/**
78
+	 * Get the task ID.
79
+	 *
80
+	 * @return string
81
+	 */
82
+	public function taskId(): string
83
+	{
84
+		return $this->task_id;
85
+	}
86 86
 
87
-    /**
88
-     * Returns whether the schedule is enabled
89
-     *
90
-     * @return bool
91
-     */
92
-    public function isEnabled(): bool
93
-    {
94
-        return $this->enabled;
95
-    }
87
+	/**
88
+	 * Returns whether the schedule is enabled
89
+	 *
90
+	 * @return bool
91
+	 */
92
+	public function isEnabled(): bool
93
+	{
94
+		return $this->enabled;
95
+	}
96 96
 
97
-    /**
98
-     * Enable the schedule
99
-     *
100
-     * @return $this
101
-     */
102
-    public function enable(): self
103
-    {
104
-        $this->enabled = true;
105
-        return $this;
106
-    }
97
+	/**
98
+	 * Enable the schedule
99
+	 *
100
+	 * @return $this
101
+	 */
102
+	public function enable(): self
103
+	{
104
+		$this->enabled = true;
105
+		return $this;
106
+	}
107 107
 
108
-    /**
109
-     * Disable the schedule
110
-     *
111
-     * @return $this
112
-     */
113
-    public function disable(): self
114
-    {
115
-        $this->enabled = false;
116
-        return $this;
117
-    }
108
+	/**
109
+	 * Disable the schedule
110
+	 *
111
+	 * @return $this
112
+	 */
113
+	public function disable(): self
114
+	{
115
+		$this->enabled = false;
116
+		return $this;
117
+	}
118 118
 
119
-    /**
120
-     * Get the frequency of the schedule
121
-     *
122
-     * @return int
123
-     */
124
-    public function frequency(): int
125
-    {
126
-        return $this->frequency;
127
-    }
119
+	/**
120
+	 * Get the frequency of the schedule
121
+	 *
122
+	 * @return int
123
+	 */
124
+	public function frequency(): int
125
+	{
126
+		return $this->frequency;
127
+	}
128 128
 
129
-    /**
130
-     * Set the frequency of the schedule
131
-     *
132
-     * @param int $frequency
133
-     * @return $this
134
-     */
135
-    public function setFrequency(int $frequency): self
136
-    {
137
-        $this->frequency = $frequency;
138
-        return $this;
139
-    }
129
+	/**
130
+	 * Set the frequency of the schedule
131
+	 *
132
+	 * @param int $frequency
133
+	 * @return $this
134
+	 */
135
+	public function setFrequency(int $frequency): self
136
+	{
137
+		$this->frequency = $frequency;
138
+		return $this;
139
+	}
140 140
 
141
-    /**
142
-     * Get the date/time of the last successful run.
143
-     *
144
-     * @return CarbonInterface
145
-     */
146
-    public function lastRunTime(): CarbonInterface
147
-    {
148
-        return $this->last_run;
149
-    }
141
+	/**
142
+	 * Get the date/time of the last successful run.
143
+	 *
144
+	 * @return CarbonInterface
145
+	 */
146
+	public function lastRunTime(): CarbonInterface
147
+	{
148
+		return $this->last_run;
149
+	}
150 150
 
151
-    /**
152
-     * Set the last successful run date/time
153
-     *
154
-     * @param CarbonInterface $last_run
155
-     * @return $this
156
-     */
157
-    public function setLastRunTime(CarbonInterface $last_run): self
158
-    {
159
-        $this->last_run = $last_run;
160
-        return $this;
161
-    }
151
+	/**
152
+	 * Set the last successful run date/time
153
+	 *
154
+	 * @param CarbonInterface $last_run
155
+	 * @return $this
156
+	 */
157
+	public function setLastRunTime(CarbonInterface $last_run): self
158
+	{
159
+		$this->last_run = $last_run;
160
+		return $this;
161
+	}
162 162
 
163
-    /**
164
-     * Returns whether the last run was successful
165
-     *
166
-     * @return bool
167
-     */
168
-    public function wasLastRunSuccess(): bool
169
-    {
170
-        return $this->last_result;
171
-    }
163
+	/**
164
+	 * Returns whether the last run was successful
165
+	 *
166
+	 * @return bool
167
+	 */
168
+	public function wasLastRunSuccess(): bool
169
+	{
170
+		return $this->last_result;
171
+	}
172 172
 
173
-    /**
174
-     * Set the last run result
175
-     *
176
-     * @param bool $last_result
177
-     * @return $this
178
-     */
179
-    public function setLastResult(bool $last_result): self
180
-    {
181
-        $this->last_result = $last_result;
182
-        return $this;
183
-    }
173
+	/**
174
+	 * Set the last run result
175
+	 *
176
+	 * @param bool $last_result
177
+	 * @return $this
178
+	 */
179
+	public function setLastResult(bool $last_result): self
180
+	{
181
+		$this->last_result = $last_result;
182
+		return $this;
183
+	}
184 184
 
185
-    /**
186
-     * Get the number of remaining of occurrences of task runs.
187
-     * Returns 0 if the tasks must be run indefinitely.
188
-     *
189
-     * @return int
190
-     */
191
-    public function remainingOccurrences(): int
192
-    {
193
-        return $this->nb_occurrences;
194
-    }
185
+	/**
186
+	 * Get the number of remaining of occurrences of task runs.
187
+	 * Returns 0 if the tasks must be run indefinitely.
188
+	 *
189
+	 * @return int
190
+	 */
191
+	public function remainingOccurrences(): int
192
+	{
193
+		return $this->nb_occurrences;
194
+	}
195 195
 
196
-    /**
197
-     * Decrements the number of remaining occurrences by 1.
198
-     * The task will be disabled when the number reaches 0.
199
-     *
200
-     * @return $this
201
-     */
202
-    public function decrementRemainingOccurrences(): self
203
-    {
204
-        if ($this->nb_occurrences > 0) {
205
-            $this->nb_occurrences--;
206
-            if ($this->nb_occurrences === 0) {
207
-                $this->disable();
208
-            }
209
-        }
210
-        return $this;
211
-    }
196
+	/**
197
+	 * Decrements the number of remaining occurrences by 1.
198
+	 * The task will be disabled when the number reaches 0.
199
+	 *
200
+	 * @return $this
201
+	 */
202
+	public function decrementRemainingOccurrences(): self
203
+	{
204
+		if ($this->nb_occurrences > 0) {
205
+			$this->nb_occurrences--;
206
+			if ($this->nb_occurrences === 0) {
207
+				$this->disable();
208
+			}
209
+		}
210
+		return $this;
211
+	}
212 212
 
213
-    /**
214
-     * Set the number of remaining occurrences of task runs.
215
-     *
216
-     * @param int $nb_occurrences
217
-     * @return $this
218
-     */
219
-    public function setRemainingOccurrences(int $nb_occurrences): self
220
-    {
221
-        $this->nb_occurrences = $nb_occurrences;
222
-        return $this;
223
-    }
213
+	/**
214
+	 * Set the number of remaining occurrences of task runs.
215
+	 *
216
+	 * @param int $nb_occurrences
217
+	 * @return $this
218
+	 */
219
+	public function setRemainingOccurrences(int $nb_occurrences): self
220
+	{
221
+		$this->nb_occurrences = $nb_occurrences;
222
+		return $this;
223
+	}
224 224
 
225
-    /**
226
-     * Returns whether the task is running
227
-     * @return bool
228
-     */
229
-    public function isRunning(): bool
230
-    {
231
-        return $this->is_running;
232
-    }
225
+	/**
226
+	 * Returns whether the task is running
227
+	 * @return bool
228
+	 */
229
+	public function isRunning(): bool
230
+	{
231
+		return $this->is_running;
232
+	}
233 233
 
234
-    /**
235
-     * Informs the schedule that the task is going to run
236
-     *
237
-     * @return $this
238
-     */
239
-    public function startRunning(): self
240
-    {
241
-        $this->is_running = true;
242
-        return $this;
243
-    }
234
+	/**
235
+	 * Informs the schedule that the task is going to run
236
+	 *
237
+	 * @return $this
238
+	 */
239
+	public function startRunning(): self
240
+	{
241
+		$this->is_running = true;
242
+		return $this;
243
+	}
244 244
 
245
-    /**
246
-     * Informs the schedule that the task has stopped running.
247
-     * @return $this
248
-     */
249
-    public function stopRunning(): self
250
-    {
251
-        $this->is_running = false;
252
-        return $this;
253
-    }
245
+	/**
246
+	 * Informs the schedule that the task has stopped running.
247
+	 * @return $this
248
+	 */
249
+	public function stopRunning(): self
250
+	{
251
+		$this->is_running = false;
252
+		return $this;
253
+	}
254 254
 
255
-    /**
256
-     * Returns the schedule details as an associate array
257
-     *
258
-     * @phpcs:ignore Generic.Files.LineLength.TooLong
259
-     * @return array{id: int, task_id: string, enabled: bool, last_run: CarbonInterface, last_result: bool, frequency: int, nb_occurrences: int, is_running: bool}
260
-     */
261
-    public function toArray(): array
262
-    {
263
-        return [
264
-            'id'            =>  $this->id,
265
-            'task_id'       =>  $this->task_id,
266
-            'enabled'       =>  $this->enabled,
267
-            'last_run'      =>  $this->last_run,
268
-            'last_result'   =>  $this->last_result,
269
-            'frequency'     =>  $this->frequency,
270
-            'nb_occurrences' =>  $this->nb_occurrences,
271
-            'is_running'    =>  $this->is_running
272
-        ];
273
-    }
255
+	/**
256
+	 * Returns the schedule details as an associate array
257
+	 *
258
+	 * @phpcs:ignore Generic.Files.LineLength.TooLong
259
+	 * @return array{id: int, task_id: string, enabled: bool, last_run: CarbonInterface, last_result: bool, frequency: int, nb_occurrences: int, is_running: bool}
260
+	 */
261
+	public function toArray(): array
262
+	{
263
+		return [
264
+			'id'            =>  $this->id,
265
+			'task_id'       =>  $this->task_id,
266
+			'enabled'       =>  $this->enabled,
267
+			'last_run'      =>  $this->last_run,
268
+			'last_result'   =>  $this->last_result,
269
+			'frequency'     =>  $this->frequency,
270
+			'nb_occurrences' =>  $this->nb_occurrences,
271
+			'is_running'    =>  $this->is_running
272
+		];
273
+	}
274 274
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaComputeModal.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -28,39 +28,39 @@
 block discarded – undo
28 28
  */
29 29
 class SosaComputeModal implements RequestHandlerInterface
30 30
 {
31
-    /**
32
-     * @var SosaModule|null $module
33
-     */
34
-    private $module;
31
+	/**
32
+	 * @var SosaModule|null $module
33
+	 */
34
+	private $module;
35 35
 
36
-    /**
37
-     * Constructor for SosaComputeModal Request Handler
38
-     *
39
-     * @param ModuleService $module_service
40
-     */
41
-    public function __construct(ModuleService $module_service)
42
-    {
43
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
44
-    }
36
+	/**
37
+	 * Constructor for SosaComputeModal Request Handler
38
+	 *
39
+	 * @param ModuleService $module_service
40
+	 */
41
+	public function __construct(ModuleService $module_service)
42
+	{
43
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
44
+	}
45 45
 
46
-    /**
47
-     * {@inheritDoc}
48
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
49
-     */
50
-    public function handle(ServerRequestInterface $request): ResponseInterface
51
-    {
52
-        if ($this->module === null) {
53
-            return Registry::responseFactory()->response(view('modals/error', [
54
-                'title' => I18N::translate('Error'),
55
-                'error' => I18N::translate('The attached module could not be found.')
56
-            ]));
57
-        }
46
+	/**
47
+	 * {@inheritDoc}
48
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
49
+	 */
50
+	public function handle(ServerRequestInterface $request): ResponseInterface
51
+	{
52
+		if ($this->module === null) {
53
+			return Registry::responseFactory()->response(view('modals/error', [
54
+				'title' => I18N::translate('Error'),
55
+				'error' => I18N::translate('The attached module could not be found.')
56
+			]));
57
+		}
58 58
 
59
-        $tree = Validator::attributes($request)->tree();
59
+		$tree = Validator::attributes($request)->tree();
60 60
 
61
-        return Registry::responseFactory()->response(view($this->module->name() . '::modals/sosa-compute', [
62
-            'tree'          => $tree,
63
-            'xref'          => Validator::attributes($request)->isXref()->string('xref', '')
64
-        ]));
65
-    }
61
+		return Registry::responseFactory()->response(view($this->module->name() . '::modals/sosa-compute', [
62
+			'tree'          => $tree,
63
+			'xref'          => Validator::attributes($request)->isXref()->string('xref', '')
64
+		]));
65
+	}
66 66
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,7 @@
 block discarded – undo
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
         ]));
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/AncestorsListIndividual.php 2 patches
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -35,79 +35,79 @@
 block discarded – undo
35 35
  */
36 36
 class AncestorsListIndividual implements RequestHandlerInterface
37 37
 {
38
-    use ViewResponseTrait;
39
-
40
-    /**
41
-     * @var SosaModule|null $module
42
-     */
43
-    private $module;
44
-
45
-    /**
46
-     * @var SosaRecordsService $sosa_record_service
47
-     */
48
-    private $sosa_record_service;
49
-
50
-    /**
51
-     * Constructor for AncestorsListIndividual Request Handler
52
-     *
53
-     * @param ModuleService $module_service
54
-     * @param SosaRecordsService $sosa_record_service
55
-     */
56
-    public function __construct(
57
-        ModuleService $module_service,
58
-        SosaRecordsService $sosa_record_service
59
-    ) {
60
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
61
-        $this->sosa_record_service = $sosa_record_service;
62
-    }
63
-
64
-    /**
65
-     * {@inheritDoc}
66
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
-     */
68
-    public function handle(ServerRequestInterface $request): ResponseInterface
69
-    {
70
-        $this->layout = 'layouts/ajax';
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
-        $current_gen = Validator::attributes($request)->integer('gen', 0);
79
-
80
-        if ($current_gen <= 0) {
81
-            return Registry::responseFactory()->response(
82
-                'Invalid generation',
83
-                StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY
84
-            );
85
-        }
86
-
87
-        $list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen);
88
-        $nb_ancestors_all = $list_ancestors->count();
89
-
90
-        /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
91
-        $list_ancestors = $list_ancestors
92
-            ->filter(function (stdClass $value) use ($tree): bool {
93
-                $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94
-                return $indi !== null && $indi->canShowName();
95
-            })
96
-            ->mapWithKeys(function (stdClass $value) use ($tree): array {
97
-                $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
98
-                return [(int) $value->majs_sosa => $indi];
99
-            });
100
-
101
-        $nb_ancestors_shown = $list_ancestors->count();
102
-
103
-        return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
104
-            'module_name'       =>  $this->module->name(),
105
-            'title'             =>  I18N::translate('Sosa Ancestors'),
106
-            'tree'              =>  $tree,
107
-            'list_ancestors'    =>  $list_ancestors,
108
-            'nb_ancestors_all'  =>  $nb_ancestors_all,
109
-            'nb_ancestors_theor' =>  pow(2, $current_gen - 1),
110
-            'nb_ancestors_shown' =>  $nb_ancestors_shown
111
-        ]);
112
-    }
38
+	use ViewResponseTrait;
39
+
40
+	/**
41
+	 * @var SosaModule|null $module
42
+	 */
43
+	private $module;
44
+
45
+	/**
46
+	 * @var SosaRecordsService $sosa_record_service
47
+	 */
48
+	private $sosa_record_service;
49
+
50
+	/**
51
+	 * Constructor for AncestorsListIndividual Request Handler
52
+	 *
53
+	 * @param ModuleService $module_service
54
+	 * @param SosaRecordsService $sosa_record_service
55
+	 */
56
+	public function __construct(
57
+		ModuleService $module_service,
58
+		SosaRecordsService $sosa_record_service
59
+	) {
60
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
61
+		$this->sosa_record_service = $sosa_record_service;
62
+	}
63
+
64
+	/**
65
+	 * {@inheritDoc}
66
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
+	 */
68
+	public function handle(ServerRequestInterface $request): ResponseInterface
69
+	{
70
+		$this->layout = 'layouts/ajax';
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
+		$current_gen = Validator::attributes($request)->integer('gen', 0);
79
+
80
+		if ($current_gen <= 0) {
81
+			return Registry::responseFactory()->response(
82
+				'Invalid generation',
83
+				StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY
84
+			);
85
+		}
86
+
87
+		$list_ancestors = $this->sosa_record_service->listAncestorsAtGeneration($tree, $user, $current_gen);
88
+		$nb_ancestors_all = $list_ancestors->count();
89
+
90
+		/** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Individual> $list_ancestors */
91
+		$list_ancestors = $list_ancestors
92
+			->filter(function (stdClass $value) use ($tree): bool {
93
+				$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94
+				return $indi !== null && $indi->canShowName();
95
+			})
96
+			->mapWithKeys(function (stdClass $value) use ($tree): array {
97
+				$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
98
+				return [(int) $value->majs_sosa => $indi];
99
+			});
100
+
101
+		$nb_ancestors_shown = $list_ancestors->count();
102
+
103
+		return $this->viewResponse($this->module->name() . '::list-ancestors-indi-tab', [
104
+			'module_name'       =>  $this->module->name(),
105
+			'title'             =>  I18N::translate('Sosa Ancestors'),
106
+			'tree'              =>  $tree,
107
+			'list_ancestors'    =>  $list_ancestors,
108
+			'nb_ancestors_all'  =>  $nb_ancestors_all,
109
+			'nb_ancestors_theor' =>  pow(2, $current_gen - 1),
110
+			'nb_ancestors_shown' =>  $nb_ancestors_shown
111
+		]);
112
+	}
113 113
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -89,18 +89,18 @@
 block discarded – undo
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,
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/AncestorsListFamily.php 2 patches
Indentation   +74 added lines, -74 removed lines patch added patch discarded remove patch
@@ -35,78 +35,78 @@
 block discarded – undo
35 35
  */
36 36
 class AncestorsListFamily implements RequestHandlerInterface
37 37
 {
38
-    use ViewResponseTrait;
39
-
40
-    /**
41
-     * @var SosaModule|null $module
42
-     */
43
-    private $module;
44
-
45
-    /**
46
-     * @var SosaRecordsService $sosa_record_service
47
-     */
48
-    private $sosa_record_service;
49
-
50
-    /**
51
-     * Constructor for AncestorsListFamily Request Handler
52
-     *
53
-     * @param ModuleService $module_service
54
-     * @param SosaRecordsService $sosa_record_service
55
-     */
56
-    public function __construct(
57
-        ModuleService $module_service,
58
-        SosaRecordsService $sosa_record_service
59
-    ) {
60
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
61
-        $this->sosa_record_service = $sosa_record_service;
62
-    }
63
-
64
-    /**
65
-     * {@inheritDoc}
66
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
-     */
68
-    public function handle(ServerRequestInterface $request): ResponseInterface
69
-    {
70
-        $this->layout = 'layouts/ajax';
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
-        $current_gen = Validator::attributes($request)->integer('gen', 0);
79
-
80
-        if ($current_gen <= 0) {
81
-            return Registry::responseFactory()->response(
82
-                'Invalid generation',
83
-                StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY
84
-            );
85
-        }
86
-
87
-        $list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen);
88
-        $nb_families_all = $list_families->count();
89
-
90
-        /** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */
91
-        $list_families = $list_families
92
-            ->filter(function (stdClass $value) use ($tree): bool {
93
-                $fam = Registry::familyFactory()->make($value->f_id, $tree);
94
-                return $fam !== null && $fam->canShow();
95
-            })
96
-            ->mapWithKeys(function (stdClass $value) use ($tree): array {
97
-                $fam = Registry::familyFactory()->make($value->f_id, $tree);
98
-                return [(int) $value->majs_sosa => $fam];
99
-            });
100
-
101
-        $nb_families_shown = $list_families->count();
102
-
103
-        return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [
104
-            'module_name'       =>  $this->module->name(),
105
-            'title'             =>  I18N::translate('Sosa Ancestors'),
106
-            'tree'              =>  $tree,
107
-            'list_families'     =>  $list_families,
108
-            'nb_families_all'   =>  $nb_families_all,
109
-            'nb_families_shown' =>  $nb_families_shown
110
-        ]);
111
-    }
38
+	use ViewResponseTrait;
39
+
40
+	/**
41
+	 * @var SosaModule|null $module
42
+	 */
43
+	private $module;
44
+
45
+	/**
46
+	 * @var SosaRecordsService $sosa_record_service
47
+	 */
48
+	private $sosa_record_service;
49
+
50
+	/**
51
+	 * Constructor for AncestorsListFamily Request Handler
52
+	 *
53
+	 * @param ModuleService $module_service
54
+	 * @param SosaRecordsService $sosa_record_service
55
+	 */
56
+	public function __construct(
57
+		ModuleService $module_service,
58
+		SosaRecordsService $sosa_record_service
59
+	) {
60
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
61
+		$this->sosa_record_service = $sosa_record_service;
62
+	}
63
+
64
+	/**
65
+	 * {@inheritDoc}
66
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
67
+	 */
68
+	public function handle(ServerRequestInterface $request): ResponseInterface
69
+	{
70
+		$this->layout = 'layouts/ajax';
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
+		$current_gen = Validator::attributes($request)->integer('gen', 0);
79
+
80
+		if ($current_gen <= 0) {
81
+			return Registry::responseFactory()->response(
82
+				'Invalid generation',
83
+				StatusCodeInterface::STATUS_UNPROCESSABLE_ENTITY
84
+			);
85
+		}
86
+
87
+		$list_families = $this->sosa_record_service->listAncestorFamiliesAtGeneration($tree, $user, $current_gen);
88
+		$nb_families_all = $list_families->count();
89
+
90
+		/** @var \Illuminate\Support\Collection<int, \Fisharebest\Webtrees\Family> $list_families */
91
+		$list_families = $list_families
92
+			->filter(function (stdClass $value) use ($tree): bool {
93
+				$fam = Registry::familyFactory()->make($value->f_id, $tree);
94
+				return $fam !== null && $fam->canShow();
95
+			})
96
+			->mapWithKeys(function (stdClass $value) use ($tree): array {
97
+				$fam = Registry::familyFactory()->make($value->f_id, $tree);
98
+				return [(int) $value->majs_sosa => $fam];
99
+			});
100
+
101
+		$nb_families_shown = $list_families->count();
102
+
103
+		return $this->viewResponse($this->module->name() . '::list-ancestors-fam-tab', [
104
+			'module_name'       =>  $this->module->name(),
105
+			'title'             =>  I18N::translate('Sosa Ancestors'),
106
+			'tree'              =>  $tree,
107
+			'list_families'     =>  $list_families,
108
+			'nb_families_all'   =>  $nb_families_all,
109
+			'nb_families_shown' =>  $nb_families_shown
110
+		]);
111
+	}
112 112
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -89,18 +89,18 @@
 block discarded – undo
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,
Please login to merge, or discard this patch.
app/Module/Sosa/GeoAnalyses/SosaByGenerationGeoAnalysis.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -32,101 +32,101 @@
 block discarded – undo
32 32
  */
33 33
 class SosaByGenerationGeoAnalysis implements GeoAnalysisInterface
34 34
 {
35
-    private SosaRecordsService $records_service;
36
-
37
-    /**
38
-     * Constructor for SosaByGenerationGeoAnalysis
39
-     *
40
-     * @param SosaRecordsService $records_service
41
-     */
42
-    public function __construct(SosaRecordsService $records_service)
43
-    {
44
-        $this->records_service = $records_service;
45
-    }
46
-
47
-    /**
48
-     * {@inheritDoc}
49
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title()
50
-     */
51
-    public function title(): string
52
-    {
53
-        return I18N::translate('Sosa ancestors places by generation');
54
-    }
55
-
56
-    /**
57
-     * {@inheritDoc}
58
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription()
59
-     */
60
-    public function itemsDescription(): callable
61
-    {
62
-        return fn(int $count): string => I18N::plural('ancestor', 'ancestors', $count);
63
-    }
64
-
65
-    /**
66
-     * {@inheritDoc}
67
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results()
68
-     */
69
-    public function results(Tree $tree, int $depth): GeoAnalysisResults
70
-    {
71
-        $results = new GeoAnalysisResults();
72
-
73
-        $unique_ancestors = $this->records_service
74
-            ->listAncestors($tree, Auth::check() ? Auth::user() : new DefaultUser())
75
-            ->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id);
76
-
77
-        foreach ($unique_ancestors as $item) {
78
-            $ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree);
79
-            if ($ancestor === null || !$ancestor->canShow()) {
80
-                continue;
81
-            }
82
-            $generation = $this->records_service->generation((int) $item->majs_sosa);
83
-            $significantplace = new GeoAnalysisPlace($tree, null, $depth);
84
-            foreach ($this->significantPlaces($ancestor) as $place) {
85
-                $significantplace = new GeoAnalysisPlace($tree, $place, $depth, true);
86
-                if ($significantplace->isKnown()) {
87
-                    break;
88
-                }
89
-            }
90
-            $results->addPlace($significantplace);
91
-            $results->addPlaceInCategory(
92
-                I18N::translate('Generation %s', I18N::number($generation)),
93
-                $generation,
94
-                $significantplace
95
-            );
96
-        }
97
-
98
-        return $results;
99
-    }
100
-
101
-    /**
102
-     * Returns significant places in order of priority for an individual
103
-     *
104
-     * @param Individual $individual
105
-     * @return Generator<\Fisharebest\Webtrees\Place>
106
-     */
107
-    protected function significantPlaces(Individual $individual): Generator
108
-    {
109
-        yield $individual->getBirthPlace();
110
-
111
-        /** @var \Fisharebest\Webtrees\Fact $fact */
112
-        foreach ($individual->facts(['RESI']) as $fact) {
113
-            yield $fact->place();
114
-        }
115
-
116
-        yield $individual->getDeathPlace();
117
-
118
-        /** @var \Fisharebest\Webtrees\Family $family */
119
-        foreach ($individual->childFamilies() as $family) {
120
-            foreach ($family->facts(['RESI']) as $fact) {
121
-                yield $fact->place();
122
-            }
123
-        }
124
-
125
-        /** @var \Fisharebest\Webtrees\Family $family */
126
-        foreach ($individual->spouseFamilies() as $family) {
127
-            foreach ($family->facts(['RESI']) as $fact) {
128
-                yield $fact->place();
129
-            }
130
-        }
131
-    }
35
+	private SosaRecordsService $records_service;
36
+
37
+	/**
38
+	 * Constructor for SosaByGenerationGeoAnalysis
39
+	 *
40
+	 * @param SosaRecordsService $records_service
41
+	 */
42
+	public function __construct(SosaRecordsService $records_service)
43
+	{
44
+		$this->records_service = $records_service;
45
+	}
46
+
47
+	/**
48
+	 * {@inheritDoc}
49
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::title()
50
+	 */
51
+	public function title(): string
52
+	{
53
+		return I18N::translate('Sosa ancestors places by generation');
54
+	}
55
+
56
+	/**
57
+	 * {@inheritDoc}
58
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::itemsDescription()
59
+	 */
60
+	public function itemsDescription(): callable
61
+	{
62
+		return fn(int $count): string => I18N::plural('ancestor', 'ancestors', $count);
63
+	}
64
+
65
+	/**
66
+	 * {@inheritDoc}
67
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\GeoAnalysisInterface::results()
68
+	 */
69
+	public function results(Tree $tree, int $depth): GeoAnalysisResults
70
+	{
71
+		$results = new GeoAnalysisResults();
72
+
73
+		$unique_ancestors = $this->records_service
74
+			->listAncestors($tree, Auth::check() ? Auth::user() : new DefaultUser())
75
+			->uniqueStrict(fn(stdClass $item): string => $item->majs_i_id);
76
+
77
+		foreach ($unique_ancestors as $item) {
78
+			$ancestor = Registry::individualFactory()->make($item->majs_i_id, $tree);
79
+			if ($ancestor === null || !$ancestor->canShow()) {
80
+				continue;
81
+			}
82
+			$generation = $this->records_service->generation((int) $item->majs_sosa);
83
+			$significantplace = new GeoAnalysisPlace($tree, null, $depth);
84
+			foreach ($this->significantPlaces($ancestor) as $place) {
85
+				$significantplace = new GeoAnalysisPlace($tree, $place, $depth, true);
86
+				if ($significantplace->isKnown()) {
87
+					break;
88
+				}
89
+			}
90
+			$results->addPlace($significantplace);
91
+			$results->addPlaceInCategory(
92
+				I18N::translate('Generation %s', I18N::number($generation)),
93
+				$generation,
94
+				$significantplace
95
+			);
96
+		}
97
+
98
+		return $results;
99
+	}
100
+
101
+	/**
102
+	 * Returns significant places in order of priority for an individual
103
+	 *
104
+	 * @param Individual $individual
105
+	 * @return Generator<\Fisharebest\Webtrees\Place>
106
+	 */
107
+	protected function significantPlaces(Individual $individual): Generator
108
+	{
109
+		yield $individual->getBirthPlace();
110
+
111
+		/** @var \Fisharebest\Webtrees\Fact $fact */
112
+		foreach ($individual->facts(['RESI']) as $fact) {
113
+			yield $fact->place();
114
+		}
115
+
116
+		yield $individual->getDeathPlace();
117
+
118
+		/** @var \Fisharebest\Webtrees\Family $family */
119
+		foreach ($individual->childFamilies() as $family) {
120
+			foreach ($family->facts(['RESI']) as $fact) {
121
+				yield $fact->place();
122
+			}
123
+		}
124
+
125
+		/** @var \Fisharebest\Webtrees\Family $family */
126
+		foreach ($individual->spouseFamilies() as $family) {
127
+			foreach ($family->facts(['RESI']) as $fact) {
128
+				yield $fact->place();
129
+			}
130
+		}
131
+	}
132 132
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -72,14 +72,14 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
app/Module/Sosa/Services/SosaStatisticsService.php 2 patches
Indentation   +527 added lines, -527 removed lines patch added patch discarded remove patch
@@ -29,538 +29,538 @@
 block discarded – undo
29 29
  */
30 30
 class SosaStatisticsService
31 31
 {
32
-    private UserInterface $user;
33
-    private Tree $tree;
34
-
35
-    /**
36
-     * Constructor for Sosa Statistics Service
37
-     *
38
-     * @param Tree $tree
39
-     * @param UserInterface $user
40
-     */
41
-    public function __construct(Tree $tree, UserInterface $user)
42
-    {
43
-        $this->tree = $tree;
44
-        $this->user = $user;
45
-    }
46
-
47
-    /**
48
-     * Check if PDO support the queries used in Sosa statistics.
49
-     *
50
-     * SQLite does not support RIGHT and FULL JOIN, and POWER/SQRT require a specific compilation flag.
51
-     *
52
-     * @return bool
53
-     */
54
-    public function isPdoSupported(): bool
55
-    {
56
-        return DB::connection()->getDriverName() !== 'sqlite';
57
-    }
58
-
59
-    /**
60
-     * Return the root individual for the reference tree and user.
61
-     *
62
-     * @return Individual|NULL
63
-     */
64
-    public function rootIndividual(): ?Individual
65
-    {
66
-        $root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
67
-        return Registry::individualFactory()->make($root_indi_id, $this->tree);
68
-    }
69
-
70
-    /**
71
-     * Get the highest generation for the reference tree and user.
72
-     *
73
-     * @return int
74
-     */
75
-    public function maxGeneration(): int
76
-    {
77
-        return (int) DB::table('maj_sosa')
78
-            ->where('majs_gedcom_id', '=', $this->tree->id())
79
-            ->where('majs_user_id', '=', $this->user->id())
80
-            ->max('majs_gen');
81
-    }
82
-
83
-    /**
84
-     * Get the total count of individuals in the tree.
85
-     *
86
-     * @return int
87
-     */
88
-    public function totalIndividuals(): int
89
-    {
90
-        return DB::table('individuals')
91
-            ->where('i_file', '=', $this->tree->id())
92
-            ->count();
93
-    }
94
-
95
-    /**
96
-     * Get the total count of Sosa ancestors for all generations
97
-     *
98
-     * @return int
99
-     */
100
-    public function totalAncestors(): int
101
-    {
102
-        return DB::table('maj_sosa')
103
-            ->where('majs_gedcom_id', '=', $this->tree->id())
104
-            ->where('majs_user_id', '=', $this->user->id())
105
-            ->count();
106
-    }
107
-
108
-    /**
109
-     * Get the total count of Sosa ancestors for a generation
110
-     *
111
-     * @return int
112
-     */
113
-    public function totalAncestorsAtGeneration(int $gen): int
114
-    {
115
-        return DB::table('maj_sosa')
116
-            ->where('majs_gedcom_id', '=', $this->tree->id())
117
-            ->where('majs_user_id', '=', $this->user->id())
118
-            ->where('majs_gen', '=', $gen)
119
-            ->count();
120
-    }
121
-
122
-    /**
123
-     * Get the total count of distinct Sosa ancestors for all generations
124
-     *
125
-     * @return int
126
-     */
127
-    public function totalDistinctAncestors(): int
128
-    {
129
-        return DB::table('maj_sosa')
130
-            ->where('majs_gedcom_id', '=', $this->tree->id())
131
-            ->where('majs_user_id', '=', $this->user->id())
132
-            ->distinct()
133
-            ->count('majs_i_id');
134
-    }
135
-
136
-    /**
137
-     * Get the mean generation time, as the slope of the linear regression of birth years vs generations
138
-     *
139
-     * @return float
140
-     */
141
-    public function meanGenerationTime(): float
142
-    {
143
-        $row = DB::table('maj_sosa')
144
-            ->where('majs_gedcom_id', '=', $this->tree->id())
145
-            ->where('majs_user_id', '=', $this->user->id())
146
-            ->whereNotNull('majs_birth_year')
147
-            ->selectRaw('COUNT(majs_sosa) AS n')
148
-            ->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy')
149
-            ->selectRaw('SUM(majs_gen) AS sum_x')
150
-            ->selectRaw('SUM(majs_birth_year) AS sum_y')
151
-            ->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2')
152
-            ->get()->first();
153
-
154
-        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));
156
-    }
157
-
158
-    /**
159
-     * Get the statistic array detailed by generation.
160
-     * Statistics for each generation are:
161
-     *  - The number of Sosa in generation
162
-     *  - The number of Sosa up to generation
163
-     *  - The number of distinct Sosa up to generation
164
-     *  - The year of the first birth in generation
165
-     *  - The year of the first estimated birth in generation
166
-     *  - The year of the last birth in generation
167
-     *  - The year of the last estimated birth in generation
168
-     *  - The average year of birth in generation
169
-     *
170
-     * @return array<int, array<string, int|null>> Statistics array
171
-     */
172
-    public function statisticsByGenerations(): array
173
-    {
174
-        $stats_by_gen = $this->statisticsByGenerationBasicData();
175
-        $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData();
176
-
177
-        $statistics_by_gen = [];
178
-        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,
183
-                'firstBirth'            =>  $stats_gen->first_year,
184
-                'firstEstimatedBirth'   =>  $stats_gen->first_est_year,
185
-                'lastBirth'             =>  $stats_gen->last_year,
186
-                'lastEstimatedBirth'    =>  $stats_gen->last_est_year
187
-            );
188
-        }
189
-
190
-        return $statistics_by_gen;
191
-    }
192
-
193
-    /**
194
-     * Returns the basic statistics data by generation.
195
-     *
196
-     * @return Collection<int, \stdClass>
197
-     */
198
-    private function statisticsByGenerationBasicData(): Collection
199
-    {
200
-        return DB::table('maj_sosa')
201
-            ->where('majs_gedcom_id', '=', $this->tree->id())
202
-            ->where('majs_user_id', '=', $this->user->id())
203
-            ->groupBy('majs_gen')
204
-            ->orderBy('majs_gen', 'asc')
205
-            ->select('majs_gen AS gen')
206
-            ->selectRaw('COUNT(majs_sosa) AS total_sosa')
207
-            ->selectRaw('MIN(majs_birth_year) AS first_year')
208
-            ->selectRaw('MIN(majs_birth_year_est) AS first_est_year')
209
-            ->selectRaw('MAX(majs_birth_year) AS last_year')
210
-            ->selectRaw('MAX(majs_birth_year_est) AS last_est_year')
211
-            ->get()->keyBy('gen');
212
-    }
213
-
214
-    /**
215
-     * Returns the cumulative statistics data by generation
216
-     *
217
-     * @return Collection<int, \stdClass>
218
-     */
219
-    private function statisticsByGenerationCumulativeData(): Collection
220
-    {
221
-        $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
222
-            ->where('majs_gedcom_id', '=', $this->tree->id())
223
-            ->where('majs_user_id', '=', $this->user->id());
224
-
225
-        return DB::table('maj_sosa')
226
-            ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
227
-                $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen')
228
-                ->where('majs_gedcom_id', '=', $this->tree->id())
229
-                ->where('majs_user_id', '=', $this->user->id());
230
-            })
231
-            ->groupBy('list_gen.majs_gen')
232
-            ->select('list_gen.majs_gen AS gen')
233
-            ->selectRaw('COUNT(majs_i_id) AS total_cumul')
234
-            ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul')
235
-            ->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple')
236
-            ->get()->keyBy('gen');
237
-    }
238
-
239
-    /**
240
-     * Returns the pedigree collapse improved calculation by generation.
241
-     *
242
-     * Format:
243
-     *  - key : generation
244
-     *  - values:
245
-     *      - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation
246
-     *      - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation
247
-     *
248
-     * @return array<int, array<string, float>>
249
-     */
250
-    public function pedigreeCollapseByGenerationData(): array
251
-    {
252
-        if (!$this->isPdoSupported()) {
253
-            return [];
254
-        }
255
-
256
-        $table_prefix = DB::connection()->getTablePrefix();
257
-
258
-        $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
259
-            ->where('majs_gedcom_id', '=', $this->tree->id())
260
-            ->where('majs_user_id', '=', $this->user->id());
261
-
262
-        /* Compute the contributions of nodes of previous generations to the current generation */
263
-        $root_ancestors_contributions = DB::table('maj_sosa AS sosa')
264
-            ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
265
-            ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
266
-            ->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 ' .
276
-                ' END) contrib'
277
-            )
278
-            ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
279
-                $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen')
280
-                    ->where('majs_gedcom_id', '=', $this->tree->id())
281
-                    ->where('majs_user_id', '=', $this->user->id());
282
-            })
283
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
284
-                // Link to sosa's father
285
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
286
-                    ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
287
-                    ->where('sosa_fat.majs_user_id', '=', $this->user->id());
288
-            })
289
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
290
-                // Link to sosa's mother
291
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
292
-                    ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
293
-                    ->where('sosa_mot.majs_user_id', '=', $this->user->id());
294
-            })
295
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
296
-            ->where('sosa.majs_user_id', '=', $this->user->id())
297
-            ->where(function (Builder $query): void {
298
-                $query->whereNull('sosa_fat.majs_i_id')
299
-                ->orWhereNull('sosa_mot.majs_i_id');
300
-            });
301
-
302
-        /* Identify nodes in the generations with ancestors who are also in the same generation.
32
+	private UserInterface $user;
33
+	private Tree $tree;
34
+
35
+	/**
36
+	 * Constructor for Sosa Statistics Service
37
+	 *
38
+	 * @param Tree $tree
39
+	 * @param UserInterface $user
40
+	 */
41
+	public function __construct(Tree $tree, UserInterface $user)
42
+	{
43
+		$this->tree = $tree;
44
+		$this->user = $user;
45
+	}
46
+
47
+	/**
48
+	 * Check if PDO support the queries used in Sosa statistics.
49
+	 *
50
+	 * SQLite does not support RIGHT and FULL JOIN, and POWER/SQRT require a specific compilation flag.
51
+	 *
52
+	 * @return bool
53
+	 */
54
+	public function isPdoSupported(): bool
55
+	{
56
+		return DB::connection()->getDriverName() !== 'sqlite';
57
+	}
58
+
59
+	/**
60
+	 * Return the root individual for the reference tree and user.
61
+	 *
62
+	 * @return Individual|NULL
63
+	 */
64
+	public function rootIndividual(): ?Individual
65
+	{
66
+		$root_indi_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
67
+		return Registry::individualFactory()->make($root_indi_id, $this->tree);
68
+	}
69
+
70
+	/**
71
+	 * Get the highest generation for the reference tree and user.
72
+	 *
73
+	 * @return int
74
+	 */
75
+	public function maxGeneration(): int
76
+	{
77
+		return (int) DB::table('maj_sosa')
78
+			->where('majs_gedcom_id', '=', $this->tree->id())
79
+			->where('majs_user_id', '=', $this->user->id())
80
+			->max('majs_gen');
81
+	}
82
+
83
+	/**
84
+	 * Get the total count of individuals in the tree.
85
+	 *
86
+	 * @return int
87
+	 */
88
+	public function totalIndividuals(): int
89
+	{
90
+		return DB::table('individuals')
91
+			->where('i_file', '=', $this->tree->id())
92
+			->count();
93
+	}
94
+
95
+	/**
96
+	 * Get the total count of Sosa ancestors for all generations
97
+	 *
98
+	 * @return int
99
+	 */
100
+	public function totalAncestors(): int
101
+	{
102
+		return DB::table('maj_sosa')
103
+			->where('majs_gedcom_id', '=', $this->tree->id())
104
+			->where('majs_user_id', '=', $this->user->id())
105
+			->count();
106
+	}
107
+
108
+	/**
109
+	 * Get the total count of Sosa ancestors for a generation
110
+	 *
111
+	 * @return int
112
+	 */
113
+	public function totalAncestorsAtGeneration(int $gen): int
114
+	{
115
+		return DB::table('maj_sosa')
116
+			->where('majs_gedcom_id', '=', $this->tree->id())
117
+			->where('majs_user_id', '=', $this->user->id())
118
+			->where('majs_gen', '=', $gen)
119
+			->count();
120
+	}
121
+
122
+	/**
123
+	 * Get the total count of distinct Sosa ancestors for all generations
124
+	 *
125
+	 * @return int
126
+	 */
127
+	public function totalDistinctAncestors(): int
128
+	{
129
+		return DB::table('maj_sosa')
130
+			->where('majs_gedcom_id', '=', $this->tree->id())
131
+			->where('majs_user_id', '=', $this->user->id())
132
+			->distinct()
133
+			->count('majs_i_id');
134
+	}
135
+
136
+	/**
137
+	 * Get the mean generation time, as the slope of the linear regression of birth years vs generations
138
+	 *
139
+	 * @return float
140
+	 */
141
+	public function meanGenerationTime(): float
142
+	{
143
+		$row = DB::table('maj_sosa')
144
+			->where('majs_gedcom_id', '=', $this->tree->id())
145
+			->where('majs_user_id', '=', $this->user->id())
146
+			->whereNotNull('majs_birth_year')
147
+			->selectRaw('COUNT(majs_sosa) AS n')
148
+			->selectRaw('SUM(majs_gen * majs_birth_year) AS sum_xy')
149
+			->selectRaw('SUM(majs_gen) AS sum_x')
150
+			->selectRaw('SUM(majs_birth_year) AS sum_y')
151
+			->selectRaw('SUM(majs_gen * majs_gen) AS sum_x2')
152
+			->get()->first();
153
+
154
+		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));
156
+	}
157
+
158
+	/**
159
+	 * Get the statistic array detailed by generation.
160
+	 * Statistics for each generation are:
161
+	 *  - The number of Sosa in generation
162
+	 *  - The number of Sosa up to generation
163
+	 *  - The number of distinct Sosa up to generation
164
+	 *  - The year of the first birth in generation
165
+	 *  - The year of the first estimated birth in generation
166
+	 *  - The year of the last birth in generation
167
+	 *  - The year of the last estimated birth in generation
168
+	 *  - The average year of birth in generation
169
+	 *
170
+	 * @return array<int, array<string, int|null>> Statistics array
171
+	 */
172
+	public function statisticsByGenerations(): array
173
+	{
174
+		$stats_by_gen = $this->statisticsByGenerationBasicData();
175
+		$cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData();
176
+
177
+		$statistics_by_gen = [];
178
+		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,
183
+				'firstBirth'            =>  $stats_gen->first_year,
184
+				'firstEstimatedBirth'   =>  $stats_gen->first_est_year,
185
+				'lastBirth'             =>  $stats_gen->last_year,
186
+				'lastEstimatedBirth'    =>  $stats_gen->last_est_year
187
+			);
188
+		}
189
+
190
+		return $statistics_by_gen;
191
+	}
192
+
193
+	/**
194
+	 * Returns the basic statistics data by generation.
195
+	 *
196
+	 * @return Collection<int, \stdClass>
197
+	 */
198
+	private function statisticsByGenerationBasicData(): Collection
199
+	{
200
+		return DB::table('maj_sosa')
201
+			->where('majs_gedcom_id', '=', $this->tree->id())
202
+			->where('majs_user_id', '=', $this->user->id())
203
+			->groupBy('majs_gen')
204
+			->orderBy('majs_gen', 'asc')
205
+			->select('majs_gen AS gen')
206
+			->selectRaw('COUNT(majs_sosa) AS total_sosa')
207
+			->selectRaw('MIN(majs_birth_year) AS first_year')
208
+			->selectRaw('MIN(majs_birth_year_est) AS first_est_year')
209
+			->selectRaw('MAX(majs_birth_year) AS last_year')
210
+			->selectRaw('MAX(majs_birth_year_est) AS last_est_year')
211
+			->get()->keyBy('gen');
212
+	}
213
+
214
+	/**
215
+	 * Returns the cumulative statistics data by generation
216
+	 *
217
+	 * @return Collection<int, \stdClass>
218
+	 */
219
+	private function statisticsByGenerationCumulativeData(): Collection
220
+	{
221
+		$list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
222
+			->where('majs_gedcom_id', '=', $this->tree->id())
223
+			->where('majs_user_id', '=', $this->user->id());
224
+
225
+		return DB::table('maj_sosa')
226
+			->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
227
+				$join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen')
228
+				->where('majs_gedcom_id', '=', $this->tree->id())
229
+				->where('majs_user_id', '=', $this->user->id());
230
+			})
231
+			->groupBy('list_gen.majs_gen')
232
+			->select('list_gen.majs_gen AS gen')
233
+			->selectRaw('COUNT(majs_i_id) AS total_cumul')
234
+			->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul')
235
+			->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple')
236
+			->get()->keyBy('gen');
237
+	}
238
+
239
+	/**
240
+	 * Returns the pedigree collapse improved calculation by generation.
241
+	 *
242
+	 * Format:
243
+	 *  - key : generation
244
+	 *  - values:
245
+	 *      - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation
246
+	 *      - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation
247
+	 *
248
+	 * @return array<int, array<string, float>>
249
+	 */
250
+	public function pedigreeCollapseByGenerationData(): array
251
+	{
252
+		if (!$this->isPdoSupported()) {
253
+			return [];
254
+		}
255
+
256
+		$table_prefix = DB::connection()->getTablePrefix();
257
+
258
+		$list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
259
+			->where('majs_gedcom_id', '=', $this->tree->id())
260
+			->where('majs_user_id', '=', $this->user->id());
261
+
262
+		/* Compute the contributions of nodes of previous generations to the current generation */
263
+		$root_ancestors_contributions = DB::table('maj_sosa AS sosa')
264
+			->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
265
+			->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
266
+			->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 ' .
276
+				' END) contrib'
277
+			)
278
+			->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
279
+				$join->on('sosa.majs_gen', '<', 'list_gen.majs_gen')
280
+					->where('majs_gedcom_id', '=', $this->tree->id())
281
+					->where('majs_user_id', '=', $this->user->id());
282
+			})
283
+			->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
284
+				// Link to sosa's father
285
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
286
+					->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
287
+					->where('sosa_fat.majs_user_id', '=', $this->user->id());
288
+			})
289
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
290
+				// Link to sosa's mother
291
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
292
+					->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
293
+					->where('sosa_mot.majs_user_id', '=', $this->user->id());
294
+			})
295
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
296
+			->where('sosa.majs_user_id', '=', $this->user->id())
297
+			->where(function (Builder $query): void {
298
+				$query->whereNull('sosa_fat.majs_i_id')
299
+				->orWhereNull('sosa_mot.majs_i_id');
300
+			});
301
+
302
+		/* Identify nodes in the generations with ancestors who are also in the same generation.
303 303
          * This is the vertical/generational collapse that will reduce the number or roots.
304 304
          */
305
-        $non_roots_ancestors = DB::table('maj_sosa AS sosa')
306
-            ->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)' .
308
-                ' AS full_ancestors')
309
-            ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void {
310
-                $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')
314
-                    ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id())
315
-                    ->where('sosa_anc.majs_user_id', '=', $this->user->id());
316
-            })
317
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
318
-            ->where('sosa.majs_user_id', '=', $this->user->id())
319
-            ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void {
320
-                $query->from('maj_sosa AS sosa_gen')
321
-                ->select('sosa_gen.majs_i_id')->distinct()
322
-                ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id())
323
-                ->where('sosa_gen.majs_user_id', '=', $this->user->id())
324
-                ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen');
325
-            })
326
-            ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id',
327
-                'sosa.majs_sosa', 'sosa.majs_i_id']);
328
-
329
-        /* Compute the contribution of the nodes in the generation,
305
+		$non_roots_ancestors = DB::table('maj_sosa AS sosa')
306
+			->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)' .
308
+				' AS full_ancestors')
309
+			->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void {
310
+				$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')
314
+					->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id())
315
+					->where('sosa_anc.majs_user_id', '=', $this->user->id());
316
+			})
317
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
318
+			->where('sosa.majs_user_id', '=', $this->user->id())
319
+			->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void {
320
+				$query->from('maj_sosa AS sosa_gen')
321
+				->select('sosa_gen.majs_i_id')->distinct()
322
+				->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id())
323
+				->where('sosa_gen.majs_user_id', '=', $this->user->id())
324
+				->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen');
325
+			})
326
+			->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id',
327
+				'sosa.majs_sosa', 'sosa.majs_i_id']);
328
+
329
+		/* Compute the contribution of the nodes in the generation,
330 330
          * excluding the nodes with ancestors in the same generation.
331 331
          * Nodes with a parent missing are not excluded to cater for the missing one.
332 332
          */
333
-        $known_ancestors_contributions = DB::table('maj_sosa AS sosa')
334
-            ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
335
-            ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
336
-            ->selectRaw('1 AS contrib')
337
-            ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void {
338
-                $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen')
339
-                    ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa')
340
-                    ->where('nonroot.full_ancestors', '>', 0)
341
-                    ->where('nonroot.majs_gedcom_id', '=', $this->tree->id())
342
-                    ->where('nonroot.majs_user_id', '=', $this->user->id());
343
-            })
344
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
345
-            ->where('sosa.majs_user_id', '=', $this->user->id())
346
-            ->whereNull('nonroot.majs_sosa');
347
-
348
-        /* Aggregate both queries, and calculate the sum of contributions by generation roots.
333
+		$known_ancestors_contributions = DB::table('maj_sosa AS sosa')
334
+			->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
335
+			->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
336
+			->selectRaw('1 AS contrib')
337
+			->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void {
338
+				$join->on('sosa.majs_gen', '=', 'nonroot.majs_gen')
339
+					->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa')
340
+					->where('nonroot.full_ancestors', '>', 0)
341
+					->where('nonroot.majs_gedcom_id', '=', $this->tree->id())
342
+					->where('nonroot.majs_user_id', '=', $this->user->id());
343
+			})
344
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
345
+			->where('sosa.majs_user_id', '=', $this->user->id())
346
+			->whereNull('nonroot.majs_sosa');
347
+
348
+		/* Aggregate both queries, and calculate the sum of contributions by generation roots.
349 349
          * Exclude as well nodes that already appear in lower generations, as their branche has already been reduced.
350 350
          */
351
-        $ancestors_contributions_sum = DB::connection()->query()
352
-            ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs')
353
-            ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id'])
354
-            ->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 {
358
-                $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen')
359
-                    ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id')
360
-                    ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id())
361
-                    ->where('sosa_low.majs_user_id', '=', $this->user->id());
362
-            })
363
-            ->whereNull('sosa_low.majs_sosa')
364
-            ->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id',
365
-                'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']);
366
-
367
-        // Aggregate all generation roots to compute root and generation pedigree collapse
368
-        $pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum')
369
-            ->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)')
370
-            ->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots')  // Roots/horizontal collapse
371
-            ->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse
372
-            ->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id'])
373
-            ->orderBy('gen')
374
-            ->get();
375
-
376
-        $pedi_collapse_by_gen = [];
377
-        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
381
-            );
382
-        }
383
-        return $pedi_collapse_by_gen;
384
-    }
385
-
386
-    /**
387
-     * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation.
388
-     * Sosa 1 is of generation 1.
389
-     *
390
-     * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes,
391
-     * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140
392
-     * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0
393
-     *
394
-     * Format:
395
-     *  - key : sosa number of the ancestor
396
-     *  - values:
397
-     *      - root_ancestor_id : ID of the ancestor
398
-     *      - mean_gen_depth : Mean generation depth
399
-     *      - stddev_gen_depth : Standard deviation of generation depth
400
-     *
401
-     * @param int $gen Sosa generation
402
-     * @return Collection<int, \stdClass>
403
-     */
404
-    public function generationDepthStatsAtGeneration(int $gen): Collection
405
-    {
406
-        if (!$this->isPdoSupported()) {
407
-            return collect();
408
-        }
409
-
410
-        $table_prefix = DB::connection()->getTablePrefix();
411
-        $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 {
417
-                // Link to sosa's father
418
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
419
-                ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
420
-                ->where('sosa_fat.majs_user_id', '=', $this->user->id());
421
-            })
422
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
423
-                // Link to sosa's mother
424
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
425
-                ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
426
-                ->where('sosa_mot.majs_user_id', '=', $this->user->id());
427
-            })
428
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
429
-            ->where('sosa.majs_user_id', '=', $this->user->id())
430
-            ->where('sosa.majs_gen', '>=', $gen)
431
-            ->where(function (Builder $query): void {
432
-                $query->whereNull('sosa_fat.majs_i_id')
433
-                    ->orWhereNull('sosa_mot.majs_i_id');
434
-            })
435
-            ->groupBy(['sosa.majs_gen', 'root_ancestor']);
436
-
437
-        return DB::table('maj_sosa AS sosa_list')
438
-            ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id'])
439
-            ->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
443
-                ' ) AS stddev_gen_depth')
444
-            ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void {
445
-                $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor')
446
-                    ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id())
447
-                    ->where('sosa_list.majs_user_id', '=', $this->user->id());
448
-            })
449
-            ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id'])
450
-            ->orderBy('stats_by_gen.root_ancestor')
451
-            ->get()->keyBy('root_ancestor_sosa');
452
-    }
453
-
454
-    /**
455
-     * Return a collection of the most duplicated root Sosa ancestors.
456
-     * The number of ancestors to return is limited by the parameter $limit.
457
-     * If several individuals are tied when reaching the limit, none of them are returned,
458
-     * which means that there can be less individuals returned than requested.
459
-     *
460
-     * Format:
461
-     *  - value:
462
-     *      - sosa_i_id : sosa individual
463
-     *      - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times)
464
-     *
465
-     * @param int $limit
466
-     * @return Collection<\stdClass>
467
-     */
468
-    public function topMultipleAncestorsWithNoTies(int $limit): Collection
469
-    {
470
-        $table_prefix = DB::connection()->getTablePrefix();
471
-        $multiple_ancestors = DB::table('maj_sosa AS sosa')
472
-            ->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 {
475
-                // Link to sosa's father
476
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
477
-                    ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
478
-                    ->where('sosa_fat.majs_user_id', '=', $this->user->id());
479
-            })
480
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
481
-                // Link to sosa's mother
482
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
483
-                ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
484
-                ->where('sosa_mot.majs_user_id', '=', $this->user->id());
485
-            })
486
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
487
-            ->where('sosa.majs_user_id', '=', $this->user->id())
488
-            ->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
489
-            ->whereNull('sosa_mot.majs_sosa')
490
-            ->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
493
-            ->limit($limit + 1)     // We want to select one more than required, for ties
494
-            ->get();
495
-
496
-        if ($multiple_ancestors->count() > $limit) {
497
-            $last_count = $multiple_ancestors->last()->sosa_count;
498
-            $multiple_ancestors = $multiple_ancestors->reject(
499
-                fn (stdClass $element): bool => $element->sosa_count ===  $last_count
500
-            );
501
-        }
502
-        return $multiple_ancestors;
503
-    }
504
-
505
-    /**
506
-     * Return a computed array of statistics about the dispersion of ancestors across the ancestors
507
-     * at a specified generation.
508
-     *
509
-     * Format:
510
-     *  - key : rank of the ancestor in generation G for which exclusive ancestors have been found
511
-     *          For instance 3 represent the maternal grand father
512
-     *          0 is used for shared ancestors
513
-     *  - values:
514
-     *      - branches: same as key
515
-     *      - majs_i_id: xref of the ancestor at rank key in generation G, or null for shared ancestors
516
-     *      - count_indi: number of ancestors exclusively in the ancestors of the ancestor at rank key
517
-     *
518
-     * For instance a result at generation 3 could be :
519
-     * [
520
-     *  0 => { branches: 0, majs_i_id: X1, count_indi: 12 } -> 12 ancestors are shared by the grand-parents
521
-     *  1 => { branches: 1, majs_i_id: X2, count_indi: 32 } -> 32 ancestors are exclusive to the paternal grand-father
522
-     *  2 => { branches: 2, majs_i_id: X3, count_indi: 25 } -> 25 ancestors are exclusive to the paternal grand-mother
523
-     *  3 => { branches: 3, majs_i_id: X4, count_indi: 12 } -> 12 ancestors are exclusive to the maternal grand-father
524
-     *  4 => { branches: 4, majs_i_id: X5, count_indi: 30 } -> 30 ancestors are exclusive to the maternal grand-mother
525
-     * ]
526
-     *
527
-     * @param int $gen
528
-     * @return Collection<int, \stdClass>
529
-     */
530
-    public function ancestorsDispersionForGeneration(int $gen): Collection
531
-    {
532
-        if (!$this->isPdoSupported()) {
533
-            return collect();
534
-        }
535
-
536
-        $ancestors_branches = DB::table('maj_sosa')
537
-            ->select('majs_i_id AS i_id')
538
-            ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen])
539
-            ->where('majs_gedcom_id', '=', $this->tree->id())
540
-            ->where('majs_user_id', '=', $this->user->id())
541
-            ->where('majs_gen', '>=', $gen)
542
-            ->groupBy('majs_i_id', 'branch');
543
-
544
-        $consolidated_ancestors_branches = DB::table('maj_sosa')
545
-            ->fromSub($ancestors_branches, 'indi_branch')
546
-            ->select('i_id')
547
-            ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches')
548
-            ->groupBy('i_id');
549
-
550
-        return DB::table('maj_sosa')
551
-            ->rightJoinSub(
552
-                $consolidated_ancestors_branches,
553
-                'indi_branch_consolidated',
554
-                function (JoinClause $join) use ($gen): void {
555
-                    $join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id())
556
-                        ->where('maj_sosa.majs_user_id', '=', $this->user->id())
557
-                        ->where('branches', '>', 0)
558
-                        ->whereRaw('majs_sosa = POW(2, ? - 1) + branches - 1', [$gen]);
559
-                }
560
-            )
561
-            ->select(['branches', 'majs_i_id'])
562
-            ->selectRaw('COUNT(i_id) AS count_indi')
563
-            ->groupBy(['branches', 'majs_i_id'])
564
-            ->get()->keyBy('branches');
565
-    }
351
+		$ancestors_contributions_sum = DB::connection()->query()
352
+			->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs')
353
+			->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id'])
354
+			->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 {
358
+				$join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen')
359
+					->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id')
360
+					->where('sosa_low.majs_gedcom_id', '=', $this->tree->id())
361
+					->where('sosa_low.majs_user_id', '=', $this->user->id());
362
+			})
363
+			->whereNull('sosa_low.majs_sosa')
364
+			->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id',
365
+				'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']);
366
+
367
+		// Aggregate all generation roots to compute root and generation pedigree collapse
368
+		$pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum')
369
+			->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)')
370
+			->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots')  // Roots/horizontal collapse
371
+			->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse
372
+			->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id'])
373
+			->orderBy('gen')
374
+			->get();
375
+
376
+		$pedi_collapse_by_gen = [];
377
+		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
381
+			);
382
+		}
383
+		return $pedi_collapse_by_gen;
384
+	}
385
+
386
+	/**
387
+	 * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation.
388
+	 * Sosa 1 is of generation 1.
389
+	 *
390
+	 * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes,
391
+	 * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140
392
+	 * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0
393
+	 *
394
+	 * Format:
395
+	 *  - key : sosa number of the ancestor
396
+	 *  - values:
397
+	 *      - root_ancestor_id : ID of the ancestor
398
+	 *      - mean_gen_depth : Mean generation depth
399
+	 *      - stddev_gen_depth : Standard deviation of generation depth
400
+	 *
401
+	 * @param int $gen Sosa generation
402
+	 * @return Collection<int, \stdClass>
403
+	 */
404
+	public function generationDepthStatsAtGeneration(int $gen): Collection
405
+	{
406
+		if (!$this->isPdoSupported()) {
407
+			return collect();
408
+		}
409
+
410
+		$table_prefix = DB::connection()->getTablePrefix();
411
+		$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 {
417
+				// Link to sosa's father
418
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
419
+				->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
420
+				->where('sosa_fat.majs_user_id', '=', $this->user->id());
421
+			})
422
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
423
+				// Link to sosa's mother
424
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
425
+				->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
426
+				->where('sosa_mot.majs_user_id', '=', $this->user->id());
427
+			})
428
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
429
+			->where('sosa.majs_user_id', '=', $this->user->id())
430
+			->where('sosa.majs_gen', '>=', $gen)
431
+			->where(function (Builder $query): void {
432
+				$query->whereNull('sosa_fat.majs_i_id')
433
+					->orWhereNull('sosa_mot.majs_i_id');
434
+			})
435
+			->groupBy(['sosa.majs_gen', 'root_ancestor']);
436
+
437
+		return DB::table('maj_sosa AS sosa_list')
438
+			->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id'])
439
+			->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
443
+				' ) AS stddev_gen_depth')
444
+			->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void {
445
+				$join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor')
446
+					->where('sosa_list.majs_gedcom_id', '=', $this->tree->id())
447
+					->where('sosa_list.majs_user_id', '=', $this->user->id());
448
+			})
449
+			->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id'])
450
+			->orderBy('stats_by_gen.root_ancestor')
451
+			->get()->keyBy('root_ancestor_sosa');
452
+	}
453
+
454
+	/**
455
+	 * Return a collection of the most duplicated root Sosa ancestors.
456
+	 * The number of ancestors to return is limited by the parameter $limit.
457
+	 * If several individuals are tied when reaching the limit, none of them are returned,
458
+	 * which means that there can be less individuals returned than requested.
459
+	 *
460
+	 * Format:
461
+	 *  - value:
462
+	 *      - sosa_i_id : sosa individual
463
+	 *      - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times)
464
+	 *
465
+	 * @param int $limit
466
+	 * @return Collection<\stdClass>
467
+	 */
468
+	public function topMultipleAncestorsWithNoTies(int $limit): Collection
469
+	{
470
+		$table_prefix = DB::connection()->getTablePrefix();
471
+		$multiple_ancestors = DB::table('maj_sosa AS sosa')
472
+			->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 {
475
+				// Link to sosa's father
476
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
477
+					->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
478
+					->where('sosa_fat.majs_user_id', '=', $this->user->id());
479
+			})
480
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
481
+				// Link to sosa's mother
482
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
483
+				->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
484
+				->where('sosa_mot.majs_user_id', '=', $this->user->id());
485
+			})
486
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
487
+			->where('sosa.majs_user_id', '=', $this->user->id())
488
+			->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
489
+			->whereNull('sosa_mot.majs_sosa')
490
+			->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
493
+			->limit($limit + 1)     // We want to select one more than required, for ties
494
+			->get();
495
+
496
+		if ($multiple_ancestors->count() > $limit) {
497
+			$last_count = $multiple_ancestors->last()->sosa_count;
498
+			$multiple_ancestors = $multiple_ancestors->reject(
499
+				fn (stdClass $element): bool => $element->sosa_count ===  $last_count
500
+			);
501
+		}
502
+		return $multiple_ancestors;
503
+	}
504
+
505
+	/**
506
+	 * Return a computed array of statistics about the dispersion of ancestors across the ancestors
507
+	 * at a specified generation.
508
+	 *
509
+	 * Format:
510
+	 *  - key : rank of the ancestor in generation G for which exclusive ancestors have been found
511
+	 *          For instance 3 represent the maternal grand father
512
+	 *          0 is used for shared ancestors
513
+	 *  - values:
514
+	 *      - branches: same as key
515
+	 *      - majs_i_id: xref of the ancestor at rank key in generation G, or null for shared ancestors
516
+	 *      - count_indi: number of ancestors exclusively in the ancestors of the ancestor at rank key
517
+	 *
518
+	 * For instance a result at generation 3 could be :
519
+	 * [
520
+	 *  0 => { branches: 0, majs_i_id: X1, count_indi: 12 } -> 12 ancestors are shared by the grand-parents
521
+	 *  1 => { branches: 1, majs_i_id: X2, count_indi: 32 } -> 32 ancestors are exclusive to the paternal grand-father
522
+	 *  2 => { branches: 2, majs_i_id: X3, count_indi: 25 } -> 25 ancestors are exclusive to the paternal grand-mother
523
+	 *  3 => { branches: 3, majs_i_id: X4, count_indi: 12 } -> 12 ancestors are exclusive to the maternal grand-father
524
+	 *  4 => { branches: 4, majs_i_id: X5, count_indi: 30 } -> 30 ancestors are exclusive to the maternal grand-mother
525
+	 * ]
526
+	 *
527
+	 * @param int $gen
528
+	 * @return Collection<int, \stdClass>
529
+	 */
530
+	public function ancestorsDispersionForGeneration(int $gen): Collection
531
+	{
532
+		if (!$this->isPdoSupported()) {
533
+			return collect();
534
+		}
535
+
536
+		$ancestors_branches = DB::table('maj_sosa')
537
+			->select('majs_i_id AS i_id')
538
+			->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen])
539
+			->where('majs_gedcom_id', '=', $this->tree->id())
540
+			->where('majs_user_id', '=', $this->user->id())
541
+			->where('majs_gen', '>=', $gen)
542
+			->groupBy('majs_i_id', 'branch');
543
+
544
+		$consolidated_ancestors_branches = DB::table('maj_sosa')
545
+			->fromSub($ancestors_branches, 'indi_branch')
546
+			->select('i_id')
547
+			->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches')
548
+			->groupBy('i_id');
549
+
550
+		return DB::table('maj_sosa')
551
+			->rightJoinSub(
552
+				$consolidated_ancestors_branches,
553
+				'indi_branch_consolidated',
554
+				function (JoinClause $join) use ($gen): void {
555
+					$join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id())
556
+						->where('maj_sosa.majs_user_id', '=', $this->user->id())
557
+						->where('branches', '>', 0)
558
+						->whereRaw('majs_sosa = POW(2, ? - 1) + branches - 1', [$gen]);
559
+				}
560
+			)
561
+			->select(['branches', 'majs_i_id'])
562
+			->selectRaw('COUNT(i_id) AS count_indi')
563
+			->groupBy(['branches', 'majs_i_id'])
564
+			->get()->keyBy('branches');
565
+	}
566 566
 }
Please login to merge, or discard this patch.
Spacing   +58 added lines, -59 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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)
Please login to merge, or discard this patch.
app/Module/Sosa/Hooks/SosaIconHook.php 2 patches
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -27,52 +27,52 @@
 block discarded – undo
27 27
  */
28 28
 class SosaIconHook implements RecordNameTextExtenderInterface
29 29
 {
30
-    private ModuleInterface $module;
31
-    private SosaRecordsService $sosa_records_service;
30
+	private ModuleInterface $module;
31
+	private SosaRecordsService $sosa_records_service;
32 32
 
33
-    /**
34
-     * Constructor for SosaIconHook
35
-     *
36
-     * @param ModuleInterface $module
37
-     * @param SosaRecordsService $sosa_records_service
38
-     */
39
-    public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service)
40
-    {
41
-        $this->module = $module;
42
-        $this->sosa_records_service = $sosa_records_service;
43
-    }
33
+	/**
34
+	 * Constructor for SosaIconHook
35
+	 *
36
+	 * @param ModuleInterface $module
37
+	 * @param SosaRecordsService $sosa_records_service
38
+	 */
39
+	public function __construct(ModuleInterface $module, SosaRecordsService $sosa_records_service)
40
+	{
41
+		$this->module = $module;
42
+		$this->sosa_records_service = $sosa_records_service;
43
+	}
44 44
 
45
-    /**
46
-     * {@inheritDoc}
47
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module()
48
-     */
49
-    public function module(): ModuleInterface
50
-    {
51
-        return $this->module;
52
-    }
45
+	/**
46
+	 * {@inheritDoc}
47
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\HookInterface::module()
48
+	 */
49
+	public function module(): ModuleInterface
50
+	{
51
+		return $this->module;
52
+	}
53 53
 
54
-    /**
55
-     * {@inheritDoc}
56
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend()
57
-     */
58
-    public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
59
-    {
60
-        return '';
61
-    }
54
+	/**
55
+	 * {@inheritDoc}
56
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNamePrepend()
57
+	 */
58
+	public function recordNamePrepend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
59
+	{
60
+		return '';
61
+	}
62 62
 
63
-    /**
64
-     * {@inheritDoc}
65
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend()
66
-     */
67
-    public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
68
-    {
69
-        $current_user = Auth::check() ? Auth::user() : new DefaultUser();
70
-        if (
71
-            $record instanceof Individual &&
72
-            $this->sosa_records_service->isSosa($record->tree(), $current_user, $record)
73
-        ) {
74
-            return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]);
75
-        }
76
-        return '';
77
-    }
63
+	/**
64
+	 * {@inheritDoc}
65
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\RecordNameTextExtenderInterface::recordNameAppend()
66
+	 */
67
+	public function recordNameAppend(GedcomRecord $record, bool $use_long = false, string $size = ''): string
68
+	{
69
+		$current_user = Auth::check() ? Auth::user() : new DefaultUser();
70
+		if (
71
+			$record instanceof Individual &&
72
+			$this->sosa_records_service->isSosa($record->tree(), $current_user, $record)
73
+		) {
74
+			return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]);
75
+		}
76
+		return '';
77
+	}
78 78
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@
 block discarded – undo
71 71
             $record instanceof Individual &&
72 72
             $this->sosa_records_service->isSosa($record->tree(), $current_user, $record)
73 73
         ) {
74
-            return view($this->module->name() . '::icons/sosa', [ 'size_style' => $size ]);
74
+            return view($this->module->name().'::icons/sosa', ['size_style' => $size]);
75 75
         }
76 76
         return '';
77 77
     }
Please login to merge, or discard this patch.