Completed
Push — master ( b746e6...94717f )
by Jonathan
06:37
created
src/Webtrees/Module/Sosa/Model/SosaProvider.php 4 patches
Doc Comments   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -277,7 +277,7 @@  discard block
 block discarded – undo
277 277
     /**
278 278
      * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals.
279 279
      *
280
-     * @param number $gen Generation
280
+     * @param integer $gen Generation
281 281
      * @return array Array of Sosa individuals
282 282
      */
283 283
     public function getSosaListAtGeneration($gen){
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
     /**
309 309
      * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families.
310 310
      *
311
-     * @param number $gen Generation
311
+     * @param integer $gen Generation
312 312
      * @return array Array of Sosa families
313 313
      */
314 314
     public function getFamilySosaListAtGeneration($gen){
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
     /**
345 345
      * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals.
346 346
      *
347
-     * @param number $gen Generation
347
+     * @param integer $gen Generation
348 348
      * @return array Array of Sosa individuals
349 349
      */
350 350
     public function getMissingSosaListAtGeneration($gen){
@@ -439,8 +439,8 @@  discard block
 block discarded – undo
439 439
     /**
440 440
      * Get the number of Sosa in a specific generation.
441 441
      *
442
-     * @param number $gen Generation
443
-     * @return number Number of Sosas in generation
442
+     * @param integer $gen Generation
443
+     * @return integer Number of Sosas in generation
444 444
      */
445 445
     public function getSosaCountAtGeneration($gen){
446 446
         if(!$this->is_setup) return 0;
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
     /**
459 459
      * Get the total number of Sosa up to a specific generation.
460 460
      *
461
-     * @param number $gen Generation
461
+     * @param integer $gen Generation
462 462
      * @return number Total number of Sosas up to generation
463 463
      */
464 464
     public function getSosaCountUpToGeneration($gen){
@@ -493,7 +493,7 @@  discard block
 block discarded – undo
493 493
     /**
494 494
      * Get the number of distinct Sosa individual up to a specific generation.
495 495
      *
496
-     * @param number $gen Generation
496
+     * @param integer $gen Generation
497 497
      * @return number Number of distinct Sosa individuals up to generation
498 498
      */
499 499
     public function getDifferentSosaCountUpToGeneration($gen){
@@ -516,7 +516,7 @@  discard block
 block discarded – undo
516 516
      *  - last : Last birth year in generation
517 517
      *  - avg : Average birth year
518 518
      *
519
-     * @param number $gen Generation
519
+     * @param integer $gen Generation
520 520
      * @return array Birth statistics array
521 521
      */
522 522
     public function getStatsBirthYearInGeneration($gen){
Please login to merge, or discard this patch.
Indentation   +560 added lines, -560 removed lines patch added patch discarded remove patch
@@ -22,389 +22,389 @@  discard block
 block discarded – undo
22 22
  */
23 23
 class SosaProvider {
24 24
     
25
-    /**
26
-     * Maximum number of generation the database is able to hold.
27
-     * @var int MAX_DB_GENERATIONS
28
-     */
29
-    const MAX_DB_GENERATIONS = 64;
30
-    
31
-    /**
32
-     * System's default user (ID -1 in the database
33
-     * @var User $default_user
34
-     */
35
-    protected static $default_user;
36
-    
37
-    /**
38
-     * Reference user
39
-     * @var User $user
40
-     */
41
-    protected $user;
42
-    
43
-    /**
44
-     * Reference tree
45
-     * @var Tree $tree
46
-     */
47
-    protected $tree;
48
-    
49
-    /**
50
-     * Cached list of Sosa Individuals by generation
51
-     * Format: key = generation, value = array ( sosa => Individual ID)
52
-     * @var array $sosa_list_by_gen
53
-     */
54
-    protected $sosa_list_by_gen;
55
-    
56
-    /**
57
-     * Cached list of Sosa Families by generation
58
-     * Format: key = generation, value = array ( sosa => Family ID)
59
-     * @var unknown $sosa_fam_list_by_gen
60
-     */
61
-    protected $sosa_fam_list_by_gen;
62
-    
63
-    /**
64
-     * Cached array of statistics by generation
65
-     * Format:  key = generation, 
66
-     *          value = array(
67
-     *              sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth
68
-     *           )
69
-     * @var array $statistics_tab
70
-     */
71
-    protected $statistics_tab;
72
-    
73
-    /**
74
-     * Has the provider's initialisation completed
75
-     * @var bool $is_setup
76
-     */
77
-    protected $is_setup;
78
-    
79
-    /**
80
-     * Constructor for Sosa Provider.
81
-     * A provider is defined in relation to a specific tree and reference user.
82
-     * 
83
-     * @param Tree $tree
84
-     * @param User $user
85
-     */
86
-    public function __construct(Tree $tree, User $user = null) {
87
-        if(self::$default_user === null) 
88
-            self::$default_user = User::find(-1);
25
+	/**
26
+	 * Maximum number of generation the database is able to hold.
27
+	 * @var int MAX_DB_GENERATIONS
28
+	 */
29
+	const MAX_DB_GENERATIONS = 64;
30
+    
31
+	/**
32
+	 * System's default user (ID -1 in the database
33
+	 * @var User $default_user
34
+	 */
35
+	protected static $default_user;
36
+    
37
+	/**
38
+	 * Reference user
39
+	 * @var User $user
40
+	 */
41
+	protected $user;
42
+    
43
+	/**
44
+	 * Reference tree
45
+	 * @var Tree $tree
46
+	 */
47
+	protected $tree;
48
+    
49
+	/**
50
+	 * Cached list of Sosa Individuals by generation
51
+	 * Format: key = generation, value = array ( sosa => Individual ID)
52
+	 * @var array $sosa_list_by_gen
53
+	 */
54
+	protected $sosa_list_by_gen;
55
+    
56
+	/**
57
+	 * Cached list of Sosa Families by generation
58
+	 * Format: key = generation, value = array ( sosa => Family ID)
59
+	 * @var unknown $sosa_fam_list_by_gen
60
+	 */
61
+	protected $sosa_fam_list_by_gen;
62
+    
63
+	/**
64
+	 * Cached array of statistics by generation
65
+	 * Format:  key = generation, 
66
+	 *          value = array(
67
+	 *              sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth
68
+	 *           )
69
+	 * @var array $statistics_tab
70
+	 */
71
+	protected $statistics_tab;
72
+    
73
+	/**
74
+	 * Has the provider's initialisation completed
75
+	 * @var bool $is_setup
76
+	 */
77
+	protected $is_setup;
78
+    
79
+	/**
80
+	 * Constructor for Sosa Provider.
81
+	 * A provider is defined in relation to a specific tree and reference user.
82
+	 * 
83
+	 * @param Tree $tree
84
+	 * @param User $user
85
+	 */
86
+	public function __construct(Tree $tree, User $user = null) {
87
+		if(self::$default_user === null) 
88
+			self::$default_user = User::find(-1);
89 89
         
90
-        $this->tree = $tree;
91
-        $this->user = $user;
92
-        $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;
90
+		$this->tree = $tree;
91
+		$this->user = $user;
92
+		$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;
95 95
         
96
-        // Check if the user, or the default user, has a root already setup;
97
-        if(empty($this->getRootIndiId())) {
98
-            if($this->user == self::$default_user) {  // If the default user is not setup
99
-                $this->is_setup = false;
100
-            }
101
-            else {
102
-                $this->user = self::$default_user;
103
-                $this->is_setup = $this->getRootIndiId() === null;
104
-            }            
105
-        }
106
-    }
107
-    
108
-    /**
109
-     * Returns is the Provider has been successfully set up
110
-     * @return bool
111
-     */
112
-    public function isSetup() {
113
-        return $this->is_setup;
114
-    }
115
-    
116
-    /**
117
-     * Return the root individual ID for the reference tree and user.
118
-     * @return string Individual ID
119
-     */
120
-    public function getRootIndiId() {
121
-        return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
122
-    }
123
-    
124
-    /**
125
-     * Return the root individual for the reference tree and user.
126
-     * @return Individual Individual
127
-     */
128
-    public function getRootIndi() {
129
-        $root_indi_id = $this->getRootIndiId();
130
-        if(!empty($root_indi_id)) {
131
-            return Individual::getInstance($root_indi_id, $this->tree);
132
-        }
133
-        return null;
134
-    }
96
+		// Check if the user, or the default user, has a root already setup;
97
+		if(empty($this->getRootIndiId())) {
98
+			if($this->user == self::$default_user) {  // If the default user is not setup
99
+				$this->is_setup = false;
100
+			}
101
+			else {
102
+				$this->user = self::$default_user;
103
+				$this->is_setup = $this->getRootIndiId() === null;
104
+			}            
105
+		}
106
+	}
107
+    
108
+	/**
109
+	 * Returns is the Provider has been successfully set up
110
+	 * @return bool
111
+	 */
112
+	public function isSetup() {
113
+		return $this->is_setup;
114
+	}
115
+    
116
+	/**
117
+	 * Return the root individual ID for the reference tree and user.
118
+	 * @return string Individual ID
119
+	 */
120
+	public function getRootIndiId() {
121
+		return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
122
+	}
123
+    
124
+	/**
125
+	 * Return the root individual for the reference tree and user.
126
+	 * @return Individual Individual
127
+	 */
128
+	public function getRootIndi() {
129
+		$root_indi_id = $this->getRootIndiId();
130
+		if(!empty($root_indi_id)) {
131
+			return Individual::getInstance($root_indi_id, $this->tree);
132
+		}
133
+		return null;
134
+	}
135 135
        
136
-    /*****************
136
+	/*****************
137 137
      * DATA CRUD LAYER
138 138
      *****************/
139 139
     
140
-    /**
141
-     * Remove all Sosa entries related to the gedcom file and user
142
-     */
143
-    public function deleteAll() {
144
-        if(!$this->is_setup) return;
145
-        Database::prepare(
146
-            'DELETE FROM `##maj_sosa`'.
147
-            ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
148
-            ->execute(array(
149
-                'tree_id' => $this->tree->getTreeId(), 
150
-                'user_id' => $this->user->getUserId()                
151
-            ));
152
-    }
153
-    
154
-    /**
155
-     * Remove all ancestors of a sosa number
156
-     * 
157
-     * @param int $sosa
158
-     */
159
-    public function deleteAncestors($sosa) {
160
-        if(!$this->is_setup) return;
161
-        $gen = Functions::getGeneration($sosa);
162
-        Database::prepare(
163
-            'DELETE FROM `##maj_sosa`'.
164
-            ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' .
165
-            ' AND majs_gen >= :gen' .
166
-            ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa'
167
-        )->execute(array(
168
-            'tree_id' => $this->tree->getTreeId(), 
169
-            'user_id' => $this->user->getUserId(),
170
-            'gen' => $gen,
171
-            'sosa' => $sosa
172
-        ));
173
-    }    
174
-    
175
-    /**
176
-     * Insert (or update if already existing) a list of Sosa individuals
177
-     * @param array $sosa_records
178
-     */
179
-    public function insertOrUpdate($sosa_records) {
180
-        if(!$this->is_setup) return;
140
+	/**
141
+	 * Remove all Sosa entries related to the gedcom file and user
142
+	 */
143
+	public function deleteAll() {
144
+		if(!$this->is_setup) return;
145
+		Database::prepare(
146
+			'DELETE FROM `##maj_sosa`'.
147
+			' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
148
+			->execute(array(
149
+				'tree_id' => $this->tree->getTreeId(), 
150
+				'user_id' => $this->user->getUserId()                
151
+			));
152
+	}
153
+    
154
+	/**
155
+	 * Remove all ancestors of a sosa number
156
+	 * 
157
+	 * @param int $sosa
158
+	 */
159
+	public function deleteAncestors($sosa) {
160
+		if(!$this->is_setup) return;
161
+		$gen = Functions::getGeneration($sosa);
162
+		Database::prepare(
163
+			'DELETE FROM `##maj_sosa`'.
164
+			' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' .
165
+			' AND majs_gen >= :gen' .
166
+			' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa'
167
+		)->execute(array(
168
+			'tree_id' => $this->tree->getTreeId(), 
169
+			'user_id' => $this->user->getUserId(),
170
+			'gen' => $gen,
171
+			'sosa' => $sosa
172
+		));
173
+	}    
174
+    
175
+	/**
176
+	 * Insert (or update if already existing) a list of Sosa individuals
177
+	 * @param array $sosa_records
178
+	 */
179
+	public function insertOrUpdate($sosa_records) {
180
+		if(!$this->is_setup) return;
181 181
         
182
-        $treeid = $this->tree->getTreeId();
183
-        $userid = $this->user->getUserId();
184
-        $questionmarks_table = array();
185
-        $values_table = array();
182
+		$treeid = $this->tree->getTreeId();
183
+		$userid = $this->user->getUserId();
184
+		$questionmarks_table = array();
185
+		$values_table = array();
186 186
         
187
-        $i = 0;
188
-        foreach  ($sosa_records as $row) {
189
-            $gen = Functions::getGeneration($row['sosa']);
190
-            if($gen <= self::MAX_DB_GENERATIONS) {
191
-                $questionmarks_table[] = 
192
-                    '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')';
193
-                $values_table = array_merge(
194
-                    $values_table, 
195
-                    array(
196
-                        'tree_id'.$i => $treeid, 
197
-                        'user_id'.$i => $userid, 
198
-                        'sosa'.$i => $row['sosa'], 
199
-                        'indi_id'.$i => $row['indi'], 
200
-                        'gen'.$i => Functions::getGeneration($row['sosa']),
201
-                        'byear'.$i => $row['birth_year'],
202
-                        'dyear'.$i => $row['death_year']
203
-                    )
204
-                );
205
-            }
206
-            $i++;
207
-        }
187
+		$i = 0;
188
+		foreach  ($sosa_records as $row) {
189
+			$gen = Functions::getGeneration($row['sosa']);
190
+			if($gen <= self::MAX_DB_GENERATIONS) {
191
+				$questionmarks_table[] = 
192
+					'(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')';
193
+				$values_table = array_merge(
194
+					$values_table, 
195
+					array(
196
+						'tree_id'.$i => $treeid, 
197
+						'user_id'.$i => $userid, 
198
+						'sosa'.$i => $row['sosa'], 
199
+						'indi_id'.$i => $row['indi'], 
200
+						'gen'.$i => Functions::getGeneration($row['sosa']),
201
+						'byear'.$i => $row['birth_year'],
202
+						'dyear'.$i => $row['death_year']
203
+					)
204
+				);
205
+			}
206
+			$i++;
207
+		}
208 208
         
209
-        $sql = 'REPLACE INTO `##maj_sosa`' .
210
-            ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' .
211
-            ' VALUES '. implode(',', $questionmarks_table);
212
-        Database::prepare($sql)->execute($values_table);
213
-    }
209
+		$sql = 'REPLACE INTO `##maj_sosa`' .
210
+			' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' .
211
+			' VALUES '. implode(',', $questionmarks_table);
212
+		Database::prepare($sql)->execute($values_table);
213
+	}
214 214
     
215
-    /****************
215
+	/****************
216 216
      * SIMPLE QUERIES
217 217
      ****************/
218 218
     
219
-    /**
220
-     * Returns the list of Sosa numbers to which an individual is related.
221
-     * Format: key = sosa number, value = generation for the Sosa number
222
-     * 
223
-     * @param Individual $indi
224
-     * @return array Array of sosa numbers
225
-     */
226
-    public function getSosaNumbers(Individual $indi) {
227
-        if(!$this->is_setup) return array();
228
-        return Database::prepare(
229
-                'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
230
-                ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
231
-            )->execute(array(
232
-                'indi_id' => $indi->getXref(), 
233
-                'tree_id' => $this->tree->getTreeId(), 
234
-                'user_id' => $this->user->getUserId()
235
-            ))->fetchAssoc();
236
-    }
237
-    
238
-    /**
239
-     * Get the last generation of Sosa ancestors
240
-     *
241
-     * @return number Last generation if found, 1 otherwise
242
-     */
243
-    public function getLastGeneration() {
244
-        if(!$this->is_setup) return;
245
-        return Database::prepare(
246
-                'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
247
-                ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
248
-            )->execute(array(
249
-                'tree_id' => $this->tree->getTreeId(), 
250
-                'user_id' => $this->user->getUserId()                
251
-            ))->fetchOne() ?: 1;
252
-    }
253
-    
254
-    /*************
219
+	/**
220
+	 * Returns the list of Sosa numbers to which an individual is related.
221
+	 * Format: key = sosa number, value = generation for the Sosa number
222
+	 * 
223
+	 * @param Individual $indi
224
+	 * @return array Array of sosa numbers
225
+	 */
226
+	public function getSosaNumbers(Individual $indi) {
227
+		if(!$this->is_setup) return array();
228
+		return Database::prepare(
229
+				'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
230
+				' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
231
+			)->execute(array(
232
+				'indi_id' => $indi->getXref(), 
233
+				'tree_id' => $this->tree->getTreeId(), 
234
+				'user_id' => $this->user->getUserId()
235
+			))->fetchAssoc();
236
+	}
237
+    
238
+	/**
239
+	 * Get the last generation of Sosa ancestors
240
+	 *
241
+	 * @return number Last generation if found, 1 otherwise
242
+	 */
243
+	public function getLastGeneration() {
244
+		if(!$this->is_setup) return;
245
+		return Database::prepare(
246
+				'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
247
+				' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
248
+			)->execute(array(
249
+				'tree_id' => $this->tree->getTreeId(), 
250
+				'user_id' => $this->user->getUserId()                
251
+			))->fetchOne() ?: 1;
252
+	}
253
+    
254
+	/*************
255 255
      * SOSA LISTS
256 256
      *************/
257 257
     
258
-    /**
259
-     * Return the list of all sosas, with the generations it belongs to
260
-     *
261
-     * @return array Associative array of Sosa ancestors, with their generation, comma separated
262
-     */
263
-    public function getAllSosaWithGenerations(){
264
-        if(!$this->is_setup) return array();
265
-        return Database::prepare(
266
-            'SELECT majs_i_id AS indi,' .
267
-            ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
268
-            ' FROM `##maj_sosa`' .
269
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' .
270
-            ' GROUP BY majs_i_id'
271
-        )->execute(array(
272
-            'tree_id' => $this->tree->getTreeId(),
273
-            'user_id' => $this->user->getUserId()
274
-        ))->fetchAssoc();
275
-    }
276
-    
277
-    /**
278
-     * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals.
279
-     *
280
-     * @param number $gen Generation
281
-     * @return array Array of Sosa individuals
282
-     */
283
-    public function getSosaListAtGeneration($gen){
284
-        if(!$this->is_setup) return array();
285
-        if(!$this->sosa_list_by_gen)
286
-            $this->sosa_list_by_gen = array();
258
+	/**
259
+	 * Return the list of all sosas, with the generations it belongs to
260
+	 *
261
+	 * @return array Associative array of Sosa ancestors, with their generation, comma separated
262
+	 */
263
+	public function getAllSosaWithGenerations(){
264
+		if(!$this->is_setup) return array();
265
+		return Database::prepare(
266
+			'SELECT majs_i_id AS indi,' .
267
+			' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
268
+			' FROM `##maj_sosa`' .
269
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' .
270
+			' GROUP BY majs_i_id'
271
+		)->execute(array(
272
+			'tree_id' => $this->tree->getTreeId(),
273
+			'user_id' => $this->user->getUserId()
274
+		))->fetchAssoc();
275
+	}
276
+    
277
+	/**
278
+	 * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals.
279
+	 *
280
+	 * @param number $gen Generation
281
+	 * @return array Array of Sosa individuals
282
+	 */
283
+	public function getSosaListAtGeneration($gen){
284
+		if(!$this->is_setup) return array();
285
+		if(!$this->sosa_list_by_gen)
286
+			$this->sosa_list_by_gen = array();
287 287
         
288
-        if($gen){
289
-            if(!isset($this->sosa_list_by_gen[$gen])){
290
-                $this->sosa_list_by_gen[$gen] = Database::prepare(
291
-                    'SELECT majs_sosa AS sosa, majs_i_id AS indi'.
292
-                    ' FROM `##maj_sosa`'.
293
-                    ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
294
-                    ' AND majs_gen = :gen'.
295
-                    ' ORDER BY majs_sosa ASC')
296
-                ->execute(array(
297
-                    'tree_id' => $this->tree->getTreeId(),
298
-                    'user_id' => $this->user->getUserId(),
299
-                    'gen' => $gen
300
-                ))
301
-                ->fetchAssoc();
302
-            }
303
-            return $this->sosa_list_by_gen[$gen];
304
-        }
305
-        return array();
306
-    }
307
-    
308
-    /**
309
-     * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families.
310
-     *
311
-     * @param number $gen Generation
312
-     * @return array Array of Sosa families
313
-     */
314
-    public function getFamilySosaListAtGeneration($gen){
315
-        if(!$this->is_setup) return array();
316
-        if(!$this->sosa_fam_list_by_gen)
317
-            $this->sosa_fam_list_by_gen = array();
288
+		if($gen){
289
+			if(!isset($this->sosa_list_by_gen[$gen])){
290
+				$this->sosa_list_by_gen[$gen] = Database::prepare(
291
+					'SELECT majs_sosa AS sosa, majs_i_id AS indi'.
292
+					' FROM `##maj_sosa`'.
293
+					' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
294
+					' AND majs_gen = :gen'.
295
+					' ORDER BY majs_sosa ASC')
296
+				->execute(array(
297
+					'tree_id' => $this->tree->getTreeId(),
298
+					'user_id' => $this->user->getUserId(),
299
+					'gen' => $gen
300
+				))
301
+				->fetchAssoc();
302
+			}
303
+			return $this->sosa_list_by_gen[$gen];
304
+		}
305
+		return array();
306
+	}
307
+    
308
+	/**
309
+	 * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families.
310
+	 *
311
+	 * @param number $gen Generation
312
+	 * @return array Array of Sosa families
313
+	 */
314
+	public function getFamilySosaListAtGeneration($gen){
315
+		if(!$this->is_setup) return array();
316
+		if(!$this->sosa_fam_list_by_gen)
317
+			$this->sosa_fam_list_by_gen = array();
318 318
         
319
-        if($gen){
320
-            if(!isset($this->sosa_fam_list_by_gen[$gen])){
321
-                $this->sosa_fam_list_by_gen[$gen] = Database::prepare(
322
-                    'SELECT s1.majs_sosa AS sosa, f_id AS fam'.
323
-                    ' FROM `##families`'.
324
-                    ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'.
325
-                    ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'.
326
-                    ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'.
327
-                    ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'.
328
-                    ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'.
329
-                    ' AND s1.majs_gen = :gen'.
330
-                    ' ORDER BY s1.majs_sosa ASC'
331
-                    )
332
-                    ->execute(array(
333
-                        'tree_id' => $this->tree->getTreeId(),
334
-                        'user_id' => $this->user->getUserId(),
335
-                        'gen' => $gen
336
-                    ))
337
-                    ->fetchAssoc();
338
-            }
339
-            return $this->sosa_fam_list_by_gen[$gen];
340
-        }
341
-        return array();
342
-    }
343
-    
344
-    /**
345
-     * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals.
346
-     *
347
-     * @param number $gen Generation
348
-     * @return array Array of Sosa individuals
349
-     */
350
-    public function getMissingSosaListAtGeneration($gen){
351
-        if(!$this->is_setup) return array();    
352
-        if($gen){
353
-            return $this->sosa_list_by_gen[$gen] = Database::prepare(
354
-                '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'.
355
-                ' FROM `##maj_sosa` schild'.
356
-                ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'.
357
-                ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'.
358
-                ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'.
359
-                ' AND schild.majs_gen = :gen'.
360
-                ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'.
361
-                ' ORDER BY schild.majs_sosa ASC')
362
-                ->execute(array(
363
-                    'tree_id' => $this->tree->getTreeId(),
364
-                    'user_id' => $this->user->getUserId(),
365
-                    'gen' => $gen - 1
366
-                ))->fetchAll(\PDO::FETCH_ASSOC);
367
-        }
368
-        return array();
369
-    }
370
-    
371
-    
372
-    
373
-    /*************
319
+		if($gen){
320
+			if(!isset($this->sosa_fam_list_by_gen[$gen])){
321
+				$this->sosa_fam_list_by_gen[$gen] = Database::prepare(
322
+					'SELECT s1.majs_sosa AS sosa, f_id AS fam'.
323
+					' FROM `##families`'.
324
+					' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'.
325
+					' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'.
326
+					' WHERE s1.majs_sosa + 1 = s2.majs_sosa'.
327
+					' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'.
328
+					' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'.
329
+					' AND s1.majs_gen = :gen'.
330
+					' ORDER BY s1.majs_sosa ASC'
331
+					)
332
+					->execute(array(
333
+						'tree_id' => $this->tree->getTreeId(),
334
+						'user_id' => $this->user->getUserId(),
335
+						'gen' => $gen
336
+					))
337
+					->fetchAssoc();
338
+			}
339
+			return $this->sosa_fam_list_by_gen[$gen];
340
+		}
341
+		return array();
342
+	}
343
+    
344
+	/**
345
+	 * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals.
346
+	 *
347
+	 * @param number $gen Generation
348
+	 * @return array Array of Sosa individuals
349
+	 */
350
+	public function getMissingSosaListAtGeneration($gen){
351
+		if(!$this->is_setup) return array();    
352
+		if($gen){
353
+			return $this->sosa_list_by_gen[$gen] = Database::prepare(
354
+				'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'.
355
+				' FROM `##maj_sosa` schild'.
356
+				' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'.
357
+				' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'.
358
+				' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'.
359
+				' AND schild.majs_gen = :gen'.
360
+				' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'.
361
+				' ORDER BY schild.majs_sosa ASC')
362
+				->execute(array(
363
+					'tree_id' => $this->tree->getTreeId(),
364
+					'user_id' => $this->user->getUserId(),
365
+					'gen' => $gen - 1
366
+				))->fetchAll(\PDO::FETCH_ASSOC);
367
+		}
368
+		return array();
369
+	}
370
+    
371
+    
372
+    
373
+	/*************
374 374
      * STATISTICS
375 375
      *************/
376
-    /**
377
-     * Get the statistic array detailed by generation.
378
-     * Statistics for each generation are:
379
-     * 	- The number of Sosa in generation
380
-     * 	- The number of Sosa up to generation
381
-     *  - The number of distinct Sosa up to generation
382
-     *  - The year of the first birth in generation
383
-     *  - The year of the last birth in generation
384
-     *  - The average year of birth in generation
385
-     *
386
-     * @return array Statistics array
387
-     */
388
-    public function getStatisticsByGeneration() {
389
-        if(!$this->is_setup) return array();
390
-        if(!$this->statistics_tab) {
391
-            $this->statistics_tab = array();
392
-            if($maxGeneration = $this->getLastGeneration()) {
393
-                for ($gen = 1; $gen <= $maxGeneration; $gen++) {
394
-                    $birthStats = $this->getStatsBirthYearInGeneration($gen);
395
-                    $this->statistics_tab[$gen] = array(
396
-                        'sosaCount'				=>	$this->getSosaCountAtGeneration($gen),
397
-                        'sosaTotalCount'		=>	$this->getSosaCountUpToGeneration($gen),
398
-                        'diffSosaTotalCount'	=>	$this->getDifferentSosaCountUpToGeneration($gen),
399
-                        'firstBirth'			=>	$birthStats['first'],
400
-                        'lastBirth'				=>	$birthStats['last'],
401
-                        'avgBirth'				=>	$birthStats['avg']
402
-                    );
403
-                }
404
-            }
405
-        }
406
-        return $this->statistics_tab;        
407
-    }
376
+	/**
377
+	 * Get the statistic array detailed by generation.
378
+	 * Statistics for each generation are:
379
+	 * 	- The number of Sosa in generation
380
+	 * 	- The number of Sosa up to generation
381
+	 *  - The number of distinct Sosa up to generation
382
+	 *  - The year of the first birth in generation
383
+	 *  - The year of the last birth in generation
384
+	 *  - The average year of birth in generation
385
+	 *
386
+	 * @return array Statistics array
387
+	 */
388
+	public function getStatisticsByGeneration() {
389
+		if(!$this->is_setup) return array();
390
+		if(!$this->statistics_tab) {
391
+			$this->statistics_tab = array();
392
+			if($maxGeneration = $this->getLastGeneration()) {
393
+				for ($gen = 1; $gen <= $maxGeneration; $gen++) {
394
+					$birthStats = $this->getStatsBirthYearInGeneration($gen);
395
+					$this->statistics_tab[$gen] = array(
396
+						'sosaCount'				=>	$this->getSosaCountAtGeneration($gen),
397
+						'sosaTotalCount'		=>	$this->getSosaCountUpToGeneration($gen),
398
+						'diffSosaTotalCount'	=>	$this->getDifferentSosaCountUpToGeneration($gen),
399
+						'firstBirth'			=>	$birthStats['first'],
400
+						'lastBirth'				=>	$birthStats['last'],
401
+						'avgBirth'				=>	$birthStats['avg']
402
+					);
403
+				}
404
+			}
405
+		}
406
+		return $this->statistics_tab;        
407
+	}
408 408
     
409 409
 	/**
410 410
 	 * How many individuals exist in the tree.
@@ -412,205 +412,205 @@  discard block
 block discarded – undo
412 412
 	 * @return int
413 413
 	 */
414 414
 	public function getTotalIndividuals() {
415
-	    if(!$this->is_setup) return 0;
416
-	    return Database::prepare(
417
-	        'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' .
418
-	        ' WHERE i_file = :tree_id')
419
-	        ->execute(array('tree_id' => $this->tree->getTreeId()))
420
-	        ->fetchOne() ?: 0;
415
+		if(!$this->is_setup) return 0;
416
+		return Database::prepare(
417
+			'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' .
418
+			' WHERE i_file = :tree_id')
419
+			->execute(array('tree_id' => $this->tree->getTreeId()))
420
+			->fetchOne() ?: 0;
421 421
 	}
422 422
     
423
-    /**
424
-     * Get the total Sosa count for all generations
425
-     *
426
-     * @return number Number of Sosas
427
-     */
428
-    public function getSosaCount(){
429
-        if(!$this->is_setup) return 0;
430
-        return Database::prepare(
431
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
432
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
433
-            ->execute(array(
434
-                'tree_id' => $this->tree->getTreeId(), 
435
-                'user_id' => $this->user->getUserId() 
436
-            ))->fetchOne() ?: 0;
437
-    }
438
-    
439
-    /**
440
-     * Get the number of Sosa in a specific generation.
441
-     *
442
-     * @param number $gen Generation
443
-     * @return number Number of Sosas in generation
444
-     */
445
-    public function getSosaCountAtGeneration($gen){
446
-        if(!$this->is_setup) return 0;
447
-        return Database::prepare(
448
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
449
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
450
-            ' AND majs_gen= :gen')
451
-        ->execute(array(
452
-                'tree_id' => $this->tree->getTreeId(), 
453
-                'user_id' => $this->user->getUserId(),
454
-                'gen' => $gen            
455
-        ))->fetchOne() ?: 0;
456
-    }
457
-    
458
-    /**
459
-     * Get the total number of Sosa up to a specific generation.
460
-     *
461
-     * @param number $gen Generation
462
-     * @return number Total number of Sosas up to generation
463
-     */
464
-    public function getSosaCountUpToGeneration($gen){
465
-        if(!$this->is_setup) return 0;
466
-        return Database::prepare(
467
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
468
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
469
-            ' AND majs_gen <= :gen')
470
-        ->execute(array(
471
-                'tree_id' => $this->tree->getTreeId(), 
472
-                'user_id' => $this->user->getUserId(),
473
-                'gen' => $gen 
474
-        ))->fetchOne() ?: 0;
475
-    }
476
-    
477
-    /**
478
-     * Get the total number of distinct Sosa individual for all generations.
479
-     *
480
-     * @return number Total number of distinct individual
481
-     */
482
-    public function getDifferentSosaCount(){
483
-        if(!$this->is_setup) return 0;
484
-        return Database::prepare(
485
-            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
486
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
487
-        ->execute(array(
488
-                'tree_id' => $this->tree->getTreeId(), 
489
-                'user_id' => $this->user->getUserId()
490
-        ))->fetchOne() ?: 0;
491
-    }
492
-    
493
-    /**
494
-     * Get the number of distinct Sosa individual up to a specific generation.
495
-     *
496
-     * @param number $gen Generation
497
-     * @return number Number of distinct Sosa individuals up to generation
498
-     */
499
-    public function getDifferentSosaCountUpToGeneration($gen){
500
-        if(!$this->is_setup) return 0;
501
-        return Database::prepare(
502
-            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
503
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
504
-            ' AND majs_gen <= :gen')
505
-        ->execute(array(
506
-                'tree_id' => $this->tree->getTreeId(), 
507
-                'user_id' => $this->user->getUserId(),
508
-                'gen' => $gen 
509
-        ))->fetchOne() ?: 0;
510
-    }
511
-    
512
-    /**
513
-     * Get an array of birth statistics for a specific generation
514
-     * Statistics are :
515
-     * 	- first : First birth year in generation
516
-     *  - last : Last birth year in generation
517
-     *  - avg : Average birth year
518
-     *
519
-     * @param number $gen Generation
520
-     * @return array Birth statistics array
521
-     */
522
-    public function getStatsBirthYearInGeneration($gen){
523
-        if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
524
-        return Database::prepare(
525
-            'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'.
526
-            ' FROM `##maj_sosa`' .
527
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
528
-            ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year')
529
-            ->execute(array(
530
-                'tree_id' => $this->tree->getTreeId(), 
531
-                'user_id' => $this->user->getUserId(),
532
-                'gen' => $gen,
533
-                'birth_year' => 0))
534
-            ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0);
535
-    }
536
-    
537
-    /**
538
-     * Get the mean generation time, based on a linear regression of birth years and generations
539
-     *
540
-     * @return number|NULL Mean generation time
541
-     */
542
-    public function getMeanGenerationTime(){
543
-        if(!$this->is_setup) return;
544
-        if(!$this->statistics_tab){
545
-            $this->getStatisticsByGeneration();
546
-        }
547
-        //Linear regression on x=generation and y=birthdate
548
-        $sum_xy = 0;
549
-        $sum_x=0;
550
-        $sum_y=0;
551
-        $sum_x2=0;
552
-        $n=count($this->statistics_tab);
553
-        foreach($this->statistics_tab as $gen=>$stats){
554
-            $sum_xy+=$gen*$stats['avgBirth'];
555
-            $sum_x+=$gen;
556
-            $sum_y+=$stats['avgBirth'];
557
-            $sum_x2+=$gen*$gen;
558
-        }
559
-        $denom=($n*$sum_x2)-($sum_x*$sum_x);
560
-        if($denom!=0){
561
-            return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom);
562
-        }
563
-        return null;
564
-    }
565
-    
566
-    /**
567
-     * Return a computed array of statistics about the dispersion of ancestors across the ancestors
568
-     * at a specified generation.
569
-     * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL
570
-     * 
571
-     * Format: 
572
-     *  - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found,
573
-     *          -1 is used for shared ancestors
574
-     *          For instance base2(0100) = base10(4) represent the maternal grand father
575
-     *  - values: number of ancestors exclusively in the ancestors of the ancestor in key
576
-     *  
577
-     *  For instance a result at generation 3 could be :
578
-     *      array (   -1        =>  12      -> 12 ancestors are shared by the grand-parents
579
-     *                base10(1) =>  32      -> 32 ancestors are exclusive to the paternal grand-father
580
-     *                base10(2) =>  25      -> 25 ancestors are exclusive to the paternal grand-mother
581
-     *                base10(4) =>  12      -> 12 ancestors are exclusive to the maternal grand-father
582
-     *                base10(8) =>  30      -> 30 ancestors are exclusive to the maternal grand-mother
583
-     *            )
584
-     *  
585
-     * @param int $gen Reference generation
586
-     * @return array
587
-     */
588
-    public function getAncestorDispersionForGen($gen) {
589
-        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
590
-        return Database::prepare(
591
-            'SELECT branches, count(i_id)'.
592
-            ' FROM ('.
593
-            '   SELECT i_id,'.
594
-            '       CASE'.
595
-            '           WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
596
-            '           ELSE -1'.   // We put all ancestors shared between some branches in the same bucket
597
-            '       END branches'.
598
-            '   FROM ('.
599
-            '       SELECT DISTINCT majs_i_id i_id,'.
600
-            '           POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'.
601
-            '       FROM `##maj_sosa`'.
602
-            '       WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'.
603
-            '           AND majs_gen >= :gen'.
604
-            '   ) indistat'.
605
-            '   GROUP BY i_id'.
606
-            ') grouped'.
607
-            ' GROUP BY branches')
608
-            ->execute(array(
609
-                'tree_id' => $this->tree->getTreeId(), 
610
-                'user_id' => $this->user->getUserId(),
611
-                'gen' => $gen
612
-            ))->fetchAssoc() ?: array();
613
-    }
423
+	/**
424
+	 * Get the total Sosa count for all generations
425
+	 *
426
+	 * @return number Number of Sosas
427
+	 */
428
+	public function getSosaCount(){
429
+		if(!$this->is_setup) return 0;
430
+		return Database::prepare(
431
+			'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
432
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
433
+			->execute(array(
434
+				'tree_id' => $this->tree->getTreeId(), 
435
+				'user_id' => $this->user->getUserId() 
436
+			))->fetchOne() ?: 0;
437
+	}
438
+    
439
+	/**
440
+	 * Get the number of Sosa in a specific generation.
441
+	 *
442
+	 * @param number $gen Generation
443
+	 * @return number Number of Sosas in generation
444
+	 */
445
+	public function getSosaCountAtGeneration($gen){
446
+		if(!$this->is_setup) return 0;
447
+		return Database::prepare(
448
+			'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
449
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
450
+			' AND majs_gen= :gen')
451
+		->execute(array(
452
+				'tree_id' => $this->tree->getTreeId(), 
453
+				'user_id' => $this->user->getUserId(),
454
+				'gen' => $gen            
455
+		))->fetchOne() ?: 0;
456
+	}
457
+    
458
+	/**
459
+	 * Get the total number of Sosa up to a specific generation.
460
+	 *
461
+	 * @param number $gen Generation
462
+	 * @return number Total number of Sosas up to generation
463
+	 */
464
+	public function getSosaCountUpToGeneration($gen){
465
+		if(!$this->is_setup) return 0;
466
+		return Database::prepare(
467
+			'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
468
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
469
+			' AND majs_gen <= :gen')
470
+		->execute(array(
471
+				'tree_id' => $this->tree->getTreeId(), 
472
+				'user_id' => $this->user->getUserId(),
473
+				'gen' => $gen 
474
+		))->fetchOne() ?: 0;
475
+	}
476
+    
477
+	/**
478
+	 * Get the total number of distinct Sosa individual for all generations.
479
+	 *
480
+	 * @return number Total number of distinct individual
481
+	 */
482
+	public function getDifferentSosaCount(){
483
+		if(!$this->is_setup) return 0;
484
+		return Database::prepare(
485
+			'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
486
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
487
+		->execute(array(
488
+				'tree_id' => $this->tree->getTreeId(), 
489
+				'user_id' => $this->user->getUserId()
490
+		))->fetchOne() ?: 0;
491
+	}
492
+    
493
+	/**
494
+	 * Get the number of distinct Sosa individual up to a specific generation.
495
+	 *
496
+	 * @param number $gen Generation
497
+	 * @return number Number of distinct Sosa individuals up to generation
498
+	 */
499
+	public function getDifferentSosaCountUpToGeneration($gen){
500
+		if(!$this->is_setup) return 0;
501
+		return Database::prepare(
502
+			'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
503
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
504
+			' AND majs_gen <= :gen')
505
+		->execute(array(
506
+				'tree_id' => $this->tree->getTreeId(), 
507
+				'user_id' => $this->user->getUserId(),
508
+				'gen' => $gen 
509
+		))->fetchOne() ?: 0;
510
+	}
511
+    
512
+	/**
513
+	 * Get an array of birth statistics for a specific generation
514
+	 * Statistics are :
515
+	 * 	- first : First birth year in generation
516
+	 *  - last : Last birth year in generation
517
+	 *  - avg : Average birth year
518
+	 *
519
+	 * @param number $gen Generation
520
+	 * @return array Birth statistics array
521
+	 */
522
+	public function getStatsBirthYearInGeneration($gen){
523
+		if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
524
+		return Database::prepare(
525
+			'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'.
526
+			' FROM `##maj_sosa`' .
527
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
528
+			' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year')
529
+			->execute(array(
530
+				'tree_id' => $this->tree->getTreeId(), 
531
+				'user_id' => $this->user->getUserId(),
532
+				'gen' => $gen,
533
+				'birth_year' => 0))
534
+			->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0);
535
+	}
536
+    
537
+	/**
538
+	 * Get the mean generation time, based on a linear regression of birth years and generations
539
+	 *
540
+	 * @return number|NULL Mean generation time
541
+	 */
542
+	public function getMeanGenerationTime(){
543
+		if(!$this->is_setup) return;
544
+		if(!$this->statistics_tab){
545
+			$this->getStatisticsByGeneration();
546
+		}
547
+		//Linear regression on x=generation and y=birthdate
548
+		$sum_xy = 0;
549
+		$sum_x=0;
550
+		$sum_y=0;
551
+		$sum_x2=0;
552
+		$n=count($this->statistics_tab);
553
+		foreach($this->statistics_tab as $gen=>$stats){
554
+			$sum_xy+=$gen*$stats['avgBirth'];
555
+			$sum_x+=$gen;
556
+			$sum_y+=$stats['avgBirth'];
557
+			$sum_x2+=$gen*$gen;
558
+		}
559
+		$denom=($n*$sum_x2)-($sum_x*$sum_x);
560
+		if($denom!=0){
561
+			return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom);
562
+		}
563
+		return null;
564
+	}
565
+    
566
+	/**
567
+	 * Return a computed array of statistics about the dispersion of ancestors across the ancestors
568
+	 * at a specified generation.
569
+	 * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL
570
+	 * 
571
+	 * Format: 
572
+	 *  - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found,
573
+	 *          -1 is used for shared ancestors
574
+	 *          For instance base2(0100) = base10(4) represent the maternal grand father
575
+	 *  - values: number of ancestors exclusively in the ancestors of the ancestor in key
576
+	 *  
577
+	 *  For instance a result at generation 3 could be :
578
+	 *      array (   -1        =>  12      -> 12 ancestors are shared by the grand-parents
579
+	 *                base10(1) =>  32      -> 32 ancestors are exclusive to the paternal grand-father
580
+	 *                base10(2) =>  25      -> 25 ancestors are exclusive to the paternal grand-mother
581
+	 *                base10(4) =>  12      -> 12 ancestors are exclusive to the maternal grand-father
582
+	 *                base10(8) =>  30      -> 30 ancestors are exclusive to the maternal grand-mother
583
+	 *            )
584
+	 *  
585
+	 * @param int $gen Reference generation
586
+	 * @return array
587
+	 */
588
+	public function getAncestorDispersionForGen($gen) {
589
+		if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
590
+		return Database::prepare(
591
+			'SELECT branches, count(i_id)'.
592
+			' FROM ('.
593
+			'   SELECT i_id,'.
594
+			'       CASE'.
595
+			'           WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
596
+			'           ELSE -1'.   // We put all ancestors shared between some branches in the same bucket
597
+			'       END branches'.
598
+			'   FROM ('.
599
+			'       SELECT DISTINCT majs_i_id i_id,'.
600
+			'           POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'.
601
+			'       FROM `##maj_sosa`'.
602
+			'       WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'.
603
+			'           AND majs_gen >= :gen'.
604
+			'   ) indistat'.
605
+			'   GROUP BY i_id'.
606
+			') grouped'.
607
+			' GROUP BY branches')
608
+			->execute(array(
609
+				'tree_id' => $this->tree->getTreeId(), 
610
+				'user_id' => $this->user->getUserId(),
611
+				'gen' => $gen
612
+			))->fetchAssoc() ?: array();
613
+	}
614 614
     
615 615
                
616 616
 }
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -84,18 +84,18 @@  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) 
87
+        if (self::$default_user === null) 
88 88
             self::$default_user = User::find(-1);
89 89
         
90 90
         $this->tree = $tree;
91 91
         $this->user = $user;
92 92
         $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;
93
+        if ($this->user === null) $this->user = Auth::user();
94
+        if (strlen($this->user->getUserId()) == 0) $this->user = self::$default_user;
95 95
         
96 96
         // Check if the user, or the default user, has a root already setup;
97
-        if(empty($this->getRootIndiId())) {
98
-            if($this->user == self::$default_user) {  // If the default user is not setup
97
+        if (empty($this->getRootIndiId())) {
98
+            if ($this->user == self::$default_user) {  // If the default user is not setup
99 99
                 $this->is_setup = false;
100 100
             }
101 101
             else {
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function getRootIndi() {
129 129
         $root_indi_id = $this->getRootIndiId();
130
-        if(!empty($root_indi_id)) {
130
+        if (!empty($root_indi_id)) {
131 131
             return Individual::getInstance($root_indi_id, $this->tree);
132 132
         }
133 133
         return null;
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
      * Remove all Sosa entries related to the gedcom file and user
142 142
      */
143 143
     public function deleteAll() {
144
-        if(!$this->is_setup) return;
144
+        if (!$this->is_setup) return;
145 145
         Database::prepare(
146 146
             'DELETE FROM `##maj_sosa`'.
147 147
             ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
      * @param int $sosa
158 158
      */
159 159
     public function deleteAncestors($sosa) {
160
-        if(!$this->is_setup) return;
160
+        if (!$this->is_setup) return;
161 161
         $gen = Functions::getGeneration($sosa);
162 162
         Database::prepare(
163 163
             'DELETE FROM `##maj_sosa`'.
164
-            ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' .
165
-            ' AND majs_gen >= :gen' .
164
+            ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id'.
165
+            ' AND majs_gen >= :gen'.
166 166
             ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa'
167 167
         )->execute(array(
168 168
             'tree_id' => $this->tree->getTreeId(), 
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
      * @param array $sosa_records
178 178
      */
179 179
     public function insertOrUpdate($sosa_records) {
180
-        if(!$this->is_setup) return;
180
+        if (!$this->is_setup) return;
181 181
         
182 182
         $treeid = $this->tree->getTreeId();
183 183
         $userid = $this->user->getUserId();
@@ -185,9 +185,9 @@  discard block
 block discarded – undo
185 185
         $values_table = array();
186 186
         
187 187
         $i = 0;
188
-        foreach  ($sosa_records as $row) {
188
+        foreach ($sosa_records as $row) {
189 189
             $gen = Functions::getGeneration($row['sosa']);
190
-            if($gen <= self::MAX_DB_GENERATIONS) {
190
+            if ($gen <= self::MAX_DB_GENERATIONS) {
191 191
                 $questionmarks_table[] = 
192 192
                     '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')';
193 193
                 $values_table = array_merge(
@@ -206,9 +206,9 @@  discard block
 block discarded – undo
206 206
             $i++;
207 207
         }
208 208
         
209
-        $sql = 'REPLACE INTO `##maj_sosa`' .
210
-            ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' .
211
-            ' VALUES '. implode(',', $questionmarks_table);
209
+        $sql = 'REPLACE INTO `##maj_sosa`'.
210
+            ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)'.
211
+            ' VALUES '.implode(',', $questionmarks_table);
212 212
         Database::prepare($sql)->execute($values_table);
213 213
     }
214 214
     
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
      * @return array Array of sosa numbers
225 225
      */
226 226
     public function getSosaNumbers(Individual $indi) {
227
-        if(!$this->is_setup) return array();
227
+        if (!$this->is_setup) return array();
228 228
         return Database::prepare(
229 229
                 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
230 230
                 ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
      * @return number Last generation if found, 1 otherwise
242 242
      */
243 243
     public function getLastGeneration() {
244
-        if(!$this->is_setup) return;
244
+        if (!$this->is_setup) return;
245 245
         return Database::prepare(
246 246
                 'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
247 247
                 ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -260,13 +260,13 @@  discard block
 block discarded – undo
260 260
      *
261 261
      * @return array Associative array of Sosa ancestors, with their generation, comma separated
262 262
      */
263
-    public function getAllSosaWithGenerations(){
264
-        if(!$this->is_setup) return array();
263
+    public function getAllSosaWithGenerations() {
264
+        if (!$this->is_setup) return array();
265 265
         return Database::prepare(
266
-            'SELECT majs_i_id AS indi,' .
267
-            ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
268
-            ' FROM `##maj_sosa`' .
269
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' .
266
+            'SELECT majs_i_id AS indi,'.
267
+            ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations'.
268
+            ' FROM `##maj_sosa`'.
269
+            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
270 270
             ' GROUP BY majs_i_id'
271 271
         )->execute(array(
272 272
             'tree_id' => $this->tree->getTreeId(),
@@ -280,13 +280,13 @@  discard block
 block discarded – undo
280 280
      * @param number $gen Generation
281 281
      * @return array Array of Sosa individuals
282 282
      */
283
-    public function getSosaListAtGeneration($gen){
284
-        if(!$this->is_setup) return array();
285
-        if(!$this->sosa_list_by_gen)
283
+    public function getSosaListAtGeneration($gen) {
284
+        if (!$this->is_setup) return array();
285
+        if (!$this->sosa_list_by_gen)
286 286
             $this->sosa_list_by_gen = array();
287 287
         
288
-        if($gen){
289
-            if(!isset($this->sosa_list_by_gen[$gen])){
288
+        if ($gen) {
289
+            if (!isset($this->sosa_list_by_gen[$gen])) {
290 290
                 $this->sosa_list_by_gen[$gen] = Database::prepare(
291 291
                     'SELECT majs_sosa AS sosa, majs_i_id AS indi'.
292 292
                     ' FROM `##maj_sosa`'.
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
      * @param number $gen Generation
312 312
      * @return array Array of Sosa families
313 313
      */
314
-    public function getFamilySosaListAtGeneration($gen){
315
-        if(!$this->is_setup) return array();
316
-        if(!$this->sosa_fam_list_by_gen)
314
+    public function getFamilySosaListAtGeneration($gen) {
315
+        if (!$this->is_setup) return array();
316
+        if (!$this->sosa_fam_list_by_gen)
317 317
             $this->sosa_fam_list_by_gen = array();
318 318
         
319
-        if($gen){
320
-            if(!isset($this->sosa_fam_list_by_gen[$gen])){
319
+        if ($gen) {
320
+            if (!isset($this->sosa_fam_list_by_gen[$gen])) {
321 321
                 $this->sosa_fam_list_by_gen[$gen] = Database::prepare(
322 322
                     'SELECT s1.majs_sosa AS sosa, f_id AS fam'.
323 323
                     ' FROM `##families`'.
@@ -347,9 +347,9 @@  discard block
 block discarded – undo
347 347
      * @param number $gen Generation
348 348
      * @return array Array of Sosa individuals
349 349
      */
350
-    public function getMissingSosaListAtGeneration($gen){
351
-        if(!$this->is_setup) return array();    
352
-        if($gen){
350
+    public function getMissingSosaListAtGeneration($gen) {
351
+        if (!$this->is_setup) return array();    
352
+        if ($gen) {
353 353
             return $this->sosa_list_by_gen[$gen] = Database::prepare(
354 354
                 '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'.
355 355
                 ' FROM `##maj_sosa` schild'.
@@ -386,10 +386,10 @@  discard block
 block discarded – undo
386 386
      * @return array Statistics array
387 387
      */
388 388
     public function getStatisticsByGeneration() {
389
-        if(!$this->is_setup) return array();
390
-        if(!$this->statistics_tab) {
389
+        if (!$this->is_setup) return array();
390
+        if (!$this->statistics_tab) {
391 391
             $this->statistics_tab = array();
392
-            if($maxGeneration = $this->getLastGeneration()) {
392
+            if ($maxGeneration = $this->getLastGeneration()) {
393 393
                 for ($gen = 1; $gen <= $maxGeneration; $gen++) {
394 394
                     $birthStats = $this->getStatsBirthYearInGeneration($gen);
395 395
                     $this->statistics_tab[$gen] = array(
@@ -412,9 +412,9 @@  discard block
 block discarded – undo
412 412
 	 * @return int
413 413
 	 */
414 414
 	public function getTotalIndividuals() {
415
-	    if(!$this->is_setup) return 0;
415
+	    if (!$this->is_setup) return 0;
416 416
 	    return Database::prepare(
417
-	        'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' .
417
+	        'SELECT SQL_CACHE COUNT(*) FROM `##individuals`'.
418 418
 	        ' WHERE i_file = :tree_id')
419 419
 	        ->execute(array('tree_id' => $this->tree->getTreeId()))
420 420
 	        ->fetchOne() ?: 0;
@@ -425,10 +425,10 @@  discard block
 block discarded – undo
425 425
      *
426 426
      * @return number Number of Sosas
427 427
      */
428
-    public function getSosaCount(){
429
-        if(!$this->is_setup) return 0;
428
+    public function getSosaCount() {
429
+        if (!$this->is_setup) return 0;
430 430
         return Database::prepare(
431
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
431
+            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'.
432 432
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
433 433
             ->execute(array(
434 434
                 'tree_id' => $this->tree->getTreeId(), 
@@ -442,10 +442,10 @@  discard block
 block discarded – undo
442 442
      * @param number $gen Generation
443 443
      * @return number Number of Sosas in generation
444 444
      */
445
-    public function getSosaCountAtGeneration($gen){
446
-        if(!$this->is_setup) return 0;
445
+    public function getSosaCountAtGeneration($gen) {
446
+        if (!$this->is_setup) return 0;
447 447
         return Database::prepare(
448
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
448
+            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'.
449 449
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
450 450
             ' AND majs_gen= :gen')
451 451
         ->execute(array(
@@ -461,10 +461,10 @@  discard block
 block discarded – undo
461 461
      * @param number $gen Generation
462 462
      * @return number Total number of Sosas up to generation
463 463
      */
464
-    public function getSosaCountUpToGeneration($gen){
465
-        if(!$this->is_setup) return 0;
464
+    public function getSosaCountUpToGeneration($gen) {
465
+        if (!$this->is_setup) return 0;
466 466
         return Database::prepare(
467
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
467
+            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'.
468 468
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
469 469
             ' AND majs_gen <= :gen')
470 470
         ->execute(array(
@@ -479,10 +479,10 @@  discard block
 block discarded – undo
479 479
      *
480 480
      * @return number Total number of distinct individual
481 481
      */
482
-    public function getDifferentSosaCount(){
483
-        if(!$this->is_setup) return 0;
482
+    public function getDifferentSosaCount() {
483
+        if (!$this->is_setup) return 0;
484 484
         return Database::prepare(
485
-            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
485
+            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'.
486 486
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
487 487
         ->execute(array(
488 488
                 'tree_id' => $this->tree->getTreeId(), 
@@ -496,10 +496,10 @@  discard block
 block discarded – undo
496 496
      * @param number $gen Generation
497 497
      * @return number Number of distinct Sosa individuals up to generation
498 498
      */
499
-    public function getDifferentSosaCountUpToGeneration($gen){
500
-        if(!$this->is_setup) return 0;
499
+    public function getDifferentSosaCountUpToGeneration($gen) {
500
+        if (!$this->is_setup) return 0;
501 501
         return Database::prepare(
502
-            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
502
+            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'.
503 503
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
504 504
             ' AND majs_gen <= :gen')
505 505
         ->execute(array(
@@ -519,11 +519,11 @@  discard block
 block discarded – undo
519 519
      * @param number $gen Generation
520 520
      * @return array Birth statistics array
521 521
      */
522
-    public function getStatsBirthYearInGeneration($gen){
523
-        if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
522
+    public function getStatsBirthYearInGeneration($gen) {
523
+        if (!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
524 524
         return Database::prepare(
525 525
             'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'.
526
-            ' FROM `##maj_sosa`' .
526
+            ' FROM `##maj_sosa`'.
527 527
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
528 528
             ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year')
529 529
             ->execute(array(
@@ -539,26 +539,26 @@  discard block
 block discarded – undo
539 539
      *
540 540
      * @return number|NULL Mean generation time
541 541
      */
542
-    public function getMeanGenerationTime(){
543
-        if(!$this->is_setup) return;
544
-        if(!$this->statistics_tab){
542
+    public function getMeanGenerationTime() {
543
+        if (!$this->is_setup) return;
544
+        if (!$this->statistics_tab) {
545 545
             $this->getStatisticsByGeneration();
546 546
         }
547 547
         //Linear regression on x=generation and y=birthdate
548 548
         $sum_xy = 0;
549
-        $sum_x=0;
550
-        $sum_y=0;
551
-        $sum_x2=0;
552
-        $n=count($this->statistics_tab);
553
-        foreach($this->statistics_tab as $gen=>$stats){
554
-            $sum_xy+=$gen*$stats['avgBirth'];
555
-            $sum_x+=$gen;
556
-            $sum_y+=$stats['avgBirth'];
557
-            $sum_x2+=$gen*$gen;
549
+        $sum_x = 0;
550
+        $sum_y = 0;
551
+        $sum_x2 = 0;
552
+        $n = count($this->statistics_tab);
553
+        foreach ($this->statistics_tab as $gen=>$stats) {
554
+            $sum_xy += $gen * $stats['avgBirth'];
555
+            $sum_x += $gen;
556
+            $sum_y += $stats['avgBirth'];
557
+            $sum_x2 += $gen * $gen;
558 558
         }
559
-        $denom=($n*$sum_x2)-($sum_x*$sum_x);
560
-        if($denom!=0){
561
-            return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom);
559
+        $denom = ($n * $sum_x2) - ($sum_x * $sum_x);
560
+        if ($denom != 0) {
561
+            return -(($n * $sum_xy) - ($sum_x * $sum_y)) / ($denom);
562 562
         }
563 563
         return null;
564 564
     }
@@ -586,14 +586,14 @@  discard block
 block discarded – undo
586 586
      * @return array
587 587
      */
588 588
     public function getAncestorDispersionForGen($gen) {
589
-        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
589
+        if (!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query
590 590
         return Database::prepare(
591 591
             'SELECT branches, count(i_id)'.
592 592
             ' FROM ('.
593 593
             '   SELECT i_id,'.
594 594
             '       CASE'.
595 595
             '           WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
596
-            '           ELSE -1'.   // We put all ancestors shared between some branches in the same bucket
596
+            '           ELSE -1'.// We put all ancestors shared between some branches in the same bucket
597 597
             '       END branches'.
598 598
             '   FROM ('.
599 599
             '       SELECT DISTINCT majs_i_id i_id,'.
Please login to merge, or discard this patch.
Braces   +74 added lines, -29 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();
@@ -224,7 +234,9 @@  discard block
 block discarded – undo
224 234
      * @return array Array of sosa numbers
225 235
      */
226 236
     public function getSosaNumbers(Individual $indi) {
227
-        if(!$this->is_setup) return array();
237
+        if(!$this->is_setup) {
238
+        	return array();
239
+        }
228 240
         return Database::prepare(
229 241
                 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
230 242
                 ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -241,7 +253,9 @@  discard block
 block discarded – undo
241 253
      * @return number Last generation if found, 1 otherwise
242 254
      */
243 255
     public function getLastGeneration() {
244
-        if(!$this->is_setup) return;
256
+        if(!$this->is_setup) {
257
+        	return;
258
+        }
245 259
         return Database::prepare(
246 260
                 'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
247 261
                 ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -261,7 +275,9 @@  discard block
 block discarded – undo
261 275
      * @return array Associative array of Sosa ancestors, with their generation, comma separated
262 276
      */
263 277
     public function getAllSosaWithGenerations(){
264
-        if(!$this->is_setup) return array();
278
+        if(!$this->is_setup) {
279
+        	return array();
280
+        }
265 281
         return Database::prepare(
266 282
             'SELECT majs_i_id AS indi,' .
267 283
             ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
@@ -281,9 +297,12 @@  discard block
 block discarded – undo
281 297
      * @return array Array of Sosa individuals
282 298
      */
283 299
     public function getSosaListAtGeneration($gen){
284
-        if(!$this->is_setup) return array();
285
-        if(!$this->sosa_list_by_gen)
286
-            $this->sosa_list_by_gen = array();
300
+        if(!$this->is_setup) {
301
+        	return array();
302
+        }
303
+        if(!$this->sosa_list_by_gen) {
304
+                    $this->sosa_list_by_gen = array();
305
+        }
287 306
         
288 307
         if($gen){
289 308
             if(!isset($this->sosa_list_by_gen[$gen])){
@@ -312,9 +331,12 @@  discard block
 block discarded – undo
312 331
      * @return array Array of Sosa families
313 332
      */
314 333
     public function getFamilySosaListAtGeneration($gen){
315
-        if(!$this->is_setup) return array();
316
-        if(!$this->sosa_fam_list_by_gen)
317
-            $this->sosa_fam_list_by_gen = array();
334
+        if(!$this->is_setup) {
335
+        	return array();
336
+        }
337
+        if(!$this->sosa_fam_list_by_gen) {
338
+                    $this->sosa_fam_list_by_gen = array();
339
+        }
318 340
         
319 341
         if($gen){
320 342
             if(!isset($this->sosa_fam_list_by_gen[$gen])){
@@ -348,7 +370,9 @@  discard block
 block discarded – undo
348 370
      * @return array Array of Sosa individuals
349 371
      */
350 372
     public function getMissingSosaListAtGeneration($gen){
351
-        if(!$this->is_setup) return array();    
373
+        if(!$this->is_setup) {
374
+        	return array();
375
+        }
352 376
         if($gen){
353 377
             return $this->sosa_list_by_gen[$gen] = Database::prepare(
354 378
                 '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'.
@@ -386,7 +410,9 @@  discard block
 block discarded – undo
386 410
      * @return array Statistics array
387 411
      */
388 412
     public function getStatisticsByGeneration() {
389
-        if(!$this->is_setup) return array();
413
+        if(!$this->is_setup) {
414
+        	return array();
415
+        }
390 416
         if(!$this->statistics_tab) {
391 417
             $this->statistics_tab = array();
392 418
             if($maxGeneration = $this->getLastGeneration()) {
@@ -412,7 +438,9 @@  discard block
 block discarded – undo
412 438
 	 * @return int
413 439
 	 */
414 440
 	public function getTotalIndividuals() {
415
-	    if(!$this->is_setup) return 0;
441
+	    if(!$this->is_setup) {
442
+	    	return 0;
443
+	    }
416 444
 	    return Database::prepare(
417 445
 	        'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' .
418 446
 	        ' WHERE i_file = :tree_id')
@@ -426,7 +454,9 @@  discard block
 block discarded – undo
426 454
      * @return number Number of Sosas
427 455
      */
428 456
     public function getSosaCount(){
429
-        if(!$this->is_setup) return 0;
457
+        if(!$this->is_setup) {
458
+        	return 0;
459
+        }
430 460
         return Database::prepare(
431 461
             'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
432 462
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
@@ -443,7 +473,9 @@  discard block
 block discarded – undo
443 473
      * @return number Number of Sosas in generation
444 474
      */
445 475
     public function getSosaCountAtGeneration($gen){
446
-        if(!$this->is_setup) return 0;
476
+        if(!$this->is_setup) {
477
+        	return 0;
478
+        }
447 479
         return Database::prepare(
448 480
             'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
449 481
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -462,7 +494,9 @@  discard block
 block discarded – undo
462 494
      * @return number Total number of Sosas up to generation
463 495
      */
464 496
     public function getSosaCountUpToGeneration($gen){
465
-        if(!$this->is_setup) return 0;
497
+        if(!$this->is_setup) {
498
+        	return 0;
499
+        }
466 500
         return Database::prepare(
467 501
             'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
468 502
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -480,7 +514,9 @@  discard block
 block discarded – undo
480 514
      * @return number Total number of distinct individual
481 515
      */
482 516
     public function getDifferentSosaCount(){
483
-        if(!$this->is_setup) return 0;
517
+        if(!$this->is_setup) {
518
+        	return 0;
519
+        }
484 520
         return Database::prepare(
485 521
             'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
486 522
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
@@ -497,7 +533,9 @@  discard block
 block discarded – undo
497 533
      * @return number Number of distinct Sosa individuals up to generation
498 534
      */
499 535
     public function getDifferentSosaCountUpToGeneration($gen){
500
-        if(!$this->is_setup) return 0;
536
+        if(!$this->is_setup) {
537
+        	return 0;
538
+        }
501 539
         return Database::prepare(
502 540
             'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
503 541
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -520,7 +558,9 @@  discard block
 block discarded – undo
520 558
      * @return array Birth statistics array
521 559
      */
522 560
     public function getStatsBirthYearInGeneration($gen){
523
-        if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
561
+        if(!$this->is_setup) {
562
+        	return array('first' => 0, 'avg' => 0, 'last' => 0);
563
+        }
524 564
         return Database::prepare(
525 565
             'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'.
526 566
             ' FROM `##maj_sosa`' .
@@ -540,7 +580,9 @@  discard block
 block discarded – undo
540 580
      * @return number|NULL Mean generation time
541 581
      */
542 582
     public function getMeanGenerationTime(){
543
-        if(!$this->is_setup) return;
583
+        if(!$this->is_setup) {
584
+        	return;
585
+        }
544 586
         if(!$this->statistics_tab){
545 587
             $this->getStatisticsByGeneration();
546 588
         }
@@ -586,7 +628,10 @@  discard block
 block discarded – undo
586 628
      * @return array
587 629
      */
588 630
     public function getAncestorDispersionForGen($gen) {
589
-        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
631
+        if(!$this->is_setup || $gen > 11) {
632
+        	return array();
633
+        }
634
+        // Going further than 11 gen will be out of range in the query
590 635
         return Database::prepare(
591 636
             'SELECT branches, count(i_id)'.
592 637
             ' FROM ('.
Please login to merge, or discard this patch.
src/Webtrees/Map/GoogleMapsProvider.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -25,14 +25,14 @@  discard block
 block discarded – undo
25 25
 	 * @see \MyArtJaub\Webtrees\Map\MapProviderInterface::getProviderPlaceId()
26 26
 	 */
27 27
 	public function getProviderPlaceId(\Fisharebest\Webtrees\Place $place) {
28
-		if(!$place->isEmpty()) {
29
-			$parent = array_reverse(explode (',', $place->getGedcomName()));
28
+		if (!$place->isEmpty()) {
29
+			$parent = array_reverse(explode(',', $place->getGedcomName()));
30 30
 			$place_id = 0;
31 31
 			$nb_levels = count($parent);
32
-			for ($i=0; $i < $nb_levels; $i++) {
32
+			for ($i = 0; $i < $nb_levels; $i++) {
33 33
 				$parent[$i] = trim($parent[$i]);
34
-				if (empty($parent[$i])) $parent[$i]='unknown';// GoogleMap module uses "unknown" while GEDCOM uses , ,
35
-				$pl_id=Database::prepare('SELECT pl_id FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place')
34
+				if (empty($parent[$i])) $parent[$i] = 'unknown'; // GoogleMap module uses "unknown" while GEDCOM uses , ,
35
+				$pl_id = Database::prepare('SELECT pl_id FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place')
36 36
 					->execute(array($i, $place_id, $parent[$i]))
37 37
 					->fetchOne();
38 38
 				if (empty($pl_id)) break;
@@ -48,12 +48,12 @@  discard block
 block discarded – undo
48 48
 	 * @see \MyArtJaub\Webtrees\Map\MapProviderInterface::getPlaceIcon()
49 49
 	 */
50 50
 	public function getPlaceIcon(\Fisharebest\Webtrees\Place $place) {
51
-		if(!$place->isEmpty()){
51
+		if (!$place->isEmpty()) {
52 52
 			$place_details =
53 53
 				Database::prepare('SELECT SQL_CACHE pl_icon FROM `##placelocation` WHERE pl_id=? ORDER BY pl_place')	
54 54
 				->execute(array($this->getProviderPlaceId($place)))
55 55
 				->fetchOneRow();
56
-			if($place_details){
56
+			if ($place_details) {
57 57
 				return WT_MODULES_DIR.'googlemap/'.$place_details->pl_icon;
58 58
 			}
59 59
 		}
Please login to merge, or discard this patch.
Braces   +7 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,11 +31,16 @@
 block discarded – undo
31 31
 			$nb_levels = count($parent);
32 32
 			for ($i=0; $i < $nb_levels; $i++) {
33 33
 				$parent[$i] = trim($parent[$i]);
34
-				if (empty($parent[$i])) $parent[$i]='unknown';// GoogleMap module uses "unknown" while GEDCOM uses , ,
34
+				if (empty($parent[$i])) {
35
+					$parent[$i]='unknown';
36
+				}
37
+				// GoogleMap module uses "unknown" while GEDCOM uses , ,
35 38
 				$pl_id=Database::prepare('SELECT pl_id FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place')
36 39
 					->execute(array($i, $place_id, $parent[$i]))
37 40
 					->fetchOne();
38
-				if (empty($pl_id)) break;
41
+				if (empty($pl_id)) {
42
+					break;
43
+				}
39 44
 				$place_id = $pl_id;
40 45
 			}
41 46
 			return $place_id;
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Views/SosaConfigView.php 2 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 	 * {@inhericDoc}
25 25
 	 * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent()
26 26
 	 */
27
-    protected function renderContent() {
27
+	protected function renderContent() {
28 28
         
29
-        ?>        
29
+		?>        
30 30
         
31 31
         <div id="maj-sosa-config-page">
32 32
 			<h2><?php echo $this->data->get('title'); ?></h2>
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
         			</div>
47 47
         			<div class="value">
48 48
         				<?php 
49
-        				    $users = $this->data->get('users_settings');
50
-        				    if(count($users) == 1) {
51
-        				        $root_indi = $users[0]['rootid'];  ?>
49
+							$users = $this->data->get('users_settings');
50
+							if(count($users) == 1) {
51
+								$root_indi = $users[0]['rootid'];  ?>
52 52
         					<label>
53 53
         						<input id="maj_sosa_input_userid" type="hidden" name="userid" value="<?php echo $users[0]['user']->getUserId(); ?>" />
54 54
         						<?php echo $users[0]['user']->getRealNameHtml() ?>
@@ -56,8 +56,8 @@  discard block
 block discarded – undo
56 56
         				<?php  } else if(count($users) > 1) { ?>
57 57
         					<select id='maj-sosa-config-select' name="userid">
58 58
         					<?php 
59
-        					   $root_indi = $users[0]['rootid'];
60
-        					   foreach ($this->data->get('users_settings') as $user) { ?>
59
+							   $root_indi = $users[0]['rootid'];
60
+							   foreach ($this->data->get('users_settings') as $user) { ?>
61 61
         						<option value="<?php echo $user['user']->getUserId(); ?>"><?php echo $user['user']->getRealNameHtml() ?></option>
62 62
         					<?php  } ?>
63 63
         					</select>
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 			</form>	
81 81
 		
82 82
 		<?php        
83
-    }
83
+	}
84 84
     
85 85
 }
86 86
  
87 87
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -47,13 +47,13 @@
 block discarded – undo
47 47
         			<div class="value">
48 48
         				<?php 
49 49
         				    $users = $this->data->get('users_settings');
50
-        				    if(count($users) == 1) {
51
-        				        $root_indi = $users[0]['rootid'];  ?>
50
+        				    if (count($users) == 1) {
51
+        				        $root_indi = $users[0]['rootid']; ?>
52 52
         					<label>
53 53
         						<input id="maj_sosa_input_userid" type="hidden" name="userid" value="<?php echo $users[0]['user']->getUserId(); ?>" />
54 54
         						<?php echo $users[0]['user']->getRealNameHtml() ?>
55 55
         					</label>
56
-        				<?php  } else if(count($users) > 1) { ?>
56
+        				<?php  } else if (count($users) > 1) { ?>
57 57
         					<select id='maj-sosa-config-select' name="userid">
58 58
         					<?php 
59 59
         					   $root_indi = $users[0]['rootid'];
Please login to merge, or discard this patch.
src/Webtrees/Hook/HookProvider.php 3 patches
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -43,11 +43,11 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public static function getInstance()
45 45
 	{
46
-	    if (null === static::$instance) {
47
-	        static::$instance = new static();
48
-	    }
46
+		if (null === static::$instance) {
47
+			static::$instance = new static();
48
+		}
49 49
 	
50
-	    return static::$instance;
50
+		return static::$instance;
51 51
 	}
52 52
 	
53 53
 	/**
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
 	 * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::get()
56 56
 	 */
57 57
 	public function get($hook_function, $hook_context = null) {
58
-	    return new Hook($hook_function, $hook_context);
58
+		return new Hook($hook_function, $hook_context);
59 59
 	}
60 60
 	
61 61
 	/**
@@ -73,20 +73,20 @@  discard block
 block discarded – undo
73 73
 	public function getPossibleHooks() {
74 74
 		static $hooks=null;
75 75
 		if ($hooks === null) {
76
-		    $hooks = array();
76
+			$hooks = array();
77 77
 		    
78
-		    // Cannot use the same logic as the core Module loading,
79
-		    // as this forces a new include of the module.php file.
80
-		    // This causes issue when classes are defined in this file.
81
-		    // Cannot use Module::getActiveModules as well, as this is private.
82
-		    $module_names = Database::prepare(
83
-		        'SELECT SQL_CACHE module_name FROM `##module`'
84
-		    )->fetchOneColumn();
78
+			// Cannot use the same logic as the core Module loading,
79
+			// as this forces a new include of the module.php file.
80
+			// This causes issue when classes are defined in this file.
81
+			// Cannot use Module::getActiveModules as well, as this is private.
82
+			$module_names = Database::prepare(
83
+				'SELECT SQL_CACHE module_name FROM `##module`'
84
+			)->fetchOneColumn();
85 85
 		    
86
-		    foreach($module_names as $module_name) {
87
-		        $module = Module::getModuleByName($module_name);
86
+			foreach($module_names as $module_name) {
87
+				$module = Module::getModuleByName($module_name);
88 88
 		        
89
-		        if($module instanceof HookSubscriberInterface){
89
+				if($module instanceof HookSubscriberInterface){
90 90
 					$subscribedhooks = $module->getSubscribedHooks();
91 91
 					if(is_array($subscribedhooks)){
92 92
 						foreach($subscribedhooks as $key => $value){
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 							}
112 112
 						}
113 113
 					}
114
-		        }
114
+				}
115 115
 			}
116 116
 		}
117 117
 		return $hooks;
@@ -153,33 +153,33 @@  discard block
 block discarded – undo
153 153
 	 */
154 154
 	public function updateHooks() {
155 155
 	    
156
-	    if(Auth::isAdmin()){
157
-	        $ihooks = self::getInstalledHooks();
158
-	        $phooks = self::getPossibleHooks();
156
+		if(Auth::isAdmin()){
157
+			$ihooks = self::getInstalledHooks();
158
+			$phooks = self::getPossibleHooks();
159 159
 	        	
160
-	        // Insert hooks not existing yet in the DB
161
-	        if($phooks !== null){
162
-	            foreach($phooks as $phook => $priority){
163
-	                $array_hook = explode('#', $phook);
164
-	                if($ihooks === null || !array_key_exists($phook, $ihooks)){
165
-	                    $chook = new Hook($array_hook[1], $array_hook[2]);
166
-	                    $chook->subscribe($array_hook[0]);
167
-	                    $chook->setPriority($array_hook[0], $priority);
168
-	                }
169
-	            }
170
-	        }
160
+			// Insert hooks not existing yet in the DB
161
+			if($phooks !== null){
162
+				foreach($phooks as $phook => $priority){
163
+					$array_hook = explode('#', $phook);
164
+					if($ihooks === null || !array_key_exists($phook, $ihooks)){
165
+						$chook = new Hook($array_hook[1], $array_hook[2]);
166
+						$chook->subscribe($array_hook[0]);
167
+						$chook->setPriority($array_hook[0], $priority);
168
+					}
169
+				}
170
+			}
171 171
 	        	
172
-	        //Remove hooks not existing any more in the file system
173
-	        if($ihooks !== null){
174
-	            foreach(array_keys($ihooks) as $ihook){
175
-	                $array_hook = explode('#', $ihook);
176
-	                if($phooks === null || !array_key_exists($ihook, $phooks)){
177
-	                    $chook = new Hook($array_hook[1], $array_hook[2]);
178
-	                    $chook->remove($array_hook[0]);
179
-	                }
180
-	            }
181
-	        }
182
-	    }
172
+			//Remove hooks not existing any more in the file system
173
+			if($ihooks !== null){
174
+				foreach(array_keys($ihooks) as $ihook){
175
+					$array_hook = explode('#', $ihook);
176
+					if($phooks === null || !array_key_exists($ihook, $phooks)){
177
+						$chook = new Hook($array_hook[1], $array_hook[2]);
178
+						$chook->remove($array_hook[0]);
179
+					}
180
+				}
181
+			}
182
+		}
183 183
 	}
184 184
 	
185 185
 }
186 186
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 	 * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getPossibleHooks()
72 72
 	 */
73 73
 	public function getPossibleHooks() {
74
-		static $hooks=null;
74
+		static $hooks = null;
75 75
 		if ($hooks === null) {
76 76
 		    $hooks = array();
77 77
 		    
@@ -83,31 +83,31 @@  discard block
 block discarded – undo
83 83
 		        'SELECT SQL_CACHE module_name FROM `##module`'
84 84
 		    )->fetchOneColumn();
85 85
 		    
86
-		    foreach($module_names as $module_name) {
86
+		    foreach ($module_names as $module_name) {
87 87
 		        $module = Module::getModuleByName($module_name);
88 88
 		        
89
-		        if($module instanceof HookSubscriberInterface){
89
+		        if ($module instanceof HookSubscriberInterface) {
90 90
 					$subscribedhooks = $module->getSubscribedHooks();
91
-					if(is_array($subscribedhooks)){
92
-						foreach($subscribedhooks as $key => $value){
93
-							if(is_int($key)) {
91
+					if (is_array($subscribedhooks)) {
92
+						foreach ($subscribedhooks as $key => $value) {
93
+							if (is_int($key)) {
94 94
 								$hook_item = $value;
95 95
 								$priority = self::DEFAULT_PRIORITY;
96 96
 							}
97
-							else{
97
+							else {
98 98
 								$hook_item = explode('#', $key, 2);
99 99
 								$priority = $value;
100 100
 							}
101
-							if($hook_item && count($hook_item) == 2){
101
+							if ($hook_item && count($hook_item) == 2) {
102 102
 								$hook_func = $hook_item[0];
103 103
 								$hook_cont = $hook_item[1];
104 104
 							}
105
-							else{
105
+							else {
106 106
 								$hook_func = $hook_item[0];
107 107
 								$hook_cont = 'all';
108 108
 							}
109
-							if(method_exists($module, $hook_func)){
110
-								$hooks[$module->getName().'#'.$hook_func.'#'.$hook_cont]=$priority;
109
+							if (method_exists($module, $hook_func)) {
110
+								$hooks[$module->getName().'#'.$hook_func.'#'.$hook_cont] = $priority;
111 111
 							}
112 112
 						}
113 113
 					}
@@ -121,8 +121,8 @@  discard block
 block discarded – undo
121 121
 	 * {@inheritDoc}
122 122
 	 * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getRawInstalledHooks()
123 123
 	 */
124
-	public function getRawInstalledHooks(){
125
-		if(self::isModuleOperational()){
124
+	public function getRawInstalledHooks() {
125
+		if (self::isModuleOperational()) {
126 126
 			return Database::prepare(
127 127
 					"SELECT majh_id AS id, majh_module_name AS module, majh_hook_function AS hook, majh_hook_context as context, majh_module_priority AS priority,  majh_status AS status".
128 128
 					" FROM `##maj_hooks`".
@@ -136,11 +136,11 @@  discard block
 block discarded – undo
136 136
 	 * {@inheritDoc}
137 137
 	 * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::getInstalledHooks()
138 138
 	 */
139
-	public function getInstalledHooks(){
140
-		static $installedhooks =null;
141
-		if($installedhooks===null){
142
-			$dbhooks=self::getRawInstalledHooks();
143
-			foreach($dbhooks as $dbhook){
139
+	public function getInstalledHooks() {
140
+		static $installedhooks = null;
141
+		if ($installedhooks === null) {
142
+			$dbhooks = self::getRawInstalledHooks();
143
+			foreach ($dbhooks as $dbhook) {
144 144
 				$installedhooks[($dbhook->module).'#'.($dbhook->hook).'#'.($dbhook->context)] = array('id' => $dbhook->id, 'status' => $dbhook->status, 'priority' => $dbhook->priority);
145 145
 			}
146 146
 		}
@@ -153,15 +153,15 @@  discard block
 block discarded – undo
153 153
 	 */
154 154
 	public function updateHooks() {
155 155
 	    
156
-	    if(Auth::isAdmin()){
156
+	    if (Auth::isAdmin()) {
157 157
 	        $ihooks = self::getInstalledHooks();
158 158
 	        $phooks = self::getPossibleHooks();
159 159
 	        	
160 160
 	        // Insert hooks not existing yet in the DB
161
-	        if($phooks !== null){
162
-	            foreach($phooks as $phook => $priority){
161
+	        if ($phooks !== null) {
162
+	            foreach ($phooks as $phook => $priority) {
163 163
 	                $array_hook = explode('#', $phook);
164
-	                if($ihooks === null || !array_key_exists($phook, $ihooks)){
164
+	                if ($ihooks === null || !array_key_exists($phook, $ihooks)) {
165 165
 	                    $chook = new Hook($array_hook[1], $array_hook[2]);
166 166
 	                    $chook->subscribe($array_hook[0]);
167 167
 	                    $chook->setPriority($array_hook[0], $priority);
@@ -170,10 +170,10 @@  discard block
 block discarded – undo
170 170
 	        }
171 171
 	        	
172 172
 	        //Remove hooks not existing any more in the file system
173
-	        if($ihooks !== null){
174
-	            foreach(array_keys($ihooks) as $ihook){
173
+	        if ($ihooks !== null) {
174
+	            foreach (array_keys($ihooks) as $ihook) {
175 175
 	                $array_hook = explode('#', $ihook);
176
-	                if($phooks === null || !array_key_exists($ihook, $phooks)){
176
+	                if ($phooks === null || !array_key_exists($ihook, $phooks)) {
177 177
 	                    $chook = new Hook($array_hook[1], $array_hook[2]);
178 178
 	                    $chook->remove($array_hook[0]);
179 179
 	                }
Please login to merge, or discard this patch.
Braces   +2 added lines, -4 removed lines patch added patch discarded remove patch
@@ -93,16 +93,14 @@
 block discarded – undo
93 93
 							if(is_int($key)) {
94 94
 								$hook_item = $value;
95 95
 								$priority = self::DEFAULT_PRIORITY;
96
-							}
97
-							else{
96
+							} else{
98 97
 								$hook_item = explode('#', $key, 2);
99 98
 								$priority = $value;
100 99
 							}
101 100
 							if($hook_item && count($hook_item) == 2){
102 101
 								$hook_func = $hook_item[0];
103 102
 								$hook_cont = $hook_item[1];
104
-							}
105
-							else{
103
+							} else{
106 104
 								$hook_func = $hook_item[0];
107 105
 								$hook_cont = 'all';
108 106
 							}
Please login to merge, or discard this patch.
src/Webtrees/Controller/JsonController.php 1 patch
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -18,50 +18,50 @@
 block discarded – undo
18 18
  */
19 19
 class JsonController extends BaseController {
20 20
     
21
-    /**
22
-     * {@inheritDoc}
23
-     * @see \Fisharebest\Webtrees\Controller\BaseController::pageHeader()
24
-     */
25
-    public function pageHeader() {        
26
-        header('Content-Type: application/json');
27
-        header('Cache-Control: no-cache, must-revalidate');
28
-        header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
29
-        // We've displayed the header - display the footer automatically
30
-        register_shutdown_function(array($this, 'pageFooter'));
21
+	/**
22
+	 * {@inheritDoc}
23
+	 * @see \Fisharebest\Webtrees\Controller\BaseController::pageHeader()
24
+	 */
25
+	public function pageHeader() {        
26
+		header('Content-Type: application/json');
27
+		header('Cache-Control: no-cache, must-revalidate');
28
+		header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
29
+		// We've displayed the header - display the footer automatically
30
+		register_shutdown_function(array($this, 'pageFooter'));
31 31
         
32
-        return $this;
33
-    }
32
+		return $this;
33
+	}
34 34
     
35
-    /**
36
-     * {@inheritDoc}
37
-     * @see \Fisharebest\Webtrees\Controller\BaseController::pageFooter()
38
-     */
39
-    public function pageFooter() {
40
-        return $this;
41
-    }
35
+	/**
36
+	 * {@inheritDoc}
37
+	 * @see \Fisharebest\Webtrees\Controller\BaseController::pageFooter()
38
+	 */
39
+	public function pageFooter() {
40
+		return $this;
41
+	}
42 42
     
43
-    /**
44
-     * Restrict access.
45
-     *
46
-     * @param bool $condition
47
-     *
48
-     * @return $this
49
-     */
50
-    public function restrictAccess($condition) {
51
-        if ($condition !== true) {
52
-            throw new MvcException(403);
53
-        }
43
+	/**
44
+	 * Restrict access.
45
+	 *
46
+	 * @param bool $condition
47
+	 *
48
+	 * @return $this
49
+	 */
50
+	public function restrictAccess($condition) {
51
+		if ($condition !== true) {
52
+			throw new MvcException(403);
53
+		}
54 54
     
55
-        return $this;
56
-    }
55
+		return $this;
56
+	}
57 57
     
58
-    /**
59
-     * Encode the data to JSON format.
60
-     * 
61
-     * @param array $data Data to encode
62
-     * @param number $options JSON options mask. See http://php.net/manual/fr/json.constants.php
63
-     */
64
-    public function encode(array $data, $options = 0) {
65
-        echo json_encode($data, $options);
66
-    }
58
+	/**
59
+	 * Encode the data to JSON format.
60
+	 * 
61
+	 * @param array $data Data to encode
62
+	 * @param number $options JSON options mask. See http://php.net/manual/fr/json.constants.php
63
+	 */
64
+	public function encode(array $data, $options = 0) {
65
+		echo json_encode($data, $options);
66
+	}
67 67
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/GeoDispersion/GeoAnalysisController.php 3 patches
Indentation   +231 added lines, -231 removed lines patch added patch discarded remove patch
@@ -35,47 +35,47 @@  discard block
 block discarded – undo
35 35
  */
36 36
 class GeoAnalysisController extends MvcController
37 37
 {
38
-    /**
39
-     * GeoAnalysis Provider
40
-     * @var GeoAnalysisProvider $provider
41
-     */
42
-    protected $provider;
38
+	/**
39
+	 * GeoAnalysis Provider
40
+	 * @var GeoAnalysisProvider $provider
41
+	 */
42
+	protected $provider;
43 43
     
44
-    /**
45
-     * Constructor for GeoAnalysis controller
46
-     * @param AbstractModule $module
47
-     */
48
-    public function __construct(AbstractModule $module) {
49
-        parent::__construct($module);
44
+	/**
45
+	 * Constructor for GeoAnalysis controller
46
+	 * @param AbstractModule $module
47
+	 */
48
+	public function __construct(AbstractModule $module) {
49
+		parent::__construct($module);
50 50
         
51
-        $this->provider = $this->module->getProvider();
52
-    }    
51
+		$this->provider = $this->module->getProvider();
52
+	}    
53 53
     
54
-    /**
55
-     * Pages
56
-     */
54
+	/**
55
+	 * Pages
56
+	 */
57 57
         
58
-    /**
59
-     * GeoAnalysis@index
60
-     */
61
-    public function index() {
58
+	/**
59
+	 * GeoAnalysis@index
60
+	 */
61
+	public function index() {
62 62
         
63
-        $controller = new PageController();
64
-        $controller->setPageTitle(I18N::translate('Sosa Geographical dispersion'));
63
+		$controller = new PageController();
64
+		$controller->setPageTitle(I18N::translate('Sosa Geographical dispersion'));
65 65
         
66
-        $data = new ViewBag();
67
-        $data->set('title', $controller->getPageTitle());
68
-        $data->set('has_analysis', false);
66
+		$data = new ViewBag();
67
+		$data->set('title', $controller->getPageTitle());
68
+		$data->set('has_analysis', false);
69 69
         
70
-        $ga_id = Filter::getInteger('ga_id');        
70
+		$ga_id = Filter::getInteger('ga_id');        
71 71
         
72
-        if($ga_id && $ga = $this->provider->getGeoAnalysis($ga_id)) {
73
-            $data->set('has_analysis', true);
74
-            $data->set('geoanalysis', $ga);
72
+		if($ga_id && $ga = $this->provider->getGeoAnalysis($ga_id)) {
73
+			$data->set('has_analysis', true);
74
+			$data->set('geoanalysis', $ga);
75 75
             
76
-            $controller
77
-                ->addExternalJavascript(Constants::WT_RAPHAEL_JS_URL())
78
-                ->addInlineJavascript('
76
+			$controller
77
+				->addExternalJavascript(Constants::WT_RAPHAEL_JS_URL())
78
+				->addInlineJavascript('
79 79
                 jQuery("#geodispersion-tabs").tabs();
80 80
                 jQuery("#geodispersion-tabs").css("visibility", "visible");
81 81
                 
@@ -96,133 +96,133 @@  discard block
 block discarded – undo
96 96
 					"json"
97 97
 				);
98 98
             ');
99
-        }
99
+		}
100 100
         
101
-        ViewFactory::make('GeoAnalysis', $this, $controller, $data)->render();
102
-    }
101
+		ViewFactory::make('GeoAnalysis', $this, $controller, $data)->render();
102
+	}
103 103
     
104
-    /**
105
-     * GeoAnalysis@listAll
106
-     */
107
-    public function listAll() {
104
+	/**
105
+	 * GeoAnalysis@listAll
106
+	 */
107
+	public function listAll() {
108 108
         
109
-        $controller = new PageController();
110
-        $controller->setPageTitle(I18N::translate('Sosa Geographical dispersion'));
109
+		$controller = new PageController();
110
+		$controller->setPageTitle(I18N::translate('Sosa Geographical dispersion'));
111 111
         
112
-        $data = new ViewBag();
113
-        $data->set('title', $controller->getPageTitle());
114
-        $data->set('has_list', false);
112
+		$data = new ViewBag();
113
+		$data->set('title', $controller->getPageTitle());
114
+		$data->set('has_list', false);
115 115
         
116
-        $ga_list = $this->provider->getGeoAnalysisList();
117
-        if(count($ga_list) > 0 ) {
118
-             $data->set('has_list', true);
119
-             $data->set('geoanalysislist', $ga_list);
120
-        }
116
+		$ga_list = $this->provider->getGeoAnalysisList();
117
+		if(count($ga_list) > 0 ) {
118
+			 $data->set('has_list', true);
119
+			 $data->set('geoanalysislist', $ga_list);
120
+		}
121 121
         
122
-        ViewFactory::make('GeoAnalysisList', $this, $controller, $data)->render();        
123
-    }
122
+		ViewFactory::make('GeoAnalysisList', $this, $controller, $data)->render();        
123
+	}
124 124
     	
125 125
 	/**
126 126
 	 * GeoAnalysis@setStatus
127 127
 	 */
128
-    public function setStatus() {  
129
-        global $WT_TREE;
128
+	public function setStatus() {  
129
+		global $WT_TREE;
130 130
         
131
-        $controller = new JsonController();
131
+		$controller = new JsonController();
132 132
         
133
-        $ga_id = Filter::getInteger('ga_id');
134
-        $ga = $this->provider->getGeoAnalysis($ga_id, false);
133
+		$ga_id = Filter::getInteger('ga_id');
134
+		$ga = $this->provider->getGeoAnalysis($ga_id, false);
135 135
         
136
-        $controller->restrictAccess(
137
-            true // Filter::checkCsrf()   -- Cannot use CSRF on a GET request (modules can only work with GET requests)
138
-            &&  Auth::isManager($WT_TREE) 
139
-            && $ga !== null
140
-        );
136
+		$controller->restrictAccess(
137
+			true // Filter::checkCsrf()   -- Cannot use CSRF on a GET request (modules can only work with GET requests)
138
+			&&  Auth::isManager($WT_TREE) 
139
+			&& $ga !== null
140
+		);
141 141
         
142
-        $status = Filter::getBool('status');
143
-        $res = array('geoanalysis' => $ga->getId() , 'error' => null);
144
-        try{
145
-            $this->provider->setGeoAnalysisStatus($ga, $status);
146
-            $res['status'] = $status;
142
+		$status = Filter::getBool('status');
143
+		$res = array('geoanalysis' => $ga->getId() , 'error' => null);
144
+		try{
145
+			$this->provider->setGeoAnalysisStatus($ga, $status);
146
+			$res['status'] = $status;
147 147
 			Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been '. ($status ? 'enabled' : 'disabled') .'.');
148
-        }
149
-        catch (\Exception $ex) {
150
-            $res['error'] = $ex->getMessage();
148
+		}
149
+		catch (\Exception $ex) {
150
+			$res['error'] = $ex->getMessage();
151 151
 			Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage());
152
-        }
152
+		}
153 153
         
154
-        $controller->pageHeader();
155
-        if($res['error']) http_response_code(500);
154
+		$controller->pageHeader();
155
+		if($res['error']) http_response_code(500);
156 156
         
157
-        $controller->encode($res);
158
-    }
157
+		$controller->encode($res);
158
+	}
159 159
     
160 160
 	/**
161
-     * GeoAnalysis@delete
162
-     */
163
-    public function delete() {
164
-        global $WT_TREE;
161
+	 * GeoAnalysis@delete
162
+	 */
163
+	public function delete() {
164
+		global $WT_TREE;
165 165
     
166
-        $controller = new JsonController();
166
+		$controller = new JsonController();
167 167
     
168
-        $ga_id = Filter::getInteger('ga_id');
169
-        $ga = $this->provider->getGeoAnalysis($ga_id, false);
168
+		$ga_id = Filter::getInteger('ga_id');
169
+		$ga = $this->provider->getGeoAnalysis($ga_id, false);
170 170
     
171
-        $controller->restrictAccess(
172
-            true // Filter::checkCsrf()   -- Cannot use CSRF on a GET request (modules can only work with GET requests)
173
-            &&  Auth::isManager($WT_TREE)
174
-            && $ga
175
-            );
171
+		$controller->restrictAccess(
172
+			true // Filter::checkCsrf()   -- Cannot use CSRF on a GET request (modules can only work with GET requests)
173
+			&&  Auth::isManager($WT_TREE)
174
+			&& $ga
175
+			);
176 176
             
177
-        $res = array('geoanalysis' => $ga->getId() , 'error' => null);
178
-        try{
179
-            $this->provider->deleteGeoAnalysis($ga);
177
+		$res = array('geoanalysis' => $ga->getId() , 'error' => null);
178
+		try{
179
+			$this->provider->deleteGeoAnalysis($ga);
180 180
 			Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been deleted.');
181
-        }
182
-        catch (\Exception $ex) {
183
-            $res['error'] = $ex->getMessage();
181
+		}
182
+		catch (\Exception $ex) {
183
+			$res['error'] = $ex->getMessage();
184 184
 			Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be deleted. Error: '. $ex->getMessage());
185
-        }
185
+		}
186 186
     
187
-        $controller->pageHeader();
188
-        if($res['error']) http_response_code(500);
187
+		$controller->pageHeader();
188
+		if($res['error']) http_response_code(500);
189 189
 
190
-        $controller->encode($res);
191
-    }
190
+		$controller->encode($res);
191
+	}
192 192
         	
193
-    /**
194
-     * GeoAnalysis@dataTabs
195
-     */
196
-    public function dataTabs() {
197
-        global $WT_TREE;
193
+	/**
194
+	 * GeoAnalysis@dataTabs
195
+	 */
196
+	public function dataTabs() {
197
+		global $WT_TREE;
198 198
         
199
-        $controller = new JsonController();
199
+		$controller = new JsonController();
200 200
         
201
-        $ga_id = Filter::getInteger('ga_id');
202
-        $ga = $this->provider->getGeoAnalysis($ga_id);
203
-        $sosa_provider = new SosaProvider($WT_TREE, Auth::user());
201
+		$ga_id = Filter::getInteger('ga_id');
202
+		$ga = $this->provider->getGeoAnalysis($ga_id);
203
+		$sosa_provider = new SosaProvider($WT_TREE, Auth::user());
204 204
         
205
-        $controller
206
-            ->restrictAccess($ga && $sosa_provider->isSetup())
207
-            ->pageHeader();
205
+		$controller
206
+			->restrictAccess($ga && $sosa_provider->isSetup())
207
+			->pageHeader();
208 208
         
209
-        $jsonArray = array();
209
+		$jsonArray = array();
210 210
         
211
-        list($placesDispGeneral, $placesDispGenerations) = $ga->getAnalysisResults($sosa_provider->getAllSosaWithGenerations());
211
+		list($placesDispGeneral, $placesDispGenerations) = $ga->getAnalysisResults($sosa_provider->getAllSosaWithGenerations());
212 212
         
213
-        $flags = array();
214
-        if($placesDispGeneral && $ga->getOptions() && $ga->getOptions()->isUsingFlags()) {
215
-            $mapProvider = new GoogleMapsProvider();            
216
-            foreach($placesDispGeneral['places'] as $place => $count) {
217
-                $flags[$place] = $mapProvider->getPlaceIcon(new Place($place, $WT_TREE));
218
-            }
219
-        }
213
+		$flags = array();
214
+		if($placesDispGeneral && $ga->getOptions() && $ga->getOptions()->isUsingFlags()) {
215
+			$mapProvider = new GoogleMapsProvider();            
216
+			foreach($placesDispGeneral['places'] as $place => $count) {
217
+				$flags[$place] = $mapProvider->getPlaceIcon(new Place($place, $WT_TREE));
218
+			}
219
+		}
220 220
         
221
-        $jsonArray['generaltab'] = $this->htmlPlacesAnalysisGeneralTab($ga, $placesDispGeneral, $flags);
222
-        $jsonArray['generationstab'] = $this->htmlPlacesAnalysisGenerationsTab($ga, $placesDispGenerations, $flags);
221
+		$jsonArray['generaltab'] = $this->htmlPlacesAnalysisGeneralTab($ga, $placesDispGeneral, $flags);
222
+		$jsonArray['generationstab'] = $this->htmlPlacesAnalysisGenerationsTab($ga, $placesDispGenerations, $flags);
223 223
 
224
-        $controller->encode($jsonArray);
225
-    }
224
+		$controller->encode($jsonArray);
225
+	}
226 226
     
227 227
 	/**
228 228
 	 * Returns HTML code for the GeoAnalysis general tab (can be either a map or a table).
@@ -232,70 +232,70 @@  discard block
 block discarded – undo
232 232
 	 * @param (null|array) $flags Array of flags
233 233
 	 * @return string HTML code for the general tab
234 234
 	 */
235
-    protected function htmlPlacesAnalysisGeneralTab(GeoAnalysis $ga, $placesGeneralResults, $flags= null) {
236
-        global $WT_TREE;
235
+	protected function htmlPlacesAnalysisGeneralTab(GeoAnalysis $ga, $placesGeneralResults, $flags= null) {
236
+		global $WT_TREE;
237 237
         
238
-        if(!empty($placesGeneralResults)){
239
-            $data = new ViewBag();
238
+		if(!empty($placesGeneralResults)){
239
+			$data = new ViewBag();
240 240
             
241
-            $nb_found = $placesGeneralResults['knownsum'];
242
-            $nb_other = 0;
243
-            if(isset($placesGeneralResults['other'])) $nb_other =$placesGeneralResults['other'];
244
-            $nb_unknown = $placesGeneralResults['unknown'];
241
+			$nb_found = $placesGeneralResults['knownsum'];
242
+			$nb_other = 0;
243
+			if(isset($placesGeneralResults['other'])) $nb_other =$placesGeneralResults['other'];
244
+			$nb_unknown = $placesGeneralResults['unknown'];
245 245
             
246
-            $data->set('stats_gen_nb_found', $nb_found);
247
-            $data->set('stats_gen_nb_other', $nb_other);
248
-            $data->set('stats_gen_nb_unknown', $nb_unknown);
246
+			$data->set('stats_gen_nb_found', $nb_found);
247
+			$data->set('stats_gen_nb_other', $nb_other);
248
+			$data->set('stats_gen_nb_unknown', $nb_unknown);
249 249
             
250
-            $data->set('use_flags', $ga->getOptions() && $ga->getOptions()->isUsingFlags());
250
+			$data->set('use_flags', $ga->getOptions() && $ga->getOptions()->isUsingFlags());
251 251
             
252
-            if($ga->hasMap()) {
253
-                $max = $placesGeneralResults['max'];
254
-                $map = $ga->getOptions()->getMap();
255
-                $results_by_subdivs = $map->getSubdivisions();
256
-                $places_mappings = $map->getPlacesMappings();
257
-                foreach ($placesGeneralResults['places'] as $location => $count) {
258
-                    $levelvalues = array_reverse(array_map('trim',explode(',', $location)));
259
-                    $level_map = $ga->getAnalysisLevel() - $ga->getOptions()->getMapLevel();
260
-                    if($level_map >= 0 && $level_map < count($levelvalues)) {
261
-                        $levelref = $levelvalues[0] . '@' . $levelvalues[$level_map];
262
-                        if(!isset($results_by_subdivs[$levelref])) { $levelref = $levelvalues[0]; }
263
-                    }
264
-                    else {
265
-                        $levelref = $levelvalues[0];
266
-                    }
267
-                    if(isset($places_mappings[$levelref])) $levelref = $places_mappings[$levelref];
268
-                    if(isset($results_by_subdivs[$levelref])) {
269
-                        $count_subd = isset($results_by_subdivs[$levelref]['count']) ? $results_by_subdivs[$levelref]['count'] : 0;
270
-                        $count_subd  += $count;
271
-                        $results_by_subdivs[$levelref]['count'] = $count_subd;   
272
-                        $results_by_subdivs[$levelref]['transparency'] = Functions::safeDivision($count_subd, $max);
273
-                        if($ga->getOptions()->isUsingFlags() && $flags) {
274
-                            $results_by_subdivs[$levelref]['place'] = new Place($location, $WT_TREE);
275
-                            $results_by_subdivs[$levelref]['flag'] = $flags[$location];
276
-                        }
277
-                    }
278
-                }             
252
+			if($ga->hasMap()) {
253
+				$max = $placesGeneralResults['max'];
254
+				$map = $ga->getOptions()->getMap();
255
+				$results_by_subdivs = $map->getSubdivisions();
256
+				$places_mappings = $map->getPlacesMappings();
257
+				foreach ($placesGeneralResults['places'] as $location => $count) {
258
+					$levelvalues = array_reverse(array_map('trim',explode(',', $location)));
259
+					$level_map = $ga->getAnalysisLevel() - $ga->getOptions()->getMapLevel();
260
+					if($level_map >= 0 && $level_map < count($levelvalues)) {
261
+						$levelref = $levelvalues[0] . '@' . $levelvalues[$level_map];
262
+						if(!isset($results_by_subdivs[$levelref])) { $levelref = $levelvalues[0]; }
263
+					}
264
+					else {
265
+						$levelref = $levelvalues[0];
266
+					}
267
+					if(isset($places_mappings[$levelref])) $levelref = $places_mappings[$levelref];
268
+					if(isset($results_by_subdivs[$levelref])) {
269
+						$count_subd = isset($results_by_subdivs[$levelref]['count']) ? $results_by_subdivs[$levelref]['count'] : 0;
270
+						$count_subd  += $count;
271
+						$results_by_subdivs[$levelref]['count'] = $count_subd;   
272
+						$results_by_subdivs[$levelref]['transparency'] = Functions::safeDivision($count_subd, $max);
273
+						if($ga->getOptions()->isUsingFlags() && $flags) {
274
+							$results_by_subdivs[$levelref]['place'] = new Place($location, $WT_TREE);
275
+							$results_by_subdivs[$levelref]['flag'] = $flags[$location];
276
+						}
277
+					}
278
+				}             
279 279
                 
280
-                $data->set('map', $ga->getOptions()->getMap());
281
-                $data->set('results_by_subdivisions', $results_by_subdivs);
280
+				$data->set('map', $ga->getOptions()->getMap());
281
+				$data->set('results_by_subdivisions', $results_by_subdivs);
282 282
                 
283
-                $html = ViewFactory::make('GeoAnalysisTabGeneralMap', $this, new BaseController(), $data)->getHtmlPartial();
284
-            }
285
-            else {
286
-                $results = $placesGeneralResults['places'];
287
-                arsort($results);
288
-                $data->set('results', $results);
289
-                $data->set('analysis_level', $ga->getAnalysisLevel());
283
+				$html = ViewFactory::make('GeoAnalysisTabGeneralMap', $this, new BaseController(), $data)->getHtmlPartial();
284
+			}
285
+			else {
286
+				$results = $placesGeneralResults['places'];
287
+				arsort($results);
288
+				$data->set('results', $results);
289
+				$data->set('analysis_level', $ga->getAnalysisLevel());
290 290
                 
291
-                $html = ViewFactory::make('GeoAnalysisTabGeneralTable', $this, new BaseController(), $data)->getHtmlPartial();
292
-            }
293
-        }
294
-        else {
295
-            $html = '<p class="warning">' . I18N::translate('No data is available for the general analysis.') . '</p>';
296
-        }
297
-        return $html;
298
-    }
291
+				$html = ViewFactory::make('GeoAnalysisTabGeneralTable', $this, new BaseController(), $data)->getHtmlPartial();
292
+			}
293
+		}
294
+		else {
295
+			$html = '<p class="warning">' . I18N::translate('No data is available for the general analysis.') . '</p>';
296
+		}
297
+		return $html;
298
+	}
299 299
     
300 300
 	/**
301 301
 	 * Returns HTML code for the GeoAnalysis generations tab.
@@ -305,68 +305,68 @@  discard block
 block discarded – undo
305 305
 	 * @param (null|array) $flags Array of flags
306 306
 	 * @return string HTML code for the generations tab
307 307
 	 */
308
-    protected function htmlPlacesAnalysisGenerationsTab(GeoAnalysis $ga, $placesGenerationsResults, $flags = null) {
309
-        global $WT_TREE;
308
+	protected function htmlPlacesAnalysisGenerationsTab(GeoAnalysis $ga, $placesGenerationsResults, $flags = null) {
309
+		global $WT_TREE;
310 310
         
311
-        if(!empty($placesGenerationsResults) && $ga->getOptions()){
312
-            $data = new ViewBag();
311
+		if(!empty($placesGenerationsResults) && $ga->getOptions()){
312
+			$data = new ViewBag();
313 313
             
314
-            ksort($placesGenerationsResults);
314
+			ksort($placesGenerationsResults);
315 315
             
316
-            $detailslevel = $ga->getOptions()->getMaxDetailsInGen();
317
-            $data->set('max_details_gen', $detailslevel);    
318
-            $data->set('use_flags', $ga->getOptions()->isUsingFlags());
319
-            $data->set('analysis_level', $ga->getAnalysisLevel());
320
-            $display_all_places = !is_null($detailslevel) && $detailslevel == 0;
321
-            $data->set('display_all_places', $display_all_places);
316
+			$detailslevel = $ga->getOptions()->getMaxDetailsInGen();
317
+			$data->set('max_details_gen', $detailslevel);    
318
+			$data->set('use_flags', $ga->getOptions()->isUsingFlags());
319
+			$data->set('analysis_level', $ga->getAnalysisLevel());
320
+			$display_all_places = !is_null($detailslevel) && $detailslevel == 0;
321
+			$data->set('display_all_places', $display_all_places);
322 322
             
323
-            $results_by_gen = array();
324
-            foreach($placesGenerationsResults as $gen => $genData){
325
-                $sum = 0;
326
-                $other = 0;
327
-                $unknown = 0;
328
-                if(isset($genData['sum'])) $sum = $genData['sum'];
329
-                if(isset($genData['other'])) $other = $genData['other'];
330
-                if(isset($genData['unknown'])) $unknown = $genData['unknown'];
323
+			$results_by_gen = array();
324
+			foreach($placesGenerationsResults as $gen => $genData){
325
+				$sum = 0;
326
+				$other = 0;
327
+				$unknown = 0;
328
+				if(isset($genData['sum'])) $sum = $genData['sum'];
329
+				if(isset($genData['other'])) $other = $genData['other'];
330
+				if(isset($genData['unknown'])) $unknown = $genData['unknown'];
331 331
                 
332
-                if($sum > 0) {                
333
-                    $results_by_gen[$gen]['sum'] = $sum;
334
-                    $results_by_gen[$gen]['other'] = $other;
335
-                    $results_by_gen[$gen]['unknown'] = $unknown;
336
-                    $results_by_gen[$gen]['places'] = array();                    
337
-                    arsort($genData['places']);
332
+				if($sum > 0) {                
333
+					$results_by_gen[$gen]['sum'] = $sum;
334
+					$results_by_gen[$gen]['other'] = $other;
335
+					$results_by_gen[$gen]['unknown'] = $unknown;
336
+					$results_by_gen[$gen]['places'] = array();                    
337
+					arsort($genData['places']);
338 338
                     
339
-                    if($display_all_places){
340
-                        foreach($genData['places'] as $placename=> $count){
341
-                            $results_by_gen[$gen]['places'][$placename]['count'] = $count;
339
+					if($display_all_places){
340
+						foreach($genData['places'] as $placename=> $count){
341
+							$results_by_gen[$gen]['places'][$placename]['count'] = $count;
342 342
                             
343
-                            if($ga->getOptions() && $ga->getOptions()->isUsingFlags() && ($flag = $flags[$placename]) != ''){
344
-                                $results_by_gen[$gen]['places'][$placename]['place'] = new Place($placename, $WT_TREE);
345
-                                $results_by_gen[$gen]['places'][$placename]['flag'] = $flag;
346
-                            }
347
-                        }
348
-                    }
349
-                    else {
350
-                        $tmp = $genData['places'];
351
-                        if($other > 0) {
352
-                            $tmp = array_slice($tmp, 0, 5, true);
353
-                            $tmp['other'] = $other;
354
-                            arsort($tmp);  
355
-                        }                      
356
-                        $results_by_gen[$gen]['places'] = array_slice($tmp, 0, 5, true);                        
357
-                    }
358
-                }
359
-            }
343
+							if($ga->getOptions() && $ga->getOptions()->isUsingFlags() && ($flag = $flags[$placename]) != ''){
344
+								$results_by_gen[$gen]['places'][$placename]['place'] = new Place($placename, $WT_TREE);
345
+								$results_by_gen[$gen]['places'][$placename]['flag'] = $flag;
346
+							}
347
+						}
348
+					}
349
+					else {
350
+						$tmp = $genData['places'];
351
+						if($other > 0) {
352
+							$tmp = array_slice($tmp, 0, 5, true);
353
+							$tmp['other'] = $other;
354
+							arsort($tmp);  
355
+						}                      
356
+						$results_by_gen[$gen]['places'] = array_slice($tmp, 0, 5, true);                        
357
+					}
358
+				}
359
+			}
360 360
             
361
-            $data->set('results_by_generations', $results_by_gen);
361
+			$data->set('results_by_generations', $results_by_gen);
362 362
             
363
-            $html = ViewFactory::make('GeoAnalysisTabGenerations', $this, new BaseController(), $data)->getHtmlPartial();
363
+			$html = ViewFactory::make('GeoAnalysisTabGenerations', $this, new BaseController(), $data)->getHtmlPartial();
364 364
             
365
-        }
366
-        else {
367
-            $html = '<p class="warning">' . I18N::translate('No data is available for the generations analysis.') . '</p>';
368
-        }
369
-        return $html;
370
-    }
365
+		}
366
+		else {
367
+			$html = '<p class="warning">' . I18N::translate('No data is available for the generations analysis.') . '</p>';
368
+		}
369
+		return $html;
370
+	}
371 371
         
372 372
 }
373 373
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
         
70 70
         $ga_id = Filter::getInteger('ga_id');        
71 71
         
72
-        if($ga_id && $ga = $this->provider->getGeoAnalysis($ga_id)) {
72
+        if ($ga_id && $ga = $this->provider->getGeoAnalysis($ga_id)) {
73 73
             $data->set('has_analysis', true);
74 74
             $data->set('geoanalysis', $ga);
75 75
             
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                 jQuery.get(
83 83
 					"module.php",
84 84
 					{
85
-                        "mod" : "'. $this->module->getName() .'",  
85
+                        "mod" : "'. $this->module->getName().'",  
86 86
                         "mod_action": "GeoAnalysis@dataTabs",
87 87
                         "ga_id" : "'.$ga_id.'"
88 88
                     },
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
         $data->set('has_list', false);
115 115
         
116 116
         $ga_list = $this->provider->getGeoAnalysisList();
117
-        if(count($ga_list) > 0 ) {
117
+        if (count($ga_list) > 0) {
118 118
              $data->set('has_list', true);
119 119
              $data->set('geoanalysislist', $ga_list);
120 120
         }
@@ -140,19 +140,19 @@  discard block
 block discarded – undo
140 140
         );
141 141
         
142 142
         $status = Filter::getBool('status');
143
-        $res = array('geoanalysis' => $ga->getId() , 'error' => null);
144
-        try{
143
+        $res = array('geoanalysis' => $ga->getId(), 'error' => null);
144
+        try {
145 145
             $this->provider->setGeoAnalysisStatus($ga, $status);
146 146
             $res['status'] = $status;
147
-			Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been '. ($status ? 'enabled' : 'disabled') .'.');
147
+			Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been '.($status ? 'enabled' : 'disabled').'.');
148 148
         }
149 149
         catch (\Exception $ex) {
150 150
             $res['error'] = $ex->getMessage();
151
-			Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage());
151
+			Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be '.($status ? 'enabled' : 'disabled').'. Error: '.$ex->getMessage());
152 152
         }
153 153
         
154 154
         $controller->pageHeader();
155
-        if($res['error']) http_response_code(500);
155
+        if ($res['error']) http_response_code(500);
156 156
         
157 157
         $controller->encode($res);
158 158
     }
@@ -174,18 +174,18 @@  discard block
 block discarded – undo
174 174
             && $ga
175 175
             );
176 176
             
177
-        $res = array('geoanalysis' => $ga->getId() , 'error' => null);
178
-        try{
177
+        $res = array('geoanalysis' => $ga->getId(), 'error' => null);
178
+        try {
179 179
             $this->provider->deleteGeoAnalysis($ga);
180 180
 			Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been deleted.');
181 181
         }
182 182
         catch (\Exception $ex) {
183 183
             $res['error'] = $ex->getMessage();
184
-			Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be deleted. Error: '. $ex->getMessage());
184
+			Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be deleted. Error: '.$ex->getMessage());
185 185
         }
186 186
     
187 187
         $controller->pageHeader();
188
-        if($res['error']) http_response_code(500);
188
+        if ($res['error']) http_response_code(500);
189 189
 
190 190
         $controller->encode($res);
191 191
     }
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
         list($placesDispGeneral, $placesDispGenerations) = $ga->getAnalysisResults($sosa_provider->getAllSosaWithGenerations());
212 212
         
213 213
         $flags = array();
214
-        if($placesDispGeneral && $ga->getOptions() && $ga->getOptions()->isUsingFlags()) {
214
+        if ($placesDispGeneral && $ga->getOptions() && $ga->getOptions()->isUsingFlags()) {
215 215
             $mapProvider = new GoogleMapsProvider();            
216
-            foreach($placesDispGeneral['places'] as $place => $count) {
216
+            foreach ($placesDispGeneral['places'] as $place => $count) {
217 217
                 $flags[$place] = $mapProvider->getPlaceIcon(new Place($place, $WT_TREE));
218 218
             }
219 219
         }
@@ -232,15 +232,15 @@  discard block
 block discarded – undo
232 232
 	 * @param (null|array) $flags Array of flags
233 233
 	 * @return string HTML code for the general tab
234 234
 	 */
235
-    protected function htmlPlacesAnalysisGeneralTab(GeoAnalysis $ga, $placesGeneralResults, $flags= null) {
235
+    protected function htmlPlacesAnalysisGeneralTab(GeoAnalysis $ga, $placesGeneralResults, $flags = null) {
236 236
         global $WT_TREE;
237 237
         
238
-        if(!empty($placesGeneralResults)){
238
+        if (!empty($placesGeneralResults)) {
239 239
             $data = new ViewBag();
240 240
             
241 241
             $nb_found = $placesGeneralResults['knownsum'];
242 242
             $nb_other = 0;
243
-            if(isset($placesGeneralResults['other'])) $nb_other =$placesGeneralResults['other'];
243
+            if (isset($placesGeneralResults['other'])) $nb_other = $placesGeneralResults['other'];
244 244
             $nb_unknown = $placesGeneralResults['unknown'];
245 245
             
246 246
             $data->set('stats_gen_nb_found', $nb_found);
@@ -249,28 +249,28 @@  discard block
 block discarded – undo
249 249
             
250 250
             $data->set('use_flags', $ga->getOptions() && $ga->getOptions()->isUsingFlags());
251 251
             
252
-            if($ga->hasMap()) {
252
+            if ($ga->hasMap()) {
253 253
                 $max = $placesGeneralResults['max'];
254 254
                 $map = $ga->getOptions()->getMap();
255 255
                 $results_by_subdivs = $map->getSubdivisions();
256 256
                 $places_mappings = $map->getPlacesMappings();
257 257
                 foreach ($placesGeneralResults['places'] as $location => $count) {
258
-                    $levelvalues = array_reverse(array_map('trim',explode(',', $location)));
258
+                    $levelvalues = array_reverse(array_map('trim', explode(',', $location)));
259 259
                     $level_map = $ga->getAnalysisLevel() - $ga->getOptions()->getMapLevel();
260
-                    if($level_map >= 0 && $level_map < count($levelvalues)) {
261
-                        $levelref = $levelvalues[0] . '@' . $levelvalues[$level_map];
262
-                        if(!isset($results_by_subdivs[$levelref])) { $levelref = $levelvalues[0]; }
260
+                    if ($level_map >= 0 && $level_map < count($levelvalues)) {
261
+                        $levelref = $levelvalues[0].'@'.$levelvalues[$level_map];
262
+                        if (!isset($results_by_subdivs[$levelref])) { $levelref = $levelvalues[0]; }
263 263
                     }
264 264
                     else {
265 265
                         $levelref = $levelvalues[0];
266 266
                     }
267
-                    if(isset($places_mappings[$levelref])) $levelref = $places_mappings[$levelref];
268
-                    if(isset($results_by_subdivs[$levelref])) {
267
+                    if (isset($places_mappings[$levelref])) $levelref = $places_mappings[$levelref];
268
+                    if (isset($results_by_subdivs[$levelref])) {
269 269
                         $count_subd = isset($results_by_subdivs[$levelref]['count']) ? $results_by_subdivs[$levelref]['count'] : 0;
270
-                        $count_subd  += $count;
270
+                        $count_subd += $count;
271 271
                         $results_by_subdivs[$levelref]['count'] = $count_subd;   
272 272
                         $results_by_subdivs[$levelref]['transparency'] = Functions::safeDivision($count_subd, $max);
273
-                        if($ga->getOptions()->isUsingFlags() && $flags) {
273
+                        if ($ga->getOptions()->isUsingFlags() && $flags) {
274 274
                             $results_by_subdivs[$levelref]['place'] = new Place($location, $WT_TREE);
275 275
                             $results_by_subdivs[$levelref]['flag'] = $flags[$location];
276 276
                         }
@@ -292,7 +292,7 @@  discard block
 block discarded – undo
292 292
             }
293 293
         }
294 294
         else {
295
-            $html = '<p class="warning">' . I18N::translate('No data is available for the general analysis.') . '</p>';
295
+            $html = '<p class="warning">'.I18N::translate('No data is available for the general analysis.').'</p>';
296 296
         }
297 297
         return $html;
298 298
     }
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
     protected function htmlPlacesAnalysisGenerationsTab(GeoAnalysis $ga, $placesGenerationsResults, $flags = null) {
309 309
         global $WT_TREE;
310 310
         
311
-        if(!empty($placesGenerationsResults) && $ga->getOptions()){
311
+        if (!empty($placesGenerationsResults) && $ga->getOptions()) {
312 312
             $data = new ViewBag();
313 313
             
314 314
             ksort($placesGenerationsResults);
@@ -321,26 +321,26 @@  discard block
 block discarded – undo
321 321
             $data->set('display_all_places', $display_all_places);
322 322
             
323 323
             $results_by_gen = array();
324
-            foreach($placesGenerationsResults as $gen => $genData){
324
+            foreach ($placesGenerationsResults as $gen => $genData) {
325 325
                 $sum = 0;
326 326
                 $other = 0;
327 327
                 $unknown = 0;
328
-                if(isset($genData['sum'])) $sum = $genData['sum'];
329
-                if(isset($genData['other'])) $other = $genData['other'];
330
-                if(isset($genData['unknown'])) $unknown = $genData['unknown'];
328
+                if (isset($genData['sum'])) $sum = $genData['sum'];
329
+                if (isset($genData['other'])) $other = $genData['other'];
330
+                if (isset($genData['unknown'])) $unknown = $genData['unknown'];
331 331
                 
332
-                if($sum > 0) {                
332
+                if ($sum > 0) {                
333 333
                     $results_by_gen[$gen]['sum'] = $sum;
334 334
                     $results_by_gen[$gen]['other'] = $other;
335 335
                     $results_by_gen[$gen]['unknown'] = $unknown;
336 336
                     $results_by_gen[$gen]['places'] = array();                    
337 337
                     arsort($genData['places']);
338 338
                     
339
-                    if($display_all_places){
340
-                        foreach($genData['places'] as $placename=> $count){
339
+                    if ($display_all_places) {
340
+                        foreach ($genData['places'] as $placename=> $count) {
341 341
                             $results_by_gen[$gen]['places'][$placename]['count'] = $count;
342 342
                             
343
-                            if($ga->getOptions() && $ga->getOptions()->isUsingFlags() && ($flag = $flags[$placename]) != ''){
343
+                            if ($ga->getOptions() && $ga->getOptions()->isUsingFlags() && ($flag = $flags[$placename]) != '') {
344 344
                                 $results_by_gen[$gen]['places'][$placename]['place'] = new Place($placename, $WT_TREE);
345 345
                                 $results_by_gen[$gen]['places'][$placename]['flag'] = $flag;
346 346
                             }
@@ -348,7 +348,7 @@  discard block
 block discarded – undo
348 348
                     }
349 349
                     else {
350 350
                         $tmp = $genData['places'];
351
-                        if($other > 0) {
351
+                        if ($other > 0) {
352 352
                             $tmp = array_slice($tmp, 0, 5, true);
353 353
                             $tmp['other'] = $other;
354 354
                             arsort($tmp);  
@@ -364,7 +364,7 @@  discard block
 block discarded – undo
364 364
             
365 365
         }
366 366
         else {
367
-            $html = '<p class="warning">' . I18N::translate('No data is available for the generations analysis.') . '</p>';
367
+            $html = '<p class="warning">'.I18N::translate('No data is available for the generations analysis.').'</p>';
368 368
         }
369 369
         return $html;
370 370
     }
Please login to merge, or discard this patch.
Braces   +28 added lines, -21 removed lines patch added patch discarded remove patch
@@ -145,14 +145,15 @@  discard block
 block discarded – undo
145 145
             $this->provider->setGeoAnalysisStatus($ga, $status);
146 146
             $res['status'] = $status;
147 147
 			Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been '. ($status ? 'enabled' : 'disabled') .'.');
148
-        }
149
-        catch (\Exception $ex) {
148
+        } catch (\Exception $ex) {
150 149
             $res['error'] = $ex->getMessage();
151 150
 			Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage());
152 151
         }
153 152
         
154 153
         $controller->pageHeader();
155
-        if($res['error']) http_response_code(500);
154
+        if($res['error']) {
155
+        	http_response_code(500);
156
+        }
156 157
         
157 158
         $controller->encode($res);
158 159
     }
@@ -178,14 +179,15 @@  discard block
 block discarded – undo
178 179
         try{
179 180
             $this->provider->deleteGeoAnalysis($ga);
180 181
 			Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been deleted.');
181
-        }
182
-        catch (\Exception $ex) {
182
+        } catch (\Exception $ex) {
183 183
             $res['error'] = $ex->getMessage();
184 184
 			Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be deleted. Error: '. $ex->getMessage());
185 185
         }
186 186
     
187 187
         $controller->pageHeader();
188
-        if($res['error']) http_response_code(500);
188
+        if($res['error']) {
189
+        	http_response_code(500);
190
+        }
189 191
 
190 192
         $controller->encode($res);
191 193
     }
@@ -240,7 +242,9 @@  discard block
 block discarded – undo
240 242
             
241 243
             $nb_found = $placesGeneralResults['knownsum'];
242 244
             $nb_other = 0;
243
-            if(isset($placesGeneralResults['other'])) $nb_other =$placesGeneralResults['other'];
245
+            if(isset($placesGeneralResults['other'])) {
246
+            	$nb_other =$placesGeneralResults['other'];
247
+            }
244 248
             $nb_unknown = $placesGeneralResults['unknown'];
245 249
             
246 250
             $data->set('stats_gen_nb_found', $nb_found);
@@ -260,11 +264,12 @@  discard block
 block discarded – undo
260 264
                     if($level_map >= 0 && $level_map < count($levelvalues)) {
261 265
                         $levelref = $levelvalues[0] . '@' . $levelvalues[$level_map];
262 266
                         if(!isset($results_by_subdivs[$levelref])) { $levelref = $levelvalues[0]; }
263
-                    }
264
-                    else {
267
+                    } else {
265 268
                         $levelref = $levelvalues[0];
266 269
                     }
267
-                    if(isset($places_mappings[$levelref])) $levelref = $places_mappings[$levelref];
270
+                    if(isset($places_mappings[$levelref])) {
271
+                    	$levelref = $places_mappings[$levelref];
272
+                    }
268 273
                     if(isset($results_by_subdivs[$levelref])) {
269 274
                         $count_subd = isset($results_by_subdivs[$levelref]['count']) ? $results_by_subdivs[$levelref]['count'] : 0;
270 275
                         $count_subd  += $count;
@@ -281,8 +286,7 @@  discard block
 block discarded – undo
281 286
                 $data->set('results_by_subdivisions', $results_by_subdivs);
282 287
                 
283 288
                 $html = ViewFactory::make('GeoAnalysisTabGeneralMap', $this, new BaseController(), $data)->getHtmlPartial();
284
-            }
285
-            else {
289
+            } else {
286 290
                 $results = $placesGeneralResults['places'];
287 291
                 arsort($results);
288 292
                 $data->set('results', $results);
@@ -290,8 +294,7 @@  discard block
 block discarded – undo
290 294
                 
291 295
                 $html = ViewFactory::make('GeoAnalysisTabGeneralTable', $this, new BaseController(), $data)->getHtmlPartial();
292 296
             }
293
-        }
294
-        else {
297
+        } else {
295 298
             $html = '<p class="warning">' . I18N::translate('No data is available for the general analysis.') . '</p>';
296 299
         }
297 300
         return $html;
@@ -325,9 +328,15 @@  discard block
 block discarded – undo
325 328
                 $sum = 0;
326 329
                 $other = 0;
327 330
                 $unknown = 0;
328
-                if(isset($genData['sum'])) $sum = $genData['sum'];
329
-                if(isset($genData['other'])) $other = $genData['other'];
330
-                if(isset($genData['unknown'])) $unknown = $genData['unknown'];
331
+                if(isset($genData['sum'])) {
332
+                	$sum = $genData['sum'];
333
+                }
334
+                if(isset($genData['other'])) {
335
+                	$other = $genData['other'];
336
+                }
337
+                if(isset($genData['unknown'])) {
338
+                	$unknown = $genData['unknown'];
339
+                }
331 340
                 
332 341
                 if($sum > 0) {                
333 342
                     $results_by_gen[$gen]['sum'] = $sum;
@@ -345,8 +354,7 @@  discard block
 block discarded – undo
345 354
                                 $results_by_gen[$gen]['places'][$placename]['flag'] = $flag;
346 355
                             }
347 356
                         }
348
-                    }
349
-                    else {
357
+                    } else {
350 358
                         $tmp = $genData['places'];
351 359
                         if($other > 0) {
352 360
                             $tmp = array_slice($tmp, 0, 5, true);
@@ -362,8 +370,7 @@  discard block
 block discarded – undo
362 370
             
363 371
             $html = ViewFactory::make('GeoAnalysisTabGenerations', $this, new BaseController(), $data)->getHtmlPartial();
364 372
             
365
-        }
366
-        else {
373
+        } else {
367 374
             $html = '<p class="warning">' . I18N::translate('No data is available for the generations analysis.') . '</p>';
368 375
         }
369 376
         return $html;
Please login to merge, or discard this patch.
src/Webtrees/Module/AdminTasks/TaskController.php 3 patches
Indentation   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -34,25 +34,25 @@  discard block
 block discarded – undo
34 34
  */
35 35
 class TaskController extends MvcController
36 36
 {    
37
-    /**
38
-     * Tasks Provider
39
-     * @var TaskProviderInterface $provider
40
-     */
41
-    protected $provider;    
37
+	/**
38
+	 * Tasks Provider
39
+	 * @var TaskProviderInterface $provider
40
+	 */
41
+	protected $provider;    
42 42
     
43
-    /**
44
-     * Constructor for Admin Config controller
45
-     * @param AbstractModule $module
46
-     */
47
-    public function __construct(AbstractModule $module) {
48
-        parent::__construct($module);
43
+	/**
44
+	 * Constructor for Admin Config controller
45
+	 * @param AbstractModule $module
46
+	 */
47
+	public function __construct(AbstractModule $module) {
48
+		parent::__construct($module);
49 49
         
50
-        $this->provider = $this->module->getProvider();
51
-    }    
50
+		$this->provider = $this->module->getProvider();
51
+	}    
52 52
     
53
-    /**
54
-     * Pages
55
-     */        
53
+	/**
54
+	 * Pages
55
+	 */        
56 56
 	
57 57
 	/**
58 58
 	 * Task@trigger
@@ -76,35 +76,35 @@  discard block
 block discarded – undo
76 76
 	/**
77 77
 	 * Task@setStatus
78 78
 	 */
79
-    public function setStatus() {          
80
-        $controller = new JsonController();
79
+	public function setStatus() {          
80
+		$controller = new JsonController();
81 81
         
82
-        $task_name = Filter::get('task');
83
-        $task = $this->provider->getTask($task_name, false);
82
+		$task_name = Filter::get('task');
83
+		$task = $this->provider->getTask($task_name, false);
84 84
         
85
-        $controller->restrictAccess(
86
-            true // Filter::checkCsrf()   -- Cannot use CSRF on a GET request (modules can only work with GET requests)
87
-            &&  Auth::isAdmin() 
88
-            && $task
89
-        );
85
+		$controller->restrictAccess(
86
+			true // Filter::checkCsrf()   -- Cannot use CSRF on a GET request (modules can only work with GET requests)
87
+			&&  Auth::isAdmin() 
88
+			&& $task
89
+		);
90 90
         
91
-        $status = Filter::getBool('status');
92
-        $res = array('task' => $task->getName() , 'error' => null);
93
-        try{
94
-            $this->provider->setTaskStatus($task, $status);
95
-            $res['status'] = $status;
91
+		$status = Filter::getBool('status');
92
+		$res = array('task' => $task->getName() , 'error' => null);
93
+		try{
94
+			$this->provider->setTaskStatus($task, $status);
95
+			$res['status'] = $status;
96 96
 			Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '. ($status ? 'enabled' : 'disabled') .'.');
97
-        }
98
-        catch (\Exception $ex) {
99
-            $res['error'] = $ex->getMessage();
97
+		}
98
+		catch (\Exception $ex) {
99
+			$res['error'] = $ex->getMessage();
100 100
 			Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage());
101
-        }
101
+		}
102 102
         
103
-        $controller->pageHeader();
104
-        if($res['error']) http_response_code(500);
103
+		$controller->pageHeader();
104
+		if($res['error']) http_response_code(500);
105 105
         
106
-        $controller->encode($res);
107
-    }
106
+		$controller->encode($res);
107
+	}
108 108
 	
109 109
 	/**
110 110
 	 * Task@edit
@@ -112,15 +112,15 @@  discard block
 block discarded – undo
112 112
 	public function edit() {
113 113
 		global $WT_TREE;
114 114
         		
115
-        $task_name = Filter::get('task');
116
-        $task = $this->provider->getTask($task_name, false);
115
+		$task_name = Filter::get('task');
116
+		$task = $this->provider->getTask($task_name, false);
117 117
 		
118
-        Theme::theme(new AdministrationTheme)->init($WT_TREE);
119
-        $controller = new PageController();        
120
-        $controller
121
-            ->restrictAccess(Auth::isAdmin() && $task)
118
+		Theme::theme(new AdministrationTheme)->init($WT_TREE);
119
+		$controller = new PageController();        
120
+		$controller
121
+			->restrictAccess(Auth::isAdmin() && $task)
122 122
 			->setPageTitle(I18N::translate('Edit the administrative task'))
123
-            ->addInlineJavascript('
123
+			->addInlineJavascript('
124 124
                 function toggleRemainingOccurrences() {
125 125
                     if($("input:radio[name=\'is_limited\']:checked").val() == 1) {
126 126
                         $("#nb_occurences").show();
@@ -133,39 +133,39 @@  discard block
 block discarded – undo
133 133
                 $("[name=\'is_limited\']").on("change", toggleRemainingOccurrences);
134 134
                 toggleRemainingOccurrences();
135 135
             ')
136
-        ;
136
+		;
137 137
         
138 138
         
139
-        $data = new ViewBag();        
140
-        $data->set('title', $controller->getPageTitle());
139
+		$data = new ViewBag();        
140
+		$data->set('title', $controller->getPageTitle());
141 141
 		$data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $WT_TREE->getNameUrl());
142
-        $data->set('module_title', $this->module->getTitle());
142
+		$data->set('module_title', $this->module->getTitle());
143 143
 		$data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@save&ged=' . $WT_TREE->getNameUrl());
144 144
 		$data->set('task', $task);
145 145
 		    
146
-        ViewFactory::make('TaskEdit', $this, $controller, $data)->render();	
146
+		ViewFactory::make('TaskEdit', $this, $controller, $data)->render();	
147 147
 	}	
148 148
 	
149 149
 	/**
150 150
 	 * Task@save
151 151
 	 */
152 152
 	public function save() {		
153
-        $tmp_contrl = new PageController();
153
+		$tmp_contrl = new PageController();
154 154
 				
155
-        $tmp_contrl->restrictAccess(
156
-            Auth::isAdmin() 
157
-            && Filter::checkCsrf()
158
-         );
155
+		$tmp_contrl->restrictAccess(
156
+			Auth::isAdmin() 
157
+			&& Filter::checkCsrf()
158
+		 );
159 159
         
160 160
 		$task_name      = Filter::post('task');
161
-        $frequency    	= Filter::postInteger('frequency');
162
-        $is_limited  	= Filter::postInteger('is_limited', 0, 1);
163
-        $nb_occur       = Filter::postInteger('nb_occur');
161
+		$frequency    	= Filter::postInteger('frequency');
162
+		$is_limited  	= Filter::postInteger('is_limited', 0, 1);
163
+		$nb_occur       = Filter::postInteger('nb_occur');
164 164
 				
165 165
 		$task = $this->provider->getTask($task_name, false);
166 166
         
167
-        $success = false; 
168
-        if($task) {
167
+		$success = false; 
168
+		if($task) {
169 169
 			$task->setFrequency($frequency);
170 170
 			if($is_limited == 1) {
171 171
 				$task->setRemainingOccurrences($nb_occur);
@@ -197,13 +197,13 @@  discard block
 block discarded – undo
197 197
 				Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.');
198 198
 			}
199 199
 			
200
-        }
200
+		}
201 201
         
202
-        $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig';
203
-        if(!$success) {
202
+		$redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig';
203
+		if(!$success) {
204 204
 			$redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@edit&task='. $task->getName();
205
-        }        
206
-        header('Location: ' . WT_BASE_URL . $redirection_url);
205
+		}        
206
+		header('Location: ' . WT_BASE_URL . $redirection_url);
207 207
 	}
208 208
      
209 209
 }
210 210
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 		
69 69
 		$tasks = $this->provider->getTasksToRun($token == $token_submitted, $task_name);
70 70
 		
71
-		foreach($tasks as $task) {
71
+		foreach ($tasks as $task) {
72 72
 			$task->execute();		
73 73
 		}
74 74
 	}	
@@ -89,19 +89,19 @@  discard block
 block discarded – undo
89 89
         );
90 90
         
91 91
         $status = Filter::getBool('status');
92
-        $res = array('task' => $task->getName() , 'error' => null);
93
-        try{
92
+        $res = array('task' => $task->getName(), 'error' => null);
93
+        try {
94 94
             $this->provider->setTaskStatus($task, $status);
95 95
             $res['status'] = $status;
96
-			Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '. ($status ? 'enabled' : 'disabled') .'.');
96
+			Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '.($status ? 'enabled' : 'disabled').'.');
97 97
         }
98 98
         catch (\Exception $ex) {
99 99
             $res['error'] = $ex->getMessage();
100
-			Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage());
100
+			Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be '.($status ? 'enabled' : 'disabled').'. Error: '.$ex->getMessage());
101 101
         }
102 102
         
103 103
         $controller->pageHeader();
104
-        if($res['error']) http_response_code(500);
104
+        if ($res['error']) http_response_code(500);
105 105
         
106 106
         $controller->encode($res);
107 107
     }
@@ -138,9 +138,9 @@  discard block
 block discarded – undo
138 138
         
139 139
         $data = new ViewBag();        
140 140
         $data->set('title', $controller->getPageTitle());
141
-		$data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $WT_TREE->getNameUrl());
141
+		$data->set('admin_config_url', 'module.php?mod='.$this->module->getName().'&mod_action=AdminConfig&ged='.$WT_TREE->getNameUrl());
142 142
         $data->set('module_title', $this->module->getTitle());
143
-		$data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@save&ged=' . $WT_TREE->getNameUrl());
143
+		$data->set('save_url', 'module.php?mod='.$this->module->getName().'&mod_action=Task@save&ged='.$WT_TREE->getNameUrl());
144 144
 		$data->set('task', $task);
145 145
 		    
146 146
         ViewFactory::make('TaskEdit', $this, $controller, $data)->render();	
@@ -157,17 +157,17 @@  discard block
 block discarded – undo
157 157
             && Filter::checkCsrf()
158 158
          );
159 159
         
160
-		$task_name      = Filter::post('task');
161
-        $frequency    	= Filter::postInteger('frequency');
162
-        $is_limited  	= Filter::postInteger('is_limited', 0, 1);
163
-        $nb_occur       = Filter::postInteger('nb_occur');
160
+		$task_name = Filter::post('task');
161
+        $frequency = Filter::postInteger('frequency');
162
+        $is_limited = Filter::postInteger('is_limited', 0, 1);
163
+        $nb_occur = Filter::postInteger('nb_occur');
164 164
 				
165 165
 		$task = $this->provider->getTask($task_name, false);
166 166
         
167 167
         $success = false; 
168
-        if($task) {
168
+        if ($task) {
169 169
 			$task->setFrequency($frequency);
170
-			if($is_limited == 1) {
170
+			if ($is_limited == 1) {
171 171
 				$task->setRemainingOccurrences($nb_occur);
172 172
 			}
173 173
 			else {
@@ -176,34 +176,34 @@  discard block
 block discarded – undo
176 176
 			
177 177
 			$res = $task->save();
178 178
 						
179
-			if($res) {						
180
-				if($task instanceof MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface) {
179
+			if ($res) {						
180
+				if ($task instanceof MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface) {
181 181
 					$res = $task->saveConfig();
182 182
 					
183
-					if(!$res) {
183
+					if (!$res) {
184 184
 						FlashMessages::addMessage(I18N::translate('An error occured while updating the specific settings of administrative task “%s”', $task->getTitle()), 'danger');
185
-						Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” specific settings could not be updated. See error log.');
185
+						Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName().'” specific settings could not be updated. See error log.');
186 186
 					}
187 187
 				}
188 188
 			
189
-				if($res) {
189
+				if ($res) {
190 190
 					FlashMessages::addMessage(I18N::translate('The administrative task “%s” has been successfully updated', $task->getTitle()), 'success');
191
-					Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName() .'” has been updated.');
191
+					Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName().'” has been updated.');
192 192
 					$success = true;
193 193
 				}
194 194
 			}
195 195
 			else {
196 196
 				FlashMessages::addMessage(I18N::translate('An error occured while updating the administrative task “%s”', $task->getTitle()), 'danger');
197
-				Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.');
197
+				Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName().'” could not be updated. See error log.');
198 198
 			}
199 199
 			
200 200
         }
201 201
         
202
-        $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig';
203
-        if(!$success) {
204
-			$redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@edit&task='. $task->getName();
202
+        $redirection_url = 'module.php?mod='.$this->module->getName().'&mod_action=AdminConfig';
203
+        if (!$success) {
204
+			$redirection_url = 'module.php?mod='.$this->module->getName().'&mod_action=Task@edit&task='.$task->getName();
205 205
         }        
206
-        header('Location: ' . WT_BASE_URL . $redirection_url);
206
+        header('Location: '.WT_BASE_URL.$redirection_url);
207 207
 	}
208 208
      
209 209
 }
210 210
\ No newline at end of file
Please login to merge, or discard this patch.
Braces   +6 added lines, -7 removed lines patch added patch discarded remove patch
@@ -94,14 +94,15 @@  discard block
 block discarded – undo
94 94
             $this->provider->setTaskStatus($task, $status);
95 95
             $res['status'] = $status;
96 96
 			Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '. ($status ? 'enabled' : 'disabled') .'.');
97
-        }
98
-        catch (\Exception $ex) {
97
+        } catch (\Exception $ex) {
99 98
             $res['error'] = $ex->getMessage();
100 99
 			Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage());
101 100
         }
102 101
         
103 102
         $controller->pageHeader();
104
-        if($res['error']) http_response_code(500);
103
+        if($res['error']) {
104
+        	http_response_code(500);
105
+        }
105 106
         
106 107
         $controller->encode($res);
107 108
     }
@@ -169,8 +170,7 @@  discard block
 block discarded – undo
169 170
 			$task->setFrequency($frequency);
170 171
 			if($is_limited == 1) {
171 172
 				$task->setRemainingOccurrences($nb_occur);
172
-			}
173
-			else {
173
+			} else {
174 174
 				$task->setRemainingOccurrences(0);
175 175
 			}
176 176
 			
@@ -191,8 +191,7 @@  discard block
 block discarded – undo
191 191
 					Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName() .'” has been updated.');
192 192
 					$success = true;
193 193
 				}
194
-			}
195
-			else {
194
+			} else {
196 195
 				FlashMessages::addMessage(I18N::translate('An error occured while updating the administrative task “%s”', $task->getTitle()), 'danger');
197 196
 				Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.');
198 197
 			}
Please login to merge, or discard this patch.
src/Webtrees/Module/WelcomeBlock/PiwikController.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,7 +50,9 @@
 block discarded – undo
50 50
         
51 51
             if($fetched = File::fetchUrl($url)) {
52 52
                 $content = @unserialize($fetched);
53
-                if(is_numeric($content)) return $content;
53
+                if(is_numeric($content)) {
54
+                	return $content;
55
+                }
54 56
             }
55 57
         }
56 58
     
Please login to merge, or discard this patch.
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -23,77 +23,77 @@
 block discarded – undo
23 23
  */
24 24
 class PiwikController extends MvcController
25 25
 {   
26
-    /**
27
-     * Retrieve the number of visitors from Piwik, for a given period.
28
-     * 
29
-     * @param string $block_id
30
-     * @param string $period
31
-     * @param (null|int) Number of visits
32
-     */
33
-    private function getNumberOfVisitsPiwik($block_id, $period='year'){
26
+	/**
27
+	 * Retrieve the number of visitors from Piwik, for a given period.
28
+	 * 
29
+	 * @param string $block_id
30
+	 * @param string $period
31
+	 * @param (null|int) Number of visits
32
+	 */
33
+	private function getNumberOfVisitsPiwik($block_id, $period='year'){
34 34
     
35
-        $piwik_url = $this->module->getBlockSetting($block_id, 'piwik_url');
36
-        $piwik_siteid = $this->module->getBlockSetting($block_id, 'piwik_siteid');
37
-        $piwik_token = $this->module->getBlockSetting($block_id, 'piwik_token');
35
+		$piwik_url = $this->module->getBlockSetting($block_id, 'piwik_url');
36
+		$piwik_siteid = $this->module->getBlockSetting($block_id, 'piwik_siteid');
37
+		$piwik_token = $this->module->getBlockSetting($block_id, 'piwik_token');
38 38
     
39
-        if($piwik_url && strlen($piwik_url) > 0 &&
40
-            $piwik_siteid  && strlen($piwik_siteid) > 0 &&
41
-            $piwik_token && strlen($piwik_token)            
42
-            ) 
43
-        {        
44
-            // calling Piwik REST API
45
-            $url = $piwik_url;
46
-            $url .= '?module=API&method=VisitsSummary.getVisits';
47
-            $url .= '&idSite='.$piwik_siteid.'&period='.$period.'&date=today';
48
-            $url .= '&format=PHP';
49
-            $url .= '&token_auth='.$piwik_token;
39
+		if($piwik_url && strlen($piwik_url) > 0 &&
40
+			$piwik_siteid  && strlen($piwik_siteid) > 0 &&
41
+			$piwik_token && strlen($piwik_token)            
42
+			) 
43
+		{        
44
+			// calling Piwik REST API
45
+			$url = $piwik_url;
46
+			$url .= '?module=API&method=VisitsSummary.getVisits';
47
+			$url .= '&idSite='.$piwik_siteid.'&period='.$period.'&date=today';
48
+			$url .= '&format=PHP';
49
+			$url .= '&token_auth='.$piwik_token;
50 50
         
51
-            if($fetched = File::fetchUrl($url)) {
52
-                $content = @unserialize($fetched);
53
-                if(is_numeric($content)) return $content;
54
-            }
55
-        }
51
+			if($fetched = File::fetchUrl($url)) {
52
+				$content = @unserialize($fetched);
53
+				if(is_numeric($content)) return $content;
54
+			}
55
+		}
56 56
     
57
-        return null;
58
-    }
57
+		return null;
58
+	}
59 59
     
60
-    /**
61
-     * Pages
62
-     */
60
+	/**
61
+	 * Pages
62
+	 */
63 63
         
64
-    /**
65
-     * Piwik@index
66
-     */
67
-    public function index() {  
64
+	/**
65
+	 * Piwik@index
66
+	 */
67
+	public function index() {  
68 68
         
69
-        $ctrl = new AjaxController();
69
+		$ctrl = new AjaxController();
70 70
         
71
-        $data = new ViewBag();
72
-        $data->set('has_stats', false);
71
+		$data = new ViewBag();
72
+		$data->set('has_stats', false);
73 73
         
74
-        $block_id = Filter::get('block_id');        
75
-        if($block_id){
76
-            $cached_item = Cache::get('piwikCountYear', $this->module);
77
-            $visitCountYear = $cached_item->get();
78
-            if(!$cached_item->isHit()) {
79
-                $visitCountYear = $this->getNumberOfVisitsPiwik($block_id);
80
-                if(!is_null($visitCountYear)) {
81
-                    $cached_item->expiresAt(new \DateTime('tomorrow'));  // Expires the next day at midnight
82
-                    Cache::save($cached_item, $visitCountYear);
83
-                }
84
-            }
74
+		$block_id = Filter::get('block_id');        
75
+		if($block_id){
76
+			$cached_item = Cache::get('piwikCountYear', $this->module);
77
+			$visitCountYear = $cached_item->get();
78
+			if(!$cached_item->isHit()) {
79
+				$visitCountYear = $this->getNumberOfVisitsPiwik($block_id);
80
+				if(!is_null($visitCountYear)) {
81
+					$cached_item->expiresAt(new \DateTime('tomorrow'));  // Expires the next day at midnight
82
+					Cache::save($cached_item, $visitCountYear);
83
+				}
84
+			}
85 85
             
86
-            if($visitCountYear){
87
-                $visitCountToday = max(0, $this->getNumberOfVisitsPiwik($block_id, 'day'));
88
-                $visitCountYear = max( 0, $visitCountYear);
86
+			if($visitCountYear){
87
+				$visitCountToday = max(0, $this->getNumberOfVisitsPiwik($block_id, 'day'));
88
+				$visitCountYear = max( 0, $visitCountYear);
89 89
                 
90
-                $data->set('has_stats', true);
91
-                $data->set('visits_today', $visitCountToday);
92
-                $data->set('visits_year', $visitCountYear + $visitCountToday);                
93
-            }
94
-        }
90
+				$data->set('has_stats', true);
91
+				$data->set('visits_today', $visitCountToday);
92
+				$data->set('visits_year', $visitCountYear + $visitCountToday);                
93
+			}
94
+		}
95 95
         
96
-        ViewFactory::make('PiwikStats', $this, $ctrl, $data)->render();        
97
-    }
96
+		ViewFactory::make('PiwikStats', $this, $ctrl, $data)->render();        
97
+	}
98 98
     
99 99
 }
100 100
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
      * @param string $period
31 31
      * @param (null|int) Number of visits
32 32
      */
33
-    private function getNumberOfVisitsPiwik($block_id, $period='year'){
33
+    private function getNumberOfVisitsPiwik($block_id, $period = 'year') {
34 34
     
35 35
         $piwik_url = $this->module->getBlockSetting($block_id, 'piwik_url');
36 36
         $piwik_siteid = $this->module->getBlockSetting($block_id, 'piwik_siteid');
37 37
         $piwik_token = $this->module->getBlockSetting($block_id, 'piwik_token');
38 38
     
39
-        if($piwik_url && strlen($piwik_url) > 0 &&
40
-            $piwik_siteid  && strlen($piwik_siteid) > 0 &&
39
+        if ($piwik_url && strlen($piwik_url) > 0 &&
40
+            $piwik_siteid && strlen($piwik_siteid) > 0 &&
41 41
             $piwik_token && strlen($piwik_token)            
42 42
             ) 
43 43
         {        
@@ -48,9 +48,9 @@  discard block
 block discarded – undo
48 48
             $url .= '&format=PHP';
49 49
             $url .= '&token_auth='.$piwik_token;
50 50
         
51
-            if($fetched = File::fetchUrl($url)) {
51
+            if ($fetched = File::fetchUrl($url)) {
52 52
                 $content = @unserialize($fetched);
53
-                if(is_numeric($content)) return $content;
53
+                if (is_numeric($content)) return $content;
54 54
             }
55 55
         }
56 56
     
@@ -72,20 +72,20 @@  discard block
 block discarded – undo
72 72
         $data->set('has_stats', false);
73 73
         
74 74
         $block_id = Filter::get('block_id');        
75
-        if($block_id){
75
+        if ($block_id) {
76 76
             $cached_item = Cache::get('piwikCountYear', $this->module);
77 77
             $visitCountYear = $cached_item->get();
78
-            if(!$cached_item->isHit()) {
78
+            if (!$cached_item->isHit()) {
79 79
                 $visitCountYear = $this->getNumberOfVisitsPiwik($block_id);
80
-                if(!is_null($visitCountYear)) {
81
-                    $cached_item->expiresAt(new \DateTime('tomorrow'));  // Expires the next day at midnight
80
+                if (!is_null($visitCountYear)) {
81
+                    $cached_item->expiresAt(new \DateTime('tomorrow')); // Expires the next day at midnight
82 82
                     Cache::save($cached_item, $visitCountYear);
83 83
                 }
84 84
             }
85 85
             
86
-            if($visitCountYear){
86
+            if ($visitCountYear) {
87 87
                 $visitCountToday = max(0, $this->getNumberOfVisitsPiwik($block_id, 'day'));
88
-                $visitCountYear = max( 0, $visitCountYear);
88
+                $visitCountYear = max(0, $visitCountYear);
89 89
                 
90 90
                 $data->set('has_stats', true);
91 91
                 $data->set('visits_today', $visitCountToday);
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Views/SosaListMissingView.php 4 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -10,7 +10,6 @@
 block discarded – undo
10 10
  */
11 11
 namespace MyArtJaub\Webtrees\Module\Sosa\Views;
12 12
 
13
-use Fisharebest\Webtrees\Date;
14 13
 use Fisharebest\Webtrees\Filter;
15 14
 use Fisharebest\Webtrees\Functions\Functions;
16 15
 use Fisharebest\Webtrees\GedcomTag;
Please login to merge, or discard this patch.
Braces   +4 added lines, -1 removed lines patch added patch discarded remove patch
@@ -184,7 +184,10 @@
 block discarded – undo
184 184
 							<td class="ui-state-default" colspan="11">
185 185
 								<div class="center">
186 186
 									<?= I18N::translate('Number of different missing ancestors: %s', I18N::number($this->data->get('missing_diff_count'))) ?>
187
-									<?php if($this->data->get('missing_hidden') > 0) echo ' ['. I18N::translate('%s hidden', I18N::number($this->data->get('missing_hidden'))).']'; ?>
187
+									<?php if($this->data->get('missing_hidden') > 0) {
188
+	echo ' ['. I18N::translate('%s hidden', I18N::number($this->data->get('missing_hidden'))).']';
189
+}
190
+?>
188 191
 									<?= ' - ' . I18N::translate('Generation complete at %s', I18N::percentage($this->data->get('perc_sosa'), 2)) ?>
189 192
 									<?= ' [' . I18N::translate('Potential %s', I18N::percentage($this->data->get('perc_sosa_potential'),2)).']' ?>
190 193
 								</div>
Please login to merge, or discard this patch.
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -30,16 +30,16 @@  discard block
 block discarded – undo
30 30
 	 * {@inhericDoc}
31 31
 	 * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent()
32 32
 	 */
33
-    protected function renderContent() {
34
-        ?>
33
+	protected function renderContent() {
34
+		?>
35 35
             <div id="maj-sosa-missing-page" class="center">
36 36
     			<h2><?= $this->data->get('title') ?></h2>
37 37
     			
38 38
     			<?php  if($this->data->get('is_setup')) { 
39
-    			    $this->renderSosaHeader();
40
-    			    if($this->data->get('has_missing', false)) {
41
-    			        $table_id = $this->data->get('table_id');
42
-    			        ?>
39
+					$this->renderSosaHeader();
40
+					if($this->data->get('has_missing', false)) {
41
+						$table_id = $this->data->get('table_id');
42
+						?>
43 43
     			<div id="sosa-indi-missing" class="smissing-list">
44 44
                 	<table id="<?= $table_id ?>">
45 45
         				<thead>     
@@ -103,52 +103,52 @@  discard block
 block discarded – undo
103 103
         			<tbody>
104 104
         			
105 105
         			<?php foreach($this->data->get('missing_list') as $missing_tab) {
106
-        			    $person = $missing_tab['indi'];
106
+						$person = $missing_tab['indi'];
107 107
         			    
108
-        			    /** @var \Fisharebest\Webtrees\Individual $person */
109
-        			    if ($person->isPendingAddtion()) {
110
-        			        $class = ' class="new"';
111
-        			    } elseif ($person->isPendingDeletion()) {
112
-        			        $class = ' class="old"';
113
-        			    } else {
114
-        			        $class = '';
115
-        			    }
116
-        			    $dperson = new \MyArtJaub\Webtrees\Individual($person);
117
-        			    list($surn_givn, $givn_surn) = FunctionsPrintLists::sortableNames($person);
118
-        			    ?>			
108
+						/** @var \Fisharebest\Webtrees\Individual $person */
109
+						if ($person->isPendingAddtion()) {
110
+							$class = ' class="new"';
111
+						} elseif ($person->isPendingDeletion()) {
112
+							$class = ' class="old"';
113
+						} else {
114
+							$class = '';
115
+						}
116
+						$dperson = new \MyArtJaub\Webtrees\Individual($person);
117
+						list($surn_givn, $givn_surn) = FunctionsPrintLists::sortableNames($person);
118
+						?>			
119 119
                 		<tr <?= $class ?>>
120 120
                 			<td class="transparent"><?= $missing_tab['sosa'] ?></td>
121 121
                 			<td class="transparent"><?= $person->getXref() ?></td>
122 122
                 			<td colspan="2" data-sort="<?= Filter::escapeHtml($givn_surn) ?>">
123 123
                 			<?php foreach ($person->getAllNames() as $num=>$name) {
124
-                				if ($name['type']=='NAME') {
125
-                					$title='';
126
-                				} else {
127
-                					$title='title="'.strip_tags(GedcomTag::getLabel($name['type'], $person)).'"';
128
-                				}
129
-                				if ($num==$person->getPrimaryName()) {
130
-                					$class=' class="name2"';
131
-                					$sex_image=$person->getSexImage();
132
-                				} else {
133
-                					$class='';
134
-                					$sex_image='';
135
-                				} ?>
124
+								if ($name['type']=='NAME') {
125
+									$title='';
126
+								} else {
127
+									$title='title="'.strip_tags(GedcomTag::getLabel($name['type'], $person)).'"';
128
+								}
129
+								if ($num==$person->getPrimaryName()) {
130
+									$class=' class="name2"';
131
+									$sex_image=$person->getSexImage();
132
+								} else {
133
+									$class='';
134
+									$sex_image='';
135
+								} ?>
136 136
                 				<a <?= $title.' '.$class ?> href="<?= $person->getHtmlUrl() ?>">
137 137
                 					<?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($name['full']) ?>
138 138
                 				</a>
139 139
                 				<?= $sex_image;
140
-                				echo implode('&nbsp;',
141
-                				    \MyArtJaub\Webtrees\Hook\HookProvider::getInstance()
142
-                				    ->get('hRecordNameAppend')
143
-                				    ->executeOnlyFor(array(Constants::MODULE_MAJ_SOSA_NAME),  $person, 'smaller'));  ?>
140
+								echo implode('&nbsp;',
141
+									\MyArtJaub\Webtrees\Hook\HookProvider::getInstance()
142
+									->get('hRecordNameAppend')
143
+									->executeOnlyFor(array(Constants::MODULE_MAJ_SOSA_NAME),  $person, 'smaller'));  ?>
144 144
                 				<br/>
145 145
                     		<?php }
146
-                    		echo $person->getPrimaryParentsNames('parents details1', 'none');
147
-                    		?>
146
+							echo $person->getPrimaryParentsNames('parents details1', 'none');
147
+							?>
148 148
                     		</td>
149 149
 							<td hidden data-sort="<?= Filter::escapeHtml($surn_givn) ?>"></td>             		
150 150
                 			<?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) {
151
-        				        $isISourced = $dperson->isSourced(); ?>
151
+								$isISourced = $dperson->isSourced(); ?>
152 152
         				   	<td data-sort="<?= $isISourced ?>"><?= FunctionsPrint::formatIsSourcedIcon('R', $isISourced, 'INDI', 1, 'medium') ?></td>
153 153
         					<?php } else { ?>
154 154
         					<td>&nbsp;</td>
@@ -158,23 +158,23 @@  discard block
 block discarded – undo
158 158
                     		<?php $birth_dates = $person->getAllBirthDates(); ?>
159 159
                     		<td data-sort="<?= $person->getEstimatedBirthDate()->julianDay() ?>">
160 160
                     		<?php                     		
161
-                    		foreach ($birth_dates as $n => $birth_date) {
162
-                    		    if ($n > 0) { ?> <br> <?php  } 
163
-                    		    echo $birth_date->display(true);
164
-                    		}
165
-                    		?>
161
+							foreach ($birth_dates as $n => $birth_date) {
162
+								if ($n > 0) { ?> <br> <?php  } 
163
+								echo $birth_date->display(true);
164
+							}
165
+							?>
166 166
                     		</td>
167 167
                 			<td>
168 168
                 			<?php foreach ($person->getAllBirthPlaces() as $n => $birth_place) {
169
-        				        $tmp = new \Fisharebest\Webtrees\Place($birth_place, $person->getTree());
170
-                				if ($n > 0) { ?><br><?php } ?>
169
+								$tmp = new \Fisharebest\Webtrees\Place($birth_place, $person->getTree());
170
+								if ($n > 0) { ?><br><?php } ?>
171 171
                 				<a href="'<?= $tmp->getURL(); ?>" title="<?= strip_tags($tmp->getFullName()) ?>">
172 172
                 					<?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($tmp->getShortName()) ?>
173 173
                 				</a>
174 174
                 			<?php } ?>
175 175
                 			</td>
176 176
         					<?php if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_ISSOURCED_NAME)) {
177
-        				        $isBSourced = $dperson->isBirthSourced(); ?>
177
+								$isBSourced = $dperson->isBirthSourced(); ?>
178 178
         				   	<td data-sort="<?= $isBSourced ?>"><?= FunctionsPrint::formatIsSourcedIcon('E', $isBSourced, 'BIRT', 1, 'medium') ?></td>
179 179
         					<?php } else { ?>
180 180
         					<td>&nbsp;</td>
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
     			 <?php } else if ($this->data->get('generation', 0) > 0) { ?> 
200 200
     			<p><?= I18N::translate('No ancestors are missing for this generation. Generation complete at %s.', I18N::percentage($this->data->get('perc_sosa'), 2)) ?></p>
201 201
     			    <?php }   			    
202
-    			} else { ?>
202
+				} else { ?>
203 203
     			<p class="warning"><?= I18N::translate('The list could not be displayed. Reasons might be:') ?><br/>
204 204
     				<ul>
205 205
     					<li><?= I18N::translate('No Sosa root individual has been defined.') ?></li>
@@ -210,6 +210,6 @@  discard block
 block discarded – undo
210 210
     			<?php } ?>
211 211
     		</div> 
212 212
     		<?php 
213
-        }
213
+		}
214 214
 }
215 215
  
216 216
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -35,9 +35,9 @@  discard block
 block discarded – undo
35 35
             <div id="maj-sosa-missing-page" class="center">
36 36
     			<h2><?= $this->data->get('title') ?></h2>
37 37
     			
38
-    			<?php  if($this->data->get('is_setup')) { 
38
+    			<?php  if ($this->data->get('is_setup')) { 
39 39
     			    $this->renderSosaHeader();
40
-    			    if($this->data->get('has_missing', false)) {
40
+    			    if ($this->data->get('has_missing', false)) {
41 41
     			        $table_id = $this->data->get('table_id');
42 42
     			        ?>
43 43
     			<div id="sosa-indi-missing" class="smissing-list">
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
         				</thead>
103 103
         			<tbody>
104 104
         			
105
-        			<?php foreach($this->data->get('missing_list') as $missing_tab) {
105
+        			<?php foreach ($this->data->get('missing_list') as $missing_tab) {
106 106
         			    $person = $missing_tab['indi'];
107 107
         			    
108 108
         			    /** @var \Fisharebest\Webtrees\Individual $person */
@@ -121,17 +121,17 @@  discard block
 block discarded – undo
121 121
                 			<td class="transparent"><?= $person->getXref() ?></td>
122 122
                 			<td colspan="2" data-sort="<?= Filter::escapeHtml($givn_surn) ?>">
123 123
                 			<?php foreach ($person->getAllNames() as $num=>$name) {
124
-                				if ($name['type']=='NAME') {
125
-                					$title='';
124
+                				if ($name['type'] == 'NAME') {
125
+                					$title = '';
126 126
                 				} else {
127
-                					$title='title="'.strip_tags(GedcomTag::getLabel($name['type'], $person)).'"';
127
+                					$title = 'title="'.strip_tags(GedcomTag::getLabel($name['type'], $person)).'"';
128 128
                 				}
129
-                				if ($num==$person->getPrimaryName()) {
130
-                					$class=' class="name2"';
131
-                					$sex_image=$person->getSexImage();
129
+                				if ($num == $person->getPrimaryName()) {
130
+                					$class = ' class="name2"';
131
+                					$sex_image = $person->getSexImage();
132 132
                 				} else {
133
-                					$class='';
134
-                					$sex_image='';
133
+                					$class = '';
134
+                					$sex_image = '';
135 135
                 				} ?>
136 136
                 				<a <?= $title.' '.$class ?> href="<?= $person->getHtmlUrl() ?>">
137 137
                 					<?= \Fisharebest\Webtrees\Functions\FunctionsPrint::highlightSearchHits($name['full']) ?>
@@ -140,7 +140,7 @@  discard block
 block discarded – undo
140 140
                 				echo implode('&nbsp;',
141 141
                 				    \MyArtJaub\Webtrees\Hook\HookProvider::getInstance()
142 142
                 				    ->get('hRecordNameAppend')
143
-                				    ->executeOnlyFor(array(Constants::MODULE_MAJ_SOSA_NAME),  $person, 'smaller'));  ?>
143
+                				    ->executeOnlyFor(array(Constants::MODULE_MAJ_SOSA_NAME), $person, 'smaller')); ?>
144 144
                 				<br/>
145 145
                     		<?php }
146 146
                     		echo $person->getPrimaryParentsNames('parents details1', 'none');
@@ -188,9 +188,9 @@  discard block
 block discarded – undo
188 188
 							<td class="ui-state-default" colspan="11">
189 189
 								<div class="center">
190 190
 									<?= I18N::translate('Number of different missing ancestors: %s', I18N::number($this->data->get('missing_diff_count'))) ?>
191
-									<?php if($this->data->get('missing_hidden') > 0) echo ' ['. I18N::translate('%s hidden', I18N::number($this->data->get('missing_hidden'))).']'; ?>
192
-									<?= ' - ' . I18N::translate('Generation complete at %s', I18N::percentage($this->data->get('perc_sosa'), 2)) ?>
193
-									<?= ' [' . I18N::translate('Potential %s', I18N::percentage($this->data->get('perc_sosa_potential'),2)).']' ?>
191
+									<?php if ($this->data->get('missing_hidden') > 0) echo ' ['.I18N::translate('%s hidden', I18N::number($this->data->get('missing_hidden'))).']'; ?>
192
+									<?= ' - '.I18N::translate('Generation complete at %s', I18N::percentage($this->data->get('perc_sosa'), 2)) ?>
193
+									<?= ' ['.I18N::translate('Potential %s', I18N::percentage($this->data->get('perc_sosa_potential'), 2)).']' ?>
194 194
 								</div>
195 195
 							</td>
196 196
 						</tr>
Please login to merge, or discard this patch.