Passed
Push — master ( e8097c...9fd6b6 )
by Jonathan
05:26
created
src/Webtrees/Module/Sosa/SosaStatsController.php 1 patch
Braces   +9 added lines, -3 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
                 $gen_equiv += $perc_sosa_count_theor;
@@ -154,7 +158,9 @@  discard block
 block discarded – undo
154 158
      private function htmlAncestorDispersionG2()
155 159
     {
156 160
         $ancestorsDispGen2 = $this->sosa_provider->getAncestorDispersionForGen(2);
157
-        if(count($ancestorsDispGen2) == 0) return;
161
+        if(count($ancestorsDispGen2) == 0) {
162
+        	return;
163
+        }
158 164
         
159 165
         $size = '600x300';
160 166
         
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Model/SosaProvider.php 1 patch
Braces   +77 added lines, -30 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
             }            
@@ -141,7 +145,9 @@  discard block
 block discarded – undo
141 145
      * Remove all Sosa entries related to the gedcom file and user
142 146
      */
143 147
     public function deleteAll() {
144
-        if(!$this->is_setup) return;
148
+        if(!$this->is_setup) {
149
+        	return;
150
+        }
145 151
         Database::prepare(
146 152
             'DELETE FROM `##maj_sosa`'.
147 153
             ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
@@ -157,7 +163,9 @@  discard block
 block discarded – undo
157 163
      * @param int $sosa
158 164
      */
159 165
     public function deleteAncestors($sosa) {
160
-        if(!$this->is_setup) return;
166
+        if(!$this->is_setup) {
167
+        	return;
168
+        }
161 169
         $gen = Functions::getGeneration($sosa);
162 170
         Database::prepare(
163 171
             'DELETE FROM `##maj_sosa`'.
@@ -177,7 +185,9 @@  discard block
 block discarded – undo
177 185
      * @param array $sosa_records
178 186
      */
179 187
     public function insertOrUpdate($sosa_records) {
180
-        if(!$this->is_setup) return;
188
+        if(!$this->is_setup) {
189
+        	return;
190
+        }
181 191
         
182 192
         $treeid = $this->tree->getTreeId();
183 193
         $userid = $this->user->getUserId();
@@ -226,7 +236,9 @@  discard block
 block discarded – undo
226 236
      * @return array Array of sosa numbers
227 237
      */
228 238
     public function getSosaNumbers(Individual $indi) {
229
-        if(!$this->is_setup) return array();
239
+        if(!$this->is_setup) {
240
+        	return array();
241
+        }
230 242
         return Database::prepare(
231 243
                 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
232 244
                 ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -243,7 +255,9 @@  discard block
 block discarded – undo
243 255
      * @return number Last generation if found, 1 otherwise
244 256
      */
245 257
     public function getLastGeneration() {
246
-        if(!$this->is_setup) return;
258
+        if(!$this->is_setup) {
259
+        	return;
260
+        }
247 261
         return Database::prepare(
248 262
                 'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
249 263
                 ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -263,7 +277,9 @@  discard block
 block discarded – undo
263 277
      * @return array Associative array of Sosa ancestors, with their generation, comma separated
264 278
      */
265 279
     public function getAllSosaWithGenerations(){
266
-        if(!$this->is_setup) return array();
280
+        if(!$this->is_setup) {
281
+        	return array();
282
+        }
267 283
         return Database::prepare(
268 284
             'SELECT majs_i_id AS indi,' .
269 285
             ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
@@ -283,9 +299,12 @@  discard block
 block discarded – undo
283 299
      * @return array Array of Sosa individuals
284 300
      */
285 301
     public function getSosaListAtGeneration($gen){
286
-        if(!$this->is_setup) return array();
287
-        if(!$this->sosa_list_by_gen)
288
-            $this->sosa_list_by_gen = array();
302
+        if(!$this->is_setup) {
303
+        	return array();
304
+        }
305
+        if(!$this->sosa_list_by_gen) {
306
+                    $this->sosa_list_by_gen = array();
307
+        }
289 308
         
290 309
         if($gen){
291 310
             if(!isset($this->sosa_list_by_gen[$gen])){
@@ -314,9 +333,12 @@  discard block
 block discarded – undo
314 333
      * @return array Array of Sosa families
315 334
      */
316 335
     public function getFamilySosaListAtGeneration($gen){
317
-        if(!$this->is_setup) return array();
318
-        if(!$this->sosa_fam_list_by_gen)
319
-            $this->sosa_fam_list_by_gen = array();
336
+        if(!$this->is_setup) {
337
+        	return array();
338
+        }
339
+        if(!$this->sosa_fam_list_by_gen) {
340
+                    $this->sosa_fam_list_by_gen = array();
341
+        }
320 342
         
321 343
         if($gen){
322 344
             if(!isset($this->sosa_fam_list_by_gen[$gen])){
@@ -350,7 +372,9 @@  discard block
 block discarded – undo
350 372
      * @return array Array of Sosa individuals
351 373
      */
352 374
     public function getMissingSosaListAtGeneration($gen){
353
-        if(!$this->is_setup) return array();    
375
+        if(!$this->is_setup) {
376
+        	return array();
377
+        }
354 378
         if($gen){
355 379
             return $this->sosa_list_by_gen[$gen] = Database::prepare(
356 380
                 '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'.
@@ -390,7 +414,9 @@  discard block
 block discarded – undo
390 414
      * @return array Statistics array
391 415
      */
392 416
     public function getStatisticsByGeneration() {
393
-        if(!$this->is_setup) return array();
417
+        if(!$this->is_setup) {
418
+        	return array();
419
+        }
394 420
         if(!$this->statistics_tab) {
395 421
             $this->statistics_tab = array();
396 422
             if($maxGeneration = $this->getLastGeneration()) {
@@ -418,7 +444,9 @@  discard block
 block discarded – undo
418 444
 	 * @return int
419 445
 	 */
420 446
 	public function getTotalIndividuals() {
421
-	    if(!$this->is_setup) return 0;
447
+	    if(!$this->is_setup) {
448
+	    	return 0;
449
+	    }
422 450
 	    return Database::prepare(
423 451
 	        'SELECT COUNT(*) FROM `##individuals`' .
424 452
 	        ' WHERE i_file = :tree_id')
@@ -432,7 +460,9 @@  discard block
 block discarded – undo
432 460
      * @return number Number of Sosas
433 461
      */
434 462
     public function getSosaCount(){
435
-        if(!$this->is_setup) return 0;
463
+        if(!$this->is_setup) {
464
+        	return 0;
465
+        }
436 466
         return Database::prepare(
437 467
             'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' .
438 468
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
@@ -449,7 +479,9 @@  discard block
 block discarded – undo
449 479
      * @return number Number of Sosas in generation
450 480
      */
451 481
     public function getSosaCountAtGeneration($gen){
452
-        if(!$this->is_setup) return 0;
482
+        if(!$this->is_setup) {
483
+        	return 0;
484
+        }
453 485
         return Database::prepare(
454 486
             'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' .
455 487
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -468,7 +500,9 @@  discard block
 block discarded – undo
468 500
      * @return number Total number of Sosas up to generation
469 501
      */
470 502
     public function getSosaCountUpToGeneration($gen){
471
-        if(!$this->is_setup) return 0;
503
+        if(!$this->is_setup) {
504
+        	return 0;
505
+        }
472 506
         return Database::prepare(
473 507
             'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' .
474 508
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -486,7 +520,9 @@  discard block
 block discarded – undo
486 520
      * @return number Total number of distinct individual
487 521
      */
488 522
     public function getDifferentSosaCount(){
489
-        if(!$this->is_setup) return 0;
523
+        if(!$this->is_setup) {
524
+        	return 0;
525
+        }
490 526
         return Database::prepare(
491 527
             'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
492 528
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
@@ -503,7 +539,9 @@  discard block
 block discarded – undo
503 539
      * @return number Number of distinct Sosa individuals up to generation
504 540
      */
505 541
     public function getDifferentSosaCountUpToGeneration($gen){
506
-        if(!$this->is_setup) return 0;
542
+        if(!$this->is_setup) {
543
+        	return 0;
544
+        }
507 545
         return Database::prepare(
508 546
             'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
509 547
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -528,7 +566,9 @@  discard block
 block discarded – undo
528 566
      * @return array Birth statistics array
529 567
      */
530 568
     public function getStatsBirthYearInGeneration($gen){
531
-        if(!$this->is_setup) return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0);
569
+        if(!$this->is_setup) {
570
+        	return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0);
571
+        }
532 572
         return Database::prepare(
533 573
             'SELECT'.
534 574
             ' MIN(majs_birth_year) AS first, MIN(majs_birth_year_est) AS first_est,'.
@@ -550,7 +590,9 @@  discard block
 block discarded – undo
550 590
      * @return number|NULL Mean generation time
551 591
      */
552 592
     public function getMeanGenerationTime(){
553
-        if(!$this->is_setup) return;
593
+        if(!$this->is_setup) {
594
+        	return;
595
+        }
554 596
         if(!$this->statistics_tab){
555 597
             $this->getStatisticsByGeneration();
556 598
         }
@@ -596,7 +638,10 @@  discard block
 block discarded – undo
596 638
      * @return array
597 639
      */
598 640
     public function getAncestorDispersionForGen($gen) {
599
-        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
641
+        if(!$this->is_setup || $gen > 11) {
642
+        	return array();
643
+        }
644
+        // Going further than 11 gen will be out of range in the query
600 645
         return Database::prepare(
601 646
             'SELECT branches, count(i_id)'.
602 647
             ' FROM ('.
@@ -636,7 +681,9 @@  discard block
 block discarded – undo
636 681
      * @return array 
637 682
      */
638 683
     public function getTopMultiSosaAncestorsNoTies($limit) {
639
-        if(!$this->is_setup) return array();
684
+        if(!$this->is_setup) {
685
+        	return array();
686
+        }
640 687
         return Database::prepare(
641 688
             'SELECT sosa_i_id, sosa_count FROM ('.
642 689
             '   SELECT'.
Please login to merge, or discard this patch.