@@ -52,7 +52,7 @@ |
||
52 | 52 | /** |
53 | 53 | * Find the spouse of a person, using the Xref comparison. |
54 | 54 | * |
55 | - * @param Individual $person |
|
55 | + * @param fw\Individual $person |
|
56 | 56 | * |
57 | 57 | * @return Individual|null |
58 | 58 | */ |
@@ -39,10 +39,10 @@ |
||
39 | 39 | } |
40 | 40 | |
41 | 41 | /** |
42 | - * Check if this family's marriages are sourced |
|
43 | - * |
|
44 | - * @return int Level of sources |
|
45 | - * */ |
|
42 | + * Check if this family's marriages are sourced |
|
43 | + * |
|
44 | + * @return int Level of sources |
|
45 | + * */ |
|
46 | 46 | function isMarriageSourced(){ |
47 | 47 | if($this->_ismarriagesourced != null) return $this->_ismarriagesourced; |
48 | 48 | $this->_ismarriagesourced = $this->isFactSourced(WT_EVENTS_MARR.'|MARC'); |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | * |
75 | 75 | * @param \Fisharebest\Webtrees\Place $place |
76 | 76 | * @param string $icon_path |
77 | - * @param number $size |
|
77 | + * @param integer $size |
|
78 | 78 | * @return string HTML code of the inserted flag |
79 | 79 | */ |
80 | 80 | public static function htmlPlaceIcon(\Fisharebest\Webtrees\Place $place, $icon_path , $size = 50) { |
@@ -184,7 +184,6 @@ discard block |
||
184 | 184 | /** |
185 | 185 | * Format date to display short (just years) |
186 | 186 | * |
187 | - * @param \Fisharebest\Webtrees\Fact $eventObj Fact to display date |
|
188 | 187 | * @param boolean $anchor option to print a link to calendar |
189 | 188 | * @return string HTML code for short date |
190 | 189 | */ |
@@ -212,7 +211,6 @@ discard block |
||
212 | 211 | /** |
213 | 212 | * Format fact place to display short |
214 | 213 | * |
215 | - * @param \Fisharebest\Webtrees\Fact $eventObj Fact to display date |
|
216 | 214 | * @param string $format Format of the place |
217 | 215 | * @param boolean $anchor option to print a link to placelist |
218 | 216 | * @return string HTML code for short place |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * @return string HTML code of the inserted flag |
80 | 80 | */ |
81 | 81 | public static function htmlPlaceIcon(\Fisharebest\Webtrees\Place $place, $icon_path , $size = 50) { |
82 | - return '<img class="flag_gm_h'. $size . '" src="' . $icon_path . '" title="' . $place->getGedcomName() . '" alt="' . $place->getGedcomName() . '" />'; |
|
82 | + return '<img class="flag_gm_h'. $size . '" src="' . $icon_path . '" title="' . $place->getGedcomName() . '" alt="' . $place->getGedcomName() . '" />'; |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | /** |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @return boolean |
356 | 356 | */ |
357 | 357 | public static function isDateWithinChartsRange(Date $date) { |
358 | - return $date->gregorianYear() >= 1550 && $date->gregorianYear() < 2030; |
|
358 | + return $date->gregorianYear() >= 1550 && $date->gregorianYear() < 2030; |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | } |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | * Returns an estimated birth place based on statistics on the base |
94 | 94 | * |
95 | 95 | * @param boolean $perc Should the coefficient of reliability be returned |
96 | - * @return string|array Estimated birth place if found, null otherwise |
|
96 | + * @return string Estimated birth place if found, null otherwise |
|
97 | 97 | */ |
98 | 98 | public function getEstimatedBirthPlace($perc=false){ |
99 | 99 | if($bplace = $this->gedcomrecord->getBirthPlace()){ |
@@ -110,7 +110,6 @@ discard block |
||
110 | 110 | /** |
111 | 111 | * Returns a significant place for the individual |
112 | 112 | * |
113 | - * @param boolean $perc Should the coefficient of reliability be returned |
|
114 | 113 | * @return string|array Estimated birth place if found, null otherwise |
115 | 114 | */ |
116 | 115 | public function getSignificantPlace(){ |
@@ -113,29 +113,29 @@ discard block |
||
113 | 113 | * @return string|array Estimated birth place if found, null otherwise |
114 | 114 | */ |
115 | 115 | public function getSignificantPlace(){ |
116 | - if($bplace = $this->gedcomrecord->getBirthPlace()){ |
|
117 | - return $bplace; |
|
118 | - } |
|
116 | + if($bplace = $this->gedcomrecord->getBirthPlace()){ |
|
117 | + return $bplace; |
|
118 | + } |
|
119 | 119 | |
120 | - foreach ($this->gedcomrecord->getAllEventPlaces('RESI') as $rplace) { |
|
121 | - if ($rplace) { |
|
122 | - return $rplace; |
|
123 | - } |
|
124 | - } |
|
120 | + foreach ($this->gedcomrecord->getAllEventPlaces('RESI') as $rplace) { |
|
121 | + if ($rplace) { |
|
122 | + return $rplace; |
|
123 | + } |
|
124 | + } |
|
125 | 125 | |
126 | - if($dplace = $this->gedcomrecord->getDeathPlace()){ |
|
127 | - return $dplace; |
|
128 | - } |
|
126 | + if($dplace = $this->gedcomrecord->getDeathPlace()){ |
|
127 | + return $dplace; |
|
128 | + } |
|
129 | 129 | |
130 | - foreach($this->gedcomrecord->getSpouseFamilies() as $fams) { |
|
131 | - foreach ($fams->getAllEventPlaces('RESI') as $rplace) { |
|
132 | - if ($rplace) { |
|
133 | - return $rplace; |
|
134 | - } |
|
135 | - } |
|
136 | - } |
|
130 | + foreach($this->gedcomrecord->getSpouseFamilies() as $fams) { |
|
131 | + foreach ($fams->getAllEventPlaces('RESI') as $rplace) { |
|
132 | + if ($rplace) { |
|
133 | + return $rplace; |
|
134 | + } |
|
135 | + } |
|
136 | + } |
|
137 | 137 | |
138 | - return null; |
|
138 | + return null; |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @return boolean Is the individual a Sosa ancestor |
145 | 145 | */ |
146 | 146 | public function isSosa(){ |
147 | - return count($this->getSosaNumbers()) > 0; |
|
147 | + return count($this->getSosaNumbers()) > 0; |
|
148 | 148 | } |
149 | 149 | |
150 | 150 | /** |
@@ -155,11 +155,11 @@ discard block |
||
155 | 155 | * @return array List of Sosa numbers |
156 | 156 | */ |
157 | 157 | public function getSosaNumbers(){ |
158 | - if($this->sosa === null) { |
|
159 | - $provider = new SosaProvider($this->gedcomrecord->getTree()); |
|
160 | - $this->sosa = $provider->getSosaNumbers($this->gedcomrecord); |
|
161 | - } |
|
162 | - return $this->sosa; |
|
158 | + if($this->sosa === null) { |
|
159 | + $provider = new SosaProvider($this->gedcomrecord->getTree()); |
|
160 | + $this->sosa = $provider->getSosaNumbers($this->gedcomrecord); |
|
161 | + } |
|
162 | + return $this->sosa; |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | /** |
@@ -174,10 +174,10 @@ discard block |
||
174 | 174 | } |
175 | 175 | |
176 | 176 | /** |
177 | - * Check if this individual's death is sourced |
|
178 | - * |
|
179 | - * @return int Level of sources |
|
180 | - * */ |
|
177 | + * Check if this individual's death is sourced |
|
178 | + * |
|
179 | + * @return int Level of sources |
|
180 | + * */ |
|
181 | 181 | public function isDeathSourced(){ |
182 | 182 | if($this->is_death_sourced !== null) return $this->is_death_sourced; |
183 | 183 | $this->is_death_sourced = $this->isFactSourced(WT_EVENTS_DEAT); |
@@ -110,7 +110,7 @@ |
||
110 | 110 | * Set parameters of the Task |
111 | 111 | * |
112 | 112 | * @param bool $is_enabled Status of the task |
113 | - * @param \DateTime $lastupdated Time of the last task run |
|
113 | + * @param \DateTime $last_updated Time of the last task run |
|
114 | 114 | * @param bool $last_result Result of the last run, true for success, false for failure |
115 | 115 | * @param int $frequency Frequency of execution in minutes |
116 | 116 | * @param int $nb_occur Number of remaining occurrences, 0 for tasks not limited |
@@ -20,253 +20,253 @@ |
||
20 | 20 | */ |
21 | 21 | abstract class AbstractTask { |
22 | 22 | |
23 | - /** |
|
24 | - * Time out for runnign tasks, in seconds. Default 5 min |
|
25 | - * @var int TASK_TIME_OUT |
|
26 | - */ |
|
27 | - const TASK_TIME_OUT = 300; |
|
23 | + /** |
|
24 | + * Time out for runnign tasks, in seconds. Default 5 min |
|
25 | + * @var int TASK_TIME_OUT |
|
26 | + */ |
|
27 | + const TASK_TIME_OUT = 300; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Task provider |
|
31 | - * @var TaskProviderInterface $provider |
|
32 | - */ |
|
29 | + /** |
|
30 | + * Task provider |
|
31 | + * @var TaskProviderInterface $provider |
|
32 | + */ |
|
33 | 33 | protected $provider; |
34 | 34 | |
35 | 35 | /** |
36 | 36 | * Task name |
37 | 37 | * @var string $name |
38 | 38 | */ |
39 | - protected $name; |
|
39 | + protected $name; |
|
40 | 40 | |
41 | - /** |
|
42 | - * Status of the task |
|
43 | - * @var bool $is_enabled |
|
44 | - */ |
|
45 | - protected $is_enabled; |
|
41 | + /** |
|
42 | + * Status of the task |
|
43 | + * @var bool $is_enabled |
|
44 | + */ |
|
45 | + protected $is_enabled; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Last updated date |
|
49 | - * @var \DateTime $last_updated |
|
50 | - */ |
|
51 | - protected $last_updated; |
|
47 | + /** |
|
48 | + * Last updated date |
|
49 | + * @var \DateTime $last_updated |
|
50 | + */ |
|
51 | + protected $last_updated; |
|
52 | 52 | |
53 | - /** |
|
54 | - * Last run result |
|
55 | - * @var bool $last_result |
|
56 | - */ |
|
57 | - protected $last_result; |
|
53 | + /** |
|
54 | + * Last run result |
|
55 | + * @var bool $last_result |
|
56 | + */ |
|
57 | + protected $last_result; |
|
58 | 58 | |
59 | - /** |
|
60 | - * Task run frequency |
|
61 | - * @var int $frequency |
|
62 | - */ |
|
63 | - protected $frequency; |
|
59 | + /** |
|
60 | + * Task run frequency |
|
61 | + * @var int $frequency |
|
62 | + */ |
|
63 | + protected $frequency; |
|
64 | 64 | |
65 | - /** |
|
66 | - * Task remaining runs |
|
67 | - * @var int $nb_occurrences |
|
68 | - */ |
|
69 | - protected $nb_occurrences; |
|
65 | + /** |
|
66 | + * Task remaining runs |
|
67 | + * @var int $nb_occurrences |
|
68 | + */ |
|
69 | + protected $nb_occurrences; |
|
70 | 70 | |
71 | - /** |
|
72 | - * Current running status of the task |
|
73 | - * @var bool $is_running |
|
74 | - */ |
|
75 | - protected $is_running; |
|
71 | + /** |
|
72 | + * Current running status of the task |
|
73 | + * @var bool $is_running |
|
74 | + */ |
|
75 | + protected $is_running; |
|
76 | 76 | |
77 | - /** |
|
78 | - * Constructor for the Admin task class |
|
77 | + /** |
|
78 | + * Constructor for the Admin task class |
|
79 | 79 | * |
80 | 80 | * @param string $file Filename containing the task object |
81 | 81 | * @param TaskProviderInterface $provider Provider for tasks |
82 | - */ |
|
83 | - public function __construct($file, TaskProviderInterface $provider = null){ |
|
84 | - $this->name = trim(basename($file, '.php')); |
|
82 | + */ |
|
83 | + public function __construct($file, TaskProviderInterface $provider = null){ |
|
84 | + $this->name = trim(basename($file, '.php')); |
|
85 | 85 | $this->provider = $provider; |
86 | - } |
|
86 | + } |
|
87 | 87 | |
88 | - /** |
|
89 | - * Get the provider. |
|
90 | - * |
|
91 | - * @return TaskProviderInterface |
|
92 | - */ |
|
93 | - public function getProvider(){ |
|
94 | - return $this->provider; |
|
95 | - } |
|
88 | + /** |
|
89 | + * Get the provider. |
|
90 | + * |
|
91 | + * @return TaskProviderInterface |
|
92 | + */ |
|
93 | + public function getProvider(){ |
|
94 | + return $this->provider; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Set the provider. |
|
99 | - * |
|
100 | - * @param TaskProviderInterface $provider |
|
101 | - * @return self Enable method-chaining |
|
102 | - */ |
|
103 | - public function setProvider(TaskProviderInterface $provider){ |
|
104 | - $this->provider = $provider; |
|
105 | - return $this; |
|
106 | - } |
|
97 | + /** |
|
98 | + * Set the provider. |
|
99 | + * |
|
100 | + * @param TaskProviderInterface $provider |
|
101 | + * @return self Enable method-chaining |
|
102 | + */ |
|
103 | + public function setProvider(TaskProviderInterface $provider){ |
|
104 | + $this->provider = $provider; |
|
105 | + return $this; |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * Set parameters of the Task |
|
110 | - * |
|
111 | - * @param bool $is_enabled Status of the task |
|
112 | - * @param \DateTime $lastupdated Time of the last task run |
|
113 | - * @param bool $last_result Result of the last run, true for success, false for failure |
|
114 | - * @param int $frequency Frequency of execution in minutes |
|
115 | - * @param int $nb_occur Number of remaining occurrences, 0 for tasks not limited |
|
116 | - * @param bool $is_running Indicates if the task is currently running |
|
117 | - */ |
|
118 | - public function setParameters($is_enabled, \DateTime $last_updated, $last_result, $frequency, $nb_occur, $is_running){ |
|
119 | - $this->is_enabled = $is_enabled; |
|
120 | - $this->last_updated = $last_updated; |
|
121 | - $this->last_result = $last_result; |
|
122 | - $this->frequency = $frequency; |
|
123 | - $this->nb_occurrences = $nb_occur; |
|
124 | - $this->is_running = $is_running; |
|
125 | - } |
|
108 | + /** |
|
109 | + * Set parameters of the Task |
|
110 | + * |
|
111 | + * @param bool $is_enabled Status of the task |
|
112 | + * @param \DateTime $lastupdated Time of the last task run |
|
113 | + * @param bool $last_result Result of the last run, true for success, false for failure |
|
114 | + * @param int $frequency Frequency of execution in minutes |
|
115 | + * @param int $nb_occur Number of remaining occurrences, 0 for tasks not limited |
|
116 | + * @param bool $is_running Indicates if the task is currently running |
|
117 | + */ |
|
118 | + public function setParameters($is_enabled, \DateTime $last_updated, $last_result, $frequency, $nb_occur, $is_running){ |
|
119 | + $this->is_enabled = $is_enabled; |
|
120 | + $this->last_updated = $last_updated; |
|
121 | + $this->last_result = $last_result; |
|
122 | + $this->frequency = $frequency; |
|
123 | + $this->nb_occurrences = $nb_occur; |
|
124 | + $this->is_running = $is_running; |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Get the name of the task |
|
129 | - * |
|
130 | - * @return string |
|
131 | - */ |
|
132 | - public function getName(){ |
|
133 | - return $this->name; |
|
134 | - } |
|
127 | + /** |
|
128 | + * Get the name of the task |
|
129 | + * |
|
130 | + * @return string |
|
131 | + */ |
|
132 | + public function getName(){ |
|
133 | + return $this->name; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | |
137 | - /** |
|
138 | - * Return the status of the task in a boolean way |
|
139 | - * |
|
140 | - * @return boolean True if enabled |
|
141 | - */ |
|
142 | - public function isEnabled(){ |
|
143 | - return $this->is_enabled; |
|
144 | - } |
|
137 | + /** |
|
138 | + * Return the status of the task in a boolean way |
|
139 | + * |
|
140 | + * @return boolean True if enabled |
|
141 | + */ |
|
142 | + public function isEnabled(){ |
|
143 | + return $this->is_enabled; |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Get the last updated time. |
|
148 | - * |
|
149 | - * @return \DateTime |
|
150 | - */ |
|
151 | - public function getLastUpdated(){ |
|
152 | - return $this->last_updated; |
|
153 | - } |
|
146 | + /** |
|
147 | + * Get the last updated time. |
|
148 | + * |
|
149 | + * @return \DateTime |
|
150 | + */ |
|
151 | + public function getLastUpdated(){ |
|
152 | + return $this->last_updated; |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * Check if the last result has been successful. |
|
157 | - * |
|
158 | - * @return bool |
|
159 | - */ |
|
160 | - public function isLastRunSuccess(){ |
|
161 | - return $this->last_result; |
|
162 | - } |
|
155 | + /** |
|
156 | + * Check if the last result has been successful. |
|
157 | + * |
|
158 | + * @return bool |
|
159 | + */ |
|
160 | + public function isLastRunSuccess(){ |
|
161 | + return $this->last_result; |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * Get the task frequency. |
|
166 | - * |
|
167 | - * @return int |
|
168 | - */ |
|
169 | - public function getFrequency(){ |
|
170 | - return $this->frequency; |
|
171 | - } |
|
164 | + /** |
|
165 | + * Get the task frequency. |
|
166 | + * |
|
167 | + * @return int |
|
168 | + */ |
|
169 | + public function getFrequency(){ |
|
170 | + return $this->frequency; |
|
171 | + } |
|
172 | 172 | |
173 | 173 | /** |
174 | - * Set the task frequency. |
|
175 | - * |
|
174 | + * Set the task frequency. |
|
175 | + * |
|
176 | 176 | * @param int $frequency |
177 | - * @return self Enable method-chaining |
|
178 | - */ |
|
179 | - public function setFrequency($frequency){ |
|
180 | - $this->frequency = $frequency; |
|
177 | + * @return self Enable method-chaining |
|
178 | + */ |
|
179 | + public function setFrequency($frequency){ |
|
180 | + $this->frequency = $frequency; |
|
181 | 181 | return $this; |
182 | - } |
|
182 | + } |
|
183 | 183 | |
184 | - /** |
|
185 | - * Get the number of remaining occurrences. |
|
186 | - * |
|
187 | - * @return int |
|
188 | - */ |
|
189 | - public function getRemainingOccurrences(){ |
|
190 | - return $this->nb_occurrences; |
|
191 | - } |
|
184 | + /** |
|
185 | + * Get the number of remaining occurrences. |
|
186 | + * |
|
187 | + * @return int |
|
188 | + */ |
|
189 | + public function getRemainingOccurrences(){ |
|
190 | + return $this->nb_occurrences; |
|
191 | + } |
|
192 | 192 | |
193 | 193 | /** |
194 | - * Set the number of remaining occurrences. |
|
195 | - * |
|
194 | + * Set the number of remaining occurrences. |
|
195 | + * |
|
196 | 196 | * @param int $nb_occur |
197 | - * @return self Enable method-chaining |
|
198 | - */ |
|
199 | - public function setRemainingOccurrences($nb_occur){ |
|
200 | - $this->nb_occurrences = $nb_occur; |
|
197 | + * @return self Enable method-chaining |
|
198 | + */ |
|
199 | + public function setRemainingOccurrences($nb_occur){ |
|
200 | + $this->nb_occurrences = $nb_occur; |
|
201 | 201 | return $this; |
202 | - } |
|
202 | + } |
|
203 | 203 | |
204 | - /** |
|
205 | - * Check if the task if running. |
|
206 | - * |
|
207 | - * @return bool |
|
208 | - */ |
|
209 | - public function isRunning(){ |
|
210 | - return $this->is_running; |
|
211 | - } |
|
204 | + /** |
|
205 | + * Check if the task if running. |
|
206 | + * |
|
207 | + * @return bool |
|
208 | + */ |
|
209 | + public function isRunning(){ |
|
210 | + return $this->is_running; |
|
211 | + } |
|
212 | 212 | |
213 | 213 | |
214 | - /** |
|
215 | - * Return the name to display for the task |
|
216 | - * |
|
217 | - * @return string Title for the task |
|
218 | - */ |
|
219 | - abstract public function getTitle(); |
|
214 | + /** |
|
215 | + * Return the name to display for the task |
|
216 | + * |
|
217 | + * @return string Title for the task |
|
218 | + */ |
|
219 | + abstract public function getTitle(); |
|
220 | 220 | |
221 | - /** |
|
222 | - * Return the default frequency for the execution of the task |
|
223 | - * |
|
224 | - * @return int Frequency for the execution of the task |
|
225 | - */ |
|
226 | - abstract public function getDefaultFrequency(); |
|
221 | + /** |
|
222 | + * Return the default frequency for the execution of the task |
|
223 | + * |
|
224 | + * @return int Frequency for the execution of the task |
|
225 | + */ |
|
226 | + abstract public function getDefaultFrequency(); |
|
227 | 227 | |
228 | - /** |
|
229 | - * Execute the task's actions |
|
230 | - */ |
|
231 | - abstract protected function executeSteps(); |
|
228 | + /** |
|
229 | + * Execute the task's actions |
|
230 | + */ |
|
231 | + abstract protected function executeSteps(); |
|
232 | 232 | |
233 | 233 | /** |
234 | 234 | * Persist task state into database. |
235 | 235 | * @return bool |
236 | 236 | */ |
237 | 237 | public function save() { |
238 | - if(!$this->provider) throw new \Exception('The task has not been initialised with a provider.'); |
|
238 | + if(!$this->provider) throw new \Exception('The task has not been initialised with a provider.'); |
|
239 | 239 | return $this->provider->updateTask($this); |
240 | 240 | } |
241 | 241 | |
242 | - /** |
|
243 | - * Execute the task, default skeleton |
|
244 | - * |
|
245 | - */ |
|
246 | - public function execute(){ |
|
242 | + /** |
|
243 | + * Execute the task, default skeleton |
|
244 | + * |
|
245 | + */ |
|
246 | + public function execute(){ |
|
247 | 247 | |
248 | - if($this->last_updated->add(new \DateInterval('PT'.self::TASK_TIME_OUT.'S')) < new \DateTime()) |
|
249 | - $this->is_running = false; |
|
248 | + if($this->last_updated->add(new \DateInterval('PT'.self::TASK_TIME_OUT.'S')) < new \DateTime()) |
|
249 | + $this->is_running = false; |
|
250 | 250 | |
251 | - if(!$this->is_running){ |
|
252 | - $this->last_result = false; |
|
253 | - $this->is_running = true; |
|
254 | - $this->save(); |
|
251 | + if(!$this->is_running){ |
|
252 | + $this->last_result = false; |
|
253 | + $this->is_running = true; |
|
254 | + $this->save(); |
|
255 | 255 | |
256 | - Log::addDebugLog('Start execution of Admin task: '.$this->getTitle()); |
|
257 | - $this->last_result = $this->executeSteps(); |
|
258 | - if($this->last_result){ |
|
259 | - $this->last_updated = new \DateTime(); |
|
260 | - if($this->nb_occurrences > 0){ |
|
261 | - $this->nb_occurrences--; |
|
262 | - if($this->nb_occurrences == 0) $this->is_enabled = false; |
|
263 | - } |
|
264 | - } |
|
265 | - $this->is_running = false; |
|
266 | - $this->save(); |
|
267 | - Log::addDebugLog('Execution completed for Admin task: '.$this->getTitle().' - '.($this->last_result ? 'Success' : 'Failure')); |
|
268 | - } |
|
269 | - } |
|
256 | + Log::addDebugLog('Start execution of Admin task: '.$this->getTitle()); |
|
257 | + $this->last_result = $this->executeSteps(); |
|
258 | + if($this->last_result){ |
|
259 | + $this->last_updated = new \DateTime(); |
|
260 | + if($this->nb_occurrences > 0){ |
|
261 | + $this->nb_occurrences--; |
|
262 | + if($this->nb_occurrences == 0) $this->is_enabled = false; |
|
263 | + } |
|
264 | + } |
|
265 | + $this->is_running = false; |
|
266 | + $this->save(); |
|
267 | + Log::addDebugLog('Execution completed for Admin task: '.$this->getTitle().' - '.($this->last_result ? 'Success' : 'Failure')); |
|
268 | + } |
|
269 | + } |
|
270 | 270 | |
271 | 271 | |
272 | 272 | } |
@@ -32,8 +32,8 @@ discard block |
||
32 | 32 | * Set the status of a specific admin task. |
33 | 33 | * The status can be enabled (true), or disabled (false). |
34 | 34 | * |
35 | - * @param AbstractTask $ga |
|
36 | 35 | * @param bool $status |
36 | + * @return void |
|
37 | 37 | */ |
38 | 38 | public function setTaskStatus(AbstractTask $task, $status); |
39 | 39 | |
@@ -49,6 +49,7 @@ discard block |
||
49 | 49 | * Delete the task from the database, in a transactional manner. |
50 | 50 | * |
51 | 51 | * @param string $task_name Task to delete |
52 | + * @return boolean |
|
52 | 53 | */ |
53 | 54 | public function deleteTask($task_name); |
54 | 55 | |
@@ -75,7 +76,7 @@ discard block |
||
75 | 76 | * Returns the list of tasks that are currently meant to run. |
76 | 77 | * Tasks to run can be forced, or can be limited to only one. |
77 | 78 | * |
78 | - * @param string|null $force Force the enabled tasks to run. |
|
79 | + * @param boolean $force Force the enabled tasks to run. |
|
79 | 80 | * @param string|null $task_name Name of the specific task to run |
80 | 81 | */ |
81 | 82 | function getTasksToRun($force = false, $task_name = null); |
@@ -37,47 +37,47 @@ |
||
37 | 37 | */ |
38 | 38 | public function setTaskStatus(AbstractTask $task, $status); |
39 | 39 | |
40 | - /** |
|
41 | - * Update an Admin Task in the database. |
|
42 | - * |
|
43 | - * @param AbstractTask $task Task to update |
|
44 | - * @return bool |
|
45 | - */ |
|
46 | - function updateTask(AbstractTask $task); |
|
40 | + /** |
|
41 | + * Update an Admin Task in the database. |
|
42 | + * |
|
43 | + * @param AbstractTask $task Task to update |
|
44 | + * @return bool |
|
45 | + */ |
|
46 | + function updateTask(AbstractTask $task); |
|
47 | 47 | |
48 | - /** |
|
49 | - * Delete the task from the database, in a transactional manner. |
|
50 | - * |
|
51 | - * @param string $task_name Task to delete |
|
52 | - */ |
|
53 | - public function deleteTask($task_name); |
|
48 | + /** |
|
49 | + * Delete the task from the database, in a transactional manner. |
|
50 | + * |
|
51 | + * @param string $task_name Task to delete |
|
52 | + */ |
|
53 | + public function deleteTask($task_name); |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Returns the number of Admin Tasks (active and inactive). |
|
58 | - * |
|
59 | - * @return int |
|
60 | - */ |
|
61 | - public function getTasksCount(); |
|
56 | + /** |
|
57 | + * Returns the number of Admin Tasks (active and inactive). |
|
58 | + * |
|
59 | + * @return int |
|
60 | + */ |
|
61 | + public function getTasksCount(); |
|
62 | 62 | |
63 | - /** |
|
64 | - * Return the list of Admin Tasks matching specified criterias. |
|
65 | - * |
|
66 | - * @param string $search Search criteria in analysis description |
|
67 | - * @param array $order_by Columns to order by |
|
68 | - * @param int $start Offset to start with (for pagination) |
|
69 | - * @param int|null $limit Max number of items to return (for pagination) |
|
70 | - * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[] |
|
71 | - */ |
|
72 | - function getFilteredTasksList($search = null, $order_by = null, $start = 0, $limit = null); |
|
63 | + /** |
|
64 | + * Return the list of Admin Tasks matching specified criterias. |
|
65 | + * |
|
66 | + * @param string $search Search criteria in analysis description |
|
67 | + * @param array $order_by Columns to order by |
|
68 | + * @param int $start Offset to start with (for pagination) |
|
69 | + * @param int|null $limit Max number of items to return (for pagination) |
|
70 | + * @return \MyArtJaub\Webtrees\Module\GeoDispersion\Model\GeoAnalysis[] |
|
71 | + */ |
|
72 | + function getFilteredTasksList($search = null, $order_by = null, $start = 0, $limit = null); |
|
73 | 73 | |
74 | - /** |
|
75 | - * Returns the list of tasks that are currently meant to run. |
|
76 | - * Tasks to run can be forced, or can be limited to only one. |
|
77 | - * |
|
78 | - * @param string|null $force Force the enabled tasks to run. |
|
79 | - * @param string|null $task_name Name of the specific task to run |
|
80 | - */ |
|
74 | + /** |
|
75 | + * Returns the list of tasks that are currently meant to run. |
|
76 | + * Tasks to run can be forced, or can be limited to only one. |
|
77 | + * |
|
78 | + * @param string|null $force Force the enabled tasks to run. |
|
79 | + * @param string|null $task_name Name of the specific task to run |
|
80 | + */ |
|
81 | 81 | function getTasksToRun($force = false, $task_name = null); |
82 | 82 | |
83 | 83 | /** |
@@ -109,6 +109,7 @@ discard block |
||
109 | 109 | /** |
110 | 110 | * {@inhericDoc} |
111 | 111 | * @see \Fisharebest\Webtrees\GedcomRecord::getInstance() |
112 | + * @param string $xref |
|
112 | 113 | */ |
113 | 114 | static public function getInstance($xref, Tree $tree, $gedcom = null, CertificateProviderInterface $provider = null) { |
114 | 115 | try{ |
@@ -150,7 +151,7 @@ discard block |
||
150 | 151 | /** |
151 | 152 | * Define a source associated with the certificate |
152 | 153 | * |
153 | - * @param string|Source $xref |
|
154 | + * @param string|null $xref |
|
154 | 155 | */ |
155 | 156 | public function setSource($xref){ |
156 | 157 | if($xref instanceof Source){ |
@@ -35,12 +35,12 @@ discard block |
||
35 | 35 | */ |
36 | 36 | class Certificate extends Media { |
37 | 37 | |
38 | - const URL_PREFIX = 'module.php?mod=myartjaub_certificates&mod_action=Certificate&cid='; |
|
38 | + const URL_PREFIX = 'module.php?mod=myartjaub_certificates&mod_action=Certificate&cid='; |
|
39 | 39 | |
40 | - /** @var string The "TITL" value from the GEDCOM |
|
41 | - * This is a tweak to overcome the private level from the parent object... |
|
42 | - */ |
|
43 | - protected $title = ''; |
|
40 | + /** @var string The "TITL" value from the GEDCOM |
|
41 | + * This is a tweak to overcome the private level from the parent object... |
|
42 | + */ |
|
43 | + protected $title = ''; |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Certificate provider |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @param CertificateProviderInterface $provider |
81 | 81 | */ |
82 | 82 | public function __construct($data, Tree $tree, CertificateProviderInterface $provider) { |
83 | - $this->provider = $provider; |
|
83 | + $this->provider = $provider; |
|
84 | 84 | // Data is only the file name |
85 | 85 | $data = str_replace("\\", '/', $data); |
86 | 86 | $xref = Functions::encryptToSafeBase64($data); |
@@ -165,7 +165,7 @@ discard block |
||
165 | 165 | * @see \Fisharebest\Webtrees\Media::getTitle() |
166 | 166 | */ |
167 | 167 | public function getTitle() { |
168 | - return $this->title; |
|
168 | + return $this->title; |
|
169 | 169 | } |
170 | 170 | |
171 | 171 | /** |
@@ -241,26 +241,26 @@ discard block |
||
241 | 241 | $module = Module::getModuleByName(Constants::MODULE_MAJ_CERTIF_NAME); |
242 | 242 | |
243 | 243 | if($module) { |
244 | - $wmtext = $module->getSetting('MAJ_WM_DEFAULT', I18N::translate('This image is protected under copyright law.')); |
|
245 | - $sid= Filter::get('sid', WT_REGEX_XREF); |
|
244 | + $wmtext = $module->getSetting('MAJ_WM_DEFAULT', I18N::translate('This image is protected under copyright law.')); |
|
245 | + $sid= Filter::get('sid', WT_REGEX_XREF); |
|
246 | 246 | |
247 | - if($sid){ |
|
248 | - $this->source = Source::getInstance($sid, $this->tree); |
|
249 | - } |
|
250 | - else{ |
|
251 | - $this->fetchALinkedSource(); // the method already attach the source to the Certificate object; |
|
252 | - } |
|
247 | + if($sid){ |
|
248 | + $this->source = Source::getInstance($sid, $this->tree); |
|
249 | + } |
|
250 | + else{ |
|
251 | + $this->fetchALinkedSource(); // the method already attach the source to the Certificate object; |
|
252 | + } |
|
253 | 253 | |
254 | - if($this->source) { |
|
255 | - $wmtext = '©'; |
|
256 | - $repofact = $this->source->getFirstFact('REPO'); |
|
257 | - if($repofact) { |
|
258 | - $repo = $repofact->getTarget(); |
|
259 | - if($repo && $repo instanceof Repository) $wmtext .= ' '.$repo->getFullName().' - '; |
|
260 | - } |
|
261 | - $wmtext .= $this->source->getFullName(); |
|
262 | - } |
|
263 | - return $wmtext; |
|
254 | + if($this->source) { |
|
255 | + $wmtext = '©'; |
|
256 | + $repofact = $this->source->getFirstFact('REPO'); |
|
257 | + if($repofact) { |
|
258 | + $repo = $repofact->getTarget(); |
|
259 | + if($repo && $repo instanceof Repository) $wmtext .= ' '.$repo->getFullName().' - '; |
|
260 | + } |
|
261 | + $wmtext .= $this->source->getFullName(); |
|
262 | + } |
|
263 | + return $wmtext; |
|
264 | 264 | } |
265 | 265 | return ''; |
266 | 266 | } |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | ' FROM `##individuals`'. |
324 | 324 | ' WHERE i_file= :gedcom_id AND i_gedcom LIKE :gedcom') |
325 | 325 | ->execute(array( |
326 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
327 | - 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
326 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
327 | + 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
328 | 328 | ))->fetchAll(); |
329 | 329 | |
330 | 330 | $list = array(); |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | ' FROM `##families`'. |
348 | 348 | ' WHERE f_file= :gedcom_id AND f_gedcom LIKE :gedcom') |
349 | 349 | ->execute(array( |
350 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
351 | - 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
350 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
351 | + 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
352 | 352 | ))->fetchAll(); |
353 | 353 | |
354 | 354 | $list = array(); |
@@ -375,25 +375,25 @@ discard block |
||
375 | 375 | 'SELECT i_gedcom AS gedrec FROM `##individuals`'. |
376 | 376 | ' WHERE i_file=:gedcom_id AND i_gedcom LIKE :gedcom') |
377 | 377 | ->execute(array( |
378 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
379 | - 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
378 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
379 | + 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
380 | 380 | ))->fetchOne(); |
381 | 381 | if(!$ged){ |
382 | 382 | $ged = Database::prepare( |
383 | 383 | 'SELECT f_gedcom AS gedrec FROM `##families`'. |
384 | 384 | ' WHERE f_file=:gedcom_id AND f_gedcom LIKE :gedcom') |
385 | - ->execute(array( |
|
386 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
387 | - 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
388 | - ))->fetchOne(); |
|
385 | + ->execute(array( |
|
386 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
387 | + 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
388 | + ))->fetchOne(); |
|
389 | 389 | if(!$ged){ |
390 | 390 | $ged = Database::prepare( |
391 | - 'SELECT o_gedcom AS gedrec FROM `##other`'. |
|
392 | - ' WHERE o_file=:gedcom_id AND o_gedcom LIKE :gedcom') |
|
393 | - ->execute(array( |
|
394 | - 'gedcom_id' => $this->tree->getTreeId(), |
|
395 | - 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
396 | - ))->fetchOne(); |
|
391 | + 'SELECT o_gedcom AS gedrec FROM `##other`'. |
|
392 | + ' WHERE o_file=:gedcom_id AND o_gedcom LIKE :gedcom') |
|
393 | + ->execute(array( |
|
394 | + 'gedcom_id' => $this->tree->getTreeId(), |
|
395 | + 'gedcom' => '%_ACT '.$this->getFilename().'%' |
|
396 | + ))->fetchOne(); |
|
397 | 397 | } |
398 | 398 | } |
399 | 399 | //If a record has been found, parse it to find the source reference. |
@@ -252,7 +252,7 @@ |
||
252 | 252 | /** |
253 | 253 | * Return the HTML code for custom simple tag _ACT |
254 | 254 | * |
255 | - * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
255 | + * @param Certificate $certificate Certificate (as per the GEDCOM) |
|
256 | 256 | * @param string|null $sid Linked Source ID, if it exists |
257 | 257 | */ |
258 | 258 | protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
@@ -30,151 +30,151 @@ discard block |
||
30 | 30 | * Certificates Module. |
31 | 31 | */ |
32 | 32 | class CertificatesModule |
33 | - extends AbstractModule |
|
34 | - implements HookSubscriberInterface, ModuleConfigInterface, ModuleMenuItemInterface, FactSourceTextExtenderInterface, CustomSimpleTagManagerInterface, DependentInterface |
|
33 | + extends AbstractModule |
|
34 | + implements HookSubscriberInterface, ModuleConfigInterface, ModuleMenuItemInterface, FactSourceTextExtenderInterface, CustomSimpleTagManagerInterface, DependentInterface |
|
35 | 35 | { |
36 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
37 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
36 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
37 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Provider for Certificates |
|
41 | - * @var CertificateProviderInterface $provider |
|
42 | - */ |
|
43 | - protected $provider; |
|
39 | + /** |
|
40 | + * Provider for Certificates |
|
41 | + * @var CertificateProviderInterface $provider |
|
42 | + */ |
|
43 | + protected $provider; |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inhericDoc} |
|
47 | - */ |
|
48 | - public function getTitle() { |
|
49 | - return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
50 | - } |
|
45 | + /** |
|
46 | + * {@inhericDoc} |
|
47 | + */ |
|
48 | + public function getTitle() { |
|
49 | + return /* I18N: Name of the “Certificates” module */ I18N::translate('Certificates'); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * {@inhericDoc} |
|
54 | - */ |
|
55 | - public function getDescription() { |
|
56 | - return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
57 | - } |
|
52 | + /** |
|
53 | + * {@inhericDoc} |
|
54 | + */ |
|
55 | + public function getDescription() { |
|
56 | + return /* I18N: Description of the “Certificates” module */ I18N::translate('Display and edition of certificates linked to sources.'); |
|
57 | + } |
|
58 | 58 | |
59 | - /** |
|
60 | - * {@inhericDoc} |
|
61 | - */ |
|
62 | - public function modAction($mod_action) { |
|
63 | - \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
64 | - } |
|
59 | + /** |
|
60 | + * {@inhericDoc} |
|
61 | + */ |
|
62 | + public function modAction($mod_action) { |
|
63 | + \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * {@inheritDoc} |
|
68 | - * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
69 | - */ |
|
70 | - public function validatePrerequisites() { |
|
71 | - return Functions::isEncryptionCompatible(); |
|
72 | - } |
|
66 | + /** |
|
67 | + * {@inheritDoc} |
|
68 | + * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
69 | + */ |
|
70 | + public function validatePrerequisites() { |
|
71 | + return Functions::isEncryptionCompatible(); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * {@inhericDoc} |
|
76 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
77 | - */ |
|
78 | - public function getConfigLink() { |
|
79 | - return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
80 | - } |
|
74 | + /** |
|
75 | + * {@inhericDoc} |
|
76 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
77 | + */ |
|
78 | + public function getConfigLink() { |
|
79 | + return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * {@inhericDoc} |
|
84 | - * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
85 | - */ |
|
86 | - public function getSubscribedHooks() { |
|
87 | - return array( |
|
88 | - 'hFactSourcePrepend' => 50, |
|
89 | - 'hGetExpectedTags' => 50, |
|
90 | - 'hHtmlSimpleTagDisplay#_ACT' => 50, |
|
91 | - 'hHtmlSimpleTagEditor#_ACT' => 50, |
|
92 | - 'hAddSimpleTag#SOUR' => 50, |
|
93 | - 'hHasHelpTextTag#_ACT' => 50, |
|
94 | - 'hGetHelpTextTag#_ACT' => 50 |
|
95 | - ); |
|
96 | - } |
|
82 | + /** |
|
83 | + * {@inhericDoc} |
|
84 | + * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
85 | + */ |
|
86 | + public function getSubscribedHooks() { |
|
87 | + return array( |
|
88 | + 'hFactSourcePrepend' => 50, |
|
89 | + 'hGetExpectedTags' => 50, |
|
90 | + 'hHtmlSimpleTagDisplay#_ACT' => 50, |
|
91 | + 'hHtmlSimpleTagEditor#_ACT' => 50, |
|
92 | + 'hAddSimpleTag#SOUR' => 50, |
|
93 | + 'hHasHelpTextTag#_ACT' => 50, |
|
94 | + 'hGetHelpTextTag#_ACT' => 50 |
|
95 | + ); |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * {@inhericDoc} |
|
100 | - * @see \MyArtJaub\Webtrees\Module\ModuleMenuItemInterface::getMenu() |
|
101 | - */ |
|
102 | - public function getMenu(Tree $tree, $reference = null) { |
|
103 | - $tree_url = $tree ? $tree->getNameUrl() : ''; |
|
104 | - return new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=Certificate@listAll&ged=' . $tree_url, 'menu-maj-list-certificate', array('rel' => 'nofollow')); |
|
105 | - } |
|
98 | + /** |
|
99 | + * {@inhericDoc} |
|
100 | + * @see \MyArtJaub\Webtrees\Module\ModuleMenuItemInterface::getMenu() |
|
101 | + */ |
|
102 | + public function getMenu(Tree $tree, $reference = null) { |
|
103 | + $tree_url = $tree ? $tree->getNameUrl() : ''; |
|
104 | + return new Menu($this->getTitle(), 'module.php?mod=' . $this->getName() . '&mod_action=Certificate@listAll&ged=' . $tree_url, 'menu-maj-list-certificate', array('rel' => 'nofollow')); |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * {@inhericDoc} |
|
109 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourcePrepend() |
|
110 | - */ |
|
111 | - public function hFactSourcePrepend($srec) { |
|
112 | - global $WT_TREE; |
|
107 | + /** |
|
108 | + * {@inhericDoc} |
|
109 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourcePrepend() |
|
110 | + */ |
|
111 | + public function hFactSourcePrepend($srec) { |
|
112 | + global $WT_TREE; |
|
113 | 113 | |
114 | - $html=''; |
|
115 | - $sid=null; |
|
114 | + $html=''; |
|
115 | + $sid=null; |
|
116 | 116 | |
117 | - if($this->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($WT_TREE)){ |
|
118 | - if (!$srec || strlen($srec) == 0) return $html; |
|
117 | + if($this->getSetting('MAJ_SHOW_CERT', Auth::PRIV_HIDE) >= Auth::accessLevel($WT_TREE)){ |
|
118 | + if (!$srec || strlen($srec) == 0) return $html; |
|
119 | 119 | |
120 | - $certificate = null; |
|
121 | - $subrecords = explode("\n", $srec); |
|
122 | - $levelSOUR = substr($subrecords[0], 0, 1); |
|
123 | - $match = null; |
|
124 | - if (preg_match('~^'.$levelSOUR.' SOUR @('.WT_REGEX_XREF.')@$~', $subrecords[0], $match)) { |
|
125 | - $sid=$match[1]; |
|
126 | - }; |
|
127 | - $nb_subrecords = count($subrecords); |
|
128 | - for ($i=0; $i < $nb_subrecords; $i++) { |
|
129 | - $subrecords[$i] = trim($subrecords[$i]); |
|
130 | - $tag = substr($subrecords[$i], 2, 4); |
|
131 | - $text = substr($subrecords[$i], 7); |
|
132 | - if($tag == '_ACT') $certificate= new Certificate($text, $WT_TREE, $this->getProvider()); |
|
133 | - } |
|
120 | + $certificate = null; |
|
121 | + $subrecords = explode("\n", $srec); |
|
122 | + $levelSOUR = substr($subrecords[0], 0, 1); |
|
123 | + $match = null; |
|
124 | + if (preg_match('~^'.$levelSOUR.' SOUR @('.WT_REGEX_XREF.')@$~', $subrecords[0], $match)) { |
|
125 | + $sid=$match[1]; |
|
126 | + }; |
|
127 | + $nb_subrecords = count($subrecords); |
|
128 | + for ($i=0; $i < $nb_subrecords; $i++) { |
|
129 | + $subrecords[$i] = trim($subrecords[$i]); |
|
130 | + $tag = substr($subrecords[$i], 2, 4); |
|
131 | + $text = substr($subrecords[$i], 7); |
|
132 | + if($tag == '_ACT') $certificate= new Certificate($text, $WT_TREE, $this->getProvider()); |
|
133 | + } |
|
134 | 134 | |
135 | - if($certificate && $certificate->canShow()) |
|
136 | - $html = $this->getDisplay_ACT($certificate, $sid); |
|
135 | + if($certificate && $certificate->canShow()) |
|
136 | + $html = $this->getDisplay_ACT($certificate, $sid); |
|
137 | 137 | |
138 | - } |
|
139 | - return $html; |
|
140 | - } |
|
138 | + } |
|
139 | + return $html; |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * {@inhericDoc} |
|
144 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourceAppend() |
|
145 | - */ |
|
146 | - public function hFactSourceAppend($srec) { } |
|
142 | + /** |
|
143 | + * {@inhericDoc} |
|
144 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\FactSourceTextExtenderInterface::hFactSourceAppend() |
|
145 | + */ |
|
146 | + public function hFactSourceAppend($srec) { } |
|
147 | 147 | |
148 | - /** |
|
149 | - * {@inhericDoc} |
|
150 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetExpectedTags() |
|
151 | - */ |
|
152 | - public function hGetExpectedTags() { |
|
153 | - return array('SOUR' => '_ACT'); |
|
154 | - } |
|
148 | + /** |
|
149 | + * {@inhericDoc} |
|
150 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetExpectedTags() |
|
151 | + */ |
|
152 | + public function hGetExpectedTags() { |
|
153 | + return array('SOUR' => '_ACT'); |
|
154 | + } |
|
155 | 155 | |
156 | - /** |
|
157 | - * {@inhericDoc} |
|
158 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagDisplay() |
|
159 | - */ |
|
160 | - public function hHtmlSimpleTagDisplay($tag, $value, $context = null, $contextid = null) { |
|
161 | - $html = ''; |
|
162 | - switch($tag){ |
|
163 | - case '_ACT': |
|
164 | - if($context == 'SOUR') $html = $this->getDisplay_ACT($value, $contextid); |
|
165 | - break; |
|
166 | - } |
|
167 | - return $html; |
|
168 | - } |
|
156 | + /** |
|
157 | + * {@inhericDoc} |
|
158 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagDisplay() |
|
159 | + */ |
|
160 | + public function hHtmlSimpleTagDisplay($tag, $value, $context = null, $contextid = null) { |
|
161 | + $html = ''; |
|
162 | + switch($tag){ |
|
163 | + case '_ACT': |
|
164 | + if($context == 'SOUR') $html = $this->getDisplay_ACT($value, $contextid); |
|
165 | + break; |
|
166 | + } |
|
167 | + return $html; |
|
168 | + } |
|
169 | 169 | |
170 | - /** |
|
171 | - * {@inhericDoc} |
|
172 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagEditor() |
|
173 | - */ |
|
174 | - public function hHtmlSimpleTagEditor($tag, $value = null, $element_id = '', $element_name = '', $context = null, $contextid = null) { |
|
175 | - global $controller, $WT_TREE; |
|
170 | + /** |
|
171 | + * {@inhericDoc} |
|
172 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHtmlSimpleTagEditor() |
|
173 | + */ |
|
174 | + public function hHtmlSimpleTagEditor($tag, $value = null, $element_id = '', $element_name = '', $context = null, $contextid = null) { |
|
175 | + global $controller, $WT_TREE; |
|
176 | 176 | |
177 | - $html = ''; |
|
177 | + $html = ''; |
|
178 | 178 | |
179 | 179 | switch($tag){ |
180 | 180 | case '_ACT': |
@@ -202,77 +202,77 @@ discard block |
||
202 | 202 | } |
203 | 203 | |
204 | 204 | return $html; |
205 | - } |
|
205 | + } |
|
206 | 206 | |
207 | - /** |
|
208 | - * {@inhericDoc} |
|
209 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hAddSimpleTag() |
|
210 | - */ |
|
211 | - public function hAddSimpleTag($context, $level) { |
|
212 | - switch($context){ |
|
213 | - case 'SOUR': |
|
214 | - FunctionsEdit::addSimpleTag($level.' _ACT'); |
|
215 | - break; |
|
216 | - } |
|
217 | - } |
|
207 | + /** |
|
208 | + * {@inhericDoc} |
|
209 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hAddSimpleTag() |
|
210 | + */ |
|
211 | + public function hAddSimpleTag($context, $level) { |
|
212 | + switch($context){ |
|
213 | + case 'SOUR': |
|
214 | + FunctionsEdit::addSimpleTag($level.' _ACT'); |
|
215 | + break; |
|
216 | + } |
|
217 | + } |
|
218 | 218 | |
219 | - /** |
|
220 | - * {@inhericDoc} |
|
221 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHasHelpTextTag() |
|
222 | - */ |
|
223 | - public function hHasHelpTextTag($tag) { |
|
224 | - switch($tag){ |
|
219 | + /** |
|
220 | + * {@inhericDoc} |
|
221 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hHasHelpTextTag() |
|
222 | + */ |
|
223 | + public function hHasHelpTextTag($tag) { |
|
224 | + switch($tag){ |
|
225 | 225 | case '_ACT': |
226 | 226 | return true; |
227 | 227 | } |
228 | 228 | return false; |
229 | - } |
|
229 | + } |
|
230 | 230 | |
231 | - /** |
|
232 | - * {@inhericDoc} |
|
233 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetHelpTextTag() |
|
234 | - */ |
|
235 | - public function hGetHelpTextTag($tag) { |
|
236 | - switch($tag){ |
|
237 | - case '_ACT': |
|
238 | - return array( |
|
239 | - I18N::translate('Certificate'), |
|
240 | - '<p>'.I18N::translate('Path to a certificate linked to a source reference.').'</p>'); |
|
241 | - default: |
|
242 | - return null; |
|
243 | - } |
|
244 | - } |
|
231 | + /** |
|
232 | + * {@inhericDoc} |
|
233 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\CustomSimpleTagManagerInterface::hGetHelpTextTag() |
|
234 | + */ |
|
235 | + public function hGetHelpTextTag($tag) { |
|
236 | + switch($tag){ |
|
237 | + case '_ACT': |
|
238 | + return array( |
|
239 | + I18N::translate('Certificate'), |
|
240 | + '<p>'.I18N::translate('Path to a certificate linked to a source reference.').'</p>'); |
|
241 | + default: |
|
242 | + return null; |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | - /** |
|
247 | - * Returns the default Certificate File Provider, as configured in the module |
|
248 | - * |
|
249 | - * @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface |
|
250 | - */ |
|
251 | - public function getProvider() { |
|
252 | - global $WT_TREE; |
|
246 | + /** |
|
247 | + * Returns the default Certificate File Provider, as configured in the module |
|
248 | + * |
|
249 | + * @return \MyArtJaub\Webtrees\Module\Certificates\Model\CertificateProviderInterface |
|
250 | + */ |
|
251 | + public function getProvider() { |
|
252 | + global $WT_TREE; |
|
253 | 253 | |
254 | - if(!$this->provider) { |
|
255 | - $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); |
|
256 | - $this->provider = new CertificateFileProvider($root_path, $WT_TREE); |
|
257 | - } |
|
258 | - return $this->provider; |
|
259 | - } |
|
254 | + if(!$this->provider) { |
|
255 | + $root_path = $this->getSetting('MAJ_CERT_ROOTDIR', 'certificates/'); |
|
256 | + $this->provider = new CertificateFileProvider($root_path, $WT_TREE); |
|
257 | + } |
|
258 | + return $this->provider; |
|
259 | + } |
|
260 | 260 | |
261 | 261 | |
262 | - /** |
|
263 | - * Return the HTML code for custom simple tag _ACT |
|
264 | - * |
|
265 | - * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
266 | - * @param string|null $sid Linked Source ID, if it exists |
|
267 | - */ |
|
268 | - protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
|
269 | - $html = ''; |
|
270 | - if($certificate){ |
|
271 | - $certificate->setSource($sid); |
|
272 | - $html = $certificate->displayImage('icon'); |
|
273 | - } |
|
274 | - return $html; |
|
275 | - } |
|
262 | + /** |
|
263 | + * Return the HTML code for custom simple tag _ACT |
|
264 | + * |
|
265 | + * @param Certificate $certificatePath Certificate (as per the GEDCOM) |
|
266 | + * @param string|null $sid Linked Source ID, if it exists |
|
267 | + */ |
|
268 | + protected function getDisplay_ACT(Certificate $certificate, $sid = null){ |
|
269 | + $html = ''; |
|
270 | + if($certificate){ |
|
271 | + $certificate->setSource($sid); |
|
272 | + $html = $certificate->displayImage('icon'); |
|
273 | + } |
|
274 | + return $html; |
|
275 | + } |
|
276 | 276 | |
277 | 277 | |
278 | 278 | } |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * Constructor for Lineage node |
42 | 42 | * |
43 | - * @param Fisharebest\Webtrees\Individual $node_indi Main individual |
|
43 | + * @param Individual $node_indi Main individual |
|
44 | 44 | * @param LineageRootNode $root_node Node of the lineage root |
45 | 45 | * @param unknown $alt_surname Follow-up surname |
46 | 46 | */ |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | /** |
55 | 55 | * Add a spouse family to the node |
56 | 56 | * |
57 | - * @param Fisharebest\Webtrees\Family $fams |
|
57 | + * @param Family $fams |
|
58 | 58 | */ |
59 | 59 | public function addFamily(Family $fams) { |
60 | 60 | if($fams && !isset($this->linked_fams[$fams])) { |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * Add a child LineageNode to the node |
67 | 67 | * |
68 | - * @param Fisharebest\Webtrees\Family $fams |
|
68 | + * @param Family $fams |
|
69 | 69 | * @param LineageNode $child |
70 | 70 | */ |
71 | 71 | public function addChild(Family $fams, LineageNode $child = null) { |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | /** |
81 | 81 | * Returns the node individual |
82 | 82 | * |
83 | - * @return Fisharebest\Webtrees\Individual |
|
83 | + * @return \Fisharebest\Webtrees\GedcomRecord |
|
84 | 84 | */ |
85 | 85 | public function getIndividual() { |
86 | 86 | return $this->node_indi; |
@@ -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,390 +22,390 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class SosaProvider { |
24 | 24 | |
25 | - /** |
|
26 | - * Maximum number of generation the database is able to hold. |
|
27 | - * @var int MAX_DB_GENERATIONS |
|
28 | - */ |
|
29 | - const MAX_DB_GENERATIONS = 64; |
|
30 | - |
|
31 | - /** |
|
32 | - * System's default user (ID -1 in the database |
|
33 | - * @var User $default_user |
|
34 | - */ |
|
35 | - protected static $default_user; |
|
36 | - |
|
37 | - /** |
|
38 | - * Reference user |
|
39 | - * @var User $user |
|
40 | - */ |
|
41 | - protected $user; |
|
42 | - |
|
43 | - /** |
|
44 | - * Reference tree |
|
45 | - * @var Tree $tree |
|
46 | - */ |
|
47 | - protected $tree; |
|
48 | - |
|
49 | - /** |
|
50 | - * Cached list of Sosa Individuals by generation |
|
51 | - * Format: key = generation, value = array ( sosa => Individual ID) |
|
52 | - * @var array $sosa_list_by_gen |
|
53 | - */ |
|
54 | - protected $sosa_list_by_gen; |
|
55 | - |
|
56 | - /** |
|
57 | - * Cached list of Sosa Families by generation |
|
58 | - * Format: key = generation, value = array ( sosa => Family ID) |
|
59 | - * @var unknown $sosa_fam_list_by_gen |
|
60 | - */ |
|
61 | - protected $sosa_fam_list_by_gen; |
|
62 | - |
|
63 | - /** |
|
64 | - * Cached array of statistics by generation |
|
65 | - * Format: key = generation, |
|
66 | - * value = array( |
|
67 | - * sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth |
|
68 | - * ) |
|
69 | - * @var array $statistics_tab |
|
70 | - */ |
|
71 | - protected $statistics_tab; |
|
72 | - |
|
73 | - /** |
|
74 | - * Has the provider's initialisation completed |
|
75 | - * @var bool $is_setup |
|
76 | - */ |
|
77 | - protected $is_setup; |
|
78 | - |
|
79 | - /** |
|
80 | - * Constructor for Sosa Provider. |
|
81 | - * A provider is defined in relation to a specific tree and reference user. |
|
82 | - * |
|
83 | - * @param Tree $tree |
|
84 | - * @param User $user |
|
85 | - */ |
|
86 | - public function __construct(Tree $tree, User $user = null) { |
|
87 | - if(self::$default_user === null) |
|
88 | - self::$default_user = User::find(-1); |
|
25 | + /** |
|
26 | + * Maximum number of generation the database is able to hold. |
|
27 | + * @var int MAX_DB_GENERATIONS |
|
28 | + */ |
|
29 | + const MAX_DB_GENERATIONS = 64; |
|
30 | + |
|
31 | + /** |
|
32 | + * System's default user (ID -1 in the database |
|
33 | + * @var User $default_user |
|
34 | + */ |
|
35 | + protected static $default_user; |
|
36 | + |
|
37 | + /** |
|
38 | + * Reference user |
|
39 | + * @var User $user |
|
40 | + */ |
|
41 | + protected $user; |
|
42 | + |
|
43 | + /** |
|
44 | + * Reference tree |
|
45 | + * @var Tree $tree |
|
46 | + */ |
|
47 | + protected $tree; |
|
48 | + |
|
49 | + /** |
|
50 | + * Cached list of Sosa Individuals by generation |
|
51 | + * Format: key = generation, value = array ( sosa => Individual ID) |
|
52 | + * @var array $sosa_list_by_gen |
|
53 | + */ |
|
54 | + protected $sosa_list_by_gen; |
|
55 | + |
|
56 | + /** |
|
57 | + * Cached list of Sosa Families by generation |
|
58 | + * Format: key = generation, value = array ( sosa => Family ID) |
|
59 | + * @var unknown $sosa_fam_list_by_gen |
|
60 | + */ |
|
61 | + protected $sosa_fam_list_by_gen; |
|
62 | + |
|
63 | + /** |
|
64 | + * Cached array of statistics by generation |
|
65 | + * Format: key = generation, |
|
66 | + * value = array( |
|
67 | + * sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth |
|
68 | + * ) |
|
69 | + * @var array $statistics_tab |
|
70 | + */ |
|
71 | + protected $statistics_tab; |
|
72 | + |
|
73 | + /** |
|
74 | + * Has the provider's initialisation completed |
|
75 | + * @var bool $is_setup |
|
76 | + */ |
|
77 | + protected $is_setup; |
|
78 | + |
|
79 | + /** |
|
80 | + * Constructor for Sosa Provider. |
|
81 | + * A provider is defined in relation to a specific tree and reference user. |
|
82 | + * |
|
83 | + * @param Tree $tree |
|
84 | + * @param User $user |
|
85 | + */ |
|
86 | + public function __construct(Tree $tree, User $user = null) { |
|
87 | + if(self::$default_user === null) |
|
88 | + self::$default_user = User::find(-1); |
|
89 | 89 | |
90 | - $this->tree = $tree; |
|
91 | - $this->user = $user; |
|
92 | - $this->is_setup = true; |
|
93 | - if($this->user === null) $this->user = Auth::user(); |
|
94 | - if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
90 | + $this->tree = $tree; |
|
91 | + $this->user = $user; |
|
92 | + $this->is_setup = true; |
|
93 | + if($this->user === null) $this->user = Auth::user(); |
|
94 | + if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
95 | 95 | |
96 | - // Check if the user, or the default user, has a root already setup; |
|
97 | - if(empty($this->getRootIndiId())) { |
|
98 | - if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | - $this->is_setup = false; |
|
100 | - } |
|
101 | - else { |
|
102 | - $this->user = self::$default_user; |
|
103 | - $this->is_setup = $this->getRootIndiId() === null; |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns is the Provider has been successfully set up |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isSetup() { |
|
113 | - return $this->is_setup; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Return the root individual ID for the reference tree and user. |
|
118 | - * @return string Individual ID |
|
119 | - */ |
|
120 | - public function getRootIndiId() { |
|
121 | - return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Return the root individual for the reference tree and user. |
|
126 | - * @return Individual Individual |
|
127 | - */ |
|
128 | - public function getRootIndi() { |
|
129 | - $root_indi_id = $this->getRootIndiId(); |
|
130 | - if(!empty($root_indi_id)) { |
|
131 | - return Individual::getInstance($root_indi_id, $this->tree); |
|
132 | - } |
|
133 | - return null; |
|
134 | - } |
|
96 | + // Check if the user, or the default user, has a root already setup; |
|
97 | + if(empty($this->getRootIndiId())) { |
|
98 | + if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | + $this->is_setup = false; |
|
100 | + } |
|
101 | + else { |
|
102 | + $this->user = self::$default_user; |
|
103 | + $this->is_setup = $this->getRootIndiId() === null; |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns is the Provider has been successfully set up |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isSetup() { |
|
113 | + return $this->is_setup; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Return the root individual ID for the reference tree and user. |
|
118 | + * @return string Individual ID |
|
119 | + */ |
|
120 | + public function getRootIndiId() { |
|
121 | + return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Return the root individual for the reference tree and user. |
|
126 | + * @return Individual Individual |
|
127 | + */ |
|
128 | + public function getRootIndi() { |
|
129 | + $root_indi_id = $this->getRootIndiId(); |
|
130 | + if(!empty($root_indi_id)) { |
|
131 | + return Individual::getInstance($root_indi_id, $this->tree); |
|
132 | + } |
|
133 | + return null; |
|
134 | + } |
|
135 | 135 | |
136 | - /***************** |
|
136 | + /***************** |
|
137 | 137 | * DATA CRUD LAYER |
138 | 138 | *****************/ |
139 | 139 | |
140 | - /** |
|
141 | - * Remove all Sosa entries related to the gedcom file and user |
|
142 | - */ |
|
143 | - public function deleteAll() { |
|
144 | - if(!$this->is_setup) return; |
|
145 | - Database::prepare( |
|
146 | - 'DELETE FROM `##maj_sosa`'. |
|
147 | - ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
148 | - ->execute(array( |
|
149 | - 'tree_id' => $this->tree->getTreeId(), |
|
150 | - 'user_id' => $this->user->getUserId() |
|
151 | - )); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Remove all ancestors of a sosa number |
|
156 | - * |
|
157 | - * @param int $sosa |
|
158 | - */ |
|
159 | - public function deleteAncestors($sosa) { |
|
160 | - if(!$this->is_setup) return; |
|
161 | - $gen = Functions::getGeneration($sosa); |
|
162 | - Database::prepare( |
|
163 | - 'DELETE FROM `##maj_sosa`'. |
|
164 | - ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | - ' AND majs_gen >= :gen' . |
|
166 | - ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
167 | - )->execute(array( |
|
168 | - 'tree_id' => $this->tree->getTreeId(), |
|
169 | - 'user_id' => $this->user->getUserId(), |
|
170 | - 'gen' => $gen, |
|
171 | - 'sosa' => $sosa |
|
172 | - )); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Insert (or update if already existing) a list of Sosa individuals |
|
177 | - * @param array $sosa_records |
|
178 | - */ |
|
179 | - public function insertOrUpdate($sosa_records) { |
|
180 | - if(!$this->is_setup) return; |
|
140 | + /** |
|
141 | + * Remove all Sosa entries related to the gedcom file and user |
|
142 | + */ |
|
143 | + public function deleteAll() { |
|
144 | + if(!$this->is_setup) return; |
|
145 | + Database::prepare( |
|
146 | + 'DELETE FROM `##maj_sosa`'. |
|
147 | + ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
148 | + ->execute(array( |
|
149 | + 'tree_id' => $this->tree->getTreeId(), |
|
150 | + 'user_id' => $this->user->getUserId() |
|
151 | + )); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Remove all ancestors of a sosa number |
|
156 | + * |
|
157 | + * @param int $sosa |
|
158 | + */ |
|
159 | + public function deleteAncestors($sosa) { |
|
160 | + if(!$this->is_setup) return; |
|
161 | + $gen = Functions::getGeneration($sosa); |
|
162 | + Database::prepare( |
|
163 | + 'DELETE FROM `##maj_sosa`'. |
|
164 | + ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | + ' AND majs_gen >= :gen' . |
|
166 | + ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
167 | + )->execute(array( |
|
168 | + 'tree_id' => $this->tree->getTreeId(), |
|
169 | + 'user_id' => $this->user->getUserId(), |
|
170 | + 'gen' => $gen, |
|
171 | + 'sosa' => $sosa |
|
172 | + )); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Insert (or update if already existing) a list of Sosa individuals |
|
177 | + * @param array $sosa_records |
|
178 | + */ |
|
179 | + public function insertOrUpdate($sosa_records) { |
|
180 | + if(!$this->is_setup) return; |
|
181 | 181 | |
182 | - $treeid = $this->tree->getTreeId(); |
|
183 | - $userid = $this->user->getUserId(); |
|
184 | - $questionmarks_table = array(); |
|
185 | - $values_table = array(); |
|
182 | + $treeid = $this->tree->getTreeId(); |
|
183 | + $userid = $this->user->getUserId(); |
|
184 | + $questionmarks_table = array(); |
|
185 | + $values_table = array(); |
|
186 | 186 | |
187 | - $i = 0; |
|
188 | - foreach ($sosa_records as $row) { |
|
189 | - $gen = Functions::getGeneration($row['sosa']); |
|
190 | - if($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | - $questionmarks_table[] = |
|
192 | - '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
193 | - $values_table = array_merge( |
|
194 | - $values_table, |
|
195 | - array( |
|
196 | - 'tree_id'.$i => $treeid, |
|
197 | - 'user_id'.$i => $userid, |
|
198 | - 'sosa'.$i => $row['sosa'], |
|
199 | - 'indi_id'.$i => $row['indi'], |
|
200 | - 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
201 | - 'byear'.$i => $row['birth_year'], |
|
202 | - 'dyear'.$i => $row['death_year'] |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - $i++; |
|
207 | - } |
|
187 | + $i = 0; |
|
188 | + foreach ($sosa_records as $row) { |
|
189 | + $gen = Functions::getGeneration($row['sosa']); |
|
190 | + if($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | + $questionmarks_table[] = |
|
192 | + '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
193 | + $values_table = array_merge( |
|
194 | + $values_table, |
|
195 | + array( |
|
196 | + 'tree_id'.$i => $treeid, |
|
197 | + 'user_id'.$i => $userid, |
|
198 | + 'sosa'.$i => $row['sosa'], |
|
199 | + 'indi_id'.$i => $row['indi'], |
|
200 | + 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
201 | + 'byear'.$i => $row['birth_year'], |
|
202 | + 'dyear'.$i => $row['death_year'] |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + $i++; |
|
207 | + } |
|
208 | 208 | |
209 | - $sql = 'REPLACE INTO `##maj_sosa`' . |
|
210 | - ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
211 | - ' VALUES '. implode(',', $questionmarks_table); |
|
212 | - Database::prepare($sql)->execute($values_table); |
|
213 | - } |
|
209 | + $sql = 'REPLACE INTO `##maj_sosa`' . |
|
210 | + ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
211 | + ' VALUES '. implode(',', $questionmarks_table); |
|
212 | + Database::prepare($sql)->execute($values_table); |
|
213 | + } |
|
214 | 214 | |
215 | - /**************** |
|
215 | + /**************** |
|
216 | 216 | * SIMPLE QUERIES |
217 | 217 | ****************/ |
218 | 218 | |
219 | - /** |
|
220 | - * Returns the list of Sosa numbers to which an individual is related. |
|
221 | - * Format: key = sosa number, value = generation for the Sosa number |
|
222 | - * |
|
223 | - * @param Individual $indi |
|
224 | - * @return array Array of sosa numbers |
|
225 | - */ |
|
226 | - public function getSosaNumbers(Individual $indi) { |
|
227 | - if(!$this->is_setup) return array(); |
|
228 | - return Database::prepare( |
|
229 | - 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
230 | - ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
231 | - )->execute(array( |
|
232 | - 'indi_id' => $indi->getXref(), |
|
233 | - 'tree_id' => $this->tree->getTreeId(), |
|
234 | - 'user_id' => $this->user->getUserId() |
|
235 | - ))->fetchAssoc(); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Get the last generation of Sosa ancestors |
|
240 | - * |
|
241 | - * @return number Last generation if found, 1 otherwise |
|
242 | - */ |
|
243 | - public function getLastGeneration() { |
|
244 | - if(!$this->is_setup) return; |
|
245 | - return Database::prepare( |
|
246 | - 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
247 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
248 | - )->execute(array( |
|
249 | - 'tree_id' => $this->tree->getTreeId(), |
|
250 | - 'user_id' => $this->user->getUserId() |
|
251 | - ))->fetchOne() ?: 1; |
|
252 | - } |
|
253 | - |
|
254 | - /************* |
|
219 | + /** |
|
220 | + * Returns the list of Sosa numbers to which an individual is related. |
|
221 | + * Format: key = sosa number, value = generation for the Sosa number |
|
222 | + * |
|
223 | + * @param Individual $indi |
|
224 | + * @return array Array of sosa numbers |
|
225 | + */ |
|
226 | + public function getSosaNumbers(Individual $indi) { |
|
227 | + if(!$this->is_setup) return array(); |
|
228 | + return Database::prepare( |
|
229 | + 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
230 | + ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
231 | + )->execute(array( |
|
232 | + 'indi_id' => $indi->getXref(), |
|
233 | + 'tree_id' => $this->tree->getTreeId(), |
|
234 | + 'user_id' => $this->user->getUserId() |
|
235 | + ))->fetchAssoc(); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Get the last generation of Sosa ancestors |
|
240 | + * |
|
241 | + * @return number Last generation if found, 1 otherwise |
|
242 | + */ |
|
243 | + public function getLastGeneration() { |
|
244 | + if(!$this->is_setup) return; |
|
245 | + return Database::prepare( |
|
246 | + 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
247 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
248 | + )->execute(array( |
|
249 | + 'tree_id' => $this->tree->getTreeId(), |
|
250 | + 'user_id' => $this->user->getUserId() |
|
251 | + ))->fetchOne() ?: 1; |
|
252 | + } |
|
253 | + |
|
254 | + /************* |
|
255 | 255 | * SOSA LISTS |
256 | 256 | *************/ |
257 | 257 | |
258 | - /** |
|
259 | - * Return the list of all sosas, with the generations it belongs to |
|
260 | - * |
|
261 | - * @param int $ged_id ID of the gedcom file |
|
262 | - * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
263 | - */ |
|
264 | - public function getAllSosaWithGenerations(){ |
|
265 | - if(!$this->is_setup) return array(); |
|
266 | - return Database::prepare( |
|
267 | - 'SELECT majs_i_id AS indi,' . |
|
268 | - ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
269 | - ' FROM `##maj_sosa`' . |
|
270 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
271 | - ' GROUP BY majs_i_id' |
|
272 | - )->execute(array( |
|
273 | - 'tree_id' => $this->tree->getTreeId(), |
|
274 | - 'user_id' => $this->user->getUserId() |
|
275 | - ))->fetchAssoc(); |
|
276 | - } |
|
277 | - |
|
278 | - /** |
|
279 | - * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
280 | - * |
|
281 | - * @param number $gen Generation |
|
282 | - * @return array Array of Sosa individuals |
|
283 | - */ |
|
284 | - public function getSosaListAtGeneration($gen){ |
|
285 | - if(!$this->is_setup) return array(); |
|
286 | - if(!$this->sosa_list_by_gen) |
|
287 | - $this->sosa_list_by_gen = array(); |
|
258 | + /** |
|
259 | + * Return the list of all sosas, with the generations it belongs to |
|
260 | + * |
|
261 | + * @param int $ged_id ID of the gedcom file |
|
262 | + * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
263 | + */ |
|
264 | + public function getAllSosaWithGenerations(){ |
|
265 | + if(!$this->is_setup) return array(); |
|
266 | + return Database::prepare( |
|
267 | + 'SELECT majs_i_id AS indi,' . |
|
268 | + ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
269 | + ' FROM `##maj_sosa`' . |
|
270 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
271 | + ' GROUP BY majs_i_id' |
|
272 | + )->execute(array( |
|
273 | + 'tree_id' => $this->tree->getTreeId(), |
|
274 | + 'user_id' => $this->user->getUserId() |
|
275 | + ))->fetchAssoc(); |
|
276 | + } |
|
277 | + |
|
278 | + /** |
|
279 | + * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
280 | + * |
|
281 | + * @param number $gen Generation |
|
282 | + * @return array Array of Sosa individuals |
|
283 | + */ |
|
284 | + public function getSosaListAtGeneration($gen){ |
|
285 | + if(!$this->is_setup) return array(); |
|
286 | + if(!$this->sosa_list_by_gen) |
|
287 | + $this->sosa_list_by_gen = array(); |
|
288 | 288 | |
289 | - if($gen){ |
|
290 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
291 | - $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
292 | - 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
293 | - ' FROM `##maj_sosa`'. |
|
294 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
295 | - ' AND majs_gen = :gen'. |
|
296 | - ' ORDER BY majs_sosa ASC') |
|
297 | - ->execute(array( |
|
298 | - 'tree_id' => $this->tree->getTreeId(), |
|
299 | - 'user_id' => $this->user->getUserId(), |
|
300 | - 'gen' => $gen |
|
301 | - )) |
|
302 | - ->fetchAssoc(); |
|
303 | - } |
|
304 | - return $this->sosa_list_by_gen[$gen]; |
|
305 | - } |
|
306 | - return array(); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
311 | - * |
|
312 | - * @param number $gen Generation |
|
313 | - * @return array Array of Sosa families |
|
314 | - */ |
|
315 | - public function getFamilySosaListAtGeneration($gen){ |
|
316 | - if(!$this->is_setup) return array(); |
|
317 | - if(!$this->sosa_fam_list_by_gen) |
|
318 | - $this->sosa_fam_list_by_gen = array(); |
|
289 | + if($gen){ |
|
290 | + if(!isset($this->sosa_list_by_gen[$gen])){ |
|
291 | + $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
292 | + 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
293 | + ' FROM `##maj_sosa`'. |
|
294 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
295 | + ' AND majs_gen = :gen'. |
|
296 | + ' ORDER BY majs_sosa ASC') |
|
297 | + ->execute(array( |
|
298 | + 'tree_id' => $this->tree->getTreeId(), |
|
299 | + 'user_id' => $this->user->getUserId(), |
|
300 | + 'gen' => $gen |
|
301 | + )) |
|
302 | + ->fetchAssoc(); |
|
303 | + } |
|
304 | + return $this->sosa_list_by_gen[$gen]; |
|
305 | + } |
|
306 | + return array(); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
311 | + * |
|
312 | + * @param number $gen Generation |
|
313 | + * @return array Array of Sosa families |
|
314 | + */ |
|
315 | + public function getFamilySosaListAtGeneration($gen){ |
|
316 | + if(!$this->is_setup) return array(); |
|
317 | + if(!$this->sosa_fam_list_by_gen) |
|
318 | + $this->sosa_fam_list_by_gen = array(); |
|
319 | 319 | |
320 | - if($gen){ |
|
321 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
322 | - $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
323 | - 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
324 | - ' FROM `##families`'. |
|
325 | - ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
326 | - ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
327 | - ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
328 | - ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
329 | - ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
330 | - ' AND s1.majs_gen = :gen'. |
|
331 | - ' ORDER BY s1.majs_sosa ASC' |
|
332 | - ) |
|
333 | - ->execute(array( |
|
334 | - 'tree_id' => $this->tree->getTreeId(), |
|
335 | - 'user_id' => $this->user->getUserId(), |
|
336 | - 'gen' => $gen |
|
337 | - )) |
|
338 | - ->fetchAssoc(); |
|
339 | - } |
|
340 | - return $this->sosa_fam_list_by_gen[$gen]; |
|
341 | - } |
|
342 | - return array(); |
|
343 | - } |
|
344 | - |
|
345 | - /** |
|
346 | - * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
347 | - * |
|
348 | - * @param number $gen Generation |
|
349 | - * @return array Array of Sosa individuals |
|
350 | - */ |
|
351 | - public function getMissingSosaListAtGeneration($gen){ |
|
352 | - if(!$this->is_setup) return array(); |
|
353 | - if($gen){ |
|
354 | - return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
355 | - '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'. |
|
356 | - ' FROM `##maj_sosa` schild'. |
|
357 | - ' 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)'. |
|
358 | - ' 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)'. |
|
359 | - ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
360 | - ' AND schild.majs_gen = :gen'. |
|
361 | - ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
362 | - ' ORDER BY schild.majs_sosa ASC') |
|
363 | - ->execute(array( |
|
364 | - 'tree_id' => $this->tree->getTreeId(), |
|
365 | - 'user_id' => $this->user->getUserId(), |
|
366 | - 'gen' => $gen - 1 |
|
367 | - ))->fetchAll(\PDO::FETCH_ASSOC); |
|
368 | - } |
|
369 | - return array(); |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /************* |
|
320 | + if($gen){ |
|
321 | + if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
322 | + $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
323 | + 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
324 | + ' FROM `##families`'. |
|
325 | + ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
326 | + ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
327 | + ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
328 | + ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
329 | + ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
330 | + ' AND s1.majs_gen = :gen'. |
|
331 | + ' ORDER BY s1.majs_sosa ASC' |
|
332 | + ) |
|
333 | + ->execute(array( |
|
334 | + 'tree_id' => $this->tree->getTreeId(), |
|
335 | + 'user_id' => $this->user->getUserId(), |
|
336 | + 'gen' => $gen |
|
337 | + )) |
|
338 | + ->fetchAssoc(); |
|
339 | + } |
|
340 | + return $this->sosa_fam_list_by_gen[$gen]; |
|
341 | + } |
|
342 | + return array(); |
|
343 | + } |
|
344 | + |
|
345 | + /** |
|
346 | + * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
347 | + * |
|
348 | + * @param number $gen Generation |
|
349 | + * @return array Array of Sosa individuals |
|
350 | + */ |
|
351 | + public function getMissingSosaListAtGeneration($gen){ |
|
352 | + if(!$this->is_setup) return array(); |
|
353 | + if($gen){ |
|
354 | + return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
355 | + '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'. |
|
356 | + ' FROM `##maj_sosa` schild'. |
|
357 | + ' 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)'. |
|
358 | + ' 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)'. |
|
359 | + ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
360 | + ' AND schild.majs_gen = :gen'. |
|
361 | + ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
362 | + ' ORDER BY schild.majs_sosa ASC') |
|
363 | + ->execute(array( |
|
364 | + 'tree_id' => $this->tree->getTreeId(), |
|
365 | + 'user_id' => $this->user->getUserId(), |
|
366 | + 'gen' => $gen - 1 |
|
367 | + ))->fetchAll(\PDO::FETCH_ASSOC); |
|
368 | + } |
|
369 | + return array(); |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /************* |
|
375 | 375 | * STATISTICS |
376 | 376 | *************/ |
377 | - /** |
|
378 | - * Get the statistic array detailed by generation. |
|
379 | - * Statistics for each generation are: |
|
380 | - * - The number of Sosa in generation |
|
381 | - * - The number of Sosa up to generation |
|
382 | - * - The number of distinct Sosa up to generation |
|
383 | - * - The year of the first birth in generation |
|
384 | - * - The year of the last birth in generation |
|
385 | - * - The average year of birth in generation |
|
386 | - * |
|
387 | - * @return array Statistics array |
|
388 | - */ |
|
389 | - public function getStatisticsByGeneration() { |
|
390 | - if(!$this->is_setup) return array(); |
|
391 | - if(!$this->statistics_tab) { |
|
392 | - $this->statistics_tab = array(); |
|
393 | - if($maxGeneration = $this->getLastGeneration()) { |
|
394 | - for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
395 | - $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
396 | - $this->statistics_tab[$gen] = array( |
|
397 | - 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
398 | - 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
399 | - 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
400 | - 'firstBirth' => $birthStats['first'], |
|
401 | - 'lastBirth' => $birthStats['last'], |
|
402 | - 'avgBirth' => $birthStats['avg'] |
|
403 | - ); |
|
404 | - } |
|
405 | - } |
|
406 | - } |
|
407 | - return $this->statistics_tab; |
|
408 | - } |
|
377 | + /** |
|
378 | + * Get the statistic array detailed by generation. |
|
379 | + * Statistics for each generation are: |
|
380 | + * - The number of Sosa in generation |
|
381 | + * - The number of Sosa up to generation |
|
382 | + * - The number of distinct Sosa up to generation |
|
383 | + * - The year of the first birth in generation |
|
384 | + * - The year of the last birth in generation |
|
385 | + * - The average year of birth in generation |
|
386 | + * |
|
387 | + * @return array Statistics array |
|
388 | + */ |
|
389 | + public function getStatisticsByGeneration() { |
|
390 | + if(!$this->is_setup) return array(); |
|
391 | + if(!$this->statistics_tab) { |
|
392 | + $this->statistics_tab = array(); |
|
393 | + if($maxGeneration = $this->getLastGeneration()) { |
|
394 | + for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
395 | + $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
396 | + $this->statistics_tab[$gen] = array( |
|
397 | + 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
398 | + 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
399 | + 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
400 | + 'firstBirth' => $birthStats['first'], |
|
401 | + 'lastBirth' => $birthStats['last'], |
|
402 | + 'avgBirth' => $birthStats['avg'] |
|
403 | + ); |
|
404 | + } |
|
405 | + } |
|
406 | + } |
|
407 | + return $this->statistics_tab; |
|
408 | + } |
|
409 | 409 | |
410 | 410 | /** |
411 | 411 | * How many individuals exist in the tree. |
@@ -413,205 +413,205 @@ discard block |
||
413 | 413 | * @return int |
414 | 414 | */ |
415 | 415 | public function getTotalIndividuals() { |
416 | - if(!$this->is_setup) return 0; |
|
417 | - return Database::prepare( |
|
418 | - 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
|
419 | - ' WHERE i_file = :tree_id') |
|
420 | - ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
421 | - ->fetchOne() ?: 0; |
|
416 | + if(!$this->is_setup) return 0; |
|
417 | + return Database::prepare( |
|
418 | + 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
|
419 | + ' WHERE i_file = :tree_id') |
|
420 | + ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
421 | + ->fetchOne() ?: 0; |
|
422 | 422 | } |
423 | 423 | |
424 | - /** |
|
425 | - * Get the total Sosa count for all generations |
|
426 | - * |
|
427 | - * @return number Number of Sosas |
|
428 | - */ |
|
429 | - public function getSosaCount(){ |
|
430 | - if(!$this->is_setup) return 0; |
|
431 | - return Database::prepare( |
|
432 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
433 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
434 | - ->execute(array( |
|
435 | - 'tree_id' => $this->tree->getTreeId(), |
|
436 | - 'user_id' => $this->user->getUserId() |
|
437 | - ))->fetchOne() ?: 0; |
|
438 | - } |
|
439 | - |
|
440 | - /** |
|
441 | - * Get the number of Sosa in a specific generation. |
|
442 | - * |
|
443 | - * @param number $gen Generation |
|
444 | - * @return number Number of Sosas in generation |
|
445 | - */ |
|
446 | - public function getSosaCountAtGeneration($gen){ |
|
447 | - if(!$this->is_setup) return 0; |
|
448 | - return Database::prepare( |
|
449 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
450 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
451 | - ' AND majs_gen= :gen') |
|
452 | - ->execute(array( |
|
453 | - 'tree_id' => $this->tree->getTreeId(), |
|
454 | - 'user_id' => $this->user->getUserId(), |
|
455 | - 'gen' => $gen |
|
456 | - ))->fetchOne() ?: 0; |
|
457 | - } |
|
458 | - |
|
459 | - /** |
|
460 | - * Get the total number of Sosa up to a specific generation. |
|
461 | - * |
|
462 | - * @param number $gen Generation |
|
463 | - * @return number Total number of Sosas up to generation |
|
464 | - */ |
|
465 | - public function getSosaCountUpToGeneration($gen){ |
|
466 | - if(!$this->is_setup) return 0; |
|
467 | - return Database::prepare( |
|
468 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
469 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
470 | - ' AND majs_gen <= :gen') |
|
471 | - ->execute(array( |
|
472 | - 'tree_id' => $this->tree->getTreeId(), |
|
473 | - 'user_id' => $this->user->getUserId(), |
|
474 | - 'gen' => $gen |
|
475 | - ))->fetchOne() ?: 0; |
|
476 | - } |
|
477 | - |
|
478 | - /** |
|
479 | - * Get the total number of distinct Sosa individual for all generations. |
|
480 | - * |
|
481 | - * @return number Total number of distinct individual |
|
482 | - */ |
|
483 | - public function getDifferentSosaCount(){ |
|
484 | - if(!$this->is_setup) return 0; |
|
485 | - return Database::prepare( |
|
486 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
487 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
488 | - ->execute(array( |
|
489 | - 'tree_id' => $this->tree->getTreeId(), |
|
490 | - 'user_id' => $this->user->getUserId() |
|
491 | - ))->fetchOne() ?: 0; |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * Get the number of distinct Sosa individual up to a specific generation. |
|
496 | - * |
|
497 | - * @param number $gen Generation |
|
498 | - * @return number Number of distinct Sosa individuals up to generation |
|
499 | - */ |
|
500 | - public function getDifferentSosaCountUpToGeneration($gen){ |
|
501 | - if(!$this->is_setup) return 0; |
|
502 | - return Database::prepare( |
|
503 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
504 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
505 | - ' AND majs_gen <= :gen') |
|
506 | - ->execute(array( |
|
507 | - 'tree_id' => $this->tree->getTreeId(), |
|
508 | - 'user_id' => $this->user->getUserId(), |
|
509 | - 'gen' => $gen |
|
510 | - ))->fetchOne() ?: 0; |
|
511 | - } |
|
512 | - |
|
513 | - /** |
|
514 | - * Get an array of birth statistics for a specific generation |
|
515 | - * Statistics are : |
|
516 | - * - first : First birth year in generation |
|
517 | - * - last : Last birth year in generation |
|
518 | - * - avg : Average birth year |
|
519 | - * |
|
520 | - * @param number $gen Generation |
|
521 | - * @return array Birth statistics array |
|
522 | - */ |
|
523 | - public function getStatsBirthYearInGeneration($gen){ |
|
524 | - if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
525 | - return Database::prepare( |
|
526 | - 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
|
527 | - ' FROM `##maj_sosa`' . |
|
528 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
529 | - ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
|
530 | - ->execute(array( |
|
531 | - 'tree_id' => $this->tree->getTreeId(), |
|
532 | - 'user_id' => $this->user->getUserId(), |
|
533 | - 'gen' => $gen, |
|
534 | - 'birth_year' => 0)) |
|
535 | - ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0); |
|
536 | - } |
|
537 | - |
|
538 | - /** |
|
539 | - * Get the mean generation time, based on a linear regression of birth years and generations |
|
540 | - * |
|
541 | - * @return number|NULL Mean generation time |
|
542 | - */ |
|
543 | - public function getMeanGenerationTime(){ |
|
544 | - if(!$this->is_setup) return; |
|
545 | - if(!$this->statistics_tab){ |
|
546 | - $this->getStatisticsByGeneration(); |
|
547 | - } |
|
548 | - //Linear regression on x=generation and y=birthdate |
|
549 | - $sum_xy = 0; |
|
550 | - $sum_x=0; |
|
551 | - $sum_y=0; |
|
552 | - $sum_x2=0; |
|
553 | - $n=count($this->statistics_tab); |
|
554 | - foreach($this->statistics_tab as $gen=>$stats){ |
|
555 | - $sum_xy+=$gen*$stats['avgBirth']; |
|
556 | - $sum_x+=$gen; |
|
557 | - $sum_y+=$stats['avgBirth']; |
|
558 | - $sum_x2+=$gen*$gen; |
|
559 | - } |
|
560 | - $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
561 | - if($denom!=0){ |
|
562 | - return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
563 | - } |
|
564 | - return null; |
|
565 | - } |
|
566 | - |
|
567 | - /** |
|
568 | - * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
569 | - * at a specified generation. |
|
570 | - * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
571 | - * |
|
572 | - * Format: |
|
573 | - * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
574 | - * -1 is used for shared ancestors |
|
575 | - * For instance base2(0100) = base10(4) represent the maternal grand father |
|
576 | - * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
577 | - * |
|
578 | - * For instance a result at generation 3 could be : |
|
579 | - * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
580 | - * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
581 | - * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
582 | - * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
583 | - * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
584 | - * ) |
|
585 | - * |
|
586 | - * @param int $gen Reference generation |
|
587 | - * @return array |
|
588 | - */ |
|
589 | - public function getAncestorDispersionForGen($gen) { |
|
590 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
591 | - return Database::prepare( |
|
592 | - 'SELECT branches, count(i_id)'. |
|
593 | - ' FROM ('. |
|
594 | - ' SELECT i_id,'. |
|
595 | - ' CASE'. |
|
596 | - ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
597 | - ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
598 | - ' END branches'. |
|
599 | - ' FROM ('. |
|
600 | - ' SELECT DISTINCT majs_i_id i_id,'. |
|
601 | - ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
602 | - ' FROM `##maj_sosa`'. |
|
603 | - ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
604 | - ' AND majs_gen >= :gen'. |
|
605 | - ' ) indistat'. |
|
606 | - ' GROUP BY i_id'. |
|
607 | - ') grouped'. |
|
608 | - ' GROUP BY branches') |
|
609 | - ->execute(array( |
|
610 | - 'tree_id' => $this->tree->getTreeId(), |
|
611 | - 'user_id' => $this->user->getUserId(), |
|
612 | - 'gen' => $gen |
|
613 | - ))->fetchAssoc() ?: array(); |
|
614 | - } |
|
424 | + /** |
|
425 | + * Get the total Sosa count for all generations |
|
426 | + * |
|
427 | + * @return number Number of Sosas |
|
428 | + */ |
|
429 | + public function getSosaCount(){ |
|
430 | + if(!$this->is_setup) return 0; |
|
431 | + return Database::prepare( |
|
432 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
433 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
434 | + ->execute(array( |
|
435 | + 'tree_id' => $this->tree->getTreeId(), |
|
436 | + 'user_id' => $this->user->getUserId() |
|
437 | + ))->fetchOne() ?: 0; |
|
438 | + } |
|
439 | + |
|
440 | + /** |
|
441 | + * Get the number of Sosa in a specific generation. |
|
442 | + * |
|
443 | + * @param number $gen Generation |
|
444 | + * @return number Number of Sosas in generation |
|
445 | + */ |
|
446 | + public function getSosaCountAtGeneration($gen){ |
|
447 | + if(!$this->is_setup) return 0; |
|
448 | + return Database::prepare( |
|
449 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
450 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
451 | + ' AND majs_gen= :gen') |
|
452 | + ->execute(array( |
|
453 | + 'tree_id' => $this->tree->getTreeId(), |
|
454 | + 'user_id' => $this->user->getUserId(), |
|
455 | + 'gen' => $gen |
|
456 | + ))->fetchOne() ?: 0; |
|
457 | + } |
|
458 | + |
|
459 | + /** |
|
460 | + * Get the total number of Sosa up to a specific generation. |
|
461 | + * |
|
462 | + * @param number $gen Generation |
|
463 | + * @return number Total number of Sosas up to generation |
|
464 | + */ |
|
465 | + public function getSosaCountUpToGeneration($gen){ |
|
466 | + if(!$this->is_setup) return 0; |
|
467 | + return Database::prepare( |
|
468 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
469 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
470 | + ' AND majs_gen <= :gen') |
|
471 | + ->execute(array( |
|
472 | + 'tree_id' => $this->tree->getTreeId(), |
|
473 | + 'user_id' => $this->user->getUserId(), |
|
474 | + 'gen' => $gen |
|
475 | + ))->fetchOne() ?: 0; |
|
476 | + } |
|
477 | + |
|
478 | + /** |
|
479 | + * Get the total number of distinct Sosa individual for all generations. |
|
480 | + * |
|
481 | + * @return number Total number of distinct individual |
|
482 | + */ |
|
483 | + public function getDifferentSosaCount(){ |
|
484 | + if(!$this->is_setup) return 0; |
|
485 | + return Database::prepare( |
|
486 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
487 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
488 | + ->execute(array( |
|
489 | + 'tree_id' => $this->tree->getTreeId(), |
|
490 | + 'user_id' => $this->user->getUserId() |
|
491 | + ))->fetchOne() ?: 0; |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * Get the number of distinct Sosa individual up to a specific generation. |
|
496 | + * |
|
497 | + * @param number $gen Generation |
|
498 | + * @return number Number of distinct Sosa individuals up to generation |
|
499 | + */ |
|
500 | + public function getDifferentSosaCountUpToGeneration($gen){ |
|
501 | + if(!$this->is_setup) return 0; |
|
502 | + return Database::prepare( |
|
503 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
504 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
505 | + ' AND majs_gen <= :gen') |
|
506 | + ->execute(array( |
|
507 | + 'tree_id' => $this->tree->getTreeId(), |
|
508 | + 'user_id' => $this->user->getUserId(), |
|
509 | + 'gen' => $gen |
|
510 | + ))->fetchOne() ?: 0; |
|
511 | + } |
|
512 | + |
|
513 | + /** |
|
514 | + * Get an array of birth statistics for a specific generation |
|
515 | + * Statistics are : |
|
516 | + * - first : First birth year in generation |
|
517 | + * - last : Last birth year in generation |
|
518 | + * - avg : Average birth year |
|
519 | + * |
|
520 | + * @param number $gen Generation |
|
521 | + * @return array Birth statistics array |
|
522 | + */ |
|
523 | + public function getStatsBirthYearInGeneration($gen){ |
|
524 | + if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
525 | + return Database::prepare( |
|
526 | + 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
|
527 | + ' FROM `##maj_sosa`' . |
|
528 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
529 | + ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
|
530 | + ->execute(array( |
|
531 | + 'tree_id' => $this->tree->getTreeId(), |
|
532 | + 'user_id' => $this->user->getUserId(), |
|
533 | + 'gen' => $gen, |
|
534 | + 'birth_year' => 0)) |
|
535 | + ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0); |
|
536 | + } |
|
537 | + |
|
538 | + /** |
|
539 | + * Get the mean generation time, based on a linear regression of birth years and generations |
|
540 | + * |
|
541 | + * @return number|NULL Mean generation time |
|
542 | + */ |
|
543 | + public function getMeanGenerationTime(){ |
|
544 | + if(!$this->is_setup) return; |
|
545 | + if(!$this->statistics_tab){ |
|
546 | + $this->getStatisticsByGeneration(); |
|
547 | + } |
|
548 | + //Linear regression on x=generation and y=birthdate |
|
549 | + $sum_xy = 0; |
|
550 | + $sum_x=0; |
|
551 | + $sum_y=0; |
|
552 | + $sum_x2=0; |
|
553 | + $n=count($this->statistics_tab); |
|
554 | + foreach($this->statistics_tab as $gen=>$stats){ |
|
555 | + $sum_xy+=$gen*$stats['avgBirth']; |
|
556 | + $sum_x+=$gen; |
|
557 | + $sum_y+=$stats['avgBirth']; |
|
558 | + $sum_x2+=$gen*$gen; |
|
559 | + } |
|
560 | + $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
561 | + if($denom!=0){ |
|
562 | + return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
563 | + } |
|
564 | + return null; |
|
565 | + } |
|
566 | + |
|
567 | + /** |
|
568 | + * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
569 | + * at a specified generation. |
|
570 | + * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
571 | + * |
|
572 | + * Format: |
|
573 | + * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
574 | + * -1 is used for shared ancestors |
|
575 | + * For instance base2(0100) = base10(4) represent the maternal grand father |
|
576 | + * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
577 | + * |
|
578 | + * For instance a result at generation 3 could be : |
|
579 | + * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
580 | + * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
581 | + * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
582 | + * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
583 | + * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
584 | + * ) |
|
585 | + * |
|
586 | + * @param int $gen Reference generation |
|
587 | + * @return array |
|
588 | + */ |
|
589 | + public function getAncestorDispersionForGen($gen) { |
|
590 | + if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
591 | + return Database::prepare( |
|
592 | + 'SELECT branches, count(i_id)'. |
|
593 | + ' FROM ('. |
|
594 | + ' SELECT i_id,'. |
|
595 | + ' CASE'. |
|
596 | + ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
597 | + ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
598 | + ' END branches'. |
|
599 | + ' FROM ('. |
|
600 | + ' SELECT DISTINCT majs_i_id i_id,'. |
|
601 | + ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
602 | + ' FROM `##maj_sosa`'. |
|
603 | + ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
604 | + ' AND majs_gen >= :gen'. |
|
605 | + ' ) indistat'. |
|
606 | + ' GROUP BY i_id'. |
|
607 | + ') grouped'. |
|
608 | + ' GROUP BY branches') |
|
609 | + ->execute(array( |
|
610 | + 'tree_id' => $this->tree->getTreeId(), |
|
611 | + 'user_id' => $this->user->getUserId(), |
|
612 | + 'gen' => $gen |
|
613 | + ))->fetchAssoc() ?: array(); |
|
614 | + } |
|
615 | 615 | |
616 | 616 | |
617 | 617 | } |