@@ -246,7 +246,6 @@ discard block |
||
246 | 246 | /** |
247 | 247 | * Return the list of all sosas, with the generations it belongs to |
248 | 248 | * |
249 | - * @param int $ged_id ID of the gedcom file |
|
250 | 249 | * @return array Associative array of Sosa ancestors, with their generation, comma separated |
251 | 250 | */ |
252 | 251 | public function getAllSosaWithGenerations(){ |
@@ -266,7 +265,7 @@ discard block |
||
266 | 265 | /** |
267 | 266 | * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
268 | 267 | * |
269 | - * @param number $gen Generation |
|
268 | + * @param integer $gen Generation |
|
270 | 269 | * @return array Array of Sosa individuals |
271 | 270 | */ |
272 | 271 | public function getSosaListAtGeneration($gen){ |
@@ -297,7 +296,7 @@ discard block |
||
297 | 296 | /** |
298 | 297 | * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
299 | 298 | * |
300 | - * @param number $gen Generation |
|
299 | + * @param integer $gen Generation |
|
301 | 300 | * @return array Array of Sosa families |
302 | 301 | */ |
303 | 302 | public function getFamilySosaListAtGeneration($gen){ |
@@ -333,7 +332,7 @@ discard block |
||
333 | 332 | /** |
334 | 333 | * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
335 | 334 | * |
336 | - * @param number $gen Generation |
|
335 | + * @param integer $gen Generation |
|
337 | 336 | * @return array Array of Sosa individuals |
338 | 337 | */ |
339 | 338 | public function getMissingSosaListAtGeneration($gen){ |
@@ -428,8 +427,8 @@ discard block |
||
428 | 427 | /** |
429 | 428 | * Get the number of Sosa in a specific generation. |
430 | 429 | * |
431 | - * @param number $gen Generation |
|
432 | - * @return number Number of Sosas in generation |
|
430 | + * @param integer $gen Generation |
|
431 | + * @return integer Number of Sosas in generation |
|
433 | 432 | */ |
434 | 433 | public function getSosaCountAtGeneration($gen){ |
435 | 434 | if(!$this->is_setup) return 0; |
@@ -447,7 +446,7 @@ discard block |
||
447 | 446 | /** |
448 | 447 | * Get the total number of Sosa up to a specific generation. |
449 | 448 | * |
450 | - * @param number $gen Generation |
|
449 | + * @param integer $gen Generation |
|
451 | 450 | * @return number Total number of Sosas up to generation |
452 | 451 | */ |
453 | 452 | public function getSosaCountUpToGeneration($gen){ |
@@ -482,7 +481,7 @@ discard block |
||
482 | 481 | /** |
483 | 482 | * Get the number of distinct Sosa individual up to a specific generation. |
484 | 483 | * |
485 | - * @param number $gen Generation |
|
484 | + * @param integer $gen Generation |
|
486 | 485 | * @return number Number of distinct Sosa individuals up to generation |
487 | 486 | */ |
488 | 487 | public function getDifferentSosaCountUpToGeneration($gen){ |
@@ -505,7 +504,7 @@ discard block |
||
505 | 504 | * - last : Last birth year in generation |
506 | 505 | * - avg : Average birth year |
507 | 506 | * |
508 | - * @param number $gen Generation |
|
507 | + * @param integer $gen Generation |
|
509 | 508 | * @return array Birth statistics array |
510 | 509 | */ |
511 | 510 | public function getStatsBirthYearInGeneration($gen){ |
@@ -22,378 +22,378 @@ 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(!$this->getRootIndi()) { |
|
98 | - if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | - $this->is_setup = false; |
|
100 | - } |
|
101 | - else { |
|
102 | - $this->user = self::$default_user; |
|
103 | - $this->is_setup = $this->getRootIndi() === null; |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns is the Provider has been successfully set up |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isSetup() { |
|
113 | - return $this->is_setup; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Return the root individual for the reference tree and user. |
|
118 | - * @return string Individual ID |
|
119 | - */ |
|
120 | - public function getRootIndi() { |
|
121 | - return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | - } |
|
96 | + // Check if the user, or the default user, has a root already setup; |
|
97 | + if(!$this->getRootIndi()) { |
|
98 | + if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | + $this->is_setup = false; |
|
100 | + } |
|
101 | + else { |
|
102 | + $this->user = self::$default_user; |
|
103 | + $this->is_setup = $this->getRootIndi() === null; |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns is the Provider has been successfully set up |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isSetup() { |
|
113 | + return $this->is_setup; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Return the root individual for the reference tree and user. |
|
118 | + * @return string Individual ID |
|
119 | + */ |
|
120 | + public function getRootIndi() { |
|
121 | + return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | + } |
|
123 | 123 | |
124 | - /***************** |
|
124 | + /***************** |
|
125 | 125 | * DATA CRUD LAYER |
126 | 126 | *****************/ |
127 | 127 | |
128 | - /** |
|
129 | - * Remove all Sosa entries related to the gedcom file and user |
|
130 | - */ |
|
131 | - public function deleteAll() { |
|
132 | - if(!$this->is_setup) return; |
|
133 | - Database::prepare( |
|
134 | - 'DELETE FROM `##maj_sosa`'. |
|
135 | - ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
136 | - ->execute(array( |
|
137 | - 'tree_id' => $this->tree->getTreeId(), |
|
138 | - 'user_id' => $this->user->getUserId() |
|
139 | - )); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * Remove all ancestors of a sosa number |
|
144 | - * |
|
145 | - * @param int $sosa |
|
146 | - */ |
|
147 | - public function deleteAncestors($sosa) { |
|
148 | - if(!$this->is_setup) return; |
|
149 | - $gen = Functions::getGeneration($sosa); |
|
150 | - Database::prepare( |
|
151 | - 'DELETE FROM `##maj_sosa`'. |
|
152 | - ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
153 | - ' AND majs_gen >= :gen' . |
|
154 | - ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
155 | - )->execute(array( |
|
156 | - 'tree_id' => $this->tree->getTreeId(), |
|
157 | - 'user_id' => $this->user->getUserId(), |
|
158 | - 'gen' => $gen, |
|
159 | - 'sosa' => $sosa |
|
160 | - )); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Insert (or update if already existing) a list of Sosa individuals |
|
165 | - * @param array $sosa_records |
|
166 | - */ |
|
167 | - public function insertOrUpdate($sosa_records) { |
|
168 | - if(!$this->is_setup) return; |
|
128 | + /** |
|
129 | + * Remove all Sosa entries related to the gedcom file and user |
|
130 | + */ |
|
131 | + public function deleteAll() { |
|
132 | + if(!$this->is_setup) return; |
|
133 | + Database::prepare( |
|
134 | + 'DELETE FROM `##maj_sosa`'. |
|
135 | + ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
136 | + ->execute(array( |
|
137 | + 'tree_id' => $this->tree->getTreeId(), |
|
138 | + 'user_id' => $this->user->getUserId() |
|
139 | + )); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * Remove all ancestors of a sosa number |
|
144 | + * |
|
145 | + * @param int $sosa |
|
146 | + */ |
|
147 | + public function deleteAncestors($sosa) { |
|
148 | + if(!$this->is_setup) return; |
|
149 | + $gen = Functions::getGeneration($sosa); |
|
150 | + Database::prepare( |
|
151 | + 'DELETE FROM `##maj_sosa`'. |
|
152 | + ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
153 | + ' AND majs_gen >= :gen' . |
|
154 | + ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
155 | + )->execute(array( |
|
156 | + 'tree_id' => $this->tree->getTreeId(), |
|
157 | + 'user_id' => $this->user->getUserId(), |
|
158 | + 'gen' => $gen, |
|
159 | + 'sosa' => $sosa |
|
160 | + )); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Insert (or update if already existing) a list of Sosa individuals |
|
165 | + * @param array $sosa_records |
|
166 | + */ |
|
167 | + public function insertOrUpdate($sosa_records) { |
|
168 | + if(!$this->is_setup) return; |
|
169 | 169 | |
170 | - $treeid = $this->tree->getTreeId(); |
|
171 | - $userid = $this->user->getUserId(); |
|
172 | - $questionmarks_table = array(); |
|
173 | - $values_table = array(); |
|
170 | + $treeid = $this->tree->getTreeId(); |
|
171 | + $userid = $this->user->getUserId(); |
|
172 | + $questionmarks_table = array(); |
|
173 | + $values_table = array(); |
|
174 | 174 | |
175 | - $i = 0; |
|
176 | - foreach ($sosa_records as $row) { |
|
177 | - $gen = Functions::getGeneration($row['sosa']); |
|
178 | - if($gen <= self::MAX_DB_GENERATIONS) { |
|
179 | - $questionmarks_table[] = |
|
180 | - '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
181 | - $values_table = array_merge( |
|
182 | - $values_table, |
|
183 | - array( |
|
184 | - 'tree_id'.$i => $treeid, |
|
185 | - 'user_id'.$i => $userid, |
|
186 | - 'sosa'.$i => $row['sosa'], |
|
187 | - 'indi_id'.$i => $row['indi'], |
|
188 | - 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
189 | - 'byear'.$i => $row['birth_year'], |
|
190 | - 'dyear'.$i => $row['death_year'] |
|
191 | - ) |
|
192 | - ); |
|
193 | - } |
|
194 | - $i++; |
|
195 | - } |
|
175 | + $i = 0; |
|
176 | + foreach ($sosa_records as $row) { |
|
177 | + $gen = Functions::getGeneration($row['sosa']); |
|
178 | + if($gen <= self::MAX_DB_GENERATIONS) { |
|
179 | + $questionmarks_table[] = |
|
180 | + '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
181 | + $values_table = array_merge( |
|
182 | + $values_table, |
|
183 | + array( |
|
184 | + 'tree_id'.$i => $treeid, |
|
185 | + 'user_id'.$i => $userid, |
|
186 | + 'sosa'.$i => $row['sosa'], |
|
187 | + 'indi_id'.$i => $row['indi'], |
|
188 | + 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
189 | + 'byear'.$i => $row['birth_year'], |
|
190 | + 'dyear'.$i => $row['death_year'] |
|
191 | + ) |
|
192 | + ); |
|
193 | + } |
|
194 | + $i++; |
|
195 | + } |
|
196 | 196 | |
197 | - $sql = 'REPLACE INTO `##maj_sosa`' . |
|
198 | - ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
199 | - ' VALUES '. implode(',', $questionmarks_table); |
|
200 | - Database::prepare($sql)->execute($values_table); |
|
201 | - } |
|
197 | + $sql = 'REPLACE INTO `##maj_sosa`' . |
|
198 | + ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
199 | + ' VALUES '. implode(',', $questionmarks_table); |
|
200 | + Database::prepare($sql)->execute($values_table); |
|
201 | + } |
|
202 | 202 | |
203 | - /**************** |
|
203 | + /**************** |
|
204 | 204 | * SIMPLE QUERIES |
205 | 205 | ****************/ |
206 | 206 | |
207 | - /** |
|
208 | - * Returns the list of Sosa numbers to which an individual is related. |
|
209 | - * Format: key = sosa number, value = generation for the Sosa number |
|
210 | - * |
|
211 | - * @param Individual $indi |
|
212 | - * @return array Array of sosa numbers |
|
213 | - */ |
|
214 | - public function getSosaNumbers(Individual $indi) { |
|
215 | - if(!$this->is_setup) return array(); |
|
216 | - return Database::prepare( |
|
217 | - 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
218 | - ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
219 | - )->execute(array( |
|
220 | - 'indi_id' => $indi->getXref(), |
|
221 | - 'tree_id' => $this->tree->getTreeId(), |
|
222 | - 'user_id' => $this->user->getUserId() |
|
223 | - ))->fetchAssoc(); |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * Get the last generation of Sosa ancestors |
|
228 | - * |
|
229 | - * @return number Last generation if found, 1 otherwise |
|
230 | - */ |
|
231 | - public function getLastGeneration() { |
|
232 | - if(!$this->is_setup) return; |
|
233 | - return Database::prepare( |
|
234 | - 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
235 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
236 | - )->execute(array( |
|
237 | - 'tree_id' => $this->tree->getTreeId(), |
|
238 | - 'user_id' => $this->user->getUserId() |
|
239 | - ))->fetchOne() ?: 1; |
|
240 | - } |
|
241 | - |
|
242 | - /************* |
|
207 | + /** |
|
208 | + * Returns the list of Sosa numbers to which an individual is related. |
|
209 | + * Format: key = sosa number, value = generation for the Sosa number |
|
210 | + * |
|
211 | + * @param Individual $indi |
|
212 | + * @return array Array of sosa numbers |
|
213 | + */ |
|
214 | + public function getSosaNumbers(Individual $indi) { |
|
215 | + if(!$this->is_setup) return array(); |
|
216 | + return Database::prepare( |
|
217 | + 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
218 | + ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
219 | + )->execute(array( |
|
220 | + 'indi_id' => $indi->getXref(), |
|
221 | + 'tree_id' => $this->tree->getTreeId(), |
|
222 | + 'user_id' => $this->user->getUserId() |
|
223 | + ))->fetchAssoc(); |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * Get the last generation of Sosa ancestors |
|
228 | + * |
|
229 | + * @return number Last generation if found, 1 otherwise |
|
230 | + */ |
|
231 | + public function getLastGeneration() { |
|
232 | + if(!$this->is_setup) return; |
|
233 | + return Database::prepare( |
|
234 | + 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
235 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
236 | + )->execute(array( |
|
237 | + 'tree_id' => $this->tree->getTreeId(), |
|
238 | + 'user_id' => $this->user->getUserId() |
|
239 | + ))->fetchOne() ?: 1; |
|
240 | + } |
|
241 | + |
|
242 | + /************* |
|
243 | 243 | * SOSA LISTS |
244 | 244 | *************/ |
245 | 245 | |
246 | - /** |
|
247 | - * Return the list of all sosas, with the generations it belongs to |
|
248 | - * |
|
249 | - * @param int $ged_id ID of the gedcom file |
|
250 | - * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
251 | - */ |
|
252 | - public function getAllSosaWithGenerations(){ |
|
253 | - if(!$this->is_setup) return array(); |
|
254 | - return Database::prepare( |
|
255 | - 'SELECT majs_i_id AS indi,' . |
|
256 | - ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
257 | - ' FROM `##maj_sosa`' . |
|
258 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
259 | - ' GROUP BY majs_i_id' |
|
260 | - )->execute(array( |
|
261 | - 'tree_id' => $this->tree->getTreeId(), |
|
262 | - 'user_id' => $this->user->getUserId() |
|
263 | - ))->fetchAssoc(); |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
268 | - * |
|
269 | - * @param number $gen Generation |
|
270 | - * @return array Array of Sosa individuals |
|
271 | - */ |
|
272 | - public function getSosaListAtGeneration($gen){ |
|
273 | - if(!$this->is_setup) return array(); |
|
274 | - if(!$this->sosa_list_by_gen) |
|
275 | - $this->sosa_list_by_gen = array(); |
|
246 | + /** |
|
247 | + * Return the list of all sosas, with the generations it belongs to |
|
248 | + * |
|
249 | + * @param int $ged_id ID of the gedcom file |
|
250 | + * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
251 | + */ |
|
252 | + public function getAllSosaWithGenerations(){ |
|
253 | + if(!$this->is_setup) return array(); |
|
254 | + return Database::prepare( |
|
255 | + 'SELECT majs_i_id AS indi,' . |
|
256 | + ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
257 | + ' FROM `##maj_sosa`' . |
|
258 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
259 | + ' GROUP BY majs_i_id' |
|
260 | + )->execute(array( |
|
261 | + 'tree_id' => $this->tree->getTreeId(), |
|
262 | + 'user_id' => $this->user->getUserId() |
|
263 | + ))->fetchAssoc(); |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
268 | + * |
|
269 | + * @param number $gen Generation |
|
270 | + * @return array Array of Sosa individuals |
|
271 | + */ |
|
272 | + public function getSosaListAtGeneration($gen){ |
|
273 | + if(!$this->is_setup) return array(); |
|
274 | + if(!$this->sosa_list_by_gen) |
|
275 | + $this->sosa_list_by_gen = array(); |
|
276 | 276 | |
277 | - if($gen){ |
|
278 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
279 | - $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
280 | - 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
281 | - ' FROM `##maj_sosa`'. |
|
282 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
283 | - ' AND majs_gen = :gen'. |
|
284 | - ' ORDER BY majs_sosa ASC') |
|
285 | - ->execute(array( |
|
286 | - 'tree_id' => $this->tree->getTreeId(), |
|
287 | - 'user_id' => $this->user->getUserId(), |
|
288 | - 'gen' => $gen |
|
289 | - )) |
|
290 | - ->fetchAssoc(); |
|
291 | - } |
|
292 | - return $this->sosa_list_by_gen[$gen]; |
|
293 | - } |
|
294 | - return array(); |
|
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
299 | - * |
|
300 | - * @param number $gen Generation |
|
301 | - * @return array Array of Sosa families |
|
302 | - */ |
|
303 | - public function getFamilySosaListAtGeneration($gen){ |
|
304 | - if(!$this->is_setup) return array(); |
|
305 | - if(!$this->sosa_fam_list_by_gen) |
|
306 | - $this->sosa_fam_list_by_gen = array(); |
|
277 | + if($gen){ |
|
278 | + if(!isset($this->sosa_list_by_gen[$gen])){ |
|
279 | + $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
280 | + 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
281 | + ' FROM `##maj_sosa`'. |
|
282 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
283 | + ' AND majs_gen = :gen'. |
|
284 | + ' ORDER BY majs_sosa ASC') |
|
285 | + ->execute(array( |
|
286 | + 'tree_id' => $this->tree->getTreeId(), |
|
287 | + 'user_id' => $this->user->getUserId(), |
|
288 | + 'gen' => $gen |
|
289 | + )) |
|
290 | + ->fetchAssoc(); |
|
291 | + } |
|
292 | + return $this->sosa_list_by_gen[$gen]; |
|
293 | + } |
|
294 | + return array(); |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
299 | + * |
|
300 | + * @param number $gen Generation |
|
301 | + * @return array Array of Sosa families |
|
302 | + */ |
|
303 | + public function getFamilySosaListAtGeneration($gen){ |
|
304 | + if(!$this->is_setup) return array(); |
|
305 | + if(!$this->sosa_fam_list_by_gen) |
|
306 | + $this->sosa_fam_list_by_gen = array(); |
|
307 | 307 | |
308 | - if($gen){ |
|
309 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
310 | - $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
311 | - 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
312 | - ' FROM `##families`'. |
|
313 | - ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
314 | - ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
315 | - ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
316 | - ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
317 | - ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
318 | - ' AND s1.majs_gen = :gen'. |
|
319 | - ' ORDER BY s1.majs_sosa ASC' |
|
320 | - ) |
|
321 | - ->execute(array( |
|
322 | - 'tree_id' => $this->tree->getTreeId(), |
|
323 | - 'user_id' => $this->user->getUserId(), |
|
324 | - 'gen' => $gen |
|
325 | - )) |
|
326 | - ->fetchAssoc(); |
|
327 | - } |
|
328 | - return $this->sosa_fam_list_by_gen[$gen]; |
|
329 | - } |
|
330 | - return array(); |
|
331 | - } |
|
332 | - |
|
333 | - /** |
|
334 | - * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
335 | - * |
|
336 | - * @param number $gen Generation |
|
337 | - * @return array Array of Sosa individuals |
|
338 | - */ |
|
339 | - public function getMissingSosaListAtGeneration($gen){ |
|
340 | - if(!$this->is_setup) return array(); |
|
341 | - if($gen){ |
|
342 | - return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
343 | - 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
|
344 | - ' FROM `##maj_sosa` schild'. |
|
345 | - ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'. |
|
346 | - ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'. |
|
347 | - ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
348 | - ' AND schild.majs_gen = :gen'. |
|
349 | - ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
350 | - ' ORDER BY schild.majs_sosa ASC') |
|
351 | - ->execute(array( |
|
352 | - 'tree_id' => $this->tree->getTreeId(), |
|
353 | - 'user_id' => $this->user->getUserId(), |
|
354 | - 'gen' => $gen - 1 |
|
355 | - ))->fetchAll(\PDO::FETCH_ASSOC); |
|
356 | - } |
|
357 | - return array(); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /************* |
|
308 | + if($gen){ |
|
309 | + if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
310 | + $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
311 | + 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
312 | + ' FROM `##families`'. |
|
313 | + ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
314 | + ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
315 | + ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
316 | + ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
317 | + ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
318 | + ' AND s1.majs_gen = :gen'. |
|
319 | + ' ORDER BY s1.majs_sosa ASC' |
|
320 | + ) |
|
321 | + ->execute(array( |
|
322 | + 'tree_id' => $this->tree->getTreeId(), |
|
323 | + 'user_id' => $this->user->getUserId(), |
|
324 | + 'gen' => $gen |
|
325 | + )) |
|
326 | + ->fetchAssoc(); |
|
327 | + } |
|
328 | + return $this->sosa_fam_list_by_gen[$gen]; |
|
329 | + } |
|
330 | + return array(); |
|
331 | + } |
|
332 | + |
|
333 | + /** |
|
334 | + * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
335 | + * |
|
336 | + * @param number $gen Generation |
|
337 | + * @return array Array of Sosa individuals |
|
338 | + */ |
|
339 | + public function getMissingSosaListAtGeneration($gen){ |
|
340 | + if(!$this->is_setup) return array(); |
|
341 | + if($gen){ |
|
342 | + return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
343 | + 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
|
344 | + ' FROM `##maj_sosa` schild'. |
|
345 | + ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'. |
|
346 | + ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'. |
|
347 | + ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
348 | + ' AND schild.majs_gen = :gen'. |
|
349 | + ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
350 | + ' ORDER BY schild.majs_sosa ASC') |
|
351 | + ->execute(array( |
|
352 | + 'tree_id' => $this->tree->getTreeId(), |
|
353 | + 'user_id' => $this->user->getUserId(), |
|
354 | + 'gen' => $gen - 1 |
|
355 | + ))->fetchAll(\PDO::FETCH_ASSOC); |
|
356 | + } |
|
357 | + return array(); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /************* |
|
363 | 363 | * STATISTICS |
364 | 364 | *************/ |
365 | - /** |
|
366 | - * Get the statistic array detailed by generation. |
|
367 | - * Statistics for each generation are: |
|
368 | - * - The number of Sosa in generation |
|
369 | - * - The number of Sosa up to generation |
|
370 | - * - The number of distinct Sosa up to generation |
|
371 | - * - The year of the first birth in generation |
|
372 | - * - The year of the last birth in generation |
|
373 | - * - The average year of birth in generation |
|
374 | - * |
|
375 | - * @return array Statistics array |
|
376 | - */ |
|
377 | - public function getStatisticsByGeneration() { |
|
378 | - if(!$this->is_setup) return array(); |
|
379 | - if(!$this->statistics_tab) { |
|
380 | - $this->statistics_tab = array(); |
|
381 | - if($maxGeneration = $this->getLastGeneration()) { |
|
382 | - for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
383 | - $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
384 | - $this->statistics_tab[$gen] = array( |
|
385 | - 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
386 | - 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
387 | - 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
388 | - 'firstBirth' => $birthStats['first'], |
|
389 | - 'lastBirth' => $birthStats['last'], |
|
390 | - 'avgBirth' => $birthStats['avg'] |
|
391 | - ); |
|
392 | - } |
|
393 | - } |
|
394 | - } |
|
395 | - return $this->statistics_tab; |
|
396 | - } |
|
365 | + /** |
|
366 | + * Get the statistic array detailed by generation. |
|
367 | + * Statistics for each generation are: |
|
368 | + * - The number of Sosa in generation |
|
369 | + * - The number of Sosa up to generation |
|
370 | + * - The number of distinct Sosa up to generation |
|
371 | + * - The year of the first birth in generation |
|
372 | + * - The year of the last birth in generation |
|
373 | + * - The average year of birth in generation |
|
374 | + * |
|
375 | + * @return array Statistics array |
|
376 | + */ |
|
377 | + public function getStatisticsByGeneration() { |
|
378 | + if(!$this->is_setup) return array(); |
|
379 | + if(!$this->statistics_tab) { |
|
380 | + $this->statistics_tab = array(); |
|
381 | + if($maxGeneration = $this->getLastGeneration()) { |
|
382 | + for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
383 | + $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
384 | + $this->statistics_tab[$gen] = array( |
|
385 | + 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
386 | + 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
387 | + 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
388 | + 'firstBirth' => $birthStats['first'], |
|
389 | + 'lastBirth' => $birthStats['last'], |
|
390 | + 'avgBirth' => $birthStats['avg'] |
|
391 | + ); |
|
392 | + } |
|
393 | + } |
|
394 | + } |
|
395 | + return $this->statistics_tab; |
|
396 | + } |
|
397 | 397 | |
398 | 398 | /** |
399 | 399 | * How many individuals exist in the tree. |
@@ -401,205 +401,205 @@ discard block |
||
401 | 401 | * @return int |
402 | 402 | */ |
403 | 403 | public function getTotalIndividuals() { |
404 | - if(!$this->is_setup) return 0; |
|
405 | - return Database::prepare( |
|
406 | - 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
|
407 | - ' WHERE i_file = :tree_id') |
|
408 | - ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
409 | - ->fetchOne() ?: 0; |
|
404 | + if(!$this->is_setup) return 0; |
|
405 | + return Database::prepare( |
|
406 | + 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
|
407 | + ' WHERE i_file = :tree_id') |
|
408 | + ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
409 | + ->fetchOne() ?: 0; |
|
410 | 410 | } |
411 | 411 | |
412 | - /** |
|
413 | - * Get the total Sosa count for all generations |
|
414 | - * |
|
415 | - * @return number Number of Sosas |
|
416 | - */ |
|
417 | - public function getSosaCount(){ |
|
418 | - if(!$this->is_setup) return 0; |
|
419 | - return Database::prepare( |
|
420 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
421 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
422 | - ->execute(array( |
|
423 | - 'tree_id' => $this->tree->getTreeId(), |
|
424 | - 'user_id' => $this->user->getUserId() |
|
425 | - ))->fetchOne() ?: 0; |
|
426 | - } |
|
427 | - |
|
428 | - /** |
|
429 | - * Get the number of Sosa in a specific generation. |
|
430 | - * |
|
431 | - * @param number $gen Generation |
|
432 | - * @return number Number of Sosas in generation |
|
433 | - */ |
|
434 | - public function getSosaCountAtGeneration($gen){ |
|
435 | - if(!$this->is_setup) return 0; |
|
436 | - return Database::prepare( |
|
437 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
438 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
439 | - ' AND majs_gen= :gen') |
|
440 | - ->execute(array( |
|
441 | - 'tree_id' => $this->tree->getTreeId(), |
|
442 | - 'user_id' => $this->user->getUserId(), |
|
443 | - 'gen' => $gen |
|
444 | - ))->fetchOne() ?: 0; |
|
445 | - } |
|
446 | - |
|
447 | - /** |
|
448 | - * Get the total number of Sosa up to a specific generation. |
|
449 | - * |
|
450 | - * @param number $gen Generation |
|
451 | - * @return number Total number of Sosas up to generation |
|
452 | - */ |
|
453 | - public function getSosaCountUpToGeneration($gen){ |
|
454 | - if(!$this->is_setup) return 0; |
|
455 | - return Database::prepare( |
|
456 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
457 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
458 | - ' AND majs_gen <= :gen') |
|
459 | - ->execute(array( |
|
460 | - 'tree_id' => $this->tree->getTreeId(), |
|
461 | - 'user_id' => $this->user->getUserId(), |
|
462 | - 'gen' => $gen |
|
463 | - ))->fetchOne() ?: 0; |
|
464 | - } |
|
465 | - |
|
466 | - /** |
|
467 | - * Get the total number of distinct Sosa individual for all generations. |
|
468 | - * |
|
469 | - * @return number Total number of distinct individual |
|
470 | - */ |
|
471 | - public function getDifferentSosaCount(){ |
|
472 | - if(!$this->is_setup) return 0; |
|
473 | - return Database::prepare( |
|
474 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
475 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
476 | - ->execute(array( |
|
477 | - 'tree_id' => $this->tree->getTreeId(), |
|
478 | - 'user_id' => $this->user->getUserId() |
|
479 | - ))->fetchOne() ?: 0; |
|
480 | - } |
|
481 | - |
|
482 | - /** |
|
483 | - * Get the number of distinct Sosa individual up to a specific generation. |
|
484 | - * |
|
485 | - * @param number $gen Generation |
|
486 | - * @return number Number of distinct Sosa individuals up to generation |
|
487 | - */ |
|
488 | - public function getDifferentSosaCountUpToGeneration($gen){ |
|
489 | - if(!$this->is_setup) return 0; |
|
490 | - return Database::prepare( |
|
491 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
492 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
493 | - ' AND majs_gen <= :gen') |
|
494 | - ->execute(array( |
|
495 | - 'tree_id' => $this->tree->getTreeId(), |
|
496 | - 'user_id' => $this->user->getUserId(), |
|
497 | - 'gen' => $gen |
|
498 | - ))->fetchOne() ?: 0; |
|
499 | - } |
|
500 | - |
|
501 | - /** |
|
502 | - * Get an array of birth statistics for a specific generation |
|
503 | - * Statistics are : |
|
504 | - * - first : First birth year in generation |
|
505 | - * - last : Last birth year in generation |
|
506 | - * - avg : Average birth year |
|
507 | - * |
|
508 | - * @param number $gen Generation |
|
509 | - * @return array Birth statistics array |
|
510 | - */ |
|
511 | - public function getStatsBirthYearInGeneration($gen){ |
|
512 | - if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
513 | - return Database::prepare( |
|
514 | - 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
|
515 | - ' FROM `##maj_sosa`' . |
|
516 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
517 | - ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
|
518 | - ->execute(array( |
|
519 | - 'tree_id' => $this->tree->getTreeId(), |
|
520 | - 'user_id' => $this->user->getUserId(), |
|
521 | - 'gen' => $gen, |
|
522 | - 'birth_year' => 0)) |
|
523 | - ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0); |
|
524 | - } |
|
525 | - |
|
526 | - /** |
|
527 | - * Get the mean generation time, based on a linear regression of birth years and generations |
|
528 | - * |
|
529 | - * @return number|NULL Mean generation time |
|
530 | - */ |
|
531 | - public function getMeanGenerationTime(){ |
|
532 | - if(!$this->is_setup) return; |
|
533 | - if(!$this->statistics_tab){ |
|
534 | - $this->getStatisticsByGeneration(); |
|
535 | - } |
|
536 | - //Linear regression on x=generation and y=birthdate |
|
537 | - $sum_xy = 0; |
|
538 | - $sum_x=0; |
|
539 | - $sum_y=0; |
|
540 | - $sum_x2=0; |
|
541 | - $n=count($this->statistics_tab); |
|
542 | - foreach($this->statistics_tab as $gen=>$stats){ |
|
543 | - $sum_xy+=$gen*$stats['avgBirth']; |
|
544 | - $sum_x+=$gen; |
|
545 | - $sum_y+=$stats['avgBirth']; |
|
546 | - $sum_x2+=$gen*$gen; |
|
547 | - } |
|
548 | - $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
549 | - if($denom!=0){ |
|
550 | - return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
551 | - } |
|
552 | - return null; |
|
553 | - } |
|
554 | - |
|
555 | - /** |
|
556 | - * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
557 | - * at a specified generation. |
|
558 | - * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
559 | - * |
|
560 | - * Format: |
|
561 | - * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
562 | - * -1 is used for shared ancestors |
|
563 | - * For instance base2(0100) = base10(4) represent the maternal grand father |
|
564 | - * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
565 | - * |
|
566 | - * For instance a result at generation 3 could be : |
|
567 | - * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
568 | - * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
569 | - * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
570 | - * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
571 | - * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
572 | - * ) |
|
573 | - * |
|
574 | - * @param int $gen Reference generation |
|
575 | - * @return array |
|
576 | - */ |
|
577 | - public function getAncestorDispersionForGen($gen) { |
|
578 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
579 | - return Database::prepare( |
|
580 | - 'SELECT branches, count(i_id)'. |
|
581 | - ' FROM ('. |
|
582 | - ' SELECT i_id,'. |
|
583 | - ' CASE'. |
|
584 | - ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
585 | - ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
586 | - ' END branches'. |
|
587 | - ' FROM ('. |
|
588 | - ' SELECT DISTINCT majs_i_id i_id,'. |
|
589 | - ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
590 | - ' FROM `##maj_sosa`'. |
|
591 | - ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
592 | - ' AND majs_gen >= :gen'. |
|
593 | - ' ) indistat'. |
|
594 | - ' GROUP BY i_id'. |
|
595 | - ') grouped'. |
|
596 | - ' GROUP BY branches') |
|
597 | - ->execute(array( |
|
598 | - 'tree_id' => $this->tree->getTreeId(), |
|
599 | - 'user_id' => $this->user->getUserId(), |
|
600 | - 'gen' => $gen |
|
601 | - ))->fetchAssoc() ?: array(); |
|
602 | - } |
|
412 | + /** |
|
413 | + * Get the total Sosa count for all generations |
|
414 | + * |
|
415 | + * @return number Number of Sosas |
|
416 | + */ |
|
417 | + public function getSosaCount(){ |
|
418 | + if(!$this->is_setup) return 0; |
|
419 | + return Database::prepare( |
|
420 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
421 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
422 | + ->execute(array( |
|
423 | + 'tree_id' => $this->tree->getTreeId(), |
|
424 | + 'user_id' => $this->user->getUserId() |
|
425 | + ))->fetchOne() ?: 0; |
|
426 | + } |
|
427 | + |
|
428 | + /** |
|
429 | + * Get the number of Sosa in a specific generation. |
|
430 | + * |
|
431 | + * @param number $gen Generation |
|
432 | + * @return number Number of Sosas in generation |
|
433 | + */ |
|
434 | + public function getSosaCountAtGeneration($gen){ |
|
435 | + if(!$this->is_setup) return 0; |
|
436 | + return Database::prepare( |
|
437 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
438 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
439 | + ' AND majs_gen= :gen') |
|
440 | + ->execute(array( |
|
441 | + 'tree_id' => $this->tree->getTreeId(), |
|
442 | + 'user_id' => $this->user->getUserId(), |
|
443 | + 'gen' => $gen |
|
444 | + ))->fetchOne() ?: 0; |
|
445 | + } |
|
446 | + |
|
447 | + /** |
|
448 | + * Get the total number of Sosa up to a specific generation. |
|
449 | + * |
|
450 | + * @param number $gen Generation |
|
451 | + * @return number Total number of Sosas up to generation |
|
452 | + */ |
|
453 | + public function getSosaCountUpToGeneration($gen){ |
|
454 | + if(!$this->is_setup) return 0; |
|
455 | + return Database::prepare( |
|
456 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
457 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
458 | + ' AND majs_gen <= :gen') |
|
459 | + ->execute(array( |
|
460 | + 'tree_id' => $this->tree->getTreeId(), |
|
461 | + 'user_id' => $this->user->getUserId(), |
|
462 | + 'gen' => $gen |
|
463 | + ))->fetchOne() ?: 0; |
|
464 | + } |
|
465 | + |
|
466 | + /** |
|
467 | + * Get the total number of distinct Sosa individual for all generations. |
|
468 | + * |
|
469 | + * @return number Total number of distinct individual |
|
470 | + */ |
|
471 | + public function getDifferentSosaCount(){ |
|
472 | + if(!$this->is_setup) return 0; |
|
473 | + return Database::prepare( |
|
474 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
475 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
476 | + ->execute(array( |
|
477 | + 'tree_id' => $this->tree->getTreeId(), |
|
478 | + 'user_id' => $this->user->getUserId() |
|
479 | + ))->fetchOne() ?: 0; |
|
480 | + } |
|
481 | + |
|
482 | + /** |
|
483 | + * Get the number of distinct Sosa individual up to a specific generation. |
|
484 | + * |
|
485 | + * @param number $gen Generation |
|
486 | + * @return number Number of distinct Sosa individuals up to generation |
|
487 | + */ |
|
488 | + public function getDifferentSosaCountUpToGeneration($gen){ |
|
489 | + if(!$this->is_setup) return 0; |
|
490 | + return Database::prepare( |
|
491 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
492 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
493 | + ' AND majs_gen <= :gen') |
|
494 | + ->execute(array( |
|
495 | + 'tree_id' => $this->tree->getTreeId(), |
|
496 | + 'user_id' => $this->user->getUserId(), |
|
497 | + 'gen' => $gen |
|
498 | + ))->fetchOne() ?: 0; |
|
499 | + } |
|
500 | + |
|
501 | + /** |
|
502 | + * Get an array of birth statistics for a specific generation |
|
503 | + * Statistics are : |
|
504 | + * - first : First birth year in generation |
|
505 | + * - last : Last birth year in generation |
|
506 | + * - avg : Average birth year |
|
507 | + * |
|
508 | + * @param number $gen Generation |
|
509 | + * @return array Birth statistics array |
|
510 | + */ |
|
511 | + public function getStatsBirthYearInGeneration($gen){ |
|
512 | + if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
513 | + return Database::prepare( |
|
514 | + 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
|
515 | + ' FROM `##maj_sosa`' . |
|
516 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
517 | + ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
|
518 | + ->execute(array( |
|
519 | + 'tree_id' => $this->tree->getTreeId(), |
|
520 | + 'user_id' => $this->user->getUserId(), |
|
521 | + 'gen' => $gen, |
|
522 | + 'birth_year' => 0)) |
|
523 | + ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0); |
|
524 | + } |
|
525 | + |
|
526 | + /** |
|
527 | + * Get the mean generation time, based on a linear regression of birth years and generations |
|
528 | + * |
|
529 | + * @return number|NULL Mean generation time |
|
530 | + */ |
|
531 | + public function getMeanGenerationTime(){ |
|
532 | + if(!$this->is_setup) return; |
|
533 | + if(!$this->statistics_tab){ |
|
534 | + $this->getStatisticsByGeneration(); |
|
535 | + } |
|
536 | + //Linear regression on x=generation and y=birthdate |
|
537 | + $sum_xy = 0; |
|
538 | + $sum_x=0; |
|
539 | + $sum_y=0; |
|
540 | + $sum_x2=0; |
|
541 | + $n=count($this->statistics_tab); |
|
542 | + foreach($this->statistics_tab as $gen=>$stats){ |
|
543 | + $sum_xy+=$gen*$stats['avgBirth']; |
|
544 | + $sum_x+=$gen; |
|
545 | + $sum_y+=$stats['avgBirth']; |
|
546 | + $sum_x2+=$gen*$gen; |
|
547 | + } |
|
548 | + $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
549 | + if($denom!=0){ |
|
550 | + return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
551 | + } |
|
552 | + return null; |
|
553 | + } |
|
554 | + |
|
555 | + /** |
|
556 | + * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
557 | + * at a specified generation. |
|
558 | + * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
559 | + * |
|
560 | + * Format: |
|
561 | + * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
562 | + * -1 is used for shared ancestors |
|
563 | + * For instance base2(0100) = base10(4) represent the maternal grand father |
|
564 | + * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
565 | + * |
|
566 | + * For instance a result at generation 3 could be : |
|
567 | + * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
568 | + * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
569 | + * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
570 | + * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
571 | + * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
572 | + * ) |
|
573 | + * |
|
574 | + * @param int $gen Reference generation |
|
575 | + * @return array |
|
576 | + */ |
|
577 | + public function getAncestorDispersionForGen($gen) { |
|
578 | + if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
579 | + return Database::prepare( |
|
580 | + 'SELECT branches, count(i_id)'. |
|
581 | + ' FROM ('. |
|
582 | + ' SELECT i_id,'. |
|
583 | + ' CASE'. |
|
584 | + ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
585 | + ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
586 | + ' END branches'. |
|
587 | + ' FROM ('. |
|
588 | + ' SELECT DISTINCT majs_i_id i_id,'. |
|
589 | + ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
590 | + ' FROM `##maj_sosa`'. |
|
591 | + ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
592 | + ' AND majs_gen >= :gen'. |
|
593 | + ' ) indistat'. |
|
594 | + ' GROUP BY i_id'. |
|
595 | + ') grouped'. |
|
596 | + ' GROUP BY branches') |
|
597 | + ->execute(array( |
|
598 | + 'tree_id' => $this->tree->getTreeId(), |
|
599 | + 'user_id' => $this->user->getUserId(), |
|
600 | + 'gen' => $gen |
|
601 | + ))->fetchAssoc() ?: array(); |
|
602 | + } |
|
603 | 603 | |
604 | 604 | |
605 | 605 | } |
@@ -84,18 +84,18 @@ discard block |
||
84 | 84 | * @param User $user |
85 | 85 | */ |
86 | 86 | public function __construct(Tree $tree, User $user = null) { |
87 | - if(self::$default_user === null) |
|
87 | + if (self::$default_user === null) |
|
88 | 88 | self::$default_user = User::find(-1); |
89 | 89 | |
90 | 90 | $this->tree = $tree; |
91 | 91 | $this->user = $user; |
92 | 92 | $this->is_setup = true; |
93 | - if($this->user === null) $this->user = Auth::user(); |
|
94 | - if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
93 | + if ($this->user === null) $this->user = Auth::user(); |
|
94 | + if (strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
95 | 95 | |
96 | 96 | // Check if the user, or the default user, has a root already setup; |
97 | - if(!$this->getRootIndi()) { |
|
98 | - if($this->user == self::$default_user) { // If the default user is not setup |
|
97 | + if (!$this->getRootIndi()) { |
|
98 | + if ($this->user == self::$default_user) { // If the default user is not setup |
|
99 | 99 | $this->is_setup = false; |
100 | 100 | } |
101 | 101 | else { |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | * Remove all Sosa entries related to the gedcom file and user |
130 | 130 | */ |
131 | 131 | public function deleteAll() { |
132 | - if(!$this->is_setup) return; |
|
132 | + if (!$this->is_setup) return; |
|
133 | 133 | Database::prepare( |
134 | 134 | 'DELETE FROM `##maj_sosa`'. |
135 | 135 | ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
@@ -145,12 +145,12 @@ discard block |
||
145 | 145 | * @param int $sosa |
146 | 146 | */ |
147 | 147 | public function deleteAncestors($sosa) { |
148 | - if(!$this->is_setup) return; |
|
148 | + if (!$this->is_setup) return; |
|
149 | 149 | $gen = Functions::getGeneration($sosa); |
150 | 150 | Database::prepare( |
151 | 151 | 'DELETE FROM `##maj_sosa`'. |
152 | - ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
153 | - ' AND majs_gen >= :gen' . |
|
152 | + ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id'. |
|
153 | + ' AND majs_gen >= :gen'. |
|
154 | 154 | ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
155 | 155 | )->execute(array( |
156 | 156 | 'tree_id' => $this->tree->getTreeId(), |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @param array $sosa_records |
166 | 166 | */ |
167 | 167 | public function insertOrUpdate($sosa_records) { |
168 | - if(!$this->is_setup) return; |
|
168 | + if (!$this->is_setup) return; |
|
169 | 169 | |
170 | 170 | $treeid = $this->tree->getTreeId(); |
171 | 171 | $userid = $this->user->getUserId(); |
@@ -173,9 +173,9 @@ discard block |
||
173 | 173 | $values_table = array(); |
174 | 174 | |
175 | 175 | $i = 0; |
176 | - foreach ($sosa_records as $row) { |
|
176 | + foreach ($sosa_records as $row) { |
|
177 | 177 | $gen = Functions::getGeneration($row['sosa']); |
178 | - if($gen <= self::MAX_DB_GENERATIONS) { |
|
178 | + if ($gen <= self::MAX_DB_GENERATIONS) { |
|
179 | 179 | $questionmarks_table[] = |
180 | 180 | '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
181 | 181 | $values_table = array_merge( |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | $i++; |
195 | 195 | } |
196 | 196 | |
197 | - $sql = 'REPLACE INTO `##maj_sosa`' . |
|
198 | - ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
199 | - ' VALUES '. implode(',', $questionmarks_table); |
|
197 | + $sql = 'REPLACE INTO `##maj_sosa`'. |
|
198 | + ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)'. |
|
199 | + ' VALUES '.implode(',', $questionmarks_table); |
|
200 | 200 | Database::prepare($sql)->execute($values_table); |
201 | 201 | } |
202 | 202 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | * @return array Array of sosa numbers |
213 | 213 | */ |
214 | 214 | public function getSosaNumbers(Individual $indi) { |
215 | - if(!$this->is_setup) return array(); |
|
215 | + if (!$this->is_setup) return array(); |
|
216 | 216 | return Database::prepare( |
217 | 217 | 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
218 | 218 | ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * @return number Last generation if found, 1 otherwise |
230 | 230 | */ |
231 | 231 | public function getLastGeneration() { |
232 | - if(!$this->is_setup) return; |
|
232 | + if (!$this->is_setup) return; |
|
233 | 233 | return Database::prepare( |
234 | 234 | 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
235 | 235 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -249,13 +249,13 @@ discard block |
||
249 | 249 | * @param int $ged_id ID of the gedcom file |
250 | 250 | * @return array Associative array of Sosa ancestors, with their generation, comma separated |
251 | 251 | */ |
252 | - public function getAllSosaWithGenerations(){ |
|
253 | - if(!$this->is_setup) return array(); |
|
252 | + public function getAllSosaWithGenerations() { |
|
253 | + if (!$this->is_setup) return array(); |
|
254 | 254 | return Database::prepare( |
255 | - 'SELECT majs_i_id AS indi,' . |
|
256 | - ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
257 | - ' FROM `##maj_sosa`' . |
|
258 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
255 | + 'SELECT majs_i_id AS indi,'. |
|
256 | + ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations'. |
|
257 | + ' FROM `##maj_sosa`'. |
|
258 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
259 | 259 | ' GROUP BY majs_i_id' |
260 | 260 | )->execute(array( |
261 | 261 | 'tree_id' => $this->tree->getTreeId(), |
@@ -269,13 +269,13 @@ discard block |
||
269 | 269 | * @param number $gen Generation |
270 | 270 | * @return array Array of Sosa individuals |
271 | 271 | */ |
272 | - public function getSosaListAtGeneration($gen){ |
|
273 | - if(!$this->is_setup) return array(); |
|
274 | - if(!$this->sosa_list_by_gen) |
|
272 | + public function getSosaListAtGeneration($gen) { |
|
273 | + if (!$this->is_setup) return array(); |
|
274 | + if (!$this->sosa_list_by_gen) |
|
275 | 275 | $this->sosa_list_by_gen = array(); |
276 | 276 | |
277 | - if($gen){ |
|
278 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
277 | + if ($gen) { |
|
278 | + if (!isset($this->sosa_list_by_gen[$gen])) { |
|
279 | 279 | $this->sosa_list_by_gen[$gen] = Database::prepare( |
280 | 280 | 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
281 | 281 | ' FROM `##maj_sosa`'. |
@@ -300,13 +300,13 @@ discard block |
||
300 | 300 | * @param number $gen Generation |
301 | 301 | * @return array Array of Sosa families |
302 | 302 | */ |
303 | - public function getFamilySosaListAtGeneration($gen){ |
|
304 | - if(!$this->is_setup) return array(); |
|
305 | - if(!$this->sosa_fam_list_by_gen) |
|
303 | + public function getFamilySosaListAtGeneration($gen) { |
|
304 | + if (!$this->is_setup) return array(); |
|
305 | + if (!$this->sosa_fam_list_by_gen) |
|
306 | 306 | $this->sosa_fam_list_by_gen = array(); |
307 | 307 | |
308 | - if($gen){ |
|
309 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
308 | + if ($gen) { |
|
309 | + if (!isset($this->sosa_fam_list_by_gen[$gen])) { |
|
310 | 310 | $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
311 | 311 | 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
312 | 312 | ' FROM `##families`'. |
@@ -336,9 +336,9 @@ discard block |
||
336 | 336 | * @param number $gen Generation |
337 | 337 | * @return array Array of Sosa individuals |
338 | 338 | */ |
339 | - public function getMissingSosaListAtGeneration($gen){ |
|
340 | - if(!$this->is_setup) return array(); |
|
341 | - if($gen){ |
|
339 | + public function getMissingSosaListAtGeneration($gen) { |
|
340 | + if (!$this->is_setup) return array(); |
|
341 | + if ($gen) { |
|
342 | 342 | return $this->sosa_list_by_gen[$gen] = Database::prepare( |
343 | 343 | 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
344 | 344 | ' FROM `##maj_sosa` schild'. |
@@ -375,10 +375,10 @@ discard block |
||
375 | 375 | * @return array Statistics array |
376 | 376 | */ |
377 | 377 | public function getStatisticsByGeneration() { |
378 | - if(!$this->is_setup) return array(); |
|
379 | - if(!$this->statistics_tab) { |
|
378 | + if (!$this->is_setup) return array(); |
|
379 | + if (!$this->statistics_tab) { |
|
380 | 380 | $this->statistics_tab = array(); |
381 | - if($maxGeneration = $this->getLastGeneration()) { |
|
381 | + if ($maxGeneration = $this->getLastGeneration()) { |
|
382 | 382 | for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
383 | 383 | $birthStats = $this->getStatsBirthYearInGeneration($gen); |
384 | 384 | $this->statistics_tab[$gen] = array( |
@@ -401,9 +401,9 @@ discard block |
||
401 | 401 | * @return int |
402 | 402 | */ |
403 | 403 | public function getTotalIndividuals() { |
404 | - if(!$this->is_setup) return 0; |
|
404 | + if (!$this->is_setup) return 0; |
|
405 | 405 | return Database::prepare( |
406 | - 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
|
406 | + 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`'. |
|
407 | 407 | ' WHERE i_file = :tree_id') |
408 | 408 | ->execute(array('tree_id' => $this->tree->getTreeId())) |
409 | 409 | ->fetchOne() ?: 0; |
@@ -414,10 +414,10 @@ discard block |
||
414 | 414 | * |
415 | 415 | * @return number Number of Sosas |
416 | 416 | */ |
417 | - public function getSosaCount(){ |
|
418 | - if(!$this->is_setup) return 0; |
|
417 | + public function getSosaCount() { |
|
418 | + if (!$this->is_setup) return 0; |
|
419 | 419 | return Database::prepare( |
420 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
420 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
421 | 421 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
422 | 422 | ->execute(array( |
423 | 423 | 'tree_id' => $this->tree->getTreeId(), |
@@ -431,10 +431,10 @@ discard block |
||
431 | 431 | * @param number $gen Generation |
432 | 432 | * @return number Number of Sosas in generation |
433 | 433 | */ |
434 | - public function getSosaCountAtGeneration($gen){ |
|
435 | - if(!$this->is_setup) return 0; |
|
434 | + public function getSosaCountAtGeneration($gen) { |
|
435 | + if (!$this->is_setup) return 0; |
|
436 | 436 | return Database::prepare( |
437 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
437 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
438 | 438 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
439 | 439 | ' AND majs_gen= :gen') |
440 | 440 | ->execute(array( |
@@ -450,10 +450,10 @@ discard block |
||
450 | 450 | * @param number $gen Generation |
451 | 451 | * @return number Total number of Sosas up to generation |
452 | 452 | */ |
453 | - public function getSosaCountUpToGeneration($gen){ |
|
454 | - if(!$this->is_setup) return 0; |
|
453 | + public function getSosaCountUpToGeneration($gen) { |
|
454 | + if (!$this->is_setup) return 0; |
|
455 | 455 | return Database::prepare( |
456 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
456 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
457 | 457 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
458 | 458 | ' AND majs_gen <= :gen') |
459 | 459 | ->execute(array( |
@@ -468,10 +468,10 @@ discard block |
||
468 | 468 | * |
469 | 469 | * @return number Total number of distinct individual |
470 | 470 | */ |
471 | - public function getDifferentSosaCount(){ |
|
472 | - if(!$this->is_setup) return 0; |
|
471 | + public function getDifferentSosaCount() { |
|
472 | + if (!$this->is_setup) return 0; |
|
473 | 473 | return Database::prepare( |
474 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
474 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'. |
|
475 | 475 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
476 | 476 | ->execute(array( |
477 | 477 | 'tree_id' => $this->tree->getTreeId(), |
@@ -485,10 +485,10 @@ discard block |
||
485 | 485 | * @param number $gen Generation |
486 | 486 | * @return number Number of distinct Sosa individuals up to generation |
487 | 487 | */ |
488 | - public function getDifferentSosaCountUpToGeneration($gen){ |
|
489 | - if(!$this->is_setup) return 0; |
|
488 | + public function getDifferentSosaCountUpToGeneration($gen) { |
|
489 | + if (!$this->is_setup) return 0; |
|
490 | 490 | return Database::prepare( |
491 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
491 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'. |
|
492 | 492 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
493 | 493 | ' AND majs_gen <= :gen') |
494 | 494 | ->execute(array( |
@@ -508,11 +508,11 @@ discard block |
||
508 | 508 | * @param number $gen Generation |
509 | 509 | * @return array Birth statistics array |
510 | 510 | */ |
511 | - public function getStatsBirthYearInGeneration($gen){ |
|
512 | - if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
511 | + public function getStatsBirthYearInGeneration($gen) { |
|
512 | + if (!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
513 | 513 | return Database::prepare( |
514 | 514 | 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
515 | - ' FROM `##maj_sosa`' . |
|
515 | + ' FROM `##maj_sosa`'. |
|
516 | 516 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
517 | 517 | ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
518 | 518 | ->execute(array( |
@@ -528,26 +528,26 @@ discard block |
||
528 | 528 | * |
529 | 529 | * @return number|NULL Mean generation time |
530 | 530 | */ |
531 | - public function getMeanGenerationTime(){ |
|
532 | - if(!$this->is_setup) return; |
|
533 | - if(!$this->statistics_tab){ |
|
531 | + public function getMeanGenerationTime() { |
|
532 | + if (!$this->is_setup) return; |
|
533 | + if (!$this->statistics_tab) { |
|
534 | 534 | $this->getStatisticsByGeneration(); |
535 | 535 | } |
536 | 536 | //Linear regression on x=generation and y=birthdate |
537 | 537 | $sum_xy = 0; |
538 | - $sum_x=0; |
|
539 | - $sum_y=0; |
|
540 | - $sum_x2=0; |
|
541 | - $n=count($this->statistics_tab); |
|
542 | - foreach($this->statistics_tab as $gen=>$stats){ |
|
543 | - $sum_xy+=$gen*$stats['avgBirth']; |
|
544 | - $sum_x+=$gen; |
|
545 | - $sum_y+=$stats['avgBirth']; |
|
546 | - $sum_x2+=$gen*$gen; |
|
538 | + $sum_x = 0; |
|
539 | + $sum_y = 0; |
|
540 | + $sum_x2 = 0; |
|
541 | + $n = count($this->statistics_tab); |
|
542 | + foreach ($this->statistics_tab as $gen=>$stats) { |
|
543 | + $sum_xy += $gen * $stats['avgBirth']; |
|
544 | + $sum_x += $gen; |
|
545 | + $sum_y += $stats['avgBirth']; |
|
546 | + $sum_x2 += $gen * $gen; |
|
547 | 547 | } |
548 | - $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
549 | - if($denom!=0){ |
|
550 | - return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
548 | + $denom = ($n * $sum_x2) - ($sum_x * $sum_x); |
|
549 | + if ($denom != 0) { |
|
550 | + return -(($n * $sum_xy) - ($sum_x * $sum_y)) / ($denom); |
|
551 | 551 | } |
552 | 552 | return null; |
553 | 553 | } |
@@ -575,14 +575,14 @@ discard block |
||
575 | 575 | * @return array |
576 | 576 | */ |
577 | 577 | public function getAncestorDispersionForGen($gen) { |
578 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
578 | + if (!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
579 | 579 | return Database::prepare( |
580 | 580 | 'SELECT branches, count(i_id)'. |
581 | 581 | ' FROM ('. |
582 | 582 | ' SELECT i_id,'. |
583 | 583 | ' CASE'. |
584 | 584 | ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
585 | - ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
585 | + ' ELSE -1'.// We put all ancestors shared between some branches in the same bucket |
|
586 | 586 | ' END branches'. |
587 | 587 | ' FROM ('. |
588 | 588 | ' SELECT DISTINCT majs_i_id i_id,'. |
@@ -84,21 +84,25 @@ discard block |
||
84 | 84 | * @param User $user |
85 | 85 | */ |
86 | 86 | public function __construct(Tree $tree, User $user = null) { |
87 | - if(self::$default_user === null) |
|
88 | - self::$default_user = User::find(-1); |
|
87 | + if(self::$default_user === null) { |
|
88 | + self::$default_user = User::find(-1); |
|
89 | + } |
|
89 | 90 | |
90 | 91 | $this->tree = $tree; |
91 | 92 | $this->user = $user; |
92 | 93 | $this->is_setup = true; |
93 | - if($this->user === null) $this->user = Auth::user(); |
|
94 | - if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
94 | + if($this->user === null) { |
|
95 | + $this->user = Auth::user(); |
|
96 | + } |
|
97 | + if(strlen($this->user->getUserId()) == 0) { |
|
98 | + $this->user = self::$default_user; |
|
99 | + } |
|
95 | 100 | |
96 | 101 | // Check if the user, or the default user, has a root already setup; |
97 | 102 | if(!$this->getRootIndi()) { |
98 | 103 | if($this->user == self::$default_user) { // If the default user is not setup |
99 | 104 | $this->is_setup = false; |
100 | - } |
|
101 | - else { |
|
105 | + } else { |
|
102 | 106 | $this->user = self::$default_user; |
103 | 107 | $this->is_setup = $this->getRootIndi() === null; |
104 | 108 | } |
@@ -129,7 +133,9 @@ discard block |
||
129 | 133 | * Remove all Sosa entries related to the gedcom file and user |
130 | 134 | */ |
131 | 135 | public function deleteAll() { |
132 | - if(!$this->is_setup) return; |
|
136 | + if(!$this->is_setup) { |
|
137 | + return; |
|
138 | + } |
|
133 | 139 | Database::prepare( |
134 | 140 | 'DELETE FROM `##maj_sosa`'. |
135 | 141 | ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
@@ -145,7 +151,9 @@ discard block |
||
145 | 151 | * @param int $sosa |
146 | 152 | */ |
147 | 153 | public function deleteAncestors($sosa) { |
148 | - if(!$this->is_setup) return; |
|
154 | + if(!$this->is_setup) { |
|
155 | + return; |
|
156 | + } |
|
149 | 157 | $gen = Functions::getGeneration($sosa); |
150 | 158 | Database::prepare( |
151 | 159 | 'DELETE FROM `##maj_sosa`'. |
@@ -165,7 +173,9 @@ discard block |
||
165 | 173 | * @param array $sosa_records |
166 | 174 | */ |
167 | 175 | public function insertOrUpdate($sosa_records) { |
168 | - if(!$this->is_setup) return; |
|
176 | + if(!$this->is_setup) { |
|
177 | + return; |
|
178 | + } |
|
169 | 179 | |
170 | 180 | $treeid = $this->tree->getTreeId(); |
171 | 181 | $userid = $this->user->getUserId(); |
@@ -212,7 +222,9 @@ discard block |
||
212 | 222 | * @return array Array of sosa numbers |
213 | 223 | */ |
214 | 224 | public function getSosaNumbers(Individual $indi) { |
215 | - if(!$this->is_setup) return array(); |
|
225 | + if(!$this->is_setup) { |
|
226 | + return array(); |
|
227 | + } |
|
216 | 228 | return Database::prepare( |
217 | 229 | 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
218 | 230 | ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -229,7 +241,9 @@ discard block |
||
229 | 241 | * @return number Last generation if found, 1 otherwise |
230 | 242 | */ |
231 | 243 | public function getLastGeneration() { |
232 | - if(!$this->is_setup) return; |
|
244 | + if(!$this->is_setup) { |
|
245 | + return; |
|
246 | + } |
|
233 | 247 | return Database::prepare( |
234 | 248 | 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
235 | 249 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -250,7 +264,9 @@ discard block |
||
250 | 264 | * @return array Associative array of Sosa ancestors, with their generation, comma separated |
251 | 265 | */ |
252 | 266 | public function getAllSosaWithGenerations(){ |
253 | - if(!$this->is_setup) return array(); |
|
267 | + if(!$this->is_setup) { |
|
268 | + return array(); |
|
269 | + } |
|
254 | 270 | return Database::prepare( |
255 | 271 | 'SELECT majs_i_id AS indi,' . |
256 | 272 | ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
@@ -270,9 +286,12 @@ discard block |
||
270 | 286 | * @return array Array of Sosa individuals |
271 | 287 | */ |
272 | 288 | public function getSosaListAtGeneration($gen){ |
273 | - if(!$this->is_setup) return array(); |
|
274 | - if(!$this->sosa_list_by_gen) |
|
275 | - $this->sosa_list_by_gen = array(); |
|
289 | + if(!$this->is_setup) { |
|
290 | + return array(); |
|
291 | + } |
|
292 | + if(!$this->sosa_list_by_gen) { |
|
293 | + $this->sosa_list_by_gen = array(); |
|
294 | + } |
|
276 | 295 | |
277 | 296 | if($gen){ |
278 | 297 | if(!isset($this->sosa_list_by_gen[$gen])){ |
@@ -301,9 +320,12 @@ discard block |
||
301 | 320 | * @return array Array of Sosa families |
302 | 321 | */ |
303 | 322 | public function getFamilySosaListAtGeneration($gen){ |
304 | - if(!$this->is_setup) return array(); |
|
305 | - if(!$this->sosa_fam_list_by_gen) |
|
306 | - $this->sosa_fam_list_by_gen = array(); |
|
323 | + if(!$this->is_setup) { |
|
324 | + return array(); |
|
325 | + } |
|
326 | + if(!$this->sosa_fam_list_by_gen) { |
|
327 | + $this->sosa_fam_list_by_gen = array(); |
|
328 | + } |
|
307 | 329 | |
308 | 330 | if($gen){ |
309 | 331 | if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
@@ -337,7 +359,9 @@ discard block |
||
337 | 359 | * @return array Array of Sosa individuals |
338 | 360 | */ |
339 | 361 | public function getMissingSosaListAtGeneration($gen){ |
340 | - if(!$this->is_setup) return array(); |
|
362 | + if(!$this->is_setup) { |
|
363 | + return array(); |
|
364 | + } |
|
341 | 365 | if($gen){ |
342 | 366 | return $this->sosa_list_by_gen[$gen] = Database::prepare( |
343 | 367 | 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
@@ -375,7 +399,9 @@ discard block |
||
375 | 399 | * @return array Statistics array |
376 | 400 | */ |
377 | 401 | public function getStatisticsByGeneration() { |
378 | - if(!$this->is_setup) return array(); |
|
402 | + if(!$this->is_setup) { |
|
403 | + return array(); |
|
404 | + } |
|
379 | 405 | if(!$this->statistics_tab) { |
380 | 406 | $this->statistics_tab = array(); |
381 | 407 | if($maxGeneration = $this->getLastGeneration()) { |
@@ -401,7 +427,9 @@ discard block |
||
401 | 427 | * @return int |
402 | 428 | */ |
403 | 429 | public function getTotalIndividuals() { |
404 | - if(!$this->is_setup) return 0; |
|
430 | + if(!$this->is_setup) { |
|
431 | + return 0; |
|
432 | + } |
|
405 | 433 | return Database::prepare( |
406 | 434 | 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
407 | 435 | ' WHERE i_file = :tree_id') |
@@ -415,7 +443,9 @@ discard block |
||
415 | 443 | * @return number Number of Sosas |
416 | 444 | */ |
417 | 445 | public function getSosaCount(){ |
418 | - if(!$this->is_setup) return 0; |
|
446 | + if(!$this->is_setup) { |
|
447 | + return 0; |
|
448 | + } |
|
419 | 449 | return Database::prepare( |
420 | 450 | 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
421 | 451 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
@@ -432,7 +462,9 @@ discard block |
||
432 | 462 | * @return number Number of Sosas in generation |
433 | 463 | */ |
434 | 464 | public function getSosaCountAtGeneration($gen){ |
435 | - if(!$this->is_setup) return 0; |
|
465 | + if(!$this->is_setup) { |
|
466 | + return 0; |
|
467 | + } |
|
436 | 468 | return Database::prepare( |
437 | 469 | 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
438 | 470 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -451,7 +483,9 @@ discard block |
||
451 | 483 | * @return number Total number of Sosas up to generation |
452 | 484 | */ |
453 | 485 | public function getSosaCountUpToGeneration($gen){ |
454 | - if(!$this->is_setup) return 0; |
|
486 | + if(!$this->is_setup) { |
|
487 | + return 0; |
|
488 | + } |
|
455 | 489 | return Database::prepare( |
456 | 490 | 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
457 | 491 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -469,7 +503,9 @@ discard block |
||
469 | 503 | * @return number Total number of distinct individual |
470 | 504 | */ |
471 | 505 | public function getDifferentSosaCount(){ |
472 | - if(!$this->is_setup) return 0; |
|
506 | + if(!$this->is_setup) { |
|
507 | + return 0; |
|
508 | + } |
|
473 | 509 | return Database::prepare( |
474 | 510 | 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
475 | 511 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
@@ -486,7 +522,9 @@ discard block |
||
486 | 522 | * @return number Number of distinct Sosa individuals up to generation |
487 | 523 | */ |
488 | 524 | public function getDifferentSosaCountUpToGeneration($gen){ |
489 | - if(!$this->is_setup) return 0; |
|
525 | + if(!$this->is_setup) { |
|
526 | + return 0; |
|
527 | + } |
|
490 | 528 | return Database::prepare( |
491 | 529 | 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
492 | 530 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -509,7 +547,9 @@ discard block |
||
509 | 547 | * @return array Birth statistics array |
510 | 548 | */ |
511 | 549 | public function getStatsBirthYearInGeneration($gen){ |
512 | - if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
550 | + if(!$this->is_setup) { |
|
551 | + return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
552 | + } |
|
513 | 553 | return Database::prepare( |
514 | 554 | 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
515 | 555 | ' FROM `##maj_sosa`' . |
@@ -529,7 +569,9 @@ discard block |
||
529 | 569 | * @return number|NULL Mean generation time |
530 | 570 | */ |
531 | 571 | public function getMeanGenerationTime(){ |
532 | - if(!$this->is_setup) return; |
|
572 | + if(!$this->is_setup) { |
|
573 | + return; |
|
574 | + } |
|
533 | 575 | if(!$this->statistics_tab){ |
534 | 576 | $this->getStatisticsByGeneration(); |
535 | 577 | } |
@@ -575,7 +617,10 @@ discard block |
||
575 | 617 | * @return array |
576 | 618 | */ |
577 | 619 | public function getAncestorDispersionForGen($gen) { |
578 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
620 | + if(!$this->is_setup || $gen > 11) { |
|
621 | + return array(); |
|
622 | + } |
|
623 | + // Going further than 11 gen will be out of range in the query |
|
579 | 624 | return Database::prepare( |
580 | 625 | 'SELECT branches, count(i_id)'. |
581 | 626 | ' FROM ('. |
@@ -42,7 +42,6 @@ |
||
42 | 42 | * Get all the data from the bag for a given key. |
43 | 43 | * |
44 | 44 | * @param string $key |
45 | - * @param string $format |
|
46 | 45 | * @return unknown |
47 | 46 | */ |
48 | 47 | public function get($key, $default = null) |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | * @param bool $override |
74 | 74 | */ |
75 | 75 | public function set($key, $value, $override = true) { |
76 | - if(is_null($key)) return; |
|
77 | - if(!$override && array_key_exists($key, $this->data)) return; |
|
76 | + if (is_null($key)) return; |
|
77 | + if (!$override && array_key_exists($key, $this->data)) return; |
|
78 | 78 | $this->data[$key] = $value; |
79 | 79 | } |
80 | 80 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @param string $key |
108 | 108 | */ |
109 | 109 | public function __unset($key) { |
110 | - unset($this->data[$key]);; |
|
110 | + unset($this->data[$key]); ; |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | } |
@@ -73,8 +73,12 @@ |
||
73 | 73 | * @param bool $override |
74 | 74 | */ |
75 | 75 | public function set($key, $value, $override = true) { |
76 | - if(is_null($key)) return; |
|
77 | - if(!$override && array_key_exists($key, $this->data)) return; |
|
76 | + if(is_null($key)) { |
|
77 | + return; |
|
78 | + } |
|
79 | + if(!$override && array_key_exists($key, $this->data)) { |
|
80 | + return; |
|
81 | + } |
|
78 | 82 | $this->data[$key] = $value; |
79 | 83 | } |
80 | 84 |
@@ -18,97 +18,97 @@ |
||
18 | 18 | /** |
19 | 19 | * @var array $data Container for data |
20 | 20 | */ |
21 | - protected $data = array(); |
|
21 | + protected $data = array(); |
|
22 | 22 | |
23 | - /** |
|
24 | - * Constructor for ViewBag |
|
25 | - * @param array $data_in |
|
26 | - */ |
|
27 | - public function __construct(array $data_in = array()) { |
|
28 | - $this->data = $data_in; |
|
29 | - } |
|
23 | + /** |
|
24 | + * Constructor for ViewBag |
|
25 | + * @param array $data_in |
|
26 | + */ |
|
27 | + public function __construct(array $data_in = array()) { |
|
28 | + $this->data = $data_in; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Get the keys present in the view bag. |
|
33 | - * |
|
34 | - * @return array |
|
35 | - */ |
|
36 | - public function keys() |
|
37 | - { |
|
38 | - return array_keys($this->data); |
|
39 | - } |
|
31 | + /** |
|
32 | + * Get the keys present in the view bag. |
|
33 | + * |
|
34 | + * @return array |
|
35 | + */ |
|
36 | + public function keys() |
|
37 | + { |
|
38 | + return array_keys($this->data); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Get all the data from the bag for a given key. |
|
43 | - * |
|
44 | - * @param string $key |
|
45 | - * @param string $format |
|
46 | - * @return unknown |
|
47 | - */ |
|
48 | - public function get($key, $default = null) |
|
49 | - { |
|
50 | - if (array_key_exists($key, $this->data)) { |
|
51 | - return $this->data[$key]; |
|
52 | - } |
|
53 | - return $default; |
|
54 | - } |
|
41 | + /** |
|
42 | + * Get all the data from the bag for a given key. |
|
43 | + * |
|
44 | + * @param string $key |
|
45 | + * @param string $format |
|
46 | + * @return unknown |
|
47 | + */ |
|
48 | + public function get($key, $default = null) |
|
49 | + { |
|
50 | + if (array_key_exists($key, $this->data)) { |
|
51 | + return $this->data[$key]; |
|
52 | + } |
|
53 | + return $default; |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Magic getter. |
|
58 | - * Returns the value associated with the key. |
|
59 | - * |
|
60 | - * @param string $key |
|
61 | - * @return unknown |
|
62 | - */ |
|
63 | - public function __get($key) { |
|
64 | - return $this->get($key, null); |
|
65 | - } |
|
56 | + /** |
|
57 | + * Magic getter. |
|
58 | + * Returns the value associated with the key. |
|
59 | + * |
|
60 | + * @param string $key |
|
61 | + * @return unknown |
|
62 | + */ |
|
63 | + public function __get($key) { |
|
64 | + return $this->get($key, null); |
|
65 | + } |
|
66 | 66 | |
67 | - /** |
|
68 | - * Set the value for the specified key. |
|
69 | - * Can define whether to override an existing value; |
|
70 | - * |
|
71 | - * @param string $key |
|
72 | - * @param mixed $value |
|
73 | - * @param bool $override |
|
74 | - */ |
|
75 | - public function set($key, $value, $override = true) { |
|
76 | - if(is_null($key)) return; |
|
77 | - if(!$override && array_key_exists($key, $this->data)) return; |
|
78 | - $this->data[$key] = $value; |
|
79 | - } |
|
67 | + /** |
|
68 | + * Set the value for the specified key. |
|
69 | + * Can define whether to override an existing value; |
|
70 | + * |
|
71 | + * @param string $key |
|
72 | + * @param mixed $value |
|
73 | + * @param bool $override |
|
74 | + */ |
|
75 | + public function set($key, $value, $override = true) { |
|
76 | + if(is_null($key)) return; |
|
77 | + if(!$override && array_key_exists($key, $this->data)) return; |
|
78 | + $this->data[$key] = $value; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Magic setter. |
|
83 | - * Set the value for the specified key. |
|
84 | - * |
|
85 | - * @param string $key |
|
86 | - * @param mixed $value |
|
87 | - */ |
|
88 | - public function __set($key, $value) { |
|
89 | - $this->set($key, $value); |
|
90 | - } |
|
81 | + /** |
|
82 | + * Magic setter. |
|
83 | + * Set the value for the specified key. |
|
84 | + * |
|
85 | + * @param string $key |
|
86 | + * @param mixed $value |
|
87 | + */ |
|
88 | + public function __set($key, $value) { |
|
89 | + $this->set($key, $value); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Magic isset |
|
94 | - * Checks whether the ViewBag contains the specified key |
|
95 | - * |
|
96 | - * @param string $key |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public function __isset($key) { |
|
100 | - return isset($this->data[$key]); |
|
101 | - } |
|
92 | + /** |
|
93 | + * Magic isset |
|
94 | + * Checks whether the ViewBag contains the specified key |
|
95 | + * |
|
96 | + * @param string $key |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public function __isset($key) { |
|
100 | + return isset($this->data[$key]); |
|
101 | + } |
|
102 | 102 | |
103 | - /** |
|
104 | - * Magic unset |
|
105 | - * Unset the specified key from the ViewBag |
|
106 | - * |
|
107 | - * @param string $key |
|
108 | - */ |
|
109 | - public function __unset($key) { |
|
110 | - unset($this->data[$key]);; |
|
111 | - } |
|
103 | + /** |
|
104 | + * Magic unset |
|
105 | + * Unset the specified key from the ViewBag |
|
106 | + * |
|
107 | + * @param string $key |
|
108 | + */ |
|
109 | + public function __unset($key) { |
|
110 | + unset($this->data[$key]);; |
|
111 | + } |
|
112 | 112 | |
113 | 113 | } |
114 | 114 | |
115 | 115 | \ No newline at end of file |
@@ -26,7 +26,7 @@ |
||
26 | 26 | /** |
27 | 27 | * Contructor for the decorator |
28 | 28 | * |
29 | - * @param \Fisharebest\Webtrees\Place $place_in The Place to extend |
|
29 | + * @param \Fisharebest\Webtrees\Place $place The Place to extend |
|
30 | 30 | */ |
31 | 31 | public function __construct(\Fisharebest\Webtrees\Place $place){ |
32 | 32 | $this->_place = $place; |
@@ -77,8 +77,7 @@ |
||
77 | 77 | $index = str_replace('%', '', $match2); |
78 | 78 | if(is_numeric($index) && $index >0 && $index <= $nbLevels){ |
79 | 79 | $displayPlace = str_replace($match2, $levels[$index-1] , $displayPlace); |
80 | - } |
|
81 | - else{ |
|
80 | + } else{ |
|
82 | 81 | $displayPlace = str_replace($match2, '' , $displayPlace); |
83 | 82 | } |
84 | 83 | } |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | * |
28 | 28 | * @param \Fisharebest\Webtrees\Place $place_in The Place to extend |
29 | 29 | */ |
30 | - public function __construct(\Fisharebest\Webtrees\Place $place){ |
|
30 | + public function __construct(\Fisharebest\Webtrees\Place $place) { |
|
31 | 31 | $this->place = $place; |
32 | 32 | } |
33 | 33 | |
@@ -39,9 +39,9 @@ discard block |
||
39 | 39 | * @param \Fisharebest\Webtrees\Tree $tree |
40 | 40 | * @return \MyArtJaub\Webtrees\Place|null Instance of \MyArtJaub\Webtrees\Place, if relevant |
41 | 41 | */ |
42 | - public static function getIntance($place_str, Tree $tree){ |
|
42 | + public static function getIntance($place_str, Tree $tree) { |
|
43 | 43 | $dplace = null; |
44 | - if(is_string($place_str) && strlen($place_str) > 0){ |
|
44 | + if (is_string($place_str) && strlen($place_str) > 0) { |
|
45 | 45 | $dplace = new Place(new \Fisharebest\Webtrees\Place($place_str, $tree)); |
46 | 46 | } |
47 | 47 | return $dplace; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * |
53 | 53 | * @return \Fisharebest\Webtrees\Place Embedded place record |
54 | 54 | */ |
55 | - public function getDerivedPlace(){ |
|
55 | + public function getDerivedPlace() { |
|
56 | 56 | return $this->place; |
57 | 57 | } |
58 | 58 | |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | * @param bool $anchor Option to print a link to placelist |
66 | 66 | * @return string HTML code for formatted place |
67 | 67 | */ |
68 | - public function htmlFormattedName($format, $anchor = false){ |
|
69 | - $html=''; |
|
68 | + public function htmlFormattedName($format, $anchor = false) { |
|
69 | + $html = ''; |
|
70 | 70 | |
71 | 71 | $levels = array_map('trim', explode(',', $this->place->getGedcomName())); |
72 | 72 | $nbLevels = count($levels); |
@@ -74,15 +74,15 @@ discard block |
||
74 | 74 | preg_match_all('/%[^%]/', $displayPlace, $matches); |
75 | 75 | foreach ($matches[0] as $match2) { |
76 | 76 | $index = str_replace('%', '', $match2); |
77 | - if(is_numeric($index) && $index >0 && $index <= $nbLevels){ |
|
78 | - $displayPlace = str_replace($match2, $levels[$index-1] , $displayPlace); |
|
77 | + if (is_numeric($index) && $index > 0 && $index <= $nbLevels) { |
|
78 | + $displayPlace = str_replace($match2, $levels[$index - 1], $displayPlace); |
|
79 | 79 | } |
80 | - else{ |
|
81 | - $displayPlace = str_replace($match2, '' , $displayPlace); |
|
80 | + else { |
|
81 | + $displayPlace = str_replace($match2, '', $displayPlace); |
|
82 | 82 | } |
83 | 83 | } |
84 | 84 | if ($anchor && !Auth::isSearchEngine()) { |
85 | - $html .='<a href="' . $this->place->getURL() . '">' . $displayPlace . '</a>'; |
|
85 | + $html .= '<a href="'.$this->place->getURL().'">'.$displayPlace.'</a>'; |
|
86 | 86 | } else { |
87 | 87 | $html .= $displayPlace; |
88 | 88 | } |
@@ -14,17 +14,17 @@ discard block |
||
14 | 14 | */ |
15 | 15 | class Constants { |
16 | 16 | |
17 | - const LIB_NAMESPACE = __NAMESPACE__; |
|
17 | + const LIB_NAMESPACE = __NAMESPACE__; |
|
18 | 18 | |
19 | - /** Internal name of the Certificates Module |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - const MODULE_MAJ_CERTIF_NAME = 'myartjaub_certificates'; |
|
19 | + /** Internal name of the Certificates Module |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + const MODULE_MAJ_CERTIF_NAME = 'myartjaub_certificates'; |
|
23 | 23 | |
24 | - /** Internal name of the GeoDispersion Module |
|
25 | - * @var string |
|
26 | - */ |
|
27 | - const MODULE_MAJ_GEODISP_NAME = 'myartjaub_geodispersion'; |
|
24 | + /** Internal name of the GeoDispersion Module |
|
25 | + * @var string |
|
26 | + */ |
|
27 | + const MODULE_MAJ_GEODISP_NAME = 'myartjaub_geodispersion'; |
|
28 | 28 | |
29 | 29 | /** Internal name of the Hooks Module |
30 | 30 | * @var string |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @return string $WT_RAPHAEL_JS_URL |
62 | 62 | */ |
63 | 63 | public static function WT_RAPHAEL_JS_URL() { |
64 | - return WT_STATIC_URL . 'packages/raphael-2.1.4/raphael-min.js'; |
|
64 | + return WT_STATIC_URL . 'packages/raphael-2.1.4/raphael-min.js'; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | } |
68 | 68 | \ No newline at end of file |
@@ -61,7 +61,7 @@ |
||
61 | 61 | * @return string $WT_RAPHAEL_JS_URL |
62 | 62 | */ |
63 | 63 | public static function WT_RAPHAEL_JS_URL() { |
64 | - return WT_STATIC_URL . 'packages/raphael-2.1.4/raphael-min.js'; |
|
64 | + return WT_STATIC_URL.'packages/raphael-2.1.4/raphael-min.js'; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | } |
68 | 68 | \ No newline at end of file |
@@ -30,11 +30,16 @@ |
||
30 | 30 | $place_id = 0; |
31 | 31 | for ($i=0; $i<count($parent); $i++) { |
32 | 32 | $parent[$i] = trim($parent[$i]); |
33 | - if (empty($parent[$i])) $parent[$i]='unknown';// GoogleMap module uses "unknown" while GEDCOM uses , , |
|
33 | + if (empty($parent[$i])) { |
|
34 | + $parent[$i]='unknown'; |
|
35 | + } |
|
36 | + // GoogleMap module uses "unknown" while GEDCOM uses , , |
|
34 | 37 | $pl_id=Database::prepare('SELECT pl_id FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place') |
35 | 38 | ->execute(array($i, $place_id, $parent[$i])) |
36 | 39 | ->fetchOne(); |
37 | - if (empty($pl_id)) break; |
|
40 | + if (empty($pl_id)) { |
|
41 | + break; |
|
42 | + } |
|
38 | 43 | $place_id = $pl_id; |
39 | 44 | } |
40 | 45 | return $place_id; |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | * @see \MyArtJaub\Webtrees\Map\MapProviderInterface::getProviderPlaceId() |
26 | 26 | */ |
27 | 27 | public function getProviderPlaceId(\Fisharebest\Webtrees\Place $place) { |
28 | - if(!$place->isEmpty()) { |
|
29 | - $parent = explode (',', $place->getGedcomName()); |
|
28 | + if (!$place->isEmpty()) { |
|
29 | + $parent = explode(',', $place->getGedcomName()); |
|
30 | 30 | $place_id = 0; |
31 | 31 | $nb_levels = count($parent); |
32 | - for ($i=0; $i < $nb_levels; $i++) { |
|
32 | + for ($i = 0; $i < $nb_levels; $i++) { |
|
33 | 33 | $parent[$i] = trim($parent[$i]); |
34 | - if (empty($parent[$i])) $parent[$i]='unknown';// GoogleMap module uses "unknown" while GEDCOM uses , , |
|
35 | - $pl_id=Database::prepare('SELECT pl_id FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place') |
|
34 | + if (empty($parent[$i])) $parent[$i] = 'unknown'; // GoogleMap module uses "unknown" while GEDCOM uses , , |
|
35 | + $pl_id = Database::prepare('SELECT pl_id FROM `##placelocation` WHERE pl_level=? AND pl_parent_id=? AND pl_place LIKE ? ORDER BY pl_place') |
|
36 | 36 | ->execute(array($i, $place_id, $parent[$i])) |
37 | 37 | ->fetchOne(); |
38 | 38 | if (empty($pl_id)) break; |
@@ -48,12 +48,12 @@ discard block |
||
48 | 48 | * @see \MyArtJaub\Webtrees\Map\MapProviderInterface::getPlaceIcon() |
49 | 49 | */ |
50 | 50 | public function getPlaceIcon(\Fisharebest\Webtrees\Place $place) { |
51 | - if(!$place->isEmpty()){ |
|
51 | + if (!$place->isEmpty()) { |
|
52 | 52 | $place_details = |
53 | 53 | Database::prepare("SELECT SQL_CACHE pl_icon FROM `##placelocation` WHERE pl_id=? ORDER BY pl_place") |
54 | 54 | ->execute(array($this->getProviderPlaceId($place))) |
55 | 55 | ->fetchOneRow(); |
56 | - if($place_details){ |
|
56 | + if ($place_details) { |
|
57 | 57 | return WT_MODULES_DIR.'googlemap/'.$place_details->pl_icon; |
58 | 58 | } |
59 | 59 | } |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtender::hExtendIndiHeaderIcons() |
62 | 62 | */ |
63 | 63 | public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) { |
64 | - if($ctrlIndi){ |
|
64 | + if ($ctrlIndi) { |
|
65 | 65 | $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
66 | 66 | if ($dindi->canDisplayIsSourced()) |
67 | 67 | return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
@@ -85,19 +85,19 @@ discard block |
||
85 | 85 | * {@inheritDoc} |
86 | 86 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtender::hRecordNamePrepend() |
87 | 87 | */ |
88 | - public function hRecordNamePrepend(GedcomRecord $grec){ } |
|
88 | + public function hRecordNamePrepend(GedcomRecord $grec) { } |
|
89 | 89 | |
90 | 90 | /** |
91 | 91 | * {@inheritDoc} |
92 | 92 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtender::hRecordNameAppend() |
93 | 93 | */ |
94 | - public function hRecordNameAppend(GedcomRecord $grec){ |
|
94 | + public function hRecordNameAppend(GedcomRecord $grec) { |
|
95 | 95 | $html = ''; |
96 | - if($grec instanceof \Fisharebest\Webtrees\Individual){ |
|
96 | + if ($grec instanceof \Fisharebest\Webtrees\Individual) { |
|
97 | 97 | $dindi = new Individual($grec); |
98 | 98 | $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small'); |
99 | 99 | $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small'); |
100 | - if($grec->isDead()) |
|
100 | + if ($grec->isDead()) |
|
101 | 101 | $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
102 | 102 | } |
103 | 103 | return $html; |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * {@inheritDoc} |
116 | 116 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
117 | 117 | */ |
118 | - public function hasSidebarContent(){ |
|
118 | + public function hasSidebarContent() { |
|
119 | 119 | return true; |
120 | 120 | } |
121 | 121 | |
@@ -145,24 +145,24 @@ discard block |
||
145 | 145 | echo ' |
146 | 146 | <table class="issourcedtable"> |
147 | 147 | <tr> |
148 | - <td class="slabel"> ' . GedcomTag::getLabel('INDI') . '</td> |
|
148 | + <td class="slabel"> ' . GedcomTag::getLabel('INDI').'</td> |
|
149 | 149 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1).'</td> |
150 | 150 | </tr> |
151 | 151 | <tr> |
152 | - <td class="slabel">' . GedcomTag::getLabel('BIRT') . '</td> |
|
152 | + <td class="slabel">' . GedcomTag::getLabel('BIRT').'</td> |
|
153 | 153 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1).'</td> |
154 | 154 | </tr>'; |
155 | 155 | |
156 | 156 | $fams = $root->getSpouseFamilies(); |
157 | - ($ct = count($fams)) > 1 ? $nb=1 : $nb=' '; |
|
158 | - foreach($fams as $fam){ |
|
157 | + ($ct = count($fams)) > 1 ? $nb = 1 : $nb = ' '; |
|
158 | + foreach ($fams as $fam) { |
|
159 | 159 | $dfam = new Family($fam); |
160 | 160 | echo ' |
161 | 161 | <tr> |
162 | 162 | <td class="slabel right"> |
163 | - <a href="' . $fam->getHtmlUrl() . '"> '. GedcomTag::getLabel('MARR'); |
|
164 | - if($ct > 1){ |
|
165 | - echo ' ',$nb; |
|
163 | + <a href="' . $fam->getHtmlUrl().'"> '.GedcomTag::getLabel('MARR'); |
|
164 | + if ($ct > 1) { |
|
165 | + echo ' ', $nb; |
|
166 | 166 | $nb++; |
167 | 167 | } |
168 | 168 | echo ' </a> |
@@ -171,10 +171,10 @@ discard block |
||
171 | 171 | </tr>'; |
172 | 172 | } |
173 | 173 | |
174 | - if( $root->isDead() ) |
|
174 | + if ($root->isDead()) |
|
175 | 175 | echo ' |
176 | 176 | <tr> |
177 | - <td class="slabel">' . GedcomTag::getLabel('DEAT') . '</td> |
|
177 | + <td class="slabel">' . GedcomTag::getLabel('DEAT').'</td> |
|
178 | 178 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1).'</td> |
179 | 179 | </tr>'; |
180 | 180 |
@@ -63,8 +63,9 @@ discard block |
||
63 | 63 | public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) { |
64 | 64 | if($ctrlIndi){ |
65 | 65 | $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
66 | - if ($dindi->canDisplayIsSourced()) |
|
67 | - return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
|
66 | + if ($dindi->canDisplayIsSourced()) { |
|
67 | + return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
|
68 | + } |
|
68 | 69 | } |
69 | 70 | return ''; |
70 | 71 | } |
@@ -97,8 +98,9 @@ discard block |
||
97 | 98 | $dindi = new Individual($grec); |
98 | 99 | $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small'); |
99 | 100 | $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small'); |
100 | - if($grec->isDead()) |
|
101 | - $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
|
101 | + if($grec->isDead()) { |
|
102 | + $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
|
103 | + } |
|
102 | 104 | } |
103 | 105 | return $html; |
104 | 106 | } |
@@ -171,12 +173,13 @@ discard block |
||
171 | 173 | </tr>'; |
172 | 174 | } |
173 | 175 | |
174 | - if( $root->isDead() ) |
|
175 | - echo ' |
|
176 | + if( $root->isDead() ) { |
|
177 | + echo ' |
|
176 | 178 | <tr> |
177 | 179 | <td class="slabel">' . GedcomTag::getLabel('DEAT') . '</td> |
178 | 180 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1).'</td> |
179 | 181 | </tr>'; |
182 | + } |
|
180 | 183 | |
181 | 184 | echo '</table>'; |
182 | 185 | } |
@@ -28,29 +28,29 @@ discard block |
||
28 | 28 | class IsSourcedModule extends AbstractModule |
29 | 29 | implements ModuleSidebarInterface, HookSubscriberInterface, IndividualHeaderExtenderInterface, RecordNameTextExtenderInterface |
30 | 30 | { |
31 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
32 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
31 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
32 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
33 | 33 | |
34 | - /** |
|
35 | - * {@inheritDoc} |
|
36 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle() |
|
37 | - */ |
|
38 | - public function getTitle() { |
|
39 | - return I18N::translate('Sourced events'); |
|
40 | - } |
|
34 | + /** |
|
35 | + * {@inheritDoc} |
|
36 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle() |
|
37 | + */ |
|
38 | + public function getTitle() { |
|
39 | + return I18N::translate('Sourced events'); |
|
40 | + } |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * {@inheritDoc} |
44 | 44 | * @see \Fisharebest\Webtrees\Module\AbstractModule::getDescription() |
45 | 45 | */ |
46 | - public function getDescription() { |
|
47 | - return I18N::translate('Indicate if events related to an record are sourced.'); |
|
48 | - } |
|
46 | + public function getDescription() { |
|
47 | + return I18N::translate('Indicate if events related to an record are sourced.'); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * {@inheritDoc} |
|
52 | - * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
53 | - */ |
|
50 | + /** |
|
51 | + * {@inheritDoc} |
|
52 | + * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
53 | + */ |
|
54 | 54 | public function getSubscribedHooks() { |
55 | 55 | return array( |
56 | 56 | 'hExtendIndiHeaderIcons' => 10, |
@@ -63,12 +63,12 @@ discard block |
||
63 | 63 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderIcons() |
64 | 64 | */ |
65 | 65 | public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) { |
66 | - if($ctrlIndi){ |
|
67 | - $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
68 | - if ($dindi->canDisplayIsSourced()) |
|
69 | - return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
|
70 | - } |
|
71 | - return ''; |
|
66 | + if($ctrlIndi){ |
|
67 | + $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
68 | + if ($dindi->canDisplayIsSourced()) |
|
69 | + return FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'large'); |
|
70 | + } |
|
71 | + return ''; |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | /** |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtenderInterface::hRecordNameAppend() |
95 | 95 | */ |
96 | 96 | public function hRecordNameAppend(GedcomRecord $grec){ |
97 | - $html = ''; |
|
98 | - if($grec instanceof \Fisharebest\Webtrees\Individual){ |
|
99 | - $dindi = new Individual($grec); |
|
100 | - $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small'); |
|
101 | - $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small'); |
|
102 | - if($grec->isDead()) |
|
103 | - $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
|
104 | - } |
|
105 | - return $html; |
|
97 | + $html = ''; |
|
98 | + if($grec instanceof \Fisharebest\Webtrees\Individual){ |
|
99 | + $dindi = new Individual($grec); |
|
100 | + $html .= FunctionsPrint::formatIsSourcedIcon('R', $dindi->isSourced(), 'INDI', 1, 'small'); |
|
101 | + $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1, 'small'); |
|
102 | + if($grec->isDead()) |
|
103 | + $html .= FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1, 'small'); |
|
104 | + } |
|
105 | + return $html; |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | /** |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::defaultSidebarOrder() |
111 | 111 | */ |
112 | 112 | public function defaultSidebarOrder() { |
113 | - return 15; |
|
113 | + return 15; |
|
114 | 114 | } |
115 | 115 | |
116 | 116 | /** |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::hasSidebarContent() |
119 | 119 | */ |
120 | 120 | public function hasSidebarContent(){ |
121 | - return true; |
|
121 | + return true; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | /** |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarAjaxContent() |
127 | 127 | */ |
128 | 128 | public function getSidebarAjaxContent() { |
129 | - return ''; |
|
129 | + return ''; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | /** |
@@ -134,17 +134,17 @@ discard block |
||
134 | 134 | * @see \Fisharebest\Webtrees\Module\ModuleSidebarInterface::getSidebarContent() |
135 | 135 | */ |
136 | 136 | public function getSidebarContent() { |
137 | - global $controller; |
|
137 | + global $controller; |
|
138 | 138 | |
139 | - ob_start(); |
|
140 | - $root = $controller->getSignificantIndividual(); |
|
141 | - if ($root) { |
|
142 | - $dindi = new Individual($root); |
|
139 | + ob_start(); |
|
140 | + $root = $controller->getSignificantIndividual(); |
|
141 | + if ($root) { |
|
142 | + $dindi = new Individual($root); |
|
143 | 143 | |
144 | - if (!$dindi->canDisplayIsSourced()) { |
|
145 | - echo '<div class="error">', I18N::translate('This information is private and cannot be shown.'), '</div>'; |
|
146 | - } else { |
|
147 | - echo ' |
|
144 | + if (!$dindi->canDisplayIsSourced()) { |
|
145 | + echo '<div class="error">', I18N::translate('This information is private and cannot be shown.'), '</div>'; |
|
146 | + } else { |
|
147 | + echo ' |
|
148 | 148 | <table class="issourcedtable"> |
149 | 149 | <tr> |
150 | 150 | <td class="slabel"> ' . GedcomTag::getLabel('INDI') . '</td> |
@@ -155,35 +155,35 @@ discard block |
||
155 | 155 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isBirthSourced(), 'BIRT', 1).'</td> |
156 | 156 | </tr>'; |
157 | 157 | |
158 | - $fams = $root->getSpouseFamilies(); |
|
159 | - ($ct = count($fams)) > 1 ? $nb=1 : $nb=' '; |
|
160 | - foreach($fams as $fam){ |
|
161 | - $dfam = new Family($fam); |
|
162 | - echo ' |
|
158 | + $fams = $root->getSpouseFamilies(); |
|
159 | + ($ct = count($fams)) > 1 ? $nb=1 : $nb=' '; |
|
160 | + foreach($fams as $fam){ |
|
161 | + $dfam = new Family($fam); |
|
162 | + echo ' |
|
163 | 163 | <tr> |
164 | 164 | <td class="slabel right"> |
165 | 165 | <a href="' . $fam->getHtmlUrl() . '"> '. GedcomTag::getLabel('MARR'); |
166 | - if($ct > 1){ |
|
167 | - echo ' ',$nb; |
|
168 | - $nb++; |
|
169 | - } |
|
170 | - echo ' </a> |
|
166 | + if($ct > 1){ |
|
167 | + echo ' ',$nb; |
|
168 | + $nb++; |
|
169 | + } |
|
170 | + echo ' </a> |
|
171 | 171 | </td> |
172 | 172 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dfam->isMarriageSourced(), 'MARR', 1).'</td> |
173 | 173 | </tr>'; |
174 | - } |
|
174 | + } |
|
175 | 175 | |
176 | - if( $root->isDead() ) |
|
177 | - echo ' |
|
176 | + if( $root->isDead() ) |
|
177 | + echo ' |
|
178 | 178 | <tr> |
179 | 179 | <td class="slabel">' . GedcomTag::getLabel('DEAT') . '</td> |
180 | 180 | <td class="svalue">' . FunctionsPrint::formatIsSourcedIcon('E', $dindi->isDeathSourced(), 'DEAT', 1).'</td> |
181 | 181 | </tr>'; |
182 | 182 | |
183 | - echo '</table>'; |
|
184 | - } |
|
185 | - } |
|
186 | - return ob_get_clean(); |
|
183 | + echo '</table>'; |
|
184 | + } |
|
185 | + } |
|
186 | + return ob_get_clean(); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 |
@@ -15,11 +15,11 @@ |
||
15 | 15 | */ |
16 | 16 | interface ModuleMenuItemInterface |
17 | 17 | { |
18 | - /** |
|
19 | - * Returns a menu item for the module. |
|
20 | - * |
|
21 | - * @param \Fisharebest\Webtrees\Tree|null $tree |
|
22 | - * @param mixed $reference |
|
23 | - */ |
|
24 | - public function getMenu(\Fisharebest\Webtrees\Tree $tree, $reference); |
|
18 | + /** |
|
19 | + * Returns a menu item for the module. |
|
20 | + * |
|
21 | + * @param \Fisharebest\Webtrees\Tree|null $tree |
|
22 | + * @param mixed $reference |
|
23 | + */ |
|
24 | + public function getMenu(\Fisharebest\Webtrees\Tree $tree, $reference); |
|
25 | 25 | } |
26 | 26 | \ No newline at end of file |
@@ -35,25 +35,25 @@ discard block |
||
35 | 35 | */ |
36 | 36 | class TaskController extends MvcController |
37 | 37 | { |
38 | - /** |
|
39 | - * Tasks Provider |
|
40 | - * @var TaskProviderInterface $provider |
|
41 | - */ |
|
42 | - protected $provider; |
|
38 | + /** |
|
39 | + * Tasks Provider |
|
40 | + * @var TaskProviderInterface $provider |
|
41 | + */ |
|
42 | + protected $provider; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Constructor for Admin Config controller |
|
46 | - * @param AbstractModule $module |
|
47 | - */ |
|
48 | - public function __construct(AbstractModule $module) { |
|
49 | - parent::__construct($module); |
|
44 | + /** |
|
45 | + * Constructor for Admin Config controller |
|
46 | + * @param AbstractModule $module |
|
47 | + */ |
|
48 | + public function __construct(AbstractModule $module) { |
|
49 | + parent::__construct($module); |
|
50 | 50 | |
51 | - $this->provider = $this->module->getProvider(); |
|
52 | - } |
|
51 | + $this->provider = $this->module->getProvider(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Pages |
|
56 | - */ |
|
54 | + /** |
|
55 | + * Pages |
|
56 | + */ |
|
57 | 57 | |
58 | 58 | /** |
59 | 59 | * Task@trigger |
@@ -77,35 +77,35 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * Task@setStatus |
79 | 79 | */ |
80 | - public function setStatus() { |
|
81 | - $controller = new JsonController(); |
|
80 | + public function setStatus() { |
|
81 | + $controller = new JsonController(); |
|
82 | 82 | |
83 | - $task_name = Filter::get('task'); |
|
84 | - $task = $this->provider->getTask($task_name, false); |
|
83 | + $task_name = Filter::get('task'); |
|
84 | + $task = $this->provider->getTask($task_name, false); |
|
85 | 85 | |
86 | - $controller->restrictAccess( |
|
87 | - true // Filter::checkCsrf() -- Cannot use CSRF on a GET request (modules can only work with GET requests) |
|
88 | - && Auth::isAdmin() |
|
89 | - && $task |
|
90 | - ); |
|
86 | + $controller->restrictAccess( |
|
87 | + true // Filter::checkCsrf() -- Cannot use CSRF on a GET request (modules can only work with GET requests) |
|
88 | + && Auth::isAdmin() |
|
89 | + && $task |
|
90 | + ); |
|
91 | 91 | |
92 | - $status = Filter::getBool('status'); |
|
93 | - $res = array('task' => $task->getName() , 'error' => null); |
|
94 | - try{ |
|
95 | - $this->provider->setTaskStatus($task, $status); |
|
96 | - $res['status'] = $status; |
|
92 | + $status = Filter::getBool('status'); |
|
93 | + $res = array('task' => $task->getName() , 'error' => null); |
|
94 | + try{ |
|
95 | + $this->provider->setTaskStatus($task, $status); |
|
96 | + $res['status'] = $status; |
|
97 | 97 | Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '. ($status ? 'enabled' : 'disabled') .'.'); |
98 | - } |
|
99 | - catch (\Exception $ex) { |
|
100 | - $res['error'] = $ex->getMessage(); |
|
98 | + } |
|
99 | + catch (\Exception $ex) { |
|
100 | + $res['error'] = $ex->getMessage(); |
|
101 | 101 | Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage()); |
102 | - } |
|
102 | + } |
|
103 | 103 | |
104 | - $controller->pageHeader(); |
|
105 | - if($res['error']) http_response_code(500); |
|
104 | + $controller->pageHeader(); |
|
105 | + if($res['error']) http_response_code(500); |
|
106 | 106 | |
107 | - echo \Zend_Json::encode($res); |
|
108 | - } |
|
107 | + echo \Zend_Json::encode($res); |
|
108 | + } |
|
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Task@edit |
@@ -113,15 +113,15 @@ discard block |
||
113 | 113 | public function edit() { |
114 | 114 | global $WT_TREE; |
115 | 115 | |
116 | - $task_name = Filter::get('task'); |
|
117 | - $task = $this->provider->getTask($task_name, false); |
|
116 | + $task_name = Filter::get('task'); |
|
117 | + $task = $this->provider->getTask($task_name, false); |
|
118 | 118 | |
119 | - Theme::theme(new AdministrationTheme)->init($WT_TREE); |
|
120 | - $controller = new PageController(); |
|
121 | - $controller |
|
122 | - ->restrictAccess(Auth::isAdmin() && $task) |
|
119 | + Theme::theme(new AdministrationTheme)->init($WT_TREE); |
|
120 | + $controller = new PageController(); |
|
121 | + $controller |
|
122 | + ->restrictAccess(Auth::isAdmin() && $task) |
|
123 | 123 | ->setPageTitle(I18N::translate('Edit the administrative task')) |
124 | - ->addInlineJavascript(' |
|
124 | + ->addInlineJavascript(' |
|
125 | 125 | function toggleRemainingOccurrences() { |
126 | 126 | if($("input:radio[name=\'is_limited\']:checked").val() == 1) { |
127 | 127 | $("#nb_occurences").show(); |
@@ -134,39 +134,39 @@ discard block |
||
134 | 134 | $("[name=\'is_limited\']").on("change", toggleRemainingOccurrences); |
135 | 135 | toggleRemainingOccurrences(); |
136 | 136 | ') |
137 | - ; |
|
137 | + ; |
|
138 | 138 | |
139 | 139 | |
140 | - $data = new ViewBag(); |
|
141 | - $data->set('title', $controller->getPageTitle()); |
|
140 | + $data = new ViewBag(); |
|
141 | + $data->set('title', $controller->getPageTitle()); |
|
142 | 142 | $data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $WT_TREE->getNameUrl()); |
143 | - $data->set('module_title', $this->module->getTitle()); |
|
143 | + $data->set('module_title', $this->module->getTitle()); |
|
144 | 144 | $data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@save&ged=' . $WT_TREE->getNameUrl()); |
145 | 145 | $data->set('task', $task); |
146 | 146 | |
147 | - ViewFactory::make('TaskEdit', $this, $controller, $data)->render(); |
|
147 | + ViewFactory::make('TaskEdit', $this, $controller, $data)->render(); |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
151 | 151 | * Task@save |
152 | 152 | */ |
153 | 153 | public function save() { |
154 | - $tmp_contrl = new PageController(); |
|
154 | + $tmp_contrl = new PageController(); |
|
155 | 155 | |
156 | - $tmp_contrl->restrictAccess( |
|
157 | - Auth::isAdmin() |
|
158 | - && Filter::checkCsrf() |
|
159 | - ); |
|
156 | + $tmp_contrl->restrictAccess( |
|
157 | + Auth::isAdmin() |
|
158 | + && Filter::checkCsrf() |
|
159 | + ); |
|
160 | 160 | |
161 | 161 | $task_name = Filter::post('task'); |
162 | - $frequency = Filter::postInteger('frequency'); |
|
163 | - $is_limited = Filter::postInteger('is_limited', 0, 1); |
|
164 | - $nb_occur = Filter::postInteger('nb_occur'); |
|
162 | + $frequency = Filter::postInteger('frequency'); |
|
163 | + $is_limited = Filter::postInteger('is_limited', 0, 1); |
|
164 | + $nb_occur = Filter::postInteger('nb_occur'); |
|
165 | 165 | |
166 | 166 | $task = $this->provider->getTask($task_name, false); |
167 | 167 | |
168 | - $success = false; |
|
169 | - if($task) { |
|
168 | + $success = false; |
|
169 | + if($task) { |
|
170 | 170 | $task->setFrequency($frequency); |
171 | 171 | if($is_limited == 1) { |
172 | 172 | $task->setRemainingOccurrences($nb_occur); |
@@ -198,13 +198,13 @@ discard block |
||
198 | 198 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.'); |
199 | 199 | } |
200 | 200 | |
201 | - } |
|
201 | + } |
|
202 | 202 | |
203 | - $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig'; |
|
204 | - if(!$success) { |
|
203 | + $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig'; |
|
204 | + if(!$success) { |
|
205 | 205 | $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@edit&task='. $task->getName(); |
206 | - } |
|
207 | - header('Location: ' . WT_BASE_URL . $redirection_url); |
|
206 | + } |
|
207 | + header('Location: ' . WT_BASE_URL . $redirection_url); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | } |
211 | 211 | \ No newline at end of file |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | $tasks = $this->provider->getTasksToRun($token == $token_submitted, $task_name); |
71 | 71 | |
72 | - foreach($tasks as $task) { |
|
72 | + foreach ($tasks as $task) { |
|
73 | 73 | $task->execute(); |
74 | 74 | } |
75 | 75 | } |
@@ -90,19 +90,19 @@ discard block |
||
90 | 90 | ); |
91 | 91 | |
92 | 92 | $status = Filter::getBool('status'); |
93 | - $res = array('task' => $task->getName() , 'error' => null); |
|
94 | - try{ |
|
93 | + $res = array('task' => $task->getName(), 'error' => null); |
|
94 | + try { |
|
95 | 95 | $this->provider->setTaskStatus($task, $status); |
96 | 96 | $res['status'] = $status; |
97 | - Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '. ($status ? 'enabled' : 'disabled') .'.'); |
|
97 | + Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '.($status ? 'enabled' : 'disabled').'.'); |
|
98 | 98 | } |
99 | 99 | catch (\Exception $ex) { |
100 | 100 | $res['error'] = $ex->getMessage(); |
101 | - Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage()); |
|
101 | + Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be '.($status ? 'enabled' : 'disabled').'. Error: '.$ex->getMessage()); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | $controller->pageHeader(); |
105 | - if($res['error']) http_response_code(500); |
|
105 | + if ($res['error']) http_response_code(500); |
|
106 | 106 | |
107 | 107 | echo \Zend_Json::encode($res); |
108 | 108 | } |
@@ -139,9 +139,9 @@ discard block |
||
139 | 139 | |
140 | 140 | $data = new ViewBag(); |
141 | 141 | $data->set('title', $controller->getPageTitle()); |
142 | - $data->set('admin_config_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig&ged=' . $WT_TREE->getNameUrl()); |
|
142 | + $data->set('admin_config_url', 'module.php?mod='.$this->module->getName().'&mod_action=AdminConfig&ged='.$WT_TREE->getNameUrl()); |
|
143 | 143 | $data->set('module_title', $this->module->getTitle()); |
144 | - $data->set('save_url', 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@save&ged=' . $WT_TREE->getNameUrl()); |
|
144 | + $data->set('save_url', 'module.php?mod='.$this->module->getName().'&mod_action=Task@save&ged='.$WT_TREE->getNameUrl()); |
|
145 | 145 | $data->set('task', $task); |
146 | 146 | |
147 | 147 | ViewFactory::make('TaskEdit', $this, $controller, $data)->render(); |
@@ -158,17 +158,17 @@ discard block |
||
158 | 158 | && Filter::checkCsrf() |
159 | 159 | ); |
160 | 160 | |
161 | - $task_name = Filter::post('task'); |
|
162 | - $frequency = Filter::postInteger('frequency'); |
|
163 | - $is_limited = Filter::postInteger('is_limited', 0, 1); |
|
164 | - $nb_occur = Filter::postInteger('nb_occur'); |
|
161 | + $task_name = Filter::post('task'); |
|
162 | + $frequency = Filter::postInteger('frequency'); |
|
163 | + $is_limited = Filter::postInteger('is_limited', 0, 1); |
|
164 | + $nb_occur = Filter::postInteger('nb_occur'); |
|
165 | 165 | |
166 | 166 | $task = $this->provider->getTask($task_name, false); |
167 | 167 | |
168 | 168 | $success = false; |
169 | - if($task) { |
|
169 | + if ($task) { |
|
170 | 170 | $task->setFrequency($frequency); |
171 | - if($is_limited == 1) { |
|
171 | + if ($is_limited == 1) { |
|
172 | 172 | $task->setRemainingOccurrences($nb_occur); |
173 | 173 | } |
174 | 174 | else { |
@@ -177,34 +177,34 @@ discard block |
||
177 | 177 | |
178 | 178 | $res = $task->save(); |
179 | 179 | |
180 | - if($res) { |
|
181 | - if($task instanceof MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface) { |
|
180 | + if ($res) { |
|
181 | + if ($task instanceof MyArtJaub\Webtrees\Module\AdminTasks\Model\ConfigurableTaskInterface) { |
|
182 | 182 | $res = $task->saveConfig(); |
183 | 183 | |
184 | - if(!$res) { |
|
184 | + if (!$res) { |
|
185 | 185 | FlashMessages::addMessage(I18N::translate('An error occured while updating the specific settings of administrative task “%s”', $task->getTitle()), 'danger'); |
186 | - Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” specific settings could not be updated. See error log.'); |
|
186 | + Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName().'” specific settings could not be updated. See error log.'); |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | |
190 | - if($res) { |
|
190 | + if ($res) { |
|
191 | 191 | FlashMessages::addMessage(I18N::translate('The administrative task “%s” has been successfully updated', $task->getTitle()), 'success'); |
192 | - Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName() .'” has been updated.'); |
|
192 | + Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName().'” has been updated.'); |
|
193 | 193 | $success = true; |
194 | 194 | } |
195 | 195 | } |
196 | 196 | else { |
197 | 197 | FlashMessages::addMessage(I18N::translate('An error occured while updating the administrative task “%s”', $task->getTitle()), 'danger'); |
198 | - Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.'); |
|
198 | + Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName().'” could not be updated. See error log.'); |
|
199 | 199 | } |
200 | 200 | |
201 | 201 | } |
202 | 202 | |
203 | - $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=AdminConfig'; |
|
204 | - if(!$success) { |
|
205 | - $redirection_url = 'module.php?mod=' . $this->module->getName() . '&mod_action=Task@edit&task='. $task->getName(); |
|
203 | + $redirection_url = 'module.php?mod='.$this->module->getName().'&mod_action=AdminConfig'; |
|
204 | + if (!$success) { |
|
205 | + $redirection_url = 'module.php?mod='.$this->module->getName().'&mod_action=Task@edit&task='.$task->getName(); |
|
206 | 206 | } |
207 | - header('Location: ' . WT_BASE_URL . $redirection_url); |
|
207 | + header('Location: '.WT_BASE_URL.$redirection_url); |
|
208 | 208 | } |
209 | 209 | |
210 | 210 | } |
211 | 211 | \ No newline at end of file |
@@ -95,14 +95,15 @@ discard block |
||
95 | 95 | $this->provider->setTaskStatus($task, $status); |
96 | 96 | $res['status'] = $status; |
97 | 97 | Log::addConfigurationLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" has been '. ($status ? 'enabled' : 'disabled') .'.'); |
98 | - } |
|
99 | - catch (\Exception $ex) { |
|
98 | + } catch (\Exception $ex) { |
|
100 | 99 | $res['error'] = $ex->getMessage(); |
101 | 100 | Log::addErrorLog('Module '.$this->module->getName().' : Admin Task "'.$task->getName().'" could not be ' . ($status ? 'enabled' : 'disabled') .'. Error: '. $ex->getMessage()); |
102 | 101 | } |
103 | 102 | |
104 | 103 | $controller->pageHeader(); |
105 | - if($res['error']) http_response_code(500); |
|
104 | + if($res['error']) { |
|
105 | + http_response_code(500); |
|
106 | + } |
|
106 | 107 | |
107 | 108 | echo \Zend_Json::encode($res); |
108 | 109 | } |
@@ -170,8 +171,7 @@ discard block |
||
170 | 171 | $task->setFrequency($frequency); |
171 | 172 | if($is_limited == 1) { |
172 | 173 | $task->setRemainingOccurrences($nb_occur); |
173 | - } |
|
174 | - else { |
|
174 | + } else { |
|
175 | 175 | $task->setRemainingOccurrences(0); |
176 | 176 | } |
177 | 177 | |
@@ -192,8 +192,7 @@ discard block |
||
192 | 192 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'.$task->getName() .'” has been updated.'); |
193 | 193 | $success = true; |
194 | 194 | } |
195 | - } |
|
196 | - else { |
|
195 | + } else { |
|
197 | 196 | FlashMessages::addMessage(I18N::translate('An error occured while updating the administrative task “%s”', $task->getTitle()), 'danger'); |
198 | 197 | Log::addConfigurationLog('Module '.$this->module->getName().' : AdminTask “'. $task->getName() .'” could not be updated. See error log.'); |
199 | 198 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | */ |
16 | 16 | interface ConfigurableTaskInterface { |
17 | 17 | |
18 | - /** |
|
19 | - * Returns the HTML code to display the specific task configuration. |
|
20 | - * |
|
21 | - * @return string HTML code |
|
22 | - */ |
|
18 | + /** |
|
19 | + * Returns the HTML code to display the specific task configuration. |
|
20 | + * |
|
21 | + * @return string HTML code |
|
22 | + */ |
|
23 | 23 | function htmlConfigForm(); |
24 | 24 | |
25 | 25 | /** |