Passed
Push — master ( e8097c...9fd6b6 )
by Jonathan
05:26
created
src/Webtrees/Module/Sosa/Model/SosaCalculator.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -19,121 +19,121 @@
 block discarded – undo
19 19
  */
20 20
 class SosaCalculator {
21 21
     
22
-    /**
23
-     * Maximium size for the temporary Sosa table
24
-     * @var int TMP_SOSA_TABLE_LIMIT
25
-     */
26
-    const TMP_SOSA_TABLE_LIMIT = 1000;
22
+	/**
23
+	 * Maximium size for the temporary Sosa table
24
+	 * @var int TMP_SOSA_TABLE_LIMIT
25
+	 */
26
+	const TMP_SOSA_TABLE_LIMIT = 1000;
27 27
     
28
-    /**
29
-     * Reference user
30
-     * @var Fisharebest\Webtrees\User $user
31
-     */
32
-    protected $user;
28
+	/**
29
+	 * Reference user
30
+	 * @var Fisharebest\Webtrees\User $user
31
+	 */
32
+	protected $user;
33 33
     
34
-    /**
35
-     * Reference tree
36
-     * @var Fisharebest\Webtrees\Tree $tree
37
-     */
38
-    protected $tree;
34
+	/**
35
+	 * Reference tree
36
+	 * @var Fisharebest\Webtrees\Tree $tree
37
+	 */
38
+	protected $tree;
39 39
     
40
-    /**
41
-     * Sosa Provider for the calculator
42
-     * @var \MyArtJaub\Webtrees\Module\Sosa\Model\SosaCalculator $sosa_provider
43
-     */
44
-    protected $sosa_provider;
40
+	/**
41
+	 * Sosa Provider for the calculator
42
+	 * @var \MyArtJaub\Webtrees\Module\Sosa\Model\SosaCalculator $sosa_provider
43
+	 */
44
+	protected $sosa_provider;
45 45
     
46
-    /**
47
-     * Temporary Sosa table, used during construction
48
-     * @var array $tmp_sosa_table
49
-     */
50
-    protected $tmp_sosa_table;
46
+	/**
47
+	 * Temporary Sosa table, used during construction
48
+	 * @var array $tmp_sosa_table
49
+	 */
50
+	protected $tmp_sosa_table;
51 51
     
52
-    /**
53
-     * Constructor for the Sosa Calculator
54
-     * @param Tree $tree
55
-     * @param User $user
56
-     */
57
-    public function __construct(Tree $tree, User $user) {        
58
-        $this->tree = $tree;
59
-        $this->user = $user;
52
+	/**
53
+	 * Constructor for the Sosa Calculator
54
+	 * @param Tree $tree
55
+	 * @param User $user
56
+	 */
57
+	public function __construct(Tree $tree, User $user) {        
58
+		$this->tree = $tree;
59
+		$this->user = $user;
60 60
         
61
-        $this->sosa_provider = new SosaProvider($this->tree, $this->user);;
62
-    }
61
+		$this->sosa_provider = new SosaProvider($this->tree, $this->user);;
62
+	}
63 63
     
64
-    /**
65
-     * Compute all Sosa ancestors from the user's root individual.
66
-     * @return bool Result of the computation
67
-     */
68
-    public function computeAll() {
69
-        $root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');        
70
-        $indi = Individual::getInstance($root_id, $this->tree);
71
-        if($indi){
72
-            $this->sosa_provider->deleteAll();
73
-            $this->addNode($indi, 1);
74
-            $this->flushTmpSosaTable(true);
75
-            return true;
76
-        }
77
-        return false;
78
-    }
64
+	/**
65
+	 * Compute all Sosa ancestors from the user's root individual.
66
+	 * @return bool Result of the computation
67
+	 */
68
+	public function computeAll() {
69
+		$root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');        
70
+		$indi = Individual::getInstance($root_id, $this->tree);
71
+		if($indi){
72
+			$this->sosa_provider->deleteAll();
73
+			$this->addNode($indi, 1);
74
+			$this->flushTmpSosaTable(true);
75
+			return true;
76
+		}
77
+		return false;
78
+	}
79 79
     
80
-    /**
81
-     * Compute all Sosa Ancestors from a specified Individual
82
-     * @param Individual $indi
83
-     * @return bool Result of the computation
84
-     */
85
-    public function computeFromIndividual(Individual $indi) {
86
-        $dindi = new \MyArtJaub\Webtrees\Individual($indi);
87
-        $current_sosas = $dindi->getSosaNumbers();
88
-        foreach($current_sosas as $current_sosa => $gen) {
89
-            $this->sosa_provider->deleteAncestors($current_sosa);
90
-            $this->addNode($indi, $current_sosa);
91
-        }
92
-        $this->flushTmpSosaTable(true);
93
-        return true;
94
-    }
80
+	/**
81
+	 * Compute all Sosa Ancestors from a specified Individual
82
+	 * @param Individual $indi
83
+	 * @return bool Result of the computation
84
+	 */
85
+	public function computeFromIndividual(Individual $indi) {
86
+		$dindi = new \MyArtJaub\Webtrees\Individual($indi);
87
+		$current_sosas = $dindi->getSosaNumbers();
88
+		foreach($current_sosas as $current_sosa => $gen) {
89
+			$this->sosa_provider->deleteAncestors($current_sosa);
90
+			$this->addNode($indi, $current_sosa);
91
+		}
92
+		$this->flushTmpSosaTable(true);
93
+		return true;
94
+	}
95 95
     
96
-    /**
97
-     * Recursive method to add individual to the Sosa table, and flush it regularly
98
-     * @param Individual $indi Individual to add
99
-     * @param int $sosa Individual's sosa
100
-     */
101
-    protected function addNode(Individual $indi, $sosa) {                
102
-        $birth_year = $indi->getBirthDate()->gregorianYear();
103
-        $birth_year_est = $birth_year === 0 ? $indi->getEstimatedBirthDate()->gregorianYear() : $birth_year;
96
+	/**
97
+	 * Recursive method to add individual to the Sosa table, and flush it regularly
98
+	 * @param Individual $indi Individual to add
99
+	 * @param int $sosa Individual's sosa
100
+	 */
101
+	protected function addNode(Individual $indi, $sosa) {                
102
+		$birth_year = $indi->getBirthDate()->gregorianYear();
103
+		$birth_year_est = $birth_year === 0 ? $indi->getEstimatedBirthDate()->gregorianYear() : $birth_year;
104 104
         
105
-        $death_year = $indi->getDeathDate()->gregorianYear();
106
-        $death_year_est = $death_year === 0 ? $indi->getEstimatedDeathDate()->gregorianYear() : $death_year;
105
+		$death_year = $indi->getDeathDate()->gregorianYear();
106
+		$death_year_est = $death_year === 0 ? $indi->getEstimatedDeathDate()->gregorianYear() : $death_year;
107 107
         
108
-        $this->tmp_sosa_table[] = array(
109
-            'indi' => $indi->getXref(),
110
-            'sosa' => $sosa,
111
-            'birth_year' => $birth_year === 0 ? null : $birth_year,
112
-            'birth_year_est' => $birth_year_est === 0 ? null : $birth_year_est,
113
-            'death_year' => $death_year === 0 ? null : $death_year,
114
-            'death_year_est' => $death_year_est === 0 ? null : $death_year_est
115
-        );
108
+		$this->tmp_sosa_table[] = array(
109
+			'indi' => $indi->getXref(),
110
+			'sosa' => $sosa,
111
+			'birth_year' => $birth_year === 0 ? null : $birth_year,
112
+			'birth_year_est' => $birth_year_est === 0 ? null : $birth_year_est,
113
+			'death_year' => $death_year === 0 ? null : $death_year,
114
+			'death_year_est' => $death_year_est === 0 ? null : $death_year_est
115
+		);
116 116
         
117
-        $this->flushTmpSosaTable();
117
+		$this->flushTmpSosaTable();
118 118
         
119
-        if($fam = $indi->getPrimaryChildFamily()) {
120
-            if($husb = $fam->getHusband()) $this->addNode($husb, 2 * $sosa);
121
-            if($wife = $fam->getWife()) $this->addNode($wife, 2 * $sosa + 1);
122
-        }
123
-    }
119
+		if($fam = $indi->getPrimaryChildFamily()) {
120
+			if($husb = $fam->getHusband()) $this->addNode($husb, 2 * $sosa);
121
+			if($wife = $fam->getWife()) $this->addNode($wife, 2 * $sosa + 1);
122
+		}
123
+	}
124 124
     
125
-    /**
126
-     * Write sosas in the table, if the number of items is superior to the limit, or if forced.
127
-     *
128
-     * @param bool $force Should the flush be forced
129
-     */
130
-    protected function flushTmpSosaTable($force = false) {
131
-        if( count($this->tmp_sosa_table)> 0 && 
132
-            ($force ||  count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT)){            
133
-                $this->sosa_provider->insertOrUpdate($this->tmp_sosa_table);
134
-                $this->tmp_sosa_table = array();
135
-        }
136
-    }
125
+	/**
126
+	 * Write sosas in the table, if the number of items is superior to the limit, or if forced.
127
+	 *
128
+	 * @param bool $force Should the flush be forced
129
+	 */
130
+	protected function flushTmpSosaTable($force = false) {
131
+		if( count($this->tmp_sosa_table)> 0 && 
132
+			($force ||  count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT)){            
133
+				$this->sosa_provider->insertOrUpdate($this->tmp_sosa_table);
134
+				$this->tmp_sosa_table = array();
135
+		}
136
+	}
137 137
                
138 138
 }
139 139
  
140 140
\ No newline at end of file
Please login to merge, or discard this patch.