@@ -21,130 +21,130 @@ discard block |
||
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 | - ->setUsingFlags($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 | + ->setUsingFlags($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 |
||
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,236 +217,236 @@ discard block |
||
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 | - $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 | + $nb_levels = 0; |
|
385 | 385 | |
386 | - //Select all '2 PLAC ' tags in the file and create array |
|
387 | - $places_list=array(); |
|
388 | - $ged_data = Database::prepare( |
|
389 | - 'SELECT i_gedcom AS gedcom'. |
|
390 | - ' FROM `##individuals`'. |
|
391 | - ' WHERE i_gedcom LIKE :gedcom AND i_file = :gedcom_id'. |
|
392 | - ' UNION ALL'. |
|
393 | - 'SELECT f_gedcom AS gedcom'. |
|
394 | - ' FROM `##families`'. |
|
395 | - ' WHERE f_gedcom LIKE :gedcom AND f_file = :gedcom_id' |
|
396 | - )->execute(array( |
|
397 | - 'gedcom' => '%\n2 PLAC %', |
|
398 | - 'gedcom_id' => $this->tree->getTreeId() |
|
399 | - ))->fetchOneColumn(); |
|
400 | - foreach ($ged_data as $ged_datum) { |
|
401 | - $matches = null; |
|
402 | - preg_match_all('/\n2 PLAC (.+)/', $ged_datum, $matches); |
|
403 | - foreach ($matches[1] as $match) { |
|
404 | - $places_list[$match]=true; |
|
405 | - } |
|
406 | - } |
|
386 | + //Select all '2 PLAC ' tags in the file and create array |
|
387 | + $places_list=array(); |
|
388 | + $ged_data = Database::prepare( |
|
389 | + 'SELECT i_gedcom AS gedcom'. |
|
390 | + ' FROM `##individuals`'. |
|
391 | + ' WHERE i_gedcom LIKE :gedcom AND i_file = :gedcom_id'. |
|
392 | + ' UNION ALL'. |
|
393 | + 'SELECT f_gedcom AS gedcom'. |
|
394 | + ' FROM `##families`'. |
|
395 | + ' WHERE f_gedcom LIKE :gedcom AND f_file = :gedcom_id' |
|
396 | + )->execute(array( |
|
397 | + 'gedcom' => '%\n2 PLAC %', |
|
398 | + 'gedcom_id' => $this->tree->getTreeId() |
|
399 | + ))->fetchOneColumn(); |
|
400 | + foreach ($ged_data as $ged_datum) { |
|
401 | + $matches = null; |
|
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 | - usort($places_list, array('I18N', 'strcasecmp')); |
|
411 | + //sort the array, limit to unique values, and count them |
|
412 | + usort($places_list, array('I18N', 'strcasecmp')); |
|
413 | 413 | |
414 | - //calculate maximum no. of levels to display |
|
415 | - $has_found_good_example = false; |
|
416 | - foreach($places_list as $place){ |
|
417 | - $levels = explode(",", $place); |
|
418 | - $parts = count($levels); |
|
419 | - if ($parts >= $nb_levels){ |
|
420 | - $nb_levels = $parts; |
|
421 | - if(!$has_found_good_example){ |
|
422 | - $random_place = $place; |
|
423 | - if(min(array_map('strlen', $levels)) > 0){ |
|
424 | - $has_found_good_example = true; |
|
425 | - } |
|
426 | - } |
|
427 | - } |
|
428 | - } |
|
414 | + //calculate maximum no. of levels to display |
|
415 | + $has_found_good_example = false; |
|
416 | + foreach($places_list as $place){ |
|
417 | + $levels = explode(",", $place); |
|
418 | + $parts = count($levels); |
|
419 | + if ($parts >= $nb_levels){ |
|
420 | + $nb_levels = $parts; |
|
421 | + if(!$has_found_good_example){ |
|
422 | + $random_place = $place; |
|
423 | + if(min(array_map('strlen', $levels)) > 0){ |
|
424 | + $has_found_good_example = true; |
|
425 | + } |
|
426 | + } |
|
427 | + } |
|
428 | + } |
|
429 | 429 | |
430 | - return array_reverse(array_map('trim',explode(',', $random_place))); |
|
431 | - } |
|
430 | + return array_reverse(array_map('trim',explode(',', $random_place))); |
|
431 | + } |
|
432 | 432 | |
433 | - /** |
|
434 | - * Returns the list of geodispersion maps available within the maps folder. |
|
435 | - * |
|
436 | - * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\OutlineMap[] |
|
437 | - */ |
|
438 | - public function getOutlineMapsList() { |
|
439 | - $res = array(); |
|
440 | - $root_path = WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'; |
|
441 | - if(is_dir($root_path)){ |
|
442 | - $dir = opendir($root_path); |
|
443 | - while (($file=readdir($dir))!== false) { |
|
444 | - if (preg_match('/^[a-zA-Z0-9_]+.xml$/', $file)) { |
|
445 | - $res[base64_encode($file)] = new OutlineMap($file, true); |
|
446 | - } |
|
447 | - } |
|
448 | - } |
|
449 | - return $res; |
|
450 | - } |
|
433 | + /** |
|
434 | + * Returns the list of geodispersion maps available within the maps folder. |
|
435 | + * |
|
436 | + * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\OutlineMap[] |
|
437 | + */ |
|
438 | + public function getOutlineMapsList() { |
|
439 | + $res = array(); |
|
440 | + $root_path = WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'; |
|
441 | + if(is_dir($root_path)){ |
|
442 | + $dir = opendir($root_path); |
|
443 | + while (($file=readdir($dir))!== false) { |
|
444 | + if (preg_match('/^[a-zA-Z0-9_]+.xml$/', $file)) { |
|
445 | + $res[base64_encode($file)] = new OutlineMap($file, true); |
|
446 | + } |
|
447 | + } |
|
448 | + } |
|
449 | + return $res; |
|
450 | + } |
|
451 | 451 | } |
452 | 452 | |
453 | 453 | \ No newline at end of file |
@@ -24,64 +24,64 @@ discard block |
||
24 | 24 | * Geo Analysis ID |
25 | 25 | * @var int $id |
26 | 26 | */ |
27 | - protected $id; |
|
27 | + protected $id; |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Geo Analysis Title |
31 | 31 | * @var string $title |
32 | 32 | */ |
33 | - protected $title; |
|
33 | + protected $title; |
|
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Level of the Gedcom hierarchy for the analysis |
37 | 37 | * @var int $analysis_level |
38 | 38 | */ |
39 | - protected $analysis_level; |
|
39 | + protected $analysis_level; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Display options |
|
43 | - * @var GeoDisplayOptions $options |
|
44 | - */ |
|
45 | - protected $options; |
|
41 | + /** |
|
42 | + * Display options |
|
43 | + * @var GeoDisplayOptions $options |
|
44 | + */ |
|
45 | + protected $options; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Reference tree |
|
49 | - * @var Tree $tree |
|
50 | - */ |
|
51 | - protected $tree; |
|
47 | + /** |
|
48 | + * Reference tree |
|
49 | + * @var Tree $tree |
|
50 | + */ |
|
51 | + protected $tree; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Is the analysis enabled |
|
55 | - * @var bool $enabled |
|
56 | - */ |
|
57 | - protected $enabled; |
|
53 | + /** |
|
54 | + * Is the analysis enabled |
|
55 | + * @var bool $enabled |
|
56 | + */ |
|
57 | + protected $enabled; |
|
58 | 58 | |
59 | - /** |
|
60 | - * Constructor for GeoAnalysis. |
|
61 | - * |
|
62 | - * @param Tree $tree Reference tree |
|
59 | + /** |
|
60 | + * Constructor for GeoAnalysis. |
|
61 | + * |
|
62 | + * @param Tree $tree Reference tree |
|
63 | 63 | * @param int $id GeoAnalysis ID |
64 | 64 | * @param string $title GeoAnalysis title |
65 | 65 | * @param int $analysis_level Analysis level |
66 | 66 | * @param (GeoDisplayOptions|null) $options Display options |
67 | 67 | * @param bool $enabled Is analysis enabled |
68 | - */ |
|
69 | - public function __construct(Tree $tree, $id, $title, $analysis_level, GeoDisplayOptions $options = null, $enabled = true) { |
|
70 | - $this->tree = $tree; |
|
71 | - $this->id = $id; |
|
72 | - $this->title = $title; |
|
73 | - $this->analysis_level = $analysis_level; |
|
74 | - $this->options = $options; |
|
75 | - $this->enabled = $enabled; |
|
76 | - } |
|
68 | + */ |
|
69 | + public function __construct(Tree $tree, $id, $title, $analysis_level, GeoDisplayOptions $options = null, $enabled = true) { |
|
70 | + $this->tree = $tree; |
|
71 | + $this->id = $id; |
|
72 | + $this->title = $title; |
|
73 | + $this->analysis_level = $analysis_level; |
|
74 | + $this->options = $options; |
|
75 | + $this->enabled = $enabled; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Get the analysis title |
80 | 80 | * @return string |
81 | 81 | */ |
82 | - public function getTitle() { |
|
83 | - return $this->title; |
|
84 | - } |
|
82 | + public function getTitle() { |
|
83 | + return $this->title; |
|
84 | + } |
|
85 | 85 | |
86 | 86 | /** |
87 | 87 | * Set the analysis title |
@@ -89,53 +89,53 @@ discard block |
||
89 | 89 | * @param string $title |
90 | 90 | * @return self Enable method-chaining |
91 | 91 | */ |
92 | - public function setTitle($title) { |
|
93 | - $this->title = $title; |
|
94 | - return $this; |
|
95 | - } |
|
92 | + public function setTitle($title) { |
|
93 | + $this->title = $title; |
|
94 | + return $this; |
|
95 | + } |
|
96 | 96 | |
97 | 97 | /** |
98 | 98 | * Get the analysis ID |
99 | 99 | * @return int |
100 | 100 | */ |
101 | - public function getId() { |
|
102 | - return $this->id; |
|
103 | - } |
|
101 | + public function getId() { |
|
102 | + return $this->id; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | /** |
106 | 106 | * Get the analysis status (enabled/disabled) |
107 | 107 | * @return bool |
108 | 108 | */ |
109 | - public function isEnabled() { |
|
110 | - return $this->enabled; |
|
111 | - } |
|
109 | + public function isEnabled() { |
|
110 | + return $this->enabled; |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Get analysis options |
|
115 | - * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoDisplayOptions |
|
116 | - */ |
|
117 | - public function getOptions() { |
|
118 | - return $this->options; |
|
119 | - } |
|
113 | + /** |
|
114 | + * Get analysis options |
|
115 | + * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoDisplayOptions |
|
116 | + */ |
|
117 | + public function getOptions() { |
|
118 | + return $this->options; |
|
119 | + } |
|
120 | 120 | |
121 | 121 | /** |
122 | - * Set analysis options |
|
122 | + * Set analysis options |
|
123 | 123 | * |
124 | - * @param \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoDisplayOptions $options |
|
124 | + * @param \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoDisplayOptions $options |
|
125 | 125 | * @return self Enable method-chaining |
126 | - */ |
|
127 | - public function setOptions(GeoDisplayOptions $options) { |
|
128 | - $this->options = $options; |
|
129 | - return $this; |
|
130 | - } |
|
126 | + */ |
|
127 | + public function setOptions(GeoDisplayOptions $options) { |
|
128 | + $this->options = $options; |
|
129 | + return $this; |
|
130 | + } |
|
131 | 131 | |
132 | 132 | /** |
133 | 133 | * Get analysis level |
134 | 134 | * @return int |
135 | 135 | */ |
136 | - public function getAnalysisLevel() { |
|
137 | - return $this->analysis_level; |
|
138 | - } |
|
136 | + public function getAnalysisLevel() { |
|
137 | + return $this->analysis_level; |
|
138 | + } |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * Get analysis level |
@@ -143,19 +143,19 @@ discard block |
||
143 | 143 | * @param int $analysis_level |
144 | 144 | * @return self Enable method-chaining |
145 | 145 | */ |
146 | - public function setAnalysisLevel($analysis_level) { |
|
147 | - $this->analysis_level = $analysis_level; |
|
148 | - return $this; |
|
149 | - } |
|
146 | + public function setAnalysisLevel($analysis_level) { |
|
147 | + $this->analysis_level = $analysis_level; |
|
148 | + return $this; |
|
149 | + } |
|
150 | 150 | |
151 | 151 | /** |
152 | 152 | * Check whether the analysis has a linked map |
153 | 153 | * |
154 | 154 | * @return bool |
155 | 155 | */ |
156 | - public function hasMap() { |
|
157 | - return $this->options && $this->options->getMap(); |
|
158 | - } |
|
156 | + public function hasMap() { |
|
157 | + return $this->options && $this->options->getMap(); |
|
158 | + } |
|
159 | 159 | |
160 | 160 | /** |
161 | 161 | * Get the URL for the GeoAnalysis. |
@@ -163,120 +163,120 @@ discard block |
||
163 | 163 | * @return string |
164 | 164 | */ |
165 | 165 | public function getHtmlUrl() { |
166 | - return 'module.php?mod='. Constants::MODULE_MAJ_GEODISP_NAME . '&mod_action=GeoAnalysis&ga_id=' . $this->getId() . '&ged=' . $this->tree->getNameUrl(); |
|
167 | - } |
|
166 | + return 'module.php?mod='. Constants::MODULE_MAJ_GEODISP_NAME . '&mod_action=GeoAnalysis&ga_id=' . $this->getId() . '&ged=' . $this->tree->getNameUrl(); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * Return the dispersion analysis tables. |
|
171 | - * Two arrays are returned : |
|
172 | - * - the General analysis, which returns the number of ancestors for each place found, plus 4 additional indicators : |
|
173 | - * - knownsum : Number of known places |
|
174 | - * - unknown : Number of unknown places |
|
175 | - * - max : Maximum count of ancestors within a place |
|
176 | - * - other : Other places (not in the top level area) |
|
177 | - * - the Generations analysis, which returns the number of ancestors for each place found for each generation, plus 3 additional indicators within each generation : |
|
178 | - * - sum : Number of known places |
|
179 | - * - unknown : Number of unknown places |
|
180 | - * - other : Other places (not in the top level area) |
|
181 | - * |
|
182 | - * @param array $sosalist List of all sosas |
|
183 | - * @return array Array of the general and generations table |
|
184 | - */ |
|
185 | - public function getAnalysisResults($sosalist) { |
|
186 | - $placesDispGeneral = null; |
|
187 | - $placesDispGenerations = null; |
|
169 | + /** |
|
170 | + * Return the dispersion analysis tables. |
|
171 | + * Two arrays are returned : |
|
172 | + * - the General analysis, which returns the number of ancestors for each place found, plus 4 additional indicators : |
|
173 | + * - knownsum : Number of known places |
|
174 | + * - unknown : Number of unknown places |
|
175 | + * - max : Maximum count of ancestors within a place |
|
176 | + * - other : Other places (not in the top level area) |
|
177 | + * - the Generations analysis, which returns the number of ancestors for each place found for each generation, plus 3 additional indicators within each generation : |
|
178 | + * - sum : Number of known places |
|
179 | + * - unknown : Number of unknown places |
|
180 | + * - other : Other places (not in the top level area) |
|
181 | + * |
|
182 | + * @param array $sosalist List of all sosas |
|
183 | + * @return array Array of the general and generations table |
|
184 | + */ |
|
185 | + public function getAnalysisResults($sosalist) { |
|
186 | + $placesDispGeneral = null; |
|
187 | + $placesDispGenerations = null; |
|
188 | 188 | |
189 | - if($sosalist && count($sosalist) > 0) { |
|
190 | - $placesDispGeneral['knownsum'] = 0; |
|
191 | - $placesDispGeneral['unknown'] = 0; |
|
192 | - $placesDispGeneral['max'] = 0; |
|
193 | - $placesDispGeneral['places'] = array(); |
|
194 | - foreach($sosalist as $sosaid => $gens) { |
|
195 | - $sosa = Individual::getIntance($sosaid, $this->tree); |
|
196 | - $place =$sosa->getSignificantPlace(); |
|
197 | - $genstab = explode(',', $gens); |
|
198 | - $isUnknown=true; |
|
199 | - if($sosa->getDerivedRecord()->canShow() && !is_null($place)){ |
|
200 | - $levels = array_reverse(array_map('trim',explode(',', $place))); |
|
201 | - if(count($levels)>= $this->analysis_level){ |
|
202 | - $toplevelvalues = array(); |
|
203 | - if($this->hasMap() |
|
204 | - && $this->options->getMap()->isLoaded() |
|
205 | - && $toplevelvalue = $this->options->getMap()->getTopLevelName() |
|
206 | - ) { |
|
207 | - $toplevelvalues = array_map('trim',explode(',', strtolower($toplevelvalue))); |
|
208 | - } |
|
209 | - if(!$this->hasMap() |
|
210 | - || is_null($this->options->getMapLevel()) |
|
211 | - || ( $this->options->getMap()->isLoaded() && $this->options->getMap()->getTopLevelName() == '*') |
|
212 | - || ( |
|
213 | - $this->options->getMapLevel() <= $this->analysis_level |
|
214 | - && $this->options->getMapLevel() > 0 |
|
215 | - && count($levels) >= $this->options->getMapLevel() |
|
216 | - && in_array(strtolower($levels[$this->options->getMapLevel()-1]), $toplevelvalues) |
|
217 | - ) |
|
218 | - ) { |
|
219 | - $placest = implode(I18N::$list_separator, array_slice($levels, 0, $this->analysis_level)); |
|
220 | - if(isset($placesDispGeneral['places'][$placest])) { |
|
221 | - $placesDispGeneral['places'][$placest] += 1; |
|
222 | - } |
|
223 | - else { |
|
224 | - $placesDispGeneral['places'][$placest] = 1; |
|
225 | - } |
|
226 | - if($placesDispGeneral['places'][$placest]>$placesDispGeneral['max']) |
|
227 | - $placesDispGeneral['max'] = $placesDispGeneral['places'][$placest]; |
|
228 | - foreach($genstab as $gen) { |
|
229 | - if(isset($placesDispGenerations[$gen]['places'][$placest])) { |
|
230 | - $placesDispGenerations[$gen]['places'][$placest] += 1; |
|
231 | - } |
|
232 | - else { |
|
233 | - $placesDispGenerations[$gen]['places'][$placest] = 1; |
|
234 | - } |
|
235 | - if(isset($placesDispGenerations[$gen]['sum'])) { |
|
236 | - $placesDispGenerations[$gen]['sum'] += 1; |
|
237 | - } |
|
238 | - else { |
|
239 | - $placesDispGenerations[$gen]['sum'] = 1; |
|
240 | - } |
|
241 | - } |
|
242 | - } |
|
243 | - else{ |
|
244 | - if(isset($placesDispGeneral['other'])) { |
|
245 | - $placesDispGeneral['other'] += 1; |
|
246 | - } |
|
247 | - else { |
|
248 | - $placesDispGeneral['other'] = 1; |
|
249 | - } |
|
250 | - foreach($genstab as $gen) { |
|
251 | - if(isset($placesDispGenerations[$gen]['other'])) { |
|
252 | - $placesDispGenerations[$gen]['other'] += 1; |
|
253 | - } |
|
254 | - else { |
|
255 | - $placesDispGenerations[$gen]['other'] = 1; |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
259 | - $placesDispGeneral['knownsum'] += 1; |
|
260 | - $isUnknown = false; |
|
261 | - } |
|
262 | - } |
|
263 | - if($isUnknown){ |
|
264 | - $placesDispGeneral['unknown'] += 1; |
|
265 | - foreach($genstab as $gen) { |
|
266 | - if(isset($placesDispGenerations[$gen]['unknown'])) { |
|
267 | - $placesDispGenerations[$gen]['unknown'] += 1; |
|
268 | - } |
|
269 | - else { |
|
270 | - $placesDispGenerations[$gen]['unknown'] = 1; |
|
271 | - } |
|
272 | - } |
|
273 | - } |
|
274 | - } |
|
189 | + if($sosalist && count($sosalist) > 0) { |
|
190 | + $placesDispGeneral['knownsum'] = 0; |
|
191 | + $placesDispGeneral['unknown'] = 0; |
|
192 | + $placesDispGeneral['max'] = 0; |
|
193 | + $placesDispGeneral['places'] = array(); |
|
194 | + foreach($sosalist as $sosaid => $gens) { |
|
195 | + $sosa = Individual::getIntance($sosaid, $this->tree); |
|
196 | + $place =$sosa->getSignificantPlace(); |
|
197 | + $genstab = explode(',', $gens); |
|
198 | + $isUnknown=true; |
|
199 | + if($sosa->getDerivedRecord()->canShow() && !is_null($place)){ |
|
200 | + $levels = array_reverse(array_map('trim',explode(',', $place))); |
|
201 | + if(count($levels)>= $this->analysis_level){ |
|
202 | + $toplevelvalues = array(); |
|
203 | + if($this->hasMap() |
|
204 | + && $this->options->getMap()->isLoaded() |
|
205 | + && $toplevelvalue = $this->options->getMap()->getTopLevelName() |
|
206 | + ) { |
|
207 | + $toplevelvalues = array_map('trim',explode(',', strtolower($toplevelvalue))); |
|
208 | + } |
|
209 | + if(!$this->hasMap() |
|
210 | + || is_null($this->options->getMapLevel()) |
|
211 | + || ( $this->options->getMap()->isLoaded() && $this->options->getMap()->getTopLevelName() == '*') |
|
212 | + || ( |
|
213 | + $this->options->getMapLevel() <= $this->analysis_level |
|
214 | + && $this->options->getMapLevel() > 0 |
|
215 | + && count($levels) >= $this->options->getMapLevel() |
|
216 | + && in_array(strtolower($levels[$this->options->getMapLevel()-1]), $toplevelvalues) |
|
217 | + ) |
|
218 | + ) { |
|
219 | + $placest = implode(I18N::$list_separator, array_slice($levels, 0, $this->analysis_level)); |
|
220 | + if(isset($placesDispGeneral['places'][$placest])) { |
|
221 | + $placesDispGeneral['places'][$placest] += 1; |
|
222 | + } |
|
223 | + else { |
|
224 | + $placesDispGeneral['places'][$placest] = 1; |
|
225 | + } |
|
226 | + if($placesDispGeneral['places'][$placest]>$placesDispGeneral['max']) |
|
227 | + $placesDispGeneral['max'] = $placesDispGeneral['places'][$placest]; |
|
228 | + foreach($genstab as $gen) { |
|
229 | + if(isset($placesDispGenerations[$gen]['places'][$placest])) { |
|
230 | + $placesDispGenerations[$gen]['places'][$placest] += 1; |
|
231 | + } |
|
232 | + else { |
|
233 | + $placesDispGenerations[$gen]['places'][$placest] = 1; |
|
234 | + } |
|
235 | + if(isset($placesDispGenerations[$gen]['sum'])) { |
|
236 | + $placesDispGenerations[$gen]['sum'] += 1; |
|
237 | + } |
|
238 | + else { |
|
239 | + $placesDispGenerations[$gen]['sum'] = 1; |
|
240 | + } |
|
241 | + } |
|
242 | + } |
|
243 | + else{ |
|
244 | + if(isset($placesDispGeneral['other'])) { |
|
245 | + $placesDispGeneral['other'] += 1; |
|
246 | + } |
|
247 | + else { |
|
248 | + $placesDispGeneral['other'] = 1; |
|
249 | + } |
|
250 | + foreach($genstab as $gen) { |
|
251 | + if(isset($placesDispGenerations[$gen]['other'])) { |
|
252 | + $placesDispGenerations[$gen]['other'] += 1; |
|
253 | + } |
|
254 | + else { |
|
255 | + $placesDispGenerations[$gen]['other'] = 1; |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | + $placesDispGeneral['knownsum'] += 1; |
|
260 | + $isUnknown = false; |
|
261 | + } |
|
262 | + } |
|
263 | + if($isUnknown){ |
|
264 | + $placesDispGeneral['unknown'] += 1; |
|
265 | + foreach($genstab as $gen) { |
|
266 | + if(isset($placesDispGenerations[$gen]['unknown'])) { |
|
267 | + $placesDispGenerations[$gen]['unknown'] += 1; |
|
268 | + } |
|
269 | + else { |
|
270 | + $placesDispGenerations[$gen]['unknown'] = 1; |
|
271 | + } |
|
272 | + } |
|
273 | + } |
|
274 | + } |
|
275 | 275 | |
276 | - } |
|
276 | + } |
|
277 | 277 | |
278 | - return array($placesDispGeneral, $placesDispGenerations); |
|
279 | - } |
|
278 | + return array($placesDispGeneral, $placesDispGenerations); |
|
279 | + } |
|
280 | 280 | |
281 | 281 | |
282 | 282 | } |
@@ -25,24 +25,24 @@ discard block |
||
25 | 25 | * {@inheritDoc} |
26 | 26 | * @see \MyArtJaub\Webtrees\Module\GeoDispersion\Views\AbstractGeoAnalysisTabGeneralView::htmlAnalysisData() |
27 | 27 | */ |
28 | - protected function htmlAnalysisData() { |
|
28 | + protected function htmlAnalysisData() { |
|
29 | 29 | |
30 | - /** @var OutlineMap $map */ |
|
31 | - $map = $this->data->get('map'); |
|
30 | + /** @var OutlineMap $map */ |
|
31 | + $map = $this->data->get('map'); |
|
32 | 32 | |
33 | - if($map === null) { |
|
34 | - return '<p class="warning">' . |
|
35 | - I18N::translate('The map could not be loaded.') . |
|
36 | - '</p>'; |
|
37 | - } |
|
33 | + if($map === null) { |
|
34 | + return '<p class="warning">' . |
|
35 | + I18N::translate('The map could not be loaded.') . |
|
36 | + '</p>'; |
|
37 | + } |
|
38 | 38 | |
39 | - $canvas = $map->getCanvas(); |
|
40 | - $subdvisions_results = $this->data->get('results_by_subdivisions'); |
|
39 | + $canvas = $map->getCanvas(); |
|
40 | + $subdvisions_results = $this->data->get('results_by_subdivisions'); |
|
41 | 41 | |
42 | - $nb_found = $this->data->get('stats_gen_nb_found'); |
|
43 | - $nb_other = $this->data->get('stats_gen_nb_other'); |
|
42 | + $nb_found = $this->data->get('stats_gen_nb_found'); |
|
43 | + $nb_other = $this->data->get('stats_gen_nb_other'); |
|
44 | 44 | |
45 | - $html = '<script> |
|
45 | + $html = '<script> |
|
46 | 46 | var tip = null; |
47 | 47 | var tipText = ""; |
48 | 48 | var over = false; |
@@ -89,29 +89,29 @@ discard block |
||
89 | 89 | var map = {}; |
90 | 90 | '; |
91 | 91 | |
92 | - foreach($subdvisions_results as $name => $location){ |
|
93 | - $html.= 'map.area'.$location['id'].' = paper.path("'.$location['coord'].'").attr(attr);'; |
|
94 | - if(isset($location['transparency'])) { |
|
95 | - $textToolTip = '<strong>'.$location['displayname'].'</strong><br/>'; |
|
96 | - if($this->data->get('use_flags') && $location['flag'] != '') $textToolTip .= '<span class="geodispersion_flag">'.FunctionsPrint::htmlPlaceIcon($location['place'], $location['flag']).'</span><br/>'; |
|
97 | - $textToolTip .= I18N::translate('%d individuals', $location['count']).'<br/>'.I18N::percentage(Functions::safeDivision($location['count'], $nb_found - $nb_other), 1); |
|
98 | - $html.= 'addTip(map.area'.$location['id'].'.node, "'.Filter::escapeJs($textToolTip).'");'; |
|
99 | - $html.= 'map.area'.$location['id'].'.attr({"fill" : "'. $canvas->max_color .'", "fill-opacity" : '.$location['transparency'].' });'; |
|
100 | - $html.= 'map.area'.$location['id'].'.mouseover(function () {'. |
|
101 | - 'map.area'.$location['id'].'.stop().animate({"fill" : "'. $canvas->hover_color .'", "fill-opacity" : 1}, 100, "linear");'. |
|
102 | - '});'. |
|
103 | - 'map.area'.$location['id'].'.mouseout(function () {'. |
|
104 | - 'map.area'.$location['id'].'.stop().animate({"fill" : "'.$canvas->max_color.'", "fill-opacity" : '.$location['transparency'].'}, 100, "linear");'. |
|
105 | - '});'; |
|
106 | - } |
|
107 | - } |
|
108 | - $html .= '}); |
|
92 | + foreach($subdvisions_results as $name => $location){ |
|
93 | + $html.= 'map.area'.$location['id'].' = paper.path("'.$location['coord'].'").attr(attr);'; |
|
94 | + if(isset($location['transparency'])) { |
|
95 | + $textToolTip = '<strong>'.$location['displayname'].'</strong><br/>'; |
|
96 | + if($this->data->get('use_flags') && $location['flag'] != '') $textToolTip .= '<span class="geodispersion_flag">'.FunctionsPrint::htmlPlaceIcon($location['place'], $location['flag']).'</span><br/>'; |
|
97 | + $textToolTip .= I18N::translate('%d individuals', $location['count']).'<br/>'.I18N::percentage(Functions::safeDivision($location['count'], $nb_found - $nb_other), 1); |
|
98 | + $html.= 'addTip(map.area'.$location['id'].'.node, "'.Filter::escapeJs($textToolTip).'");'; |
|
99 | + $html.= 'map.area'.$location['id'].'.attr({"fill" : "'. $canvas->max_color .'", "fill-opacity" : '.$location['transparency'].' });'; |
|
100 | + $html.= 'map.area'.$location['id'].'.mouseover(function () {'. |
|
101 | + 'map.area'.$location['id'].'.stop().animate({"fill" : "'. $canvas->hover_color .'", "fill-opacity" : 1}, 100, "linear");'. |
|
102 | + '});'. |
|
103 | + 'map.area'.$location['id'].'.mouseout(function () {'. |
|
104 | + 'map.area'.$location['id'].'.stop().animate({"fill" : "'.$canvas->max_color.'", "fill-opacity" : '.$location['transparency'].'}, 100, "linear");'. |
|
105 | + '});'; |
|
106 | + } |
|
107 | + } |
|
108 | + $html .= '}); |
|
109 | 109 | </script> |
110 | 110 | |
111 | 111 | <div id="geodispersion_map"></div> |
112 | 112 | <div id="geodispersion_tip"></div>'; |
113 | 113 | |
114 | - return $html; |
|
115 | - } |
|
114 | + return $html; |
|
115 | + } |
|
116 | 116 | |
117 | 117 | } |
118 | 118 | \ No newline at end of file |
@@ -36,58 +36,58 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class AdminConfigController extends MvcController |
38 | 38 | { |
39 | - /** |
|
40 | - * GeoAnalysis Provider |
|
41 | - * @var GeoAnalysisProvider $provider |
|
42 | - */ |
|
43 | - protected $provider; |
|
39 | + /** |
|
40 | + * GeoAnalysis Provider |
|
41 | + * @var GeoAnalysisProvider $provider |
|
42 | + */ |
|
43 | + protected $provider; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Constructor for Admin Config controller |
|
47 | - * @param AbstractModule $module |
|
48 | - */ |
|
49 | - public function __construct(AbstractModule $module) { |
|
50 | - parent::__construct($module); |
|
45 | + /** |
|
46 | + * Constructor for Admin Config controller |
|
47 | + * @param AbstractModule $module |
|
48 | + */ |
|
49 | + public function __construct(AbstractModule $module) { |
|
50 | + parent::__construct($module); |
|
51 | 51 | |
52 | - $this->provider = $this->module->getProvider(); |
|
53 | - } |
|
52 | + $this->provider = $this->module->getProvider(); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Pages |
|
57 | - */ |
|
55 | + /** |
|
56 | + * Pages |
|
57 | + */ |
|
58 | 58 | |
59 | - /** |
|
60 | - * AdminConfig@index |
|
61 | - */ |
|
62 | - public function index() { |
|
63 | - $wt_tree = Globals::getTree(); |
|
64 | - Theme::theme(new AdministrationTheme)->init($wt_tree); |
|
65 | - $controller = new PageController(); |
|
66 | - $controller |
|
67 | - ->restrictAccess(Auth::isManager($wt_tree)) |
|
68 | - ->setPageTitle($this->module->getTitle()); |
|
59 | + /** |
|
60 | + * AdminConfig@index |
|
61 | + */ |
|
62 | + public function index() { |
|
63 | + $wt_tree = Globals::getTree(); |
|
64 | + Theme::theme(new AdministrationTheme)->init($wt_tree); |
|
65 | + $controller = new PageController(); |
|
66 | + $controller |
|
67 | + ->restrictAccess(Auth::isManager($wt_tree)) |
|
68 | + ->setPageTitle($this->module->getTitle()); |
|
69 | 69 | |
70 | - $data = new ViewBag(); |
|
71 | - $data->set('title', $controller->getPageTitle()); |
|
72 | - $data->set('tree', $wt_tree); |
|
70 | + $data = new ViewBag(); |
|
71 | + $data->set('title', $controller->getPageTitle()); |
|
72 | + $data->set('tree', $wt_tree); |
|
73 | 73 | |
74 | - $data->set('root_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig'); |
|
74 | + $data->set('root_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig'); |
|
75 | 75 | |
76 | - $table_id = 'table-geoanalysis-' . Uuid::uuid4(); |
|
77 | - $data->set('table_id', $table_id); |
|
76 | + $table_id = 'table-geoanalysis-' . Uuid::uuid4(); |
|
77 | + $data->set('table_id', $table_id); |
|
78 | 78 | |
79 | - $other_trees = array(); |
|
80 | - foreach (Tree::getAll() as $tree) { |
|
81 | - if($tree->getTreeId() != $wt_tree->getTreeId()) $other_trees[] = $tree; |
|
82 | - } |
|
83 | - $data->set('other_trees', $other_trees); |
|
79 | + $other_trees = array(); |
|
80 | + foreach (Tree::getAll() as $tree) { |
|
81 | + if($tree->getTreeId() != $wt_tree->getTreeId()) $other_trees[] = $tree; |
|
82 | + } |
|
83 | + $data->set('other_trees', $other_trees); |
|
84 | 84 | |
85 | - $data->set('places_hierarchy', $this->provider->getPlacesHierarchy()); |
|
85 | + $data->set('places_hierarchy', $this->provider->getPlacesHierarchy()); |
|
86 | 86 | |
87 | - $controller |
|
88 | - ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) |
|
89 | - ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL) |
|
90 | - ->addInlineJavascript(' |
|
87 | + $controller |
|
88 | + ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) |
|
89 | + ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL) |
|
90 | + ->addInlineJavascript(' |
|
91 | 91 | jQuery.fn.dataTableExt.oSort["text-asc"] = textCompareAsc; |
92 | 92 | jQuery.fn.dataTableExt.oSort["text-desc"] = textCompareDesc; |
93 | 93 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | }); |
120 | 120 | |
121 | 121 | ') |
122 | - ->addInlineJavascript(' |
|
122 | + ->addInlineJavascript(' |
|
123 | 123 | function set_geoanalysis_status(ga_id, status, gedcom) { |
124 | 124 | jQuery.ajax({ |
125 | 125 | url: "module.php", |
@@ -163,54 +163,54 @@ discard block |
||
163 | 163 | '); |
164 | 164 | |
165 | 165 | |
166 | - ViewFactory::make('AdminConfig', $this, $controller, $data)->render(); |
|
167 | - } |
|
166 | + ViewFactory::make('AdminConfig', $this, $controller, $data)->render(); |
|
167 | + } |
|
168 | 168 | |
169 | - /** |
|
170 | - * AdminConfig@jsonGeoAnalysisList |
|
171 | - */ |
|
172 | - public function jsonGeoAnalysisList() { |
|
173 | - $wt_tree = Globals::getTree(); |
|
174 | - $controller = new JsonController(); |
|
175 | - $controller |
|
176 | - ->restrictAccess(Auth::isManager($wt_tree)); |
|
169 | + /** |
|
170 | + * AdminConfig@jsonGeoAnalysisList |
|
171 | + */ |
|
172 | + public function jsonGeoAnalysisList() { |
|
173 | + $wt_tree = Globals::getTree(); |
|
174 | + $controller = new JsonController(); |
|
175 | + $controller |
|
176 | + ->restrictAccess(Auth::isManager($wt_tree)); |
|
177 | 177 | |
178 | - // Generate an AJAX/JSON response for datatables to load a block of rows |
|
179 | - $search = Filter::postArray('search'); |
|
180 | - if($search) $search = $search['value']; |
|
181 | - $start = Filter::postInteger('start'); |
|
182 | - $length = Filter::postInteger('length'); |
|
183 | - $order = Filter::postArray('order'); |
|
178 | + // Generate an AJAX/JSON response for datatables to load a block of rows |
|
179 | + $search = Filter::postArray('search'); |
|
180 | + if($search) $search = $search['value']; |
|
181 | + $start = Filter::postInteger('start'); |
|
182 | + $length = Filter::postInteger('length'); |
|
183 | + $order = Filter::postArray('order'); |
|
184 | 184 | |
185 | - foreach($order as $key => &$value) { |
|
186 | - switch($value['column']) { |
|
187 | - case 3: |
|
188 | - $value['column'] = 'majgd_descr'; |
|
189 | - break; |
|
190 | - case 5; |
|
191 | - $value['column'] = 'majgd_sublevel'; |
|
192 | - break; |
|
193 | - default: |
|
194 | - unset($order[$key]); |
|
195 | - } |
|
196 | - } |
|
185 | + foreach($order as $key => &$value) { |
|
186 | + switch($value['column']) { |
|
187 | + case 3: |
|
188 | + $value['column'] = 'majgd_descr'; |
|
189 | + break; |
|
190 | + case 5; |
|
191 | + $value['column'] = 'majgd_sublevel'; |
|
192 | + break; |
|
193 | + default: |
|
194 | + unset($order[$key]); |
|
195 | + } |
|
196 | + } |
|
197 | 197 | |
198 | - /** @var GeoAnalysisProvider $provider */ |
|
199 | - $provider = $this->module->getProvider(); |
|
198 | + /** @var GeoAnalysisProvider $provider */ |
|
199 | + $provider = $this->module->getProvider(); |
|
200 | 200 | |
201 | - $list = $provider->getFilteredGeoAnalysisList($search, $order, $start, $length); |
|
202 | - $recordsFiltered = count($list); |
|
203 | - $recordsTotal = $this->provider->getGeoAnalysisCount(); |
|
201 | + $list = $provider->getFilteredGeoAnalysisList($search, $order, $start, $length); |
|
202 | + $recordsFiltered = count($list); |
|
203 | + $recordsTotal = $this->provider->getGeoAnalysisCount(); |
|
204 | 204 | |
205 | - $data = array(); |
|
206 | - $place_hierarchy = $this->provider->getPlacesHierarchy(); |
|
207 | - foreach($list as $ga) { |
|
208 | - /** @var GeoAnalysis $ga */ |
|
205 | + $data = array(); |
|
206 | + $place_hierarchy = $this->provider->getPlacesHierarchy(); |
|
207 | + foreach($list as $ga) { |
|
208 | + /** @var GeoAnalysis $ga */ |
|
209 | 209 | |
210 | - $datum = array(); |
|
211 | - $options= $ga->getOptions(); |
|
210 | + $datum = array(); |
|
211 | + $options= $ga->getOptions(); |
|
212 | 212 | |
213 | - $datum[0] = ' |
|
213 | + $datum[0] = ' |
|
214 | 214 | <div class="btn-group"> |
215 | 215 | <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> |
216 | 216 | <i class="fa fa-pencil"></i><span class="caret"></span> |
@@ -234,112 +234,112 @@ discard block |
||
234 | 234 | </li> |
235 | 235 | </ul> |
236 | 236 | </div>'; |
237 | - $datum[1] = $ga->getId(); |
|
238 | - $datum[2] = $ga->isEnabled() ? |
|
237 | + $datum[1] = $ga->getId(); |
|
238 | + $datum[2] = $ga->isEnabled() ? |
|
239 | 239 | '<i class="fa fa-check"></i><span class="sr-only">'.I18N::translate('Enabled').'</span>' : |
240 | 240 | '<i class="fa fa-times"></i><span class="sr-only">'.I18N::translate('Disabled').'</span>'; |
241 | - $datum[3] = $ga->getTitle(); |
|
242 | - $analysis_level = $ga->getAnalysisLevel(); |
|
243 | - if($place_hierarchy['type'] == 'header') { |
|
244 | - $datum[4] = $place_hierarchy['hierarchy'][$analysis_level - 1]; |
|
245 | - } else { |
|
246 | - $datum[4] = $analysis_level . '(' . $place_hierarchy['hierarchy'][$analysis_level - 1] . ')'; |
|
247 | - } |
|
248 | - $datum[5] = $ga->getAnalysisLevel(); |
|
249 | - $datum[6] = '<i class="fa fa-times"></i><span class="sr-only">'.I18N::translate('None').'</span>'; |
|
250 | - $datum[7] = '<i class="fa fa-times"></i><span class="sr-only">'.I18N::translate('None').'</span>'; |
|
251 | - if($ga->hasMap()) { |
|
252 | - if($options->getMap()->isLoaded()) { |
|
253 | - $datum[6] = $options->getMap()->getDescription(); |
|
254 | - $datum[7] = '<span data-toggle="tooltip" title="' . $options->getMap()->getTopLevelName() . '" />'; |
|
255 | - $top_level = $options->getMapLevel(); |
|
256 | - if($place_hierarchy['type'] == 'header') { |
|
257 | - $datum[7] .= $place_hierarchy['hierarchy'][$top_level - 1]; |
|
258 | - } else { |
|
259 | - $datum[7] .= $top_level . '(' . $place_hierarchy['hierarchy'][$top_level - 1] . ')'; |
|
260 | - } |
|
261 | - $datum[7] .= '</span>'; |
|
262 | - } |
|
263 | - else { |
|
264 | - $datum[6] = I18N::translate('Error when loading map.'); |
|
265 | - } |
|
266 | - } |
|
267 | - $datum[8] = $options->isUsingFlags() ? |
|
241 | + $datum[3] = $ga->getTitle(); |
|
242 | + $analysis_level = $ga->getAnalysisLevel(); |
|
243 | + if($place_hierarchy['type'] == 'header') { |
|
244 | + $datum[4] = $place_hierarchy['hierarchy'][$analysis_level - 1]; |
|
245 | + } else { |
|
246 | + $datum[4] = $analysis_level . '(' . $place_hierarchy['hierarchy'][$analysis_level - 1] . ')'; |
|
247 | + } |
|
248 | + $datum[5] = $ga->getAnalysisLevel(); |
|
249 | + $datum[6] = '<i class="fa fa-times"></i><span class="sr-only">'.I18N::translate('None').'</span>'; |
|
250 | + $datum[7] = '<i class="fa fa-times"></i><span class="sr-only">'.I18N::translate('None').'</span>'; |
|
251 | + if($ga->hasMap()) { |
|
252 | + if($options->getMap()->isLoaded()) { |
|
253 | + $datum[6] = $options->getMap()->getDescription(); |
|
254 | + $datum[7] = '<span data-toggle="tooltip" title="' . $options->getMap()->getTopLevelName() . '" />'; |
|
255 | + $top_level = $options->getMapLevel(); |
|
256 | + if($place_hierarchy['type'] == 'header') { |
|
257 | + $datum[7] .= $place_hierarchy['hierarchy'][$top_level - 1]; |
|
258 | + } else { |
|
259 | + $datum[7] .= $top_level . '(' . $place_hierarchy['hierarchy'][$top_level - 1] . ')'; |
|
260 | + } |
|
261 | + $datum[7] .= '</span>'; |
|
262 | + } |
|
263 | + else { |
|
264 | + $datum[6] = I18N::translate('Error when loading map.'); |
|
265 | + } |
|
266 | + } |
|
267 | + $datum[8] = $options->isUsingFlags() ? |
|
268 | 268 | '<i class="fa fa-check"></i><span class="sr-only">'.I18N::translate('Yes').'</span>' : |
269 | 269 | '<i class="fa fa-times"></i><span class="sr-only">'.I18N::translate('No').'</span>'; |
270 | - $datum[9] = $options->getMaxDetailsInGen() > 0 ? $options->getMaxDetailsInGen() : I18N::translate('All'); |
|
270 | + $datum[9] = $options->getMaxDetailsInGen() > 0 ? $options->getMaxDetailsInGen() : I18N::translate('All'); |
|
271 | 271 | |
272 | - $data[] = $datum; |
|
273 | - } |
|
272 | + $data[] = $datum; |
|
273 | + } |
|
274 | 274 | |
275 | - $controller->pageHeader(); |
|
275 | + $controller->pageHeader(); |
|
276 | 276 | |
277 | - $controller->encode(array( |
|
278 | - 'draw' => Filter::getInteger('draw'), |
|
279 | - 'recordsTotal' => $recordsTotal, |
|
280 | - 'recordsFiltered' => $recordsFiltered, |
|
281 | - 'data' => $data |
|
282 | - )); |
|
277 | + $controller->encode(array( |
|
278 | + 'draw' => Filter::getInteger('draw'), |
|
279 | + 'recordsTotal' => $recordsTotal, |
|
280 | + 'recordsFiltered' => $recordsFiltered, |
|
281 | + 'data' => $data |
|
282 | + )); |
|
283 | 283 | |
284 | - } |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * AdminConfig@edit |
|
288 | - */ |
|
289 | - public function edit() { |
|
290 | - $ga_id = Filter::getInteger('ga_id'); |
|
291 | - $ga = $this->provider->getGeoAnalysis($ga_id, false); |
|
286 | + /** |
|
287 | + * AdminConfig@edit |
|
288 | + */ |
|
289 | + public function edit() { |
|
290 | + $ga_id = Filter::getInteger('ga_id'); |
|
291 | + $ga = $this->provider->getGeoAnalysis($ga_id, false); |
|
292 | 292 | |
293 | - $this->renderEdit($ga); |
|
294 | - } |
|
293 | + $this->renderEdit($ga); |
|
294 | + } |
|
295 | 295 | |
296 | - /** |
|
297 | - * AdminConfig@add |
|
298 | - */ |
|
299 | - public function add() { |
|
300 | - $this->renderEdit(null); |
|
301 | - } |
|
296 | + /** |
|
297 | + * AdminConfig@add |
|
298 | + */ |
|
299 | + public function add() { |
|
300 | + $this->renderEdit(null); |
|
301 | + } |
|
302 | 302 | |
303 | - /** |
|
304 | - * AdminConfig@save |
|
305 | - */ |
|
306 | - public function save() { |
|
307 | - $wt_tree = Globals::getTree(); |
|
308 | - $tmp_contrl = new PageController(); |
|
309 | - $tmp_contrl->restrictAccess( |
|
310 | - Auth::isManager($wt_tree) |
|
311 | - && Filter::checkCsrf() |
|
312 | - ); |
|
303 | + /** |
|
304 | + * AdminConfig@save |
|
305 | + */ |
|
306 | + public function save() { |
|
307 | + $wt_tree = Globals::getTree(); |
|
308 | + $tmp_contrl = new PageController(); |
|
309 | + $tmp_contrl->restrictAccess( |
|
310 | + Auth::isManager($wt_tree) |
|
311 | + && Filter::checkCsrf() |
|
312 | + ); |
|
313 | 313 | |
314 | - $ga_id = Filter::postInteger('ga_id'); |
|
315 | - $description = Filter::post('description'); |
|
316 | - $analysislevel = Filter::postInteger('analysislevel'); |
|
317 | - $use_map = Filter::postBool('use_map'); |
|
318 | - if($use_map) { |
|
319 | - $map_file = base64_decode(Filter::post('map_file')); |
|
320 | - $map_top_level = Filter::postInteger('map_top_level'); |
|
321 | - } |
|
322 | - $use_flags = Filter::postBool('use_flags'); |
|
323 | - $gen_details = Filter::postInteger('gen_details'); |
|
314 | + $ga_id = Filter::postInteger('ga_id'); |
|
315 | + $description = Filter::post('description'); |
|
316 | + $analysislevel = Filter::postInteger('analysislevel'); |
|
317 | + $use_map = Filter::postBool('use_map'); |
|
318 | + if($use_map) { |
|
319 | + $map_file = base64_decode(Filter::post('map_file')); |
|
320 | + $map_top_level = Filter::postInteger('map_top_level'); |
|
321 | + } |
|
322 | + $use_flags = Filter::postBool('use_flags'); |
|
323 | + $gen_details = Filter::postInteger('gen_details'); |
|
324 | 324 | |
325 | - $success = false; |
|
326 | - if($ga_id) { |
|
327 | - $ga = $this->provider->getGeoAnalysis($ga_id, false); |
|
328 | - if($ga) { |
|
329 | - $ga->setTitle($description); |
|
330 | - $ga->setAnalysisLevel($analysislevel + 1); |
|
331 | - $options = $ga->getOptions(); |
|
332 | - if($options) { |
|
333 | - $options->setUsingFlags($use_flags); |
|
334 | - $options->setMaxDetailsInGen($gen_details); |
|
335 | - if($use_map) { |
|
336 | - $options->setMap(new OutlineMap($map_file)); |
|
337 | - $options->setMapLevel($map_top_level + 1); |
|
338 | - } |
|
339 | - else { |
|
340 | - $options->setMap(null); |
|
341 | - } |
|
342 | - } |
|
325 | + $success = false; |
|
326 | + if($ga_id) { |
|
327 | + $ga = $this->provider->getGeoAnalysis($ga_id, false); |
|
328 | + if($ga) { |
|
329 | + $ga->setTitle($description); |
|
330 | + $ga->setAnalysisLevel($analysislevel + 1); |
|
331 | + $options = $ga->getOptions(); |
|
332 | + if($options) { |
|
333 | + $options->setUsingFlags($use_flags); |
|
334 | + $options->setMaxDetailsInGen($gen_details); |
|
335 | + if($use_map) { |
|
336 | + $options->setMap(new OutlineMap($map_file)); |
|
337 | + $options->setMapLevel($map_top_level + 1); |
|
338 | + } |
|
339 | + else { |
|
340 | + $options->setMap(null); |
|
341 | + } |
|
342 | + } |
|
343 | 343 | |
344 | 344 | $res = $this->provider->updateGeoAnalysis($ga); |
345 | 345 | if($res) { |
@@ -352,8 +352,8 @@ discard block |
||
352 | 352 | FlashMessages::addMessage(I18N::translate('An error occured while updating the geographical dispersion analysis “%s”', $ga->getTitle()), 'danger'); |
353 | 353 | Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID “'. $ga->getId() .'” could not be updated. See error log.'); |
354 | 354 | } |
355 | - } |
|
356 | - } else { |
|
355 | + } |
|
356 | + } else { |
|
357 | 357 | $ga = $this->provider->createGeoAnalysis( |
358 | 358 | $description, |
359 | 359 | $analysislevel + 1, |
@@ -371,33 +371,33 @@ discard block |
||
371 | 371 | FlashMessages::addMessage(I18N::translate('An error occured while adding the geographical dispersion analysis “%s”', $description), 'danger'); |
372 | 372 | Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis “'.$description.'” could not be added. See error log.'); |
373 | 373 | } |
374 | - } |
|
374 | + } |
|
375 | 375 | |
376 | - $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $wt_tree->getNameUrl(); |
|
377 | - if(!$success) { |
|
378 | - if($ga) { |
|
379 | - $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig@edit&ga_id='. $ga->getId() .'&ged=' . $wt_tree->getNameUrl(); |
|
380 | - } |
|
381 | - else { |
|
382 | - $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig@add&ged=' . $wt_tree->getNameUrl(); |
|
383 | - } |
|
384 | - } |
|
385 | - header('Location: ' . WT_BASE_URL . $redirection_url); |
|
376 | + $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $wt_tree->getNameUrl(); |
|
377 | + if(!$success) { |
|
378 | + if($ga) { |
|
379 | + $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig@edit&ga_id='. $ga->getId() .'&ged=' . $wt_tree->getNameUrl(); |
|
380 | + } |
|
381 | + else { |
|
382 | + $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig@add&ged=' . $wt_tree->getNameUrl(); |
|
383 | + } |
|
384 | + } |
|
385 | + header('Location: ' . WT_BASE_URL . $redirection_url); |
|
386 | 386 | |
387 | - } |
|
387 | + } |
|
388 | 388 | |
389 | 389 | /** |
390 | 390 | * Renders the edit form, whether it is an edition of an existing GeoAnalysis, or the addition of a new one. |
391 | 391 | * |
392 | 392 | * @param (GeoAnalysis!null) $ga GeoAnalysis to edit |
393 | 393 | */ |
394 | - protected function renderEdit(GeoAnalysis $ga = null) { |
|
395 | - $wt_tree = Globals::getTree(); |
|
396 | - Theme::theme(new AdministrationTheme)->init($wt_tree); |
|
397 | - $controller = new PageController(); |
|
398 | - $controller |
|
399 | - ->restrictAccess(Auth::isManager($wt_tree)) |
|
400 | - ->addInlineJavascript(' |
|
394 | + protected function renderEdit(GeoAnalysis $ga = null) { |
|
395 | + $wt_tree = Globals::getTree(); |
|
396 | + Theme::theme(new AdministrationTheme)->init($wt_tree); |
|
397 | + $controller = new PageController(); |
|
398 | + $controller |
|
399 | + ->restrictAccess(Auth::isManager($wt_tree)) |
|
400 | + ->addInlineJavascript(' |
|
401 | 401 | function toggleMapOptions() { |
402 | 402 | if($("input:radio[name=\'use_map\']:checked").val() == 1) { |
403 | 403 | $("#map_options").show(); |
@@ -411,34 +411,34 @@ discard block |
||
411 | 411 | toggleMapOptions(); |
412 | 412 | '); |
413 | 413 | |
414 | - $data = new ViewBag(); |
|
415 | - if($ga) { |
|
416 | - $controller->setPageTitle(I18N::translate('Edit the geographical dispersion analysis')); |
|
417 | - $data->set('geo_analysis', $ga); |
|
418 | - } else { |
|
419 | - $controller->setPageTitle(I18N::translate('Add a geographical dispersion analysis')); |
|
420 | - } |
|
414 | + $data = new ViewBag(); |
|
415 | + if($ga) { |
|
416 | + $controller->setPageTitle(I18N::translate('Edit the geographical dispersion analysis')); |
|
417 | + $data->set('geo_analysis', $ga); |
|
418 | + } else { |
|
419 | + $controller->setPageTitle(I18N::translate('Add a geographical dispersion analysis')); |
|
420 | + } |
|
421 | 421 | |
422 | - $data->set('title', $controller->getPageTitle()); |
|
423 | - $data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $wt_tree->getNameUrl()); |
|
424 | - $data->set('module_title', $this->module->getTitle()); |
|
425 | - $data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig@save&ged=' . $wt_tree->getNameUrl()); |
|
426 | - $data->set('places_hierarchy', $this->provider->getPlacesHierarchy()); |
|
422 | + $data->set('title', $controller->getPageTitle()); |
|
423 | + $data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $wt_tree->getNameUrl()); |
|
424 | + $data->set('module_title', $this->module->getTitle()); |
|
425 | + $data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig@save&ged=' . $wt_tree->getNameUrl()); |
|
426 | + $data->set('places_hierarchy', $this->provider->getPlacesHierarchy()); |
|
427 | 427 | |
428 | - $map_list = array_map( |
|
429 | - function(OutlineMap $map) { |
|
430 | - return $map->getDescription(); |
|
431 | - }, |
|
432 | - $this->provider->getOutlineMapsList() |
|
433 | - ); |
|
434 | - asort($map_list); |
|
435 | - $data->set('map_list', $map_list); |
|
428 | + $map_list = array_map( |
|
429 | + function(OutlineMap $map) { |
|
430 | + return $map->getDescription(); |
|
431 | + }, |
|
432 | + $this->provider->getOutlineMapsList() |
|
433 | + ); |
|
434 | + asort($map_list); |
|
435 | + $data->set('map_list', $map_list); |
|
436 | 436 | |
437 | - $gen_details = array(0 => I18N::translate('All')); |
|
438 | - for($i = 1; $i <= 10 ; $i++) $gen_details[$i] = $i; |
|
439 | - $data->set('generation_details', $gen_details); |
|
437 | + $gen_details = array(0 => I18N::translate('All')); |
|
438 | + for($i = 1; $i <= 10 ; $i++) $gen_details[$i] = $i; |
|
439 | + $data->set('generation_details', $gen_details); |
|
440 | 440 | |
441 | - ViewFactory::make('GeoAnalysisEdit', $this, $controller, $data)->render(); |
|
442 | - } |
|
441 | + ViewFactory::make('GeoAnalysisEdit', $this, $controller, $data)->render(); |
|
442 | + } |
|
443 | 443 | |
444 | 444 | } |
445 | 445 | \ No newline at end of file |
@@ -22,389 +22,389 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class SosaProvider { |
24 | 24 | |
25 | - /** |
|
26 | - * Maximum number of generation the database is able to hold. |
|
27 | - * @var int MAX_DB_GENERATIONS |
|
28 | - */ |
|
29 | - const MAX_DB_GENERATIONS = 64; |
|
30 | - |
|
31 | - /** |
|
32 | - * System's default user (ID -1 in the database |
|
33 | - * @var User $default_user |
|
34 | - */ |
|
35 | - protected static $default_user; |
|
36 | - |
|
37 | - /** |
|
38 | - * Reference user |
|
39 | - * @var User $user |
|
40 | - */ |
|
41 | - protected $user; |
|
42 | - |
|
43 | - /** |
|
44 | - * Reference tree |
|
45 | - * @var Tree $tree |
|
46 | - */ |
|
47 | - protected $tree; |
|
48 | - |
|
49 | - /** |
|
50 | - * Cached list of Sosa Individuals by generation |
|
51 | - * Format: key = generation, value = array ( sosa => Individual ID) |
|
52 | - * @var array $sosa_list_by_gen |
|
53 | - */ |
|
54 | - protected $sosa_list_by_gen; |
|
55 | - |
|
56 | - /** |
|
57 | - * Cached list of Sosa Families by generation |
|
58 | - * Format: key = generation, value = array ( sosa => Family ID) |
|
59 | - * @var unknown $sosa_fam_list_by_gen |
|
60 | - */ |
|
61 | - protected $sosa_fam_list_by_gen; |
|
62 | - |
|
63 | - /** |
|
64 | - * Cached array of statistics by generation |
|
65 | - * Format: key = generation, |
|
66 | - * value = array( |
|
67 | - * sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth |
|
68 | - * ) |
|
69 | - * @var array $statistics_tab |
|
70 | - */ |
|
71 | - protected $statistics_tab; |
|
72 | - |
|
73 | - /** |
|
74 | - * Has the provider's initialisation completed |
|
75 | - * @var bool $is_setup |
|
76 | - */ |
|
77 | - protected $is_setup; |
|
78 | - |
|
79 | - /** |
|
80 | - * Constructor for Sosa Provider. |
|
81 | - * A provider is defined in relation to a specific tree and reference user. |
|
82 | - * |
|
83 | - * @param Tree $tree |
|
84 | - * @param User $user |
|
85 | - */ |
|
86 | - public function __construct(Tree $tree, User $user = null) { |
|
87 | - if(self::$default_user === null) |
|
88 | - self::$default_user = User::find(-1); |
|
25 | + /** |
|
26 | + * Maximum number of generation the database is able to hold. |
|
27 | + * @var int MAX_DB_GENERATIONS |
|
28 | + */ |
|
29 | + const MAX_DB_GENERATIONS = 64; |
|
30 | + |
|
31 | + /** |
|
32 | + * System's default user (ID -1 in the database |
|
33 | + * @var User $default_user |
|
34 | + */ |
|
35 | + protected static $default_user; |
|
36 | + |
|
37 | + /** |
|
38 | + * Reference user |
|
39 | + * @var User $user |
|
40 | + */ |
|
41 | + protected $user; |
|
42 | + |
|
43 | + /** |
|
44 | + * Reference tree |
|
45 | + * @var Tree $tree |
|
46 | + */ |
|
47 | + protected $tree; |
|
48 | + |
|
49 | + /** |
|
50 | + * Cached list of Sosa Individuals by generation |
|
51 | + * Format: key = generation, value = array ( sosa => Individual ID) |
|
52 | + * @var array $sosa_list_by_gen |
|
53 | + */ |
|
54 | + protected $sosa_list_by_gen; |
|
55 | + |
|
56 | + /** |
|
57 | + * Cached list of Sosa Families by generation |
|
58 | + * Format: key = generation, value = array ( sosa => Family ID) |
|
59 | + * @var unknown $sosa_fam_list_by_gen |
|
60 | + */ |
|
61 | + protected $sosa_fam_list_by_gen; |
|
62 | + |
|
63 | + /** |
|
64 | + * Cached array of statistics by generation |
|
65 | + * Format: key = generation, |
|
66 | + * value = array( |
|
67 | + * sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth |
|
68 | + * ) |
|
69 | + * @var array $statistics_tab |
|
70 | + */ |
|
71 | + protected $statistics_tab; |
|
72 | + |
|
73 | + /** |
|
74 | + * Has the provider's initialisation completed |
|
75 | + * @var bool $is_setup |
|
76 | + */ |
|
77 | + protected $is_setup; |
|
78 | + |
|
79 | + /** |
|
80 | + * Constructor for Sosa Provider. |
|
81 | + * A provider is defined in relation to a specific tree and reference user. |
|
82 | + * |
|
83 | + * @param Tree $tree |
|
84 | + * @param User $user |
|
85 | + */ |
|
86 | + public function __construct(Tree $tree, User $user = null) { |
|
87 | + if(self::$default_user === null) |
|
88 | + self::$default_user = User::find(-1); |
|
89 | 89 | |
90 | - $this->tree = $tree; |
|
91 | - $this->user = $user; |
|
92 | - $this->is_setup = true; |
|
93 | - if($this->user === null) $this->user = Auth::user(); |
|
94 | - if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
90 | + $this->tree = $tree; |
|
91 | + $this->user = $user; |
|
92 | + $this->is_setup = true; |
|
93 | + if($this->user === null) $this->user = Auth::user(); |
|
94 | + if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
95 | 95 | |
96 | - // Check if the user, or the default user, has a root already setup; |
|
97 | - if(empty($this->getRootIndiId())) { |
|
98 | - if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | - $this->is_setup = false; |
|
100 | - } |
|
101 | - else { |
|
102 | - $this->user = self::$default_user; |
|
103 | - $this->is_setup = $this->getRootIndiId() === null; |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns is the Provider has been successfully set up |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isSetup() { |
|
113 | - return $this->is_setup; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Return the root individual ID for the reference tree and user. |
|
118 | - * @return string Individual ID |
|
119 | - */ |
|
120 | - public function getRootIndiId() { |
|
121 | - return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Return the root individual for the reference tree and user. |
|
126 | - * @return Individual Individual |
|
127 | - */ |
|
128 | - public function getRootIndi() { |
|
129 | - $root_indi_id = $this->getRootIndiId(); |
|
130 | - if(!empty($root_indi_id)) { |
|
131 | - return Individual::getInstance($root_indi_id, $this->tree); |
|
132 | - } |
|
133 | - return null; |
|
134 | - } |
|
96 | + // Check if the user, or the default user, has a root already setup; |
|
97 | + if(empty($this->getRootIndiId())) { |
|
98 | + if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | + $this->is_setup = false; |
|
100 | + } |
|
101 | + else { |
|
102 | + $this->user = self::$default_user; |
|
103 | + $this->is_setup = $this->getRootIndiId() === null; |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns is the Provider has been successfully set up |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isSetup() { |
|
113 | + return $this->is_setup; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Return the root individual ID for the reference tree and user. |
|
118 | + * @return string Individual ID |
|
119 | + */ |
|
120 | + public function getRootIndiId() { |
|
121 | + return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Return the root individual for the reference tree and user. |
|
126 | + * @return Individual Individual |
|
127 | + */ |
|
128 | + public function getRootIndi() { |
|
129 | + $root_indi_id = $this->getRootIndiId(); |
|
130 | + if(!empty($root_indi_id)) { |
|
131 | + return Individual::getInstance($root_indi_id, $this->tree); |
|
132 | + } |
|
133 | + return null; |
|
134 | + } |
|
135 | 135 | |
136 | - /***************** |
|
136 | + /***************** |
|
137 | 137 | * DATA CRUD LAYER |
138 | 138 | *****************/ |
139 | 139 | |
140 | - /** |
|
141 | - * Remove all Sosa entries related to the gedcom file and user |
|
142 | - */ |
|
143 | - public function deleteAll() { |
|
144 | - if(!$this->is_setup) return; |
|
145 | - Database::prepare( |
|
146 | - 'DELETE FROM `##maj_sosa`'. |
|
147 | - ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
148 | - ->execute(array( |
|
149 | - 'tree_id' => $this->tree->getTreeId(), |
|
150 | - 'user_id' => $this->user->getUserId() |
|
151 | - )); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Remove all ancestors of a sosa number |
|
156 | - * |
|
157 | - * @param int $sosa |
|
158 | - */ |
|
159 | - public function deleteAncestors($sosa) { |
|
160 | - if(!$this->is_setup) return; |
|
161 | - $gen = Functions::getGeneration($sosa); |
|
162 | - Database::prepare( |
|
163 | - 'DELETE FROM `##maj_sosa`'. |
|
164 | - ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | - ' AND majs_gen >= :gen' . |
|
166 | - ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
167 | - )->execute(array( |
|
168 | - 'tree_id' => $this->tree->getTreeId(), |
|
169 | - 'user_id' => $this->user->getUserId(), |
|
170 | - 'gen' => $gen, |
|
171 | - 'sosa' => $sosa |
|
172 | - )); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Insert (or update if already existing) a list of Sosa individuals |
|
177 | - * @param array $sosa_records |
|
178 | - */ |
|
179 | - public function insertOrUpdate($sosa_records) { |
|
180 | - if(!$this->is_setup) return; |
|
140 | + /** |
|
141 | + * Remove all Sosa entries related to the gedcom file and user |
|
142 | + */ |
|
143 | + public function deleteAll() { |
|
144 | + if(!$this->is_setup) return; |
|
145 | + Database::prepare( |
|
146 | + 'DELETE FROM `##maj_sosa`'. |
|
147 | + ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
148 | + ->execute(array( |
|
149 | + 'tree_id' => $this->tree->getTreeId(), |
|
150 | + 'user_id' => $this->user->getUserId() |
|
151 | + )); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Remove all ancestors of a sosa number |
|
156 | + * |
|
157 | + * @param int $sosa |
|
158 | + */ |
|
159 | + public function deleteAncestors($sosa) { |
|
160 | + if(!$this->is_setup) return; |
|
161 | + $gen = Functions::getGeneration($sosa); |
|
162 | + Database::prepare( |
|
163 | + 'DELETE FROM `##maj_sosa`'. |
|
164 | + ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | + ' AND majs_gen >= :gen' . |
|
166 | + ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
167 | + )->execute(array( |
|
168 | + 'tree_id' => $this->tree->getTreeId(), |
|
169 | + 'user_id' => $this->user->getUserId(), |
|
170 | + 'gen' => $gen, |
|
171 | + 'sosa' => $sosa |
|
172 | + )); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Insert (or update if already existing) a list of Sosa individuals |
|
177 | + * @param array $sosa_records |
|
178 | + */ |
|
179 | + public function insertOrUpdate($sosa_records) { |
|
180 | + if(!$this->is_setup) return; |
|
181 | 181 | |
182 | - $treeid = $this->tree->getTreeId(); |
|
183 | - $userid = $this->user->getUserId(); |
|
184 | - $questionmarks_table = array(); |
|
185 | - $values_table = array(); |
|
182 | + $treeid = $this->tree->getTreeId(); |
|
183 | + $userid = $this->user->getUserId(); |
|
184 | + $questionmarks_table = array(); |
|
185 | + $values_table = array(); |
|
186 | 186 | |
187 | - $i = 0; |
|
188 | - foreach ($sosa_records as $row) { |
|
189 | - $gen = Functions::getGeneration($row['sosa']); |
|
190 | - if($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | - $questionmarks_table[] = |
|
192 | - '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
193 | - $values_table = array_merge( |
|
194 | - $values_table, |
|
195 | - array( |
|
196 | - 'tree_id'.$i => $treeid, |
|
197 | - 'user_id'.$i => $userid, |
|
198 | - 'sosa'.$i => $row['sosa'], |
|
199 | - 'indi_id'.$i => $row['indi'], |
|
200 | - 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
201 | - 'byear'.$i => $row['birth_year'], |
|
202 | - 'dyear'.$i => $row['death_year'] |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - $i++; |
|
207 | - } |
|
187 | + $i = 0; |
|
188 | + foreach ($sosa_records as $row) { |
|
189 | + $gen = Functions::getGeneration($row['sosa']); |
|
190 | + if($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | + $questionmarks_table[] = |
|
192 | + '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
193 | + $values_table = array_merge( |
|
194 | + $values_table, |
|
195 | + array( |
|
196 | + 'tree_id'.$i => $treeid, |
|
197 | + 'user_id'.$i => $userid, |
|
198 | + 'sosa'.$i => $row['sosa'], |
|
199 | + 'indi_id'.$i => $row['indi'], |
|
200 | + 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
201 | + 'byear'.$i => $row['birth_year'], |
|
202 | + 'dyear'.$i => $row['death_year'] |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + $i++; |
|
207 | + } |
|
208 | 208 | |
209 | - $sql = 'REPLACE INTO `##maj_sosa`' . |
|
210 | - ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
211 | - ' VALUES '. implode(',', $questionmarks_table); |
|
212 | - Database::prepare($sql)->execute($values_table); |
|
213 | - } |
|
209 | + $sql = 'REPLACE INTO `##maj_sosa`' . |
|
210 | + ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
211 | + ' VALUES '. implode(',', $questionmarks_table); |
|
212 | + Database::prepare($sql)->execute($values_table); |
|
213 | + } |
|
214 | 214 | |
215 | - /**************** |
|
215 | + /**************** |
|
216 | 216 | * SIMPLE QUERIES |
217 | 217 | ****************/ |
218 | 218 | |
219 | - /** |
|
220 | - * Returns the list of Sosa numbers to which an individual is related. |
|
221 | - * Format: key = sosa number, value = generation for the Sosa number |
|
222 | - * |
|
223 | - * @param Individual $indi |
|
224 | - * @return array Array of sosa numbers |
|
225 | - */ |
|
226 | - public function getSosaNumbers(Individual $indi) { |
|
227 | - if(!$this->is_setup) return array(); |
|
228 | - return Database::prepare( |
|
229 | - 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
230 | - ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
231 | - )->execute(array( |
|
232 | - 'indi_id' => $indi->getXref(), |
|
233 | - 'tree_id' => $this->tree->getTreeId(), |
|
234 | - 'user_id' => $this->user->getUserId() |
|
235 | - ))->fetchAssoc(); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Get the last generation of Sosa ancestors |
|
240 | - * |
|
241 | - * @return number Last generation if found, 1 otherwise |
|
242 | - */ |
|
243 | - public function getLastGeneration() { |
|
244 | - if(!$this->is_setup) return; |
|
245 | - return Database::prepare( |
|
246 | - 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
247 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
248 | - )->execute(array( |
|
249 | - 'tree_id' => $this->tree->getTreeId(), |
|
250 | - 'user_id' => $this->user->getUserId() |
|
251 | - ))->fetchOne() ?: 1; |
|
252 | - } |
|
253 | - |
|
254 | - /************* |
|
219 | + /** |
|
220 | + * Returns the list of Sosa numbers to which an individual is related. |
|
221 | + * Format: key = sosa number, value = generation for the Sosa number |
|
222 | + * |
|
223 | + * @param Individual $indi |
|
224 | + * @return array Array of sosa numbers |
|
225 | + */ |
|
226 | + public function getSosaNumbers(Individual $indi) { |
|
227 | + if(!$this->is_setup) return array(); |
|
228 | + return Database::prepare( |
|
229 | + 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
230 | + ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
231 | + )->execute(array( |
|
232 | + 'indi_id' => $indi->getXref(), |
|
233 | + 'tree_id' => $this->tree->getTreeId(), |
|
234 | + 'user_id' => $this->user->getUserId() |
|
235 | + ))->fetchAssoc(); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Get the last generation of Sosa ancestors |
|
240 | + * |
|
241 | + * @return number Last generation if found, 1 otherwise |
|
242 | + */ |
|
243 | + public function getLastGeneration() { |
|
244 | + if(!$this->is_setup) return; |
|
245 | + return Database::prepare( |
|
246 | + 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
247 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
248 | + )->execute(array( |
|
249 | + 'tree_id' => $this->tree->getTreeId(), |
|
250 | + 'user_id' => $this->user->getUserId() |
|
251 | + ))->fetchOne() ?: 1; |
|
252 | + } |
|
253 | + |
|
254 | + /************* |
|
255 | 255 | * SOSA LISTS |
256 | 256 | *************/ |
257 | 257 | |
258 | - /** |
|
259 | - * Return the list of all sosas, with the generations it belongs to |
|
260 | - * |
|
261 | - * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
262 | - */ |
|
263 | - public function getAllSosaWithGenerations(){ |
|
264 | - if(!$this->is_setup) return array(); |
|
265 | - return Database::prepare( |
|
266 | - 'SELECT majs_i_id AS indi,' . |
|
267 | - ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
268 | - ' FROM `##maj_sosa`' . |
|
269 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
270 | - ' GROUP BY majs_i_id' |
|
271 | - )->execute(array( |
|
272 | - 'tree_id' => $this->tree->getTreeId(), |
|
273 | - 'user_id' => $this->user->getUserId() |
|
274 | - ))->fetchAssoc(); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
279 | - * |
|
280 | - * @param number $gen Generation |
|
281 | - * @return array Array of Sosa individuals |
|
282 | - */ |
|
283 | - public function getSosaListAtGeneration($gen){ |
|
284 | - if(!$this->is_setup) return array(); |
|
285 | - if(!$this->sosa_list_by_gen) |
|
286 | - $this->sosa_list_by_gen = array(); |
|
258 | + /** |
|
259 | + * Return the list of all sosas, with the generations it belongs to |
|
260 | + * |
|
261 | + * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
262 | + */ |
|
263 | + public function getAllSosaWithGenerations(){ |
|
264 | + if(!$this->is_setup) return array(); |
|
265 | + return Database::prepare( |
|
266 | + 'SELECT majs_i_id AS indi,' . |
|
267 | + ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
268 | + ' FROM `##maj_sosa`' . |
|
269 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
270 | + ' GROUP BY majs_i_id' |
|
271 | + )->execute(array( |
|
272 | + 'tree_id' => $this->tree->getTreeId(), |
|
273 | + 'user_id' => $this->user->getUserId() |
|
274 | + ))->fetchAssoc(); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
279 | + * |
|
280 | + * @param number $gen Generation |
|
281 | + * @return array Array of Sosa individuals |
|
282 | + */ |
|
283 | + public function getSosaListAtGeneration($gen){ |
|
284 | + if(!$this->is_setup) return array(); |
|
285 | + if(!$this->sosa_list_by_gen) |
|
286 | + $this->sosa_list_by_gen = array(); |
|
287 | 287 | |
288 | - if($gen){ |
|
289 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
290 | - $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
291 | - 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
292 | - ' FROM `##maj_sosa`'. |
|
293 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
294 | - ' AND majs_gen = :gen'. |
|
295 | - ' ORDER BY majs_sosa ASC') |
|
296 | - ->execute(array( |
|
297 | - 'tree_id' => $this->tree->getTreeId(), |
|
298 | - 'user_id' => $this->user->getUserId(), |
|
299 | - 'gen' => $gen |
|
300 | - )) |
|
301 | - ->fetchAssoc(); |
|
302 | - } |
|
303 | - return $this->sosa_list_by_gen[$gen]; |
|
304 | - } |
|
305 | - return array(); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
310 | - * |
|
311 | - * @param number $gen Generation |
|
312 | - * @return array Array of Sosa families |
|
313 | - */ |
|
314 | - public function getFamilySosaListAtGeneration($gen){ |
|
315 | - if(!$this->is_setup) return array(); |
|
316 | - if(!$this->sosa_fam_list_by_gen) |
|
317 | - $this->sosa_fam_list_by_gen = array(); |
|
288 | + if($gen){ |
|
289 | + if(!isset($this->sosa_list_by_gen[$gen])){ |
|
290 | + $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
291 | + 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
292 | + ' FROM `##maj_sosa`'. |
|
293 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
294 | + ' AND majs_gen = :gen'. |
|
295 | + ' ORDER BY majs_sosa ASC') |
|
296 | + ->execute(array( |
|
297 | + 'tree_id' => $this->tree->getTreeId(), |
|
298 | + 'user_id' => $this->user->getUserId(), |
|
299 | + 'gen' => $gen |
|
300 | + )) |
|
301 | + ->fetchAssoc(); |
|
302 | + } |
|
303 | + return $this->sosa_list_by_gen[$gen]; |
|
304 | + } |
|
305 | + return array(); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
310 | + * |
|
311 | + * @param number $gen Generation |
|
312 | + * @return array Array of Sosa families |
|
313 | + */ |
|
314 | + public function getFamilySosaListAtGeneration($gen){ |
|
315 | + if(!$this->is_setup) return array(); |
|
316 | + if(!$this->sosa_fam_list_by_gen) |
|
317 | + $this->sosa_fam_list_by_gen = array(); |
|
318 | 318 | |
319 | - if($gen){ |
|
320 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
321 | - $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
322 | - 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
323 | - ' FROM `##families`'. |
|
324 | - ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
325 | - ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
326 | - ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
327 | - ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
328 | - ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
329 | - ' AND s1.majs_gen = :gen'. |
|
330 | - ' ORDER BY s1.majs_sosa ASC' |
|
331 | - ) |
|
332 | - ->execute(array( |
|
333 | - 'tree_id' => $this->tree->getTreeId(), |
|
334 | - 'user_id' => $this->user->getUserId(), |
|
335 | - 'gen' => $gen |
|
336 | - )) |
|
337 | - ->fetchAssoc(); |
|
338 | - } |
|
339 | - return $this->sosa_fam_list_by_gen[$gen]; |
|
340 | - } |
|
341 | - return array(); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
346 | - * |
|
347 | - * @param number $gen Generation |
|
348 | - * @return array Array of Sosa individuals |
|
349 | - */ |
|
350 | - public function getMissingSosaListAtGeneration($gen){ |
|
351 | - if(!$this->is_setup) return array(); |
|
352 | - if($gen){ |
|
353 | - return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
354 | - 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
|
355 | - ' FROM `##maj_sosa` schild'. |
|
356 | - ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'. |
|
357 | - ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'. |
|
358 | - ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
359 | - ' AND schild.majs_gen = :gen'. |
|
360 | - ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
361 | - ' ORDER BY schild.majs_sosa ASC') |
|
362 | - ->execute(array( |
|
363 | - 'tree_id' => $this->tree->getTreeId(), |
|
364 | - 'user_id' => $this->user->getUserId(), |
|
365 | - 'gen' => $gen - 1 |
|
366 | - ))->fetchAll(\PDO::FETCH_ASSOC); |
|
367 | - } |
|
368 | - return array(); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /************* |
|
319 | + if($gen){ |
|
320 | + if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
321 | + $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
322 | + 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
323 | + ' FROM `##families`'. |
|
324 | + ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
325 | + ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
326 | + ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
327 | + ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
328 | + ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
329 | + ' AND s1.majs_gen = :gen'. |
|
330 | + ' ORDER BY s1.majs_sosa ASC' |
|
331 | + ) |
|
332 | + ->execute(array( |
|
333 | + 'tree_id' => $this->tree->getTreeId(), |
|
334 | + 'user_id' => $this->user->getUserId(), |
|
335 | + 'gen' => $gen |
|
336 | + )) |
|
337 | + ->fetchAssoc(); |
|
338 | + } |
|
339 | + return $this->sosa_fam_list_by_gen[$gen]; |
|
340 | + } |
|
341 | + return array(); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
346 | + * |
|
347 | + * @param number $gen Generation |
|
348 | + * @return array Array of Sosa individuals |
|
349 | + */ |
|
350 | + public function getMissingSosaListAtGeneration($gen){ |
|
351 | + if(!$this->is_setup) return array(); |
|
352 | + if($gen){ |
|
353 | + return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
354 | + 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
|
355 | + ' FROM `##maj_sosa` schild'. |
|
356 | + ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'. |
|
357 | + ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'. |
|
358 | + ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
359 | + ' AND schild.majs_gen = :gen'. |
|
360 | + ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
361 | + ' ORDER BY schild.majs_sosa ASC') |
|
362 | + ->execute(array( |
|
363 | + 'tree_id' => $this->tree->getTreeId(), |
|
364 | + 'user_id' => $this->user->getUserId(), |
|
365 | + 'gen' => $gen - 1 |
|
366 | + ))->fetchAll(\PDO::FETCH_ASSOC); |
|
367 | + } |
|
368 | + return array(); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /************* |
|
374 | 374 | * STATISTICS |
375 | 375 | *************/ |
376 | - /** |
|
377 | - * Get the statistic array detailed by generation. |
|
378 | - * Statistics for each generation are: |
|
379 | - * - The number of Sosa in generation |
|
380 | - * - The number of Sosa up to generation |
|
381 | - * - The number of distinct Sosa up to generation |
|
382 | - * - The year of the first birth in generation |
|
383 | - * - The year of the last birth in generation |
|
384 | - * - The average year of birth in generation |
|
385 | - * |
|
386 | - * @return array Statistics array |
|
387 | - */ |
|
388 | - public function getStatisticsByGeneration() { |
|
389 | - if(!$this->is_setup) return array(); |
|
390 | - if(!$this->statistics_tab) { |
|
391 | - $this->statistics_tab = array(); |
|
392 | - if($maxGeneration = $this->getLastGeneration()) { |
|
393 | - for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
394 | - $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
395 | - $this->statistics_tab[$gen] = array( |
|
396 | - 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
397 | - 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
398 | - 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
399 | - 'firstBirth' => $birthStats['first'], |
|
400 | - 'lastBirth' => $birthStats['last'], |
|
401 | - 'avgBirth' => $birthStats['avg'] |
|
402 | - ); |
|
403 | - } |
|
404 | - } |
|
405 | - } |
|
406 | - return $this->statistics_tab; |
|
407 | - } |
|
376 | + /** |
|
377 | + * Get the statistic array detailed by generation. |
|
378 | + * Statistics for each generation are: |
|
379 | + * - The number of Sosa in generation |
|
380 | + * - The number of Sosa up to generation |
|
381 | + * - The number of distinct Sosa up to generation |
|
382 | + * - The year of the first birth in generation |
|
383 | + * - The year of the last birth in generation |
|
384 | + * - The average year of birth in generation |
|
385 | + * |
|
386 | + * @return array Statistics array |
|
387 | + */ |
|
388 | + public function getStatisticsByGeneration() { |
|
389 | + if(!$this->is_setup) return array(); |
|
390 | + if(!$this->statistics_tab) { |
|
391 | + $this->statistics_tab = array(); |
|
392 | + if($maxGeneration = $this->getLastGeneration()) { |
|
393 | + for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
394 | + $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
395 | + $this->statistics_tab[$gen] = array( |
|
396 | + 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
397 | + 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
398 | + 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
399 | + 'firstBirth' => $birthStats['first'], |
|
400 | + 'lastBirth' => $birthStats['last'], |
|
401 | + 'avgBirth' => $birthStats['avg'] |
|
402 | + ); |
|
403 | + } |
|
404 | + } |
|
405 | + } |
|
406 | + return $this->statistics_tab; |
|
407 | + } |
|
408 | 408 | |
409 | 409 | /** |
410 | 410 | * How many individuals exist in the tree. |
@@ -412,258 +412,258 @@ discard block |
||
412 | 412 | * @return int |
413 | 413 | */ |
414 | 414 | public function getTotalIndividuals() { |
415 | - if(!$this->is_setup) return 0; |
|
416 | - return Database::prepare( |
|
417 | - 'SELECT COUNT(*) FROM `##individuals`' . |
|
418 | - ' WHERE i_file = :tree_id') |
|
419 | - ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
420 | - ->fetchOne() ?: 0; |
|
415 | + if(!$this->is_setup) return 0; |
|
416 | + return Database::prepare( |
|
417 | + 'SELECT COUNT(*) FROM `##individuals`' . |
|
418 | + ' WHERE i_file = :tree_id') |
|
419 | + ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
420 | + ->fetchOne() ?: 0; |
|
421 | + } |
|
422 | + |
|
423 | + /** |
|
424 | + * Get the total Sosa count for all generations |
|
425 | + * |
|
426 | + * @return number Number of Sosas |
|
427 | + */ |
|
428 | + public function getSosaCount(){ |
|
429 | + if(!$this->is_setup) return 0; |
|
430 | + return Database::prepare( |
|
431 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
432 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
433 | + ->execute(array( |
|
434 | + 'tree_id' => $this->tree->getTreeId(), |
|
435 | + 'user_id' => $this->user->getUserId() |
|
436 | + ))->fetchOne() ?: 0; |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * Get the number of Sosa in a specific generation. |
|
441 | + * |
|
442 | + * @param number $gen Generation |
|
443 | + * @return number Number of Sosas in generation |
|
444 | + */ |
|
445 | + public function getSosaCountAtGeneration($gen){ |
|
446 | + if(!$this->is_setup) return 0; |
|
447 | + return Database::prepare( |
|
448 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
449 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
450 | + ' AND majs_gen= :gen') |
|
451 | + ->execute(array( |
|
452 | + 'tree_id' => $this->tree->getTreeId(), |
|
453 | + 'user_id' => $this->user->getUserId(), |
|
454 | + 'gen' => $gen |
|
455 | + ))->fetchOne() ?: 0; |
|
421 | 456 | } |
422 | 457 | |
423 | - /** |
|
424 | - * Get the total Sosa count for all generations |
|
425 | - * |
|
426 | - * @return number Number of Sosas |
|
427 | - */ |
|
428 | - public function getSosaCount(){ |
|
429 | - if(!$this->is_setup) return 0; |
|
430 | - return Database::prepare( |
|
431 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
432 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
433 | - ->execute(array( |
|
434 | - 'tree_id' => $this->tree->getTreeId(), |
|
435 | - 'user_id' => $this->user->getUserId() |
|
436 | - ))->fetchOne() ?: 0; |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * Get the number of Sosa in a specific generation. |
|
441 | - * |
|
442 | - * @param number $gen Generation |
|
443 | - * @return number Number of Sosas in generation |
|
444 | - */ |
|
445 | - public function getSosaCountAtGeneration($gen){ |
|
446 | - if(!$this->is_setup) return 0; |
|
447 | - return Database::prepare( |
|
448 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
449 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
450 | - ' AND majs_gen= :gen') |
|
451 | - ->execute(array( |
|
452 | - 'tree_id' => $this->tree->getTreeId(), |
|
453 | - 'user_id' => $this->user->getUserId(), |
|
454 | - 'gen' => $gen |
|
455 | - ))->fetchOne() ?: 0; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Get the total number of Sosa up to a specific generation. |
|
460 | - * |
|
461 | - * @param number $gen Generation |
|
462 | - * @return number Total number of Sosas up to generation |
|
463 | - */ |
|
464 | - public function getSosaCountUpToGeneration($gen){ |
|
465 | - if(!$this->is_setup) return 0; |
|
466 | - return Database::prepare( |
|
467 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
468 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
469 | - ' AND majs_gen <= :gen') |
|
470 | - ->execute(array( |
|
471 | - 'tree_id' => $this->tree->getTreeId(), |
|
472 | - 'user_id' => $this->user->getUserId(), |
|
473 | - 'gen' => $gen |
|
474 | - ))->fetchOne() ?: 0; |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Get the total number of distinct Sosa individual for all generations. |
|
479 | - * |
|
480 | - * @return number Total number of distinct individual |
|
481 | - */ |
|
482 | - public function getDifferentSosaCount(){ |
|
483 | - if(!$this->is_setup) return 0; |
|
484 | - return Database::prepare( |
|
485 | - 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
486 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
487 | - ->execute(array( |
|
488 | - 'tree_id' => $this->tree->getTreeId(), |
|
489 | - 'user_id' => $this->user->getUserId() |
|
490 | - ))->fetchOne() ?: 0; |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Get the number of distinct Sosa individual up to a specific generation. |
|
495 | - * |
|
496 | - * @param number $gen Generation |
|
497 | - * @return number Number of distinct Sosa individuals up to generation |
|
498 | - */ |
|
499 | - public function getDifferentSosaCountUpToGeneration($gen){ |
|
500 | - if(!$this->is_setup) return 0; |
|
501 | - return Database::prepare( |
|
502 | - 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
503 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
504 | - ' AND majs_gen <= :gen') |
|
505 | - ->execute(array( |
|
506 | - 'tree_id' => $this->tree->getTreeId(), |
|
507 | - 'user_id' => $this->user->getUserId(), |
|
508 | - 'gen' => $gen |
|
509 | - ))->fetchOne() ?: 0; |
|
510 | - } |
|
511 | - |
|
512 | - /** |
|
513 | - * Get an array of birth statistics for a specific generation |
|
514 | - * Statistics are : |
|
515 | - * - first : First birth year in generation |
|
516 | - * - last : Last birth year in generation |
|
517 | - * - avg : Average birth year |
|
518 | - * |
|
519 | - * @param number $gen Generation |
|
520 | - * @return array Birth statistics array |
|
521 | - */ |
|
522 | - public function getStatsBirthYearInGeneration($gen){ |
|
523 | - if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
524 | - return Database::prepare( |
|
525 | - 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
|
526 | - ' FROM `##maj_sosa`' . |
|
527 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
528 | - ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
|
529 | - ->execute(array( |
|
530 | - 'tree_id' => $this->tree->getTreeId(), |
|
531 | - 'user_id' => $this->user->getUserId(), |
|
532 | - 'gen' => $gen, |
|
533 | - 'birth_year' => 0)) |
|
534 | - ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0); |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Get the mean generation time, based on a linear regression of birth years and generations |
|
539 | - * |
|
540 | - * @return number|NULL Mean generation time |
|
541 | - */ |
|
542 | - public function getMeanGenerationTime(){ |
|
543 | - if(!$this->is_setup) return; |
|
544 | - if(!$this->statistics_tab){ |
|
545 | - $this->getStatisticsByGeneration(); |
|
546 | - } |
|
547 | - //Linear regression on x=generation and y=birthdate |
|
548 | - $sum_xy = 0; |
|
549 | - $sum_x=0; |
|
550 | - $sum_y=0; |
|
551 | - $sum_x2=0; |
|
552 | - $n=count($this->statistics_tab); |
|
553 | - foreach($this->statistics_tab as $gen=>$stats){ |
|
554 | - $sum_xy+=$gen*$stats['avgBirth']; |
|
555 | - $sum_x+=$gen; |
|
556 | - $sum_y+=$stats['avgBirth']; |
|
557 | - $sum_x2+=$gen*$gen; |
|
558 | - } |
|
559 | - $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
560 | - if($denom!=0){ |
|
561 | - return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
562 | - } |
|
563 | - return null; |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
568 | - * at a specified generation. |
|
569 | - * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
570 | - * |
|
571 | - * Format: |
|
572 | - * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
573 | - * -1 is used for shared ancestors |
|
574 | - * For instance base2(0100) = base10(4) represent the maternal grand father |
|
575 | - * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
576 | - * |
|
577 | - * For instance a result at generation 3 could be : |
|
578 | - * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
579 | - * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
580 | - * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
581 | - * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
582 | - * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
583 | - * ) |
|
584 | - * |
|
585 | - * @param int $gen Reference generation |
|
586 | - * @return array |
|
587 | - */ |
|
588 | - public function getAncestorDispersionForGen($gen) { |
|
589 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
590 | - return Database::prepare( |
|
591 | - 'SELECT branches, count(i_id)'. |
|
592 | - ' FROM ('. |
|
593 | - ' SELECT i_id,'. |
|
594 | - ' CASE'. |
|
595 | - ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
596 | - ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
597 | - ' END branches'. |
|
598 | - ' FROM ('. |
|
599 | - ' SELECT DISTINCT majs_i_id i_id,'. |
|
600 | - ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
601 | - ' FROM `##maj_sosa`'. |
|
602 | - ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
603 | - ' AND majs_gen >= :gen'. |
|
604 | - ' ) indistat'. |
|
605 | - ' GROUP BY i_id'. |
|
606 | - ') grouped'. |
|
607 | - ' GROUP BY branches') |
|
608 | - ->execute(array( |
|
609 | - 'tree_id' => $this->tree->getTreeId(), |
|
610 | - 'user_id' => $this->user->getUserId(), |
|
611 | - 'gen' => $gen |
|
612 | - ))->fetchAssoc() ?: array(); |
|
613 | - } |
|
614 | - |
|
615 | - /** |
|
616 | - * Return an array of the most duplicated root Sosa ancestors. |
|
617 | - * The number of ancestors to return is limited by the parameter $limit. |
|
618 | - * If several individuals are tied when reaching the limit, none of them are returned, |
|
619 | - * which means that there can be less individuals returned than requested. |
|
620 | - * |
|
621 | - * Format: |
|
622 | - * - key : root Sosa individual |
|
623 | - * - value: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
624 | - * |
|
625 | - * @param number $limit Maximum number of individuals to return |
|
626 | - * @return array |
|
627 | - */ |
|
628 | - public function getTopMultiSosaAncestorsNoTies($limit) { |
|
629 | - if(!$this->is_setup) return array(); |
|
630 | - return Database::prepare( |
|
631 | - 'SELECT sosa_i_id, sosa_count FROM ('. |
|
632 | - ' SELECT'. |
|
633 | - ' top_sosa.sosa_i_id, top_sosa.sosa_count, top_sosa.sosa_min,'. |
|
634 | - ' @keep := IF(@prev_count = 0 OR sosa_count = @prev_count, @keep, 1) AS keep,'. |
|
635 | - ' @prev_count := top_sosa.sosa_count AS prev_count'. |
|
636 | - ' FROM ('. |
|
637 | - ' SELECT'. |
|
638 | - ' sosa.majs_i_id sosa_i_id,'. |
|
639 | - ' COUNT(sosa.majs_sosa) sosa_count,'. |
|
640 | - ' MIN(sosa.majs_sosa) sosa_min'. |
|
641 | - ' FROM ##maj_sosa AS sosa'. |
|
642 | - ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'. // Link to sosa's father |
|
643 | - ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
644 | - ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
645 | - ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'. // Link to sosa's mother |
|
646 | - ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
647 | - ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
648 | - ' WHERE sosa.majs_gedcom_id = :tree_id'. |
|
649 | - ' AND sosa.majs_user_id = :user_id'. |
|
650 | - ' AND sosa_fat.majs_sosa IS NULL'. // We keep only root individuals, i.e. those with no father or mother |
|
651 | - ' AND sosa_mot.majs_sosa IS NULL'. |
|
652 | - ' GROUP BY sosa.majs_i_id'. |
|
653 | - ' HAVING COUNT(sosa.majs_sosa) > 1'. // Limit to the duplicate sosas. |
|
654 | - ' ORDER BY COUNT(sosa.majs_sosa) DESC'. |
|
655 | - ' LIMIT ' . ($limit + 1) . // We want to select one more than required |
|
656 | - ' ) AS top_sosa,'. |
|
657 | - ' (SELECT @prev_count := 0, @keep := 0) x'. |
|
658 | - ' ORDER BY top_sosa.sosa_count ASC'. |
|
659 | - ' ) top_sosa_list'. |
|
660 | - ' WHERE keep = 1'. |
|
661 | - ' ORDER BY sosa_count DESC, sosa_min ASC' |
|
662 | - )->execute(array( |
|
663 | - 'tree_id' => $this->tree->getTreeId(), |
|
664 | - 'user_id' => $this->user->getUserId() |
|
665 | - ))->fetchAssoc() ?: array(); |
|
666 | - } |
|
458 | + /** |
|
459 | + * Get the total number of Sosa up to a specific generation. |
|
460 | + * |
|
461 | + * @param number $gen Generation |
|
462 | + * @return number Total number of Sosas up to generation |
|
463 | + */ |
|
464 | + public function getSosaCountUpToGeneration($gen){ |
|
465 | + if(!$this->is_setup) return 0; |
|
466 | + return Database::prepare( |
|
467 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
468 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
469 | + ' AND majs_gen <= :gen') |
|
470 | + ->execute(array( |
|
471 | + 'tree_id' => $this->tree->getTreeId(), |
|
472 | + 'user_id' => $this->user->getUserId(), |
|
473 | + 'gen' => $gen |
|
474 | + ))->fetchOne() ?: 0; |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Get the total number of distinct Sosa individual for all generations. |
|
479 | + * |
|
480 | + * @return number Total number of distinct individual |
|
481 | + */ |
|
482 | + public function getDifferentSosaCount(){ |
|
483 | + if(!$this->is_setup) return 0; |
|
484 | + return Database::prepare( |
|
485 | + 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
486 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
487 | + ->execute(array( |
|
488 | + 'tree_id' => $this->tree->getTreeId(), |
|
489 | + 'user_id' => $this->user->getUserId() |
|
490 | + ))->fetchOne() ?: 0; |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Get the number of distinct Sosa individual up to a specific generation. |
|
495 | + * |
|
496 | + * @param number $gen Generation |
|
497 | + * @return number Number of distinct Sosa individuals up to generation |
|
498 | + */ |
|
499 | + public function getDifferentSosaCountUpToGeneration($gen){ |
|
500 | + if(!$this->is_setup) return 0; |
|
501 | + return Database::prepare( |
|
502 | + 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
503 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
504 | + ' AND majs_gen <= :gen') |
|
505 | + ->execute(array( |
|
506 | + 'tree_id' => $this->tree->getTreeId(), |
|
507 | + 'user_id' => $this->user->getUserId(), |
|
508 | + 'gen' => $gen |
|
509 | + ))->fetchOne() ?: 0; |
|
510 | + } |
|
511 | + |
|
512 | + /** |
|
513 | + * Get an array of birth statistics for a specific generation |
|
514 | + * Statistics are : |
|
515 | + * - first : First birth year in generation |
|
516 | + * - last : Last birth year in generation |
|
517 | + * - avg : Average birth year |
|
518 | + * |
|
519 | + * @param number $gen Generation |
|
520 | + * @return array Birth statistics array |
|
521 | + */ |
|
522 | + public function getStatsBirthYearInGeneration($gen){ |
|
523 | + if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
524 | + return Database::prepare( |
|
525 | + 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
|
526 | + ' FROM `##maj_sosa`' . |
|
527 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
528 | + ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
|
529 | + ->execute(array( |
|
530 | + 'tree_id' => $this->tree->getTreeId(), |
|
531 | + 'user_id' => $this->user->getUserId(), |
|
532 | + 'gen' => $gen, |
|
533 | + 'birth_year' => 0)) |
|
534 | + ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0); |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Get the mean generation time, based on a linear regression of birth years and generations |
|
539 | + * |
|
540 | + * @return number|NULL Mean generation time |
|
541 | + */ |
|
542 | + public function getMeanGenerationTime(){ |
|
543 | + if(!$this->is_setup) return; |
|
544 | + if(!$this->statistics_tab){ |
|
545 | + $this->getStatisticsByGeneration(); |
|
546 | + } |
|
547 | + //Linear regression on x=generation and y=birthdate |
|
548 | + $sum_xy = 0; |
|
549 | + $sum_x=0; |
|
550 | + $sum_y=0; |
|
551 | + $sum_x2=0; |
|
552 | + $n=count($this->statistics_tab); |
|
553 | + foreach($this->statistics_tab as $gen=>$stats){ |
|
554 | + $sum_xy+=$gen*$stats['avgBirth']; |
|
555 | + $sum_x+=$gen; |
|
556 | + $sum_y+=$stats['avgBirth']; |
|
557 | + $sum_x2+=$gen*$gen; |
|
558 | + } |
|
559 | + $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
560 | + if($denom!=0){ |
|
561 | + return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
562 | + } |
|
563 | + return null; |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
568 | + * at a specified generation. |
|
569 | + * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
570 | + * |
|
571 | + * Format: |
|
572 | + * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
573 | + * -1 is used for shared ancestors |
|
574 | + * For instance base2(0100) = base10(4) represent the maternal grand father |
|
575 | + * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
576 | + * |
|
577 | + * For instance a result at generation 3 could be : |
|
578 | + * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
579 | + * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
580 | + * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
581 | + * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
582 | + * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
583 | + * ) |
|
584 | + * |
|
585 | + * @param int $gen Reference generation |
|
586 | + * @return array |
|
587 | + */ |
|
588 | + public function getAncestorDispersionForGen($gen) { |
|
589 | + if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
590 | + return Database::prepare( |
|
591 | + 'SELECT branches, count(i_id)'. |
|
592 | + ' FROM ('. |
|
593 | + ' SELECT i_id,'. |
|
594 | + ' CASE'. |
|
595 | + ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
596 | + ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
597 | + ' END branches'. |
|
598 | + ' FROM ('. |
|
599 | + ' SELECT DISTINCT majs_i_id i_id,'. |
|
600 | + ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
601 | + ' FROM `##maj_sosa`'. |
|
602 | + ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
603 | + ' AND majs_gen >= :gen'. |
|
604 | + ' ) indistat'. |
|
605 | + ' GROUP BY i_id'. |
|
606 | + ') grouped'. |
|
607 | + ' GROUP BY branches') |
|
608 | + ->execute(array( |
|
609 | + 'tree_id' => $this->tree->getTreeId(), |
|
610 | + 'user_id' => $this->user->getUserId(), |
|
611 | + 'gen' => $gen |
|
612 | + ))->fetchAssoc() ?: array(); |
|
613 | + } |
|
614 | + |
|
615 | + /** |
|
616 | + * Return an array of the most duplicated root Sosa ancestors. |
|
617 | + * The number of ancestors to return is limited by the parameter $limit. |
|
618 | + * If several individuals are tied when reaching the limit, none of them are returned, |
|
619 | + * which means that there can be less individuals returned than requested. |
|
620 | + * |
|
621 | + * Format: |
|
622 | + * - key : root Sosa individual |
|
623 | + * - value: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
624 | + * |
|
625 | + * @param number $limit Maximum number of individuals to return |
|
626 | + * @return array |
|
627 | + */ |
|
628 | + public function getTopMultiSosaAncestorsNoTies($limit) { |
|
629 | + if(!$this->is_setup) return array(); |
|
630 | + return Database::prepare( |
|
631 | + 'SELECT sosa_i_id, sosa_count FROM ('. |
|
632 | + ' SELECT'. |
|
633 | + ' top_sosa.sosa_i_id, top_sosa.sosa_count, top_sosa.sosa_min,'. |
|
634 | + ' @keep := IF(@prev_count = 0 OR sosa_count = @prev_count, @keep, 1) AS keep,'. |
|
635 | + ' @prev_count := top_sosa.sosa_count AS prev_count'. |
|
636 | + ' FROM ('. |
|
637 | + ' SELECT'. |
|
638 | + ' sosa.majs_i_id sosa_i_id,'. |
|
639 | + ' COUNT(sosa.majs_sosa) sosa_count,'. |
|
640 | + ' MIN(sosa.majs_sosa) sosa_min'. |
|
641 | + ' FROM ##maj_sosa AS sosa'. |
|
642 | + ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'. // Link to sosa's father |
|
643 | + ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
644 | + ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
645 | + ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'. // Link to sosa's mother |
|
646 | + ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
647 | + ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
648 | + ' WHERE sosa.majs_gedcom_id = :tree_id'. |
|
649 | + ' AND sosa.majs_user_id = :user_id'. |
|
650 | + ' AND sosa_fat.majs_sosa IS NULL'. // We keep only root individuals, i.e. those with no father or mother |
|
651 | + ' AND sosa_mot.majs_sosa IS NULL'. |
|
652 | + ' GROUP BY sosa.majs_i_id'. |
|
653 | + ' HAVING COUNT(sosa.majs_sosa) > 1'. // Limit to the duplicate sosas. |
|
654 | + ' ORDER BY COUNT(sosa.majs_sosa) DESC'. |
|
655 | + ' LIMIT ' . ($limit + 1) . // We want to select one more than required |
|
656 | + ' ) AS top_sosa,'. |
|
657 | + ' (SELECT @prev_count := 0, @keep := 0) x'. |
|
658 | + ' ORDER BY top_sosa.sosa_count ASC'. |
|
659 | + ' ) top_sosa_list'. |
|
660 | + ' WHERE keep = 1'. |
|
661 | + ' ORDER BY sosa_count DESC, sosa_min ASC' |
|
662 | + )->execute(array( |
|
663 | + 'tree_id' => $this->tree->getTreeId(), |
|
664 | + 'user_id' => $this->user->getUserId() |
|
665 | + ))->fetchAssoc() ?: array(); |
|
666 | + } |
|
667 | 667 | |
668 | 668 | |
669 | 669 | } |
@@ -22,187 +22,187 @@ |
||
22 | 22 | * Name of the file containing the description of the map. |
23 | 23 | * @var string $filename |
24 | 24 | */ |
25 | - protected $filename; |
|
25 | + protected $filename; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Indicates whether the description has been loaded from the file. |
29 | 29 | * @var bool $is_loaded |
30 | 30 | */ |
31 | - protected $is_loaded; |
|
31 | + protected $is_loaded; |
|
32 | 32 | |
33 | 33 | /** |
34 | 34 | * Description/title of the map. |
35 | 35 | * @var string $description |
36 | 36 | */ |
37 | - protected $description; |
|
37 | + protected $description; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * Name(s) of the parent level(s) of the map. |
41 | 41 | * @var string $is_loaded |
42 | 42 | */ |
43 | - protected $top_level_name; |
|
44 | - |
|
45 | - /** |
|
46 | - * Map canvas |
|
47 | - * @var OutlineMapCanvas $canvas |
|
48 | - */ |
|
49 | - protected $canvas; |
|
50 | - |
|
51 | - /** |
|
52 | - * Map subdivisions |
|
53 | - * @var array $subdivisions |
|
54 | - */ |
|
55 | - protected $subdivisions; |
|
56 | - |
|
57 | - /** |
|
58 | - * Places mappings |
|
59 | - * @var array $subdivisions |
|
60 | - */ |
|
61 | - protected $mappings; |
|
62 | - |
|
63 | - /** |
|
64 | - * Constructor for GeoAnalysisMap. |
|
65 | - * |
|
66 | - * @param string $filename Outline map file name |
|
67 | - * @param bool $load Should the map be loaded immediately |
|
68 | - */ |
|
69 | - public function __construct($filename, $load = false) { |
|
70 | - $this->filename = $filename; |
|
71 | - $this->is_loaded = false; |
|
72 | - $this->subdivisions = array(); |
|
73 | - $this->mappings = array(); |
|
74 | - if($load) $this->load(); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * Load the map settings contained within its XML representation |
|
79 | - * |
|
80 | - * XML structure : |
|
81 | - * - displayName : Display name of the map |
|
82 | - * - topLevel : Values of the top level subdivisions (separated by commas, if multiple) |
|
83 | - * - canvas : all settings related to the map canvas. |
|
84 | - * - width : canvas width, in px |
|
85 | - * - height : canvas height, in px |
|
86 | - * - maxcolor : color to identify places with ancestors, RGB hexadecimal |
|
87 | - * - hovercolor : same as previous, color when mouse is hovering the place, RGB hexadecimal |
|
88 | - * - bgcolor : map background color, RGB hexadecimal |
|
89 | - * - bgstroke : map stroke color, RGB hexadecimal |
|
90 | - * - defaultcolor : default color of places, RGB hexadecimal |
|
91 | - * - defaultstroke : default stroke color, RGB hexadecimal |
|
92 | - * - subdvisions : for each subdivision : |
|
43 | + protected $top_level_name; |
|
44 | + |
|
45 | + /** |
|
46 | + * Map canvas |
|
47 | + * @var OutlineMapCanvas $canvas |
|
48 | + */ |
|
49 | + protected $canvas; |
|
50 | + |
|
51 | + /** |
|
52 | + * Map subdivisions |
|
53 | + * @var array $subdivisions |
|
54 | + */ |
|
55 | + protected $subdivisions; |
|
56 | + |
|
57 | + /** |
|
58 | + * Places mappings |
|
59 | + * @var array $subdivisions |
|
60 | + */ |
|
61 | + protected $mappings; |
|
62 | + |
|
63 | + /** |
|
64 | + * Constructor for GeoAnalysisMap. |
|
65 | + * |
|
66 | + * @param string $filename Outline map file name |
|
67 | + * @param bool $load Should the map be loaded immediately |
|
68 | + */ |
|
69 | + public function __construct($filename, $load = false) { |
|
70 | + $this->filename = $filename; |
|
71 | + $this->is_loaded = false; |
|
72 | + $this->subdivisions = array(); |
|
73 | + $this->mappings = array(); |
|
74 | + if($load) $this->load(); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * Load the map settings contained within its XML representation |
|
79 | + * |
|
80 | + * XML structure : |
|
81 | + * - displayName : Display name of the map |
|
82 | + * - topLevel : Values of the top level subdivisions (separated by commas, if multiple) |
|
83 | + * - canvas : all settings related to the map canvas. |
|
84 | + * - width : canvas width, in px |
|
85 | + * - height : canvas height, in px |
|
86 | + * - maxcolor : color to identify places with ancestors, RGB hexadecimal |
|
87 | + * - hovercolor : same as previous, color when mouse is hovering the place, RGB hexadecimal |
|
88 | + * - bgcolor : map background color, RGB hexadecimal |
|
89 | + * - bgstroke : map stroke color, RGB hexadecimal |
|
90 | + * - defaultcolor : default color of places, RGB hexadecimal |
|
91 | + * - defaultstroke : default stroke color, RGB hexadecimal |
|
92 | + * - subdvisions : for each subdivision : |
|
93 | 93 | * - id : Subdivision id, must be compatible with PHP variable constraints, and unique |
94 | - * - name: Display name for the place |
|
94 | + * - name: Display name for the place |
|
95 | 95 | * - parent: if any, describe to which parent level the place if belonging to |
96 | - * - <em>Element value<em> : SVG description of the subdvision shape |
|
96 | + * - <em>Element value<em> : SVG description of the subdvision shape |
|
97 | 97 | * - mapping : for each subdivision : |
98 | 98 | * - name : Name of the place to map |
99 | - * - mapto: Name of the place to map to |
|
99 | + * - mapto: Name of the place to map to |
|
100 | 100 | * |
101 | - */ |
|
102 | - protected function load() { |
|
103 | - if(file_exists(WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'.$this->filename)){ |
|
104 | - $xml = simplexml_load_file(WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'.$this->filename); |
|
105 | - if($xml){ |
|
106 | - $this->description = trim($xml->displayName); |
|
107 | - $this->top_level_name = trim($xml->topLevel); |
|
108 | - $this->canvas = new OutlineMapCanvas( |
|
109 | - trim($xml->canvas->width), |
|
110 | - trim($xml->canvas->height), |
|
111 | - trim($xml->canvas->maxcolor), |
|
112 | - trim($xml->canvas->hovercolor), |
|
113 | - trim($xml->canvas->bgcolor), |
|
114 | - trim($xml->canvas->bgstroke), |
|
115 | - trim($xml->canvas->defaultcolor), |
|
116 | - trim($xml->canvas->defaultstroke) |
|
117 | - ); |
|
118 | - foreach($xml->subdivisions->children() as $subdivision){ |
|
119 | - $attributes = $subdivision->attributes(); |
|
120 | - $key = I18N::strtolower(trim($attributes['name'])); |
|
121 | - if(isset($attributes['parent'])) $key .= '@'. I18N::strtolower(trim($attributes['parent'])); |
|
122 | - $this->subdivisions[$key] = array( |
|
123 | - 'id' => trim($attributes['id']), |
|
124 | - 'displayname' => trim($attributes['name']), |
|
125 | - 'coord' => trim($subdivision[0]) |
|
126 | - ); |
|
127 | - } |
|
128 | - if(isset($xml->mappings)) { |
|
129 | - foreach($xml->mappings->children() as $mappings){ |
|
130 | - $attributes = $mappings->attributes(); |
|
131 | - $this->mappings[I18N::strtolower(trim($attributes['name']))] = I18N::strtolower(trim($attributes['mapto'])); |
|
132 | - } |
|
133 | - } |
|
134 | - $this->is_loaded = true; |
|
135 | - return; |
|
136 | - } |
|
137 | - } |
|
138 | - throw new \Exception('The Outline Map could not be loaded from XML.'); |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * Get the status of the map loading from the XML file. |
|
143 | - * |
|
144 | - * @return bool |
|
145 | - */ |
|
146 | - public function isLoaded() { |
|
147 | - try{ |
|
148 | - if(!$this->is_loaded) $this->load(); |
|
149 | - } |
|
150 | - catch (\Exception $ex) { } |
|
151 | - return $this->is_loaded; |
|
152 | - } |
|
101 | + */ |
|
102 | + protected function load() { |
|
103 | + if(file_exists(WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'.$this->filename)){ |
|
104 | + $xml = simplexml_load_file(WT_ROOT.WT_MODULES_DIR.Constants::MODULE_MAJ_GEODISP_NAME.'/maps/'.$this->filename); |
|
105 | + if($xml){ |
|
106 | + $this->description = trim($xml->displayName); |
|
107 | + $this->top_level_name = trim($xml->topLevel); |
|
108 | + $this->canvas = new OutlineMapCanvas( |
|
109 | + trim($xml->canvas->width), |
|
110 | + trim($xml->canvas->height), |
|
111 | + trim($xml->canvas->maxcolor), |
|
112 | + trim($xml->canvas->hovercolor), |
|
113 | + trim($xml->canvas->bgcolor), |
|
114 | + trim($xml->canvas->bgstroke), |
|
115 | + trim($xml->canvas->defaultcolor), |
|
116 | + trim($xml->canvas->defaultstroke) |
|
117 | + ); |
|
118 | + foreach($xml->subdivisions->children() as $subdivision){ |
|
119 | + $attributes = $subdivision->attributes(); |
|
120 | + $key = I18N::strtolower(trim($attributes['name'])); |
|
121 | + if(isset($attributes['parent'])) $key .= '@'. I18N::strtolower(trim($attributes['parent'])); |
|
122 | + $this->subdivisions[$key] = array( |
|
123 | + 'id' => trim($attributes['id']), |
|
124 | + 'displayname' => trim($attributes['name']), |
|
125 | + 'coord' => trim($subdivision[0]) |
|
126 | + ); |
|
127 | + } |
|
128 | + if(isset($xml->mappings)) { |
|
129 | + foreach($xml->mappings->children() as $mappings){ |
|
130 | + $attributes = $mappings->attributes(); |
|
131 | + $this->mappings[I18N::strtolower(trim($attributes['name']))] = I18N::strtolower(trim($attributes['mapto'])); |
|
132 | + } |
|
133 | + } |
|
134 | + $this->is_loaded = true; |
|
135 | + return; |
|
136 | + } |
|
137 | + } |
|
138 | + throw new \Exception('The Outline Map could not be loaded from XML.'); |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * Get the status of the map loading from the XML file. |
|
143 | + * |
|
144 | + * @return bool |
|
145 | + */ |
|
146 | + public function isLoaded() { |
|
147 | + try{ |
|
148 | + if(!$this->is_loaded) $this->load(); |
|
149 | + } |
|
150 | + catch (\Exception $ex) { } |
|
151 | + return $this->is_loaded; |
|
152 | + } |
|
153 | 153 | |
154 | 154 | /** |
155 | 155 | * Get the map file name. |
156 | 156 | * @return string |
157 | 157 | */ |
158 | - public function getFileName() { |
|
159 | - return $this->filename; |
|
160 | - } |
|
158 | + public function getFileName() { |
|
159 | + return $this->filename; |
|
160 | + } |
|
161 | 161 | |
162 | 162 | /** |
163 | 163 | * Get the map file name. |
164 | 164 | * @return string |
165 | 165 | */ |
166 | - public function getDescription() { |
|
167 | - if(!$this->is_loaded) $this->load(); |
|
168 | - return $this->description; |
|
169 | - } |
|
166 | + public function getDescription() { |
|
167 | + if(!$this->is_loaded) $this->load(); |
|
168 | + return $this->description; |
|
169 | + } |
|
170 | 170 | |
171 | 171 | /** |
172 | 172 | * Get the name of the map parent level. |
173 | 173 | * @return string |
174 | 174 | */ |
175 | - public function getTopLevelName() { |
|
176 | - if(!$this->is_loaded) $this->load(); |
|
177 | - return $this->top_level_name; |
|
178 | - } |
|
179 | - |
|
180 | - /** |
|
181 | - * Get the Outline Map canvas. |
|
182 | - * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\OutlineMapCanvas |
|
183 | - */ |
|
184 | - public function getCanvas() { |
|
185 | - if(!$this->is_loaded) $this->load(); |
|
186 | - return $this->canvas; |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Get the subdivisions of the map. |
|
191 | - * @return array |
|
192 | - */ |
|
193 | - public function getSubdivisions() { |
|
194 | - if(!$this->is_loaded) $this->load(); |
|
195 | - return $this->subdivisions; |
|
196 | - } |
|
197 | - |
|
198 | - /** |
|
199 | - * Get the places mappings of the map. |
|
200 | - * @return array |
|
201 | - */ |
|
202 | - public function getPlacesMappings() { |
|
203 | - if(!$this->is_loaded) $this->load(); |
|
204 | - return $this->mappings; |
|
205 | - } |
|
175 | + public function getTopLevelName() { |
|
176 | + if(!$this->is_loaded) $this->load(); |
|
177 | + return $this->top_level_name; |
|
178 | + } |
|
179 | + |
|
180 | + /** |
|
181 | + * Get the Outline Map canvas. |
|
182 | + * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\OutlineMapCanvas |
|
183 | + */ |
|
184 | + public function getCanvas() { |
|
185 | + if(!$this->is_loaded) $this->load(); |
|
186 | + return $this->canvas; |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Get the subdivisions of the map. |
|
191 | + * @return array |
|
192 | + */ |
|
193 | + public function getSubdivisions() { |
|
194 | + if(!$this->is_loaded) $this->load(); |
|
195 | + return $this->subdivisions; |
|
196 | + } |
|
197 | + |
|
198 | + /** |
|
199 | + * Get the places mappings of the map. |
|
200 | + * @return array |
|
201 | + */ |
|
202 | + public function getPlacesMappings() { |
|
203 | + if(!$this->is_loaded) $this->load(); |
|
204 | + return $this->mappings; |
|
205 | + } |
|
206 | 206 | |
207 | 207 | } |
208 | 208 | |
209 | 209 | \ No newline at end of file |
@@ -36,47 +36,47 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class GeoAnalysisController extends MvcController |
38 | 38 | { |
39 | - /** |
|
40 | - * GeoAnalysis Provider |
|
41 | - * @var GeoAnalysisProvider $provider |
|
42 | - */ |
|
43 | - protected $provider; |
|
39 | + /** |
|
40 | + * GeoAnalysis Provider |
|
41 | + * @var GeoAnalysisProvider $provider |
|
42 | + */ |
|
43 | + protected $provider; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Constructor for GeoAnalysis controller |
|
47 | - * @param AbstractModule $module |
|
48 | - */ |
|
49 | - public function __construct(AbstractModule $module) { |
|
50 | - parent::__construct($module); |
|
45 | + /** |
|
46 | + * Constructor for GeoAnalysis controller |
|
47 | + * @param AbstractModule $module |
|
48 | + */ |
|
49 | + public function __construct(AbstractModule $module) { |
|
50 | + parent::__construct($module); |
|
51 | 51 | |
52 | - $this->provider = $this->module->getProvider(); |
|
53 | - } |
|
52 | + $this->provider = $this->module->getProvider(); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Pages |
|
57 | - */ |
|
55 | + /** |
|
56 | + * Pages |
|
57 | + */ |
|
58 | 58 | |
59 | - /** |
|
60 | - * GeoAnalysis@index |
|
61 | - */ |
|
62 | - public function index() { |
|
59 | + /** |
|
60 | + * GeoAnalysis@index |
|
61 | + */ |
|
62 | + public function index() { |
|
63 | 63 | |
64 | - $controller = new PageController(); |
|
65 | - $controller->setPageTitle(I18N::translate('Sosa Geographical dispersion')); |
|
64 | + $controller = new PageController(); |
|
65 | + $controller->setPageTitle(I18N::translate('Sosa Geographical dispersion')); |
|
66 | 66 | |
67 | - $data = new ViewBag(); |
|
68 | - $data->set('title', $controller->getPageTitle()); |
|
69 | - $data->set('has_analysis', false); |
|
67 | + $data = new ViewBag(); |
|
68 | + $data->set('title', $controller->getPageTitle()); |
|
69 | + $data->set('has_analysis', false); |
|
70 | 70 | |
71 | - $ga_id = Filter::getInteger('ga_id'); |
|
71 | + $ga_id = Filter::getInteger('ga_id'); |
|
72 | 72 | |
73 | - if($ga_id && $ga = $this->provider->getGeoAnalysis($ga_id)) { |
|
74 | - $data->set('has_analysis', true); |
|
75 | - $data->set('geoanalysis', $ga); |
|
73 | + if($ga_id && $ga = $this->provider->getGeoAnalysis($ga_id)) { |
|
74 | + $data->set('has_analysis', true); |
|
75 | + $data->set('geoanalysis', $ga); |
|
76 | 76 | |
77 | - $controller |
|
78 | - ->addExternalJavascript(Constants::WT_RAPHAEL_JS_URL()) |
|
79 | - ->addInlineJavascript(' |
|
77 | + $controller |
|
78 | + ->addExternalJavascript(Constants::WT_RAPHAEL_JS_URL()) |
|
79 | + ->addInlineJavascript(' |
|
80 | 80 | jQuery("#geodispersion-tabs").tabs(); |
81 | 81 | jQuery("#geodispersion-tabs").css("visibility", "visible"); |
82 | 82 | |
@@ -97,128 +97,128 @@ discard block |
||
97 | 97 | "json" |
98 | 98 | ); |
99 | 99 | '); |
100 | - } |
|
100 | + } |
|
101 | 101 | |
102 | - ViewFactory::make('GeoAnalysis', $this, $controller, $data)->render(); |
|
103 | - } |
|
102 | + ViewFactory::make('GeoAnalysis', $this, $controller, $data)->render(); |
|
103 | + } |
|
104 | 104 | |
105 | - /** |
|
106 | - * GeoAnalysis@listAll |
|
107 | - */ |
|
108 | - public function listAll() { |
|
105 | + /** |
|
106 | + * GeoAnalysis@listAll |
|
107 | + */ |
|
108 | + public function listAll() { |
|
109 | 109 | |
110 | - $controller = new PageController(); |
|
111 | - $controller->setPageTitle(I18N::translate('Sosa Geographical dispersion')); |
|
110 | + $controller = new PageController(); |
|
111 | + $controller->setPageTitle(I18N::translate('Sosa Geographical dispersion')); |
|
112 | 112 | |
113 | - $data = new ViewBag(); |
|
114 | - $data->set('title', $controller->getPageTitle()); |
|
115 | - $data->set('has_list', false); |
|
113 | + $data = new ViewBag(); |
|
114 | + $data->set('title', $controller->getPageTitle()); |
|
115 | + $data->set('has_list', false); |
|
116 | 116 | |
117 | - $ga_list = $this->provider->getGeoAnalysisList(); |
|
118 | - if(count($ga_list) > 0 ) { |
|
119 | - $data->set('has_list', true); |
|
120 | - $data->set('geoanalysislist', $ga_list); |
|
121 | - } |
|
117 | + $ga_list = $this->provider->getGeoAnalysisList(); |
|
118 | + if(count($ga_list) > 0 ) { |
|
119 | + $data->set('has_list', true); |
|
120 | + $data->set('geoanalysislist', $ga_list); |
|
121 | + } |
|
122 | 122 | |
123 | - ViewFactory::make('GeoAnalysisList', $this, $controller, $data)->render(); |
|
124 | - } |
|
123 | + ViewFactory::make('GeoAnalysisList', $this, $controller, $data)->render(); |
|
124 | + } |
|
125 | 125 | |
126 | 126 | /** |
127 | 127 | * GeoAnalysis@setStatus |
128 | 128 | */ |
129 | - public function setStatus() { |
|
130 | - $controller = new JsonController(); |
|
129 | + public function setStatus() { |
|
130 | + $controller = new JsonController(); |
|
131 | 131 | |
132 | - $ga_id = Filter::getInteger('ga_id'); |
|
133 | - $ga = $this->provider->getGeoAnalysis($ga_id, false); |
|
132 | + $ga_id = Filter::getInteger('ga_id'); |
|
133 | + $ga = $this->provider->getGeoAnalysis($ga_id, false); |
|
134 | 134 | |
135 | - $controller->restrictAccess( |
|
136 | - true // Filter::checkCsrf() -- Cannot use CSRF on a GET request (modules can only work with GET requests) |
|
137 | - && Auth::isManager(Globals::getTree()) |
|
138 | - && $ga !== null |
|
139 | - ); |
|
135 | + $controller->restrictAccess( |
|
136 | + true // Filter::checkCsrf() -- Cannot use CSRF on a GET request (modules can only work with GET requests) |
|
137 | + && Auth::isManager(Globals::getTree()) |
|
138 | + && $ga !== null |
|
139 | + ); |
|
140 | 140 | |
141 | - $status = Filter::getBool('status'); |
|
142 | - $res = array('geoanalysis' => $ga->getId() , 'error' => null); |
|
143 | - try{ |
|
144 | - $this->provider->setGeoAnalysisStatus($ga, $status); |
|
145 | - $res['status'] = $status; |
|
141 | + $status = Filter::getBool('status'); |
|
142 | + $res = array('geoanalysis' => $ga->getId() , 'error' => null); |
|
143 | + try{ |
|
144 | + $this->provider->setGeoAnalysisStatus($ga, $status); |
|
145 | + $res['status'] = $status; |
|
146 | 146 | Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been '. ($status ? 'enabled' : 'disabled') .'.'); |
147 | - } |
|
148 | - catch (\Exception $ex) { |
|
149 | - $res['error'] = $ex->getMessage(); |
|
147 | + } |
|
148 | + catch (\Exception $ex) { |
|
149 | + $res['error'] = $ex->getMessage(); |
|
150 | 150 | Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage()); |
151 | - } |
|
151 | + } |
|
152 | 152 | |
153 | - $controller->pageHeader(); |
|
154 | - if($res['error']) http_response_code(500); |
|
153 | + $controller->pageHeader(); |
|
154 | + if($res['error']) http_response_code(500); |
|
155 | 155 | |
156 | - $controller->encode($res); |
|
157 | - } |
|
156 | + $controller->encode($res); |
|
157 | + } |
|
158 | 158 | |
159 | 159 | /** |
160 | - * GeoAnalysis@delete |
|
161 | - */ |
|
162 | - public function delete() { |
|
163 | - $controller = new JsonController(); |
|
160 | + * GeoAnalysis@delete |
|
161 | + */ |
|
162 | + public function delete() { |
|
163 | + $controller = new JsonController(); |
|
164 | 164 | |
165 | - $ga_id = Filter::getInteger('ga_id'); |
|
166 | - $ga = $this->provider->getGeoAnalysis($ga_id, false); |
|
165 | + $ga_id = Filter::getInteger('ga_id'); |
|
166 | + $ga = $this->provider->getGeoAnalysis($ga_id, false); |
|
167 | 167 | |
168 | - $controller->restrictAccess( |
|
169 | - true // Filter::checkCsrf() -- Cannot use CSRF on a GET request (modules can only work with GET requests) |
|
170 | - && Auth::isManager(Globals::getTree()) |
|
171 | - && $ga |
|
172 | - ); |
|
168 | + $controller->restrictAccess( |
|
169 | + true // Filter::checkCsrf() -- Cannot use CSRF on a GET request (modules can only work with GET requests) |
|
170 | + && Auth::isManager(Globals::getTree()) |
|
171 | + && $ga |
|
172 | + ); |
|
173 | 173 | |
174 | - $res = array('geoanalysis' => $ga->getId() , 'error' => null); |
|
175 | - try{ |
|
176 | - $this->provider->deleteGeoAnalysis($ga); |
|
174 | + $res = array('geoanalysis' => $ga->getId() , 'error' => null); |
|
175 | + try{ |
|
176 | + $this->provider->deleteGeoAnalysis($ga); |
|
177 | 177 | Log::addConfigurationLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" has been deleted.'); |
178 | - } |
|
179 | - catch (\Exception $ex) { |
|
180 | - $res['error'] = $ex->getMessage(); |
|
178 | + } |
|
179 | + catch (\Exception $ex) { |
|
180 | + $res['error'] = $ex->getMessage(); |
|
181 | 181 | Log::addErrorLog('Module '.$this->module->getName().' : Geo Analysis ID "'.$ga->getId().'" could not be deleted. Error: '. $ex->getMessage()); |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - $controller->pageHeader(); |
|
185 | - if($res['error']) http_response_code(500); |
|
184 | + $controller->pageHeader(); |
|
185 | + if($res['error']) http_response_code(500); |
|
186 | 186 | |
187 | - $controller->encode($res); |
|
188 | - } |
|
187 | + $controller->encode($res); |
|
188 | + } |
|
189 | 189 | |
190 | - /** |
|
191 | - * GeoAnalysis@dataTabs |
|
192 | - */ |
|
193 | - public function dataTabs() { |
|
194 | - $wt_tree = Globals::getTree(); |
|
195 | - $controller = new JsonController(); |
|
190 | + /** |
|
191 | + * GeoAnalysis@dataTabs |
|
192 | + */ |
|
193 | + public function dataTabs() { |
|
194 | + $wt_tree = Globals::getTree(); |
|
195 | + $controller = new JsonController(); |
|
196 | 196 | |
197 | - $ga_id = Filter::getInteger('ga_id'); |
|
198 | - $ga = $this->provider->getGeoAnalysis($ga_id); |
|
199 | - $sosa_provider = new SosaProvider($wt_tree, Auth::user()); |
|
197 | + $ga_id = Filter::getInteger('ga_id'); |
|
198 | + $ga = $this->provider->getGeoAnalysis($ga_id); |
|
199 | + $sosa_provider = new SosaProvider($wt_tree, Auth::user()); |
|
200 | 200 | |
201 | - $controller |
|
202 | - ->restrictAccess($ga && $sosa_provider->isSetup()) |
|
203 | - ->pageHeader(); |
|
201 | + $controller |
|
202 | + ->restrictAccess($ga && $sosa_provider->isSetup()) |
|
203 | + ->pageHeader(); |
|
204 | 204 | |
205 | - $jsonArray = array(); |
|
205 | + $jsonArray = array(); |
|
206 | 206 | |
207 | - list($placesDispGeneral, $placesDispGenerations) = $ga->getAnalysisResults($sosa_provider->getAllSosaWithGenerations()); |
|
207 | + list($placesDispGeneral, $placesDispGenerations) = $ga->getAnalysisResults($sosa_provider->getAllSosaWithGenerations()); |
|
208 | 208 | |
209 | - $flags = array(); |
|
210 | - if($placesDispGeneral && $ga->getOptions() && $ga->getOptions()->isUsingFlags()) { |
|
211 | - $mapProvider = new GoogleMapsProvider(); |
|
212 | - foreach($placesDispGeneral['places'] as $place => $count) { |
|
213 | - $flags[$place] = $mapProvider->getPlaceIcon(new Place($place, $wt_tree)); |
|
214 | - } |
|
215 | - } |
|
209 | + $flags = array(); |
|
210 | + if($placesDispGeneral && $ga->getOptions() && $ga->getOptions()->isUsingFlags()) { |
|
211 | + $mapProvider = new GoogleMapsProvider(); |
|
212 | + foreach($placesDispGeneral['places'] as $place => $count) { |
|
213 | + $flags[$place] = $mapProvider->getPlaceIcon(new Place($place, $wt_tree)); |
|
214 | + } |
|
215 | + } |
|
216 | 216 | |
217 | - $jsonArray['generaltab'] = $this->htmlPlacesAnalysisGeneralTab($ga, $placesDispGeneral, $flags); |
|
218 | - $jsonArray['generationstab'] = $this->htmlPlacesAnalysisGenerationsTab($ga, $placesDispGenerations, $flags); |
|
217 | + $jsonArray['generaltab'] = $this->htmlPlacesAnalysisGeneralTab($ga, $placesDispGeneral, $flags); |
|
218 | + $jsonArray['generationstab'] = $this->htmlPlacesAnalysisGenerationsTab($ga, $placesDispGenerations, $flags); |
|
219 | 219 | |
220 | - $controller->encode($jsonArray); |
|
221 | - } |
|
220 | + $controller->encode($jsonArray); |
|
221 | + } |
|
222 | 222 | |
223 | 223 | /** |
224 | 224 | * Returns HTML code for the GeoAnalysis general tab (can be either a map or a table). |
@@ -228,71 +228,71 @@ discard block |
||
228 | 228 | * @param (null|array) $flags Array of flags |
229 | 229 | * @return string HTML code for the general tab |
230 | 230 | */ |
231 | - protected function htmlPlacesAnalysisGeneralTab(GeoAnalysis $ga, $placesGeneralResults, $flags= null) { |
|
232 | - if(!empty($placesGeneralResults)){ |
|
233 | - $data = new ViewBag(); |
|
231 | + protected function htmlPlacesAnalysisGeneralTab(GeoAnalysis $ga, $placesGeneralResults, $flags= null) { |
|
232 | + if(!empty($placesGeneralResults)){ |
|
233 | + $data = new ViewBag(); |
|
234 | 234 | |
235 | - $nb_found = $placesGeneralResults['knownsum']; |
|
236 | - $nb_other = 0; |
|
237 | - if(isset($placesGeneralResults['other'])) $nb_other =$placesGeneralResults['other']; |
|
238 | - $nb_unknown = $placesGeneralResults['unknown']; |
|
235 | + $nb_found = $placesGeneralResults['knownsum']; |
|
236 | + $nb_other = 0; |
|
237 | + if(isset($placesGeneralResults['other'])) $nb_other =$placesGeneralResults['other']; |
|
238 | + $nb_unknown = $placesGeneralResults['unknown']; |
|
239 | 239 | |
240 | - $data->set('stats_gen_nb_found', $nb_found); |
|
241 | - $data->set('stats_gen_nb_other', $nb_other); |
|
242 | - $data->set('stats_gen_nb_unknown', $nb_unknown); |
|
240 | + $data->set('stats_gen_nb_found', $nb_found); |
|
241 | + $data->set('stats_gen_nb_other', $nb_other); |
|
242 | + $data->set('stats_gen_nb_unknown', $nb_unknown); |
|
243 | 243 | |
244 | - $data->set('use_flags', $ga->getOptions() && $ga->getOptions()->isUsingFlags()); |
|
244 | + $data->set('use_flags', $ga->getOptions() && $ga->getOptions()->isUsingFlags()); |
|
245 | 245 | |
246 | - if($ga->hasMap()) { |
|
247 | - $max = $placesGeneralResults['max']; |
|
248 | - $map = $ga->getOptions()->getMap(); |
|
249 | - if($map->isLoaded()) { |
|
250 | - $results_by_subdivs = $map->getSubdivisions(); |
|
251 | - $places_mappings = $map->getPlacesMappings(); |
|
252 | - foreach ($placesGeneralResults['places'] as $location => $count) { |
|
253 | - $levelvalues = array_reverse(array_map('trim',explode(',', $location))); |
|
254 | - $level_map = $ga->getAnalysisLevel() - $ga->getOptions()->getMapLevel(); |
|
255 | - if($level_map >= 0 && $level_map < count($levelvalues)) { |
|
256 | - $levelref = I18N::strtolower($levelvalues[0] . '@' . $levelvalues[$level_map]); |
|
257 | - if(!isset($results_by_subdivs[$levelref])) { $levelref = $levelvalues[0]; } |
|
258 | - } |
|
259 | - else { |
|
260 | - $levelref = $levelvalues[0]; |
|
261 | - } |
|
262 | - $levelref = I18N::strtolower($levelref); |
|
263 | - if(isset($places_mappings[$levelref])) $levelref = $places_mappings[$levelref]; |
|
264 | - if(isset($results_by_subdivs[$levelref])) { |
|
265 | - $count_subd = isset($results_by_subdivs[$levelref]['count']) ? $results_by_subdivs[$levelref]['count'] : 0; |
|
266 | - $count_subd += $count; |
|
267 | - $results_by_subdivs[$levelref]['count'] = $count_subd; |
|
268 | - $results_by_subdivs[$levelref]['transparency'] = Functions::safeDivision($count_subd, $max); |
|
269 | - if($ga->getOptions()->isUsingFlags() && $flags) { |
|
270 | - $results_by_subdivs[$levelref]['place'] = new Place($location, Globals::getTree()); |
|
271 | - $results_by_subdivs[$levelref]['flag'] = $flags[$location]; |
|
272 | - } |
|
273 | - } |
|
274 | - } |
|
246 | + if($ga->hasMap()) { |
|
247 | + $max = $placesGeneralResults['max']; |
|
248 | + $map = $ga->getOptions()->getMap(); |
|
249 | + if($map->isLoaded()) { |
|
250 | + $results_by_subdivs = $map->getSubdivisions(); |
|
251 | + $places_mappings = $map->getPlacesMappings(); |
|
252 | + foreach ($placesGeneralResults['places'] as $location => $count) { |
|
253 | + $levelvalues = array_reverse(array_map('trim',explode(',', $location))); |
|
254 | + $level_map = $ga->getAnalysisLevel() - $ga->getOptions()->getMapLevel(); |
|
255 | + if($level_map >= 0 && $level_map < count($levelvalues)) { |
|
256 | + $levelref = I18N::strtolower($levelvalues[0] . '@' . $levelvalues[$level_map]); |
|
257 | + if(!isset($results_by_subdivs[$levelref])) { $levelref = $levelvalues[0]; } |
|
258 | + } |
|
259 | + else { |
|
260 | + $levelref = $levelvalues[0]; |
|
261 | + } |
|
262 | + $levelref = I18N::strtolower($levelref); |
|
263 | + if(isset($places_mappings[$levelref])) $levelref = $places_mappings[$levelref]; |
|
264 | + if(isset($results_by_subdivs[$levelref])) { |
|
265 | + $count_subd = isset($results_by_subdivs[$levelref]['count']) ? $results_by_subdivs[$levelref]['count'] : 0; |
|
266 | + $count_subd += $count; |
|
267 | + $results_by_subdivs[$levelref]['count'] = $count_subd; |
|
268 | + $results_by_subdivs[$levelref]['transparency'] = Functions::safeDivision($count_subd, $max); |
|
269 | + if($ga->getOptions()->isUsingFlags() && $flags) { |
|
270 | + $results_by_subdivs[$levelref]['place'] = new Place($location, Globals::getTree()); |
|
271 | + $results_by_subdivs[$levelref]['flag'] = $flags[$location]; |
|
272 | + } |
|
273 | + } |
|
274 | + } |
|
275 | 275 | |
276 | - $data->set('map', $map); |
|
277 | - $data->set('results_by_subdivisions', $results_by_subdivs); |
|
278 | - } |
|
276 | + $data->set('map', $map); |
|
277 | + $data->set('results_by_subdivisions', $results_by_subdivs); |
|
278 | + } |
|
279 | 279 | |
280 | - $html = ViewFactory::make('GeoAnalysisTabGeneralMap', $this, new BaseController(), $data)->getHtmlPartial(); |
|
281 | - } |
|
282 | - else { |
|
283 | - $results = $placesGeneralResults['places']; |
|
284 | - arsort($results); |
|
285 | - $data->set('results', $results); |
|
286 | - $data->set('analysis_level', $ga->getAnalysisLevel()); |
|
280 | + $html = ViewFactory::make('GeoAnalysisTabGeneralMap', $this, new BaseController(), $data)->getHtmlPartial(); |
|
281 | + } |
|
282 | + else { |
|
283 | + $results = $placesGeneralResults['places']; |
|
284 | + arsort($results); |
|
285 | + $data->set('results', $results); |
|
286 | + $data->set('analysis_level', $ga->getAnalysisLevel()); |
|
287 | 287 | |
288 | - $html = ViewFactory::make('GeoAnalysisTabGeneralTable', $this, new BaseController(), $data)->getHtmlPartial(); |
|
289 | - } |
|
290 | - } |
|
291 | - else { |
|
292 | - $html = '<p class="warning">' . I18N::translate('No data is available for the general analysis.') . '</p>'; |
|
293 | - } |
|
294 | - return $html; |
|
295 | - } |
|
288 | + $html = ViewFactory::make('GeoAnalysisTabGeneralTable', $this, new BaseController(), $data)->getHtmlPartial(); |
|
289 | + } |
|
290 | + } |
|
291 | + else { |
|
292 | + $html = '<p class="warning">' . I18N::translate('No data is available for the general analysis.') . '</p>'; |
|
293 | + } |
|
294 | + return $html; |
|
295 | + } |
|
296 | 296 | |
297 | 297 | /** |
298 | 298 | * Returns HTML code for the GeoAnalysis generations tab. |
@@ -302,66 +302,66 @@ discard block |
||
302 | 302 | * @param (null|array) $flags Array of flags |
303 | 303 | * @return string HTML code for the generations tab |
304 | 304 | */ |
305 | - protected function htmlPlacesAnalysisGenerationsTab(GeoAnalysis $ga, $placesGenerationsResults, $flags = null) { |
|
306 | - if(!empty($placesGenerationsResults) && $ga->getOptions()){ |
|
307 | - $data = new ViewBag(); |
|
305 | + protected function htmlPlacesAnalysisGenerationsTab(GeoAnalysis $ga, $placesGenerationsResults, $flags = null) { |
|
306 | + if(!empty($placesGenerationsResults) && $ga->getOptions()){ |
|
307 | + $data = new ViewBag(); |
|
308 | 308 | |
309 | - ksort($placesGenerationsResults); |
|
309 | + ksort($placesGenerationsResults); |
|
310 | 310 | |
311 | - $detailslevel = $ga->getOptions()->getMaxDetailsInGen(); |
|
312 | - $data->set('max_details_gen', $detailslevel); |
|
313 | - $data->set('use_flags', $ga->getOptions()->isUsingFlags()); |
|
314 | - $data->set('analysis_level', $ga->getAnalysisLevel()); |
|
315 | - $display_all_places = !is_null($detailslevel) && $detailslevel == 0; |
|
316 | - $data->set('display_all_places', $display_all_places); |
|
311 | + $detailslevel = $ga->getOptions()->getMaxDetailsInGen(); |
|
312 | + $data->set('max_details_gen', $detailslevel); |
|
313 | + $data->set('use_flags', $ga->getOptions()->isUsingFlags()); |
|
314 | + $data->set('analysis_level', $ga->getAnalysisLevel()); |
|
315 | + $display_all_places = !is_null($detailslevel) && $detailslevel == 0; |
|
316 | + $data->set('display_all_places', $display_all_places); |
|
317 | 317 | |
318 | - $results_by_gen = array(); |
|
319 | - foreach($placesGenerationsResults as $gen => $genData){ |
|
320 | - $sum = 0; |
|
321 | - $other = 0; |
|
322 | - $unknown = 0; |
|
323 | - if(isset($genData['sum'])) $sum = $genData['sum']; |
|
324 | - if(isset($genData['other'])) $other = $genData['other']; |
|
325 | - if(isset($genData['unknown'])) $unknown = $genData['unknown']; |
|
318 | + $results_by_gen = array(); |
|
319 | + foreach($placesGenerationsResults as $gen => $genData){ |
|
320 | + $sum = 0; |
|
321 | + $other = 0; |
|
322 | + $unknown = 0; |
|
323 | + if(isset($genData['sum'])) $sum = $genData['sum']; |
|
324 | + if(isset($genData['other'])) $other = $genData['other']; |
|
325 | + if(isset($genData['unknown'])) $unknown = $genData['unknown']; |
|
326 | 326 | |
327 | - if($sum > 0) { |
|
328 | - $results_by_gen[$gen]['sum'] = $sum; |
|
329 | - $results_by_gen[$gen]['other'] = $other; |
|
330 | - $results_by_gen[$gen]['unknown'] = $unknown; |
|
331 | - $results_by_gen[$gen]['places'] = array(); |
|
332 | - arsort($genData['places']); |
|
327 | + if($sum > 0) { |
|
328 | + $results_by_gen[$gen]['sum'] = $sum; |
|
329 | + $results_by_gen[$gen]['other'] = $other; |
|
330 | + $results_by_gen[$gen]['unknown'] = $unknown; |
|
331 | + $results_by_gen[$gen]['places'] = array(); |
|
332 | + arsort($genData['places']); |
|
333 | 333 | |
334 | - if($display_all_places){ |
|
335 | - foreach($genData['places'] as $placename=> $count){ |
|
336 | - $results_by_gen[$gen]['places'][$placename]['count'] = $count; |
|
334 | + if($display_all_places){ |
|
335 | + foreach($genData['places'] as $placename=> $count){ |
|
336 | + $results_by_gen[$gen]['places'][$placename]['count'] = $count; |
|
337 | 337 | |
338 | - if($ga->getOptions() && $ga->getOptions()->isUsingFlags() && ($flag = $flags[$placename]) != ''){ |
|
339 | - $results_by_gen[$gen]['places'][$placename]['place'] = new Place($placename, Globals::getTree()); |
|
340 | - $results_by_gen[$gen]['places'][$placename]['flag'] = $flag; |
|
341 | - } |
|
342 | - } |
|
343 | - } |
|
344 | - else { |
|
345 | - $tmp = $genData['places']; |
|
346 | - if($other > 0) { |
|
347 | - $tmp = array_slice($tmp, 0, 5, true); |
|
348 | - $tmp['other'] = $other; |
|
349 | - arsort($tmp); |
|
350 | - } |
|
351 | - $results_by_gen[$gen]['places'] = array_slice($tmp, 0, 5, true); |
|
352 | - } |
|
353 | - } |
|
354 | - } |
|
338 | + if($ga->getOptions() && $ga->getOptions()->isUsingFlags() && ($flag = $flags[$placename]) != ''){ |
|
339 | + $results_by_gen[$gen]['places'][$placename]['place'] = new Place($placename, Globals::getTree()); |
|
340 | + $results_by_gen[$gen]['places'][$placename]['flag'] = $flag; |
|
341 | + } |
|
342 | + } |
|
343 | + } |
|
344 | + else { |
|
345 | + $tmp = $genData['places']; |
|
346 | + if($other > 0) { |
|
347 | + $tmp = array_slice($tmp, 0, 5, true); |
|
348 | + $tmp['other'] = $other; |
|
349 | + arsort($tmp); |
|
350 | + } |
|
351 | + $results_by_gen[$gen]['places'] = array_slice($tmp, 0, 5, true); |
|
352 | + } |
|
353 | + } |
|
354 | + } |
|
355 | 355 | |
356 | - $data->set('results_by_generations', $results_by_gen); |
|
356 | + $data->set('results_by_generations', $results_by_gen); |
|
357 | 357 | |
358 | - $html = ViewFactory::make('GeoAnalysisTabGenerations', $this, new BaseController(), $data)->getHtmlPartial(); |
|
358 | + $html = ViewFactory::make('GeoAnalysisTabGenerations', $this, new BaseController(), $data)->getHtmlPartial(); |
|
359 | 359 | |
360 | - } |
|
361 | - else { |
|
362 | - $html = '<p class="warning">' . I18N::translate('No data is available for the generations analysis.') . '</p>'; |
|
363 | - } |
|
364 | - return $html; |
|
365 | - } |
|
360 | + } |
|
361 | + else { |
|
362 | + $html = '<p class="warning">' . I18N::translate('No data is available for the generations analysis.') . '</p>'; |
|
363 | + } |
|
364 | + return $html; |
|
365 | + } |
|
366 | 366 | |
367 | 367 | } |
368 | 368 | \ No newline at end of file |
@@ -31,140 +31,140 @@ discard block |
||
31 | 31 | * Certificates Module. |
32 | 32 | */ |
33 | 33 | class CertificatesModule |
34 | - extends AbstractModule |
|
35 | - implements HookSubscriberInterface, ModuleConfigInterface, ModuleMenuItemInterface, FactSourceTextExtenderInterface, CustomSimpleTagManagerInterface |
|
34 | + extends AbstractModule |
|
35 | + implements HookSubscriberInterface, ModuleConfigInterface, ModuleMenuItemInterface, FactSourceTextExtenderInterface, CustomSimpleTagManagerInterface |
|
36 | 36 | { |
37 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
38 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
37 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
38 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Provider for Certificates |
|
42 | - * @var CertificateProviderInterface $provider |
|
43 | - */ |
|
44 | - protected $provider; |
|
40 | + /** |
|
41 | + * Provider for Certificates |
|
42 | + * @var CertificateProviderInterface $provider |
|
43 | + */ |
|
44 | + protected $provider; |
|
45 | 45 | |
46 | - /** |
|
47 | - * {@inhericDoc} |
|
48 | - */ |
|
49 | - public function getTitle() { |
|
50 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
51 | - } |
|
46 | + /** |
|
47 | + * {@inhericDoc} |
|
48 | + */ |
|
49 | + public function getTitle() { |
|
50 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * {@inhericDoc} |
|
55 | - */ |
|
56 | - public function getDescription() { |
|
57 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
58 | - } |
|
53 | + /** |
|
54 | + * {@inhericDoc} |
|
55 | + */ |
|
56 | + public function getDescription() { |
|
57 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inhericDoc} |
|
62 | - */ |
|
63 | - public function modAction($mod_action) { |
|
64 | - \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
65 | - } |
|
60 | + /** |
|
61 | + * {@inhericDoc} |
|
62 | + */ |
|
63 | + public function modAction($mod_action) { |
|
64 | + \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * {@inhericDoc} |
|
69 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
70 | - */ |
|
71 | - public function getConfigLink() { |
|
72 | - return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
73 | - } |
|
67 | + /** |
|
68 | + * {@inhericDoc} |
|
69 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
70 | + */ |
|
71 | + public function getConfigLink() { |
|
72 | + return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * {@inhericDoc} |
|
77 | - * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
78 | - */ |
|
79 | - public function getSubscribedHooks() { |
|
80 | - return array( |
|
81 | - 'hFactSourcePrepend' => 50, |
|
82 | - 'hGetExpectedTags' => 50, |
|
83 | - 'hHtmlSimpleTagDisplay#_ACT' => 50, |
|
84 | - 'hHtmlSimpleTagEditor#_ACT' => 50, |
|
85 | - 'hAddSimpleTag#SOUR' => 50, |
|
86 | - 'hHasHelpTextTag#_ACT' => 50, |
|
87 | - 'hGetHelpTextTag#_ACT' => 50 |
|
88 | - ); |
|
89 | - } |
|
75 | + /** |
|
76 | + * {@inhericDoc} |
|
77 | + * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
78 | + */ |
|
79 | + public function getSubscribedHooks() { |
|
80 | + return array( |
|
81 | + 'hFactSourcePrepend' => 50, |
|
82 | + 'hGetExpectedTags' => 50, |
|
83 | + 'hHtmlSimpleTagDisplay#_ACT' => 50, |
|
84 | + 'hHtmlSimpleTagEditor#_ACT' => 50, |
|
85 | + 'hAddSimpleTag#SOUR' => 50, |
|
86 | + 'hHasHelpTextTag#_ACT' => 50, |
|
87 | + 'hGetHelpTextTag#_ACT' => 50 |
|
88 | + ); |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * {@inhericDoc} |
|
93 | - * @see \MyArtJaub\Webtrees\Module\ModuleMenuItemInterface::getMenu() |
|
94 | - */ |
|
95 | - public function getMenu(Tree $tree, $reference = null) { |
|
96 | - $tree_url = $tree ? $tree->getNameUrl() : ''; |
|
97 | - return new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=Certificate@listAll&ged=' . $tree_url, 'menu-maj-list-certificate', array('rel' => 'nofollow')); |
|
98 | - } |
|
91 | + /** |
|
92 | + * {@inhericDoc} |
|
93 | + * @see \MyArtJaub\Webtrees\Module\ModuleMenuItemInterface::getMenu() |
|
94 | + */ |
|
95 | + public function getMenu(Tree $tree, $reference = null) { |
|
96 | + $tree_url = $tree ? $tree->getNameUrl() : ''; |
|
97 | + return new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=Certificate@listAll&ged=' . $tree_url, 'menu-maj-list-certificate', array('rel' => 'nofollow')); |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * {@inhericDoc} |
|
102 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourcePrepend() |
|
103 | - */ |
|
104 | - public function hFactSourcePrepend($srec) { |
|
105 | - $wt_tree = Globals::getTree(); |
|
106 | - $html=''; |
|
107 | - $sid=null; |
|
100 | + /** |
|
101 | + * {@inhericDoc} |
|
102 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourcePrepend() |
|
103 | + */ |
|
104 | + public function hFactSourcePrepend($srec) { |
|
105 | + $wt_tree = Globals::getTree(); |
|
106 | + $html=''; |
|
107 | + $sid=null; |
|
108 | 108 | |
109 | - if($this->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($wt_tree)){ |
|
110 | - if (!$srec || strlen($srec) == 0) return $html; |
|
109 | + if($this->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($wt_tree)){ |
|
110 | + if (!$srec || strlen($srec) == 0) return $html; |
|
111 | 111 | |
112 | - $certificate = null; |
|
113 | - $subrecords = explode("\n", $srec); |
|
114 | - $levelSOUR = substr($subrecords[0], 0, 1); |
|
115 | - $match = null; |
|
116 | - if (preg_match('~^'.$levelSOUR.' SOUR @('.WT_REGEX_XREF.')@$~', $subrecords[0], $match)) { |
|
117 | - $sid=$match[1]; |
|
118 | - }; |
|
119 | - $nb_subrecords = count($subrecords); |
|
120 | - for ($i=0; $i < $nb_subrecords; $i++) { |
|
121 | - $subrecords[$i] = trim($subrecords[$i]); |
|
122 | - $tag = substr($subrecords[$i], 2, 4); |
|
123 | - $text = substr($subrecords[$i], 7); |
|
124 | - if($tag == '_ACT') $certificate= new Certificate($text, $wt_tree, $this->getProvider()); |
|
125 | - } |
|
112 | + $certificate = null; |
|
113 | + $subrecords = explode("\n", $srec); |
|
114 | + $levelSOUR = substr($subrecords[0], 0, 1); |
|
115 | + $match = null; |
|
116 | + if (preg_match('~^'.$levelSOUR.' SOUR @('.WT_REGEX_XREF.')@$~', $subrecords[0], $match)) { |
|
117 | + $sid=$match[1]; |
|
118 | + }; |
|
119 | + $nb_subrecords = count($subrecords); |
|
120 | + for ($i=0; $i < $nb_subrecords; $i++) { |
|
121 | + $subrecords[$i] = trim($subrecords[$i]); |
|
122 | + $tag = substr($subrecords[$i], 2, 4); |
|
123 | + $text = substr($subrecords[$i], 7); |
|
124 | + if($tag == '_ACT') $certificate= new Certificate($text, $wt_tree, $this->getProvider()); |
|
125 | + } |
|
126 | 126 | |
127 | - if($certificate && $certificate->canShow()) |
|
128 | - $html = $this->getDisplay_ACT($certificate, $sid); |
|
127 | + if($certificate && $certificate->canShow()) |
|
128 | + $html = $this->getDisplay_ACT($certificate, $sid); |
|
129 | 129 | |
130 | - } |
|
131 | - return $html; |
|
132 | - } |
|
130 | + } |
|
131 | + return $html; |
|
132 | + } |
|
133 | 133 | |
134 | - /** |
|
135 | - * {@inhericDoc} |
|
136 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourceAppend() |
|
137 | - */ |
|
138 | - public function hFactSourceAppend($srec) { } |
|
134 | + /** |
|
135 | + * {@inhericDoc} |
|
136 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourceAppend() |
|
137 | + */ |
|
138 | + public function hFactSourceAppend($srec) { } |
|
139 | 139 | |
140 | - /** |
|
141 | - * {@inhericDoc} |
|
142 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetExpectedTags() |
|
143 | - */ |
|
144 | - public function hGetExpectedTags() { |
|
145 | - return array('SOUR' => '_ACT'); |
|
146 | - } |
|
140 | + /** |
|
141 | + * {@inhericDoc} |
|
142 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetExpectedTags() |
|
143 | + */ |
|
144 | + public function hGetExpectedTags() { |
|
145 | + return array('SOUR' => '_ACT'); |
|
146 | + } |
|
147 | 147 | |
148 | - /** |
|
149 | - * {@inhericDoc} |
|
150 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagDisplay() |
|
151 | - */ |
|
152 | - public function hHtmlSimpleTagDisplay($tag, $value, $context = null, $contextid = null) { |
|
153 | - $html = ''; |
|
154 | - switch($tag){ |
|
155 | - case '_ACT': |
|
156 | - if($context == 'SOUR') $html = $this->getDisplay_ACT($value, $contextid); |
|
157 | - break; |
|
158 | - } |
|
159 | - return $html; |
|
160 | - } |
|
148 | + /** |
|
149 | + * {@inhericDoc} |
|
150 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagDisplay() |
|
151 | + */ |
|
152 | + public function hHtmlSimpleTagDisplay($tag, $value, $context = null, $contextid = null) { |
|
153 | + $html = ''; |
|
154 | + switch($tag){ |
|
155 | + case '_ACT': |
|
156 | + if($context == 'SOUR') $html = $this->getDisplay_ACT($value, $contextid); |
|
157 | + break; |
|
158 | + } |
|
159 | + return $html; |
|
160 | + } |
|
161 | 161 | |
162 | - /** |
|
163 | - * {@inhericDoc} |
|
164 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagEditor() |
|
165 | - */ |
|
166 | - public function hHtmlSimpleTagEditor($tag, $value = null, $element_id = '', $element_name = '', $context = null, $contextid = null) { |
|
167 | - $html = ''; |
|
162 | + /** |
|
163 | + * {@inhericDoc} |
|
164 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagEditor() |
|
165 | + */ |
|
166 | + public function hHtmlSimpleTagEditor($tag, $value = null, $element_id = '', $element_name = '', $context = null, $contextid = null) { |
|
167 | + $html = ''; |
|
168 | 168 | |
169 | 169 | switch($tag){ |
170 | 170 | case '_ACT': |
@@ -192,75 +192,75 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | return $html; |
195 | - } |
|
195 | + } |
|
196 | 196 | |
197 | - /** |
|
198 | - * {@inhericDoc} |
|
199 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hAddSimpleTag() |
|
200 | - */ |
|
201 | - public function hAddSimpleTag($context, $level) { |
|
202 | - switch($context){ |
|
203 | - case 'SOUR': |
|
204 | - FunctionsEdit::addSimpleTag($level.' _ACT'); |
|
205 | - break; |
|
206 | - } |
|
207 | - } |
|
197 | + /** |
|
198 | + * {@inhericDoc} |
|
199 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hAddSimpleTag() |
|
200 | + */ |
|
201 | + public function hAddSimpleTag($context, $level) { |
|
202 | + switch($context){ |
|
203 | + case 'SOUR': |
|
204 | + FunctionsEdit::addSimpleTag($level.' _ACT'); |
|
205 | + break; |
|
206 | + } |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * {@inhericDoc} |
|
211 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHasHelpTextTag() |
|
212 | - */ |
|
213 | - public function hHasHelpTextTag($tag) { |
|
214 | - switch($tag){ |
|
209 | + /** |
|
210 | + * {@inhericDoc} |
|
211 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHasHelpTextTag() |
|
212 | + */ |
|
213 | + public function hHasHelpTextTag($tag) { |
|
214 | + switch($tag){ |
|
215 | 215 | case '_ACT': |
216 | 216 | return true; |
217 | 217 | } |
218 | 218 | return false; |
219 | - } |
|
219 | + } |
|
220 | 220 | |
221 | - /** |
|
222 | - * {@inhericDoc} |
|
223 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetHelpTextTag() |
|
224 | - */ |
|
225 | - public function hGetHelpTextTag($tag) { |
|
226 | - switch($tag){ |
|
227 | - case '_ACT': |
|
228 | - return array( |
|
229 | - I18N::translate('Certificate'), |
|
230 | - '<p>'.I18N::translate('Path to a certificate linked to a source reference.').'</p>'); |
|
231 | - default: |
|
232 | - return null; |
|
233 | - } |
|
234 | - } |
|
221 | + /** |
|
222 | + * {@inhericDoc} |
|
223 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetHelpTextTag() |
|
224 | + */ |
|
225 | + public function hGetHelpTextTag($tag) { |
|
226 | + switch($tag){ |
|
227 | + case '_ACT': |
|
228 | + return array( |
|
229 | + I18N::translate('Certificate'), |
|
230 | + '<p>'.I18N::translate('Path to a certificate linked to a source reference.').'</p>'); |
|
231 | + default: |
|
232 | + return null; |
|
233 | + } |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Returns the default Certificate File Provider, as configured in the module |
|
238 | - * |
|
239 | - * @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface |
|
240 | - */ |
|
241 | - public function getProvider() { |
|
242 | - if(!$this->provider) { |
|
243 | - $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); |
|
244 | - $this->provider = new CertificateFileProvider($root_path, Globals::getTree()); |
|
245 | - } |
|
246 | - return $this->provider; |
|
247 | - } |
|
236 | + /** |
|
237 | + * Returns the default Certificate File Provider, as configured in the module |
|
238 | + * |
|
239 | + * @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface |
|
240 | + */ |
|
241 | + public function getProvider() { |
|
242 | + if(!$this->provider) { |
|
243 | + $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); |
|
244 | + $this->provider = new CertificateFileProvider($root_path, Globals::getTree()); |
|
245 | + } |
|
246 | + return $this->provider; |
|
247 | + } |
|
248 | 248 | |
249 | 249 | |
250 | - /** |
|
251 | - * Return the HTML code for custom simple tag _ACT |
|
252 | - * |
|
253 | - * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
254 | - * @param string|null $sid Linked Source ID, if it exists |
|
255 | - */ |
|
256 | - protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
|
257 | - $html = ''; |
|
258 | - if($certificate){ |
|
259 | - $certificate->setSource($sid); |
|
260 | - $html = $certificate->displayImage('icon'); |
|
261 | - } |
|
262 | - return $html; |
|
263 | - } |
|
250 | + /** |
|
251 | + * Return the HTML code for custom simple tag _ACT |
|
252 | + * |
|
253 | + * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
254 | + * @param string|null $sid Linked Source ID, if it exists |
|
255 | + */ |
|
256 | + protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
|
257 | + $html = ''; |
|
258 | + if($certificate){ |
|
259 | + $certificate->setSource($sid); |
|
260 | + $html = $certificate->displayImage('icon'); |
|
261 | + } |
|
262 | + return $html; |
|
263 | + } |
|
264 | 264 | |
265 | 265 | |
266 | 266 | } |
@@ -27,162 +27,162 @@ |
||
27 | 27 | class LineageController extends MvcController |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * Generate the patronymic lineage for this surname |
|
32 | - * @var string $surname Reference surname |
|
33 | - */ |
|
34 | - private $surname; |
|
30 | + /** |
|
31 | + * Generate the patronymic lineage for this surname |
|
32 | + * @var string $surname Reference surname |
|
33 | + */ |
|
34 | + private $surname; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Initial letter |
|
38 | - * @var string $alpha |
|
39 | - */ |
|
40 | - private $alpha; |
|
36 | + /** |
|
37 | + * Initial letter |
|
38 | + * @var string $alpha |
|
39 | + */ |
|
40 | + private $alpha; |
|
41 | 41 | |
42 | - /** |
|
43 | - * Show all names (values: yes|no) |
|
44 | - * @var bool $show |
|
45 | - */ |
|
46 | - private $show_all; |
|
42 | + /** |
|
43 | + * Show all names (values: yes|no) |
|
44 | + * @var bool $show |
|
45 | + */ |
|
46 | + private $show_all; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Page to display (values: surn|lineage) |
|
50 | - * @var unknown $show |
|
51 | - */ |
|
52 | - private $show; |
|
48 | + /** |
|
49 | + * Page to display (values: surn|lineage) |
|
50 | + * @var unknown $show |
|
51 | + */ |
|
52 | + private $show; |
|
53 | 53 | |
54 | - /** |
|
55 | - * Page title |
|
56 | - * @var string $legend |
|
57 | - */ |
|
58 | - private $legend; |
|
54 | + /** |
|
55 | + * Page title |
|
56 | + * @var string $legend |
|
57 | + */ |
|
58 | + private $legend; |
|
59 | 59 | |
60 | - /** |
|
61 | - * {@inheritDoc} |
|
62 | - * @see \MyArtJaub\Webtrees\Mvc\Controller\MvcController::__construct(AbstractModule $module) |
|
63 | - */ |
|
64 | - public function __construct(AbstractModule $module) { |
|
65 | - parent::__construct($module); |
|
60 | + /** |
|
61 | + * {@inheritDoc} |
|
62 | + * @see \MyArtJaub\Webtrees\Mvc\Controller\MvcController::__construct(AbstractModule $module) |
|
63 | + */ |
|
64 | + public function __construct(AbstractModule $module) { |
|
65 | + parent::__construct($module); |
|
66 | 66 | |
67 | - $this->surname = Filter::get('surname'); |
|
68 | - $this->alpha = Filter::get('alpha'); // All surnames beginning with this letter where "@"=unknown and ","=none |
|
69 | - $this->show_all = Filter::get('show_all', 'no|yes', 'no'); // All indis |
|
70 | - // Make sure selections are consistent. |
|
71 | - // i.e. can’t specify show_all and surname at the same time. |
|
72 | - if ($this->show_all === 'yes') { |
|
73 | - $this->alpha = ''; |
|
74 | - $this->surname = ''; |
|
75 | - $this->legend = I18N::translate('All'); |
|
76 | - $this->show = Filter::get('show', 'surn|lineage', 'surn'); |
|
77 | - } elseif ($this->surname) { |
|
78 | - $this->alpha = QueryName::initialLetter($this->surname); // so we can highlight the initial letter |
|
79 | - $this->show_all = 'no'; |
|
80 | - if ($this->surname === '@N.N.') { |
|
81 | - $this->legend = I18N::translateContext('Unknown surname', '…'); |
|
82 | - } else { |
|
83 | - $this->legend = Filter::escapeHtml($this->surname); |
|
84 | - // The surname parameter is a root/canonical form. |
|
85 | - // Display it as the actual surname |
|
86 | - foreach (QueryName::surnames(Globals::getTree(), $this->surname, $this->alpha, false, false) as $details) { |
|
87 | - $this->legend = implode('/', array_keys($details)); |
|
88 | - } |
|
89 | - } |
|
90 | - $this->show = 'lineage'; // SURN list makes no sense here |
|
91 | - } elseif ($this->alpha === '@') { |
|
92 | - $this->show_all = 'no'; |
|
93 | - $this->legend = I18N::translateContext('Unknown surname', '…'); |
|
94 | - $this->show = 'lineage'; // SURN list makes no sense here |
|
95 | - } elseif ($this->alpha === ',') { |
|
96 | - $this->show_all = 'no'; |
|
97 | - $this->legend = I18N::translate('None'); |
|
98 | - $this->show = 'lineage'; // SURN list makes no sense here |
|
99 | - } elseif ($this->alpha) { |
|
100 | - $this->show_all = 'no'; |
|
101 | - $this->legend = Filter::escapeHtml($this->alpha) . '…'; |
|
102 | - $this->show = Filter::get('show', 'surn|lineage', 'surn'); |
|
103 | - } else { |
|
104 | - $this->show_all = 'no'; |
|
105 | - $this->legend = '…'; |
|
106 | - $this->show = 'none'; // Don't show lists until something is chosen |
|
107 | - } |
|
108 | - $this->legend = '<span dir="auto">' . $this->legend . '</span>'; |
|
67 | + $this->surname = Filter::get('surname'); |
|
68 | + $this->alpha = Filter::get('alpha'); // All surnames beginning with this letter where "@"=unknown and ","=none |
|
69 | + $this->show_all = Filter::get('show_all', 'no|yes', 'no'); // All indis |
|
70 | + // Make sure selections are consistent. |
|
71 | + // i.e. can’t specify show_all and surname at the same time. |
|
72 | + if ($this->show_all === 'yes') { |
|
73 | + $this->alpha = ''; |
|
74 | + $this->surname = ''; |
|
75 | + $this->legend = I18N::translate('All'); |
|
76 | + $this->show = Filter::get('show', 'surn|lineage', 'surn'); |
|
77 | + } elseif ($this->surname) { |
|
78 | + $this->alpha = QueryName::initialLetter($this->surname); // so we can highlight the initial letter |
|
79 | + $this->show_all = 'no'; |
|
80 | + if ($this->surname === '@N.N.') { |
|
81 | + $this->legend = I18N::translateContext('Unknown surname', '…'); |
|
82 | + } else { |
|
83 | + $this->legend = Filter::escapeHtml($this->surname); |
|
84 | + // The surname parameter is a root/canonical form. |
|
85 | + // Display it as the actual surname |
|
86 | + foreach (QueryName::surnames(Globals::getTree(), $this->surname, $this->alpha, false, false) as $details) { |
|
87 | + $this->legend = implode('/', array_keys($details)); |
|
88 | + } |
|
89 | + } |
|
90 | + $this->show = 'lineage'; // SURN list makes no sense here |
|
91 | + } elseif ($this->alpha === '@') { |
|
92 | + $this->show_all = 'no'; |
|
93 | + $this->legend = I18N::translateContext('Unknown surname', '…'); |
|
94 | + $this->show = 'lineage'; // SURN list makes no sense here |
|
95 | + } elseif ($this->alpha === ',') { |
|
96 | + $this->show_all = 'no'; |
|
97 | + $this->legend = I18N::translate('None'); |
|
98 | + $this->show = 'lineage'; // SURN list makes no sense here |
|
99 | + } elseif ($this->alpha) { |
|
100 | + $this->show_all = 'no'; |
|
101 | + $this->legend = Filter::escapeHtml($this->alpha) . '…'; |
|
102 | + $this->show = Filter::get('show', 'surn|lineage', 'surn'); |
|
103 | + } else { |
|
104 | + $this->show_all = 'no'; |
|
105 | + $this->legend = '…'; |
|
106 | + $this->show = 'none'; // Don't show lists until something is chosen |
|
107 | + } |
|
108 | + $this->legend = '<span dir="auto">' . $this->legend . '</span>'; |
|
109 | 109 | |
110 | - } |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Indicates whether the list of surname should be displayed |
|
114 | - * @return bool |
|
115 | - */ |
|
116 | - protected function isShowingSurnames() { |
|
117 | - return $this->show === 'surn'; |
|
118 | - } |
|
112 | + /** |
|
113 | + * Indicates whether the list of surname should be displayed |
|
114 | + * @return bool |
|
115 | + */ |
|
116 | + protected function isShowingSurnames() { |
|
117 | + return $this->show === 'surn'; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Indicates whether the lineages should be displayed |
|
122 | - * @return bool |
|
123 | - */ |
|
124 | - protected function isShowingLineages() { |
|
125 | - return $this->show === 'lineage'; |
|
126 | - } |
|
120 | + /** |
|
121 | + * Indicates whether the lineages should be displayed |
|
122 | + * @return bool |
|
123 | + */ |
|
124 | + protected function isShowingLineages() { |
|
125 | + return $this->show === 'lineage'; |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Get list of surnames, starting with the specified initial |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - protected function getSurnamesList() { |
|
133 | - return QueryName::surnames(Globals::getTree(), $this->surname, $this->alpha, false, false); |
|
134 | - } |
|
128 | + /** |
|
129 | + * Get list of surnames, starting with the specified initial |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + protected function getSurnamesList() { |
|
133 | + return QueryName::surnames(Globals::getTree(), $this->surname, $this->alpha, false, false); |
|
134 | + } |
|
135 | 135 | |
136 | - /** |
|
137 | - * Get the lineages for the controller's specified surname |
|
138 | - */ |
|
139 | - protected function getLineages() { |
|
140 | - $builder = new LineageBuilder($this->surname, Globals::getTree()); |
|
136 | + /** |
|
137 | + * Get the lineages for the controller's specified surname |
|
138 | + */ |
|
139 | + protected function getLineages() { |
|
140 | + $builder = new LineageBuilder($this->surname, Globals::getTree()); |
|
141 | 141 | $lineages = $builder->buildLineages(); |
142 | 142 | |
143 | - return $lineages; |
|
144 | - } |
|
143 | + return $lineages; |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Pages |
|
148 | - */ |
|
146 | + /** |
|
147 | + * Pages |
|
148 | + */ |
|
149 | 149 | |
150 | - /** |
|
151 | - * Lineage@index |
|
152 | - */ |
|
153 | - public function index() { |
|
154 | - $controller = new PageController(); |
|
155 | - $controller->setPageTitle( |
|
156 | - $this->show === 'none' ? |
|
157 | - I18N::translate('Patronymic Lineages') : |
|
158 | - I18N::translate('Patronymic Lineages') . ' : ' . $this->legend |
|
159 | - ); |
|
150 | + /** |
|
151 | + * Lineage@index |
|
152 | + */ |
|
153 | + public function index() { |
|
154 | + $controller = new PageController(); |
|
155 | + $controller->setPageTitle( |
|
156 | + $this->show === 'none' ? |
|
157 | + I18N::translate('Patronymic Lineages') : |
|
158 | + I18N::translate('Patronymic Lineages') . ' : ' . $this->legend |
|
159 | + ); |
|
160 | 160 | |
161 | - $view_bag = new ViewBag(); |
|
162 | - $view_bag->set('title', $controller->getPageTitle()); |
|
163 | - $view_bag->set('tree', Globals::getTree()); |
|
164 | - $view_bag->set('alpha', $this->alpha); |
|
165 | - $view_bag->set('surname', $this->surname); |
|
166 | - $view_bag->set('legend', $this->legend); |
|
167 | - $view_bag->set('show_all', $this->show_all); |
|
168 | - if($this->isShowingSurnames()) { |
|
169 | - $view_bag->set('issurnames', true); |
|
170 | - $view_bag->set('surnameslist', $this->getSurnamesList()); |
|
171 | - } |
|
172 | - if($this->isShowingLineages()) { |
|
173 | - $view_bag->set('islineages', true); |
|
174 | - $view_bag->set('lineages', $this->getLineages()); |
|
161 | + $view_bag = new ViewBag(); |
|
162 | + $view_bag->set('title', $controller->getPageTitle()); |
|
163 | + $view_bag->set('tree', Globals::getTree()); |
|
164 | + $view_bag->set('alpha', $this->alpha); |
|
165 | + $view_bag->set('surname', $this->surname); |
|
166 | + $view_bag->set('legend', $this->legend); |
|
167 | + $view_bag->set('show_all', $this->show_all); |
|
168 | + if($this->isShowingSurnames()) { |
|
169 | + $view_bag->set('issurnames', true); |
|
170 | + $view_bag->set('surnameslist', $this->getSurnamesList()); |
|
171 | + } |
|
172 | + if($this->isShowingLineages()) { |
|
173 | + $view_bag->set('islineages', true); |
|
174 | + $view_bag->set('lineages', $this->getLineages()); |
|
175 | 175 | |
176 | - if ($this->show_all==='no') { |
|
177 | - $view_bag->set('table_title', I18N::translate('Individuals in %s lineages', $this->legend)); |
|
178 | - } |
|
179 | - else { |
|
180 | - $view_bag->set('table_title', I18N::translate('All lineages')); |
|
181 | - } |
|
182 | - } |
|
176 | + if ($this->show_all==='no') { |
|
177 | + $view_bag->set('table_title', I18N::translate('Individuals in %s lineages', $this->legend)); |
|
178 | + } |
|
179 | + else { |
|
180 | + $view_bag->set('table_title', I18N::translate('All lineages')); |
|
181 | + } |
|
182 | + } |
|
183 | 183 | |
184 | - ViewFactory::make('Lineage', $this, $controller, $view_bag)->render(); |
|
185 | - } |
|
184 | + ViewFactory::make('Lineage', $this, $controller, $view_bag)->render(); |
|
185 | + } |
|
186 | 186 | |
187 | 187 | |
188 | 188 |