Passed
Push — master ( 9fd6b6...ce1e09 )
by Jonathan
05:22
created
src/Webtrees/Module/Sosa/SosaStatsController.php 1 patch
Braces   +13 added lines, -6 removed lines patch added patch discarded remove patch
@@ -93,8 +93,12 @@  discard block
 block discarded – undo
93 93
             foreach($stats_gen as $gen => $tab){
94 94
                 $genY1= I18N::translate('-');
95 95
                 $genY2= I18N::translate('-');
96
-                if($tab['firstBirth']>0) $genY1=$tab['firstEstimatedBirth'];
97
-                if($tab['lastBirth']>0) $genY2=$tab['lastEstimatedBirth'];
96
+                if($tab['firstBirth']>0) {
97
+                	$genY1=$tab['firstEstimatedBirth'];
98
+                }
99
+                if($tab['lastBirth']>0) {
100
+                	$genY2=$tab['lastEstimatedBirth'];
101
+                }
98 102
                 $total_theoretical += $gen_theoretical;
99 103
                 $perc_sosa_count_theor = Functions::safeDivision($tab['sosaCount'], $gen_theoretical);
100 104
                 $missing=2*$prev_known - $tab['sosaCount'];
@@ -169,7 +173,9 @@  discard block
 block discarded – undo
169 173
      private function htmlAncestorDispersionG2()
170 174
     {
171 175
         $ancestorsDispGen2 = $this->sosa_provider->getAncestorDispersionForGen(2);
172
-        if(count($ancestorsDispGen2) == 0) return;
176
+        if(count($ancestorsDispGen2) == 0) {
177
+        	return;
178
+        }
173 179
         
174 180
         $size = '600x300';
175 181
         
@@ -251,7 +257,9 @@  discard block
 block discarded – undo
251 257
      */
252 258
     private function htmlAncestorGenDepthG3() {
253 259
         $ancestorsGenDepth3 = $this->sosa_provider->getGenerationDepthStatsAtGen(3);
254
-        if(count($ancestorsGenDepth3) == 0) return;
260
+        if(count($ancestorsGenDepth3) == 0) {
261
+        	return;
262
+        }
255 263
         
256 264
         $ancestors = array();
257 265
         $chd_mean = array();
@@ -262,8 +270,7 @@  discard block
 block discarded – undo
262 270
             if($ancestor !== null && $ancestor->canShowName()) {
263 271
                 $tmp = $ancestor->getAllNames();
264 272
                 $ancestors[] = Filter::escapeUrl($tmp[$ancestor->getPrimaryName()]['fullNN']);
265
-            }
266
-            else {
273
+            } else {
267 274
                 $ancestors[] = I18N::translate('Sosa %s', I18N::number($sosa));
268 275
             }
269 276
             $chd_mean[] = $genDepthStat['mean_gen_depth'];
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Model/SosaProvider.php 1 patch
Braces   +80 added lines, -31 removed lines patch added patch discarded remove patch
@@ -84,21 +84,25 @@  discard block
 block discarded – undo
84 84
      * @param User $user
85 85
      */
86 86
     public function __construct(Tree $tree, User $user = null) {
87
-        if(self::$default_user === null) 
88
-            self::$default_user = User::find(-1);
87
+        if(self::$default_user === null) {
88
+                    self::$default_user = User::find(-1);
89
+        }
89 90
         
90 91
         $this->tree = $tree;
91 92
         $this->user = $user;
92 93
         $this->is_setup = true;
93
-        if($this->user === null) $this->user = Auth::user();
94
-        if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user;
94
+        if($this->user === null) {
95
+        	$this->user = Auth::user();
96
+        }
97
+        if(strlen($this->user->getUserId()) == 0) {
98
+        	$this->user = self::$default_user;
99
+        }
95 100
         
96 101
         // Check if the user, or the default user, has a root already setup;
97 102
         if(empty($this->getRootIndiId())) {
98 103
             if($this->user == self::$default_user) {  // If the default user is not setup
99 104
                 $this->is_setup = false;
100
-            }
101
-            else {
105
+            } else {
102 106
                 $this->user = self::$default_user;
103 107
                 $this->is_setup = $this->getRootIndiId() === null;
104 108
             }            
@@ -159,7 +163,9 @@  discard block
 block discarded – undo
159 163
      * Remove all Sosa entries related to the gedcom file and user
160 164
      */
161 165
     public function deleteAll() {
162
-        if(!$this->is_setup) return;
166
+        if(!$this->is_setup) {
167
+        	return;
168
+        }
163 169
         Database::prepare(
164 170
             'DELETE FROM `##maj_sosa`'.
165 171
             ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
@@ -175,7 +181,9 @@  discard block
 block discarded – undo
175 181
      * @param int $sosa
176 182
      */
177 183
     public function deleteAncestors($sosa) {
178
-        if(!$this->is_setup) return;
184
+        if(!$this->is_setup) {
185
+        	return;
186
+        }
179 187
         $gen = Functions::getGeneration($sosa);
180 188
         Database::prepare(
181 189
             'DELETE FROM `##maj_sosa`'.
@@ -195,7 +203,9 @@  discard block
 block discarded – undo
195 203
      * @param array $sosa_records
196 204
      */
197 205
     public function insertOrUpdate($sosa_records) {
198
-        if(!$this->is_setup) return;
206
+        if(!$this->is_setup) {
207
+        	return;
208
+        }
199 209
         
200 210
         $treeid = $this->tree->getTreeId();
201 211
         $userid = $this->user->getUserId();
@@ -244,7 +254,9 @@  discard block
 block discarded – undo
244 254
      * @return array Array of sosa numbers
245 255
      */
246 256
     public function getSosaNumbers(Individual $indi) {
247
-        if(!$this->is_setup) return array();
257
+        if(!$this->is_setup) {
258
+        	return array();
259
+        }
248 260
         return Database::prepare(
249 261
                 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
250 262
                 ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -261,7 +273,9 @@  discard block
 block discarded – undo
261 273
      * @return number Last generation if found, 1 otherwise
262 274
      */
263 275
     public function getLastGeneration() {
264
-        if(!$this->is_setup) return;
276
+        if(!$this->is_setup) {
277
+        	return;
278
+        }
265 279
         return Database::prepare(
266 280
                 'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
267 281
                 ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -281,7 +295,9 @@  discard block
 block discarded – undo
281 295
      * @return array Associative array of Sosa ancestors, with their generation, comma separated
282 296
      */
283 297
     public function getAllSosaWithGenerations(){
284
-        if(!$this->is_setup) return array();
298
+        if(!$this->is_setup) {
299
+        	return array();
300
+        }
285 301
         return Database::prepare(
286 302
             'SELECT majs_i_id AS indi,' .
287 303
             ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
@@ -301,9 +317,12 @@  discard block
 block discarded – undo
301 317
      * @return array Array of Sosa individuals
302 318
      */
303 319
     public function getSosaListAtGeneration($gen){
304
-        if(!$this->is_setup) return array();
305
-        if(!$this->sosa_list_by_gen)
306
-            $this->sosa_list_by_gen = array();
320
+        if(!$this->is_setup) {
321
+        	return array();
322
+        }
323
+        if(!$this->sosa_list_by_gen) {
324
+                    $this->sosa_list_by_gen = array();
325
+        }
307 326
         
308 327
         if($gen){
309 328
             if(!isset($this->sosa_list_by_gen[$gen])){
@@ -332,9 +351,12 @@  discard block
 block discarded – undo
332 351
      * @return array Array of Sosa families
333 352
      */
334 353
     public function getFamilySosaListAtGeneration($gen){
335
-        if(!$this->is_setup) return array();
336
-        if(!$this->sosa_fam_list_by_gen)
337
-            $this->sosa_fam_list_by_gen = array();
354
+        if(!$this->is_setup) {
355
+        	return array();
356
+        }
357
+        if(!$this->sosa_fam_list_by_gen) {
358
+                    $this->sosa_fam_list_by_gen = array();
359
+        }
338 360
         
339 361
         if($gen){
340 362
             if(!isset($this->sosa_fam_list_by_gen[$gen])){
@@ -368,7 +390,9 @@  discard block
 block discarded – undo
368 390
      * @return array Array of Sosa individuals
369 391
      */
370 392
     public function getMissingSosaListAtGeneration($gen){
371
-        if(!$this->is_setup) return array();    
393
+        if(!$this->is_setup) {
394
+        	return array();
395
+        }
372 396
         if($gen){
373 397
             return $this->sosa_list_by_gen[$gen] = Database::prepare(
374 398
                 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'.
@@ -408,7 +432,9 @@  discard block
 block discarded – undo
408 432
      * @return array Statistics array
409 433
      */
410 434
     public function getStatisticsByGeneration() {
411
-        if(!$this->is_setup) return array();
435
+        if(!$this->is_setup) {
436
+        	return array();
437
+        }
412 438
         if(!$this->statistics_tab) {
413 439
             $this->statistics_tab = array();
414 440
             if($maxGeneration = $this->getLastGeneration()) {
@@ -436,7 +462,9 @@  discard block
 block discarded – undo
436 462
 	 * @return int
437 463
 	 */
438 464
 	public function getTotalIndividuals() {
439
-	    if(!$this->is_setup) return 0;
465
+	    if(!$this->is_setup) {
466
+	    	return 0;
467
+	    }
440 468
 	    return Database::prepare(
441 469
 	        'SELECT COUNT(*) FROM `##individuals`' .
442 470
 	        ' WHERE i_file = :tree_id')
@@ -450,7 +478,9 @@  discard block
 block discarded – undo
450 478
      * @return number Number of Sosas
451 479
      */
452 480
     public function getSosaCount(){
453
-        if(!$this->is_setup) return 0;
481
+        if(!$this->is_setup) {
482
+        	return 0;
483
+        }
454 484
         return Database::prepare(
455 485
             'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' .
456 486
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
@@ -467,7 +497,9 @@  discard block
 block discarded – undo
467 497
      * @return number Number of Sosas in generation
468 498
      */
469 499
     public function getSosaCountAtGeneration($gen){
470
-        if(!$this->is_setup) return 0;
500
+        if(!$this->is_setup) {
501
+        	return 0;
502
+        }
471 503
         return Database::prepare(
472 504
             'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' .
473 505
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -486,7 +518,9 @@  discard block
 block discarded – undo
486 518
      * @return number Total number of Sosas up to generation
487 519
      */
488 520
     public function getSosaCountUpToGeneration($gen){
489
-        if(!$this->is_setup) return 0;
521
+        if(!$this->is_setup) {
522
+        	return 0;
523
+        }
490 524
         return Database::prepare(
491 525
             'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' .
492 526
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -504,7 +538,9 @@  discard block
 block discarded – undo
504 538
      * @return number Total number of distinct individual
505 539
      */
506 540
     public function getDifferentSosaCount(){
507
-        if(!$this->is_setup) return 0;
541
+        if(!$this->is_setup) {
542
+        	return 0;
543
+        }
508 544
         return Database::prepare(
509 545
             'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
510 546
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
@@ -521,7 +557,9 @@  discard block
 block discarded – undo
521 557
      * @return number Number of distinct Sosa individuals up to generation
522 558
      */
523 559
     public function getDifferentSosaCountUpToGeneration($gen){
524
-        if(!$this->is_setup) return 0;
560
+        if(!$this->is_setup) {
561
+        	return 0;
562
+        }
525 563
         return Database::prepare(
526 564
             'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
527 565
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -546,7 +584,9 @@  discard block
 block discarded – undo
546 584
      * @return array Birth statistics array
547 585
      */
548 586
     public function getStatsBirthYearInGeneration($gen){
549
-        if(!$this->is_setup) return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0);
587
+        if(!$this->is_setup) {
588
+        	return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0);
589
+        }
550 590
         return Database::prepare(
551 591
             'SELECT'.
552 592
             ' MIN(majs_birth_year) AS first, MIN(majs_birth_year_est) AS first_est,'.
@@ -568,7 +608,9 @@  discard block
 block discarded – undo
568 608
      * @return number|NULL Mean generation time
569 609
      */
570 610
     public function getMeanGenerationTime(){
571
-        if(!$this->is_setup) return;
611
+        if(!$this->is_setup) {
612
+        	return;
613
+        }
572 614
         if(!$this->statistics_tab){
573 615
             $this->getStatisticsByGeneration();
574 616
         }
@@ -610,7 +652,9 @@  discard block
 block discarded – undo
610 652
      * @return array
611 653
      */
612 654
     public function getGenerationDepthStatsAtGen($gen) {
613
-        if(!$this->is_setup) return array();
655
+        if(!$this->is_setup) {
656
+        	return array();
657
+        }
614 658
         $gen_depth_stats_raw = Database::prepare(
615 659
             'SELECT stats_by_gen.root_ancestor AS root_ancestor_sosa,'.
616 660
             '   sosa_list.majs_i_id as root_ancestor_id,'.
@@ -685,7 +729,10 @@  discard block
 block discarded – undo
685 729
      * @return array
686 730
      */
687 731
     public function getAncestorDispersionForGen($gen) {
688
-        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
732
+        if(!$this->is_setup || $gen > 11) {
733
+        	return array();
734
+        }
735
+        // Going further than 11 gen will be out of range in the query
689 736
         return Database::prepare(
690 737
             'SELECT branches, count(i_id)'.
691 738
             ' FROM ('.
@@ -725,7 +772,9 @@  discard block
 block discarded – undo
725 772
      * @return array 
726 773
      */
727 774
     public function getTopMultiSosaAncestorsNoTies($limit) {
728
-        if(!$this->is_setup) return array();
775
+        if(!$this->is_setup) {
776
+        	return array();
777
+        }
729 778
         return Database::prepare(
730 779
             'SELECT sosa_i_id, sosa_count FROM ('.
731 780
             '   SELECT'.
Please login to merge, or discard this patch.