Passed
Push — feature/code-analysis ( e321b8...2d8a51 )
by Jonathan
13:14 queued 09:07
created
app/Module/Sosa/SosaModule.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
     // How to update the database schema for this module
74 74
     private const SCHEMA_TARGET_VERSION   = 3;
75 75
     private const SCHEMA_SETTING_NAME     = 'MAJ_SOSA_SCHEMA_VERSION';
76
-    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
76
+    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__.'\Schema';
77 77
 /**
78 78
      * {@inheritDoc}
79 79
      * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
@@ -113,25 +113,25 @@  discard block
 block discarded – undo
113 113
      */
114 114
     public function loadRoutes(Map $router): void
115 115
     {
116
-        $router->attach('', '', static function (Map $router): void {
116
+        $router->attach('', '', static function(Map $router): void {
117 117
 
118
-            $router->attach('', '/module-maj/sosa', static function (Map $router): void {
118
+            $router->attach('', '/module-maj/sosa', static function(Map $router): void {
119 119
 
120
-                $router->attach('', '/list', static function (Map $router): void {
120
+                $router->attach('', '/list', static function(Map $router): void {
121 121
                     $router->tokens(['gen' => '\d+']);
122 122
                     $router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class);
123
-                    $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class);    //phpcs:ignore Generic.Files.LineLength.TooLong
124
-                    $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class);   //phpcs:ignore Generic.Files.LineLength.TooLong
123
+                    $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class); //phpcs:ignore Generic.Files.LineLength.TooLong
124
+                    $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class); //phpcs:ignore Generic.Files.LineLength.TooLong
125 125
                     $router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class);
126 126
                 });
127 127
 
128
-                $router->attach('', '/statistics/{tree}', static function (Map $router): void {
128
+                $router->attach('', '/statistics/{tree}', static function(Map $router): void {
129 129
 
130 130
                     $router->get(SosaStatistics::class, '', SosaStatistics::class);
131 131
                     $router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class);
132 132
                 });
133 133
 
134
-                $router->attach('', '/config/{tree}', static function (Map $router): void {
134
+                $router->attach('', '/config/{tree}', static function(Map $router): void {
135 135
 
136 136
                     $router->get(SosaConfig::class, '', SosaConfig::class);
137 137
                     $router->post(SosaConfigAction::class, '', SosaConfigAction::class);
@@ -230,7 +230,7 @@  discard block
 block discarded – undo
230 230
      */
231 231
     public function headContent(): string
232 232
     {
233
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
233
+        return '<link rel="stylesheet" href="'.e($this->moduleCssUrl()).'">';
234 234
     }
235 235
 
236 236
     /**
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
      */
240 240
     public function bodyContent(): string
241 241
     {
242
-        return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>';
242
+        return '<script src="'.$this->assetUrl('js/sosa.min.js').'"></script>';
243 243
     }
244 244
 
245 245
     /**
@@ -250,7 +250,7 @@  discard block
 block discarded – undo
250 250
     {
251 251
         $user = Auth::check() ? Auth::user() : new DefaultUser();
252 252
 
253
-        return view($this->name() . '::sidebar/title', [
253
+        return view($this->name().'::sidebar/title', [
254 254
             'module_name'   =>  $this->name(),
255 255
             'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
256 256
         ]);
@@ -266,7 +266,7 @@  discard block
 block discarded – undo
266 266
         $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree());
267 267
         $user = Auth::check() ? Auth::user() : new DefaultUser();
268 268
 
269
-        return view($this->name() . '::sidebar/content', [
269
+        return view($this->name().'::sidebar/content', [
270 270
             'sosa_ancestor' =>  $individual,
271 271
             'sosa_root'     =>  $sosa_root,
272 272
             'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
@@ -312,7 +312,7 @@  discard block
 block discarded – undo
312 312
     public function listSubscribedHooks(): array
313 313
     {
314 314
         return [
315
-            app()->makeWith(SosaIconHook::class, [ 'module' => $this ])
315
+            app()->makeWith(SosaIconHook::class, ['module' => $this])
316 316
         ];
317 317
     }
318 318
 }
Please login to merge, or discard this patch.
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -57,261 +57,261 @@
 block discarded – undo
57 57
  * Identify and produce statistics about Sosa ancestors
58 58
  */
59 59
 class SosaModule extends AbstractModule implements
60
-    ModuleMyArtJaubInterface,
61
-    ModuleGlobalInterface,
62
-    ModuleMenuInterface,
63
-    ModuleSidebarInterface,
64
-    ModuleGeoAnalysisProviderInterface,
65
-    ModuleHookSubscriberInterface
60
+	ModuleMyArtJaubInterface,
61
+	ModuleGlobalInterface,
62
+	ModuleMenuInterface,
63
+	ModuleSidebarInterface,
64
+	ModuleGeoAnalysisProviderInterface,
65
+	ModuleHookSubscriberInterface
66 66
 {
67
-    use ModuleMyArtJaubTrait {
68
-        boot as traitBoot;
69
-    }
70
-    use ModuleGlobalTrait;
71
-    use ModuleMenuTrait;
72
-    use ModuleSidebarTrait;
73
-
74
-    // How to update the database schema for this module
75
-    private const SCHEMA_TARGET_VERSION   = 3;
76
-    private const SCHEMA_SETTING_NAME     = 'MAJ_SOSA_SCHEMA_VERSION';
77
-    private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
67
+	use ModuleMyArtJaubTrait {
68
+		boot as traitBoot;
69
+	}
70
+	use ModuleGlobalTrait;
71
+	use ModuleMenuTrait;
72
+	use ModuleSidebarTrait;
73
+
74
+	// How to update the database schema for this module
75
+	private const SCHEMA_TARGET_VERSION   = 3;
76
+	private const SCHEMA_SETTING_NAME     = 'MAJ_SOSA_SCHEMA_VERSION';
77
+	private const SCHEMA_MIGRATION_PREFIX = __NAMESPACE__ . '\Schema';
78 78
 /**
79
-     * {@inheritDoc}
80
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
81
-     */
82
-    public function title(): string
83
-    {
84
-        return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa');
85
-    }
86
-
87
-    /**
88
-     * {@inheritDoc}
89
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
90
-     */
91
-    public function description(): string
92
-    {
93
-        //phpcs:ignore Generic.Files.LineLength.TooLong
94
-        return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.');
95
-    }
96
-
97
-    /**
98
-     * {@inheritDoc}
99
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
100
-     */
101
-    public function boot(): void
102
-    {
103
-        $this->traitBoot();
104
-        app(MigrationService::class)->updateSchema(
105
-            self::SCHEMA_MIGRATION_PREFIX,
106
-            self::SCHEMA_SETTING_NAME,
107
-            self::SCHEMA_TARGET_VERSION
108
-        );
109
-    }
110
-
111
-    /**
112
-     * {@inheritDoc}
113
-     * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
114
-     */
115
-    public function loadRoutes(Map $router): void
116
-    {
117
-        $router->attach('', '', static function (Map $router): void {
118
-
119
-            $router->attach('', '/module-maj/sosa', static function (Map $router): void {
120
-
121
-                $router->attach('', '/list', static function (Map $router): void {
122
-                    $router->tokens(['gen' => '\d+']);
123
-                    $router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class);
124
-                    $router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class);    //phpcs:ignore Generic.Files.LineLength.TooLong
125
-                    $router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class);   //phpcs:ignore Generic.Files.LineLength.TooLong
126
-                    $router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class);
127
-                });
128
-
129
-                $router->attach('', '/statistics/{tree}', static function (Map $router): void {
130
-
131
-                    $router->get(SosaStatistics::class, '', SosaStatistics::class);
132
-                    $router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class);
133
-                });
134
-
135
-                $router->attach('', '/config/{tree}', static function (Map $router): void {
136
-
137
-                    $router->get(SosaConfig::class, '', SosaConfig::class);
138
-                    $router->post(SosaConfigAction::class, '', SosaConfigAction::class);
139
-                    $router->get(SosaComputeModal::class, '/compute/{xref}', SosaComputeModal::class);
140
-                    $router->post(SosaComputeAction::class, '/compute', SosaComputeAction::class);
141
-                });
142
-            });
143
-        });
144
-    }
145
-
146
-    /**
147
-     * {@inheritDoc}
148
-     * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
149
-     */
150
-    public function customModuleVersion(): string
151
-    {
152
-        return '2.1.3-v.1';
153
-    }
154
-
155
-    /**
156
-     * {@inheritDoc}
157
-     * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder()
158
-     */
159
-    public function defaultMenuOrder(): int
160
-    {
161
-        return 7;
162
-    }
163
-
164
-    /**
165
-     * {@inhericDoc}
166
-     * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu()
167
-     */
168
-    public function getMenu(Tree $tree): ?Menu
169
-    {
170
-        $menu = new Menu(I18N::translate('Sosa Statistics'));
171
-        $menu->setClass('menu-maj-sosa');
172
-        $menu->setSubmenus([
173
-            new Menu(
174
-                I18N::translate('Sosa Ancestors'),
175
-                route(AncestorsList::class, ['tree' => $tree->name()]),
176
-                'menu-maj-sosa-list',
177
-                ['rel' => 'nofollow']
178
-            ),
179
-            new Menu(
180
-                I18N::translate('Missing Ancestors'),
181
-                route(MissingAncestorsList::class, ['tree' => $tree->name()]),
182
-                'menu-maj-sosa-missing',
183
-                ['rel' => 'nofollow']
184
-            ),
185
-            new Menu(
186
-                I18N::translate('Sosa Statistics'),
187
-                route(SosaStatistics::class, ['tree' => $tree->name()]),
188
-                'menu-maj-sosa-stats'
189
-            )
190
-        ]);
191
-
192
-        if (Auth::check()) {
193
-            $menu->addSubmenu(new Menu(
194
-                I18N::translate('Sosa Configuration'),
195
-                route(SosaConfig::class, ['tree' => $tree->name()]),
196
-                'menu-maj-sosa-config'
197
-            ));
198
-
199
-            /** @var ServerRequestInterface $request */
200
-            $request = app(ServerRequestInterface::class);
201
-            $route = Validator::attributes($request)->route();
202
-
203
-            $root_indi_id = $tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID');
204
-
205
-            if ($route->name === IndividualPage::class && mb_strlen($root_indi_id) > 0) {
206
-                $xref = Validator::attributes($request)->isXref()->string('xref', '');
207
-
208
-                $menu->addSubmenu(new Menu(
209
-                    I18N::translate('Complete Sosas'),
210
-                    '#',
211
-                    'menu-maj-sosa-compute',
212
-                    [
213
-                        'rel'           => 'nofollow',
214
-                        'data-wt-href'  => route(SosaComputeModal::class, ['tree' => $tree->name(), 'xref' => $xref]),
215
-                        'data-bs-target'    => '#wt-ajax-modal',
216
-                        'data-bs-toggle'    => 'modal',
217
-                        'data-bs-backdrop'  => 'static'
218
-                    ]
219
-                ));
220
-            }
221
-        }
222
-
223
-        return $menu;
224
-    }
225
-
226
-    /**
227
-     * {@inheritDoc}
228
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
229
-     */
230
-    public function headContent(): string
231
-    {
232
-        return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
233
-    }
234
-
235
-    /**
236
-     * {@inheritDoc}
237
-     * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
238
-     */
239
-    public function bodyContent(): string
240
-    {
241
-        return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>';
242
-    }
243
-
244
-    /**
245
-     * {@inheritDoc}
246
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::sidebarTitle()
247
-     */
248
-    public function sidebarTitle(Individual $individual): string
249
-    {
250
-        $user = Auth::check() ? Auth::user() : new DefaultUser();
251
-
252
-        return view($this->name() . '::sidebar/title', [
253
-            'module_name'   =>  $this->name(),
254
-            'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
255
-        ]);
256
-    }
257
-
258
-    /**
259
-     * {@inheritDoc}
260
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
261
-     */
262
-    public function getSidebarContent(Individual $individual): string
263
-    {
264
-        $sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID');
265
-        $sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree());
266
-        $user = Auth::check() ? Auth::user() : new DefaultUser();
267
-
268
-        return view($this->name() . '::sidebar/content', [
269
-            'sosa_ancestor' =>  $individual,
270
-            'sosa_root'     =>  $sosa_root,
271
-            'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
272
-        ]);
273
-    }
274
-
275
-    /**
276
-     * {@inheritDoc}
277
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
278
-     */
279
-    public function hasSidebarContent(Individual $individual): bool
280
-    {
281
-        $user = Auth::check() ? Auth::user() : new DefaultUser();
282
-
283
-        return app(SosaRecordsService::class)
284
-            ->sosaNumbers($individual->tree(), $user, $individual)->count() > 0;
285
-    }
286
-
287
-    /**
288
-     * {@inheritDoc}
289
-     * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder()
290
-     */
291
-    public function defaultSidebarOrder(): int
292
-    {
293
-        return 1;
294
-    }
295
-
296
-    /**
297
-     * {@inheritDoc}
298
-     * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
299
-     */
300
-    public function listGeoAnalyses(): array
301
-    {
302
-        return [
303
-            SosaByGenerationGeoAnalysis::class
304
-        ];
305
-    }
306
-
307
-    /**
308
-     * {@inheritDoc}
309
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
310
-     */
311
-    public function listSubscribedHooks(): array
312
-    {
313
-        return [
314
-            app()->makeWith(SosaIconHook::class, [ 'module' => $this ])
315
-        ];
316
-    }
79
+	 * {@inheritDoc}
80
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::title()
81
+	 */
82
+	public function title(): string
83
+	{
84
+		return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa');
85
+	}
86
+
87
+	/**
88
+	 * {@inheritDoc}
89
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::description()
90
+	 */
91
+	public function description(): string
92
+	{
93
+		//phpcs:ignore Generic.Files.LineLength.TooLong
94
+		return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.');
95
+	}
96
+
97
+	/**
98
+	 * {@inheritDoc}
99
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::boot()
100
+	 */
101
+	public function boot(): void
102
+	{
103
+		$this->traitBoot();
104
+		app(MigrationService::class)->updateSchema(
105
+			self::SCHEMA_MIGRATION_PREFIX,
106
+			self::SCHEMA_SETTING_NAME,
107
+			self::SCHEMA_TARGET_VERSION
108
+		);
109
+	}
110
+
111
+	/**
112
+	 * {@inheritDoc}
113
+	 * @see \MyArtJaub\Webtrees\Module\ModuleMyArtJaubInterface::loadRoutes()
114
+	 */
115
+	public function loadRoutes(Map $router): void
116
+	{
117
+		$router->attach('', '', static function (Map $router): void {
118
+
119
+			$router->attach('', '/module-maj/sosa', static function (Map $router): void {
120
+
121
+				$router->attach('', '/list', static function (Map $router): void {
122
+					$router->tokens(['gen' => '\d+']);
123
+					$router->get(AncestorsList::class, '/ancestors/{tree}{/gen}', AncestorsList::class);
124
+					$router->get(AncestorsListIndividual::class, '/ancestors/{tree}/{gen}/tab/individuals', AncestorsListIndividual::class);    //phpcs:ignore Generic.Files.LineLength.TooLong
125
+					$router->get(AncestorsListFamily::class, '/ancestors/{tree}/{gen}/tab/families', AncestorsListFamily::class);   //phpcs:ignore Generic.Files.LineLength.TooLong
126
+					$router->get(MissingAncestorsList::class, '/missing/{tree}{/gen}', MissingAncestorsList::class);
127
+				});
128
+
129
+				$router->attach('', '/statistics/{tree}', static function (Map $router): void {
130
+
131
+					$router->get(SosaStatistics::class, '', SosaStatistics::class);
132
+					$router->get(PedigreeCollapseData::class, '/pedigreecollapse', PedigreeCollapseData::class);
133
+				});
134
+
135
+				$router->attach('', '/config/{tree}', static function (Map $router): void {
136
+
137
+					$router->get(SosaConfig::class, '', SosaConfig::class);
138
+					$router->post(SosaConfigAction::class, '', SosaConfigAction::class);
139
+					$router->get(SosaComputeModal::class, '/compute/{xref}', SosaComputeModal::class);
140
+					$router->post(SosaComputeAction::class, '/compute', SosaComputeAction::class);
141
+				});
142
+			});
143
+		});
144
+	}
145
+
146
+	/**
147
+	 * {@inheritDoc}
148
+	 * @see \Fisharebest\Webtrees\Module\ModuleCustomInterface::customModuleVersion()
149
+	 */
150
+	public function customModuleVersion(): string
151
+	{
152
+		return '2.1.3-v.1';
153
+	}
154
+
155
+	/**
156
+	 * {@inheritDoc}
157
+	 * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder()
158
+	 */
159
+	public function defaultMenuOrder(): int
160
+	{
161
+		return 7;
162
+	}
163
+
164
+	/**
165
+	 * {@inhericDoc}
166
+	 * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu()
167
+	 */
168
+	public function getMenu(Tree $tree): ?Menu
169
+	{
170
+		$menu = new Menu(I18N::translate('Sosa Statistics'));
171
+		$menu->setClass('menu-maj-sosa');
172
+		$menu->setSubmenus([
173
+			new Menu(
174
+				I18N::translate('Sosa Ancestors'),
175
+				route(AncestorsList::class, ['tree' => $tree->name()]),
176
+				'menu-maj-sosa-list',
177
+				['rel' => 'nofollow']
178
+			),
179
+			new Menu(
180
+				I18N::translate('Missing Ancestors'),
181
+				route(MissingAncestorsList::class, ['tree' => $tree->name()]),
182
+				'menu-maj-sosa-missing',
183
+				['rel' => 'nofollow']
184
+			),
185
+			new Menu(
186
+				I18N::translate('Sosa Statistics'),
187
+				route(SosaStatistics::class, ['tree' => $tree->name()]),
188
+				'menu-maj-sosa-stats'
189
+			)
190
+		]);
191
+
192
+		if (Auth::check()) {
193
+			$menu->addSubmenu(new Menu(
194
+				I18N::translate('Sosa Configuration'),
195
+				route(SosaConfig::class, ['tree' => $tree->name()]),
196
+				'menu-maj-sosa-config'
197
+			));
198
+
199
+			/** @var ServerRequestInterface $request */
200
+			$request = app(ServerRequestInterface::class);
201
+			$route = Validator::attributes($request)->route();
202
+
203
+			$root_indi_id = $tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID');
204
+
205
+			if ($route->name === IndividualPage::class && mb_strlen($root_indi_id) > 0) {
206
+				$xref = Validator::attributes($request)->isXref()->string('xref', '');
207
+
208
+				$menu->addSubmenu(new Menu(
209
+					I18N::translate('Complete Sosas'),
210
+					'#',
211
+					'menu-maj-sosa-compute',
212
+					[
213
+						'rel'           => 'nofollow',
214
+						'data-wt-href'  => route(SosaComputeModal::class, ['tree' => $tree->name(), 'xref' => $xref]),
215
+						'data-bs-target'    => '#wt-ajax-modal',
216
+						'data-bs-toggle'    => 'modal',
217
+						'data-bs-backdrop'  => 'static'
218
+					]
219
+				));
220
+			}
221
+		}
222
+
223
+		return $menu;
224
+	}
225
+
226
+	/**
227
+	 * {@inheritDoc}
228
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::headContent()
229
+	 */
230
+	public function headContent(): string
231
+	{
232
+		return '<link rel="stylesheet" href="' . e($this->moduleCssUrl()) . '">';
233
+	}
234
+
235
+	/**
236
+	 * {@inheritDoc}
237
+	 * @see \Fisharebest\Webtrees\Module\ModuleGlobalInterface::bodyContent()
238
+	 */
239
+	public function bodyContent(): string
240
+	{
241
+		return '<script src="' . $this->assetUrl('js/sosa.min.js') . '"></script>';
242
+	}
243
+
244
+	/**
245
+	 * {@inheritDoc}
246
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::sidebarTitle()
247
+	 */
248
+	public function sidebarTitle(Individual $individual): string
249
+	{
250
+		$user = Auth::check() ? Auth::user() : new DefaultUser();
251
+
252
+		return view($this->name() . '::sidebar/title', [
253
+			'module_name'   =>  $this->name(),
254
+			'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
255
+		]);
256
+	}
257
+
258
+	/**
259
+	 * {@inheritDoc}
260
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
261
+	 */
262
+	public function getSidebarContent(Individual $individual): string
263
+	{
264
+		$sosa_root_xref = $individual->tree()->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID');
265
+		$sosa_root = Registry::individualFactory()->make($sosa_root_xref, $individual->tree());
266
+		$user = Auth::check() ? Auth::user() : new DefaultUser();
267
+
268
+		return view($this->name() . '::sidebar/content', [
269
+			'sosa_ancestor' =>  $individual,
270
+			'sosa_root'     =>  $sosa_root,
271
+			'sosa_numbers'  =>  app(SosaRecordsService::class)->sosaNumbers($individual->tree(), $user, $individual)
272
+		]);
273
+	}
274
+
275
+	/**
276
+	 * {@inheritDoc}
277
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
278
+	 */
279
+	public function hasSidebarContent(Individual $individual): bool
280
+	{
281
+		$user = Auth::check() ? Auth::user() : new DefaultUser();
282
+
283
+		return app(SosaRecordsService::class)
284
+			->sosaNumbers($individual->tree(), $user, $individual)->count() > 0;
285
+	}
286
+
287
+	/**
288
+	 * {@inheritDoc}
289
+	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder()
290
+	 */
291
+	public function defaultSidebarOrder(): int
292
+	{
293
+		return 1;
294
+	}
295
+
296
+	/**
297
+	 * {@inheritDoc}
298
+	 * @see \MyArtJaub\Webtrees\Contracts\GeoDispersion\ModuleGeoAnalysisProviderInterface::listGeoAnalyses()
299
+	 */
300
+	public function listGeoAnalyses(): array
301
+	{
302
+		return [
303
+			SosaByGenerationGeoAnalysis::class
304
+		];
305
+	}
306
+
307
+	/**
308
+	 * {@inheritDoc}
309
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\ModuleHookSubscriberInterface::listSubscribedHooks()
310
+	 */
311
+	public function listSubscribedHooks(): array
312
+	{
313
+		return [
314
+			app()->makeWith(SosaIconHook::class, [ 'module' => $this ])
315
+		];
316
+	}
317 317
 }
Please login to merge, or discard this patch.
app/Contracts/Tasks/ConfigurableTaskInterface.php 1 patch
Indentation   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -22,20 +22,20 @@
 block discarded – undo
22 22
  */
23 23
 interface ConfigurableTaskInterface
24 24
 {
25
-    /**
26
-     * Returns the HTML code to display the specific task configuration.
27
-     *
28
-     * @param ServerRequestInterface $request
29
-     * @return string HTML code
30
-     */
31
-    public function configView(ServerRequestInterface $request): string;
25
+	/**
26
+	 * Returns the HTML code to display the specific task configuration.
27
+	 *
28
+	 * @param ServerRequestInterface $request
29
+	 * @return string HTML code
30
+	 */
31
+	public function configView(ServerRequestInterface $request): string;
32 32
 
33
-    /**
34
-     * Update the specific configuration of the task.
35
-     *
36
-     * @param ServerRequestInterface $request
37
-     * @param TaskSchedule $task_schedule
38
-     * @return bool Result of the update
39
-     */
40
-    public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool;
33
+	/**
34
+	 * Update the specific configuration of the task.
35
+	 *
36
+	 * @param ServerRequestInterface $request
37
+	 * @param TaskSchedule $task_schedule
38
+	 * @return bool Result of the update
39
+	 */
40
+	public function updateConfig(ServerRequestInterface $request, TaskSchedule $task_schedule): bool;
41 41
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Schema/Migration0.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@
 block discarded – undo
21 21
  */
22 22
 class Migration0 implements MigrationInterface
23 23
 {
24
-    /**
25
-     * {@inheritDoc}
26
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
27
-     */
28
-    public function upgrade(): void
29
-    {
30
-        // These migrations have been merged into migration 2.
31
-    }
24
+	/**
25
+	 * {@inheritDoc}
26
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
27
+	 */
28
+	public function upgrade(): void
29
+	{
30
+		// These migrations have been merged into migration 2.
31
+	}
32 32
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Schema/Migration1.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -21,12 +21,12 @@
 block discarded – undo
21 21
  */
22 22
 class Migration1 implements MigrationInterface
23 23
 {
24
-    /**
25
-     * {@inheritDoc}
26
-     * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
27
-     */
28
-    public function upgrade(): void
29
-    {
30
-        // These migrations have been merged into migration 2.
31
-    }
24
+	/**
25
+	 * {@inheritDoc}
26
+	 * @see \Fisharebest\Webtrees\Schema\MigrationInterface::upgrade()
27
+	 */
28
+	public function upgrade(): void
29
+	{
30
+		// These migrations have been merged into migration 2.
31
+	}
32 32
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/AncestorsList.php 2 patches
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -34,48 +34,48 @@
 block discarded – undo
34 34
  */
35 35
 class AncestorsList implements RequestHandlerInterface
36 36
 {
37
-    use ViewResponseTrait;
37
+	use ViewResponseTrait;
38 38
 
39
-    private ?SosaModule $module;
39
+	private ?SosaModule $module;
40 40
 
41
-    /**
42
-     * Constructor for AncestorsList Request Handler
43
-     *
44
-     * @param ModuleService $module_service
45
-     */
46
-    public function __construct(ModuleService $module_service)
47
-    {
48
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
49
-    }
41
+	/**
42
+	 * Constructor for AncestorsList Request Handler
43
+	 *
44
+	 * @param ModuleService $module_service
45
+	 */
46
+	public function __construct(ModuleService $module_service)
47
+	{
48
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
49
+	}
50 50
 
51
-    /**
52
-     * {@inheritDoc}
53
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
-     */
55
-    public function handle(ServerRequestInterface $request): ResponseInterface
56
-    {
57
-        if ($this->module === null) {
58
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
-        }
51
+	/**
52
+	 * {@inheritDoc}
53
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
54
+	 */
55
+	public function handle(ServerRequestInterface $request): ResponseInterface
56
+	{
57
+		if ($this->module === null) {
58
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
59
+		}
60 60
 
61
-        $tree = Validator::attributes($request)->tree();
62
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
61
+		$tree = Validator::attributes($request)->tree();
62
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
63 63
 
64
-        /** @var SosaStatisticsService $sosa_stats_service */
65
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
64
+		/** @var SosaStatisticsService $sosa_stats_service */
65
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
66 66
 
67
-        $current_gen = Validator::queryParams($request)->integer(
68
-            'gen',
69
-            Validator::attributes($request)->integer('gen', 0)
70
-        );
67
+		$current_gen = Validator::queryParams($request)->integer(
68
+			'gen',
69
+			Validator::attributes($request)->integer('gen', 0)
70
+		);
71 71
 
72
-        return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
73
-            'module_name'       =>  $this->module->name(),
74
-            'title'             =>  I18N::translate('Sosa Ancestors'),
75
-            'tree'              =>  $tree,
76
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
77
-            'max_gen'           =>  $sosa_stats_service->maxGeneration(),
78
-            'current_gen'       =>  $current_gen
79
-        ]);
80
-    }
72
+		return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
73
+			'module_name'       =>  $this->module->name(),
74
+			'title'             =>  I18N::translate('Sosa Ancestors'),
75
+			'tree'              =>  $tree,
76
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
77
+			'max_gen'           =>  $sosa_stats_service->maxGeneration(),
78
+			'current_gen'       =>  $current_gen
79
+		]);
80
+	}
81 81
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@
 block discarded – undo
69 69
             Validator::attributes($request)->integer('gen', 0)
70 70
         );
71 71
 
72
-        return $this->viewResponse($this->module->name() . '::list-ancestors-page', [
72
+        return $this->viewResponse($this->module->name().'::list-ancestors-page', [
73 73
             'module_name'       =>  $this->module->name(),
74 74
             'title'             =>  I18N::translate('Sosa Ancestors'),
75 75
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/SosaConfig.php 2 patches
Spacing   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -86,11 +86,10 @@
 block discarded – undo
86 86
         $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations();
87 87
         foreach ($users_root as $key => $user_root) {
88 88
             $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ?
89
-                (int) $user_root['max_gen'] :
90
-                $max_gen_system;
89
+                (int)$user_root['max_gen'] : $max_gen_system;
91 90
         };
92 91
 
93
-        return $this->viewResponse($this->module->name() . '::config-page', [
92
+        return $this->viewResponse($this->module->name().'::config-page', [
94 93
             'module_name'       =>  $this->module->name(),
95 94
             'title'             =>  I18N::translate('Sosa Configuration'),
96 95
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -33,71 +33,71 @@
 block discarded – undo
33 33
  */
34 34
 class SosaConfig implements RequestHandlerInterface
35 35
 {
36
-    use ViewResponseTrait;
36
+	use ViewResponseTrait;
37 37
 
38
-    /**
39
-     * @var SosaModule|null $module
40
-     */
41
-    private $module;
38
+	/**
39
+	 * @var SosaModule|null $module
40
+	 */
41
+	private $module;
42 42
 
43
-    /**
44
-     * Constructor for SosaConfig Request Handler
45
-     *
46
-     * @param ModuleService $module_service
47
-     */
48
-    public function __construct(ModuleService $module_service)
49
-    {
50
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
51
-    }
43
+	/**
44
+	 * Constructor for SosaConfig Request Handler
45
+	 *
46
+	 * @param ModuleService $module_service
47
+	 */
48
+	public function __construct(ModuleService $module_service)
49
+	{
50
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
51
+	}
52 52
 
53
-    /**
54
-     * {@inheritDoc}
55
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
-     */
57
-    public function handle(ServerRequestInterface $request): ResponseInterface
58
-    {
59
-        if ($this->module === null) {
60
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
-        }
53
+	/**
54
+	 * {@inheritDoc}
55
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
56
+	 */
57
+	public function handle(ServerRequestInterface $request): ResponseInterface
58
+	{
59
+		if ($this->module === null) {
60
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
61
+		}
62 62
 
63
-        $tree = Validator::attributes($request)->tree();
63
+		$tree = Validator::attributes($request)->tree();
64 64
 
65
-        $users_root = array();
66
-        if (Auth::check()) {
67
-            /** @var \Fisharebest\Webtrees\User $user */
68
-            $user = Auth::user();
69
-            $users_root[] = [
70
-                'user'      => $user,
71
-                'root_id'   => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'),
72
-                'max_gen'   => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN')
73
-            ];
65
+		$users_root = array();
66
+		if (Auth::check()) {
67
+			/** @var \Fisharebest\Webtrees\User $user */
68
+			$user = Auth::user();
69
+			$users_root[] = [
70
+				'user'      => $user,
71
+				'root_id'   => $tree->getUserPreference($user, 'MAJ_SOSA_ROOT_ID'),
72
+				'max_gen'   => $tree->getUserPreference($user, 'MAJ_SOSA_MAX_GEN')
73
+			];
74 74
 
75
-            if (Auth::isManager($tree)) {
76
-                $default_user = new DefaultUser();
77
-                $users_root[] = [
78
-                    'user' => $default_user,
79
-                    'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'),
80
-                    'max_gen'   => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN')
81
-                ];
82
-            }
83
-        }
75
+			if (Auth::isManager($tree)) {
76
+				$default_user = new DefaultUser();
77
+				$users_root[] = [
78
+					'user' => $default_user,
79
+					'root_id' => $tree->getUserPreference($default_user, 'MAJ_SOSA_ROOT_ID'),
80
+					'max_gen'   => $tree->getUserPreference($default_user, 'MAJ_SOSA_MAX_GEN')
81
+				];
82
+			}
83
+		}
84 84
 
85
-        // Use the system max generations if not set
86
-        $max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations();
87
-        foreach ($users_root as $key => $user_root) {
88
-            $users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ?
89
-                (int) $user_root['max_gen'] :
90
-                $max_gen_system;
91
-        };
85
+		// Use the system max generations if not set
86
+		$max_gen_system = app(SosaRecordsService::class)->maxSystemGenerations();
87
+		foreach ($users_root as $key => $user_root) {
88
+			$users_root[$key]['max_gen'] = is_numeric($user_root['max_gen']) ?
89
+				(int) $user_root['max_gen'] :
90
+				$max_gen_system;
91
+		};
92 92
 
93
-        return $this->viewResponse($this->module->name() . '::config-page', [
94
-            'module_name'       =>  $this->module->name(),
95
-            'title'             =>  I18N::translate('Sosa Configuration'),
96
-            'tree'              =>  $tree,
97
-            'user_id'           =>  Validator::attributes($request)->user(),
98
-            'selected_user_id'  =>  Validator::queryParams($request)->integer('user_id', 0),
99
-            'immediate_compute' =>  Validator::queryParams($request)->string('compute', '') === 'yes',
100
-            'users_root'        =>  $users_root
101
-        ]);
102
-    }
93
+		return $this->viewResponse($this->module->name() . '::config-page', [
94
+			'module_name'       =>  $this->module->name(),
95
+			'title'             =>  I18N::translate('Sosa Configuration'),
96
+			'tree'              =>  $tree,
97
+			'user_id'           =>  Validator::attributes($request)->user(),
98
+			'selected_user_id'  =>  Validator::queryParams($request)->integer('user_id', 0),
99
+			'immediate_compute' =>  Validator::queryParams($request)->string('compute', '') === 'yes',
100
+			'users_root'        =>  $users_root
101
+		]);
102
+	}
103 103
 }
Please login to merge, or discard this patch.
app/Module/Sosa/Http/RequestHandlers/MissingAncestorsList.php 2 patches
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -37,89 +37,89 @@
 block discarded – undo
37 37
  */
38 38
 class MissingAncestorsList implements RequestHandlerInterface
39 39
 {
40
-    use ViewResponseTrait;
41
-
42
-    /**
43
-     * @var SosaModule|null $module
44
-     */
45
-    private $module;
46
-
47
-    /**
48
-     * @var SosaRecordsService $sosa_record_service
49
-     */
50
-    private $sosa_record_service;
51
-
52
-    /**
53
-     * Constructor for MissingAncestorsList Request Handler
54
-     *
55
-     * @param ModuleService $module_service
56
-     * @param SosaRecordsService $sosa_record_service
57
-     */
58
-    public function __construct(
59
-        ModuleService $module_service,
60
-        SosaRecordsService $sosa_record_service
61
-    ) {
62
-        $this->module = $module_service->findByInterface(SosaModule::class)->first();
63
-        $this->sosa_record_service = $sosa_record_service;
64
-    }
65
-
66
-    /**
67
-     * {@inheritDoc}
68
-     * @see \Psr\Http\Server\RequestHandlerInterface::handle()
69
-     */
70
-    public function handle(ServerRequestInterface $request): ResponseInterface
71
-    {
72
-        if ($this->module === null) {
73
-            throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
-        }
75
-
76
-        $tree = Validator::attributes($request)->tree();
77
-        $user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
78
-
79
-        /** @var SosaStatisticsService $sosa_stats_service */
80
-        $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
81
-
82
-        $current_gen =  Validator::queryParams($request)->integer(
83
-            'gen',
84
-            Validator::attributes($request)->integer('gen', 0)
85
-        );
86
-
87
-        $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
88
-        $nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
89
-            return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
90
-        });
91
-
92
-        $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
93
-            $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94
-            if ($indi !== null && $indi->canShowName()) {
95
-                return new MissingAncestor(
96
-                    $indi,
97
-                    (int) $value->majs_sosa,
98
-                    $value->majs_fat_id === null,
99
-                    $value->majs_mot_id === null
100
-                );
101
-            }
102
-            return null;
103
-        })->filter();
104
-
105
-        $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
106
-            return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
107
-        });
108
-
109
-        return $this->viewResponse($this->module->name() . '::list-missing-page', [
110
-            'module_name'       =>  $this->module->name(),
111
-            'title'             =>  I18N::translate('Missing Ancestors'),
112
-            'tree'              =>  $tree,
113
-            'root_indi'         =>  $sosa_stats_service->rootIndividual(),
114
-            'max_gen'           =>  $sosa_stats_service->maxGeneration(),
115
-            'current_gen'       =>  $current_gen,
116
-            'list_missing'      =>  $list_missing,
117
-            'nb_missing_diff'   =>  $nb_missing_diff,
118
-            'nb_missing_shown'  =>  $nb_missing_shown,
119
-            'gen_completeness'  =>
120
-                $sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1),
121
-            'gen_potential'     =>
122
-                $sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2)
123
-        ]);
124
-    }
40
+	use ViewResponseTrait;
41
+
42
+	/**
43
+	 * @var SosaModule|null $module
44
+	 */
45
+	private $module;
46
+
47
+	/**
48
+	 * @var SosaRecordsService $sosa_record_service
49
+	 */
50
+	private $sosa_record_service;
51
+
52
+	/**
53
+	 * Constructor for MissingAncestorsList Request Handler
54
+	 *
55
+	 * @param ModuleService $module_service
56
+	 * @param SosaRecordsService $sosa_record_service
57
+	 */
58
+	public function __construct(
59
+		ModuleService $module_service,
60
+		SosaRecordsService $sosa_record_service
61
+	) {
62
+		$this->module = $module_service->findByInterface(SosaModule::class)->first();
63
+		$this->sosa_record_service = $sosa_record_service;
64
+	}
65
+
66
+	/**
67
+	 * {@inheritDoc}
68
+	 * @see \Psr\Http\Server\RequestHandlerInterface::handle()
69
+	 */
70
+	public function handle(ServerRequestInterface $request): ResponseInterface
71
+	{
72
+		if ($this->module === null) {
73
+			throw new HttpNotFoundException(I18N::translate('The attached module could not be found.'));
74
+		}
75
+
76
+		$tree = Validator::attributes($request)->tree();
77
+		$user = Auth::check() ? Validator::attributes($request)->user() : new DefaultUser();
78
+
79
+		/** @var SosaStatisticsService $sosa_stats_service */
80
+		$sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
81
+
82
+		$current_gen =  Validator::queryParams($request)->integer(
83
+			'gen',
84
+			Validator::attributes($request)->integer('gen', 0)
85
+		);
86
+
87
+		$list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
88
+		$nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
89
+			return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
90
+		});
91
+
92
+		$list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
93
+			$indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94
+			if ($indi !== null && $indi->canShowName()) {
95
+				return new MissingAncestor(
96
+					$indi,
97
+					(int) $value->majs_sosa,
98
+					$value->majs_fat_id === null,
99
+					$value->majs_mot_id === null
100
+				);
101
+			}
102
+			return null;
103
+		})->filter();
104
+
105
+		$nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
106
+			return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
107
+		});
108
+
109
+		return $this->viewResponse($this->module->name() . '::list-missing-page', [
110
+			'module_name'       =>  $this->module->name(),
111
+			'title'             =>  I18N::translate('Missing Ancestors'),
112
+			'tree'              =>  $tree,
113
+			'root_indi'         =>  $sosa_stats_service->rootIndividual(),
114
+			'max_gen'           =>  $sosa_stats_service->maxGeneration(),
115
+			'current_gen'       =>  $current_gen,
116
+			'list_missing'      =>  $list_missing,
117
+			'nb_missing_diff'   =>  $nb_missing_diff,
118
+			'nb_missing_shown'  =>  $nb_missing_shown,
119
+			'gen_completeness'  =>
120
+				$sosa_stats_service->totalAncestorsAtGeneration($current_gen) / pow(2, $current_gen - 1),
121
+			'gen_potential'     =>
122
+				$sosa_stats_service->totalAncestorsAtGeneration($current_gen - 1) / pow(2, $current_gen - 2)
123
+		]);
124
+	}
125 125
 }
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -79,22 +79,22 @@  discard block
 block discarded – undo
79 79
         /** @var SosaStatisticsService $sosa_stats_service */
80 80
         $sosa_stats_service = app()->makeWith(SosaStatisticsService::class, ['tree' => $tree, 'user' => $user]);
81 81
 
82
-        $current_gen =  Validator::queryParams($request)->integer(
82
+        $current_gen = Validator::queryParams($request)->integer(
83 83
             'gen',
84 84
             Validator::attributes($request)->integer('gen', 0)
85 85
         );
86 86
 
87 87
         $list_missing = $this->sosa_record_service->listMissingAncestorsAtGeneration($tree, $user, $current_gen);
88
-        $nb_missing_diff = $list_missing->sum(function (stdClass $value): int {
88
+        $nb_missing_diff = $list_missing->sum(function(stdClass $value): int {
89 89
             return ($value->majs_fat_id === null ? 1 : 0) + ($value->majs_mot_id === null ? 1 : 0);
90 90
         });
91 91
 
92
-        $list_missing = $list_missing->map(function (stdClass $value) use ($tree): ?MissingAncestor {
92
+        $list_missing = $list_missing->map(function(stdClass $value) use ($tree): ?MissingAncestor {
93 93
             $indi = Registry::individualFactory()->make($value->majs_i_id, $tree);
94 94
             if ($indi !== null && $indi->canShowName()) {
95 95
                 return new MissingAncestor(
96 96
                     $indi,
97
-                    (int) $value->majs_sosa,
97
+                    (int)$value->majs_sosa,
98 98
                     $value->majs_fat_id === null,
99 99
                     $value->majs_mot_id === null
100 100
                 );
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
             return null;
103 103
         })->filter();
104 104
 
105
-        $nb_missing_shown = $list_missing->sum(function (MissingAncestor $value): int {
105
+        $nb_missing_shown = $list_missing->sum(function(MissingAncestor $value): int {
106 106
             return ($value->isFatherMissing() ? 1 : 0) + ($value->isMotherMissing() ? 1 : 0);
107 107
         });
108 108
 
109
-        return $this->viewResponse($this->module->name() . '::list-missing-page', [
109
+        return $this->viewResponse($this->module->name().'::list-missing-page', [
110 110
             'module_name'       =>  $this->module->name(),
111 111
             'title'             =>  I18N::translate('Missing Ancestors'),
112 112
             'tree'              =>  $tree,
Please login to merge, or discard this patch.
app/Module/Sosa/Services/SosaRecordsService.php 2 patches
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -98,8 +98,8 @@  discard block
 block discarded – undo
98 98
     public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection
99 99
     {
100 100
         return Registry::cache()->array()->remember(
101
-            'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(),
102
-            function () use ($tree, $user, $indi): Collection {
101
+            'sosanumbers-'.$indi->xref().'@'.$tree->id().'-'.$user->id(),
102
+            function() use ($tree, $user, $indi): Collection {
103 103
                 return DB::table('maj_sosa')
104 104
                     ->select(['majs_sosa', 'majs_gen'])
105 105
                     ->where('majs_gedcom_id', '=', $tree->id())
@@ -159,14 +159,14 @@  discard block
 block discarded – undo
159 159
     {
160 160
         $table_prefix = DB::connection()->getTablePrefix();
161 161
         return DB::table('families')
162
-            ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void {
162
+            ->join('maj_sosa AS sosa_husb', function(JoinClause $join) use ($tree, $user): void {
163 163
                 // Link to family husband
164 164
                 $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id')
165 165
                     ->on('families.f_husb', '=', 'sosa_husb.majs_i_id')
166 166
                     ->where('sosa_husb.majs_gedcom_id', '=', $tree->id())
167 167
                     ->where('sosa_husb.majs_user_id', '=', $user->id());
168 168
             })
169
-            ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void {
169
+            ->join('maj_sosa AS sosa_wife', function(JoinClause $join) use ($tree, $user): void {
170 170
                 // Link to family husband
171 171
                 $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id')
172 172
                 ->on('families.f_wife', '=', 'sosa_wife.majs_i_id')
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
             })
176 176
             ->select(['sosa_husb.majs_sosa', 'families.f_id'])
177 177
             ->where('sosa_husb.majs_gen', '=', $gen)
178
-            ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa')
178
+            ->whereRaw($table_prefix.'sosa_husb.majs_sosa + 1 = '.$table_prefix.'sosa_wife.majs_sosa')
179 179
             ->orderBy('sosa_husb.majs_sosa')
180 180
             ->get();
181 181
     }
@@ -198,28 +198,28 @@  discard block
 block discarded – undo
198 198
         $table_prefix = DB::connection()->getTablePrefix();
199 199
         return DB::table('maj_sosa AS sosa')
200 200
             ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id'])
201
-            ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa')
202
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void {
201
+            ->selectRaw('MIN('.$table_prefix.'sosa.majs_sosa) AS majs_sosa')
202
+            ->leftJoin('maj_sosa AS sosa_fat', function(JoinClause $join) use ($tree, $user, $table_prefix): void {
203 203
                 // Link to sosa's father
204
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
204
+                $join->whereRaw($table_prefix.'sosa_fat.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa')
205 205
                     ->where('sosa_fat.majs_gedcom_id', '=', $tree->id())
206 206
                     ->where('sosa_fat.majs_user_id', '=', $user->id());
207 207
             })
208
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void {
208
+            ->leftJoin('maj_sosa AS sosa_mot', function(JoinClause $join) use ($tree, $user, $table_prefix): void {
209 209
                 // Link to sosa's mother
210
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
210
+                $join->whereRaw($table_prefix.'sosa_mot.majs_sosa = 2 * '.$table_prefix.'sosa.majs_sosa + 1')
211 211
                     ->where('sosa_mot.majs_gedcom_id', '=', $tree->id())
212 212
                     ->where('sosa_mot.majs_user_id', '=', $user->id());
213 213
             })
214 214
             ->where('sosa.majs_gedcom_id', '=', $tree->id())
215 215
             ->where('sosa.majs_user_id', '=', $user->id())
216 216
             ->where('sosa.majs_gen', '=', $gen - 1)
217
-            ->where(function (Builder $query): void {
217
+            ->where(function(Builder $query): void {
218 218
                 $query->whereNull('sosa_fat.majs_i_id')
219 219
                     ->orWhereNull('sosa_mot.majs_i_id');
220 220
             })
221 221
             ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id')
222
-            ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)')
222
+            ->orderByRaw('MIN('.$table_prefix.'sosa.majs_sosa)')
223 223
             ->get();
224 224
     }
225 225
 
@@ -271,26 +271,26 @@  discard block
 block discarded – undo
271 271
         $has_records = false;
272 272
         foreach ($sosa_records as $i => $row) {
273 273
             $gen = $this->generation($row['sosa']);
274
-            if ($gen <=  $this->maxSystemGenerations()) {
274
+            if ($gen <= $this->maxSystemGenerations()) {
275 275
                 $has_records = true;
276 276
                 if ($mass_update) {
277
-                    $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' .
278
-                        ' :indi_id' . $i . ', :gen' . $i . ',' .
279
-                        ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')';
277
+                    $bindings_placeholders[] = '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.','.
278
+                        ' :indi_id'.$i.', :gen'.$i.','.
279
+                        ' :byear'.$i.', :byearest'.$i.', :dyear'.$i.', :dyearest'.$i.')';
280 280
                     $bindings_values += [
281
-                        'tree_id' . $i => $tree->id(),
282
-                        'user_id' . $i => $user->id(),
283
-                        'sosa' . $i => $row['sosa'],
284
-                        'indi_id' . $i => $row['indi'],
285
-                        'gen' . $i => $gen,
286
-                        'byear' . $i => $row['birth_year'],
287
-                        'byearest' . $i => $row['birth_year_est'],
288
-                        'dyear' . $i => $row['death_year'],
289
-                        'dyearest' . $i => $row['death_year_est']
281
+                        'tree_id'.$i => $tree->id(),
282
+                        'user_id'.$i => $user->id(),
283
+                        'sosa'.$i => $row['sosa'],
284
+                        'indi_id'.$i => $row['indi'],
285
+                        'gen'.$i => $gen,
286
+                        'byear'.$i => $row['birth_year'],
287
+                        'byearest'.$i => $row['birth_year_est'],
288
+                        'dyear'.$i => $row['death_year'],
289
+                        'dyearest'.$i => $row['death_year_est']
290 290
                     ];
291 291
                 } else {
292 292
                     DB::table('maj_sosa')->updateOrInsert(
293
-                        [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']],
293
+                        ['majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']],
294 294
                         [
295 295
                             'majs_i_id' => $row['indi'],
296 296
                             'majs_gen' => $gen,
@@ -306,12 +306,12 @@  discard block
 block discarded – undo
306 306
 
307 307
         if ($has_records && $mass_update) {
308 308
             DB::connection()->statement(
309
-                'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' .
310
-                ' (majs_gedcom_id, majs_user_id, majs_sosa,' .
311
-                '   majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' .
312
-                ' VALUES ' . implode(',', $bindings_placeholders) .
313
-                ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' .
314
-                '   majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' .
309
+                'INSERT INTO `'.DB::connection()->getTablePrefix().'maj_sosa`'.
310
+                ' (majs_gedcom_id, majs_user_id, majs_sosa,'.
311
+                '   majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)'.
312
+                ' VALUES '.implode(',', $bindings_placeholders).
313
+                ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),'.
314
+                '   majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),'.
315 315
                 '   majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)',
316 316
                 $bindings_values
317 317
             );
Please login to merge, or discard this patch.
Indentation   +272 added lines, -272 removed lines patch added patch discarded remove patch
@@ -30,291 +30,291 @@
 block discarded – undo
30 30
  */
31 31
 class SosaRecordsService
32 32
 {
33
-    private ?int $max_system_generations = null;
33
+	private ?int $max_system_generations = null;
34 34
 
35
-    /**
36
-     * Maximum number of generation the system is able to hold.
37
-     * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type
38
-     *
39
-     * @return int
40
-     */
41
-    public function maxSystemGenerations(): int
42
-    {
43
-        if ($this->max_system_generations === null) {
44
-            $this->max_system_generations = min(63, $this->generation(PHP_INT_MAX));
45
-        }
46
-        return $this->max_system_generations;
47
-    }
35
+	/**
36
+	 * Maximum number of generation the system is able to hold.
37
+	 * This is based on the size of the bigint SQL type (2^63) and the maximum PHP integer type
38
+	 *
39
+	 * @return int
40
+	 */
41
+	public function maxSystemGenerations(): int
42
+	{
43
+		if ($this->max_system_generations === null) {
44
+			$this->max_system_generations = min(63, $this->generation(PHP_INT_MAX));
45
+		}
46
+		return $this->max_system_generations;
47
+	}
48 48
 
49
-    /**
50
-     * Calculate the generation of a sosa
51
-     * Sosa 1 is of generation 1.
52
-     *
53
-     * @param int $sosa
54
-     * @return int
55
-     */
56
-    public function generation(int $sosa): int
57
-    {
58
-        return BigInteger::of($sosa)->getBitLength();
59
-    }
49
+	/**
50
+	 * Calculate the generation of a sosa
51
+	 * Sosa 1 is of generation 1.
52
+	 *
53
+	 * @param int $sosa
54
+	 * @return int
55
+	 */
56
+	public function generation(int $sosa): int
57
+	{
58
+		return BigInteger::of($sosa)->getBitLength();
59
+	}
60 60
 
61
-    /**
62
-     * Calculate the descendant sosa of the given sosa, at the given generation.
63
-     * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother).
64
-     *
65
-     * @param int $sosa
66
-     * @param int $gen
67
-     * @return int
68
-     */
69
-    public function sosaDescendantOf(int $sosa, int $gen): int
70
-    {
71
-        $gen_sosa = $this->generation($sosa);
72
-        return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa)
73
-            ->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN)
74
-            ->toInt();
75
-    }
61
+	/**
62
+	 * Calculate the descendant sosa of the given sosa, at the given generation.
63
+	 * For instance, the descendant of the Sosa 14 at generation 2 is Sosa 3 (mother).
64
+	 *
65
+	 * @param int $sosa
66
+	 * @param int $gen
67
+	 * @return int
68
+	 */
69
+	public function sosaDescendantOf(int $sosa, int $gen): int
70
+	{
71
+		$gen_sosa = $this->generation($sosa);
72
+		return $gen_sosa <= $gen ? $sosa : BigInteger::of($sosa)
73
+			->dividedBy(BigInteger::of(2)->power($this->generation($sosa) - $gen), RoundingMode::DOWN)
74
+			->toInt();
75
+	}
76 76
 
77
-    /**
78
-     * Check whether an individual is a Sosa ancestor.
79
-     *
80
-     * @param Tree $tree
81
-     * @param UserInterface $user
82
-     * @param Individual $indi
83
-     * @return bool
84
-     */
85
-    public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool
86
-    {
87
-        return $this->sosaNumbers($tree, $user, $indi)->count() > 0;
88
-    }
77
+	/**
78
+	 * Check whether an individual is a Sosa ancestor.
79
+	 *
80
+	 * @param Tree $tree
81
+	 * @param UserInterface $user
82
+	 * @param Individual $indi
83
+	 * @return bool
84
+	 */
85
+	public function isSosa(Tree $tree, UserInterface $user, Individual $indi): bool
86
+	{
87
+		return $this->sosaNumbers($tree, $user, $indi)->count() > 0;
88
+	}
89 89
 
90
-    /**
91
-     * Returns all Sosa numbers associated to an Individual
92
-     *
93
-     * @param Tree $tree
94
-     * @param UserInterface $user
95
-     * @param Individual $indi
96
-     * @return Collection<int, int>
97
-     */
98
-    public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection
99
-    {
100
-        return Registry::cache()->array()->remember(
101
-            'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(),
102
-            function () use ($tree, $user, $indi): Collection {
103
-                return DB::table('maj_sosa')
104
-                    ->select(['majs_sosa', 'majs_gen'])
105
-                    ->where('majs_gedcom_id', '=', $tree->id())
106
-                    ->where('majs_user_id', '=', $user->id())
107
-                    ->where('majs_i_id', '=', $indi->xref())
108
-                    ->orderBy('majs_sosa')
109
-                    ->get()->pluck('majs_gen', 'majs_sosa');
110
-            }
111
-        );
112
-    }
90
+	/**
91
+	 * Returns all Sosa numbers associated to an Individual
92
+	 *
93
+	 * @param Tree $tree
94
+	 * @param UserInterface $user
95
+	 * @param Individual $indi
96
+	 * @return Collection<int, int>
97
+	 */
98
+	public function sosaNumbers(Tree $tree, UserInterface $user, Individual $indi): Collection
99
+	{
100
+		return Registry::cache()->array()->remember(
101
+			'sosanumbers-' . $indi->xref() . '@' . $tree->id() . '-' . $user->id(),
102
+			function () use ($tree, $user, $indi): Collection {
103
+				return DB::table('maj_sosa')
104
+					->select(['majs_sosa', 'majs_gen'])
105
+					->where('majs_gedcom_id', '=', $tree->id())
106
+					->where('majs_user_id', '=', $user->id())
107
+					->where('majs_i_id', '=', $indi->xref())
108
+					->orderBy('majs_sosa')
109
+					->get()->pluck('majs_gen', 'majs_sosa');
110
+			}
111
+		);
112
+	}
113 113
 
114
-    /**
115
-     * Return a list of the Sosa ancestors across all generation
116
-     *
117
-     * @param Tree $tree
118
-     * @param UserInterface $user
119
-     * @return Collection<\stdClass>
120
-     */
121
-    public function listAncestors(Tree $tree, UserInterface $user): Collection
122
-    {
123
-        return DB::table('maj_sosa')
124
-            ->select(['majs_sosa', 'majs_i_id'])
125
-            ->where('majs_gedcom_id', '=', $tree->id())
126
-            ->where('majs_user_id', '=', $user->id())
127
-            ->orderBy('majs_sosa')
128
-            ->get();
129
-    }
114
+	/**
115
+	 * Return a list of the Sosa ancestors across all generation
116
+	 *
117
+	 * @param Tree $tree
118
+	 * @param UserInterface $user
119
+	 * @return Collection<\stdClass>
120
+	 */
121
+	public function listAncestors(Tree $tree, UserInterface $user): Collection
122
+	{
123
+		return DB::table('maj_sosa')
124
+			->select(['majs_sosa', 'majs_i_id'])
125
+			->where('majs_gedcom_id', '=', $tree->id())
126
+			->where('majs_user_id', '=', $user->id())
127
+			->orderBy('majs_sosa')
128
+			->get();
129
+	}
130 130
 
131
-    /**
132
-     * Return a list of the Sosa ancestors at a given generation
133
-     *
134
-     * @param Tree $tree
135
-     * @param UserInterface $user
136
-     * @param int $gen
137
-     * @return Collection<\stdClass>
138
-     */
139
-    public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection
140
-    {
141
-        return DB::table('maj_sosa')
142
-            ->select(['majs_sosa', 'majs_i_id'])
143
-            ->where('majs_gedcom_id', '=', $tree->id())
144
-            ->where('majs_user_id', '=', $user->id())
145
-            ->where('majs_gen', '=', $gen)
146
-            ->orderBy('majs_sosa')
147
-            ->get();
148
-    }
131
+	/**
132
+	 * Return a list of the Sosa ancestors at a given generation
133
+	 *
134
+	 * @param Tree $tree
135
+	 * @param UserInterface $user
136
+	 * @param int $gen
137
+	 * @return Collection<\stdClass>
138
+	 */
139
+	public function listAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection
140
+	{
141
+		return DB::table('maj_sosa')
142
+			->select(['majs_sosa', 'majs_i_id'])
143
+			->where('majs_gedcom_id', '=', $tree->id())
144
+			->where('majs_user_id', '=', $user->id())
145
+			->where('majs_gen', '=', $gen)
146
+			->orderBy('majs_sosa')
147
+			->get();
148
+	}
149 149
 
150
-    /**
151
-     * Return a list of the Sosa families at a given generation
152
-     *
153
-     * @param Tree $tree
154
-     * @param UserInterface $user
155
-     * @param int $gen
156
-     * @return Collection<\stdClass>
157
-     */
158
-    public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection
159
-    {
160
-        $table_prefix = DB::connection()->getTablePrefix();
161
-        return DB::table('families')
162
-            ->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void {
163
-                // Link to family husband
164
-                $join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id')
165
-                    ->on('families.f_husb', '=', 'sosa_husb.majs_i_id')
166
-                    ->where('sosa_husb.majs_gedcom_id', '=', $tree->id())
167
-                    ->where('sosa_husb.majs_user_id', '=', $user->id());
168
-            })
169
-            ->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void {
170
-                // Link to family husband
171
-                $join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id')
172
-                ->on('families.f_wife', '=', 'sosa_wife.majs_i_id')
173
-                ->where('sosa_wife.majs_gedcom_id', '=', $tree->id())
174
-                ->where('sosa_wife.majs_user_id', '=', $user->id());
175
-            })
176
-            ->select(['sosa_husb.majs_sosa', 'families.f_id'])
177
-            ->where('sosa_husb.majs_gen', '=', $gen)
178
-            ->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa')
179
-            ->orderBy('sosa_husb.majs_sosa')
180
-            ->get();
181
-    }
150
+	/**
151
+	 * Return a list of the Sosa families at a given generation
152
+	 *
153
+	 * @param Tree $tree
154
+	 * @param UserInterface $user
155
+	 * @param int $gen
156
+	 * @return Collection<\stdClass>
157
+	 */
158
+	public function listAncestorFamiliesAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection
159
+	{
160
+		$table_prefix = DB::connection()->getTablePrefix();
161
+		return DB::table('families')
162
+			->join('maj_sosa AS sosa_husb', function (JoinClause $join) use ($tree, $user): void {
163
+				// Link to family husband
164
+				$join->on('families.f_file', '=', 'sosa_husb.majs_gedcom_id')
165
+					->on('families.f_husb', '=', 'sosa_husb.majs_i_id')
166
+					->where('sosa_husb.majs_gedcom_id', '=', $tree->id())
167
+					->where('sosa_husb.majs_user_id', '=', $user->id());
168
+			})
169
+			->join('maj_sosa AS sosa_wife', function (JoinClause $join) use ($tree, $user): void {
170
+				// Link to family husband
171
+				$join->on('families.f_file', '=', 'sosa_wife.majs_gedcom_id')
172
+				->on('families.f_wife', '=', 'sosa_wife.majs_i_id')
173
+				->where('sosa_wife.majs_gedcom_id', '=', $tree->id())
174
+				->where('sosa_wife.majs_user_id', '=', $user->id());
175
+			})
176
+			->select(['sosa_husb.majs_sosa', 'families.f_id'])
177
+			->where('sosa_husb.majs_gen', '=', $gen)
178
+			->whereRaw($table_prefix . 'sosa_husb.majs_sosa + 1 = ' . $table_prefix . 'sosa_wife.majs_sosa')
179
+			->orderBy('sosa_husb.majs_sosa')
180
+			->get();
181
+	}
182 182
 
183
-    /**
184
-     * Return a list of Sosa ancestors missing at a given generation.
185
-     * It includes the reference of either parent if it is known.
186
-     *
187
-     * @param Tree $tree
188
-     * @param UserInterface $user
189
-     * @param int $gen
190
-     * @return Collection<\stdClass>
191
-     */
192
-    public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection
193
-    {
194
-        if ($gen === 1) {
195
-            return collect();
196
-        }
183
+	/**
184
+	 * Return a list of Sosa ancestors missing at a given generation.
185
+	 * It includes the reference of either parent if it is known.
186
+	 *
187
+	 * @param Tree $tree
188
+	 * @param UserInterface $user
189
+	 * @param int $gen
190
+	 * @return Collection<\stdClass>
191
+	 */
192
+	public function listMissingAncestorsAtGeneration(Tree $tree, UserInterface $user, int $gen): Collection
193
+	{
194
+		if ($gen === 1) {
195
+			return collect();
196
+		}
197 197
 
198
-        $table_prefix = DB::connection()->getTablePrefix();
199
-        return DB::table('maj_sosa AS sosa')
200
-            ->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id'])
201
-            ->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa')
202
-            ->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void {
203
-                // Link to sosa's father
204
-                $join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
205
-                    ->where('sosa_fat.majs_gedcom_id', '=', $tree->id())
206
-                    ->where('sosa_fat.majs_user_id', '=', $user->id());
207
-            })
208
-            ->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void {
209
-                // Link to sosa's mother
210
-                $join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
211
-                    ->where('sosa_mot.majs_gedcom_id', '=', $tree->id())
212
-                    ->where('sosa_mot.majs_user_id', '=', $user->id());
213
-            })
214
-            ->where('sosa.majs_gedcom_id', '=', $tree->id())
215
-            ->where('sosa.majs_user_id', '=', $user->id())
216
-            ->where('sosa.majs_gen', '=', $gen - 1)
217
-            ->where(function (Builder $query): void {
218
-                $query->whereNull('sosa_fat.majs_i_id')
219
-                    ->orWhereNull('sosa_mot.majs_i_id');
220
-            })
221
-            ->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id')
222
-            ->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)')
223
-            ->get();
224
-    }
198
+		$table_prefix = DB::connection()->getTablePrefix();
199
+		return DB::table('maj_sosa AS sosa')
200
+			->select(['sosa.majs_i_id', 'sosa_fat.majs_i_id AS majs_fat_id', 'sosa_mot.majs_i_id AS majs_mot_id'])
201
+			->selectRaw('MIN(' . $table_prefix . 'sosa.majs_sosa) AS majs_sosa')
202
+			->leftJoin('maj_sosa AS sosa_fat', function (JoinClause $join) use ($tree, $user, $table_prefix): void {
203
+				// Link to sosa's father
204
+				$join->whereRaw($table_prefix . 'sosa_fat.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa')
205
+					->where('sosa_fat.majs_gedcom_id', '=', $tree->id())
206
+					->where('sosa_fat.majs_user_id', '=', $user->id());
207
+			})
208
+			->leftJoin('maj_sosa AS sosa_mot', function (JoinClause $join) use ($tree, $user, $table_prefix): void {
209
+				// Link to sosa's mother
210
+				$join->whereRaw($table_prefix . 'sosa_mot.majs_sosa = 2 * ' . $table_prefix . 'sosa.majs_sosa + 1')
211
+					->where('sosa_mot.majs_gedcom_id', '=', $tree->id())
212
+					->where('sosa_mot.majs_user_id', '=', $user->id());
213
+			})
214
+			->where('sosa.majs_gedcom_id', '=', $tree->id())
215
+			->where('sosa.majs_user_id', '=', $user->id())
216
+			->where('sosa.majs_gen', '=', $gen - 1)
217
+			->where(function (Builder $query): void {
218
+				$query->whereNull('sosa_fat.majs_i_id')
219
+					->orWhereNull('sosa_mot.majs_i_id');
220
+			})
221
+			->groupBy('sosa.majs_i_id', 'sosa_fat.majs_i_id', 'sosa_mot.majs_i_id')
222
+			->orderByRaw('MIN(' . $table_prefix . 'sosa.majs_sosa)')
223
+			->get();
224
+	}
225 225
 
226
-    /**
227
-     * Remove all Sosa entries related to the gedcom file and user
228
-     *
229
-     * @param Tree $tree
230
-     * @param UserInterface $user
231
-     */
232
-    public function deleteAll(Tree $tree, UserInterface $user): void
233
-    {
234
-        DB::table('maj_sosa')
235
-            ->where('majs_gedcom_id', '=', $tree->id())
236
-            ->where('majs_user_id', '=', $user->id())
237
-            ->delete();
238
-    }
226
+	/**
227
+	 * Remove all Sosa entries related to the gedcom file and user
228
+	 *
229
+	 * @param Tree $tree
230
+	 * @param UserInterface $user
231
+	 */
232
+	public function deleteAll(Tree $tree, UserInterface $user): void
233
+	{
234
+		DB::table('maj_sosa')
235
+			->where('majs_gedcom_id', '=', $tree->id())
236
+			->where('majs_user_id', '=', $user->id())
237
+			->delete();
238
+	}
239 239
 
240
-    /**
241
-     *
242
-     * @param Tree $tree
243
-     * @param UserInterface $user
244
-     * @param int $sosa
245
-     */
246
-    public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void
247
-    {
248
-        DB::table('maj_sosa')
249
-            ->where('majs_gedcom_id', '=', $tree->id())
250
-            ->where('majs_user_id', '=', $user->id())
251
-            ->where('majs_sosa', '>=', $sosa)
252
-            ->whereRaw(
253
-                'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?',
254
-                [$this->generation($sosa), $sosa]
255
-            )
256
-            ->delete();
257
-    }
240
+	/**
241
+	 *
242
+	 * @param Tree $tree
243
+	 * @param UserInterface $user
244
+	 * @param int $sosa
245
+	 */
246
+	public function deleteAncestorsFrom(Tree $tree, UserInterface $user, int $sosa): void
247
+	{
248
+		DB::table('maj_sosa')
249
+			->where('majs_gedcom_id', '=', $tree->id())
250
+			->where('majs_user_id', '=', $user->id())
251
+			->where('majs_sosa', '>=', $sosa)
252
+			->whereRaw(
253
+				'FLOOR(majs_sosa / (POW(2, (majs_gen - ?)))) = ?',
254
+				[$this->generation($sosa), $sosa]
255
+			)
256
+			->delete();
257
+	}
258 258
 
259
-    /**
260
-     * Insert (or update if already existing) a list of Sosa individuals
261
-     *
262
-     * @param Tree $tree
263
-     * @param UserInterface $user
264
-     * @param array<array<string,mixed>> $sosa_records
265
-     */
266
-    public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void
267
-    {
268
-        $mass_update = DB::connection()->getDriverName() === 'mysql';
259
+	/**
260
+	 * Insert (or update if already existing) a list of Sosa individuals
261
+	 *
262
+	 * @param Tree $tree
263
+	 * @param UserInterface $user
264
+	 * @param array<array<string,mixed>> $sosa_records
265
+	 */
266
+	public function insertOrUpdate(Tree $tree, UserInterface $user, array $sosa_records): void
267
+	{
268
+		$mass_update = DB::connection()->getDriverName() === 'mysql';
269 269
 
270
-        $bindings_placeholders = $bindings_values = [];
271
-        $has_records = false;
272
-        foreach ($sosa_records as $i => $row) {
273
-            $gen = $this->generation($row['sosa']);
274
-            if ($gen <=  $this->maxSystemGenerations()) {
275
-                $has_records = true;
276
-                if ($mass_update) {
277
-                    $bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' .
278
-                        ' :indi_id' . $i . ', :gen' . $i . ',' .
279
-                        ' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')';
280
-                    $bindings_values += [
281
-                        'tree_id' . $i => $tree->id(),
282
-                        'user_id' . $i => $user->id(),
283
-                        'sosa' . $i => $row['sosa'],
284
-                        'indi_id' . $i => $row['indi'],
285
-                        'gen' . $i => $gen,
286
-                        'byear' . $i => $row['birth_year'],
287
-                        'byearest' . $i => $row['birth_year_est'],
288
-                        'dyear' . $i => $row['death_year'],
289
-                        'dyearest' . $i => $row['death_year_est']
290
-                    ];
291
-                } else {
292
-                    DB::table('maj_sosa')->updateOrInsert(
293
-                        [ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']],
294
-                        [
295
-                            'majs_i_id' => $row['indi'],
296
-                            'majs_gen' => $gen,
297
-                            'majs_birth_year' => $row['birth_year'],
298
-                            'majs_birth_year_est' => $row['birth_year_est'],
299
-                            'majs_death_year' => $row['death_year'],
300
-                            'majs_death_year_est' => $row['death_year_est']
301
-                        ]
302
-                    );
303
-                }
304
-            }
305
-        }
270
+		$bindings_placeholders = $bindings_values = [];
271
+		$has_records = false;
272
+		foreach ($sosa_records as $i => $row) {
273
+			$gen = $this->generation($row['sosa']);
274
+			if ($gen <=  $this->maxSystemGenerations()) {
275
+				$has_records = true;
276
+				if ($mass_update) {
277
+					$bindings_placeholders[] = '(:tree_id' . $i . ', :user_id' . $i . ', :sosa' . $i . ',' .
278
+						' :indi_id' . $i . ', :gen' . $i . ',' .
279
+						' :byear' . $i . ', :byearest' . $i . ', :dyear' . $i . ', :dyearest' . $i . ')';
280
+					$bindings_values += [
281
+						'tree_id' . $i => $tree->id(),
282
+						'user_id' . $i => $user->id(),
283
+						'sosa' . $i => $row['sosa'],
284
+						'indi_id' . $i => $row['indi'],
285
+						'gen' . $i => $gen,
286
+						'byear' . $i => $row['birth_year'],
287
+						'byearest' . $i => $row['birth_year_est'],
288
+						'dyear' . $i => $row['death_year'],
289
+						'dyearest' . $i => $row['death_year_est']
290
+					];
291
+				} else {
292
+					DB::table('maj_sosa')->updateOrInsert(
293
+						[ 'majs_gedcom_id' => $tree->id(), 'majs_user_id' => $user->id(), 'majs_sosa' => $row['sosa']],
294
+						[
295
+							'majs_i_id' => $row['indi'],
296
+							'majs_gen' => $gen,
297
+							'majs_birth_year' => $row['birth_year'],
298
+							'majs_birth_year_est' => $row['birth_year_est'],
299
+							'majs_death_year' => $row['death_year'],
300
+							'majs_death_year_est' => $row['death_year_est']
301
+						]
302
+					);
303
+				}
304
+			}
305
+		}
306 306
 
307
-        if ($has_records && $mass_update) {
308
-            DB::connection()->statement(
309
-                'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' .
310
-                ' (majs_gedcom_id, majs_user_id, majs_sosa,' .
311
-                '   majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' .
312
-                ' VALUES ' . implode(',', $bindings_placeholders) .
313
-                ' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' .
314
-                '   majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' .
315
-                '   majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)',
316
-                $bindings_values
317
-            );
318
-        }
319
-    }
307
+		if ($has_records && $mass_update) {
308
+			DB::connection()->statement(
309
+				'INSERT INTO `' . DB::connection()->getTablePrefix() . 'maj_sosa`' .
310
+				' (majs_gedcom_id, majs_user_id, majs_sosa,' .
311
+				'   majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' .
312
+				' VALUES ' . implode(',', $bindings_placeholders) .
313
+				' ON DUPLICATE KEY UPDATE majs_i_id = VALUES(majs_i_id), majs_gen = VALUES(majs_gen),' .
314
+				'   majs_birth_year = VALUES(majs_birth_year), majs_birth_year_est = VALUES(majs_birth_year_est),' .
315
+				'   majs_death_year = VALUES(majs_death_year), majs_death_year_est = VALUES(majs_death_year_est)',
316
+				$bindings_values
317
+			);
318
+		}
319
+	}
320 320
 }
Please login to merge, or discard this patch.
app/Module/Hooks/Hooks/SosaMissingDatatablesExtenderCollector.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
  * @extends AbstractHookCollector<SosaMissingDatatablesExtenderInterface>
26 26
  */
27 27
 class SosaMissingDatatablesExtenderCollector extends AbstractHookCollector implements
28
-    SosaMissingDatatablesExtenderInterface
28
+	SosaMissingDatatablesExtenderInterface
29 29
 {
30
-    /**
31
-     * {@inheritDoc}
32
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
-     */
34
-    public function title(): string
35
-    {
36
-        return I18N::translate('Columns extender for tables of missing ancestors');
37
-    }
30
+	/**
31
+	 * {@inheritDoc}
32
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::title()
33
+	 */
34
+	public function title(): string
35
+	{
36
+		return I18N::translate('Columns extender for tables of missing ancestors');
37
+	}
38 38
 
39
-    /**
40
-     * {@inheritDoc}
41
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
-     */
43
-    public function description(): string
44
-    {
45
-        return I18N::translate('Add additional columns to tables of missing ancestors');
46
-    }
39
+	/**
40
+	 * {@inheritDoc}
41
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::description()
42
+	 */
43
+	public function description(): string
44
+	{
45
+		return I18N::translate('Add additional columns to tables of missing ancestors');
46
+	}
47 47
 
48
-    /**
49
-     * {@inheritDoc}
50
-     * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
-     */
52
-    public function hookInterface(): string
53
-    {
54
-        return SosaMissingDatatablesExtenderInterface::class;
55
-    }
48
+	/**
49
+	 * {@inheritDoc}
50
+	 * @see \MyArtJaub\Webtrees\Common\Hooks\AbstractHookCollector::hookInterface()
51
+	 */
52
+	public function hookInterface(): string
53
+	{
54
+		return SosaMissingDatatablesExtenderInterface::class;
55
+	}
56 56
 
57
-    /**
58
-     * {@inheritDoc}
59
-     * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaMissingDatatablesExtenderInterface::sosaMissingColumns()
60
-     */
61
-    public function sosaMissingColumns(iterable $records): array
62
-    {
63
-        $result = [];
64
-        foreach ($this->hooks() as $hook) {
65
-            $result += $hook->sosaMissingColumns($records);
66
-        }
67
-        return $result;
68
-    }
57
+	/**
58
+	 * {@inheritDoc}
59
+	 * @see \MyArtJaub\Webtrees\Contracts\Hooks\SosaMissingDatatablesExtenderInterface::sosaMissingColumns()
60
+	 */
61
+	public function sosaMissingColumns(iterable $records): array
62
+	{
63
+		$result = [];
64
+		foreach ($this->hooks() as $hook) {
65
+			$result += $hook->sosaMissingColumns($records);
66
+		}
67
+		return $result;
68
+	}
69 69
 }
Please login to merge, or discard this patch.