Passed
Push — main ( c808ff...4e47c4 )
by Jonathan
13:05
created
app/Module/Certificates/CertificatesModule.php 1 patch
Indentation   +175 added lines, -175 removed lines patch added patch discarded remove patch
@@ -44,180 +44,180 @@
 block discarded – undo
44 44
  * Certificates Module.
45 45
  */
46 46
 class CertificatesModule extends AbstractModule implements
47
-    ModuleMyArtJaubInterface,
48
-    ModuleConfigInterface,
49
-    ModuleGlobalInterface,
50
-    ModuleListInterface,
51
-    ModuleHookSubscriberInterface
47
+	ModuleMyArtJaubInterface,
48
+	ModuleConfigInterface,
49
+	ModuleGlobalInterface,
50
+	ModuleListInterface,
51
+	ModuleHookSubscriberInterface
52 52
 {
53
-    use ModuleMyArtJaubTrait {
54
-        ModuleMyArtJaubTrait::boot as traitMajBoot;
55
-    }
56
-    use ModuleConfigTrait;
57
-    use ModuleGlobalTrait;
58
-    use ModuleListTrait;
59
-
60
-    /**
61
-     * {@inheritDoc}
62
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
63
-     */
64
-    public function title(): string
65
-    {
66
-        return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates');
67
-    }
68
-
69
-    /**
70
-     * {@inheritDoc}
71
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
72
-     */
73
-    public function description(): string
74
-    {
75
-        //phpcs:ignore Generic.Files.LineLength.TooLong
76
-        return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.');
77
-    }
78
-
79
-    /**
80
-     * {@inheritDoc}
81
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
82
-     */
83
-    public function boot(): void
84
-    {
85
-        $this->traitMajBoot();
86
-
87
-        Registry::elementFactory()->registerTags([
88
-            'FAM:SOUR:_ACT'     =>  new SourceCertificate(I18N::translate('Certificate'), $this),
89
-            'FAM:*:SOUR:_ACT'   =>  new SourceCertificate(I18N::translate('Certificate'), $this),
90
-            'INDI:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
91
-            'INDI:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this),
92
-            'OBJE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
93
-            'OBJE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this),
94
-            'NOTE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
95
-            'NOTE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this)
96
-        ]);
97
-
98
-        Registry::elementFactory()->registerSubTags([
99
-            'FAM:SOUR'      =>  [['_ACT', '0:1']],
100
-            'FAM:*:SOUR'    =>  [['_ACT', '0:1']],
101
-            'INDI:SOUR'     =>  [['_ACT', '0:1']],
102
-            'INDI:*:SOUR'   =>  [['_ACT', '0:1']],
103
-            'OBJE:SOUR'     =>  [['_ACT', '0:1']],
104
-            'OBJE:*:SOUR'   =>  [['_ACT', '0:1']],
105
-            'NOTE:SOUR'     =>  [['_ACT', '0:1']],
106
-            'NOTE:*:SOUR'   =>  [['_ACT', '0:1']]
107
-        ]);
108
-    }
109
-
110
-    /**
111
-     * {@inheritDoc}
112
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
113
-     */
114
-    public function loadRoutes($router): void
115
-    {
116
-        $router->attach('', '', static function (Map $router): void {
117
-
118
-            $router->attach('', '/module-maj/certificates', static function (Map $router): void {
119
-
120
-                $router->attach('', '/admin', static function (Map $router): void {
121
-
122
-                    $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class);
123
-                    $router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class)
124
-                        ->extras([
125
-                            'middleware' => [
126
-                                AuthManager::class,
127
-                            ],
128
-                        ]);
129
-                });
130
-
131
-                $router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class)
132
-                    ->extras([
133
-                        'middleware'            =>  [AuthTreePreference::class],
134
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
135
-                    ]);
136
-
137
-                $router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class)
138
-                    ->extras([
139
-                        'middleware'            =>  [AuthTreePreference::class],
140
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
141
-                    ]);
142
-
143
-                $router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
144
-
145
-                    $router->extras([
146
-                        'middleware'            =>  [AuthTreePreference::class],
147
-                        'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
148
-                    ]);
149
-
150
-                    $router->get(CertificatePage::class, '', CertificatePage::class);
151
-                    $router->get(CertificateImage::class, '/image', CertificateImage::class);
152
-                });
153
-            });
154
-        });
155
-    }
156
-
157
-    /**
158
-     * {@inheritDoc}
159
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
160
-     */
161
-    public function customModuleVersion(): string
162
-    {
163
-        return '2.1.3-v.1';
164
-    }
165
-
166
-    /**
167
-     * {@inheritDoc}
168
-     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
169
-     */
170
-    public function getConfigLink(): string
171
-    {
172
-        return route(AdminConfigPage::class);
173
-    }
174
-
175
-    /**
176
-     * {@inheritDoc}
177
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
178
-     */
179
-    public function headContent(): string
180
-    {
181
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
182
-    }
183
-
184
-    /**
185
-     * {@inheritDoc}
186
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
187
-     *
188
-     * @param array<bool|int|string|array<mixed>|null> $parameters
189
-     */
190
-    public function listUrl(Tree $tree, array $parameters = []): string
191
-    {
192
-        return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
193
-    }
194
-
195
-    /**
196
-     * {@inheritDoc}
197
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
198
-     */
199
-    public function listMenuClass(): string
200
-    {
201
-        return 'menu-maj-certificates';
202
-    }
203
-
204
-    /**
205
-     * {@inheritDoc}
206
-     * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
207
-     */
208
-    public function listIsEmpty(Tree $tree): bool
209
-    {
210
-        return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
211
-    }
212
-
213
-    /**
214
-     * {@inheritDoc}
215
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
216
-     */
217
-    public function listSubscribedHooks(): array
218
-    {
219
-        return [
220
-            app()->makeWith(SourceCertificateIconHook::class, ['module' => $this])
221
-        ];
222
-    }
53
+	use ModuleMyArtJaubTrait {
54
+		ModuleMyArtJaubTrait::boot as traitMajBoot;
55
+	}
56
+	use ModuleConfigTrait;
57
+	use ModuleGlobalTrait;
58
+	use ModuleListTrait;
59
+
60
+	/**
61
+	 * {@inheritDoc}
62
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
63
+	 */
64
+	public function title(): string
65
+	{
66
+		return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates');
67
+	}
68
+
69
+	/**
70
+	 * {@inheritDoc}
71
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
72
+	 */
73
+	public function description(): string
74
+	{
75
+		//phpcs:ignore Generic.Files.LineLength.TooLong
76
+		return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.');
77
+	}
78
+
79
+	/**
80
+	 * {@inheritDoc}
81
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
82
+	 */
83
+	public function boot(): void
84
+	{
85
+		$this->traitMajBoot();
86
+
87
+		Registry::elementFactory()->registerTags([
88
+			'FAM:SOUR:_ACT'     =>  new SourceCertificate(I18N::translate('Certificate'), $this),
89
+			'FAM:*:SOUR:_ACT'   =>  new SourceCertificate(I18N::translate('Certificate'), $this),
90
+			'INDI:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
91
+			'INDI:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this),
92
+			'OBJE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
93
+			'OBJE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this),
94
+			'NOTE:SOUR:_ACT'    =>  new SourceCertificate(I18N::translate('Certificate'), $this),
95
+			'NOTE:*:SOUR:_ACT'  =>  new SourceCertificate(I18N::translate('Certificate'), $this)
96
+		]);
97
+
98
+		Registry::elementFactory()->registerSubTags([
99
+			'FAM:SOUR'      =>  [['_ACT', '0:1']],
100
+			'FAM:*:SOUR'    =>  [['_ACT', '0:1']],
101
+			'INDI:SOUR'     =>  [['_ACT', '0:1']],
102
+			'INDI:*:SOUR'   =>  [['_ACT', '0:1']],
103
+			'OBJE:SOUR'     =>  [['_ACT', '0:1']],
104
+			'OBJE:*:SOUR'   =>  [['_ACT', '0:1']],
105
+			'NOTE:SOUR'     =>  [['_ACT', '0:1']],
106
+			'NOTE:*:SOUR'   =>  [['_ACT', '0:1']]
107
+		]);
108
+	}
109
+
110
+	/**
111
+	 * {@inheritDoc}
112
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
113
+	 */
114
+	public function loadRoutes($router): void
115
+	{
116
+		$router->attach('', '', static function (Map $router): void {
117
+
118
+			$router->attach('', '/module-maj/certificates', static function (Map $router): void {
119
+
120
+				$router->attach('', '/admin', static function (Map $router): void {
121
+
122
+					$router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class);
123
+					$router->post(AdminConfigAction::class, '/config/{tree}', AdminConfigAction::class)
124
+						->extras([
125
+							'middleware' => [
126
+								AuthManager::class,
127
+							],
128
+						]);
129
+				});
130
+
131
+				$router->get(AutoCompleteFile::class, '/autocomplete/file/{tree}/{query}', AutoCompleteFile::class)
132
+					->extras([
133
+						'middleware'            =>  [AuthTreePreference::class],
134
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
135
+					]);
136
+
137
+				$router->get(CertificatesList::class, '/list/{tree}{/cityobf}', CertificatesList::class)
138
+					->extras([
139
+						'middleware'            =>  [AuthTreePreference::class],
140
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
141
+					]);
142
+
143
+				$router->attach('', '/certificate/{tree}/{cid}', static function (Map $router): void {
144
+
145
+					$router->extras([
146
+						'middleware'            =>  [AuthTreePreference::class],
147
+						'permission_preference' =>  'MAJ_CERTIF_SHOW_CERT'
148
+					]);
149
+
150
+					$router->get(CertificatePage::class, '', CertificatePage::class);
151
+					$router->get(CertificateImage::class, '/image', CertificateImage::class);
152
+				});
153
+			});
154
+		});
155
+	}
156
+
157
+	/**
158
+	 * {@inheritDoc}
159
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
160
+	 */
161
+	public function customModuleVersion(): string
162
+	{
163
+		return '2.1.3-v.1';
164
+	}
165
+
166
+	/**
167
+	 * {@inheritDoc}
168
+	 * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
169
+	 */
170
+	public function getConfigLink(): string
171
+	{
172
+		return route(AdminConfigPage::class);
173
+	}
174
+
175
+	/**
176
+	 * {@inheritDoc}
177
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
178
+	 */
179
+	public function headContent(): string
180
+	{
181
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
182
+	}
183
+
184
+	/**
185
+	 * {@inheritDoc}
186
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listUrl()
187
+	 *
188
+	 * @param array<bool|int|string|array<mixed>|null> $parameters
189
+	 */
190
+	public function listUrl(Tree $tree, array $parameters = []): string
191
+	{
192
+		return route(CertificatesList::class, ['tree' => $tree->name() ] + $parameters);
193
+	}
194
+
195
+	/**
196
+	 * {@inheritDoc}
197
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listMenuClass()
198
+	 */
199
+	public function listMenuClass(): string
200
+	{
201
+		return 'menu-maj-certificates';
202
+	}
203
+
204
+	/**
205
+	 * {@inheritDoc}
206
+	 * @see \Fisharebest\Webtrees\Module\ModuleListInterface::listIsEmpty()
207
+	 */
208
+	public function listIsEmpty(Tree $tree): bool
209
+	{
210
+		return Auth::accessLevel($tree) > (int) $tree->getPreference('MAJ_CERTIF_SHOW_CERT', (string) Auth::PRIV_HIDE);
211
+	}
212
+
213
+	/**
214
+	 * {@inheritDoc}
215
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
216
+	 */
217
+	public function listSubscribedHooks(): array
218
+	{
219
+		return [
220
+			app()->makeWith(SourceCertificateIconHook::class, ['module' => $this])
221
+		];
222
+	}
223 223
 }
Please login to merge, or discard this patch.
app/Module/WelcomeBlock/Services/MatomoStatsService.php 1 patch
Indentation   +100 added lines, -100 removed lines patch added patch discarded remove patch
@@ -29,113 +29,113 @@
 block discarded – undo
29 29
  */
30 30
 class MatomoStatsService
31 31
 {
32
-    protected ?HandlerStack $handler = null;
32
+	protected ?HandlerStack $handler = null;
33 33
 
34
-    /**
35
-     * Set or get the http handler for the service
36
-     *
37
-     * @param HandlerStack $handler
38
-     * @return HandlerStack
39
-     */
40
-    public function httpHandler(HandlerStack $handler = null): HandlerStack
41
-    {
42
-        if ($this->handler === null) {
43
-            $this->handler = HandlerStack::create();
44
-        }
45
-        if ($handler !== null) {
46
-            $this->handler = $handler;
47
-        }
48
-        return $this->handler;
49
-    }
34
+	/**
35
+	 * Set or get the http handler for the service
36
+	 *
37
+	 * @param HandlerStack $handler
38
+	 * @return HandlerStack
39
+	 */
40
+	public function httpHandler(HandlerStack $handler = null): HandlerStack
41
+	{
42
+		if ($this->handler === null) {
43
+			$this->handler = HandlerStack::create();
44
+		}
45
+		if ($handler !== null) {
46
+			$this->handler = $handler;
47
+		}
48
+		return $this->handler;
49
+	}
50 50
 
51
-    /**
52
-     * Returns the number of visits for the current year (up to the day before).
53
-     * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
54
-     *
55
-     * @param WelcomeBlockModule $module
56
-     * @param int $block_id
57
-     * @return int|NULL
58
-     */
59
-    public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
60
-    {
61
-        return Registry::cache()->file()->remember(
62
-            $module->name() . '-matomovisits-yearly-' . $block_id,
63
-            function () use ($module, $block_id): ?int {
64
-                $visits_year = $this->visits($module, $block_id, 'year');
65
-                if ($visits_year === null) {
66
-                    return null;
67
-                }
68
-                $visits_today = (int) $this->visits($module, $block_id, 'day');
51
+	/**
52
+	 * Returns the number of visits for the current year (up to the day before).
53
+	 * That statistic is cached for the day, to avoid unecessary calls to Matomo API.
54
+	 *
55
+	 * @param WelcomeBlockModule $module
56
+	 * @param int $block_id
57
+	 * @return int|NULL
58
+	 */
59
+	public function visitsThisYear(WelcomeBlockModule $module, int $block_id): ?int
60
+	{
61
+		return Registry::cache()->file()->remember(
62
+			$module->name() . '-matomovisits-yearly-' . $block_id,
63
+			function () use ($module, $block_id): ?int {
64
+				$visits_year = $this->visits($module, $block_id, 'year');
65
+				if ($visits_year === null) {
66
+					return null;
67
+				}
68
+				$visits_today = (int) $this->visits($module, $block_id, 'day');
69 69
 
70
-                return $visits_year - $visits_today;
71
-            },
72
-            Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
73
-        );
74
-    }
70
+				return $visits_year - $visits_today;
71
+			},
72
+			Carbon::now()->addDay()->startOfDay()->diffInSeconds(Carbon::now()) // Valid until midnight
73
+		);
74
+	}
75 75
 
76
-    /**
77
-     * Returns the number of visits for the current day.
78
-     *
79
-     * @param WelcomeBlockModule $module
80
-     * @param int $block_id
81
-     * @return int|NULL
82
-     */
83
-    public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
84
-    {
85
-        return Registry::cache()->array()->remember(
86
-            $module->name() . '-matomovisits-daily-' . $block_id,
87
-            function () use ($module, $block_id): ?int {
88
-                return $this->visits($module, $block_id, 'day');
89
-            }
90
-        );
91
-    }
76
+	/**
77
+	 * Returns the number of visits for the current day.
78
+	 *
79
+	 * @param WelcomeBlockModule $module
80
+	 * @param int $block_id
81
+	 * @return int|NULL
82
+	 */
83
+	public function visitsToday(WelcomeBlockModule $module, int $block_id): ?int
84
+	{
85
+		return Registry::cache()->array()->remember(
86
+			$module->name() . '-matomovisits-daily-' . $block_id,
87
+			function () use ($module, $block_id): ?int {
88
+				return $this->visits($module, $block_id, 'day');
89
+			}
90
+		);
91
+	}
92 92
 
93
-    /**
94
-     * Invoke the Matomo API to retrieve the number of visits over a period.
95
-     *
96
-     * @param WelcomeBlockModule $module
97
-     * @param int $block_id
98
-     * @param string $period
99
-     * @return int|NULL
100
-     */
101
-    protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
102
-    {
103
-        $settings = $module->matomoSettings($block_id);
93
+	/**
94
+	 * Invoke the Matomo API to retrieve the number of visits over a period.
95
+	 *
96
+	 * @param WelcomeBlockModule $module
97
+	 * @param int $block_id
98
+	 * @param string $period
99
+	 * @return int|NULL
100
+	 */
101
+	protected function visits(WelcomeBlockModule $module, int $block_id, string $period): ?int
102
+	{
103
+		$settings = $module->matomoSettings($block_id);
104 104
 
105
-        if (
106
-            $settings['matomo_enabled'] === true
107
-            && mb_strlen($settings['matomo_url']) > 0
108
-            && mb_strlen($settings['matomo_token']) > 0
109
-            && $settings['matomo_siteid'] > 0
110
-        ) {
111
-            try {
112
-                $http_client = new Client([
113
-                    RequestOptions::TIMEOUT => 30,
114
-                    'handler'   => $this->handler
115
-                ]);
105
+		if (
106
+			$settings['matomo_enabled'] === true
107
+			&& mb_strlen($settings['matomo_url']) > 0
108
+			&& mb_strlen($settings['matomo_token']) > 0
109
+			&& $settings['matomo_siteid'] > 0
110
+		) {
111
+			try {
112
+				$http_client = new Client([
113
+					RequestOptions::TIMEOUT => 30,
114
+					'handler'   => $this->handler
115
+				]);
116 116
 
117
-                $response = $http_client->get($settings['matomo_url'], [
118
-                    'query' =>  [
119
-                        'module'    =>  'API',
120
-                        'method'    =>  'VisitsSummary.getVisits',
121
-                        'idSite'    =>  $settings['matomo_siteid'],
122
-                        'period'    =>  $period,
123
-                        'date'      =>  'today',
124
-                        'token_auth' =>  $settings['matomo_token'],
125
-                        'format'    =>  'json'
126
-                    ]
127
-                ]);
117
+				$response = $http_client->get($settings['matomo_url'], [
118
+					'query' =>  [
119
+						'module'    =>  'API',
120
+						'method'    =>  'VisitsSummary.getVisits',
121
+						'idSite'    =>  $settings['matomo_siteid'],
122
+						'period'    =>  $period,
123
+						'date'      =>  'today',
124
+						'token_auth' =>  $settings['matomo_token'],
125
+						'format'    =>  'json'
126
+					]
127
+				]);
128 128
 
129
-                if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
130
-                    $result = json_decode((string) $response->getBody(), true)['value'] ?? null;
131
-                    if ($result !== null) {
132
-                        return (int)$result;
133
-                    }
134
-                }
135
-            } catch (GuzzleException $ex) {
136
-            }
137
-        }
129
+				if ($response->getStatusCode() === StatusCodeInterface::STATUS_OK) {
130
+					$result = json_decode((string) $response->getBody(), true)['value'] ?? null;
131
+					if ($result !== null) {
132
+						return (int)$result;
133
+					}
134
+				}
135
+			} catch (GuzzleException $ex) {
136
+			}
137
+		}
138 138
 
139
-        return null;
140
-    }
139
+		return null;
140
+	}
141 141
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/PlacesReferenceTableService.php 1 patch
Indentation   +79 added lines, -79 removed lines patch added patch discarded remove patch
@@ -21,91 +21,91 @@
 block discarded – undo
21 21
  */
22 22
 class PlacesReferenceTableService
23 23
 {
24
-    /**
25
-     * Mapping format placeholder tags => table column names
26
-     * @var array<string, string>
27
-     */
28
-    private const COLUMN_MAPPING = [
29
-        'name'  =>  'majgr_place_name',
30
-        'id'    =>  'majgr_place_admin_id',
31
-        'zip'   =>  'majgr_place_zip',
32
-        'gov'   =>  'majgr_place_gov_id',
33
-        'mls'   =>  'majgr_place_mls_id'
34
-    ];
24
+	/**
25
+	 * Mapping format placeholder tags => table column names
26
+	 * @var array<string, string>
27
+	 */
28
+	private const COLUMN_MAPPING = [
29
+		'name'  =>  'majgr_place_name',
30
+		'id'    =>  'majgr_place_admin_id',
31
+		'zip'   =>  'majgr_place_zip',
32
+		'gov'   =>  'majgr_place_gov_id',
33
+		'mls'   =>  'majgr_place_mls_id'
34
+	];
35 35
 
36
-    /**
37
-     * Get the formatted target mapping value of a place defined by a source format.
38
-     *
39
-     * @param string $source
40
-     * @param string $source_format
41
-     * @param string $target_format
42
-     * @return string|NULL
43
-     */
44
-    public function targetId(string $source, string $source_format, string $target_format): ?string
45
-    {
46
-        // Extract parts for the WHERE clause
47
-        $source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format);
48
-        $source_parts = preg_split('/[{}]/i', $source_format);
49
-        if ($source_parts === false) {
50
-            return null;
51
-        }
52
-        $source_parts = array_map(function (string $part): string {
53
-            if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54
-                return $this->columnName($column_id[1]);
55
-            }
56
-            return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57
-        }, array_filter($source_parts));
58
-        $source_parts[] = "'%'";
59
-        $concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
36
+	/**
37
+	 * Get the formatted target mapping value of a place defined by a source format.
38
+	 *
39
+	 * @param string $source
40
+	 * @param string $source_format
41
+	 * @param string $target_format
42
+	 * @return string|NULL
43
+	 */
44
+	public function targetId(string $source, string $source_format, string $target_format): ?string
45
+	{
46
+		// Extract parts for the WHERE clause
47
+		$source_format = str_replace(['{', '}'], ['{#', '#}'], $source_format);
48
+		$source_parts = preg_split('/[{}]/i', $source_format);
49
+		if ($source_parts === false) {
50
+			return null;
51
+		}
52
+		$source_parts = array_map(function (string $part): string {
53
+			if (preg_match('/^#([^#]+)#$/i', $part, $column_id) === 1) {
54
+				return $this->columnName($column_id[1]);
55
+			}
56
+			return $this->sanitizeString(str_replace(['?', '*'], ['_', '%'], $part));
57
+		}, array_filter($source_parts));
58
+		$source_parts[] = "'%'";
59
+		$concat_statement = 'CONCAT(' . implode(', ', $source_parts) . ')';
60 60
 
61
-        // Extract columns used in target
62
-        $columns = [];
63
-        if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) {
64
-            $columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1])));
65
-        }
61
+		// Extract columns used in target
62
+		$columns = [];
63
+		if (preg_match_all('/{(.*?)}/i', $target_format, $columns_select) === 1) {
64
+			$columns = array_unique(array_filter(array_map(fn($id) => $this->columnName($id), $columns_select[1])));
65
+		}
66 66
 
67
-        // Get the mapping
68
-        $rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69
-            ->select($columns)
70
-            ->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
71
-            ->get();
67
+		// Get the mapping
68
+		$rows = DB::table('maj_geodata_ref')  //DB::table('maj_geodata_ref')
69
+			->select($columns)
70
+			->whereRaw($this->sanitizeString($source) . " LIKE " . $concat_statement)
71
+			->get();
72 72
 
73
-        // Format the output ID
74
-        if ($rows->count() === 0) {
75
-            return null;
76
-        }
73
+		// Format the output ID
74
+		if ($rows->count() === 0) {
75
+			return null;
76
+		}
77 77
 
78
-        $mapping = (array) $rows->first();
79
-        if (count($columns_select) === 0) {
80
-            return $target_format;
81
-        }
78
+		$mapping = (array) $rows->first();
79
+		if (count($columns_select) === 0) {
80
+			return $target_format;
81
+		}
82 82
 
83
-        return str_replace(
84
-            array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
85
-            array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
86
-            $target_format
87
-        );
88
-    }
83
+		return str_replace(
84
+			array_map(fn($tag) => '{' . $tag . '}', $columns_select[1]),
85
+			array_map(fn($tag) => $mapping[$this->columnName($tag)] ?? '', $columns_select[1]),
86
+			$target_format
87
+		);
88
+	}
89 89
 
90
-    /**
91
-     * Get the column name for a format placeholder tag
92
-     *
93
-     * @param string $placeholder
94
-     * @return string
95
-     */
96
-    private function columnName(string $placeholder): string
97
-    {
98
-        return self::COLUMN_MAPPING[$placeholder] ?? '';
99
-    }
90
+	/**
91
+	 * Get the column name for a format placeholder tag
92
+	 *
93
+	 * @param string $placeholder
94
+	 * @return string
95
+	 */
96
+	private function columnName(string $placeholder): string
97
+	{
98
+		return self::COLUMN_MAPPING[$placeholder] ?? '';
99
+	}
100 100
 
101
-    /**
102
-     * Sanitize string for use in a SQL query.
103
-     *
104
-     * @param string $string
105
-     * @return string
106
-     */
107
-    private function sanitizeString(string $string): string
108
-    {
109
-        return DB::connection()->getPdo()->quote($string);
110
-    }
101
+	/**
102
+	 * Sanitize string for use in a SQL query.
103
+	 *
104
+	 * @param string $string
105
+	 * @return string
106
+	 */
107
+	private function sanitizeString(string $string): string
108
+	{
109
+		return DB::connection()->getPdo()->quote($string);
110
+	}
111 111
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Services/SosaStatisticsService.php 1 patch
Indentation   +528 added lines, -528 removed lines patch added patch discarded remove patch
@@ -29,539 +29,539 @@
 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
-        $denom = $row->n * $row->sum_x2 - pow($row->sum_x, 2);
155
-        return ((int) $row->n === 0 || $denom === 0) ? 0 :
156
-            -($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / $denom;
157
-    }
158
-
159
-    /**
160
-     * Get the statistic array detailed by generation.
161
-     * Statistics for each generation are:
162
-     *  - The number of Sosa in generation
163
-     *  - The number of Sosa up to generation
164
-     *  - The number of distinct Sosa up to generation
165
-     *  - The year of the first birth in generation
166
-     *  - The year of the first estimated birth in generation
167
-     *  - The year of the last birth in generation
168
-     *  - The year of the last estimated birth in generation
169
-     *  - The average year of birth in generation
170
-     *
171
-     * @return array<int, array<string, int|null>> Statistics array
172
-     */
173
-    public function statisticsByGenerations(): array
174
-    {
175
-        $stats_by_gen = $this->statisticsByGenerationBasicData();
176
-        $cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData();
177
-
178
-        $statistics_by_gen = [];
179
-        foreach ($stats_by_gen as $gen => $stats_gen) {
180
-            $statistics_by_gen[(int) $stats_gen->gen] = array(
181
-                'sosaCount'             =>  (int) $stats_gen->total_sosa,
182
-                'sosaTotalCount'        =>  (int) $cumul_stats_by_gen[$gen]->total_cumul,
183
-                'diffSosaTotalCount'    =>  (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul,
184
-                'firstBirth'            =>  $stats_gen->first_year,
185
-                'firstEstimatedBirth'   =>  $stats_gen->first_est_year,
186
-                'lastBirth'             =>  $stats_gen->last_year,
187
-                'lastEstimatedBirth'    =>  $stats_gen->last_est_year
188
-            );
189
-        }
190
-
191
-        return $statistics_by_gen;
192
-    }
193
-
194
-    /**
195
-     * Returns the basic statistics data by generation.
196
-     *
197
-     * @return Collection<int, \stdClass>
198
-     */
199
-    private function statisticsByGenerationBasicData(): Collection
200
-    {
201
-        return DB::table('maj_sosa')
202
-            ->where('majs_gedcom_id', '=', $this->tree->id())
203
-            ->where('majs_user_id', '=', $this->user->id())
204
-            ->groupBy('majs_gen')
205
-            ->orderBy('majs_gen', 'asc')
206
-            ->select('majs_gen AS gen')
207
-            ->selectRaw('COUNT(majs_sosa) AS total_sosa')
208
-            ->selectRaw('MIN(majs_birth_year) AS first_year')
209
-            ->selectRaw('MIN(majs_birth_year_est) AS first_est_year')
210
-            ->selectRaw('MAX(majs_birth_year) AS last_year')
211
-            ->selectRaw('MAX(majs_birth_year_est) AS last_est_year')
212
-            ->get()->keyBy('gen');
213
-    }
214
-
215
-    /**
216
-     * Returns the cumulative statistics data by generation
217
-     *
218
-     * @return Collection<int, \stdClass>
219
-     */
220
-    private function statisticsByGenerationCumulativeData(): Collection
221
-    {
222
-        $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
223
-            ->where('majs_gedcom_id', '=', $this->tree->id())
224
-            ->where('majs_user_id', '=', $this->user->id());
225
-
226
-        return DB::table('maj_sosa')
227
-            ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
228
-                $join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen')
229
-                ->where('majs_gedcom_id', '=', $this->tree->id())
230
-                ->where('majs_user_id', '=', $this->user->id());
231
-            })
232
-            ->groupBy('list_gen.majs_gen')
233
-            ->select('list_gen.majs_gen AS gen')
234
-            ->selectRaw('COUNT(majs_i_id) AS total_cumul')
235
-            ->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul')
236
-            ->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple')
237
-            ->get()->keyBy('gen');
238
-    }
239
-
240
-    /**
241
-     * Returns the pedigree collapse improved calculation by generation.
242
-     *
243
-     * Format:
244
-     *  - key : generation
245
-     *  - values:
246
-     *      - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation
247
-     *      - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation
248
-     *
249
-     * @return array<int, array<string, float>>
250
-     */
251
-    public function pedigreeCollapseByGenerationData(): array
252
-    {
253
-        if (!$this->isPdoSupported()) {
254
-            return [];
255
-        }
256
-
257
-        $table_prefix = DB::connection()->getTablePrefix();
258
-
259
-        $list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
260
-            ->where('majs_gedcom_id', '=', $this->tree->id())
261
-            ->where('majs_user_id', '=', $this->user->id());
262
-
263
-        /* Compute the contributions of nodes of previous generations to the current generation */
264
-        $root_ancestors_contributions = DB::table('maj_sosa AS sosa')
265
-            ->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
266
-            ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
267
-            ->selectRaw(
268
-                '(CASE ' .
269
-                    ' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' .
270
-                    ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' .
271
-                    ' ELSE 0 ' .
272
-                ' END)' .
273
-                ' + (CASE ' .
274
-                    ' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' .
275
-                    ' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' .
276
-                    ' ELSE 0 ' .
277
-                ' END) contrib'
278
-            )
279
-            ->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
280
-                $join->on('sosa.majs_gen', '<', 'list_gen.majs_gen')
281
-                    ->where('majs_gedcom_id', '=', $this->tree->id())
282
-                    ->where('majs_user_id', '=', $this->user->id());
283
-            })
284
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
285
-                // Link to sosa's father
286
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
287
-                    ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
288
-                    ->where('sosa_fat.majs_user_id', '=', $this->user->id());
289
-            })
290
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
291
-                // Link to sosa's mother
292
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
293
-                    ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
294
-                    ->where('sosa_mot.majs_user_id', '=', $this->user->id());
295
-            })
296
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
297
-            ->where('sosa.majs_user_id', '=', $this->user->id())
298
-            ->where(function (Builder $query): void {
299
-                $query->whereNull('sosa_fat.majs_i_id')
300
-                ->orWhereNull('sosa_mot.majs_i_id');
301
-            });
302
-
303
-        /* 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
+		$denom = $row->n * $row->sum_x2 - pow($row->sum_x, 2);
155
+		return ((int) $row->n === 0 || $denom === 0) ? 0 :
156
+			-($row->n * $row->sum_xy - $row->sum_x * $row->sum_y) / $denom;
157
+	}
158
+
159
+	/**
160
+	 * Get the statistic array detailed by generation.
161
+	 * Statistics for each generation are:
162
+	 *  - The number of Sosa in generation
163
+	 *  - The number of Sosa up to generation
164
+	 *  - The number of distinct Sosa up to generation
165
+	 *  - The year of the first birth in generation
166
+	 *  - The year of the first estimated birth in generation
167
+	 *  - The year of the last birth in generation
168
+	 *  - The year of the last estimated birth in generation
169
+	 *  - The average year of birth in generation
170
+	 *
171
+	 * @return array<int, array<string, int|null>> Statistics array
172
+	 */
173
+	public function statisticsByGenerations(): array
174
+	{
175
+		$stats_by_gen = $this->statisticsByGenerationBasicData();
176
+		$cumul_stats_by_gen = $this->statisticsByGenerationCumulativeData();
177
+
178
+		$statistics_by_gen = [];
179
+		foreach ($stats_by_gen as $gen => $stats_gen) {
180
+			$statistics_by_gen[(int) $stats_gen->gen] = array(
181
+				'sosaCount'             =>  (int) $stats_gen->total_sosa,
182
+				'sosaTotalCount'        =>  (int) $cumul_stats_by_gen[$gen]->total_cumul,
183
+				'diffSosaTotalCount'    =>  (int) $cumul_stats_by_gen[$gen]->total_distinct_cumul,
184
+				'firstBirth'            =>  $stats_gen->first_year,
185
+				'firstEstimatedBirth'   =>  $stats_gen->first_est_year,
186
+				'lastBirth'             =>  $stats_gen->last_year,
187
+				'lastEstimatedBirth'    =>  $stats_gen->last_est_year
188
+			);
189
+		}
190
+
191
+		return $statistics_by_gen;
192
+	}
193
+
194
+	/**
195
+	 * Returns the basic statistics data by generation.
196
+	 *
197
+	 * @return Collection<int, \stdClass>
198
+	 */
199
+	private function statisticsByGenerationBasicData(): Collection
200
+	{
201
+		return DB::table('maj_sosa')
202
+			->where('majs_gedcom_id', '=', $this->tree->id())
203
+			->where('majs_user_id', '=', $this->user->id())
204
+			->groupBy('majs_gen')
205
+			->orderBy('majs_gen', 'asc')
206
+			->select('majs_gen AS gen')
207
+			->selectRaw('COUNT(majs_sosa) AS total_sosa')
208
+			->selectRaw('MIN(majs_birth_year) AS first_year')
209
+			->selectRaw('MIN(majs_birth_year_est) AS first_est_year')
210
+			->selectRaw('MAX(majs_birth_year) AS last_year')
211
+			->selectRaw('MAX(majs_birth_year_est) AS last_est_year')
212
+			->get()->keyBy('gen');
213
+	}
214
+
215
+	/**
216
+	 * Returns the cumulative statistics data by generation
217
+	 *
218
+	 * @return Collection<int, \stdClass>
219
+	 */
220
+	private function statisticsByGenerationCumulativeData(): Collection
221
+	{
222
+		$list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
223
+			->where('majs_gedcom_id', '=', $this->tree->id())
224
+			->where('majs_user_id', '=', $this->user->id());
225
+
226
+		return DB::table('maj_sosa')
227
+			->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
228
+				$join->on('maj_sosa.majs_gen', '<=', 'list_gen.majs_gen')
229
+				->where('majs_gedcom_id', '=', $this->tree->id())
230
+				->where('majs_user_id', '=', $this->user->id());
231
+			})
232
+			->groupBy('list_gen.majs_gen')
233
+			->select('list_gen.majs_gen AS gen')
234
+			->selectRaw('COUNT(majs_i_id) AS total_cumul')
235
+			->selectRaw('COUNT(DISTINCT majs_i_id) AS total_distinct_cumul')
236
+			->selectRaw('1 - COUNT(DISTINCT majs_i_id) / COUNT(majs_i_id) AS pedi_collapse_simple')
237
+			->get()->keyBy('gen');
238
+	}
239
+
240
+	/**
241
+	 * Returns the pedigree collapse improved calculation by generation.
242
+	 *
243
+	 * Format:
244
+	 *  - key : generation
245
+	 *  - values:
246
+	 *      - pedi_collapse_roots : pedigree collapse of ancestor roots for the generation
247
+	 *      - pedi_collapse_xgen : pedigree cross-generation shrinkage for the generation
248
+	 *
249
+	 * @return array<int, array<string, float>>
250
+	 */
251
+	public function pedigreeCollapseByGenerationData(): array
252
+	{
253
+		if (!$this->isPdoSupported()) {
254
+			return [];
255
+		}
256
+
257
+		$table_prefix = DB::connection()->getTablePrefix();
258
+
259
+		$list_gen = DB::table('maj_sosa')->select('majs_gen')->distinct()
260
+			->where('majs_gedcom_id', '=', $this->tree->id())
261
+			->where('majs_user_id', '=', $this->user->id());
262
+
263
+		/* Compute the contributions of nodes of previous generations to the current generation */
264
+		$root_ancestors_contributions = DB::table('maj_sosa AS sosa')
265
+			->select(['list_gen.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
266
+			->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
267
+			->selectRaw(
268
+				'(CASE ' .
269
+					' WHEN ' . $table_prefix . 'sosa_fat.majs_i_id IS NULL' .
270
+					' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' .
271
+					' ELSE 0 ' .
272
+				' END)' .
273
+				' + (CASE ' .
274
+					' WHEN ' . $table_prefix . 'sosa_mot.majs_i_id IS NULL' .
275
+					' THEN POWER(2, ' . $table_prefix . 'list_gen.majs_gen - ' . $table_prefix . 'sosa.majs_gen - 1)' .
276
+					' ELSE 0 ' .
277
+				' END) contrib'
278
+			)
279
+			->joinSub($list_gen, 'list_gen', function (JoinClause $join): void {
280
+				$join->on('sosa.majs_gen', '<', 'list_gen.majs_gen')
281
+					->where('majs_gedcom_id', '=', $this->tree->id())
282
+					->where('majs_user_id', '=', $this->user->id());
283
+			})
284
+			->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
285
+				// Link to sosa's father
286
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
287
+					->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
288
+					->where('sosa_fat.majs_user_id', '=', $this->user->id());
289
+			})
290
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
291
+				// Link to sosa's mother
292
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
293
+					->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
294
+					->where('sosa_mot.majs_user_id', '=', $this->user->id());
295
+			})
296
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
297
+			->where('sosa.majs_user_id', '=', $this->user->id())
298
+			->where(function (Builder $query): void {
299
+				$query->whereNull('sosa_fat.majs_i_id')
300
+				->orWhereNull('sosa_mot.majs_i_id');
301
+			});
302
+
303
+		/* Identify nodes in the generations with ancestors who are also in the same generation.
304 304
          * This is the vertical/generational collapse that will reduce the number or roots.
305 305
          */
306
-        $non_roots_ancestors = DB::table('maj_sosa AS sosa')
307
-            ->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa'])
308
-            ->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' .
309
-                ' AS full_ancestors')
310
-            ->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void {
311
-                $join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen')
312
-                    ->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' .
313
-                        $table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' .
314
-                        $table_prefix . 'sosa.majs_sosa')
315
-                    ->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id())
316
-                    ->where('sosa_anc.majs_user_id', '=', $this->user->id());
317
-            })
318
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
319
-            ->where('sosa.majs_user_id', '=', $this->user->id())
320
-            ->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void {
321
-                $query->from('maj_sosa AS sosa_gen')
322
-                ->select('sosa_gen.majs_i_id')->distinct()
323
-                ->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id())
324
-                ->where('sosa_gen.majs_user_id', '=', $this->user->id())
325
-                ->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen');
326
-            })
327
-            ->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id',
328
-                'sosa.majs_sosa', 'sosa.majs_i_id']);
329
-
330
-        /* Compute the contribution of the nodes in the generation,
306
+		$non_roots_ancestors = DB::table('maj_sosa AS sosa')
307
+			->select(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id', 'sosa.majs_sosa'])
308
+			->selectRaw('MAX(' . $table_prefix . 'sosa_anc.majs_sosa) - MIN(' . $table_prefix . 'sosa_anc.majs_sosa)' .
309
+				' AS full_ancestors')
310
+			->join('maj_sosa AS sosa_anc', function (JoinClause $join) use ($table_prefix): void {
311
+				$join->on('sosa.majs_gen', '<', 'sosa_anc.majs_gen')
312
+					->whereRaw('FLOOR(' . $table_prefix . 'sosa_anc.majs_sosa / POWER(2, ' .
313
+						$table_prefix . 'sosa_anc.majs_gen - ' . $table_prefix . 'sosa.majs_gen)) = ' .
314
+						$table_prefix . 'sosa.majs_sosa')
315
+					->where('sosa_anc.majs_gedcom_id', '=', $this->tree->id())
316
+					->where('sosa_anc.majs_user_id', '=', $this->user->id());
317
+			})
318
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
319
+			->where('sosa.majs_user_id', '=', $this->user->id())
320
+			->whereIn('sosa_anc.majs_i_id', function (Builder $query) use ($table_prefix): void {
321
+				$query->from('maj_sosa AS sosa_gen')
322
+				->select('sosa_gen.majs_i_id')->distinct()
323
+				->where('sosa_gen.majs_gedcom_id', '=', $this->tree->id())
324
+				->where('sosa_gen.majs_user_id', '=', $this->user->id())
325
+				->whereRaw($table_prefix . 'sosa_gen.majs_gen = ' . $table_prefix . 'sosa.majs_gen');
326
+			})
327
+			->groupBy(['sosa.majs_gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id',
328
+				'sosa.majs_sosa', 'sosa.majs_i_id']);
329
+
330
+		/* Compute the contribution of the nodes in the generation,
331 331
          * excluding the nodes with ancestors in the same generation.
332 332
          * Nodes with a parent missing are not excluded to cater for the missing one.
333 333
          */
334
-        $known_ancestors_contributions = DB::table('maj_sosa AS sosa')
335
-            ->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
336
-            ->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
337
-            ->selectRaw('1 AS contrib')
338
-            ->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void {
339
-                $join->on('sosa.majs_gen', '=', 'nonroot.majs_gen')
340
-                    ->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa')
341
-                    ->where('nonroot.full_ancestors', '>', 0)
342
-                    ->where('nonroot.majs_gedcom_id', '=', $this->tree->id())
343
-                    ->where('nonroot.majs_user_id', '=', $this->user->id());
344
-            })
345
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
346
-            ->where('sosa.majs_user_id', '=', $this->user->id())
347
-            ->whereNull('nonroot.majs_sosa');
348
-
349
-        /* Aggregate both queries, and calculate the sum of contributions by generation roots.
334
+		$known_ancestors_contributions = DB::table('maj_sosa AS sosa')
335
+			->select(['sosa.majs_gen AS gen', 'sosa.majs_gedcom_id', 'sosa.majs_user_id'])
336
+			->addSelect(['sosa.majs_i_id', 'sosa.majs_gen'])
337
+			->selectRaw('1 AS contrib')
338
+			->leftJoinSub($non_roots_ancestors, 'nonroot', function (JoinClause $join): void {
339
+				$join->on('sosa.majs_gen', '=', 'nonroot.majs_gen')
340
+					->on('sosa.majs_sosa', '=', 'nonroot.majs_sosa')
341
+					->where('nonroot.full_ancestors', '>', 0)
342
+					->where('nonroot.majs_gedcom_id', '=', $this->tree->id())
343
+					->where('nonroot.majs_user_id', '=', $this->user->id());
344
+			})
345
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
346
+			->where('sosa.majs_user_id', '=', $this->user->id())
347
+			->whereNull('nonroot.majs_sosa');
348
+
349
+		/* Aggregate both queries, and calculate the sum of contributions by generation roots.
350 350
          * Exclude as well nodes that already appear in lower generations, as their branche has already been reduced.
351 351
          */
352
-        $ancestors_contributions_sum = DB::connection()->query()
353
-            ->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs')
354
-            ->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id'])
355
-            ->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib'])
356
-            ->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' .
357
-                $table_prefix . 'sosa_contribs.contrib AS totalContrib')
358
-            ->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void {
359
-                $join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen')
360
-                    ->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id')
361
-                    ->where('sosa_low.majs_gedcom_id', '=', $this->tree->id())
362
-                    ->where('sosa_low.majs_user_id', '=', $this->user->id());
363
-            })
364
-            ->whereNull('sosa_low.majs_sosa')
365
-            ->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id',
366
-                'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']);
367
-
368
-        // Aggregate all generation roots to compute root and generation pedigree collapse
369
-        $pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum')
370
-            ->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)')
371
-            ->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots')  // Roots/horizontal collapse
372
-            ->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse
373
-            ->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id'])
374
-            ->orderBy('gen')
375
-            ->get();
376
-
377
-        $pedi_collapse_by_gen = [];
378
-        foreach ($pedi_collapse_coll as $collapse_gen) {
379
-            $pedi_collapse_by_gen[(int) $collapse_gen->gen] = array(
380
-                'pedi_collapse_roots'   =>  (float) $collapse_gen->pedi_collapse_roots,
381
-                'pedi_collapse_xgen'   =>  (float) $collapse_gen->pedi_collapse_xgen
382
-            );
383
-        }
384
-        return $pedi_collapse_by_gen;
385
-    }
386
-
387
-    /**
388
-     * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation.
389
-     * Sosa 1 is of generation 1.
390
-     *
391
-     * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes,
392
-     * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140
393
-     * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0
394
-     *
395
-     * Format:
396
-     *  - key : sosa number of the ancestor
397
-     *  - values:
398
-     *      - root_ancestor_id : ID of the ancestor
399
-     *      - mean_gen_depth : Mean generation depth
400
-     *      - stddev_gen_depth : Standard deviation of generation depth
401
-     *
402
-     * @param int $gen Sosa generation
403
-     * @return Collection<int, \stdClass>
404
-     */
405
-    public function generationDepthStatsAtGeneration(int $gen): Collection
406
-    {
407
-        if (!$this->isPdoSupported()) {
408
-            return collect();
409
-        }
410
-
411
-        $table_prefix = DB::connection()->getTablePrefix();
412
-        $missing_ancestors_by_gen = DB::table('maj_sosa AS sosa')
413
-            ->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
414
-            ->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
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 1 ELSE 0 END) AS full_root_count')  //@phpcs:ignore Generic.Files.LineLength.TooLong
416
-            ->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
417
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
418
-                // Link to sosa's father
419
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
420
-                ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
421
-                ->where('sosa_fat.majs_user_id', '=', $this->user->id());
422
-            })
423
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
424
-                // Link to sosa's mother
425
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
426
-                ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
427
-                ->where('sosa_mot.majs_user_id', '=', $this->user->id());
428
-            })
429
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
430
-            ->where('sosa.majs_user_id', '=', $this->user->id())
431
-            ->where('sosa.majs_gen', '>=', $gen)
432
-            ->where(function (Builder $query): void {
433
-                $query->whereNull('sosa_fat.majs_i_id')
434
-                    ->orWhereNull('sosa_mot.majs_i_id');
435
-            })
436
-            ->groupBy(['sosa.majs_gen', 'root_ancestor']);
437
-
438
-        return DB::table('maj_sosa AS sosa_list')
439
-            ->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id'])
440
-            ->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
441
-            ->selectRaw(' SQRT(' .
442
-                '   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
443
-                '   - 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
444
-                ' ) AS stddev_gen_depth')
445
-            ->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void {
446
-                $join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor')
447
-                    ->where('sosa_list.majs_gedcom_id', '=', $this->tree->id())
448
-                    ->where('sosa_list.majs_user_id', '=', $this->user->id());
449
-            })
450
-            ->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id'])
451
-            ->orderBy('stats_by_gen.root_ancestor')
452
-            ->get()->keyBy('root_ancestor_sosa');
453
-    }
454
-
455
-    /**
456
-     * Return a collection of the most duplicated root Sosa ancestors.
457
-     * The number of ancestors to return is limited by the parameter $limit.
458
-     * If several individuals are tied when reaching the limit, none of them are returned,
459
-     * which means that there can be less individuals returned than requested.
460
-     *
461
-     * Format:
462
-     *  - value:
463
-     *      - sosa_i_id : sosa individual
464
-     *      - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times)
465
-     *
466
-     * @param int $limit
467
-     * @return Collection<\stdClass>
468
-     */
469
-    public function topMultipleAncestorsWithNoTies(int $limit): Collection
470
-    {
471
-        $table_prefix = DB::connection()->getTablePrefix();
472
-        $multiple_ancestors = DB::table('maj_sosa AS sosa')
473
-            ->select('sosa.majs_i_id AS sosa_i_id')
474
-            ->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count')
475
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
476
-                // Link to sosa's father
477
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
478
-                    ->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
479
-                    ->where('sosa_fat.majs_user_id', '=', $this->user->id());
480
-            })
481
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
482
-                // Link to sosa's mother
483
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
484
-                ->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
485
-                ->where('sosa_mot.majs_user_id', '=', $this->user->id());
486
-            })
487
-            ->where('sosa.majs_gedcom_id', '=', $this->tree->id())
488
-            ->where('sosa.majs_user_id', '=', $this->user->id())
489
-            ->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
490
-            ->whereNull('sosa_mot.majs_sosa')
491
-            ->groupBy('sosa.majs_i_id')
492
-            ->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
493
-            ->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC')   //@phpcs:ignore Generic.Files.LineLength.TooLong
494
-            ->limit($limit + 1)     // We want to select one more than required, for ties
495
-            ->get();
496
-
497
-        if ($multiple_ancestors->count() > $limit) {
498
-            $last_count = $multiple_ancestors->last()->sosa_count;
499
-            $multiple_ancestors = $multiple_ancestors->reject(
500
-                fn (stdClass $element): bool => $element->sosa_count ===  $last_count
501
-            );
502
-        }
503
-        return $multiple_ancestors;
504
-    }
505
-
506
-    /**
507
-     * Return a computed array of statistics about the dispersion of ancestors across the ancestors
508
-     * at a specified generation.
509
-     *
510
-     * Format:
511
-     *  - key : rank of the ancestor in generation G for which exclusive ancestors have been found
512
-     *          For instance 3 represent the maternal grand father
513
-     *          0 is used for shared ancestors
514
-     *  - values:
515
-     *      - branches: same as key
516
-     *      - majs_i_id: xref of the ancestor at rank key in generation G, or null for shared ancestors
517
-     *      - count_indi: number of ancestors exclusively in the ancestors of the ancestor at rank key
518
-     *
519
-     * For instance a result at generation 3 could be :
520
-     * [
521
-     *  0 => { branches: 0, majs_i_id: X1, count_indi: 12 } -> 12 ancestors are shared by the grand-parents
522
-     *  1 => { branches: 1, majs_i_id: X2, count_indi: 32 } -> 32 ancestors are exclusive to the paternal grand-father
523
-     *  2 => { branches: 2, majs_i_id: X3, count_indi: 25 } -> 25 ancestors are exclusive to the paternal grand-mother
524
-     *  3 => { branches: 3, majs_i_id: X4, count_indi: 12 } -> 12 ancestors are exclusive to the maternal grand-father
525
-     *  4 => { branches: 4, majs_i_id: X5, count_indi: 30 } -> 30 ancestors are exclusive to the maternal grand-mother
526
-     * ]
527
-     *
528
-     * @param int $gen
529
-     * @return Collection<int, \stdClass>
530
-     */
531
-    public function ancestorsDispersionForGeneration(int $gen): Collection
532
-    {
533
-        if (!$this->isPdoSupported()) {
534
-            return collect();
535
-        }
536
-
537
-        $ancestors_branches = DB::table('maj_sosa')
538
-            ->select('majs_i_id AS i_id')
539
-            ->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen])
540
-            ->where('majs_gedcom_id', '=', $this->tree->id())
541
-            ->where('majs_user_id', '=', $this->user->id())
542
-            ->where('majs_gen', '>=', $gen)
543
-            ->groupBy('majs_i_id', 'branch');
544
-
545
-        $consolidated_ancestors_branches = DB::table('maj_sosa')
546
-            ->fromSub($ancestors_branches, 'indi_branch')
547
-            ->select('i_id')
548
-            ->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches')
549
-            ->groupBy('i_id');
550
-
551
-        return DB::table('maj_sosa')
552
-            ->rightJoinSub(
553
-                $consolidated_ancestors_branches,
554
-                'indi_branch_consolidated',
555
-                function (JoinClause $join) use ($gen): void {
556
-                    $join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id())
557
-                        ->where('maj_sosa.majs_user_id', '=', $this->user->id())
558
-                        ->where('branches', '>', 0)
559
-                        ->whereRaw('majs_sosa = POW(2, ? - 1) + branches - 1', [$gen]);
560
-                }
561
-            )
562
-            ->select(['branches', 'majs_i_id'])
563
-            ->selectRaw('COUNT(i_id) AS count_indi')
564
-            ->groupBy(['branches', 'majs_i_id'])
565
-            ->get()->keyBy('branches');
566
-    }
352
+		$ancestors_contributions_sum = DB::connection()->query()
353
+			->fromSub($root_ancestors_contributions->unionAll($known_ancestors_contributions), 'sosa_contribs')
354
+			->select(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id'])
355
+			->addSelect(['sosa_contribs.majs_i_id', 'sosa_contribs.contrib'])
356
+			->selectRaw('COUNT(' . $table_prefix . 'sosa_contribs.majs_i_id) * ' .
357
+				$table_prefix . 'sosa_contribs.contrib AS totalContrib')
358
+			->leftJoin('maj_sosa AS sosa_low', function (JoinClause $join): void {
359
+				$join->on('sosa_low.majs_gen', '<', 'sosa_contribs.majs_gen')
360
+					->on('sosa_low.majs_i_id', '=', 'sosa_contribs.majs_i_id')
361
+					->where('sosa_low.majs_gedcom_id', '=', $this->tree->id())
362
+					->where('sosa_low.majs_user_id', '=', $this->user->id());
363
+			})
364
+			->whereNull('sosa_low.majs_sosa')
365
+			->groupBy(['sosa_contribs.gen', 'sosa_contribs.majs_gedcom_id', 'sosa_contribs.majs_user_id',
366
+				'sosa_contribs.majs_i_id', 'sosa_contribs.contrib']);
367
+
368
+		// Aggregate all generation roots to compute root and generation pedigree collapse
369
+		$pedi_collapse_coll = DB::connection()->query()->fromSub($ancestors_contributions_sum, 'sosa_contribs_sum')
370
+			->select(['gen'])->selectRaw('SUM(contrib), SUM(totalContrib)')
371
+			->selectRaw('1 - SUM(contrib) / SUM(totalContrib) AS pedi_collapse_roots')  // Roots/horizontal collapse
372
+			->selectRaw('1 - SUM(totalContrib) / POWER ( 2, gen - 1) AS pedi_collapse_xgen') // Crossgeneration collapse
373
+			->groupBy(['gen', 'majs_gedcom_id', 'majs_user_id'])
374
+			->orderBy('gen')
375
+			->get();
376
+
377
+		$pedi_collapse_by_gen = [];
378
+		foreach ($pedi_collapse_coll as $collapse_gen) {
379
+			$pedi_collapse_by_gen[(int) $collapse_gen->gen] = array(
380
+				'pedi_collapse_roots'   =>  (float) $collapse_gen->pedi_collapse_roots,
381
+				'pedi_collapse_xgen'   =>  (float) $collapse_gen->pedi_collapse_xgen
382
+			);
383
+		}
384
+		return $pedi_collapse_by_gen;
385
+	}
386
+
387
+	/**
388
+	 * Return a Collection of the mean generation depth and deviation for all Sosa ancestors at a given generation.
389
+	 * Sosa 1 is of generation 1.
390
+	 *
391
+	 * Mean generation depth and deviation are calculated based on the works of Marie-Héléne Cazes and Pierre Cazes,
392
+	 * published in Population (French Edition), Vol. 51, No. 1 (Jan. - Feb., 1996), pp. 117-140
393
+	 * http://kintip.net/index.php?option=com_jdownloads&task=download.send&id=9&catid=4&m=0
394
+	 *
395
+	 * Format:
396
+	 *  - key : sosa number of the ancestor
397
+	 *  - values:
398
+	 *      - root_ancestor_id : ID of the ancestor
399
+	 *      - mean_gen_depth : Mean generation depth
400
+	 *      - stddev_gen_depth : Standard deviation of generation depth
401
+	 *
402
+	 * @param int $gen Sosa generation
403
+	 * @return Collection<int, \stdClass>
404
+	 */
405
+	public function generationDepthStatsAtGeneration(int $gen): Collection
406
+	{
407
+		if (!$this->isPdoSupported()) {
408
+			return collect();
409
+		}
410
+
411
+		$table_prefix = DB::connection()->getTablePrefix();
412
+		$missing_ancestors_by_gen = DB::table('maj_sosa AS sosa')
413
+			->selectRaw($table_prefix . 'sosa.majs_gen - ? AS majs_gen_norm', [$gen])
414
+			->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
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 1 ELSE 0 END) AS full_root_count')  //@phpcs:ignore Generic.Files.LineLength.TooLong
416
+			->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
417
+			->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
418
+				// Link to sosa's father
419
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
420
+				->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
421
+				->where('sosa_fat.majs_user_id', '=', $this->user->id());
422
+			})
423
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
424
+				// Link to sosa's mother
425
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
426
+				->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
427
+				->where('sosa_mot.majs_user_id', '=', $this->user->id());
428
+			})
429
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
430
+			->where('sosa.majs_user_id', '=', $this->user->id())
431
+			->where('sosa.majs_gen', '>=', $gen)
432
+			->where(function (Builder $query): void {
433
+				$query->whereNull('sosa_fat.majs_i_id')
434
+					->orWhereNull('sosa_mot.majs_i_id');
435
+			})
436
+			->groupBy(['sosa.majs_gen', 'root_ancestor']);
437
+
438
+		return DB::table('maj_sosa AS sosa_list')
439
+			->select(['stats_by_gen.root_ancestor AS root_ancestor_sosa', 'sosa_list.majs_i_id as root_ancestor_id'])
440
+			->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
441
+			->selectRaw(' SQRT(' .
442
+				'   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
443
+				'   - 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
444
+				' ) AS stddev_gen_depth')
445
+			->joinSub($missing_ancestors_by_gen, 'stats_by_gen', function (JoinClause $join): void {
446
+				$join->on('sosa_list.majs_sosa', '=', 'stats_by_gen.root_ancestor')
447
+					->where('sosa_list.majs_gedcom_id', '=', $this->tree->id())
448
+					->where('sosa_list.majs_user_id', '=', $this->user->id());
449
+			})
450
+			->groupBy(['stats_by_gen.root_ancestor', 'sosa_list.majs_i_id'])
451
+			->orderBy('stats_by_gen.root_ancestor')
452
+			->get()->keyBy('root_ancestor_sosa');
453
+	}
454
+
455
+	/**
456
+	 * Return a collection of the most duplicated root Sosa ancestors.
457
+	 * The number of ancestors to return is limited by the parameter $limit.
458
+	 * If several individuals are tied when reaching the limit, none of them are returned,
459
+	 * which means that there can be less individuals returned than requested.
460
+	 *
461
+	 * Format:
462
+	 *  - value:
463
+	 *      - sosa_i_id : sosa individual
464
+	 *      - sosa_count: number of duplications of the ancestor (e.g. 3 if it appears 3 times)
465
+	 *
466
+	 * @param int $limit
467
+	 * @return Collection<\stdClass>
468
+	 */
469
+	public function topMultipleAncestorsWithNoTies(int $limit): Collection
470
+	{
471
+		$table_prefix = DB::connection()->getTablePrefix();
472
+		$multiple_ancestors = DB::table('maj_sosa AS sosa')
473
+			->select('sosa.majs_i_id AS sosa_i_id')
474
+			->selectRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) AS sosa_count')
475
+			->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($table_prefix): void {
476
+				// Link to sosa's father
477
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
478
+					->where('sosa_fat.majs_gedcom_id', '=', $this->tree->id())
479
+					->where('sosa_fat.majs_user_id', '=', $this->user->id());
480
+			})
481
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($table_prefix): void {
482
+				// Link to sosa's mother
483
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
484
+				->where('sosa_mot.majs_gedcom_id', '=', $this->tree->id())
485
+				->where('sosa_mot.majs_user_id', '=', $this->user->id());
486
+			})
487
+			->where('sosa.majs_gedcom_id', '=', $this->tree->id())
488
+			->where('sosa.majs_user_id', '=', $this->user->id())
489
+			->whereNull('sosa_fat.majs_sosa')   // We keep only root individuals, i.e. those with no father or mother
490
+			->whereNull('sosa_mot.majs_sosa')
491
+			->groupBy('sosa.majs_i_id')
492
+			->havingRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) > 1')    // Limit to the duplicate sosas.
493
+			->orderByRaw('COUNT(' . $table_prefix . 'sosa.majs_sosa) DESC, MIN(' . $table_prefix . 'sosa.majs_sosa) ASC')   //@phpcs:ignore Generic.Files.LineLength.TooLong
494
+			->limit($limit + 1)     // We want to select one more than required, for ties
495
+			->get();
496
+
497
+		if ($multiple_ancestors->count() > $limit) {
498
+			$last_count = $multiple_ancestors->last()->sosa_count;
499
+			$multiple_ancestors = $multiple_ancestors->reject(
500
+				fn (stdClass $element): bool => $element->sosa_count ===  $last_count
501
+			);
502
+		}
503
+		return $multiple_ancestors;
504
+	}
505
+
506
+	/**
507
+	 * Return a computed array of statistics about the dispersion of ancestors across the ancestors
508
+	 * at a specified generation.
509
+	 *
510
+	 * Format:
511
+	 *  - key : rank of the ancestor in generation G for which exclusive ancestors have been found
512
+	 *          For instance 3 represent the maternal grand father
513
+	 *          0 is used for shared ancestors
514
+	 *  - values:
515
+	 *      - branches: same as key
516
+	 *      - majs_i_id: xref of the ancestor at rank key in generation G, or null for shared ancestors
517
+	 *      - count_indi: number of ancestors exclusively in the ancestors of the ancestor at rank key
518
+	 *
519
+	 * For instance a result at generation 3 could be :
520
+	 * [
521
+	 *  0 => { branches: 0, majs_i_id: X1, count_indi: 12 } -> 12 ancestors are shared by the grand-parents
522
+	 *  1 => { branches: 1, majs_i_id: X2, count_indi: 32 } -> 32 ancestors are exclusive to the paternal grand-father
523
+	 *  2 => { branches: 2, majs_i_id: X3, count_indi: 25 } -> 25 ancestors are exclusive to the paternal grand-mother
524
+	 *  3 => { branches: 3, majs_i_id: X4, count_indi: 12 } -> 12 ancestors are exclusive to the maternal grand-father
525
+	 *  4 => { branches: 4, majs_i_id: X5, count_indi: 30 } -> 30 ancestors are exclusive to the maternal grand-mother
526
+	 * ]
527
+	 *
528
+	 * @param int $gen
529
+	 * @return Collection<int, \stdClass>
530
+	 */
531
+	public function ancestorsDispersionForGeneration(int $gen): Collection
532
+	{
533
+		if (!$this->isPdoSupported()) {
534
+			return collect();
535
+		}
536
+
537
+		$ancestors_branches = DB::table('maj_sosa')
538
+			->select('majs_i_id AS i_id')
539
+			->selectRaw('FLOOR(majs_sosa / POW(2, (majs_gen - ?))) - POW(2, ? -1) + 1 AS branch', [$gen, $gen])
540
+			->where('majs_gedcom_id', '=', $this->tree->id())
541
+			->where('majs_user_id', '=', $this->user->id())
542
+			->where('majs_gen', '>=', $gen)
543
+			->groupBy('majs_i_id', 'branch');
544
+
545
+		$consolidated_ancestors_branches = DB::table('maj_sosa')
546
+			->fromSub($ancestors_branches, 'indi_branch')
547
+			->select('i_id')
548
+			->selectRaw('CASE WHEN COUNT(branch) > 1 THEN 0 ELSE MIN(branch) END AS branches')
549
+			->groupBy('i_id');
550
+
551
+		return DB::table('maj_sosa')
552
+			->rightJoinSub(
553
+				$consolidated_ancestors_branches,
554
+				'indi_branch_consolidated',
555
+				function (JoinClause $join) use ($gen): void {
556
+					$join->where('maj_sosa.majs_gedcom_id', '=', $this->tree->id())
557
+						->where('maj_sosa.majs_user_id', '=', $this->user->id())
558
+						->where('branches', '>', 0)
559
+						->whereRaw('majs_sosa = POW(2, ? - 1) + branches - 1', [$gen]);
560
+				}
561
+			)
562
+			->select(['branches', 'majs_i_id'])
563
+			->selectRaw('COUNT(i_id) AS count_indi')
564
+			->groupBy(['branches', 'majs_i_id'])
565
+			->get()->keyBy('branches');
566
+	}
567 567
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Http/RequestHandlers/MapAdapterDeleteAction.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -31,67 +31,67 @@
 block discarded – undo
31 31
  */
32 32
 class MapAdapterDeleteAction implements RequestHandlerInterface
33 33
 {
34
-    private ?GeoDispersionModule $module;
35
-    private MapAdapterDataService $mapadapter_data_service;
34
+	private ?GeoDispersionModule $module;
35
+	private MapAdapterDataService $mapadapter_data_service;
36 36
 
37
-    /**
38
-     * Constructor for MapAdapterDeleteAction Request Handler
39
-     *
40
-     * @param ModuleService $module_service
41
-     * @param MapAdapterDataService $mapadapter_data_service
42
-     */
43
-    public function __construct(ModuleService $module_service, MapAdapterDataService $mapadapter_data_service)
44
-    {
45
-        $this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
46
-        $this->mapadapter_data_service = $mapadapter_data_service;
47
-    }
37
+	/**
38
+	 * Constructor for MapAdapterDeleteAction Request Handler
39
+	 *
40
+	 * @param ModuleService $module_service
41
+	 * @param MapAdapterDataService $mapadapter_data_service
42
+	 */
43
+	public function __construct(ModuleService $module_service, MapAdapterDataService $mapadapter_data_service)
44
+	{
45
+		$this->module = $module_service->findByInterface(GeoDispersionModule::class)->first();
46
+		$this->mapadapter_data_service = $mapadapter_data_service;
47
+	}
48 48
 
49
-    /**
50
-     * {@inheritDoc}
51
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
-     */
53
-    public function handle(ServerRequestInterface $request): ResponseInterface
54
-    {
55
-        $tree = Validator::attributes($request)->tree();
49
+	/**
50
+	 * {@inheritDoc}
51
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
52
+	 */
53
+	public function handle(ServerRequestInterface $request): ResponseInterface
54
+	{
55
+		$tree = Validator::attributes($request)->tree();
56 56
 
57
-        if ($this->module === null) {
58
-            FlashMessages::addMessage(
59
-                I18N::translate('The attached module could not be found.'),
60
-                'danger'
61
-            );
62
-            return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
63
-        }
57
+		if ($this->module === null) {
58
+			FlashMessages::addMessage(
59
+				I18N::translate('The attached module could not be found.'),
60
+				'danger'
61
+			);
62
+			return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
63
+		}
64 64
 
65
-        $adapter_id = Validator::attributes($request)->integer('adapter_id', -1);
66
-        $map_adapter = $this->mapadapter_data_service->find($adapter_id);
65
+		$adapter_id = Validator::attributes($request)->integer('adapter_id', -1);
66
+		$map_adapter = $this->mapadapter_data_service->find($adapter_id);
67 67
 
68
-        if ($map_adapter === null) {
69
-            FlashMessages::addMessage(
70
-                I18N::translate('The map configuration with ID “%s” does not exist.', I18N::number($adapter_id)),
71
-                'danger'
72
-            );
73
-            return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
74
-        }
68
+		if ($map_adapter === null) {
69
+			FlashMessages::addMessage(
70
+				I18N::translate('The map configuration with ID “%s” does not exist.', I18N::number($adapter_id)),
71
+				'danger'
72
+			);
73
+			return Registry::responseFactory()->redirect(AdminConfigPage::class, ['tree' => $tree->name()]);
74
+		}
75 75
 
76
-        if ($this->mapadapter_data_service->delete($map_adapter) > 0) {
77
-            FlashMessages::addMessage(
78
-                I18N::translate('The map configuration has been successfully deleted.'),
79
-                'success'
80
-            );
81
-            //phpcs:ignore Generic.Files.LineLength.TooLong
82
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been deleted.');
83
-        } else {
84
-            FlashMessages::addMessage(
85
-                I18N::translate('An error occured while deleting the map configuration.'),
86
-                'danger'
87
-            );
88
-            //phpcs:ignore Generic.Files.LineLength.TooLong
89
-            Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be deleted. See error log.');
90
-        }
76
+		if ($this->mapadapter_data_service->delete($map_adapter) > 0) {
77
+			FlashMessages::addMessage(
78
+				I18N::translate('The map configuration has been successfully deleted.'),
79
+				'success'
80
+			);
81
+			//phpcs:ignore Generic.Files.LineLength.TooLong
82
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” has been deleted.');
83
+		} else {
84
+			FlashMessages::addMessage(
85
+				I18N::translate('An error occured while deleting the map configuration.'),
86
+				'danger'
87
+			);
88
+			//phpcs:ignore Generic.Files.LineLength.TooLong
89
+			Log::addConfigurationLog('Module ' . $this->module->title() . ' : Map Adapter “' . $map_adapter->id() . '” could not be deleted. See error log.');
90
+		}
91 91
 
92
-        return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [
93
-            'tree'      => $tree->name(),
94
-            'view_id'   => $map_adapter->geoAnalysisViewId()
95
-        ]);
96
-    }
92
+		return Registry::responseFactory()->redirect(GeoAnalysisViewEditPage::class, [
93
+			'tree'      => $tree->name(),
94
+			'view_id'   => $map_adapter->geoAnalysisViewId()
95
+		]);
96
+	}
97 97
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/GeoDispersionModule.php 1 patch
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -59,188 +59,188 @@
 block discarded – undo
59 59
  * Geographical Dispersion Module.
60 60
  */
61 61
 class GeoDispersionModule extends AbstractModule implements
62
-    ModuleMyArtJaubInterface,
63
-    ModuleChartInterface,
64
-    ModuleConfigInterface,
65
-    ModuleGlobalInterface,
66
-    ModuleGeoAnalysisProviderInterface,
67
-    ModulePlaceMapperProviderInterface
62
+	ModuleMyArtJaubInterface,
63
+	ModuleChartInterface,
64
+	ModuleConfigInterface,
65
+	ModuleGlobalInterface,
66
+	ModuleGeoAnalysisProviderInterface,
67
+	ModulePlaceMapperProviderInterface
68 68
 {
69
-    use ModuleMyArtJaubTrait {
70
-        boot as traitBoot;
71
-    }
72
-    use ModuleChartTrait;
73
-    use ModuleConfigTrait;
74
-    use ModuleGlobalTrait;
75
-
76
-    // How to update the database schema for this module
77
-    private const SCHEMA_TARGET_VERSION   = 3;
78
-    private const SCHEMA_SETTING_NAME     = 'MAJ_GEODISP_SCHEMA_VERSION';
79
-    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
80
-
81
-    /**
82
-     * {@inheritDoc}
83
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
84
-     */
85
-    public function title(): string
86
-    {
87
-        return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion');
88
-    }
89
-
90
-    /**
91
-     * {@inheritDoc}
92
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
93
-     */
94
-    public function description(): string
95
-    {
96
-        //phpcs:ignore Generic.Files.LineLength.TooLong
97
-        return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.');
98
-    }
99
-
100
-    /**
101
-     * {@inheritDoc}
102
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
103
-     */
104
-    public function boot(): void
105
-    {
106
-        $this->traitBoot();
107
-        app(MigrationService::class)->updateSchema(
108
-            self::SCHEMA_MIGRATION_PREFIX,
109
-            self::SCHEMA_SETTING_NAME,
110
-            self::SCHEMA_TARGET_VERSION
111
-        );
112
-    }
113
-
114
-    /**
115
-     * {@inheritDoc}
116
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
117
-     */
118
-    public function customModuleVersion(): string
119
-    {
120
-        return '2.1.3-v.2';
121
-    }
122
-
123
-    /**
124
-     * {@inheritDoc}
125
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
126
-     */
127
-    public function loadRoutes(Map $router): void
128
-    {
129
-        $router->attach('', '', static function (Map $router): void {
130
-
131
-            $router->attach('', '/module-maj/geodispersion', static function (Map $router): void {
132
-                $router->attach('', '/admin', static function (Map $router): void {
133
-                    $router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class);
134
-
135
-                    $router->attach('', '/analysis-views/{tree}', static function (Map $router): void {
136
-                        $router->tokens(['view_id' => '\d+', 'enable' => '[01]']);
137
-                        $router->extras([
138
-                            'middleware' => [
139
-                                AuthManager::class,
140
-                            ],
141
-                        ]);
142
-                        $router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class);
143
-
144
-                        $router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class);
145
-                        $router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class);
146
-                        $router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class);
147
-                        $router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class);
148
-                        //phpcs:disable Generic.Files.LineLength.TooLong
149
-                        $router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class);
150
-                        $router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class);
151
-                        //phpcs:enable
152
-                    });
153
-
154
-                    $router->attach('', '/map-adapters/{tree}', static function (Map $router): void {
155
-                        $router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']);
156
-                        $router->extras([
157
-                            'middleware' => [
158
-                                AuthManager::class,
159
-                            ],
160
-                        ]);
161
-
162
-                        $router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class);
163
-                        $router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class);
164
-                        $router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class);
165
-                        $router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class);
166
-                        //phpcs:disable Generic.Files.LineLength.TooLong
167
-                        $router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class);
168
-                        $router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class);
169
-                        $router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class);
170
-                        //phpcs:enable
171
-                    });
172
-
173
-                    //phpcs:ignore Generic.Files.LineLength.TooLong
174
-                    $router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class);
175
-                });
176
-
177
-                $router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class);
178
-
179
-                $router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void {
180
-                    $router->tokens(['view_id' => '\d+']);
181
-                    $router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class);
182
-                    $router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class);
183
-                });
184
-            });
185
-        });
186
-    }
187
-
188
-    public function getConfigLink(): string
189
-    {
190
-        return route(AdminConfigPage::class);
191
-    }
192
-
193
-    /**
194
-     * {@inheritDoc}
195
-     * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl()
196
-     *
197
-     * @param array<bool|int|string|array<mixed>|null> $parameters
198
-     */
199
-    public function chartUrl(Individual $individual, array $parameters = []): string
200
-    {
201
-        return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters);
202
-    }
203
-
204
-    /**
205
-     * {@inheritDoc}
206
-     * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass()
207
-     */
208
-    public function chartMenuClass(): string
209
-    {
210
-        return 'menu-maj-geodispersion';
211
-    }
212
-
213
-    /**
214
-     * {@inheritDoc}
215
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
216
-     */
217
-    public function headContent(): string
218
-    {
219
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
220
-    }
221
-
222
-    /**
223
-     * {@inheritDoc}
224
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers()
225
-     */
226
-    public function listPlaceMappers(): array
227
-    {
228
-        return [
229
-            CoordinatesPlaceMapper::class,
230
-            SimplePlaceMapper::class,
231
-            SimpleTopFilteredPlaceMapper::class
232
-        ];
233
-    }
234
-
235
-    /**
236
-     * {@inheritDoc}
237
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
238
-     */
239
-    public function listGeoAnalyses(): array
240
-    {
241
-        return [
242
-            AllEventsByCenturyGeoAnalysis::class,
243
-            AllEventsByTypeGeoAnalysis::class
244
-        ];
245
-    }
69
+	use ModuleMyArtJaubTrait {
70
+		boot as traitBoot;
71
+	}
72
+	use ModuleChartTrait;
73
+	use ModuleConfigTrait;
74
+	use ModuleGlobalTrait;
75
+
76
+	// How to update the database schema for this module
77
+	private const SCHEMA_TARGET_VERSION   = 3;
78
+	private const SCHEMA_SETTING_NAME     = 'MAJ_GEODISP_SCHEMA_VERSION';
79
+	private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
80
+
81
+	/**
82
+	 * {@inheritDoc}
83
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
84
+	 */
85
+	public function title(): string
86
+	{
87
+		return /* I18N: Name of the “GeoDispersion” module */ I18N::translate('Geographical dispersion');
88
+	}
89
+
90
+	/**
91
+	 * {@inheritDoc}
92
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
93
+	 */
94
+	public function description(): string
95
+	{
96
+		//phpcs:ignore Generic.Files.LineLength.TooLong
97
+		return /* I18N: Description of the “GeoDispersion” module */ I18N::translate('Perform and display geographical dispersion analyses.');
98
+	}
99
+
100
+	/**
101
+	 * {@inheritDoc}
102
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
103
+	 */
104
+	public function boot(): void
105
+	{
106
+		$this->traitBoot();
107
+		app(MigrationService::class)->updateSchema(
108
+			self::SCHEMA_MIGRATION_PREFIX,
109
+			self::SCHEMA_SETTING_NAME,
110
+			self::SCHEMA_TARGET_VERSION
111
+		);
112
+	}
113
+
114
+	/**
115
+	 * {@inheritDoc}
116
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
117
+	 */
118
+	public function customModuleVersion(): string
119
+	{
120
+		return '2.1.3-v.2';
121
+	}
122
+
123
+	/**
124
+	 * {@inheritDoc}
125
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
126
+	 */
127
+	public function loadRoutes(Map $router): void
128
+	{
129
+		$router->attach('', '', static function (Map $router): void {
130
+
131
+			$router->attach('', '/module-maj/geodispersion', static function (Map $router): void {
132
+				$router->attach('', '/admin', static function (Map $router): void {
133
+					$router->get(AdminConfigPage::class, '/config{/tree}', AdminConfigPage::class);
134
+
135
+					$router->attach('', '/analysis-views/{tree}', static function (Map $router): void {
136
+						$router->tokens(['view_id' => '\d+', 'enable' => '[01]']);
137
+						$router->extras([
138
+							'middleware' => [
139
+								AuthManager::class,
140
+							],
141
+						]);
142
+						$router->get(GeoAnalysisViewListData::class, '', GeoAnalysisViewListData::class);
143
+
144
+						$router->get(GeoAnalysisViewAddPage::class, '/add', GeoAnalysisViewAddPage::class);
145
+						$router->post(GeoAnalysisViewAddAction::class, '/add', GeoAnalysisViewAddAction::class);
146
+						$router->get(GeoAnalysisViewEditPage::class, '/{view_id}', GeoAnalysisViewEditPage::class);
147
+						$router->post(GeoAnalysisViewEditAction::class, '/{view_id}', GeoAnalysisViewEditAction::class);
148
+						//phpcs:disable Generic.Files.LineLength.TooLong
149
+						$router->get(GeoAnalysisViewStatusAction::class, '/{view_id}/status/{enable}', GeoAnalysisViewStatusAction::class);
150
+						$router->get(GeoAnalysisViewDeleteAction::class, '/{view_id}/delete', GeoAnalysisViewDeleteAction::class);
151
+						//phpcs:enable
152
+					});
153
+
154
+					$router->attach('', '/map-adapters/{tree}', static function (Map $router): void {
155
+						$router->tokens(['adapter_id' => '\d+', 'view_id' => '\d+']);
156
+						$router->extras([
157
+							'middleware' => [
158
+								AuthManager::class,
159
+							],
160
+						]);
161
+
162
+						$router->get(MapAdapterAddPage::class, '/add/{view_id}', MapAdapterAddPage::class);
163
+						$router->post(MapAdapterAddAction::class, '/add/{view_id}', MapAdapterAddAction::class);
164
+						$router->get(MapAdapterEditPage::class, '/{adapter_id}', MapAdapterEditPage::class);
165
+						$router->post(MapAdapterEditAction::class, '/{adapter_id}', MapAdapterEditAction::class);
166
+						//phpcs:disable Generic.Files.LineLength.TooLong
167
+						$router->get(MapAdapterDeleteAction::class, '/{adapter_id}/delete', MapAdapterDeleteAction::class);
168
+						$router->get(MapAdapterDeleteInvalidAction::class, '/delete-invalid/{view_id}', MapAdapterDeleteInvalidAction::class);
169
+						$router->get(MapAdapterMapperConfig::class, '/mapper/config{/adapter_id}', MapAdapterMapperConfig::class);
170
+						//phpcs:enable
171
+					});
172
+
173
+					//phpcs:ignore Generic.Files.LineLength.TooLong
174
+					$router->get(MapFeaturePropertyData::class, '/map/feature-properties{/map_id}', MapFeaturePropertyData::class);
175
+				});
176
+
177
+				$router->get(GeoAnalysisViewsList::class, '/list/{tree}', GeoAnalysisViewsList::class);
178
+
179
+				$router->attach('', '/analysisview/{tree}/{view_id}', static function (Map $router): void {
180
+					$router->tokens(['view_id' => '\d+']);
181
+					$router->get(GeoAnalysisViewPage::class, '', GeoAnalysisViewPage::class);
182
+					$router->get(GeoAnalysisViewTabs::class, '/tabs', GeoAnalysisViewTabs::class);
183
+				});
184
+			});
185
+		});
186
+	}
187
+
188
+	public function getConfigLink(): string
189
+	{
190
+		return route(AdminConfigPage::class);
191
+	}
192
+
193
+	/**
194
+	 * {@inheritDoc}
195
+	 * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartUrl()
196
+	 *
197
+	 * @param array<bool|int|string|array<mixed>|null> $parameters
198
+	 */
199
+	public function chartUrl(Individual $individual, array $parameters = []): string
200
+	{
201
+		return route(GeoAnalysisViewsList::class, ['tree' => $individual->tree()->name()] + $parameters);
202
+	}
203
+
204
+	/**
205
+	 * {@inheritDoc}
206
+	 * @see \Fisharebest\Webtrees\Module\ModuleChartInterface::chartMenuClass()
207
+	 */
208
+	public function chartMenuClass(): string
209
+	{
210
+		return 'menu-maj-geodispersion';
211
+	}
212
+
213
+	/**
214
+	 * {@inheritDoc}
215
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
216
+	 */
217
+	public function headContent(): string
218
+	{
219
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
220
+	}
221
+
222
+	/**
223
+	 * {@inheritDoc}
224
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModulePlaceMapperProviderInterface::listPlaceMappers()
225
+	 */
226
+	public function listPlaceMappers(): array
227
+	{
228
+		return [
229
+			CoordinatesPlaceMapper::class,
230
+			SimplePlaceMapper::class,
231
+			SimpleTopFilteredPlaceMapper::class
232
+		];
233
+	}
234
+
235
+	/**
236
+	 * {@inheritDoc}
237
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
238
+	 */
239
+	public function listGeoAnalyses(): array
240
+	{
241
+		return [
242
+			AllEventsByCenturyGeoAnalysis::class,
243
+			AllEventsByTypeGeoAnalysis::class
244
+		];
245
+	}
246 246
 }
Please login to merge, or discard this patch.
app/Module/GeoDispersion/Services/GeoAnalysisDataService.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -26,64 +26,64 @@
 block discarded – undo
26 26
  */
27 27
 class GeoAnalysisDataService
28 28
 {
29
-    /**
30
-     * Yields indviduals and family records for a specified tree.
31
-     *
32
-     * @param Tree $tree
33
-     * @return \Generator<\Fisharebest\Webtrees\GedcomRecord>
34
-     */
35
-    public function individualsAndFamilies(Tree $tree): Generator
36
-    {
37
-        yield from DB::table('individuals')
38
-            ->where('i_file', '=', $tree->id())
39
-            ->select(['individuals.*'])
40
-            ->get()
41
-            ->map(Registry::individualFactory()->mapper($tree))
42
-            ->filter(GedcomRecord::accessFilter())
43
-            ->all();
29
+	/**
30
+	 * Yields indviduals and family records for a specified tree.
31
+	 *
32
+	 * @param Tree $tree
33
+	 * @return \Generator<\Fisharebest\Webtrees\GedcomRecord>
34
+	 */
35
+	public function individualsAndFamilies(Tree $tree): Generator
36
+	{
37
+		yield from DB::table('individuals')
38
+			->where('i_file', '=', $tree->id())
39
+			->select(['individuals.*'])
40
+			->get()
41
+			->map(Registry::individualFactory()->mapper($tree))
42
+			->filter(GedcomRecord::accessFilter())
43
+			->all();
44 44
 
45
-        yield from DB::table('families')
46
-            ->where('f_file', '=', $tree->id())
47
-            ->select(['families.*'])
48
-            ->get()
49
-            ->map(Registry::familyFactory()->mapper($tree))
50
-            ->filter(GedcomRecord::accessFilter())
51
-            ->all();
52
-    }
45
+		yield from DB::table('families')
46
+			->where('f_file', '=', $tree->id())
47
+			->select(['families.*'])
48
+			->get()
49
+			->map(Registry::familyFactory()->mapper($tree))
50
+			->filter(GedcomRecord::accessFilter())
51
+			->all();
52
+	}
53 53
 
54
-    /**
55
-     * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest
56
-     * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first).
57
-     *
58
-     * {@internal The places are taken only from the individuals and families records.}
59
-     *
60
-     * @param Tree $tree
61
-     * @return array<int, string[]>
62
-     */
63
-    public function placeHierarchyExample(Tree $tree): array
64
-    {
65
-        $query_individuals = DB::table('individuals')
66
-            ->select(['i_gedcom AS g_gedcom'])
67
-            ->where('i_file', '=', $tree->id())
68
-            ->where('i_gedcom', 'like', '%2 PLAC %');
54
+	/**
55
+	 * Returns an example of the place hierarchy, from a place within the GEDCOM file, looking for the deepest
56
+	 * hierarchy found. The part order is reversed compared to the normal GEDCOM structure (largest first).
57
+	 *
58
+	 * {@internal The places are taken only from the individuals and families records.}
59
+	 *
60
+	 * @param Tree $tree
61
+	 * @return array<int, string[]>
62
+	 */
63
+	public function placeHierarchyExample(Tree $tree): array
64
+	{
65
+		$query_individuals = DB::table('individuals')
66
+			->select(['i_gedcom AS g_gedcom'])
67
+			->where('i_file', '=', $tree->id())
68
+			->where('i_gedcom', 'like', '%2 PLAC %');
69 69
 
70
-        $query_families = DB::table('families')
71
-            ->select(['f_gedcom AS g_gedcom'])
72
-            ->where('f_file', '=', $tree->id())
73
-            ->where('f_gedcom', 'like', '%2 PLAC %');
70
+		$query_families = DB::table('families')
71
+			->select(['f_gedcom AS g_gedcom'])
72
+			->where('f_file', '=', $tree->id())
73
+			->where('f_gedcom', 'like', '%2 PLAC %');
74 74
 
75
-        return $query_individuals->unionAll($query_families)
76
-            ->get()->pluck('g_gedcom')
77
-            ->flatMap(static function (string $gedcom): array {
78
-                preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches);
79
-                return $matches[1] ?? [];
80
-            })
81
-            ->sort(I18N::comparator())->reverse()
82
-            ->mapWithKeys(static function (string $place): array {
83
-                $place_array = array_reverse(array_filter(array_map('trim', explode(",", $place))));
84
-                return [ count($place_array) => $place_array ];
85
-            })
86
-            ->sortKeys()
87
-            ->last() ?? [];
88
-    }
75
+		return $query_individuals->unionAll($query_families)
76
+			->get()->pluck('g_gedcom')
77
+			->flatMap(static function (string $gedcom): array {
78
+				preg_match_all('/\n2 PLAC (.+)/', $gedcom, $matches);
79
+				return $matches[1] ?? [];
80
+			})
81
+			->sort(I18N::comparator())->reverse()
82
+			->mapWithKeys(static function (string $place): array {
83
+				$place_array = array_reverse(array_filter(array_map('trim', explode(",", $place))));
84
+				return [ count($place_array) => $place_array ];
85
+			})
86
+			->sortKeys()
87
+			->last() ?? [];
88
+	}
89 89
 }
Please login to merge, or discard this patch.
app/Module/MiscExtensions/MiscExtensionsModule.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -34,93 +34,93 @@
 block discarded – undo
34 34
  * Provide miscellaneous improvements to webtrees.
35 35
  */
36 36
 class MiscExtensionsModule extends AbstractModule implements
37
-    ModuleMyArtJaubInterface,
38
-    ModuleConfigInterface,
39
-    ModuleHookSubscriberInterface
37
+	ModuleMyArtJaubInterface,
38
+	ModuleConfigInterface,
39
+	ModuleHookSubscriberInterface
40 40
 {
41
-    use ModuleMyArtJaubTrait {
42
-        boot as traitBoot;
43
-    }
44
-    use ModuleConfigTrait;
45
-
46
-    /**
47
-     * {@inheritDoc}
48
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
49
-     */
50
-    public function title(): string
51
-    {
52
-        return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions');
53
-    }
54
-
55
-    /**
56
-     * {@inheritDoc}
57
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
58
-     */
59
-    public function description(): string
60
-    {
61
-        //phpcs:ignore Generic.Files.LineLength.TooLong
62
-        return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.');
63
-    }
64
-
65
-    /**
66
-     * {@inheritDoc}
67
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
68
-     */
69
-    public function boot(): void
70
-    {
71
-        $this->traitBoot();
72
-        View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy');
73
-
74
-        if ((int) $this->getPreference('MAJ_USE_LEGACY_XREF') === 1) {
75
-            Registry::xrefFactory(new LegacyXrefFactory());
76
-        }
77
-    }
78
-
79
-    /**
80
-     * {@inheritDoc}
81
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
82
-     */
83
-    public function loadRoutes(Map $router): void
84
-    {
85
-        $router->attach('', '', static function (Map $router): void {
86
-
87
-            $router->attach('', '/module-maj/misc', static function (Map $router): void {
88
-
89
-                $router->attach('', '/config/admin', static function (Map $router): void {
90
-
91
-                    $router->get(AdminConfigPage::class, '', AdminConfigPage::class);
92
-                    $router->post(AdminConfigAction::class, '', AdminConfigAction::class);
93
-                });
94
-            });
95
-        });
96
-    }
97
-
98
-    /**
99
-     * {@inheritDoc}
100
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
101
-     */
102
-    public function customModuleVersion(): string
103
-    {
104
-        return '2.1.3-v.2';
105
-    }
106
-
107
-    /**
108
-     * {@inheritDoc}
109
-     * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
110
-     */
111
-    public function getConfigLink(): string
112
-    {
113
-        return route(AdminConfigPage::class);
114
-    }
115
-
116
-    /**
117
-     * {@inheritDoc}
118
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
119
-     */
120
-    public function listSubscribedHooks(): array
121
-    {
122
-        return [
123
-            app()->makeWith(TitlesCardHook::class, [ 'module' => $this ])
124
-        ];
125
-    }
41
+	use ModuleMyArtJaubTrait {
42
+		boot as traitBoot;
43
+	}
44
+	use ModuleConfigTrait;
45
+
46
+	/**
47
+	 * {@inheritDoc}
48
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
49
+	 */
50
+	public function title(): string
51
+	{
52
+		return /* I18N: Name of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions');
53
+	}
54
+
55
+	/**
56
+	 * {@inheritDoc}
57
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
58
+	 */
59
+	public function description(): string
60
+	{
61
+		//phpcs:ignore Generic.Files.LineLength.TooLong
62
+		return /* I18N: Description of the “MiscExtensions” module */ I18N::translate('Miscellaneous extensions for webtrees.');
63
+	}
64
+
65
+	/**
66
+	 * {@inheritDoc}
67
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
68
+	 */
69
+	public function boot(): void
70
+	{
71
+		$this->traitBoot();
72
+		View::registerCustomView('::modules/privacy-policy/page', $this->name() . '::privacy-policy');
73
+
74
+		if ((int) $this->getPreference('MAJ_USE_LEGACY_XREF') === 1) {
75
+			Registry::xrefFactory(new LegacyXrefFactory());
76
+		}
77
+	}
78
+
79
+	/**
80
+	 * {@inheritDoc}
81
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
82
+	 */
83
+	public function loadRoutes(Map $router): void
84
+	{
85
+		$router->attach('', '', static function (Map $router): void {
86
+
87
+			$router->attach('', '/module-maj/misc', static function (Map $router): void {
88
+
89
+				$router->attach('', '/config/admin', static function (Map $router): void {
90
+
91
+					$router->get(AdminConfigPage::class, '', AdminConfigPage::class);
92
+					$router->post(AdminConfigAction::class, '', AdminConfigAction::class);
93
+				});
94
+			});
95
+		});
96
+	}
97
+
98
+	/**
99
+	 * {@inheritDoc}
100
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
101
+	 */
102
+	public function customModuleVersion(): string
103
+	{
104
+		return '2.1.3-v.2';
105
+	}
106
+
107
+	/**
108
+	 * {@inheritDoc}
109
+	 * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink()
110
+	 */
111
+	public function getConfigLink(): string
112
+	{
113
+		return route(AdminConfigPage::class);
114
+	}
115
+
116
+	/**
117
+	 * {@inheritDoc}
118
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
119
+	 */
120
+	public function listSubscribedHooks(): array
121
+	{
122
+		return [
123
+			app()->makeWith(TitlesCardHook::class, [ 'module' => $this ])
124
+		];
125
+	}
126 126
 }
Please login to merge, or discard this patch.
app/Module/MiscExtensions/Factories/LegacyXrefFactory.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -23,67 +23,67 @@
 block discarded – undo
23 23
  */
24 24
 class LegacyXrefFactory extends XrefFactory
25 25
 {
26
-    protected const TYPE_TO_PREFIX = [
27
-        'INDI' => 'I',
28
-        'FAM'  => 'F',
29
-        'OBJE' => 'M',
30
-        'NOTE' => 'N',
31
-        'SOUR' => 'S',
32
-        'REPO' => 'R',
33
-    ];
26
+	protected const TYPE_TO_PREFIX = [
27
+		'INDI' => 'I',
28
+		'FAM'  => 'F',
29
+		'OBJE' => 'M',
30
+		'NOTE' => 'N',
31
+		'SOUR' => 'S',
32
+		'REPO' => 'R',
33
+	];
34 34
 
35
-    /**
36
-     * {@inheritDoc}
37
-     * @see \Fisharebest\Webtrees\Factories\XrefFactory::make()
38
-     */
39
-    public function make(string $record_type): string
40
-    {
41
-        $prefix = static::TYPE_TO_PREFIX[$record_type] ?? 'X';
35
+	/**
36
+	 * {@inheritDoc}
37
+	 * @see \Fisharebest\Webtrees\Factories\XrefFactory::make()
38
+	 */
39
+	public function make(string $record_type): string
40
+	{
41
+		$prefix = static::TYPE_TO_PREFIX[$record_type] ?? 'X';
42 42
 
43
-        return $this->generate($prefix, '');
44
-    }
43
+		return $this->generate($prefix, '');
44
+	}
45 45
 
46
-    /**
47
-     * {@inheritDoc}
48
-     * @see \Fisharebest\Webtrees\Factories\XrefFactory::generate()
49
-     */
50
-    protected function generate($prefix, $suffix): string
51
-    {
52
-        $tree = app(Tree::class);
53
-        if (!$tree instanceof Tree) {
54
-            return parent::generate($prefix, $suffix);
55
-        }
46
+	/**
47
+	 * {@inheritDoc}
48
+	 * @see \Fisharebest\Webtrees\Factories\XrefFactory::generate()
49
+	 */
50
+	protected function generate($prefix, $suffix): string
51
+	{
52
+		$tree = app(Tree::class);
53
+		if (!$tree instanceof Tree) {
54
+			return parent::generate($prefix, $suffix);
55
+		}
56 56
 
57
-        $setting_name = 'MAJ_MISC_XREF_NEXT_' . $prefix;
58
-        // Lock the row, so that only one new XREF may be generated at a time.
59
-        DB::table('gedcom_setting')
60
-            ->where('gedcom_id', '=', $tree->id())
61
-            ->where('setting_name', '=', $setting_name)
62
-            ->lockForUpdate()
63
-            ->get();
57
+		$setting_name = 'MAJ_MISC_XREF_NEXT_' . $prefix;
58
+		// Lock the row, so that only one new XREF may be generated at a time.
59
+		DB::table('gedcom_setting')
60
+			->where('gedcom_id', '=', $tree->id())
61
+			->where('setting_name', '=', $setting_name)
62
+			->lockForUpdate()
63
+			->get();
64 64
 
65
-        $increment = 1.0;
66
-        do {
67
-            $num = (int) $tree->getPreference($setting_name) + (int) $increment;
65
+		$increment = 1.0;
66
+		do {
67
+			$num = (int) $tree->getPreference($setting_name) + (int) $increment;
68 68
 
69
-            // This exponential increment allows us to scan over large blocks of
70
-            // existing data in a reasonable time.
71
-            $increment *= 1.01;
69
+			// This exponential increment allows us to scan over large blocks of
70
+			// existing data in a reasonable time.
71
+			$increment *= 1.01;
72 72
 
73
-            $xref = $prefix . $num . $suffix;
73
+			$xref = $prefix . $num . $suffix;
74 74
 
75
-            // Records may already exist with this sequence number.
76
-            $already_used =
77
-                DB::table('individuals')->where('i_file', '=', $tree->id())->where('i_id', '=', $xref)->exists() ||
78
-                DB::table('families')->where('f_file', '=', $tree->id())->where('f_id', '=', $xref)->exists() ||
79
-                DB::table('sources')->where('s_file', '=', $tree->id())->where('s_id', '=', $xref)->exists() ||
80
-                DB::table('media')->where('m_file', '=', $tree->id())->where('m_id', '=', $xref)->exists() ||
81
-                DB::table('other')->where('o_file', '=', $tree->id())->where('o_id', '=', $xref)->exists() ||
82
-                DB::table('change')->where('gedcom_id', '=', $tree->id())->where('xref', '=', $xref)->exists();
83
-        } while ($already_used);
75
+			// Records may already exist with this sequence number.
76
+			$already_used =
77
+				DB::table('individuals')->where('i_file', '=', $tree->id())->where('i_id', '=', $xref)->exists() ||
78
+				DB::table('families')->where('f_file', '=', $tree->id())->where('f_id', '=', $xref)->exists() ||
79
+				DB::table('sources')->where('s_file', '=', $tree->id())->where('s_id', '=', $xref)->exists() ||
80
+				DB::table('media')->where('m_file', '=', $tree->id())->where('m_id', '=', $xref)->exists() ||
81
+				DB::table('other')->where('o_file', '=', $tree->id())->where('o_id', '=', $xref)->exists() ||
82
+				DB::table('change')->where('gedcom_id', '=', $tree->id())->where('xref', '=', $xref)->exists();
83
+		} while ($already_used);
84 84
 
85
-        $tree->setPreference($setting_name, (string) $num);
85
+		$tree->setPreference($setting_name, (string) $num);
86 86
 
87
-        return $xref;
88
-    }
87
+		return $xref;
88
+	}
89 89
 }
Please login to merge, or discard this patch.