Completed
Push — master ( 95506d...0f93c5 )
by Jonathan
07:55
created
src/Webtrees/Module/GeoDispersion/Model/GeoAnalysisProvider.php 4 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@
 block discarded – undo
89 89
     /**
90 90
      * Returns the number of geographical analysis (active and inactive). 
91 91
      * 
92
-     * @return int
92
+     * @return string
93 93
      */
94 94
     public function getGeoAnalysisCount() {
95 95
         return Database::prepare(
Please login to merge, or discard this patch.
Indentation   +329 added lines, -329 removed lines patch added patch discarded remove patch
@@ -21,130 +21,130 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class GeoAnalysisProvider {
23 23
     
24
-    /**
25
-     * Reference tree
26
-     * @var Tree $tree
27
-     */
28
-    protected $tree;
24
+	/**
25
+	 * Reference tree
26
+	 * @var Tree $tree
27
+	 */
28
+	protected $tree;
29 29
     
30
-    /**
31
-     * Cached hierarchy of places in the Gedcom file.
32
-     * 
33
-     * @var (array|null) $place_hierarchy
34
-     */
35
-    protected $place_hierarchy;
30
+	/**
31
+	 * Cached hierarchy of places in the Gedcom file.
32
+	 * 
33
+	 * @var (array|null) $place_hierarchy
34
+	 */
35
+	protected $place_hierarchy;
36 36
     
37
-    /**
38
-     * Constructor for GeoAnalysis Provider.
39
-     * A provider is defined in relation to a specific tree.
40
-     *
41
-     * @param Tree $tree
42
-     */
43
-    public function __construct(Tree $tree) {
44
-        $this->tree = $tree;
45
-        $this->place_hierarchy = null;
46
-    }
37
+	/**
38
+	 * Constructor for GeoAnalysis Provider.
39
+	 * A provider is defined in relation to a specific tree.
40
+	 *
41
+	 * @param Tree $tree
42
+	 */
43
+	public function __construct(Tree $tree) {
44
+		$this->tree = $tree;
45
+		$this->place_hierarchy = null;
46
+	}
47 47
     
48
-    /**
49
-     * Creates and returns a GeoAnalysis object from a data row.
50
-     * The row data is expected to be an array with the indexes:
51
-     *  - majgd_id: geodispersion analysis ID
52
-     *  - majgd_descr: geodispersion analysis description/title
53
-     *  - majgd_sublevel: Analysis level
54
-     *  - majgd_useflagsgen: Use flags in places display
55
-     *  - majgd_detailsgen: Number of top places
56
-     *  - majgd_map: file name of the map
57
-     *  - majgd_toplevel: parent level for the map
58
-     * 
59
-     * @param array $row
60
-     * @return GeoAnalysis
61
-     */
62
-    protected function loadGeoAnalysisFromRow($row) {
63
-        $options = new GeoDisplayOptions();
64
-        $options
65
-        ->setIsUsingFlags($row['majgd_useflagsgen'] == 'yes')
66
-        ->setMaxDetailsInGen($row['majgd_detailsgen']);
48
+	/**
49
+	 * Creates and returns a GeoAnalysis object from a data row.
50
+	 * The row data is expected to be an array with the indexes:
51
+	 *  - majgd_id: geodispersion analysis ID
52
+	 *  - majgd_descr: geodispersion analysis description/title
53
+	 *  - majgd_sublevel: Analysis level
54
+	 *  - majgd_useflagsgen: Use flags in places display
55
+	 *  - majgd_detailsgen: Number of top places
56
+	 *  - majgd_map: file name of the map
57
+	 *  - majgd_toplevel: parent level for the map
58
+	 * 
59
+	 * @param array $row
60
+	 * @return GeoAnalysis
61
+	 */
62
+	protected function loadGeoAnalysisFromRow($row) {
63
+		$options = new GeoDisplayOptions();
64
+		$options
65
+		->setIsUsingFlags($row['majgd_useflagsgen'] == 'yes')
66
+		->setMaxDetailsInGen($row['majgd_detailsgen']);
67 67
         
68
-        if($row['majgd_map']) {
69
-            $options
70
-            ->setMap(new OutlineMap($row['majgd_map']))
71
-            ->setMapLevel($row['majgd_toplevel']);
72
-        }
68
+		if($row['majgd_map']) {
69
+			$options
70
+			->setMap(new OutlineMap($row['majgd_map']))
71
+			->setMapLevel($row['majgd_toplevel']);
72
+		}
73 73
         
74
-        $enabled = true;
75
-        if(isset($row['majgd_status']) && $row['majgd_status'] == 'disabled') {
76
-            $enabled = false;
77
-        }
74
+		$enabled = true;
75
+		if(isset($row['majgd_status']) && $row['majgd_status'] == 'disabled') {
76
+			$enabled = false;
77
+		}
78 78
         
79
-        return new GeoAnalysis(
80
-            $this->tree,
81
-            $row['majgd_id'],
82
-            $row['majgd_descr'],
83
-            $row['majgd_sublevel'],
84
-            $options,
85
-            $enabled
86
-            );
87
-    }
79
+		return new GeoAnalysis(
80
+			$this->tree,
81
+			$row['majgd_id'],
82
+			$row['majgd_descr'],
83
+			$row['majgd_sublevel'],
84
+			$options,
85
+			$enabled
86
+			);
87
+	}
88 88
     
89
-    /**
90
-     * Returns the number of geographical analysis (active and inactive). 
91
-     * 
92
-     * @return int
93
-     */
94
-    public function getGeoAnalysisCount() {
95
-        return Database::prepare(
96
-            'SELECT COUNT(majgd_id)' .
97
-            ' FROM `##maj_geodispersion`' .
98
-            ' WHERE majgd_file = :gedcom_id'
99
-            )->execute(array(
100
-                'gedcom_id' => $this->tree->getTreeId()
101
-            ))->fetchOne();
102
-    }
89
+	/**
90
+	 * Returns the number of geographical analysis (active and inactive). 
91
+	 * 
92
+	 * @return int
93
+	 */
94
+	public function getGeoAnalysisCount() {
95
+		return Database::prepare(
96
+			'SELECT COUNT(majgd_id)' .
97
+			' FROM `##maj_geodispersion`' .
98
+			' WHERE majgd_file = :gedcom_id'
99
+			)->execute(array(
100
+				'gedcom_id' => $this->tree->getTreeId()
101
+			))->fetchOne();
102
+	}
103 103
     
104
-    /**
105
-     * Get a geographical analysis by its ID.
106
-     * The function can only search for only enabled analysis, or all.
107
-     * 
108
-     * @param int $id geodispersion analysis ID
109
-     * @param bool $only_enabled Search for only enabled geodispersion analysis
110
-     * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis|NULL
111
-     */
112
-    public function getGeoAnalysis($id, $only_enabled = true) {
113
-        $args = array (
114
-            'gedcom_id' => $this->tree->getTreeId(),
115
-            'ga_id' => $id
116
-        );
104
+	/**
105
+	 * Get a geographical analysis by its ID.
106
+	 * The function can only search for only enabled analysis, or all.
107
+	 * 
108
+	 * @param int $id geodispersion analysis ID
109
+	 * @param bool $only_enabled Search for only enabled geodispersion analysis
110
+	 * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis|NULL
111
+	 */
112
+	public function getGeoAnalysis($id, $only_enabled = true) {
113
+		$args = array (
114
+			'gedcom_id' => $this->tree->getTreeId(),
115
+			'ga_id' => $id
116
+		);
117 117
         
118
-        $sql = 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' .
119
-            ' FROM `##maj_geodispersion`' .
120
-            ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id';
121
-        if($only_enabled) {
122
-            $sql .= ' AND majgd_status = :status';
123
-            $args['status'] = 'enabled';
124
-        }
125
-        $sql .= ' ORDER BY majgd_descr';
118
+		$sql = 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' .
119
+			' FROM `##maj_geodispersion`' .
120
+			' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id';
121
+		if($only_enabled) {
122
+			$sql .= ' AND majgd_status = :status';
123
+			$args['status'] = 'enabled';
124
+		}
125
+		$sql .= ' ORDER BY majgd_descr';
126 126
         
127
-        $ga_array = Database::prepare($sql)->execute($args)->fetchOneRow(\PDO::FETCH_ASSOC);
127
+		$ga_array = Database::prepare($sql)->execute($args)->fetchOneRow(\PDO::FETCH_ASSOC);
128 128
         
129
-        if($ga_array) {
130
-            return $this->loadGeoAnalysisFromRow($ga_array);
131
-        }
129
+		if($ga_array) {
130
+			return $this->loadGeoAnalysisFromRow($ga_array);
131
+		}
132 132
         
133
-        return null;            
134
-    }
133
+		return null;            
134
+	}
135 135
     
136
-    /**
137
-     * Add a new geodispersion analysis in the database, in a transactional manner.
138
-     * When successful, eturns the newly created GeoAnalysis object.
139
-     * 
140
-     * @param string $description geodispersion analysis title
141
-     * @param int $analysis_level Analysis level
142
-     * @param string $map_file Filename of the map
143
-     * @param int $map_top_level Parent level of the map
144
-     * @param bool $use_flags Use flag in the place display
145
-     * @param int $gen_details Number of top places to display
146
-     * @return GeoAnalysis
147
-     */
136
+	/**
137
+	 * Add a new geodispersion analysis in the database, in a transactional manner.
138
+	 * When successful, eturns the newly created GeoAnalysis object.
139
+	 * 
140
+	 * @param string $description geodispersion analysis title
141
+	 * @param int $analysis_level Analysis level
142
+	 * @param string $map_file Filename of the map
143
+	 * @param int $map_top_level Parent level of the map
144
+	 * @param bool $use_flags Use flag in the place display
145
+	 * @param int $gen_details Number of top places to display
146
+	 * @return GeoAnalysis
147
+	 */
148 148
 	public function createGeoAnalysis($description, $analysis_level, $map_file, $map_top_level, $use_flags, $gen_details) {
149 149
 		try{
150 150
 			Database::beginTransaction();
@@ -174,17 +174,17 @@  discard block
 block discarded – undo
174 174
 			Log::addErrorLog('A new Geo Analysis failed to be created. Transaction rollbacked. Parameters ['.$description.', '.$analysis_level.','.$map_file.','.$map_top_level.','.$use_flags.', '.$gen_details.']. Exception: '.$ex->getMessage());
175 175
 		}
176 176
 		return $ga;
177
-    }
177
+	}
178 178
 	
179
-    /**
180
-     * Update a geodispersion analysis in the database, in transactional manner.
181
-     * When successful, returns the updated GeoAnalysis object
182
-     *  
183
-     * @param GeoAnalysis $ga
184
-     * @return GeoAnalysis
185
-     */
186
-    public function updateGeoAnalysis(GeoAnalysis $ga) {
187
-        try {
179
+	/**
180
+	 * Update a geodispersion analysis in the database, in transactional manner.
181
+	 * When successful, returns the updated GeoAnalysis object
182
+	 *  
183
+	 * @param GeoAnalysis $ga
184
+	 * @return GeoAnalysis
185
+	 */
186
+	public function updateGeoAnalysis(GeoAnalysis $ga) {
187
+		try {
188 188
 			Database::beginTransaction();
189 189
 		
190 190
 			Database::prepare(
@@ -217,238 +217,238 @@  discard block
 block discarded – undo
217 217
 			$ga = null;
218 218
 		}
219 219
 		return $ga;
220
-    }
220
+	}
221 221
     
222
-    /**
223
-     * Set the status of a specific analysis.
224
-     * The status can be enabled (true), or disabled (false).
225
-     * 
226
-     * @param GeoAnalysis $ga
227
-     * @param bool $status
228
-     */
229
-    public function setGeoAnalysisStatus(GeoAnalysis $ga, $status) {
230
-        Database::prepare(
231
-            'UPDATE `##maj_geodispersion`'.
232
-            ' SET majgd_status = :status'.
233
-            ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id'
234
-        )->execute(array(
235
-                'gedcom_id' => $this->tree->getTreeId(),
236
-                'status' => $status ? 'enabled' : 'disabled',
237
-                'ga_id' => $ga->getId()
238
-        ));
239
-    }
222
+	/**
223
+	 * Set the status of a specific analysis.
224
+	 * The status can be enabled (true), or disabled (false).
225
+	 * 
226
+	 * @param GeoAnalysis $ga
227
+	 * @param bool $status
228
+	 */
229
+	public function setGeoAnalysisStatus(GeoAnalysis $ga, $status) {
230
+		Database::prepare(
231
+			'UPDATE `##maj_geodispersion`'.
232
+			' SET majgd_status = :status'.
233
+			' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id'
234
+		)->execute(array(
235
+				'gedcom_id' => $this->tree->getTreeId(),
236
+				'status' => $status ? 'enabled' : 'disabled',
237
+				'ga_id' => $ga->getId()
238
+		));
239
+	}
240 240
     
241
-    /**
242
-     * Delete a geodispersion analysis from the database.
243
-     * 
244
-     * @param GeoAnalysis $ga
245
-     */
246
-    public function deleteGeoAnalysis(GeoAnalysis $ga) {
247
-        Database::prepare(
248
-            'DELETE FROM `##maj_geodispersion`'.
249
-            ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id'
250
-            )->execute(array(
251
-                'gedcom_id' => $this->tree->getTreeId(),
252
-                'ga_id' => $ga->getId()
253
-            ));
254
-    }
241
+	/**
242
+	 * Delete a geodispersion analysis from the database.
243
+	 * 
244
+	 * @param GeoAnalysis $ga
245
+	 */
246
+	public function deleteGeoAnalysis(GeoAnalysis $ga) {
247
+		Database::prepare(
248
+			'DELETE FROM `##maj_geodispersion`'.
249
+			' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id'
250
+			)->execute(array(
251
+				'gedcom_id' => $this->tree->getTreeId(),
252
+				'ga_id' => $ga->getId()
253
+			));
254
+	}
255 255
         
256
-    /**
257
-     * Return the list of geodispersion analysis recorded and enabled for a specific GEDCOM
258
-     *
259
-     * @return array List of enabled maps
260
-     */
261
-    public function getGeoAnalysisList(){
262
-        $res = array();
256
+	/**
257
+	 * Return the list of geodispersion analysis recorded and enabled for a specific GEDCOM
258
+	 *
259
+	 * @return array List of enabled maps
260
+	 */
261
+	public function getGeoAnalysisList(){
262
+		$res = array();
263 263
         
264
-        $list = Database::prepare(
265
-            'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen' .
266
-            ' FROM `##maj_geodispersion`' .
267
-            ' WHERE majgd_file = :gedcom_id AND majgd_status = :status'.
268
-            ' ORDER BY majgd_descr'
269
-        )->execute(array(
270
-            'gedcom_id' => $this->tree->getTreeId(),
271
-            'status' => 'enabled'
272
-        ))->fetchAll(\PDO::FETCH_ASSOC);
264
+		$list = Database::prepare(
265
+			'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen' .
266
+			' FROM `##maj_geodispersion`' .
267
+			' WHERE majgd_file = :gedcom_id AND majgd_status = :status'.
268
+			' ORDER BY majgd_descr'
269
+		)->execute(array(
270
+			'gedcom_id' => $this->tree->getTreeId(),
271
+			'status' => 'enabled'
272
+		))->fetchAll(\PDO::FETCH_ASSOC);
273 273
         
274
-        foreach($list as $ga) {
275
-           $res[] = $this->loadGeoAnalysisFromRow($ga);
276
-        }
274
+		foreach($list as $ga) {
275
+		   $res[] = $this->loadGeoAnalysisFromRow($ga);
276
+		}
277 277
         
278
-        return $res;
279
-    }
278
+		return $res;
279
+	}
280 280
     
281
-    /**
282
-     * Return the list of geodispersion analysis matching specified criterias.
283
-     * 
284
-     * @param string $search Search criteria in analysis description
285
-     * @param array $order_by Columns to order by
286
-     * @param int $start Offset to start with (for pagination)
287
-     * @param int|null $limit Max number of items to return (for pagination)
288
-     * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[]
289
-     */
290
-    public function getFilteredGeoAnalysisList($search = null, $order_by = null, $start = 0, $limit = null){
291
-        $res = array();
281
+	/**
282
+	 * Return the list of geodispersion analysis matching specified criterias.
283
+	 * 
284
+	 * @param string $search Search criteria in analysis description
285
+	 * @param array $order_by Columns to order by
286
+	 * @param int $start Offset to start with (for pagination)
287
+	 * @param int|null $limit Max number of items to return (for pagination)
288
+	 * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[]
289
+	 */
290
+	public function getFilteredGeoAnalysisList($search = null, $order_by = null, $start = 0, $limit = null){
291
+		$res = array();
292 292
             
293
-        $sql = 
294
-            'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' .
295
-            ' FROM `##maj_geodispersion`' .
296
-            ' WHERE majgd_file = :gedcom_id';
293
+		$sql = 
294
+			'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' .
295
+			' FROM `##maj_geodispersion`' .
296
+			' WHERE majgd_file = :gedcom_id';
297 297
         
298
-        $args = array('gedcom_id'=> $this->tree->getTreeId());
298
+		$args = array('gedcom_id'=> $this->tree->getTreeId());
299 299
         
300
-        if($search) {
301
-            $sql .= ' AND majgd_descr LIKE CONCAT(\'%\', :search, \'%\')';
302
-            $args['search'] = $search;
303
-        }
300
+		if($search) {
301
+			$sql .= ' AND majgd_descr LIKE CONCAT(\'%\', :search, \'%\')';
302
+			$args['search'] = $search;
303
+		}
304 304
         
305
-        if ($order_by) {
306
-            $sql .= ' ORDER BY ';
307
-            foreach ($order_by as $key => $value) {
308
-                if ($key > 0) {
309
-                    $sql .= ',';
310
-                }
305
+		if ($order_by) {
306
+			$sql .= ' ORDER BY ';
307
+			foreach ($order_by as $key => $value) {
308
+				if ($key > 0) {
309
+					$sql .= ',';
310
+				}
311 311
                 
312
-                switch ($value['dir']) {
313
-                    case 'asc':
314
-                        $sql .= $value['column'] . ' ASC ';
315
-                        break;
316
-                    case 'desc':
317
-                        $sql .= $value['column'] . ' DESC ';
318
-                        break;
319
-                }
320
-            }
321
-        } else {
322
-            $sql = " ORDER BY majgd_descr ASC";
323
-        }
312
+				switch ($value['dir']) {
313
+					case 'asc':
314
+						$sql .= $value['column'] . ' ASC ';
315
+						break;
316
+					case 'desc':
317
+						$sql .= $value['column'] . ' DESC ';
318
+						break;
319
+				}
320
+			}
321
+		} else {
322
+			$sql = " ORDER BY majgd_descr ASC";
323
+		}
324 324
         
325
-        if ($limit) {
326
-            $sql .= " LIMIT :limit OFFSET :offset";
327
-            $args['limit']  = $limit;
328
-            $args['offset'] = $start;
329
-        }
325
+		if ($limit) {
326
+			$sql .= " LIMIT :limit OFFSET :offset";
327
+			$args['limit']  = $limit;
328
+			$args['offset'] = $start;
329
+		}
330 330
             
331
-        $data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC);
331
+		$data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC);
332 332
 
333
-        foreach($data as $ga) {
334
-            $res[] = $this->loadGeoAnalysisFromRow($ga);
335
-        }
333
+		foreach($data as $ga) {
334
+			$res[] = $this->loadGeoAnalysisFromRow($ga);
335
+		}
336 336
         
337
-        return $res;
338
-    }
337
+		return $res;
338
+	}
339 339
             
340
-    /**
341
-     * Returns the infered place hierarchy, determined from the Gedcom data.
342
-     * Depending on the data, it can be based on the Gedcom Header description, or from a place example.
343
-     * This is returned as an associative array:
344
-     *      - type:    describe the source of the data (<em>header<em> / <em>data</em>)
345
-     *      - hierarchy: an array of the place hierarchy (in reverse order of the gedcom)
346
-     *      
347
-     * @return array
348
-     */
349
-    public function getPlacesHierarchy() {
350
-        if(!$this->place_hierarchy) {
351
-            if($place_structure = $this->getPlacesHierarchyFromHeader()) {
352
-                $this->place_hierarchy = array('type' => 'header', 'hierarchy' => $place_structure);
353
-            }
354
-            else {
355
-                $this->place_hierarchy = array('type' => 'data', 'hierarchy' => $this->getPlacesHierarchyFromData());
356
-            }            
357
-        }
358
-        return $this->place_hierarchy;        
359
-    }
340
+	/**
341
+	 * Returns the infered place hierarchy, determined from the Gedcom data.
342
+	 * Depending on the data, it can be based on the Gedcom Header description, or from a place example.
343
+	 * This is returned as an associative array:
344
+	 *      - type:    describe the source of the data (<em>header<em> / <em>data</em>)
345
+	 *      - hierarchy: an array of the place hierarchy (in reverse order of the gedcom)
346
+	 *      
347
+	 * @return array
348
+	 */
349
+	public function getPlacesHierarchy() {
350
+		if(!$this->place_hierarchy) {
351
+			if($place_structure = $this->getPlacesHierarchyFromHeader()) {
352
+				$this->place_hierarchy = array('type' => 'header', 'hierarchy' => $place_structure);
353
+			}
354
+			else {
355
+				$this->place_hierarchy = array('type' => 'data', 'hierarchy' => $this->getPlacesHierarchyFromData());
356
+			}            
357
+		}
358
+		return $this->place_hierarchy;        
359
+	}
360 360
     
361
-    /**
362
-     * Returns an array of the place hierarchy, as defined in the GEDCOM header.
363
-     * The places are reversed compared to normal GEDCOM structure.
364
-     * 
365
-     * @return array|null
366
-     */
367
-    protected function getPlacesHierarchyFromHeader() {
368
-        $head = GedcomRecord::getInstance('HEAD', $this->tree);
369
-        $head_place = $head->getFirstFact('PLAC');
370
-        if($head_place && $head_place_value = $head_place->getAttribute('FORM')){
371
-            return array_reverse(array_map('trim',explode(',', $head_place_value)));
372
-        }
373
-        return null;
374
-    }
361
+	/**
362
+	 * Returns an array of the place hierarchy, as defined in the GEDCOM header.
363
+	 * The places are reversed compared to normal GEDCOM structure.
364
+	 * 
365
+	 * @return array|null
366
+	 */
367
+	protected function getPlacesHierarchyFromHeader() {
368
+		$head = GedcomRecord::getInstance('HEAD', $this->tree);
369
+		$head_place = $head->getFirstFact('PLAC');
370
+		if($head_place && $head_place_value = $head_place->getAttribute('FORM')){
371
+			return array_reverse(array_map('trim',explode(',', $head_place_value)));
372
+		}
373
+		return null;
374
+	}
375 375
     
376
-    /**
377
-     * Returns an array of the place hierarchy, based on a random example of place within the GEDCOM.
378
-     * It will look for the longest hierarchy in the tree.
379
-     * The places are reversed compared to normal GEDCOM structure.
380
-     * 
381
-     * @return array
382
-     */
383
-    protected function getPlacesHierarchyFromData() {
384
-        $random_place = null;
385
-        $nb_levels = 0;
376
+	/**
377
+	 * Returns an array of the place hierarchy, based on a random example of place within the GEDCOM.
378
+	 * It will look for the longest hierarchy in the tree.
379
+	 * The places are reversed compared to normal GEDCOM structure.
380
+	 * 
381
+	 * @return array
382
+	 */
383
+	protected function getPlacesHierarchyFromData() {
384
+		$random_place = null;
385
+		$nb_levels = 0;
386 386
         
387
-        //Select all '2 PLAC ' tags in the file and create array
388
-        $places_list=array();
389
-        $ged_data = Database::prepare(
390
-            'SELECT i_gedcom AS gedcom'.
391
-            ' FROM `##individuals`'.
392
-            ' WHERE i_gedcom LIKE :gedcom AND i_file = :gedcom_id'.
393
-            ' UNION ALL'.
394
-            'SELECT f_gedcom AS gedcom'.
395
-            ' FROM `##families`'.
396
-            ' WHERE f_gedcom LIKE :gedcom AND f_file = :gedcom_id'
397
-        )->execute(array(
398
-            'gedcom' => '%\n2 PLAC %',
399
-            'gedcom_id' => $this->tree->getTreeId()            
400
-        ))->fetchOneColumn();
401
-        foreach ($ged_data as $ged_datum) {
402
-            preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches);
403
-            foreach ($matches[1] as $match) {
404
-                $places_list[$match]=true;
405
-            }
406
-        }
387
+		//Select all '2 PLAC ' tags in the file and create array
388
+		$places_list=array();
389
+		$ged_data = Database::prepare(
390
+			'SELECT i_gedcom AS gedcom'.
391
+			' FROM `##individuals`'.
392
+			' WHERE i_gedcom LIKE :gedcom AND i_file = :gedcom_id'.
393
+			' UNION ALL'.
394
+			'SELECT f_gedcom AS gedcom'.
395
+			' FROM `##families`'.
396
+			' WHERE f_gedcom LIKE :gedcom AND f_file = :gedcom_id'
397
+		)->execute(array(
398
+			'gedcom' => '%\n2 PLAC %',
399
+			'gedcom_id' => $this->tree->getTreeId()            
400
+		))->fetchOneColumn();
401
+		foreach ($ged_data as $ged_datum) {
402
+			preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches);
403
+			foreach ($matches[1] as $match) {
404
+				$places_list[$match]=true;
405
+			}
406
+		}
407 407
         
408
-        // Unique list of places
409
-        $places_list=array_keys($places_list);
408
+		// Unique list of places
409
+		$places_list=array_keys($places_list);
410 410
         
411
-        //sort the array, limit to unique values, and count them
412
-        $places_parts=array();
413
-        usort($places_list, array('I18N', 'strcasecmp'));
414
-        $nb_places = count($places_list);
411
+		//sort the array, limit to unique values, and count them
412
+		$places_parts=array();
413
+		usort($places_list, array('I18N', 'strcasecmp'));
414
+		$nb_places = count($places_list);
415 415
         
416
-        //calculate maximum no. of levels to display
417
-        $has_found_good_example = false;
418
-        foreach($places_list as $place){
419
-            $levels = explode(",", $place);
420
-            $parts = count($levels);
421
-            if ($parts >= $nb_levels){
422
-                $nb_levels = $parts;
423
-                if(!$has_found_good_example){
424
-                    $random_place = $$place;
425
-                    if(min(array_map('strlen', $levels)) > 0){
426
-                        $has_found_good_example = true;
427
-                    }
428
-                }
429
-            }
430
-        }
416
+		//calculate maximum no. of levels to display
417
+		$has_found_good_example = false;
418
+		foreach($places_list as $place){
419
+			$levels = explode(",", $place);
420
+			$parts = count($levels);
421
+			if ($parts >= $nb_levels){
422
+				$nb_levels = $parts;
423
+				if(!$has_found_good_example){
424
+					$random_place = $$place;
425
+					if(min(array_map('strlen', $levels)) > 0){
426
+						$has_found_good_example = true;
427
+					}
428
+				}
429
+			}
430
+		}
431 431
         
432
-        return array_reverse(array_map('trim',explode(',', $randomPlace)));
433
-    }
432
+		return array_reverse(array_map('trim',explode(',', $randomPlace)));
433
+	}
434 434
     
435
-    /**
436
-     * Returns the list of geodispersion maps available within the maps folder.
437
-     * 
438
-     * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\OutlineMap[]
439
-     */
440
-    public function getOutlineMapsList() {
441
-        $res = array();
442
-        $root_path = WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/';
443
-        if(is_dir($root_path)){
444
-            $dir = opendir($root_path);
445
-            while (($file=readdir($dir))!== false) {
446
-                if (preg_match('/^[a-zA-Z0-9_]+.xml$/', $file)) {
447
-                    $res[base64_encode($file)] = new OutlineMap($file, true);
448
-                }
449
-            }
450
-        }
451
-        return $res;
452
-    }
435
+	/**
436
+	 * Returns the list of geodispersion maps available within the maps folder.
437
+	 * 
438
+	 * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\OutlineMap[]
439
+	 */
440
+	public function getOutlineMapsList() {
441
+		$res = array();
442
+		$root_path = WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/';
443
+		if(is_dir($root_path)){
444
+			$dir = opendir($root_path);
445
+			while (($file=readdir($dir))!== false) {
446
+				if (preg_match('/^[a-zA-Z0-9_]+.xml$/', $file)) {
447
+					$res[base64_encode($file)] = new OutlineMap($file, true);
448
+				}
449
+			}
450
+		}
451
+		return $res;
452
+	}
453 453
 }
454 454
  
455 455
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -65,14 +65,14 @@  discard block
 block discarded – undo
65 65
         ->setIsUsingFlags($row['majgd_useflagsgen'] == 'yes')
66 66
         ->setMaxDetailsInGen($row['majgd_detailsgen']);
67 67
         
68
-        if($row['majgd_map']) {
68
+        if ($row['majgd_map']) {
69 69
             $options
70 70
             ->setMap(new OutlineMap($row['majgd_map']))
71 71
             ->setMapLevel($row['majgd_toplevel']);
72 72
         }
73 73
         
74 74
         $enabled = true;
75
-        if(isset($row['majgd_status']) && $row['majgd_status'] == 'disabled') {
75
+        if (isset($row['majgd_status']) && $row['majgd_status'] == 'disabled') {
76 76
             $enabled = false;
77 77
         }
78 78
         
@@ -93,8 +93,8 @@  discard block
 block discarded – undo
93 93
      */
94 94
     public function getGeoAnalysisCount() {
95 95
         return Database::prepare(
96
-            'SELECT COUNT(majgd_id)' .
97
-            ' FROM `##maj_geodispersion`' .
96
+            'SELECT COUNT(majgd_id)'.
97
+            ' FROM `##maj_geodispersion`'.
98 98
             ' WHERE majgd_file = :gedcom_id'
99 99
             )->execute(array(
100 100
                 'gedcom_id' => $this->tree->getTreeId()
@@ -110,15 +110,15 @@  discard block
 block discarded – undo
110 110
      * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis|NULL
111 111
      */
112 112
     public function getGeoAnalysis($id, $only_enabled = true) {
113
-        $args = array (
113
+        $args = array(
114 114
             'gedcom_id' => $this->tree->getTreeId(),
115 115
             'ga_id' => $id
116 116
         );
117 117
         
118
-        $sql = 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' .
119
-            ' FROM `##maj_geodispersion`' .
118
+        $sql = 'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status'.
119
+            ' FROM `##maj_geodispersion`'.
120 120
             ' WHERE majgd_file = :gedcom_id AND majgd_id=:ga_id';
121
-        if($only_enabled) {
121
+        if ($only_enabled) {
122 122
             $sql .= ' AND majgd_status = :status';
123 123
             $args['status'] = 'enabled';
124 124
         }
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
         
127 127
         $ga_array = Database::prepare($sql)->execute($args)->fetchOneRow(\PDO::FETCH_ASSOC);
128 128
         
129
-        if($ga_array) {
129
+        if ($ga_array) {
130 130
             return $this->loadGeoAnalysisFromRow($ga_array);
131 131
         }
132 132
         
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      * @return GeoAnalysis
147 147
      */
148 148
 	public function createGeoAnalysis($description, $analysis_level, $map_file, $map_top_level, $use_flags, $gen_details) {
149
-		try{
149
+		try {
150 150
 			Database::beginTransaction();
151 151
 		
152 152
 			Database::prepare(
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 			
169 169
 			$id = Database::commit();
170 170
 		}
171
-		catch(\Exception $ex) {
171
+		catch (\Exception $ex) {
172 172
 			Database::rollback();
173 173
 			$ga = null;
174 174
 			Log::addErrorLog('A new Geo Analysis failed to be created. Transaction rollbacked. Parameters ['.$description.', '.$analysis_level.','.$map_file.','.$map_top_level.','.$use_flags.', '.$gen_details.']. Exception: '.$ex->getMessage());
@@ -211,9 +211,9 @@  discard block
 block discarded – undo
211 211
 			
212 212
 			$id = Database::commit();
213 213
 		}
214
-		catch(\Exception $ex) {		    
214
+		catch (\Exception $ex) {		    
215 215
 			Database::rollback();
216
-			Log::addErrorLog('The Geo Analysis ID “' . $ga->getId() . '” failed to be updated. Transaction rollbacked. Exception: '.$ex->getMessage());
216
+			Log::addErrorLog('The Geo Analysis ID “'.$ga->getId().'” failed to be updated. Transaction rollbacked. Exception: '.$ex->getMessage());
217 217
 			$ga = null;
218 218
 		}
219 219
 		return $ga;
@@ -258,12 +258,12 @@  discard block
 block discarded – undo
258 258
      *
259 259
      * @return array List of enabled maps
260 260
      */
261
-    public function getGeoAnalysisList(){
261
+    public function getGeoAnalysisList() {
262 262
         $res = array();
263 263
         
264 264
         $list = Database::prepare(
265
-            'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen' .
266
-            ' FROM `##maj_geodispersion`' .
265
+            'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen'.
266
+            ' FROM `##maj_geodispersion`'.
267 267
             ' WHERE majgd_file = :gedcom_id AND majgd_status = :status'.
268 268
             ' ORDER BY majgd_descr'
269 269
         )->execute(array(
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
             'status' => 'enabled'
272 272
         ))->fetchAll(\PDO::FETCH_ASSOC);
273 273
         
274
-        foreach($list as $ga) {
274
+        foreach ($list as $ga) {
275 275
            $res[] = $this->loadGeoAnalysisFromRow($ga);
276 276
         }
277 277
         
@@ -287,17 +287,17 @@  discard block
 block discarded – undo
287 287
      * @param int|null $limit Max number of items to return (for pagination)
288 288
      * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[]
289 289
      */
290
-    public function getFilteredGeoAnalysisList($search = null, $order_by = null, $start = 0, $limit = null){
290
+    public function getFilteredGeoAnalysisList($search = null, $order_by = null, $start = 0, $limit = null) {
291 291
         $res = array();
292 292
             
293 293
         $sql = 
294
-            'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status' .
295
-            ' FROM `##maj_geodispersion`' .
294
+            'SELECT majgd_id, majgd_descr, majgd_sublevel, majgd_map, majgd_toplevel, majgd_useflagsgen, majgd_detailsgen, majgd_status'.
295
+            ' FROM `##maj_geodispersion`'.
296 296
             ' WHERE majgd_file = :gedcom_id';
297 297
         
298 298
         $args = array('gedcom_id'=> $this->tree->getTreeId());
299 299
         
300
-        if($search) {
300
+        if ($search) {
301 301
             $sql .= ' AND majgd_descr LIKE CONCAT(\'%\', :search, \'%\')';
302 302
             $args['search'] = $search;
303 303
         }
@@ -311,10 +311,10 @@  discard block
 block discarded – undo
311 311
                 
312 312
                 switch ($value['dir']) {
313 313
                     case 'asc':
314
-                        $sql .= $value['column'] . ' ASC ';
314
+                        $sql .= $value['column'].' ASC ';
315 315
                         break;
316 316
                     case 'desc':
317
-                        $sql .= $value['column'] . ' DESC ';
317
+                        $sql .= $value['column'].' DESC ';
318 318
                         break;
319 319
                 }
320 320
             }
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
             
331 331
         $data = Database::prepare($sql)->execute($args)->fetchAll(\PDO::FETCH_ASSOC);
332 332
 
333
-        foreach($data as $ga) {
333
+        foreach ($data as $ga) {
334 334
             $res[] = $this->loadGeoAnalysisFromRow($ga);
335 335
         }
336 336
         
@@ -347,8 +347,8 @@  discard block
 block discarded – undo
347 347
      * @return array
348 348
      */
349 349
     public function getPlacesHierarchy() {
350
-        if(!$this->place_hierarchy) {
351
-            if($place_structure = $this->getPlacesHierarchyFromHeader()) {
350
+        if (!$this->place_hierarchy) {
351
+            if ($place_structure = $this->getPlacesHierarchyFromHeader()) {
352 352
                 $this->place_hierarchy = array('type' => 'header', 'hierarchy' => $place_structure);
353 353
             }
354 354
             else {
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
     protected function getPlacesHierarchyFromHeader() {
368 368
         $head = GedcomRecord::getInstance('HEAD', $this->tree);
369 369
         $head_place = $head->getFirstFact('PLAC');
370
-        if($head_place && $head_place_value = $head_place->getAttribute('FORM')){
371
-            return array_reverse(array_map('trim',explode(',', $head_place_value)));
370
+        if ($head_place && $head_place_value = $head_place->getAttribute('FORM')) {
371
+            return array_reverse(array_map('trim', explode(',', $head_place_value)));
372 372
         }
373 373
         return null;
374 374
     }
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
         $nb_levels = 0;
386 386
         
387 387
         //Select all '2 PLAC ' tags in the file and create array
388
-        $places_list=array();
388
+        $places_list = array();
389 389
         $ged_data = Database::prepare(
390 390
             'SELECT i_gedcom AS gedcom'.
391 391
             ' FROM `##individuals`'.
@@ -401,35 +401,35 @@  discard block
 block discarded – undo
401 401
         foreach ($ged_data as $ged_datum) {
402 402
             preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches);
403 403
             foreach ($matches[1] as $match) {
404
-                $places_list[$match]=true;
404
+                $places_list[$match] = true;
405 405
             }
406 406
         }
407 407
         
408 408
         // Unique list of places
409
-        $places_list=array_keys($places_list);
409
+        $places_list = array_keys($places_list);
410 410
         
411 411
         //sort the array, limit to unique values, and count them
412
-        $places_parts=array();
412
+        $places_parts = array();
413 413
         usort($places_list, array('I18N', 'strcasecmp'));
414 414
         $nb_places = count($places_list);
415 415
         
416 416
         //calculate maximum no. of levels to display
417 417
         $has_found_good_example = false;
418
-        foreach($places_list as $place){
418
+        foreach ($places_list as $place) {
419 419
             $levels = explode(",", $place);
420 420
             $parts = count($levels);
421
-            if ($parts >= $nb_levels){
421
+            if ($parts >= $nb_levels) {
422 422
                 $nb_levels = $parts;
423
-                if(!$has_found_good_example){
423
+                if (!$has_found_good_example) {
424 424
                     $random_place = $$place;
425
-                    if(min(array_map('strlen', $levels)) > 0){
425
+                    if (min(array_map('strlen', $levels)) > 0) {
426 426
                         $has_found_good_example = true;
427 427
                     }
428 428
                 }
429 429
             }
430 430
         }
431 431
         
432
-        return array_reverse(array_map('trim',explode(',', $randomPlace)));
432
+        return array_reverse(array_map('trim', explode(',', $randomPlace)));
433 433
     }
434 434
     
435 435
     /**
@@ -440,9 +440,9 @@  discard block
 block discarded – undo
440 440
     public function getOutlineMapsList() {
441 441
         $res = array();
442 442
         $root_path = WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/';
443
-        if(is_dir($root_path)){
443
+        if (is_dir($root_path)) {
444 444
             $dir = opendir($root_path);
445
-            while (($file=readdir($dir))!== false) {
445
+            while (($file = readdir($dir)) !== false) {
446 446
                 if (preg_match('/^[a-zA-Z0-9_]+.xml$/', $file)) {
447 447
                     $res[base64_encode($file)] = new OutlineMap($file, true);
448 448
                 }
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -167,8 +167,7 @@  discard block
 block discarded – undo
167 167
 			$ga = $this->getGeoAnalysis($id, false);
168 168
 			
169 169
 			$id = Database::commit();
170
-		}
171
-		catch(\Exception $ex) {
170
+		} catch(\Exception $ex) {
172 171
 			Database::rollback();
173 172
 			$ga = null;
174 173
 			Log::addErrorLog('A new Geo Analysis failed to be created. Transaction rollbacked. Parameters ['.$description.', '.$analysis_level.','.$map_file.','.$map_top_level.','.$use_flags.', '.$gen_details.']. Exception: '.$ex->getMessage());
@@ -210,8 +209,7 @@  discard block
 block discarded – undo
210 209
 			$ga = $this->getGeoAnalysis($ga->getId(), false);
211 210
 			
212 211
 			$id = Database::commit();
213
-		}
214
-		catch(\Exception $ex) {		    
212
+		} catch(\Exception $ex) {		    
215 213
 			Database::rollback();
216 214
 			Log::addErrorLog('The Geo Analysis ID “' . $ga->getId() . '” failed to be updated. Transaction rollbacked. Exception: '.$ex->getMessage());
217 215
 			$ga = null;
@@ -350,8 +348,7 @@  discard block
 block discarded – undo
350 348
         if(!$this->place_hierarchy) {
351 349
             if($place_structure = $this->getPlacesHierarchyFromHeader()) {
352 350
                 $this->place_hierarchy = array('type' => 'header', 'hierarchy' => $place_structure);
353
-            }
354
-            else {
351
+            } else {
355 352
                 $this->place_hierarchy = array('type' => 'data', 'hierarchy' => $this->getPlacesHierarchyFromData());
356 353
             }            
357 354
         }
Please login to merge, or discard this patch.
src/Webtrees/Module/PatronymicLineage/Model/LineageNode.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 	/**
41 41
 	 * Constructor for Lineage node
42 42
 	 * 
43
-	 * @param Fisharebest\Webtrees\Individual $node_indi Main individual
43
+	 * @param Individual $node_indi Main individual
44 44
 	 * @param LineageRootNode $root_node Node of the lineage root
45 45
 	 * @param unknown $alt_surname Follow-up surname
46 46
 	 */
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
 	/**
55 55
 	 * Add a spouse family to the node
56 56
 	 * 
57
-	 * @param Fisharebest\Webtrees\Family $fams
57
+	 * @param Family $fams
58 58
 	 */
59 59
 	public function addFamily(Family $fams) {
60 60
 		if($fams && !isset($this->linked_fams[$fams])) {
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
 	/**
66 66
 	 * Add a child LineageNode to the node
67 67
 	 * 
68
-	 * @param Fisharebest\Webtrees\Family $fams
68
+	 * @param Family $fams
69 69
 	 * @param LineageNode $child
70 70
 	 */
71 71
 	public function addChild(Family $fams, LineageNode $child = null) {
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
 	/**
81 81
 	 * Returns the node individual
82 82
 	 * 
83
-	 * @return Fisharebest\Webtrees\Individual
83
+	 * @return \Fisharebest\Webtrees\GedcomRecord
84 84
 	 */
85 85
 	public function getIndividual() {
86 86
 		return $this->node_indi;
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @param Fisharebest\Webtrees\Family $fams
58 58
 	 */
59 59
 	public function addFamily(Family $fams) {
60
-		if($fams && !isset($this->linked_fams[$fams])) {
60
+		if ($fams && !isset($this->linked_fams[$fams])) {
61 61
 			$this->linked_fams[$fams] = array();
62 62
 		}
63 63
 	}
@@ -69,7 +69,7 @@  discard block
 block discarded – undo
69 69
 	 * @param LineageNode $child
70 70
 	 */
71 71
 	public function addChild(Family $fams, LineageNode $child = null) {
72
-		if($fams) {
72
+		if ($fams) {
73 73
 			$this->addFamily($fams);
74 74
 			$tmp = $this->linked_fams[$fams];
75 75
 			$tmp[] = $child;
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
 	 * @return boolean
120 120
 	 */
121 121
 	public function hasFollowUpSurname() {
122
-		return !is_null($this->alt_surname) && strlen($this->alt_surname) > 0 ;
122
+		return !is_null($this->alt_surname) && strlen($this->alt_surname) > 0;
123 123
 	}
124 124
 	
125 125
 }
Please login to merge, or discard this patch.
src/Webtrees/Module/Sosa/Model/SosaProvider.php 4 patches
Doc Comments   +8 added lines, -9 removed lines patch added patch discarded remove patch
@@ -246,7 +246,6 @@  discard block
 block discarded – undo
246 246
     /**
247 247
      * Return the list of all sosas, with the generations it belongs to
248 248
      *
249
-     * @param int $ged_id ID of the gedcom file
250 249
      * @return array Associative array of Sosa ancestors, with their generation, comma separated
251 250
      */
252 251
     public function getAllSosaWithGenerations(){
@@ -266,7 +265,7 @@  discard block
 block discarded – undo
266 265
     /**
267 266
      * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals.
268 267
      *
269
-     * @param number $gen Generation
268
+     * @param integer $gen Generation
270 269
      * @return array Array of Sosa individuals
271 270
      */
272 271
     public function getSosaListAtGeneration($gen){
@@ -297,7 +296,7 @@  discard block
 block discarded – undo
297 296
     /**
298 297
      * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families.
299 298
      *
300
-     * @param number $gen Generation
299
+     * @param integer $gen Generation
301 300
      * @return array Array of Sosa families
302 301
      */
303 302
     public function getFamilySosaListAtGeneration($gen){
@@ -333,7 +332,7 @@  discard block
 block discarded – undo
333 332
     /**
334 333
      * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals.
335 334
      *
336
-     * @param number $gen Generation
335
+     * @param integer $gen Generation
337 336
      * @return array Array of Sosa individuals
338 337
      */
339 338
     public function getMissingSosaListAtGeneration($gen){
@@ -428,8 +427,8 @@  discard block
 block discarded – undo
428 427
     /**
429 428
      * Get the number of Sosa in a specific generation.
430 429
      *
431
-     * @param number $gen Generation
432
-     * @return number Number of Sosas in generation
430
+     * @param integer $gen Generation
431
+     * @return integer Number of Sosas in generation
433 432
      */
434 433
     public function getSosaCountAtGeneration($gen){
435 434
         if(!$this->is_setup) return 0;
@@ -447,7 +446,7 @@  discard block
 block discarded – undo
447 446
     /**
448 447
      * Get the total number of Sosa up to a specific generation.
449 448
      *
450
-     * @param number $gen Generation
449
+     * @param integer $gen Generation
451 450
      * @return number Total number of Sosas up to generation
452 451
      */
453 452
     public function getSosaCountUpToGeneration($gen){
@@ -482,7 +481,7 @@  discard block
 block discarded – undo
482 481
     /**
483 482
      * Get the number of distinct Sosa individual up to a specific generation.
484 483
      *
485
-     * @param number $gen Generation
484
+     * @param integer $gen Generation
486 485
      * @return number Number of distinct Sosa individuals up to generation
487 486
      */
488 487
     public function getDifferentSosaCountUpToGeneration($gen){
@@ -505,7 +504,7 @@  discard block
 block discarded – undo
505 504
      *  - last : Last birth year in generation
506 505
      *  - avg : Average birth year
507 506
      *
508
-     * @param number $gen Generation
507
+     * @param integer $gen Generation
509 508
      * @return array Birth statistics array
510 509
      */
511 510
     public function getStatsBirthYearInGeneration($gen){
Please login to merge, or discard this patch.
Indentation   +549 added lines, -549 removed lines patch added patch discarded remove patch
@@ -22,378 +22,378 @@  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(!$this->getRootIndi()) {
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->getRootIndi() === 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 for the reference tree and user.
118
-     * @return string Individual ID
119
-     */
120
-    public function getRootIndi() {
121
-        return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
122
-    }
96
+		// Check if the user, or the default user, has a root already setup;
97
+		if(!$this->getRootIndi()) {
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->getRootIndi() === 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 for the reference tree and user.
118
+	 * @return string Individual ID
119
+	 */
120
+	public function getRootIndi() {
121
+		return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID');
122
+	}
123 123
        
124
-    /*****************
124
+	/*****************
125 125
      * DATA CRUD LAYER
126 126
      *****************/
127 127
     
128
-    /**
129
-     * Remove all Sosa entries related to the gedcom file and user
130
-     */
131
-    public function deleteAll() {
132
-        if(!$this->is_setup) return;
133
-        Database::prepare(
134
-            'DELETE FROM `##maj_sosa`'.
135
-            ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
136
-            ->execute(array(
137
-                'tree_id' => $this->tree->getTreeId(), 
138
-                'user_id' => $this->user->getUserId()                
139
-            ));
140
-    }
141
-    
142
-    /**
143
-     * Remove all ancestors of a sosa number
144
-     * 
145
-     * @param int $sosa
146
-     */
147
-    public function deleteAncestors($sosa) {
148
-        if(!$this->is_setup) return;
149
-        $gen = Functions::getGeneration($sosa);
150
-        Database::prepare(
151
-            'DELETE FROM `##maj_sosa`'.
152
-            ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' .
153
-            ' AND majs_gen >= :gen' .
154
-            ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa'
155
-        )->execute(array(
156
-            'tree_id' => $this->tree->getTreeId(), 
157
-            'user_id' => $this->user->getUserId(),
158
-            'gen' => $gen,
159
-            'sosa' => $sosa
160
-        ));
161
-    }    
162
-    
163
-    /**
164
-     * Insert (or update if already existing) a list of Sosa individuals
165
-     * @param array $sosa_records
166
-     */
167
-    public function insertOrUpdate($sosa_records) {
168
-        if(!$this->is_setup) return;
128
+	/**
129
+	 * Remove all Sosa entries related to the gedcom file and user
130
+	 */
131
+	public function deleteAll() {
132
+		if(!$this->is_setup) return;
133
+		Database::prepare(
134
+			'DELETE FROM `##maj_sosa`'.
135
+			' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
136
+			->execute(array(
137
+				'tree_id' => $this->tree->getTreeId(), 
138
+				'user_id' => $this->user->getUserId()                
139
+			));
140
+	}
141
+    
142
+	/**
143
+	 * Remove all ancestors of a sosa number
144
+	 * 
145
+	 * @param int $sosa
146
+	 */
147
+	public function deleteAncestors($sosa) {
148
+		if(!$this->is_setup) return;
149
+		$gen = Functions::getGeneration($sosa);
150
+		Database::prepare(
151
+			'DELETE FROM `##maj_sosa`'.
152
+			' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' .
153
+			' AND majs_gen >= :gen' .
154
+			' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa'
155
+		)->execute(array(
156
+			'tree_id' => $this->tree->getTreeId(), 
157
+			'user_id' => $this->user->getUserId(),
158
+			'gen' => $gen,
159
+			'sosa' => $sosa
160
+		));
161
+	}    
162
+    
163
+	/**
164
+	 * Insert (or update if already existing) a list of Sosa individuals
165
+	 * @param array $sosa_records
166
+	 */
167
+	public function insertOrUpdate($sosa_records) {
168
+		if(!$this->is_setup) return;
169 169
         
170
-        $treeid = $this->tree->getTreeId();
171
-        $userid = $this->user->getUserId();
172
-        $questionmarks_table = array();
173
-        $values_table = array();
170
+		$treeid = $this->tree->getTreeId();
171
+		$userid = $this->user->getUserId();
172
+		$questionmarks_table = array();
173
+		$values_table = array();
174 174
         
175
-        $i = 0;
176
-        foreach  ($sosa_records as $row) {
177
-            $gen = Functions::getGeneration($row['sosa']);
178
-            if($gen <= self::MAX_DB_GENERATIONS) {
179
-                $questionmarks_table[] = 
180
-                    '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')';
181
-                $values_table = array_merge(
182
-                    $values_table, 
183
-                    array(
184
-                        'tree_id'.$i => $treeid, 
185
-                        'user_id'.$i => $userid, 
186
-                        'sosa'.$i => $row['sosa'], 
187
-                        'indi_id'.$i => $row['indi'], 
188
-                        'gen'.$i => Functions::getGeneration($row['sosa']),
189
-                        'byear'.$i => $row['birth_year'],
190
-                        'dyear'.$i => $row['death_year']
191
-                    )
192
-                );
193
-            }
194
-            $i++;
195
-        }
175
+		$i = 0;
176
+		foreach  ($sosa_records as $row) {
177
+			$gen = Functions::getGeneration($row['sosa']);
178
+			if($gen <= self::MAX_DB_GENERATIONS) {
179
+				$questionmarks_table[] = 
180
+					'(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')';
181
+				$values_table = array_merge(
182
+					$values_table, 
183
+					array(
184
+						'tree_id'.$i => $treeid, 
185
+						'user_id'.$i => $userid, 
186
+						'sosa'.$i => $row['sosa'], 
187
+						'indi_id'.$i => $row['indi'], 
188
+						'gen'.$i => Functions::getGeneration($row['sosa']),
189
+						'byear'.$i => $row['birth_year'],
190
+						'dyear'.$i => $row['death_year']
191
+					)
192
+				);
193
+			}
194
+			$i++;
195
+		}
196 196
         
197
-        $sql = 'REPLACE INTO `##maj_sosa`' .
198
-            ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' .
199
-            ' VALUES '. implode(',', $questionmarks_table);
200
-        Database::prepare($sql)->execute($values_table);
201
-    }
197
+		$sql = 'REPLACE INTO `##maj_sosa`' .
198
+			' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' .
199
+			' VALUES '. implode(',', $questionmarks_table);
200
+		Database::prepare($sql)->execute($values_table);
201
+	}
202 202
     
203
-    /****************
203
+	/****************
204 204
      * SIMPLE QUERIES
205 205
      ****************/
206 206
     
207
-    /**
208
-     * Returns the list of Sosa numbers to which an individual is related.
209
-     * Format: key = sosa number, value = generation for the Sosa number
210
-     * 
211
-     * @param Individual $indi
212
-     * @return array Array of sosa numbers
213
-     */
214
-    public function getSosaNumbers(Individual $indi) {
215
-        if(!$this->is_setup) return array();
216
-        return Database::prepare(
217
-                'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
218
-                ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
219
-            )->execute(array(
220
-                'indi_id' => $indi->getXref(), 
221
-                'tree_id' => $this->tree->getTreeId(), 
222
-                'user_id' => $this->user->getUserId()
223
-            ))->fetchAssoc();
224
-    }
225
-    
226
-    /**
227
-     * Get the last generation of Sosa ancestors
228
-     *
229
-     * @return number Last generation if found, 1 otherwise
230
-     */
231
-    public function getLastGeneration() {
232
-        if(!$this->is_setup) return;
233
-        return Database::prepare(
234
-                'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
235
-                ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
236
-            )->execute(array(
237
-                'tree_id' => $this->tree->getTreeId(), 
238
-                'user_id' => $this->user->getUserId()                
239
-            ))->fetchOne() ?: 1;
240
-    }
241
-    
242
-    /*************
207
+	/**
208
+	 * Returns the list of Sosa numbers to which an individual is related.
209
+	 * Format: key = sosa number, value = generation for the Sosa number
210
+	 * 
211
+	 * @param Individual $indi
212
+	 * @return array Array of sosa numbers
213
+	 */
214
+	public function getSosaNumbers(Individual $indi) {
215
+		if(!$this->is_setup) return array();
216
+		return Database::prepare(
217
+				'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
218
+				' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
219
+			)->execute(array(
220
+				'indi_id' => $indi->getXref(), 
221
+				'tree_id' => $this->tree->getTreeId(), 
222
+				'user_id' => $this->user->getUserId()
223
+			))->fetchAssoc();
224
+	}
225
+    
226
+	/**
227
+	 * Get the last generation of Sosa ancestors
228
+	 *
229
+	 * @return number Last generation if found, 1 otherwise
230
+	 */
231
+	public function getLastGeneration() {
232
+		if(!$this->is_setup) return;
233
+		return Database::prepare(
234
+				'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
235
+				' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
236
+			)->execute(array(
237
+				'tree_id' => $this->tree->getTreeId(), 
238
+				'user_id' => $this->user->getUserId()                
239
+			))->fetchOne() ?: 1;
240
+	}
241
+    
242
+	/*************
243 243
      * SOSA LISTS
244 244
      *************/
245 245
     
246
-    /**
247
-     * Return the list of all sosas, with the generations it belongs to
248
-     *
249
-     * @param int $ged_id ID of the gedcom file
250
-     * @return array Associative array of Sosa ancestors, with their generation, comma separated
251
-     */
252
-    public function getAllSosaWithGenerations(){
253
-        if(!$this->is_setup) return array();
254
-        return Database::prepare(
255
-            'SELECT majs_i_id AS indi,' .
256
-            ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
257
-            ' FROM `##maj_sosa`' .
258
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' .
259
-            ' GROUP BY majs_i_id'
260
-        )->execute(array(
261
-            'tree_id' => $this->tree->getTreeId(),
262
-            'user_id' => $this->user->getUserId()
263
-        ))->fetchAssoc();
264
-    }
265
-    
266
-    /**
267
-     * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals.
268
-     *
269
-     * @param number $gen Generation
270
-     * @return array Array of Sosa individuals
271
-     */
272
-    public function getSosaListAtGeneration($gen){
273
-        if(!$this->is_setup) return array();
274
-        if(!$this->sosa_list_by_gen)
275
-            $this->sosa_list_by_gen = array();
246
+	/**
247
+	 * Return the list of all sosas, with the generations it belongs to
248
+	 *
249
+	 * @param int $ged_id ID of the gedcom file
250
+	 * @return array Associative array of Sosa ancestors, with their generation, comma separated
251
+	 */
252
+	public function getAllSosaWithGenerations(){
253
+		if(!$this->is_setup) return array();
254
+		return Database::prepare(
255
+			'SELECT majs_i_id AS indi,' .
256
+			' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
257
+			' FROM `##maj_sosa`' .
258
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' .
259
+			' GROUP BY majs_i_id'
260
+		)->execute(array(
261
+			'tree_id' => $this->tree->getTreeId(),
262
+			'user_id' => $this->user->getUserId()
263
+		))->fetchAssoc();
264
+	}
265
+    
266
+	/**
267
+	 * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals.
268
+	 *
269
+	 * @param number $gen Generation
270
+	 * @return array Array of Sosa individuals
271
+	 */
272
+	public function getSosaListAtGeneration($gen){
273
+		if(!$this->is_setup) return array();
274
+		if(!$this->sosa_list_by_gen)
275
+			$this->sosa_list_by_gen = array();
276 276
         
277
-        if($gen){
278
-            if(!isset($this->sosa_list_by_gen[$gen])){
279
-                $this->sosa_list_by_gen[$gen] = Database::prepare(
280
-                    'SELECT majs_sosa AS sosa, majs_i_id AS indi'.
281
-                    ' FROM `##maj_sosa`'.
282
-                    ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
283
-                    ' AND majs_gen = :gen'.
284
-                    ' ORDER BY majs_sosa ASC')
285
-                ->execute(array(
286
-                    'tree_id' => $this->tree->getTreeId(),
287
-                    'user_id' => $this->user->getUserId(),
288
-                    'gen' => $gen
289
-                ))
290
-                ->fetchAssoc();
291
-            }
292
-            return $this->sosa_list_by_gen[$gen];
293
-        }
294
-        return array();
295
-    }
296
-    
297
-    /**
298
-     * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families.
299
-     *
300
-     * @param number $gen Generation
301
-     * @return array Array of Sosa families
302
-     */
303
-    public function getFamilySosaListAtGeneration($gen){
304
-        if(!$this->is_setup) return array();
305
-        if(!$this->sosa_fam_list_by_gen)
306
-            $this->sosa_fam_list_by_gen = array();
277
+		if($gen){
278
+			if(!isset($this->sosa_list_by_gen[$gen])){
279
+				$this->sosa_list_by_gen[$gen] = Database::prepare(
280
+					'SELECT majs_sosa AS sosa, majs_i_id AS indi'.
281
+					' FROM `##maj_sosa`'.
282
+					' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
283
+					' AND majs_gen = :gen'.
284
+					' ORDER BY majs_sosa ASC')
285
+				->execute(array(
286
+					'tree_id' => $this->tree->getTreeId(),
287
+					'user_id' => $this->user->getUserId(),
288
+					'gen' => $gen
289
+				))
290
+				->fetchAssoc();
291
+			}
292
+			return $this->sosa_list_by_gen[$gen];
293
+		}
294
+		return array();
295
+	}
296
+    
297
+	/**
298
+	 * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families.
299
+	 *
300
+	 * @param number $gen Generation
301
+	 * @return array Array of Sosa families
302
+	 */
303
+	public function getFamilySosaListAtGeneration($gen){
304
+		if(!$this->is_setup) return array();
305
+		if(!$this->sosa_fam_list_by_gen)
306
+			$this->sosa_fam_list_by_gen = array();
307 307
         
308
-        if($gen){
309
-            if(!isset($this->sosa_fam_list_by_gen[$gen])){
310
-                $this->sosa_fam_list_by_gen[$gen] = Database::prepare(
311
-                    'SELECT s1.majs_sosa AS sosa, f_id AS fam'.
312
-                    ' FROM `##families`'.
313
-                    ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'.
314
-                    ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'.
315
-                    ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'.
316
-                    ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'.
317
-                    ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'.
318
-                    ' AND s1.majs_gen = :gen'.
319
-                    ' ORDER BY s1.majs_sosa ASC'
320
-                    )
321
-                    ->execute(array(
322
-                        'tree_id' => $this->tree->getTreeId(),
323
-                        'user_id' => $this->user->getUserId(),
324
-                        'gen' => $gen
325
-                    ))
326
-                    ->fetchAssoc();
327
-            }
328
-            return $this->sosa_fam_list_by_gen[$gen];
329
-        }
330
-        return array();
331
-    }
332
-    
333
-    /**
334
-     * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals.
335
-     *
336
-     * @param number $gen Generation
337
-     * @return array Array of Sosa individuals
338
-     */
339
-    public function getMissingSosaListAtGeneration($gen){
340
-        if(!$this->is_setup) return array();    
341
-        if($gen){
342
-            return $this->sosa_list_by_gen[$gen] = Database::prepare(
343
-                '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'.
344
-                ' FROM `##maj_sosa` schild'.
345
-                ' 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)'.
346
-                ' 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)'.
347
-                ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'.
348
-                ' AND schild.majs_gen = :gen'.
349
-                ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'.
350
-                ' ORDER BY schild.majs_sosa ASC')
351
-                ->execute(array(
352
-                    'tree_id' => $this->tree->getTreeId(),
353
-                    'user_id' => $this->user->getUserId(),
354
-                    'gen' => $gen - 1
355
-                ))->fetchAll(\PDO::FETCH_ASSOC);
356
-        }
357
-        return array();
358
-    }
359
-    
360
-    
361
-    
362
-    /*************
308
+		if($gen){
309
+			if(!isset($this->sosa_fam_list_by_gen[$gen])){
310
+				$this->sosa_fam_list_by_gen[$gen] = Database::prepare(
311
+					'SELECT s1.majs_sosa AS sosa, f_id AS fam'.
312
+					' FROM `##families`'.
313
+					' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'.
314
+					' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'.
315
+					' WHERE s1.majs_sosa + 1 = s2.majs_sosa'.
316
+					' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'.
317
+					' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'.
318
+					' AND s1.majs_gen = :gen'.
319
+					' ORDER BY s1.majs_sosa ASC'
320
+					)
321
+					->execute(array(
322
+						'tree_id' => $this->tree->getTreeId(),
323
+						'user_id' => $this->user->getUserId(),
324
+						'gen' => $gen
325
+					))
326
+					->fetchAssoc();
327
+			}
328
+			return $this->sosa_fam_list_by_gen[$gen];
329
+		}
330
+		return array();
331
+	}
332
+    
333
+	/**
334
+	 * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals.
335
+	 *
336
+	 * @param number $gen Generation
337
+	 * @return array Array of Sosa individuals
338
+	 */
339
+	public function getMissingSosaListAtGeneration($gen){
340
+		if(!$this->is_setup) return array();    
341
+		if($gen){
342
+			return $this->sosa_list_by_gen[$gen] = Database::prepare(
343
+				'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'.
344
+				' FROM `##maj_sosa` schild'.
345
+				' 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)'.
346
+				' 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)'.
347
+				' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'.
348
+				' AND schild.majs_gen = :gen'.
349
+				' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'.
350
+				' ORDER BY schild.majs_sosa ASC')
351
+				->execute(array(
352
+					'tree_id' => $this->tree->getTreeId(),
353
+					'user_id' => $this->user->getUserId(),
354
+					'gen' => $gen - 1
355
+				))->fetchAll(\PDO::FETCH_ASSOC);
356
+		}
357
+		return array();
358
+	}
359
+    
360
+    
361
+    
362
+	/*************
363 363
      * STATISTICS
364 364
      *************/
365
-    /**
366
-     * Get the statistic array detailed by generation.
367
-     * Statistics for each generation are:
368
-     * 	- The number of Sosa in generation
369
-     * 	- The number of Sosa up to generation
370
-     *  - The number of distinct Sosa up to generation
371
-     *  - The year of the first birth in generation
372
-     *  - The year of the last birth in generation
373
-     *  - The average year of birth in generation
374
-     *
375
-     * @return array Statistics array
376
-     */
377
-    public function getStatisticsByGeneration() {
378
-        if(!$this->is_setup) return array();
379
-        if(!$this->statistics_tab) {
380
-            $this->statistics_tab = array();
381
-            if($maxGeneration = $this->getLastGeneration()) {
382
-                for ($gen = 1; $gen <= $maxGeneration; $gen++) {
383
-                    $birthStats = $this->getStatsBirthYearInGeneration($gen);
384
-                    $this->statistics_tab[$gen] = array(
385
-                        'sosaCount'				=>	$this->getSosaCountAtGeneration($gen),
386
-                        'sosaTotalCount'		=>	$this->getSosaCountUpToGeneration($gen),
387
-                        'diffSosaTotalCount'	=>	$this->getDifferentSosaCountUpToGeneration($gen),
388
-                        'firstBirth'			=>	$birthStats['first'],
389
-                        'lastBirth'				=>	$birthStats['last'],
390
-                        'avgBirth'				=>	$birthStats['avg']
391
-                    );
392
-                }
393
-            }
394
-        }
395
-        return $this->statistics_tab;        
396
-    }
365
+	/**
366
+	 * Get the statistic array detailed by generation.
367
+	 * Statistics for each generation are:
368
+	 * 	- The number of Sosa in generation
369
+	 * 	- The number of Sosa up to generation
370
+	 *  - The number of distinct Sosa up to generation
371
+	 *  - The year of the first birth in generation
372
+	 *  - The year of the last birth in generation
373
+	 *  - The average year of birth in generation
374
+	 *
375
+	 * @return array Statistics array
376
+	 */
377
+	public function getStatisticsByGeneration() {
378
+		if(!$this->is_setup) return array();
379
+		if(!$this->statistics_tab) {
380
+			$this->statistics_tab = array();
381
+			if($maxGeneration = $this->getLastGeneration()) {
382
+				for ($gen = 1; $gen <= $maxGeneration; $gen++) {
383
+					$birthStats = $this->getStatsBirthYearInGeneration($gen);
384
+					$this->statistics_tab[$gen] = array(
385
+						'sosaCount'				=>	$this->getSosaCountAtGeneration($gen),
386
+						'sosaTotalCount'		=>	$this->getSosaCountUpToGeneration($gen),
387
+						'diffSosaTotalCount'	=>	$this->getDifferentSosaCountUpToGeneration($gen),
388
+						'firstBirth'			=>	$birthStats['first'],
389
+						'lastBirth'				=>	$birthStats['last'],
390
+						'avgBirth'				=>	$birthStats['avg']
391
+					);
392
+				}
393
+			}
394
+		}
395
+		return $this->statistics_tab;        
396
+	}
397 397
     
398 398
 	/**
399 399
 	 * How many individuals exist in the tree.
@@ -401,205 +401,205 @@  discard block
 block discarded – undo
401 401
 	 * @return int
402 402
 	 */
403 403
 	public function getTotalIndividuals() {
404
-	    if(!$this->is_setup) return 0;
405
-	    return Database::prepare(
406
-	        'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' .
407
-	        ' WHERE i_file = :tree_id')
408
-	        ->execute(array('tree_id' => $this->tree->getTreeId()))
409
-	        ->fetchOne() ?: 0;
404
+		if(!$this->is_setup) return 0;
405
+		return Database::prepare(
406
+			'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' .
407
+			' WHERE i_file = :tree_id')
408
+			->execute(array('tree_id' => $this->tree->getTreeId()))
409
+			->fetchOne() ?: 0;
410 410
 	}
411 411
     
412
-    /**
413
-     * Get the total Sosa count for all generations
414
-     *
415
-     * @return number Number of Sosas
416
-     */
417
-    public function getSosaCount(){
418
-        if(!$this->is_setup) return 0;
419
-        return Database::prepare(
420
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
421
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
422
-            ->execute(array(
423
-                'tree_id' => $this->tree->getTreeId(), 
424
-                'user_id' => $this->user->getUserId() 
425
-            ))->fetchOne() ?: 0;
426
-    }
427
-    
428
-    /**
429
-     * Get the number of Sosa in a specific generation.
430
-     *
431
-     * @param number $gen Generation
432
-     * @return number Number of Sosas in generation
433
-     */
434
-    public function getSosaCountAtGeneration($gen){
435
-        if(!$this->is_setup) return 0;
436
-        return Database::prepare(
437
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
438
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
439
-            ' AND majs_gen= :gen')
440
-        ->execute(array(
441
-                'tree_id' => $this->tree->getTreeId(), 
442
-                'user_id' => $this->user->getUserId(),
443
-                'gen' => $gen            
444
-        ))->fetchOne() ?: 0;
445
-    }
446
-    
447
-    /**
448
-     * Get the total number of Sosa up to a specific generation.
449
-     *
450
-     * @param number $gen Generation
451
-     * @return number Total number of Sosas up to generation
452
-     */
453
-    public function getSosaCountUpToGeneration($gen){
454
-        if(!$this->is_setup) return 0;
455
-        return Database::prepare(
456
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
457
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
458
-            ' AND majs_gen <= :gen')
459
-        ->execute(array(
460
-                'tree_id' => $this->tree->getTreeId(), 
461
-                'user_id' => $this->user->getUserId(),
462
-                'gen' => $gen 
463
-        ))->fetchOne() ?: 0;
464
-    }
465
-    
466
-    /**
467
-     * Get the total number of distinct Sosa individual for all generations.
468
-     *
469
-     * @return number Total number of distinct individual
470
-     */
471
-    public function getDifferentSosaCount(){
472
-        if(!$this->is_setup) return 0;
473
-        return Database::prepare(
474
-            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
475
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
476
-        ->execute(array(
477
-                'tree_id' => $this->tree->getTreeId(), 
478
-                'user_id' => $this->user->getUserId()
479
-        ))->fetchOne() ?: 0;
480
-    }
481
-    
482
-    /**
483
-     * Get the number of distinct Sosa individual up to a specific generation.
484
-     *
485
-     * @param number $gen Generation
486
-     * @return number Number of distinct Sosa individuals up to generation
487
-     */
488
-    public function getDifferentSosaCountUpToGeneration($gen){
489
-        if(!$this->is_setup) return 0;
490
-        return Database::prepare(
491
-            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
492
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
493
-            ' AND majs_gen <= :gen')
494
-        ->execute(array(
495
-                'tree_id' => $this->tree->getTreeId(), 
496
-                'user_id' => $this->user->getUserId(),
497
-                'gen' => $gen 
498
-        ))->fetchOne() ?: 0;
499
-    }
500
-    
501
-    /**
502
-     * Get an array of birth statistics for a specific generation
503
-     * Statistics are :
504
-     * 	- first : First birth year in generation
505
-     *  - last : Last birth year in generation
506
-     *  - avg : Average birth year
507
-     *
508
-     * @param number $gen Generation
509
-     * @return array Birth statistics array
510
-     */
511
-    public function getStatsBirthYearInGeneration($gen){
512
-        if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
513
-        return Database::prepare(
514
-            'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'.
515
-            ' FROM `##maj_sosa`' .
516
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
517
-            ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year')
518
-            ->execute(array(
519
-                'tree_id' => $this->tree->getTreeId(), 
520
-                'user_id' => $this->user->getUserId(),
521
-                'gen' => $gen,
522
-                'birth_year' => 0))
523
-            ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0);
524
-    }
525
-    
526
-    /**
527
-     * Get the mean generation time, based on a linear regression of birth years and generations
528
-     *
529
-     * @return number|NULL Mean generation time
530
-     */
531
-    public function getMeanGenerationTime(){
532
-        if(!$this->is_setup) return;
533
-        if(!$this->statistics_tab){
534
-            $this->getStatisticsByGeneration();
535
-        }
536
-        //Linear regression on x=generation and y=birthdate
537
-        $sum_xy = 0;
538
-        $sum_x=0;
539
-        $sum_y=0;
540
-        $sum_x2=0;
541
-        $n=count($this->statistics_tab);
542
-        foreach($this->statistics_tab as $gen=>$stats){
543
-            $sum_xy+=$gen*$stats['avgBirth'];
544
-            $sum_x+=$gen;
545
-            $sum_y+=$stats['avgBirth'];
546
-            $sum_x2+=$gen*$gen;
547
-        }
548
-        $denom=($n*$sum_x2)-($sum_x*$sum_x);
549
-        if($denom!=0){
550
-            return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom);
551
-        }
552
-        return null;
553
-    }
554
-    
555
-    /**
556
-     * Return a computed array of statistics about the dispersion of ancestors across the ancestors
557
-     * at a specified generation.
558
-     * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL
559
-     * 
560
-     * Format: 
561
-     *  - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found,
562
-     *          -1 is used for shared ancestors
563
-     *          For instance base2(0100) = base10(4) represent the maternal grand father
564
-     *  - values: number of ancestors exclusively in the ancestors of the ancestor in key
565
-     *  
566
-     *  For instance a result at generation 3 could be :
567
-     *      array (   -1        =>  12      -> 12 ancestors are shared by the grand-parents
568
-     *                base10(1) =>  32      -> 32 ancestors are exclusive to the paternal grand-father
569
-     *                base10(2) =>  25      -> 25 ancestors are exclusive to the paternal grand-mother
570
-     *                base10(4) =>  12      -> 12 ancestors are exclusive to the maternal grand-father
571
-     *                base10(8) =>  30      -> 30 ancestors are exclusive to the maternal grand-mother
572
-     *            )
573
-     *  
574
-     * @param int $gen Reference generation
575
-     * @return array
576
-     */
577
-    public function getAncestorDispersionForGen($gen) {
578
-        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
579
-        return Database::prepare(
580
-            'SELECT branches, count(i_id)'.
581
-            ' FROM ('.
582
-            '   SELECT i_id,'.
583
-            '       CASE'.
584
-            '           WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
585
-            '           ELSE -1'.   // We put all ancestors shared between some branches in the same bucket
586
-            '       END branches'.
587
-            '   FROM ('.
588
-            '       SELECT DISTINCT majs_i_id i_id,'.
589
-            '           POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'.
590
-            '       FROM `##maj_sosa`'.
591
-            '       WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'.
592
-            '           AND majs_gen >= :gen'.
593
-            '   ) indistat'.
594
-            '   GROUP BY i_id'.
595
-            ') grouped'.
596
-            ' GROUP BY branches')
597
-            ->execute(array(
598
-                'tree_id' => $this->tree->getTreeId(), 
599
-                'user_id' => $this->user->getUserId(),
600
-                'gen' => $gen
601
-            ))->fetchAssoc() ?: array();
602
-    }
412
+	/**
413
+	 * Get the total Sosa count for all generations
414
+	 *
415
+	 * @return number Number of Sosas
416
+	 */
417
+	public function getSosaCount(){
418
+		if(!$this->is_setup) return 0;
419
+		return Database::prepare(
420
+			'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
421
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
422
+			->execute(array(
423
+				'tree_id' => $this->tree->getTreeId(), 
424
+				'user_id' => $this->user->getUserId() 
425
+			))->fetchOne() ?: 0;
426
+	}
427
+    
428
+	/**
429
+	 * Get the number of Sosa in a specific generation.
430
+	 *
431
+	 * @param number $gen Generation
432
+	 * @return number Number of Sosas in generation
433
+	 */
434
+	public function getSosaCountAtGeneration($gen){
435
+		if(!$this->is_setup) return 0;
436
+		return Database::prepare(
437
+			'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
438
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
439
+			' AND majs_gen= :gen')
440
+		->execute(array(
441
+				'tree_id' => $this->tree->getTreeId(), 
442
+				'user_id' => $this->user->getUserId(),
443
+				'gen' => $gen            
444
+		))->fetchOne() ?: 0;
445
+	}
446
+    
447
+	/**
448
+	 * Get the total number of Sosa up to a specific generation.
449
+	 *
450
+	 * @param number $gen Generation
451
+	 * @return number Total number of Sosas up to generation
452
+	 */
453
+	public function getSosaCountUpToGeneration($gen){
454
+		if(!$this->is_setup) return 0;
455
+		return Database::prepare(
456
+			'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
457
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
458
+			' AND majs_gen <= :gen')
459
+		->execute(array(
460
+				'tree_id' => $this->tree->getTreeId(), 
461
+				'user_id' => $this->user->getUserId(),
462
+				'gen' => $gen 
463
+		))->fetchOne() ?: 0;
464
+	}
465
+    
466
+	/**
467
+	 * Get the total number of distinct Sosa individual for all generations.
468
+	 *
469
+	 * @return number Total number of distinct individual
470
+	 */
471
+	public function getDifferentSosaCount(){
472
+		if(!$this->is_setup) return 0;
473
+		return Database::prepare(
474
+			'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
475
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
476
+		->execute(array(
477
+				'tree_id' => $this->tree->getTreeId(), 
478
+				'user_id' => $this->user->getUserId()
479
+		))->fetchOne() ?: 0;
480
+	}
481
+    
482
+	/**
483
+	 * Get the number of distinct Sosa individual up to a specific generation.
484
+	 *
485
+	 * @param number $gen Generation
486
+	 * @return number Number of distinct Sosa individuals up to generation
487
+	 */
488
+	public function getDifferentSosaCountUpToGeneration($gen){
489
+		if(!$this->is_setup) return 0;
490
+		return Database::prepare(
491
+			'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
492
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
493
+			' AND majs_gen <= :gen')
494
+		->execute(array(
495
+				'tree_id' => $this->tree->getTreeId(), 
496
+				'user_id' => $this->user->getUserId(),
497
+				'gen' => $gen 
498
+		))->fetchOne() ?: 0;
499
+	}
500
+    
501
+	/**
502
+	 * Get an array of birth statistics for a specific generation
503
+	 * Statistics are :
504
+	 * 	- first : First birth year in generation
505
+	 *  - last : Last birth year in generation
506
+	 *  - avg : Average birth year
507
+	 *
508
+	 * @param number $gen Generation
509
+	 * @return array Birth statistics array
510
+	 */
511
+	public function getStatsBirthYearInGeneration($gen){
512
+		if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
513
+		return Database::prepare(
514
+			'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'.
515
+			' FROM `##maj_sosa`' .
516
+			' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
517
+			' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year')
518
+			->execute(array(
519
+				'tree_id' => $this->tree->getTreeId(), 
520
+				'user_id' => $this->user->getUserId(),
521
+				'gen' => $gen,
522
+				'birth_year' => 0))
523
+			->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0);
524
+	}
525
+    
526
+	/**
527
+	 * Get the mean generation time, based on a linear regression of birth years and generations
528
+	 *
529
+	 * @return number|NULL Mean generation time
530
+	 */
531
+	public function getMeanGenerationTime(){
532
+		if(!$this->is_setup) return;
533
+		if(!$this->statistics_tab){
534
+			$this->getStatisticsByGeneration();
535
+		}
536
+		//Linear regression on x=generation and y=birthdate
537
+		$sum_xy = 0;
538
+		$sum_x=0;
539
+		$sum_y=0;
540
+		$sum_x2=0;
541
+		$n=count($this->statistics_tab);
542
+		foreach($this->statistics_tab as $gen=>$stats){
543
+			$sum_xy+=$gen*$stats['avgBirth'];
544
+			$sum_x+=$gen;
545
+			$sum_y+=$stats['avgBirth'];
546
+			$sum_x2+=$gen*$gen;
547
+		}
548
+		$denom=($n*$sum_x2)-($sum_x*$sum_x);
549
+		if($denom!=0){
550
+			return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom);
551
+		}
552
+		return null;
553
+	}
554
+    
555
+	/**
556
+	 * Return a computed array of statistics about the dispersion of ancestors across the ancestors
557
+	 * at a specified generation.
558
+	 * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL
559
+	 * 
560
+	 * Format: 
561
+	 *  - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found,
562
+	 *          -1 is used for shared ancestors
563
+	 *          For instance base2(0100) = base10(4) represent the maternal grand father
564
+	 *  - values: number of ancestors exclusively in the ancestors of the ancestor in key
565
+	 *  
566
+	 *  For instance a result at generation 3 could be :
567
+	 *      array (   -1        =>  12      -> 12 ancestors are shared by the grand-parents
568
+	 *                base10(1) =>  32      -> 32 ancestors are exclusive to the paternal grand-father
569
+	 *                base10(2) =>  25      -> 25 ancestors are exclusive to the paternal grand-mother
570
+	 *                base10(4) =>  12      -> 12 ancestors are exclusive to the maternal grand-father
571
+	 *                base10(8) =>  30      -> 30 ancestors are exclusive to the maternal grand-mother
572
+	 *            )
573
+	 *  
574
+	 * @param int $gen Reference generation
575
+	 * @return array
576
+	 */
577
+	public function getAncestorDispersionForGen($gen) {
578
+		if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
579
+		return Database::prepare(
580
+			'SELECT branches, count(i_id)'.
581
+			' FROM ('.
582
+			'   SELECT i_id,'.
583
+			'       CASE'.
584
+			'           WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
585
+			'           ELSE -1'.   // We put all ancestors shared between some branches in the same bucket
586
+			'       END branches'.
587
+			'   FROM ('.
588
+			'       SELECT DISTINCT majs_i_id i_id,'.
589
+			'           POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'.
590
+			'       FROM `##maj_sosa`'.
591
+			'       WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'.
592
+			'           AND majs_gen >= :gen'.
593
+			'   ) indistat'.
594
+			'   GROUP BY i_id'.
595
+			') grouped'.
596
+			' GROUP BY branches')
597
+			->execute(array(
598
+				'tree_id' => $this->tree->getTreeId(), 
599
+				'user_id' => $this->user->getUserId(),
600
+				'gen' => $gen
601
+			))->fetchAssoc() ?: array();
602
+	}
603 603
     
604 604
                
605 605
 }
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 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(!$this->getRootIndi()) {
98
-            if($this->user == self::$default_user) {  // If the default user is not setup
97
+        if (!$this->getRootIndi()) {
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 {
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      * Remove all Sosa entries related to the gedcom file and user
130 130
      */
131 131
     public function deleteAll() {
132
-        if(!$this->is_setup) return;
132
+        if (!$this->is_setup) return;
133 133
         Database::prepare(
134 134
             'DELETE FROM `##maj_sosa`'.
135 135
             ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
@@ -145,12 +145,12 @@  discard block
 block discarded – undo
145 145
      * @param int $sosa
146 146
      */
147 147
     public function deleteAncestors($sosa) {
148
-        if(!$this->is_setup) return;
148
+        if (!$this->is_setup) return;
149 149
         $gen = Functions::getGeneration($sosa);
150 150
         Database::prepare(
151 151
             'DELETE FROM `##maj_sosa`'.
152
-            ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' .
153
-            ' AND majs_gen >= :gen' .
152
+            ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id'.
153
+            ' AND majs_gen >= :gen'.
154 154
             ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa'
155 155
         )->execute(array(
156 156
             'tree_id' => $this->tree->getTreeId(), 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
      * @param array $sosa_records
166 166
      */
167 167
     public function insertOrUpdate($sosa_records) {
168
-        if(!$this->is_setup) return;
168
+        if (!$this->is_setup) return;
169 169
         
170 170
         $treeid = $this->tree->getTreeId();
171 171
         $userid = $this->user->getUserId();
@@ -173,9 +173,9 @@  discard block
 block discarded – undo
173 173
         $values_table = array();
174 174
         
175 175
         $i = 0;
176
-        foreach  ($sosa_records as $row) {
176
+        foreach ($sosa_records as $row) {
177 177
             $gen = Functions::getGeneration($row['sosa']);
178
-            if($gen <= self::MAX_DB_GENERATIONS) {
178
+            if ($gen <= self::MAX_DB_GENERATIONS) {
179 179
                 $questionmarks_table[] = 
180 180
                     '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')';
181 181
                 $values_table = array_merge(
@@ -194,9 +194,9 @@  discard block
 block discarded – undo
194 194
             $i++;
195 195
         }
196 196
         
197
-        $sql = 'REPLACE INTO `##maj_sosa`' .
198
-            ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' .
199
-            ' VALUES '. implode(',', $questionmarks_table);
197
+        $sql = 'REPLACE INTO `##maj_sosa`'.
198
+            ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)'.
199
+            ' VALUES '.implode(',', $questionmarks_table);
200 200
         Database::prepare($sql)->execute($values_table);
201 201
     }
202 202
     
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      * @return array Array of sosa numbers
213 213
      */
214 214
     public function getSosaNumbers(Individual $indi) {
215
-        if(!$this->is_setup) return array();
215
+        if (!$this->is_setup) return array();
216 216
         return Database::prepare(
217 217
                 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
218 218
                 ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
      * @return number Last generation if found, 1 otherwise
230 230
      */
231 231
     public function getLastGeneration() {
232
-        if(!$this->is_setup) return;
232
+        if (!$this->is_setup) return;
233 233
         return Database::prepare(
234 234
                 'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
235 235
                 ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -249,13 +249,13 @@  discard block
 block discarded – undo
249 249
      * @param int $ged_id ID of the gedcom file
250 250
      * @return array Associative array of Sosa ancestors, with their generation, comma separated
251 251
      */
252
-    public function getAllSosaWithGenerations(){
253
-        if(!$this->is_setup) return array();
252
+    public function getAllSosaWithGenerations() {
253
+        if (!$this->is_setup) return array();
254 254
         return Database::prepare(
255
-            'SELECT majs_i_id AS indi,' .
256
-            ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
257
-            ' FROM `##maj_sosa`' .
258
-            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' .
255
+            'SELECT majs_i_id AS indi,'.
256
+            ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations'.
257
+            ' FROM `##maj_sosa`'.
258
+            ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
259 259
             ' GROUP BY majs_i_id'
260 260
         )->execute(array(
261 261
             'tree_id' => $this->tree->getTreeId(),
@@ -269,13 +269,13 @@  discard block
 block discarded – undo
269 269
      * @param number $gen Generation
270 270
      * @return array Array of Sosa individuals
271 271
      */
272
-    public function getSosaListAtGeneration($gen){
273
-        if(!$this->is_setup) return array();
274
-        if(!$this->sosa_list_by_gen)
272
+    public function getSosaListAtGeneration($gen) {
273
+        if (!$this->is_setup) return array();
274
+        if (!$this->sosa_list_by_gen)
275 275
             $this->sosa_list_by_gen = array();
276 276
         
277
-        if($gen){
278
-            if(!isset($this->sosa_list_by_gen[$gen])){
277
+        if ($gen) {
278
+            if (!isset($this->sosa_list_by_gen[$gen])) {
279 279
                 $this->sosa_list_by_gen[$gen] = Database::prepare(
280 280
                     'SELECT majs_sosa AS sosa, majs_i_id AS indi'.
281 281
                     ' FROM `##maj_sosa`'.
@@ -300,13 +300,13 @@  discard block
 block discarded – undo
300 300
      * @param number $gen Generation
301 301
      * @return array Array of Sosa families
302 302
      */
303
-    public function getFamilySosaListAtGeneration($gen){
304
-        if(!$this->is_setup) return array();
305
-        if(!$this->sosa_fam_list_by_gen)
303
+    public function getFamilySosaListAtGeneration($gen) {
304
+        if (!$this->is_setup) return array();
305
+        if (!$this->sosa_fam_list_by_gen)
306 306
             $this->sosa_fam_list_by_gen = array();
307 307
         
308
-        if($gen){
309
-            if(!isset($this->sosa_fam_list_by_gen[$gen])){
308
+        if ($gen) {
309
+            if (!isset($this->sosa_fam_list_by_gen[$gen])) {
310 310
                 $this->sosa_fam_list_by_gen[$gen] = Database::prepare(
311 311
                     'SELECT s1.majs_sosa AS sosa, f_id AS fam'.
312 312
                     ' FROM `##families`'.
@@ -336,9 +336,9 @@  discard block
 block discarded – undo
336 336
      * @param number $gen Generation
337 337
      * @return array Array of Sosa individuals
338 338
      */
339
-    public function getMissingSosaListAtGeneration($gen){
340
-        if(!$this->is_setup) return array();    
341
-        if($gen){
339
+    public function getMissingSosaListAtGeneration($gen) {
340
+        if (!$this->is_setup) return array();    
341
+        if ($gen) {
342 342
             return $this->sosa_list_by_gen[$gen] = Database::prepare(
343 343
                 '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'.
344 344
                 ' FROM `##maj_sosa` schild'.
@@ -375,10 +375,10 @@  discard block
 block discarded – undo
375 375
      * @return array Statistics array
376 376
      */
377 377
     public function getStatisticsByGeneration() {
378
-        if(!$this->is_setup) return array();
379
-        if(!$this->statistics_tab) {
378
+        if (!$this->is_setup) return array();
379
+        if (!$this->statistics_tab) {
380 380
             $this->statistics_tab = array();
381
-            if($maxGeneration = $this->getLastGeneration()) {
381
+            if ($maxGeneration = $this->getLastGeneration()) {
382 382
                 for ($gen = 1; $gen <= $maxGeneration; $gen++) {
383 383
                     $birthStats = $this->getStatsBirthYearInGeneration($gen);
384 384
                     $this->statistics_tab[$gen] = array(
@@ -401,9 +401,9 @@  discard block
 block discarded – undo
401 401
 	 * @return int
402 402
 	 */
403 403
 	public function getTotalIndividuals() {
404
-	    if(!$this->is_setup) return 0;
404
+	    if (!$this->is_setup) return 0;
405 405
 	    return Database::prepare(
406
-	        'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' .
406
+	        'SELECT SQL_CACHE COUNT(*) FROM `##individuals`'.
407 407
 	        ' WHERE i_file = :tree_id')
408 408
 	        ->execute(array('tree_id' => $this->tree->getTreeId()))
409 409
 	        ->fetchOne() ?: 0;
@@ -414,10 +414,10 @@  discard block
 block discarded – undo
414 414
      *
415 415
      * @return number Number of Sosas
416 416
      */
417
-    public function getSosaCount(){
418
-        if(!$this->is_setup) return 0;
417
+    public function getSosaCount() {
418
+        if (!$this->is_setup) return 0;
419 419
         return Database::prepare(
420
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
420
+            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'.
421 421
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
422 422
             ->execute(array(
423 423
                 'tree_id' => $this->tree->getTreeId(), 
@@ -431,10 +431,10 @@  discard block
 block discarded – undo
431 431
      * @param number $gen Generation
432 432
      * @return number Number of Sosas in generation
433 433
      */
434
-    public function getSosaCountAtGeneration($gen){
435
-        if(!$this->is_setup) return 0;
434
+    public function getSosaCountAtGeneration($gen) {
435
+        if (!$this->is_setup) return 0;
436 436
         return Database::prepare(
437
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
437
+            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'.
438 438
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
439 439
             ' AND majs_gen= :gen')
440 440
         ->execute(array(
@@ -450,10 +450,10 @@  discard block
 block discarded – undo
450 450
      * @param number $gen Generation
451 451
      * @return number Total number of Sosas up to generation
452 452
      */
453
-    public function getSosaCountUpToGeneration($gen){
454
-        if(!$this->is_setup) return 0;
453
+    public function getSosaCountUpToGeneration($gen) {
454
+        if (!$this->is_setup) return 0;
455 455
         return Database::prepare(
456
-            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
456
+            'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'.
457 457
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
458 458
             ' AND majs_gen <= :gen')
459 459
         ->execute(array(
@@ -468,10 +468,10 @@  discard block
 block discarded – undo
468 468
      *
469 469
      * @return number Total number of distinct individual
470 470
      */
471
-    public function getDifferentSosaCount(){
472
-        if(!$this->is_setup) return 0;
471
+    public function getDifferentSosaCount() {
472
+        if (!$this->is_setup) return 0;
473 473
         return Database::prepare(
474
-            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
474
+            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'.
475 475
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
476 476
         ->execute(array(
477 477
                 'tree_id' => $this->tree->getTreeId(), 
@@ -485,10 +485,10 @@  discard block
 block discarded – undo
485 485
      * @param number $gen Generation
486 486
      * @return number Number of distinct Sosa individuals up to generation
487 487
      */
488
-    public function getDifferentSosaCountUpToGeneration($gen){
489
-        if(!$this->is_setup) return 0;
488
+    public function getDifferentSosaCountUpToGeneration($gen) {
489
+        if (!$this->is_setup) return 0;
490 490
         return Database::prepare(
491
-            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
491
+            'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'.
492 492
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
493 493
             ' AND majs_gen <= :gen')
494 494
         ->execute(array(
@@ -508,11 +508,11 @@  discard block
 block discarded – undo
508 508
      * @param number $gen Generation
509 509
      * @return array Birth statistics array
510 510
      */
511
-    public function getStatsBirthYearInGeneration($gen){
512
-        if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
511
+    public function getStatsBirthYearInGeneration($gen) {
512
+        if (!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
513 513
         return Database::prepare(
514 514
             'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'.
515
-            ' FROM `##maj_sosa`' .
515
+            ' FROM `##maj_sosa`'.
516 516
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
517 517
             ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year')
518 518
             ->execute(array(
@@ -528,26 +528,26 @@  discard block
 block discarded – undo
528 528
      *
529 529
      * @return number|NULL Mean generation time
530 530
      */
531
-    public function getMeanGenerationTime(){
532
-        if(!$this->is_setup) return;
533
-        if(!$this->statistics_tab){
531
+    public function getMeanGenerationTime() {
532
+        if (!$this->is_setup) return;
533
+        if (!$this->statistics_tab) {
534 534
             $this->getStatisticsByGeneration();
535 535
         }
536 536
         //Linear regression on x=generation and y=birthdate
537 537
         $sum_xy = 0;
538
-        $sum_x=0;
539
-        $sum_y=0;
540
-        $sum_x2=0;
541
-        $n=count($this->statistics_tab);
542
-        foreach($this->statistics_tab as $gen=>$stats){
543
-            $sum_xy+=$gen*$stats['avgBirth'];
544
-            $sum_x+=$gen;
545
-            $sum_y+=$stats['avgBirth'];
546
-            $sum_x2+=$gen*$gen;
538
+        $sum_x = 0;
539
+        $sum_y = 0;
540
+        $sum_x2 = 0;
541
+        $n = count($this->statistics_tab);
542
+        foreach ($this->statistics_tab as $gen=>$stats) {
543
+            $sum_xy += $gen * $stats['avgBirth'];
544
+            $sum_x += $gen;
545
+            $sum_y += $stats['avgBirth'];
546
+            $sum_x2 += $gen * $gen;
547 547
         }
548
-        $denom=($n*$sum_x2)-($sum_x*$sum_x);
549
-        if($denom!=0){
550
-            return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom);
548
+        $denom = ($n * $sum_x2) - ($sum_x * $sum_x);
549
+        if ($denom != 0) {
550
+            return -(($n * $sum_xy) - ($sum_x * $sum_y)) / ($denom);
551 551
         }
552 552
         return null;
553 553
     }
@@ -575,14 +575,14 @@  discard block
 block discarded – undo
575 575
      * @return array
576 576
      */
577 577
     public function getAncestorDispersionForGen($gen) {
578
-        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
578
+        if (!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query
579 579
         return Database::prepare(
580 580
             'SELECT branches, count(i_id)'.
581 581
             ' FROM ('.
582 582
             '   SELECT i_id,'.
583 583
             '       CASE'.
584 584
             '           WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'.
585
-            '           ELSE -1'.   // We put all ancestors shared between some branches in the same bucket
585
+            '           ELSE -1'.// We put all ancestors shared between some branches in the same bucket
586 586
             '       END branches'.
587 587
             '   FROM ('.
588 588
             '       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(!$this->getRootIndi()) {
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->getRootIndi() === null;
104 108
             }            
@@ -129,7 +133,9 @@  discard block
 block discarded – undo
129 133
      * Remove all Sosa entries related to the gedcom file and user
130 134
      */
131 135
     public function deleteAll() {
132
-        if(!$this->is_setup) return;
136
+        if(!$this->is_setup) {
137
+        	return;
138
+        }
133 139
         Database::prepare(
134 140
             'DELETE FROM `##maj_sosa`'.
135 141
             ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ')
@@ -145,7 +151,9 @@  discard block
 block discarded – undo
145 151
      * @param int $sosa
146 152
      */
147 153
     public function deleteAncestors($sosa) {
148
-        if(!$this->is_setup) return;
154
+        if(!$this->is_setup) {
155
+        	return;
156
+        }
149 157
         $gen = Functions::getGeneration($sosa);
150 158
         Database::prepare(
151 159
             'DELETE FROM `##maj_sosa`'.
@@ -165,7 +173,9 @@  discard block
 block discarded – undo
165 173
      * @param array $sosa_records
166 174
      */
167 175
     public function insertOrUpdate($sosa_records) {
168
-        if(!$this->is_setup) return;
176
+        if(!$this->is_setup) {
177
+        	return;
178
+        }
169 179
         
170 180
         $treeid = $this->tree->getTreeId();
171 181
         $userid = $this->user->getUserId();
@@ -212,7 +222,9 @@  discard block
 block discarded – undo
212 222
      * @return array Array of sosa numbers
213 223
      */
214 224
     public function getSosaNumbers(Individual $indi) {
215
-        if(!$this->is_setup) return array();
225
+        if(!$this->is_setup) {
226
+        	return array();
227
+        }
216 228
         return Database::prepare(
217 229
                 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'.
218 230
                 ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -229,7 +241,9 @@  discard block
 block discarded – undo
229 241
      * @return number Last generation if found, 1 otherwise
230 242
      */
231 243
     public function getLastGeneration() {
232
-        if(!$this->is_setup) return;
244
+        if(!$this->is_setup) {
245
+        	return;
246
+        }
233 247
         return Database::prepare(
234 248
                 'SELECT MAX(majs_gen) FROM `##maj_sosa`'.
235 249
                 ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'
@@ -250,7 +264,9 @@  discard block
 block discarded – undo
250 264
      * @return array Associative array of Sosa ancestors, with their generation, comma separated
251 265
      */
252 266
     public function getAllSosaWithGenerations(){
253
-        if(!$this->is_setup) return array();
267
+        if(!$this->is_setup) {
268
+        	return array();
269
+        }
254 270
         return Database::prepare(
255 271
             'SELECT majs_i_id AS indi,' .
256 272
             ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' .
@@ -270,9 +286,12 @@  discard block
 block discarded – undo
270 286
      * @return array Array of Sosa individuals
271 287
      */
272 288
     public function getSosaListAtGeneration($gen){
273
-        if(!$this->is_setup) return array();
274
-        if(!$this->sosa_list_by_gen)
275
-            $this->sosa_list_by_gen = array();
289
+        if(!$this->is_setup) {
290
+        	return array();
291
+        }
292
+        if(!$this->sosa_list_by_gen) {
293
+                    $this->sosa_list_by_gen = array();
294
+        }
276 295
         
277 296
         if($gen){
278 297
             if(!isset($this->sosa_list_by_gen[$gen])){
@@ -301,9 +320,12 @@  discard block
 block discarded – undo
301 320
      * @return array Array of Sosa families
302 321
      */
303 322
     public function getFamilySosaListAtGeneration($gen){
304
-        if(!$this->is_setup) return array();
305
-        if(!$this->sosa_fam_list_by_gen)
306
-            $this->sosa_fam_list_by_gen = array();
323
+        if(!$this->is_setup) {
324
+        	return array();
325
+        }
326
+        if(!$this->sosa_fam_list_by_gen) {
327
+                    $this->sosa_fam_list_by_gen = array();
328
+        }
307 329
         
308 330
         if($gen){
309 331
             if(!isset($this->sosa_fam_list_by_gen[$gen])){
@@ -337,7 +359,9 @@  discard block
 block discarded – undo
337 359
      * @return array Array of Sosa individuals
338 360
      */
339 361
     public function getMissingSosaListAtGeneration($gen){
340
-        if(!$this->is_setup) return array();    
362
+        if(!$this->is_setup) {
363
+        	return array();
364
+        }
341 365
         if($gen){
342 366
             return $this->sosa_list_by_gen[$gen] = Database::prepare(
343 367
                 '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'.
@@ -375,7 +399,9 @@  discard block
 block discarded – undo
375 399
      * @return array Statistics array
376 400
      */
377 401
     public function getStatisticsByGeneration() {
378
-        if(!$this->is_setup) return array();
402
+        if(!$this->is_setup) {
403
+        	return array();
404
+        }
379 405
         if(!$this->statistics_tab) {
380 406
             $this->statistics_tab = array();
381 407
             if($maxGeneration = $this->getLastGeneration()) {
@@ -401,7 +427,9 @@  discard block
 block discarded – undo
401 427
 	 * @return int
402 428
 	 */
403 429
 	public function getTotalIndividuals() {
404
-	    if(!$this->is_setup) return 0;
430
+	    if(!$this->is_setup) {
431
+	    	return 0;
432
+	    }
405 433
 	    return Database::prepare(
406 434
 	        'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' .
407 435
 	        ' WHERE i_file = :tree_id')
@@ -415,7 +443,9 @@  discard block
 block discarded – undo
415 443
      * @return number Number of Sosas
416 444
      */
417 445
     public function getSosaCount(){
418
-        if(!$this->is_setup) return 0;
446
+        if(!$this->is_setup) {
447
+        	return 0;
448
+        }
419 449
         return Database::prepare(
420 450
             'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
421 451
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
@@ -432,7 +462,9 @@  discard block
 block discarded – undo
432 462
      * @return number Number of Sosas in generation
433 463
      */
434 464
     public function getSosaCountAtGeneration($gen){
435
-        if(!$this->is_setup) return 0;
465
+        if(!$this->is_setup) {
466
+        	return 0;
467
+        }
436 468
         return Database::prepare(
437 469
             'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
438 470
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -451,7 +483,9 @@  discard block
 block discarded – undo
451 483
      * @return number Total number of Sosas up to generation
452 484
      */
453 485
     public function getSosaCountUpToGeneration($gen){
454
-        if(!$this->is_setup) return 0;
486
+        if(!$this->is_setup) {
487
+        	return 0;
488
+        }
455 489
         return Database::prepare(
456 490
             'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' .
457 491
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -469,7 +503,9 @@  discard block
 block discarded – undo
469 503
      * @return number Total number of distinct individual
470 504
      */
471 505
     public function getDifferentSosaCount(){
472
-        if(!$this->is_setup) return 0;
506
+        if(!$this->is_setup) {
507
+        	return 0;
508
+        }
473 509
         return Database::prepare(
474 510
             'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
475 511
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id')
@@ -486,7 +522,9 @@  discard block
 block discarded – undo
486 522
      * @return number Number of distinct Sosa individuals up to generation
487 523
      */
488 524
     public function getDifferentSosaCountUpToGeneration($gen){
489
-        if(!$this->is_setup) return 0;
525
+        if(!$this->is_setup) {
526
+        	return 0;
527
+        }
490 528
         return Database::prepare(
491 529
             'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' .
492 530
             ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'.
@@ -509,7 +547,9 @@  discard block
 block discarded – undo
509 547
      * @return array Birth statistics array
510 548
      */
511 549
     public function getStatsBirthYearInGeneration($gen){
512
-        if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0);
550
+        if(!$this->is_setup) {
551
+        	return array('first' => 0, 'avg' => 0, 'last' => 0);
552
+        }
513 553
         return Database::prepare(
514 554
             'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'.
515 555
             ' FROM `##maj_sosa`' .
@@ -529,7 +569,9 @@  discard block
 block discarded – undo
529 569
      * @return number|NULL Mean generation time
530 570
      */
531 571
     public function getMeanGenerationTime(){
532
-        if(!$this->is_setup) return;
572
+        if(!$this->is_setup) {
573
+        	return;
574
+        }
533 575
         if(!$this->statistics_tab){
534 576
             $this->getStatisticsByGeneration();
535 577
         }
@@ -575,7 +617,10 @@  discard block
 block discarded – undo
575 617
      * @return array
576 618
      */
577 619
     public function getAncestorDispersionForGen($gen) {
578
-        if(!$this->is_setup || $gen > 11) return array();  // Going further than 11 gen will be out of range in the query
620
+        if(!$this->is_setup || $gen > 11) {
621
+        	return array();
622
+        }
623
+        // Going further than 11 gen will be out of range in the query
579 624
         return Database::prepare(
580 625
             'SELECT branches, count(i_id)'.
581 626
             ' FROM ('.
Please login to merge, or discard this patch.
src/Webtrees/Mvc/View/ViewBag.php 4 patches
Doc Comments   -1 removed lines patch added patch discarded remove patch
@@ -42,7 +42,6 @@
 block discarded – undo
42 42
      * Get all the data from the bag for a given key.
43 43
      *
44 44
      * @param  string  $key
45
-     * @param  string  $format
46 45
      * @return unknown
47 46
      */
48 47
     public function get($key, $default = null)
Please login to merge, or discard this patch.
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -18,97 +18,97 @@
 block discarded – undo
18 18
 	/**
19 19
 	 * @var array $data Container for data
20 20
 	 */
21
-    protected $data = array();
21
+	protected $data = array();
22 22
     
23
-    /**
24
-     * Constructor for ViewBag
25
-     * @param array $data_in
26
-     */
27
-    public function __construct(array $data_in = array()) {
28
-        $this->data = $data_in;
29
-    }
23
+	/**
24
+	 * Constructor for ViewBag
25
+	 * @param array $data_in
26
+	 */
27
+	public function __construct(array $data_in = array()) {
28
+		$this->data = $data_in;
29
+	}
30 30
     
31
-    /**
32
-     * Get the keys present in the view bag.
33
-     *
34
-     * @return array
35
-     */
36
-    public function keys()
37
-    {
38
-        return array_keys($this->data);
39
-    }
31
+	/**
32
+	 * Get the keys present in the view bag.
33
+	 *
34
+	 * @return array
35
+	 */
36
+	public function keys()
37
+	{
38
+		return array_keys($this->data);
39
+	}
40 40
     
41
-    /**
42
-     * Get all the data from the bag for a given key.
43
-     *
44
-     * @param  string  $key
45
-     * @param  string  $format
46
-     * @return unknown
47
-     */
48
-    public function get($key, $default = null)
49
-    {
50
-        if (array_key_exists($key, $this->data)) {
51
-            return $this->data[$key];
52
-        }
53
-        return $default;
54
-    }
41
+	/**
42
+	 * Get all the data from the bag for a given key.
43
+	 *
44
+	 * @param  string  $key
45
+	 * @param  string  $format
46
+	 * @return unknown
47
+	 */
48
+	public function get($key, $default = null)
49
+	{
50
+		if (array_key_exists($key, $this->data)) {
51
+			return $this->data[$key];
52
+		}
53
+		return $default;
54
+	}
55 55
     
56
-    /**
57
-     * Magic getter.
58
-     * Returns the value associated with the key.
59
-     * 
60
-     * @param string $key
61
-     * @return unknown
62
-     */
63
-    public function __get($key) {
64
-        return $this->get($key, null);
65
-    }
56
+	/**
57
+	 * Magic getter.
58
+	 * Returns the value associated with the key.
59
+	 * 
60
+	 * @param string $key
61
+	 * @return unknown
62
+	 */
63
+	public function __get($key) {
64
+		return $this->get($key, null);
65
+	}
66 66
     
67
-    /**
68
-     * Set the value for the specified key.
69
-     * Can define whether to override an existing value;
70
-     * 
71
-     * @param string $key
72
-     * @param unknown $value
73
-     * @param bool $override
74
-     */
75
-    public function set($key, $value, $override = true) {
76
-        if(is_null($key)) return;
77
-        if(!$override && array_key_exists($key, $this->data)) return;
78
-        $this->data[$key] = $value;        
79
-    }
67
+	/**
68
+	 * Set the value for the specified key.
69
+	 * Can define whether to override an existing value;
70
+	 * 
71
+	 * @param string $key
72
+	 * @param unknown $value
73
+	 * @param bool $override
74
+	 */
75
+	public function set($key, $value, $override = true) {
76
+		if(is_null($key)) return;
77
+		if(!$override && array_key_exists($key, $this->data)) return;
78
+		$this->data[$key] = $value;        
79
+	}
80 80
     
81
-    /**
82
-     * Magic setter.
83
-     * Set the value for the specified key.
84
-     * 
85
-     * @param string $key
86
-     * @param unknown $value
87
-     */
88
-    public function __set($key, $value) {
89
-        $this->set($key, $value);
90
-    }
81
+	/**
82
+	 * Magic setter.
83
+	 * Set the value for the specified key.
84
+	 * 
85
+	 * @param string $key
86
+	 * @param unknown $value
87
+	 */
88
+	public function __set($key, $value) {
89
+		$this->set($key, $value);
90
+	}
91 91
     
92
-    /**
93
-     * Magic isset
94
-     * Checks whether the ViewBag contains the specified key
95
-     * 
96
-     * @param string $key
97
-     * @return bool
98
-     */
99
-    public function __isset($key) {
100
-        return isset($this->data[$key]);
101
-    }
92
+	/**
93
+	 * Magic isset
94
+	 * Checks whether the ViewBag contains the specified key
95
+	 * 
96
+	 * @param string $key
97
+	 * @return bool
98
+	 */
99
+	public function __isset($key) {
100
+		return isset($this->data[$key]);
101
+	}
102 102
     
103
-    /**
104
-     * Magic unset
105
-     * Unset the specified key from the ViewBag
106
-     * 
107
-     * @param string $key
108
-     */
109
-    public function __unset($key) {
110
-        unset($this->data[$key]);;
111
-    }
103
+	/**
104
+	 * Magic unset
105
+	 * Unset the specified key from the ViewBag
106
+	 * 
107
+	 * @param string $key
108
+	 */
109
+	public function __unset($key) {
110
+		unset($this->data[$key]);;
111
+	}
112 112
     
113 113
 }
114 114
  
115 115
\ 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
@@ -73,8 +73,8 @@  discard block
 block discarded – undo
73 73
      * @param bool $override
74 74
      */
75 75
     public function set($key, $value, $override = true) {
76
-        if(is_null($key)) return;
77
-        if(!$override && array_key_exists($key, $this->data)) return;
76
+        if (is_null($key)) return;
77
+        if (!$override && array_key_exists($key, $this->data)) return;
78 78
         $this->data[$key] = $value;        
79 79
     }
80 80
     
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @param string $key
108 108
      */
109 109
     public function __unset($key) {
110
-        unset($this->data[$key]);;
110
+        unset($this->data[$key]); ;
111 111
     }
112 112
     
113 113
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -73,8 +73,12 @@
 block discarded – undo
73 73
      * @param bool $override
74 74
      */
75 75
     public function set($key, $value, $override = true) {
76
-        if(is_null($key)) return;
77
-        if(!$override && array_key_exists($key, $this->data)) return;
76
+        if(is_null($key)) {
77
+        	return;
78
+        }
79
+        if(!$override && array_key_exists($key, $this->data)) {
80
+        	return;
81
+        }
78 82
         $this->data[$key] = $value;        
79 83
     }
80 84
     
Please login to merge, or discard this patch.
src/Webtrees/Place.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
 	/**
27 27
 	 * Contructor for the decorator
28 28
 	 *
29
-	 * @param \Fisharebest\Webtrees\Place $place_in The Place to extend
29
+	 * @param \Fisharebest\Webtrees\Place $place The Place to extend
30 30
 	 */
31 31
 	public function __construct(\Fisharebest\Webtrees\Place $place){
32 32
 		$this->_place = $place;
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -28,7 +28,7 @@  discard block
 block discarded – undo
28 28
 	 *
29 29
 	 * @param \Fisharebest\Webtrees\Place $place_in The Place to extend
30 30
 	 */
31
-	public function __construct(\Fisharebest\Webtrees\Place $place){
31
+	public function __construct(\Fisharebest\Webtrees\Place $place) {
32 32
 		$this->_place = $place;
33 33
 	}
34 34
 
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 	 * @param \Fisharebest\Webtrees\Tree $tree
41 41
 	 * @return \MyArtJaub\Webtrees\Place|null Instance of \MyArtJaub\Webtrees\Place, if relevant
42 42
 	 */
43
-	public static function getIntance($place_str, Tree $tree){
43
+	public static function getIntance($place_str, Tree $tree) {
44 44
 		$dplace = null;
45
-		if(is_string($place_str) && strlen($place_str) > 0){
45
+		if (is_string($place_str) && strlen($place_str) > 0) {
46 46
 			$dplace = new Place(new \Fisharebest\Webtrees\Place($place_str, $tree));
47 47
 		}
48 48
 		return $dplace;
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @return \Fisharebest\Webtrees\Place Embedded place record
55 55
 	 */
56
-	public function getDerivedPlace(){
56
+	public function getDerivedPlace() {
57 57
 		return $this->_place;
58 58
 	}
59 59
 	
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
 	 * @param bool $anchor Option to print a link to placelist
67 67
 	 * @return string HTML code for formatted place
68 68
 	 */
69
-	public function htmlFormattedName($format, $anchor = false){		
70
-		$html='';
69
+	public function htmlFormattedName($format, $anchor = false) {		
70
+		$html = '';
71 71
 		
72 72
 		$levels = array_map('trim', explode(',', $this->_place->getGedcomName()));
73 73
 		$nbLevels = count($levels);
@@ -75,15 +75,15 @@  discard block
 block discarded – undo
75 75
 		preg_match_all('/%[^%]/', $displayPlace, $matches);
76 76
 		foreach ($matches[0] as $match2) {
77 77
 			$index = str_replace('%', '', $match2);
78
-			if(is_numeric($index) && $index >0 && $index <= $nbLevels){
79
-				$displayPlace = str_replace($match2, $levels[$index-1] , $displayPlace);
78
+			if (is_numeric($index) && $index > 0 && $index <= $nbLevels) {
79
+				$displayPlace = str_replace($match2, $levels[$index - 1], $displayPlace);
80 80
 			}
81
-			else{
82
-				$displayPlace = str_replace($match2, '' , $displayPlace);
81
+			else {
82
+				$displayPlace = str_replace($match2, '', $displayPlace);
83 83
 			}
84 84
 		}
85 85
 		if ($anchor && !Auth::isSearchEngine()) {
86
-			$html .='<a href="' . $this->_place->getURL() . '">' . $displayPlace . '</a>';
86
+			$html .= '<a href="'.$this->_place->getURL().'">'.$displayPlace.'</a>';
87 87
 		} else {
88 88
 			$html .= $displayPlace;
89 89
 		}
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -77,8 +77,7 @@
 block discarded – undo
77 77
 			$index = str_replace('%', '', $match2);
78 78
 			if(is_numeric($index) && $index >0 && $index <= $nbLevels){
79 79
 				$displayPlace = str_replace($match2, $levels[$index-1] , $displayPlace);
80
-			}
81
-			else{
80
+			} else{
82 81
 				$displayPlace = str_replace($match2, '' , $displayPlace);
83 82
 			}
84 83
 		}
Please login to merge, or discard this patch.
phpunit.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,6 +23,6 @@
 block discarded – undo
23 23
 define('WT_REGEX_INTEGER', '-?\d+');
24 24
 define('WT_REGEX_BYTES', '[0-9]+[bBkKmMgG]?');
25 25
 define('WT_REGEX_IPV4', '\d{1,3}(\.\d{1,3}){3}');
26
-define('WT_REGEX_PASSWORD', '.{' . WT_MINIMUM_PASSWORD_LENGTH . ',}');
26
+define('WT_REGEX_PASSWORD', '.{'.WT_MINIMUM_PASSWORD_LENGTH.',}');
27 27
 
28 28
 I18N::init('en-US');
29 29
\ No newline at end of file
Please login to merge, or discard this patch.
src/Webtrees/Constants.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -14,17 +14,17 @@  discard block
 block discarded – undo
14 14
  */
15 15
 class Constants {
16 16
     
17
-    const LIB_NAMESPACE = __NAMESPACE__;
17
+	const LIB_NAMESPACE = __NAMESPACE__;
18 18
 	
19
-    /** Internal name of the Certificates Module
20
-     * @var string
21
-     */
22
-    const MODULE_MAJ_CERTIF_NAME = 'myartjaub_certificates';
19
+	/** Internal name of the Certificates Module
20
+	 * @var string
21
+	 */
22
+	const MODULE_MAJ_CERTIF_NAME = 'myartjaub_certificates';
23 23
     
24
-    /** Internal name of the GeoDispersion Module
25
-     * @var string
26
-     */
27
-    const MODULE_MAJ_GEODISP_NAME = 'myartjaub_geodispersion';
24
+	/** Internal name of the GeoDispersion Module
25
+	 * @var string
26
+	 */
27
+	const MODULE_MAJ_GEODISP_NAME = 'myartjaub_geodispersion';
28 28
     
29 29
 	/** Internal name of the Hooks Module
30 30
 	 * @var string
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * @return string $WT_RAPHAEL_JS_URL
62 62
 	 */
63 63
 	public static function WT_RAPHAEL_JS_URL() {
64
-	    return WT_STATIC_URL . 'packages/raphael-2.1.4/raphael-min.js';
64
+		return WT_STATIC_URL . 'packages/raphael-2.1.4/raphael-min.js';
65 65
 	}
66 66
 		
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
 	 * @return string $WT_RAPHAEL_JS_URL
62 62
 	 */
63 63
 	public static function WT_RAPHAEL_JS_URL() {
64
-	    return WT_STATIC_URL . 'packages/raphael-2.1.4/raphael-min.js';
64
+	    return WT_STATIC_URL.'packages/raphael-2.1.4/raphael-min.js';
65 65
 	}
66 66
 		
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
src/Webtrees/Map/GoogleMapsProvider.php 2 patches
Braces   +7 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,11 +30,16 @@
 block discarded – undo
30 30
 			$place_id = 0;
31 31
 			for ($i=0; $i<count($parent); $i++) {
32 32
 				$parent[$i] = trim($parent[$i]);
33
-				if (empty($parent[$i])) $parent[$i]='unknown';// GoogleMap module uses "unknown" while GEDCOM uses , ,
33
+				if (empty($parent[$i])) {
34
+					$parent[$i]='unknown';
35
+				}
36
+				// GoogleMap module uses "unknown" while GEDCOM uses , ,
34 37
 				$pl_id=Database::prepare('SELECT pl_id FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place')
35 38
 					->execute(array($i, $place_id, $parent[$i]))
36 39
 					->fetchOne();
37
-				if (empty($pl_id)) break;
40
+				if (empty($pl_id)) {
41
+					break;
42
+				}
38 43
 				$place_id = $pl_id;
39 44
 			}
40 45
 			return $place_id;
Please login to merge, or discard this patch.
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 = explode (',', $place->getGedcomName());
28
+		if (!$place->isEmpty()) {
29
+			$parent = 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.
src/Webtrees/Module/IsSourcedModule.php 3 patches
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtender::hExtendIndiHeaderIcons()
62 62
 	 */
63 63
 	public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) {
64
-	    if($ctrlIndi){
64
+	    if ($ctrlIndi) {
65 65
 	        $dindi = new Individual($ctrlIndi->getSignificantIndividual());
66 66
 	        if ($dindi->canDisplayIsSourced()) 
67 67
 	            return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large');
@@ -85,19 +85,19 @@  discard block
 block discarded – undo
85 85
 	 * {@inheritDoc}
86 86
 	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtender::hRecordNamePrepend()
87 87
 	 */
88
-	public function hRecordNamePrepend(GedcomRecord $grec){ }
88
+	public function hRecordNamePrepend(GedcomRecord $grec) { }
89 89
 	
90 90
 	/**
91 91
 	 * {@inheritDoc}
92 92
 	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtender::hRecordNameAppend()
93 93
 	 */
94
-	public function hRecordNameAppend(GedcomRecord $grec){
94
+	public function hRecordNameAppend(GedcomRecord $grec) {
95 95
 	    $html = '';
96
-	    if($grec instanceof \Fisharebest\Webtrees\Individual){
96
+	    if ($grec instanceof \Fisharebest\Webtrees\Individual) {
97 97
 	        $dindi = new Individual($grec);
98 98
 	        $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small');
99 99
 	        $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small');
100
-	        if($grec->isDead())
100
+	        if ($grec->isDead())
101 101
 	            $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small');
102 102
 	    }
103 103
 	    return $html;
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 	 * {@inheritDoc}
116 116
 	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
117 117
 	 */
118
-	public function hasSidebarContent(){ 
118
+	public function hasSidebarContent() { 
119 119
 	    return true;
120 120
 	}
121 121
 	
@@ -145,24 +145,24 @@  discard block
 block discarded – undo
145 145
 	            echo '
146 146
 	                <table class="issourcedtable">
147 147
 	                   <tr>
148
-	                       <td class="slabel"> ' . GedcomTag::getLabel('INDI') . '</td>
148
+	                       <td class="slabel"> ' . GedcomTag::getLabel('INDI').'</td>
149 149
 	                       <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1).'</td>
150 150
 	                   </tr>
151 151
 	                   <tr>
152
-	                       <td class="slabel">' . GedcomTag::getLabel('BIRT') . '</td>
152
+	                       <td class="slabel">' . GedcomTag::getLabel('BIRT').'</td>
153 153
 	                       <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1).'</td>
154 154
 	                   </tr>';
155 155
 	            
156 156
 	            $fams = $root->getSpouseFamilies();
157
-	            ($ct = count($fams)) > 1 ? $nb=1 : $nb=' ';	            
158
-	            foreach($fams as $fam){
157
+	            ($ct = count($fams)) > 1 ? $nb = 1 : $nb = ' ';	            
158
+	            foreach ($fams as $fam) {
159 159
 	                $dfam = new Family($fam);
160 160
 	                echo '
161 161
 	                    <tr>
162 162
 	                       <td class="slabel right">
163
-	                           <a href="' . $fam->getHtmlUrl() . '"> '. GedcomTag::getLabel('MARR');
164
-	                if($ct > 1){
165
-	                    echo ' ',$nb;
163
+	                           <a href="' . $fam->getHtmlUrl().'"> '.GedcomTag::getLabel('MARR');
164
+	                if ($ct > 1) {
165
+	                    echo ' ', $nb;
166 166
 	                    $nb++;
167 167
 	                }
168 168
 	                echo '     </a>
@@ -171,10 +171,10 @@  discard block
 block discarded – undo
171 171
 	                   </tr>';
172 172
 	            }
173 173
 	            
174
-	            if( $root->isDead() )
174
+	            if ($root->isDead())
175 175
 	                echo '
176 176
 	                    <tr>
177
-	                       <td class="slabel">' . GedcomTag::getLabel('DEAT') . '</td>
177
+	                       <td class="slabel">' . GedcomTag::getLabel('DEAT').'</td>
178 178
 	                       <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1).'</td>
179 179
 	                   </tr>';
180 180
 	            
Please login to merge, or discard this patch.
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -63,8 +63,9 @@  discard block
 block discarded – undo
63 63
 	public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) {
64 64
 	    if($ctrlIndi){
65 65
 	        $dindi = new Individual($ctrlIndi->getSignificantIndividual());
66
-	        if ($dindi->canDisplayIsSourced()) 
67
-	            return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large');
66
+	        if ($dindi->canDisplayIsSourced()) {
67
+	        	            return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large');
68
+	        }
68 69
 	    }
69 70
 	    return '';
70 71
 	}
@@ -97,8 +98,9 @@  discard block
 block discarded – undo
97 98
 	        $dindi = new Individual($grec);
98 99
 	        $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small');
99 100
 	        $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small');
100
-	        if($grec->isDead())
101
-	            $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small');
101
+	        if($grec->isDead()) {
102
+	        	            $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small');
103
+	        }
102 104
 	    }
103 105
 	    return $html;
104 106
 	}
@@ -171,12 +173,13 @@  discard block
 block discarded – undo
171 173
 	                   </tr>';
172 174
 	            }
173 175
 	            
174
-	            if( $root->isDead() )
175
-	                echo '
176
+	            if( $root->isDead() ) {
177
+	            	                echo '
176 178
 	                    <tr>
177 179
 	                       <td class="slabel">' . GedcomTag::getLabel('DEAT') . '</td>
178 180
 	                       <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1).'</td>
179 181
 	                   </tr>';
182
+	            }
180 183
 	            
181 184
 	            echo '</table>';
182 185
 	        }
Please login to merge, or discard this patch.
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -28,29 +28,29 @@  discard block
 block discarded – undo
28 28
 class IsSourcedModule extends AbstractModule 
29 29
 implements ModuleSidebarInterface, HookSubscriberInterface, IndividualHeaderExtenderInterface, RecordNameTextExtenderInterface
30 30
 {
31
-    /** @var string For custom modules - link for support, upgrades, etc. */
32
-    const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib';
31
+	/** @var string For custom modules - link for support, upgrades, etc. */
32
+	const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib';
33 33
     
34
-    /**
35
-     * {@inheritDoc}
36
-     * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle()
37
-     */
38
-    public function getTitle() {
39
-        return I18N::translate('Sourced events');
40
-    }
34
+	/**
35
+	 * {@inheritDoc}
36
+	 * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle()
37
+	 */
38
+	public function getTitle() {
39
+		return I18N::translate('Sourced events');
40
+	}
41 41
     
42 42
    /**
43 43
     * {@inheritDoc}
44 44
     * @see \Fisharebest\Webtrees\Module\AbstractModule::getDescription()
45 45
     */
46
-    public function getDescription() {
47
-        return I18N::translate('Indicate if events related to an record are sourced.');
48
-    }
46
+	public function getDescription() {
47
+		return I18N::translate('Indicate if events related to an record are sourced.');
48
+	}
49 49
     
50
-    /**
51
-     * {@inheritDoc}
52
-     * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks()
53
-     */
50
+	/**
51
+	 * {@inheritDoc}
52
+	 * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks()
53
+	 */
54 54
 	public function getSubscribedHooks() {
55 55
 		return array(
56 56
  			'hExtendIndiHeaderIcons' => 10,
@@ -63,12 +63,12 @@  discard block
 block discarded – undo
63 63
 	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderIcons()
64 64
 	 */
65 65
 	public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) {
66
-	    if($ctrlIndi){
67
-	        $dindi = new Individual($ctrlIndi->getSignificantIndividual());
68
-	        if ($dindi->canDisplayIsSourced()) 
69
-	            return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large');
70
-	    }
71
-	    return '';
66
+		if($ctrlIndi){
67
+			$dindi = new Individual($ctrlIndi->getSignificantIndividual());
68
+			if ($dindi->canDisplayIsSourced()) 
69
+				return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large');
70
+		}
71
+		return '';
72 72
 	}
73 73
 	
74 74
 	/**
@@ -94,15 +94,15 @@  discard block
 block discarded – undo
94 94
 	 * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtenderInterface::hRecordNameAppend()
95 95
 	 */
96 96
 	public function hRecordNameAppend(GedcomRecord $grec){
97
-	    $html = '';
98
-	    if($grec instanceof \Fisharebest\Webtrees\Individual){
99
-	        $dindi = new Individual($grec);
100
-	        $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small');
101
-	        $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small');
102
-	        if($grec->isDead())
103
-	            $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small');
104
-	    }
105
-	    return $html;
97
+		$html = '';
98
+		if($grec instanceof \Fisharebest\Webtrees\Individual){
99
+			$dindi = new Individual($grec);
100
+			$html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small');
101
+			$html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small');
102
+			if($grec->isDead())
103
+				$html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small');
104
+		}
105
+		return $html;
106 106
 	}
107 107
 	
108 108
 	/**
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder()
111 111
 	 */
112 112
 	public function defaultSidebarOrder() {
113
-	    return 15;
113
+		return 15;
114 114
 	}
115 115
 	
116 116
 	/**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent()
119 119
 	 */
120 120
 	public function hasSidebarContent(){ 
121
-	    return true;
121
+		return true;
122 122
 	}
123 123
 	
124 124
 	/**
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
 	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarAjaxContent()
127 127
 	 */
128 128
 	public function getSidebarAjaxContent() {
129
-	    return '';
129
+		return '';
130 130
 	}
131 131
 	
132 132
 	/**
@@ -134,17 +134,17 @@  discard block
 block discarded – undo
134 134
 	 * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent()
135 135
 	 */
136 136
 	public function getSidebarContent() {
137
-	    global $controller;
137
+		global $controller;
138 138
 	    
139
-	    ob_start();
140
-	    $root = $controller->getSignificantIndividual();
141
-	    if ($root) {
142
-	        $dindi = new Individual($root);
139
+		ob_start();
140
+		$root = $controller->getSignificantIndividual();
141
+		if ($root) {
142
+			$dindi = new Individual($root);
143 143
 	        	
144
-	        if (!$dindi->canDisplayIsSourced()) {
145
-	            echo '<div class="error">', I18N::translate('This information is private and cannot be shown.'), '</div>';
146
-	        } else {
147
-	            echo '
144
+			if (!$dindi->canDisplayIsSourced()) {
145
+				echo '<div class="error">', I18N::translate('This information is private and cannot be shown.'), '</div>';
146
+			} else {
147
+				echo '
148 148
 	                <table class="issourcedtable">
149 149
 	                   <tr>
150 150
 	                       <td class="slabel"> ' . GedcomTag::getLabel('INDI') . '</td>
@@ -155,35 +155,35 @@  discard block
 block discarded – undo
155 155
 	                       <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1).'</td>
156 156
 	                   </tr>';
157 157
 	            
158
-	            $fams = $root->getSpouseFamilies();
159
-	            ($ct = count($fams)) > 1 ? $nb=1 : $nb=' ';	            
160
-	            foreach($fams as $fam){
161
-	                $dfam = new Family($fam);
162
-	                echo '
158
+				$fams = $root->getSpouseFamilies();
159
+				($ct = count($fams)) > 1 ? $nb=1 : $nb=' ';	            
160
+				foreach($fams as $fam){
161
+					$dfam = new Family($fam);
162
+					echo '
163 163
 	                    <tr>
164 164
 	                       <td class="slabel right">
165 165
 	                           <a href="' . $fam->getHtmlUrl() . '"> '. GedcomTag::getLabel('MARR');
166
-	                if($ct > 1){
167
-	                    echo ' ',$nb;
168
-	                    $nb++;
169
-	                }
170
-	                echo '     </a>
166
+					if($ct > 1){
167
+						echo ' ',$nb;
168
+						$nb++;
169
+					}
170
+					echo '     </a>
171 171
 	                       </td>
172 172
 	                       <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dfam->isMarriageSourced(), 'MARR', 1).'</td>
173 173
 	                   </tr>';
174
-	            }
174
+				}
175 175
 	            
176
-	            if( $root->isDead() )
177
-	                echo '
176
+				if( $root->isDead() )
177
+					echo '
178 178
 	                    <tr>
179 179
 	                       <td class="slabel">' . GedcomTag::getLabel('DEAT') . '</td>
180 180
 	                       <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1).'</td>
181 181
 	                   </tr>';
182 182
 	            
183
-	            echo '</table>';
184
-	        }
185
-	    }
186
-	    return ob_get_clean();	    
183
+				echo '</table>';
184
+			}
185
+		}
186
+		return ob_get_clean();	    
187 187
 	}
188 188
 	
189 189
 	
Please login to merge, or discard this patch.