@@ -22,54 +22,54 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class ImageBuilder { |
24 | 24 | |
25 | - /** |
|
26 | - * Reference media |
|
27 | - * @var Media $media |
|
28 | - */ |
|
29 | - protected $media; |
|
25 | + /** |
|
26 | + * Reference media |
|
27 | + * @var Media $media |
|
28 | + */ |
|
29 | + protected $media; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Use TTF font |
|
33 | - * @var bool $use_ttf |
|
34 | - */ |
|
35 | - protected $use_ttf; |
|
31 | + /** |
|
32 | + * Use TTF font |
|
33 | + * @var bool $use_ttf |
|
34 | + */ |
|
35 | + protected $use_ttf; |
|
36 | 36 | |
37 | - /** |
|
38 | - * Expiration offset. Default is one day. |
|
39 | - * @var int $expire_offset |
|
40 | - */ |
|
41 | - protected $expire_offset; |
|
37 | + /** |
|
38 | + * Expiration offset. Default is one day. |
|
39 | + * @var int $expire_offset |
|
40 | + */ |
|
41 | + protected $expire_offset; |
|
42 | 42 | |
43 | - /** |
|
44 | - * Should the certificate display a watermark |
|
45 | - * @var bool $show_watermark |
|
46 | - */ |
|
47 | - protected $show_watermark; |
|
43 | + /** |
|
44 | + * Should the certificate display a watermark |
|
45 | + * @var bool $show_watermark |
|
46 | + */ |
|
47 | + protected $show_watermark; |
|
48 | 48 | |
49 | - /** |
|
50 | - * Maximum watermark font size. Default is 18. |
|
51 | - * @var int $font_max_size |
|
52 | - */ |
|
53 | - protected $font_max_size; |
|
49 | + /** |
|
50 | + * Maximum watermark font size. Default is 18. |
|
51 | + * @var int $font_max_size |
|
52 | + */ |
|
53 | + protected $font_max_size; |
|
54 | 54 | |
55 | - /** |
|
56 | - * Watermark font color, in hexadecimal. Default is #4D6DF3. |
|
57 | - * @var string $font_color |
|
58 | - */ |
|
59 | - protected $font_color; |
|
55 | + /** |
|
56 | + * Watermark font color, in hexadecimal. Default is #4D6DF3. |
|
57 | + * @var string $font_color |
|
58 | + */ |
|
59 | + protected $font_color; |
|
60 | 60 | |
61 | 61 | /** |
62 | - * Contructor for ImageBuilder |
|
63 | - * |
|
64 | - * @param Media|null $media Reference media object |
|
65 | - */ |
|
62 | + * Contructor for ImageBuilder |
|
63 | + * |
|
64 | + * @param Media|null $media Reference media object |
|
65 | + */ |
|
66 | 66 | public function __construct(Media $media = null){ |
67 | - $this->media = $media; |
|
68 | - $this->use_ttf = function_exists('imagettftext'); |
|
69 | - $this->expire_offset = 3600 * 24; |
|
70 | - $this->show_watermark = true; |
|
71 | - $this->font_max_size = 18; |
|
72 | - $this->font_color = '#4D6DF3'; |
|
67 | + $this->media = $media; |
|
68 | + $this->use_ttf = function_exists('imagettftext'); |
|
69 | + $this->expire_offset = 3600 * 24; |
|
70 | + $this->show_watermark = true; |
|
71 | + $this->font_max_size = 18; |
|
72 | + $this->font_color = '#4D6DF3'; |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | /** |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @return int |
79 | 79 | */ |
80 | 80 | public function getExpireOffset() { |
81 | - return $this->expire_offset; |
|
81 | + return $this->expire_offset; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | /** |
@@ -88,8 +88,8 @@ discard block |
||
88 | 88 | * @return ImageBuilder |
89 | 89 | */ |
90 | 90 | public function setExpireOffset($expireOffset) { |
91 | - if($expireOffset) $this->expire_offset = $expireOffset; |
|
92 | - return $this; |
|
91 | + if($expireOffset) $this->expire_offset = $expireOffset; |
|
92 | + return $this; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | /** |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | * @return bool |
99 | 99 | */ |
100 | 100 | public function isShowWatermark() { |
101 | - return $this->show_watermark; |
|
101 | + return $this->show_watermark; |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | * @return ImageBuilder |
109 | 109 | */ |
110 | 110 | public function setShowWatermark($show_watermark) { |
111 | - if(!is_null($show_watermark)) $this->show_watermark = $show_watermark; |
|
112 | - return $this; |
|
111 | + if(!is_null($show_watermark)) $this->show_watermark = $show_watermark; |
|
112 | + return $this; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | * @return ImageBuilder |
120 | 120 | */ |
121 | 121 | public function setFontMaxSize($font_max_size) { |
122 | - if($font_max_size) $this->font_max_size = $font_max_size; |
|
123 | - return $this; |
|
122 | + if($font_max_size) $this->font_max_size = $font_max_size; |
|
123 | + return $this; |
|
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
@@ -130,8 +130,8 @@ discard block |
||
130 | 130 | * @return ImageBuilder |
131 | 131 | */ |
132 | 132 | public function setFontColor($font_color) { |
133 | - if($font_color) $this->font_color = $font_color; |
|
134 | - return $this; |
|
133 | + if($font_color) $this->font_color = $font_color; |
|
134 | + return $this; |
|
135 | 135 | } |
136 | 136 | |
137 | 137 | /** |
@@ -139,134 +139,134 @@ discard block |
||
139 | 139 | */ |
140 | 140 | public function render(){ |
141 | 141 | |
142 | - if (!$this->media || !$this->media->canShow()) { |
|
143 | - Log::addMediaLog('Image Builder error: >' . I18N::translate('Missing or private media object.')); |
|
144 | - $this->renderError(); |
|
145 | - } |
|
142 | + if (!$this->media || !$this->media->canShow()) { |
|
143 | + Log::addMediaLog('Image Builder error: >' . I18N::translate('Missing or private media object.')); |
|
144 | + $this->renderError(); |
|
145 | + } |
|
146 | 146 | |
147 | - $serverFilename = $this->media->getServerFilename(); |
|
147 | + $serverFilename = $this->media->getServerFilename(); |
|
148 | 148 | |
149 | - if (!file_exists($serverFilename)) { |
|
150 | - Log::addMediaLog('Image Builder error: >'. I18N::translate('The media object does not exist.').'< for path >'.$serverFilename.'<'); |
|
151 | - $this->renderError(); |
|
152 | - } |
|
149 | + if (!file_exists($serverFilename)) { |
|
150 | + Log::addMediaLog('Image Builder error: >'. I18N::translate('The media object does not exist.').'< for path >'.$serverFilename.'<'); |
|
151 | + $this->renderError(); |
|
152 | + } |
|
153 | 153 | |
154 | - $mimetype = $this->media->mimeType(); |
|
155 | - $imgsize = $this->media->getImageAttributes(); |
|
156 | - $filetime = $this->media->getFiletime(); |
|
157 | - $filetimeHeader = gmdate('D, d M Y H:i:s', $filetime) . ' GMT'; |
|
158 | - $expireHeader = gmdate('D, d M Y H:i:s', WT_TIMESTAMP + $this->getExpireOffset()) . ' GMT'; |
|
154 | + $mimetype = $this->media->mimeType(); |
|
155 | + $imgsize = $this->media->getImageAttributes(); |
|
156 | + $filetime = $this->media->getFiletime(); |
|
157 | + $filetimeHeader = gmdate('D, d M Y H:i:s', $filetime) . ' GMT'; |
|
158 | + $expireHeader = gmdate('D, d M Y H:i:s', WT_TIMESTAMP + $this->getExpireOffset()) . ' GMT'; |
|
159 | 159 | |
160 | - $type = Functions::isImageTypeSupported($imgsize['ext']); |
|
161 | - $usewatermark = false; |
|
162 | - // if this image supports watermarks and the watermark module is intalled... |
|
163 | - if ($type) { |
|
164 | - $usewatermark = $this->isShowWatermark(); |
|
165 | - } |
|
160 | + $type = Functions::isImageTypeSupported($imgsize['ext']); |
|
161 | + $usewatermark = false; |
|
162 | + // if this image supports watermarks and the watermark module is intalled... |
|
163 | + if ($type) { |
|
164 | + $usewatermark = $this->isShowWatermark(); |
|
165 | + } |
|
166 | 166 | |
167 | - // determine whether we have enough memory to watermark this image |
|
168 | - if ($usewatermark) { |
|
169 | - if (!FunctionsMedia::hasMemoryForImage($serverFilename)) { |
|
170 | - // not enough memory to watermark this file |
|
171 | - $usewatermark = false; |
|
172 | - } |
|
173 | - } |
|
167 | + // determine whether we have enough memory to watermark this image |
|
168 | + if ($usewatermark) { |
|
169 | + if (!FunctionsMedia::hasMemoryForImage($serverFilename)) { |
|
170 | + // not enough memory to watermark this file |
|
171 | + $usewatermark = false; |
|
172 | + } |
|
173 | + } |
|
174 | 174 | |
175 | - $etag = $this->media->getEtag(); |
|
175 | + $etag = $this->media->getEtag(); |
|
176 | 176 | |
177 | - // parse IF_MODIFIED_SINCE header from client |
|
178 | - $if_modified_since = 'x'; |
|
179 | - if (!empty(Filter::server('HTTP_IF_MODIFIED_SINCE'))) { |
|
180 | - $if_modified_since = preg_replace('/;.*$/', '', Filter::server('HTTP_IF_MODIFIED_SINCE')); |
|
181 | - } |
|
177 | + // parse IF_MODIFIED_SINCE header from client |
|
178 | + $if_modified_since = 'x'; |
|
179 | + if (!empty(Filter::server('HTTP_IF_MODIFIED_SINCE'))) { |
|
180 | + $if_modified_since = preg_replace('/;.*$/', '', Filter::server('HTTP_IF_MODIFIED_SINCE')); |
|
181 | + } |
|
182 | 182 | |
183 | - // parse IF_NONE_MATCH header from client |
|
184 | - $if_none_match = 'x'; |
|
185 | - if (!empty(Filter::server('HTTP_IF_NONE_MATCH'))) { |
|
186 | - $if_none_match = str_replace('"', '', Filter::server('HTTP_IF_NONE_MATCH')); |
|
187 | - } |
|
183 | + // parse IF_NONE_MATCH header from client |
|
184 | + $if_none_match = 'x'; |
|
185 | + if (!empty(Filter::server('HTTP_IF_NONE_MATCH'))) { |
|
186 | + $if_none_match = str_replace('"', '', Filter::server('HTTP_IF_NONE_MATCH')); |
|
187 | + } |
|
188 | 188 | |
189 | - // add caching headers. allow browser to cache file, but not proxy |
|
190 | - header('Last-Modified: ' . $filetimeHeader); |
|
191 | - header('ETag: "' . $etag . '"'); |
|
192 | - header('Expires: ' . $expireHeader); |
|
193 | - header('Cache-Control: max-age=' . $this->getExpireOffset() . ', s-maxage=0, proxy-revalidate'); |
|
189 | + // add caching headers. allow browser to cache file, but not proxy |
|
190 | + header('Last-Modified: ' . $filetimeHeader); |
|
191 | + header('ETag: "' . $etag . '"'); |
|
192 | + header('Expires: ' . $expireHeader); |
|
193 | + header('Cache-Control: max-age=' . $this->getExpireOffset() . ', s-maxage=0, proxy-revalidate'); |
|
194 | 194 | |
195 | - // if this file is already in the user’s cache, don’t resend it |
|
196 | - // first check if the if_modified_since param matches |
|
197 | - if ($if_modified_since === $filetimeHeader) { |
|
198 | - // then check if the etag matches |
|
199 | - if ($if_none_match === $etag) { |
|
200 | - http_response_code(304); |
|
195 | + // if this file is already in the user’s cache, don’t resend it |
|
196 | + // first check if the if_modified_since param matches |
|
197 | + if ($if_modified_since === $filetimeHeader) { |
|
198 | + // then check if the etag matches |
|
199 | + if ($if_none_match === $etag) { |
|
200 | + http_response_code(304); |
|
201 | 201 | |
202 | - return; |
|
203 | - } |
|
204 | - } |
|
202 | + return; |
|
203 | + } |
|
204 | + } |
|
205 | 205 | |
206 | - // send headers for the image |
|
207 | - header('Content-Type: ' . $mimetype); |
|
208 | - header('Content-Disposition: filename="' . addslashes(basename($this->media->getFilename())) . '"'); |
|
206 | + // send headers for the image |
|
207 | + header('Content-Type: ' . $mimetype); |
|
208 | + header('Content-Disposition: filename="' . addslashes(basename($this->media->getFilename())) . '"'); |
|
209 | 209 | |
210 | - if ($usewatermark) { |
|
211 | - // generate the watermarked image |
|
212 | - $imCreateFunc = 'imagecreatefrom' . $type; |
|
213 | - $imSendFunc = 'image' . $type; |
|
210 | + if ($usewatermark) { |
|
211 | + // generate the watermarked image |
|
212 | + $imCreateFunc = 'imagecreatefrom' . $type; |
|
213 | + $imSendFunc = 'image' . $type; |
|
214 | 214 | |
215 | - if (function_exists($imCreateFunc) && function_exists($imSendFunc)) { |
|
216 | - $im = $imCreateFunc($serverFilename); |
|
217 | - $im = $this->applyWatermark($im); |
|
215 | + if (function_exists($imCreateFunc) && function_exists($imSendFunc)) { |
|
216 | + $im = $imCreateFunc($serverFilename); |
|
217 | + $im = $this->applyWatermark($im); |
|
218 | 218 | |
219 | - // send the image |
|
220 | - $imSendFunc($im); |
|
221 | - imagedestroy($im); |
|
219 | + // send the image |
|
220 | + $imSendFunc($im); |
|
221 | + imagedestroy($im); |
|
222 | 222 | |
223 | - return; |
|
224 | - } else { |
|
225 | - // this image is defective. log it |
|
226 | - Log::addMediaLog('Image Builder error: >' . I18N::translate('This media file is broken and cannot be watermarked.') . '< in file >' . $serverFilename . '< memory used: ' . memory_get_usage()); |
|
227 | - } |
|
228 | - } |
|
223 | + return; |
|
224 | + } else { |
|
225 | + // this image is defective. log it |
|
226 | + Log::addMediaLog('Image Builder error: >' . I18N::translate('This media file is broken and cannot be watermarked.') . '< in file >' . $serverFilename . '< memory used: ' . memory_get_usage()); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | - // determine filesize of image (could be original or watermarked version) |
|
231 | - $filesize = filesize($serverFilename); |
|
230 | + // determine filesize of image (could be original or watermarked version) |
|
231 | + $filesize = filesize($serverFilename); |
|
232 | 232 | |
233 | - // set content-length header, send file |
|
234 | - header('Content-Length: ' . $filesize); |
|
233 | + // set content-length header, send file |
|
234 | + header('Content-Length: ' . $filesize); |
|
235 | 235 | |
236 | - // Some servers disable fpassthru() and readfile() |
|
237 | - if (function_exists('readfile')) { |
|
238 | - readfile($serverFilename); |
|
239 | - } else { |
|
240 | - $fp = fopen($serverFilename, 'rb'); |
|
241 | - if (function_exists('fpassthru')) { |
|
242 | - fpassthru($fp); |
|
243 | - } else { |
|
244 | - while (!feof($fp)) { |
|
245 | - echo fread($fp, 65536); |
|
246 | - } |
|
247 | - } |
|
248 | - fclose($fp); |
|
249 | - } |
|
236 | + // Some servers disable fpassthru() and readfile() |
|
237 | + if (function_exists('readfile')) { |
|
238 | + readfile($serverFilename); |
|
239 | + } else { |
|
240 | + $fp = fopen($serverFilename, 'rb'); |
|
241 | + if (function_exists('fpassthru')) { |
|
242 | + fpassthru($fp); |
|
243 | + } else { |
|
244 | + while (!feof($fp)) { |
|
245 | + echo fread($fp, 65536); |
|
246 | + } |
|
247 | + } |
|
248 | + fclose($fp); |
|
249 | + } |
|
250 | 250 | } |
251 | 251 | |
252 | 252 | /** |
253 | 253 | * Render an error as an image. |
254 | 254 | */ |
255 | 255 | protected function renderError() { |
256 | - $error = I18N::translate('The media file was not found in this family tree.'); |
|
256 | + $error = I18N::translate('The media file was not found in this family tree.'); |
|
257 | 257 | |
258 | - $width = (mb_strlen($error) * 6.5 + 50) * 1.15; |
|
259 | - $height = 60; |
|
260 | - $im = imagecreatetruecolor($width, $height); /* Create a black image */ |
|
261 | - $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ |
|
262 | - imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ |
|
258 | + $width = (mb_strlen($error) * 6.5 + 50) * 1.15; |
|
259 | + $height = 60; |
|
260 | + $im = imagecreatetruecolor($width, $height); /* Create a black image */ |
|
261 | + $bgc = imagecolorallocate($im, 255, 255, 255); /* set background color */ |
|
262 | + imagefilledrectangle($im, 2, 2, $width - 4, $height - 4, $bgc); /* create a rectangle, leaving 2 px border */ |
|
263 | 263 | |
264 | - $this->embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left'); |
|
264 | + $this->embedText($im, $error, 100, '255, 0, 0', WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, 'top', 'left'); |
|
265 | 265 | |
266 | - http_response_code(404); |
|
267 | - header('Content-Type: image/png'); |
|
268 | - imagepng($im); |
|
269 | - imagedestroy($im); |
|
266 | + http_response_code(404); |
|
267 | + header('Content-Type: image/png'); |
|
268 | + imagepng($im); |
|
269 | + imagedestroy($im); |
|
270 | 270 | } |
271 | 271 | |
272 | 272 | /** |
@@ -278,25 +278,25 @@ discard block |
||
278 | 278 | */ |
279 | 279 | protected function applyWatermark($im) { |
280 | 280 | |
281 | - // text to watermark with |
|
282 | - if(method_exists($this->media, 'getWatermarkText')) { |
|
283 | - $word1_text = $this->media->getWatermarkText(); |
|
284 | - } |
|
285 | - else { |
|
286 | - $word1_text = $this->media->getTitle(); |
|
287 | - } |
|
281 | + // text to watermark with |
|
282 | + if(method_exists($this->media, 'getWatermarkText')) { |
|
283 | + $word1_text = $this->media->getWatermarkText(); |
|
284 | + } |
|
285 | + else { |
|
286 | + $word1_text = $this->media->getTitle(); |
|
287 | + } |
|
288 | 288 | |
289 | - $this->embedText( |
|
290 | - $im, |
|
291 | - $word1_text, |
|
292 | - $this->font_max_size, |
|
293 | - $this->font_color, |
|
294 | - WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, |
|
295 | - 'top', |
|
296 | - 'left' |
|
297 | - ); |
|
289 | + $this->embedText( |
|
290 | + $im, |
|
291 | + $word1_text, |
|
292 | + $this->font_max_size, |
|
293 | + $this->font_color, |
|
294 | + WT_ROOT . Config::FONT_DEJAVU_SANS_TTF, |
|
295 | + 'top', |
|
296 | + 'left' |
|
297 | + ); |
|
298 | 298 | |
299 | - return ($im); |
|
299 | + return ($im); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | /** |
@@ -313,94 +313,94 @@ discard block |
||
313 | 313 | */ |
314 | 314 | protected function embedText($im, $text, $maxsize, $color, $font, $vpos, $hpos) { |
315 | 315 | |
316 | - // there are two ways to embed text with PHP |
|
317 | - // (preferred) using GD and FreeType you can embed text using any True Type font |
|
318 | - // (fall back) if that is not available, you can insert basic monospaced text |
|
316 | + // there are two ways to embed text with PHP |
|
317 | + // (preferred) using GD and FreeType you can embed text using any True Type font |
|
318 | + // (fall back) if that is not available, you can insert basic monospaced text |
|
319 | 319 | |
320 | - $col = $this->hexrgb($color); |
|
321 | - $textcolor = imagecolorallocate($im, $col['red'], $col['green'], $col['blue']); |
|
320 | + $col = $this->hexrgb($color); |
|
321 | + $textcolor = imagecolorallocate($im, $col['red'], $col['green'], $col['blue']); |
|
322 | 322 | |
323 | - // make adjustments to settings that imagestring and imagestringup can’t handle |
|
324 | - if (!$this->use_ttf) { |
|
325 | - // imagestringup only writes up, can’t use top2bottom |
|
326 | - if ($hpos === 'top2bottom') { |
|
327 | - $hpos = 'bottom2top'; |
|
328 | - } |
|
329 | - } |
|
323 | + // make adjustments to settings that imagestring and imagestringup can’t handle |
|
324 | + if (!$this->use_ttf) { |
|
325 | + // imagestringup only writes up, can’t use top2bottom |
|
326 | + if ($hpos === 'top2bottom') { |
|
327 | + $hpos = 'bottom2top'; |
|
328 | + } |
|
329 | + } |
|
330 | 330 | |
331 | - $text = I18N::reverseText($text); |
|
332 | - $height = imagesy($im); |
|
333 | - $width = imagesx($im); |
|
334 | - $calc_angle = rad2deg(atan($height / $width)); |
|
335 | - $hypoth = $height / sin(deg2rad($calc_angle)); |
|
331 | + $text = I18N::reverseText($text); |
|
332 | + $height = imagesy($im); |
|
333 | + $width = imagesx($im); |
|
334 | + $calc_angle = rad2deg(atan($height / $width)); |
|
335 | + $hypoth = $height / sin(deg2rad($calc_angle)); |
|
336 | 336 | |
337 | - // vertical and horizontal position of the text |
|
338 | - switch ($vpos) { |
|
339 | - default: |
|
340 | - case 'top': |
|
341 | - $taille = $this->textLength($maxsize, $width, $text); |
|
342 | - $pos_y = $height * 0.15 + $taille; |
|
343 | - $pos_x = $width * 0.15; |
|
344 | - $rotation = 0; |
|
345 | - break; |
|
346 | - case 'middle': |
|
347 | - $taille = $this->textLength($maxsize, $width, $text); |
|
348 | - $pos_y = ($height + $taille) / 2; |
|
349 | - $pos_x = $width * 0.15; |
|
350 | - $rotation = 0; |
|
351 | - break; |
|
352 | - case 'bottom': |
|
353 | - $taille = $this->textLength($maxsize, $width, $text); |
|
354 | - $pos_y = ($height * .85 - $taille); |
|
355 | - $pos_x = $width * 0.15; |
|
356 | - $rotation = 0; |
|
357 | - break; |
|
358 | - case 'across': |
|
359 | - switch ($hpos) { |
|
360 | - default: |
|
361 | - case 'left': |
|
362 | - $taille = $this->textLength($maxsize, $hypoth, $text); |
|
363 | - $pos_y = ($height * .85 - $taille); |
|
364 | - $pos_x = $width * 0.15; |
|
365 | - $rotation = $calc_angle; |
|
366 | - break; |
|
367 | - case 'right': |
|
368 | - $taille = $this->textLength($maxsize, $hypoth, $text); |
|
369 | - $pos_y = ($height * .15 - $taille); |
|
370 | - $pos_x = $width * 0.85; |
|
371 | - $rotation = $calc_angle + 180; |
|
372 | - break; |
|
373 | - case 'top2bottom': |
|
374 | - $taille = $this->textLength($maxsize, $height, $text); |
|
375 | - $pos_y = ($height * .15 - $taille); |
|
376 | - $pos_x = ($width * .90 - $taille); |
|
377 | - $rotation = -90; |
|
378 | - break; |
|
379 | - case 'bottom2top': |
|
380 | - $taille = $this->textLength($maxsize, $height, $text); |
|
381 | - $pos_y = $height * 0.85; |
|
382 | - $pos_x = $width * 0.15; |
|
383 | - $rotation = 90; |
|
384 | - break; |
|
385 | - } |
|
386 | - break; |
|
387 | - } |
|
337 | + // vertical and horizontal position of the text |
|
338 | + switch ($vpos) { |
|
339 | + default: |
|
340 | + case 'top': |
|
341 | + $taille = $this->textLength($maxsize, $width, $text); |
|
342 | + $pos_y = $height * 0.15 + $taille; |
|
343 | + $pos_x = $width * 0.15; |
|
344 | + $rotation = 0; |
|
345 | + break; |
|
346 | + case 'middle': |
|
347 | + $taille = $this->textLength($maxsize, $width, $text); |
|
348 | + $pos_y = ($height + $taille) / 2; |
|
349 | + $pos_x = $width * 0.15; |
|
350 | + $rotation = 0; |
|
351 | + break; |
|
352 | + case 'bottom': |
|
353 | + $taille = $this->textLength($maxsize, $width, $text); |
|
354 | + $pos_y = ($height * .85 - $taille); |
|
355 | + $pos_x = $width * 0.15; |
|
356 | + $rotation = 0; |
|
357 | + break; |
|
358 | + case 'across': |
|
359 | + switch ($hpos) { |
|
360 | + default: |
|
361 | + case 'left': |
|
362 | + $taille = $this->textLength($maxsize, $hypoth, $text); |
|
363 | + $pos_y = ($height * .85 - $taille); |
|
364 | + $pos_x = $width * 0.15; |
|
365 | + $rotation = $calc_angle; |
|
366 | + break; |
|
367 | + case 'right': |
|
368 | + $taille = $this->textLength($maxsize, $hypoth, $text); |
|
369 | + $pos_y = ($height * .15 - $taille); |
|
370 | + $pos_x = $width * 0.85; |
|
371 | + $rotation = $calc_angle + 180; |
|
372 | + break; |
|
373 | + case 'top2bottom': |
|
374 | + $taille = $this->textLength($maxsize, $height, $text); |
|
375 | + $pos_y = ($height * .15 - $taille); |
|
376 | + $pos_x = ($width * .90 - $taille); |
|
377 | + $rotation = -90; |
|
378 | + break; |
|
379 | + case 'bottom2top': |
|
380 | + $taille = $this->textLength($maxsize, $height, $text); |
|
381 | + $pos_y = $height * 0.85; |
|
382 | + $pos_x = $width * 0.15; |
|
383 | + $rotation = 90; |
|
384 | + break; |
|
385 | + } |
|
386 | + break; |
|
387 | + } |
|
388 | 388 | |
389 | - // apply the text |
|
390 | - if ($this->use_ttf) { |
|
391 | - // if imagettftext throws errors, catch them with a custom error handler |
|
392 | - set_error_handler(array($this, 'imageTtfTextErrorHandler')); |
|
393 | - imagettftext($im, $taille, $rotation, $pos_x, $pos_y, $textcolor, $font, $text); |
|
394 | - restore_error_handler(); |
|
395 | - } |
|
396 | - // Don’t use an ‘else’ here since imagettftextErrorHandler may have changed the value of $useTTF from true to false |
|
397 | - if (!$this->use_ttf) { |
|
398 | - if ($rotation !== 90) { |
|
399 | - imagestring($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
400 | - } else { |
|
401 | - imagestringup($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
402 | - } |
|
403 | - } |
|
389 | + // apply the text |
|
390 | + if ($this->use_ttf) { |
|
391 | + // if imagettftext throws errors, catch them with a custom error handler |
|
392 | + set_error_handler(array($this, 'imageTtfTextErrorHandler')); |
|
393 | + imagettftext($im, $taille, $rotation, $pos_x, $pos_y, $textcolor, $font, $text); |
|
394 | + restore_error_handler(); |
|
395 | + } |
|
396 | + // Don’t use an ‘else’ here since imagettftextErrorHandler may have changed the value of $useTTF from true to false |
|
397 | + if (!$this->use_ttf) { |
|
398 | + if ($rotation !== 90) { |
|
399 | + imagestring($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
400 | + } else { |
|
401 | + imagestringup($im, 5, $pos_x, $pos_y, $text, $textcolor); |
|
402 | + } |
|
403 | + } |
|
404 | 404 | |
405 | 405 | } |
406 | 406 | |
@@ -412,53 +412,53 @@ discard block |
||
412 | 412 | */ |
413 | 413 | protected function hexrgb ($hexstr) |
414 | 414 | { |
415 | - $int = hexdec($hexstr); |
|
415 | + $int = hexdec($hexstr); |
|
416 | 416 | |
417 | - return array('red' => 0xFF & ($int >> 0x10), |
|
418 | - 'green' => 0xFF & ($int >> 0x8), |
|
419 | - 'blue' => 0xFF & $int); |
|
417 | + return array('red' => 0xFF & ($int >> 0x10), |
|
418 | + 'green' => 0xFF & ($int >> 0x8), |
|
419 | + 'blue' => 0xFF & $int); |
|
420 | 420 | } |
421 | 421 | |
422 | - /** |
|
423 | - * Generate an approximate length of text, in pixels. |
|
424 | - * |
|
425 | - * @param int $t |
|
426 | - * @param int $mxl |
|
427 | - * @param string $text |
|
428 | - * |
|
429 | - * @return int |
|
430 | - */ |
|
431 | - function textLength($t, $mxl, $text) { |
|
432 | - $taille_c = $t; |
|
433 | - $len = mb_strlen($text); |
|
434 | - while (($taille_c - 2) * $len > $mxl) { |
|
435 | - $taille_c--; |
|
436 | - if ($taille_c == 2) { |
|
437 | - break; |
|
438 | - } |
|
439 | - } |
|
422 | + /** |
|
423 | + * Generate an approximate length of text, in pixels. |
|
424 | + * |
|
425 | + * @param int $t |
|
426 | + * @param int $mxl |
|
427 | + * @param string $text |
|
428 | + * |
|
429 | + * @return int |
|
430 | + */ |
|
431 | + function textLength($t, $mxl, $text) { |
|
432 | + $taille_c = $t; |
|
433 | + $len = mb_strlen($text); |
|
434 | + while (($taille_c - 2) * $len > $mxl) { |
|
435 | + $taille_c--; |
|
436 | + if ($taille_c == 2) { |
|
437 | + break; |
|
438 | + } |
|
439 | + } |
|
440 | 440 | |
441 | - return $taille_c; |
|
442 | - } |
|
441 | + return $taille_c; |
|
442 | + } |
|
443 | 443 | |
444 | - /** |
|
445 | - * imagettftext is the function that is most likely to throw an error |
|
446 | - * use this custom error handler to catch and log it |
|
447 | - * |
|
448 | - * @param int $errno |
|
449 | - * @param string $errstr |
|
450 | - * |
|
451 | - * @return bool |
|
452 | - */ |
|
453 | - function imageTtfTextErrorHandler($errno, $errstr) { |
|
454 | - // log the error |
|
455 | - Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<'); |
|
444 | + /** |
|
445 | + * imagettftext is the function that is most likely to throw an error |
|
446 | + * use this custom error handler to catch and log it |
|
447 | + * |
|
448 | + * @param int $errno |
|
449 | + * @param string $errstr |
|
450 | + * |
|
451 | + * @return bool |
|
452 | + */ |
|
453 | + function imageTtfTextErrorHandler($errno, $errstr) { |
|
454 | + // log the error |
|
455 | + Log::addErrorLog('Image Builder error: >' . $errno . '/' . $errstr . '< while processing file >' . $this->media->getServerFilename() . '<'); |
|
456 | 456 | |
457 | - // change value of useTTF to false so the fallback watermarking can be used. |
|
458 | - $this->use_ttf = false; |
|
457 | + // change value of useTTF to false so the fallback watermarking can be used. |
|
458 | + $this->use_ttf = false; |
|
459 | 459 | |
460 | - return true; |
|
461 | - } |
|
460 | + return true; |
|
461 | + } |
|
462 | 462 | |
463 | 463 | } |
464 | 464 |
@@ -18,35 +18,35 @@ discard block |
||
18 | 18 | */ |
19 | 19 | class Dispatcher implements DispatcherInterface { |
20 | 20 | |
21 | - /** |
|
22 | - * @var Dispatcher $instance Singleton pattern instance |
|
23 | - */ |
|
24 | - private static $instance = null; |
|
21 | + /** |
|
22 | + * @var Dispatcher $instance Singleton pattern instance |
|
23 | + */ |
|
24 | + private static $instance = null; |
|
25 | 25 | |
26 | - /** |
|
27 | - * Returns the *Dispatcher* instance of this class. |
|
28 | - * |
|
29 | - * @return Dispatcher The *Singleton* instance. |
|
30 | - */ |
|
31 | - public static function getInstance() |
|
32 | - { |
|
33 | - if (null === static::$instance) { |
|
34 | - static::$instance = new static(); |
|
35 | - } |
|
26 | + /** |
|
27 | + * Returns the *Dispatcher* instance of this class. |
|
28 | + * |
|
29 | + * @return Dispatcher The *Singleton* instance. |
|
30 | + */ |
|
31 | + public static function getInstance() |
|
32 | + { |
|
33 | + if (null === static::$instance) { |
|
34 | + static::$instance = new static(); |
|
35 | + } |
|
36 | 36 | |
37 | - return static::$instance; |
|
38 | - } |
|
37 | + return static::$instance; |
|
38 | + } |
|
39 | 39 | |
40 | 40 | /** |
41 | - * Protected constructor. |
|
42 | - */ |
|
43 | - protected function __construct() {} |
|
41 | + * Protected constructor. |
|
42 | + */ |
|
43 | + protected function __construct() {} |
|
44 | 44 | |
45 | - /** |
|
46 | - * {@inheritdoc } |
|
47 | - * @see \MyArtJaub\Webtrees\Mvc\DispatcherInterface::handle() |
|
48 | - */ |
|
49 | - public function handle(fw\Module\AbstractModule $module, $request) { |
|
45 | + /** |
|
46 | + * {@inheritdoc } |
|
47 | + * @see \MyArtJaub\Webtrees\Mvc\DispatcherInterface::handle() |
|
48 | + */ |
|
49 | + public function handle(fw\Module\AbstractModule $module, $request) { |
|
50 | 50 | |
51 | 51 | $fq_modclass_name = get_class($module); |
52 | 52 | $ctrl_namespace = substr($fq_modclass_name, 0, - strlen('Module')) . '\\'; |
@@ -66,18 +66,18 @@ discard block |
||
66 | 66 | |
67 | 67 | $ctrl_class = $ctrl_namespace . $ctrl_name . 'Controller'; |
68 | 68 | if(class_exists($ctrl_class) |
69 | - && is_subclass_of($ctrl_class, '\\MyArtJaub\\Webtrees\\Mvc\\Controller\\MvcController') |
|
69 | + && is_subclass_of($ctrl_class, '\\MyArtJaub\\Webtrees\\Mvc\\Controller\\MvcController') |
|
70 | 70 | && $ctrl = new $ctrl_class($module) ) { |
71 | 71 | if(method_exists($ctrl, $method)) { |
72 | - try { |
|
73 | - call_user_func_array(array($ctrl, $method), array()); |
|
74 | - } |
|
75 | - catch (MvcException $ex) { |
|
76 | - if(!headers_sent()) { |
|
77 | - http_response_code($ex->getHttpCode()); |
|
78 | - } |
|
79 | - echo $ex->getMessage(); |
|
80 | - } |
|
72 | + try { |
|
73 | + call_user_func_array(array($ctrl, $method), array()); |
|
74 | + } |
|
75 | + catch (MvcException $ex) { |
|
76 | + if(!headers_sent()) { |
|
77 | + http_response_code($ex->getHttpCode()); |
|
78 | + } |
|
79 | + echo $ex->getMessage(); |
|
80 | + } |
|
81 | 81 | } |
82 | 82 | else { |
83 | 83 | throw new \Exception('The page requested does not exist'); |
@@ -86,27 +86,27 @@ discard block |
||
86 | 86 | else { |
87 | 87 | throw new \Exception('The page requested does not exist'); |
88 | 88 | } |
89 | - } |
|
89 | + } |
|
90 | 90 | |
91 | - /** |
|
92 | - * Private clone method to prevent cloning of the instance of the |
|
93 | - * *Dispatcher* instance. |
|
94 | - * |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - private function __clone() |
|
98 | - { |
|
99 | - } |
|
91 | + /** |
|
92 | + * Private clone method to prevent cloning of the instance of the |
|
93 | + * *Dispatcher* instance. |
|
94 | + * |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + private function __clone() |
|
98 | + { |
|
99 | + } |
|
100 | 100 | |
101 | - /** |
|
102 | - * Private unserialize method to prevent unserializing of the *Dispatcher* |
|
103 | - * instance. |
|
104 | - * |
|
105 | - * @return void |
|
106 | - */ |
|
107 | - private function __wakeup() |
|
108 | - { |
|
109 | - } |
|
101 | + /** |
|
102 | + * Private unserialize method to prevent unserializing of the *Dispatcher* |
|
103 | + * instance. |
|
104 | + * |
|
105 | + * @return void |
|
106 | + */ |
|
107 | + private function __wakeup() |
|
108 | + { |
|
109 | + } |
|
110 | 110 | |
111 | 111 | } |
112 | 112 |
@@ -16,52 +16,52 @@ |
||
16 | 16 | */ |
17 | 17 | class MvcException extends \Exception { |
18 | 18 | |
19 | - /** @var int[] $VALID_HTTP List of valid HTTP codes */ |
|
20 | - protected static $VALID_HTTP = array( |
|
21 | - 100, 101, |
|
22 | - 200, 201, 202, 203, 204, 205, 206, |
|
23 | - 300, 301, 302, 303, 304, 305, 306, 307, |
|
24 | - 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, |
|
25 | - 500, 501, 502, 503, 504, 505 |
|
26 | - ); |
|
19 | + /** @var int[] $VALID_HTTP List of valid HTTP codes */ |
|
20 | + protected static $VALID_HTTP = array( |
|
21 | + 100, 101, |
|
22 | + 200, 201, 202, 203, 204, 205, 206, |
|
23 | + 300, 301, 302, 303, 304, 305, 306, 307, |
|
24 | + 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, |
|
25 | + 500, 501, 502, 503, 504, 505 |
|
26 | + ); |
|
27 | 27 | |
28 | - /** @var int $http_code */ |
|
29 | - protected $http_code; |
|
28 | + /** @var int $http_code */ |
|
29 | + protected $http_code; |
|
30 | 30 | |
31 | - /** |
|
32 | - * Constructor for MvcException |
|
33 | - * |
|
34 | - * @param int $http_code |
|
35 | - * @param string $message |
|
36 | - * @param int $code |
|
37 | - * @param \Throwable $previous |
|
38 | - */ |
|
39 | - public function __construct($http_code = 500, $message = "", $code = 0, \Throwable $previous = null) { |
|
40 | - parent::__construct($message, $code, $previous); |
|
31 | + /** |
|
32 | + * Constructor for MvcException |
|
33 | + * |
|
34 | + * @param int $http_code |
|
35 | + * @param string $message |
|
36 | + * @param int $code |
|
37 | + * @param \Throwable $previous |
|
38 | + */ |
|
39 | + public function __construct($http_code = 500, $message = "", $code = 0, \Throwable $previous = null) { |
|
40 | + parent::__construct($message, $code, $previous); |
|
41 | 41 | |
42 | - $this->http_code = in_array($http_code, self::$VALID_HTTP) ? $http_code : 500; |
|
43 | - } |
|
42 | + $this->http_code = in_array($http_code, self::$VALID_HTTP) ? $http_code : 500; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * Get the HTTP code |
|
47 | - * |
|
48 | - * @return int |
|
49 | - */ |
|
50 | - public function getHttpCode() { |
|
51 | - return $this->http_code; |
|
52 | - } |
|
45 | + /** |
|
46 | + * Get the HTTP code |
|
47 | + * |
|
48 | + * @return int |
|
49 | + */ |
|
50 | + public function getHttpCode() { |
|
51 | + return $this->http_code; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Set the HTTP code |
|
56 | - * |
|
57 | - * @param int $http_code |
|
58 | - * @throws InvalidArgumentException Thrown if not valid Http code |
|
59 | - */ |
|
60 | - public function setHttpCode($http_code) { |
|
61 | - if(!in_array($http_code, self::$VALID_HTTP)) |
|
62 | - throw new \InvalidArgumentException('Invalid HTTP code'); |
|
63 | - $this->http_code= $http_code; |
|
64 | - } |
|
54 | + /** |
|
55 | + * Set the HTTP code |
|
56 | + * |
|
57 | + * @param int $http_code |
|
58 | + * @throws InvalidArgumentException Thrown if not valid Http code |
|
59 | + */ |
|
60 | + public function setHttpCode($http_code) { |
|
61 | + if(!in_array($http_code, self::$VALID_HTTP)) |
|
62 | + throw new \InvalidArgumentException('Invalid HTTP code'); |
|
63 | + $this->http_code= $http_code; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | } |
67 | 67 |
@@ -19,59 +19,59 @@ |
||
19 | 19 | * Hooks Module. |
20 | 20 | */ |
21 | 21 | class HooksModule extends AbstractModule implements ModuleConfigInterface, DependentInterface { |
22 | - // How to update the database schema for this module |
|
23 | - const SCHEMA_TARGET_VERSION = 1; |
|
24 | - const SCHEMA_SETTING_NAME = 'MAJ_HOOKS_SCHEMA_VERSION'; |
|
25 | - const SCHEMA_MIGRATION_PREFIX = '\MyArtJaub\Webtrees\Module\Hooks\Schema'; |
|
22 | + // How to update the database schema for this module |
|
23 | + const SCHEMA_TARGET_VERSION = 1; |
|
24 | + const SCHEMA_SETTING_NAME = 'MAJ_HOOKS_SCHEMA_VERSION'; |
|
25 | + const SCHEMA_MIGRATION_PREFIX = '\MyArtJaub\Webtrees\Module\Hooks\Schema'; |
|
26 | 26 | |
27 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
28 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
27 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
28 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
29 | 29 | |
30 | - /** |
|
31 | - * {@inhericDoc} |
|
32 | - */ |
|
33 | - public function getTitle() { |
|
34 | - return /* I18N: Name of the “Hooks” module */ I18N::translate('Hooks'); |
|
35 | - } |
|
30 | + /** |
|
31 | + * {@inhericDoc} |
|
32 | + */ |
|
33 | + public function getTitle() { |
|
34 | + return /* I18N: Name of the “Hooks” module */ I18N::translate('Hooks'); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * {@inhericDoc} |
|
39 | - */ |
|
40 | - public function getDescription() { |
|
41 | - return /* I18N: Description of the “Hooks” module */ I18N::translate('Implements hooks management.'); |
|
42 | - } |
|
37 | + /** |
|
38 | + * {@inhericDoc} |
|
39 | + */ |
|
40 | + public function getDescription() { |
|
41 | + return /* I18N: Description of the “Hooks” module */ I18N::translate('Implements hooks management.'); |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * {@inhericDoc} |
|
46 | - */ |
|
47 | - public function modAction($mod_action) { |
|
48 | - Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
44 | + /** |
|
45 | + * {@inhericDoc} |
|
46 | + */ |
|
47 | + public function modAction($mod_action) { |
|
48 | + Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
49 | 49 | |
50 | - \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
51 | - } |
|
50 | + \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * {@inhericDoc} |
|
55 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
56 | - */ |
|
57 | - public function getConfigLink() { |
|
58 | - Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
53 | + /** |
|
54 | + * {@inhericDoc} |
|
55 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
56 | + */ |
|
57 | + public function getConfigLink() { |
|
58 | + Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
59 | 59 | |
60 | - return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
61 | - } |
|
60 | + return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * {@inheritDoc} |
|
65 | - * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
66 | - */ |
|
67 | - public function validatePrerequisites() { |
|
68 | - try { |
|
69 | - Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
70 | - return true; |
|
71 | - } |
|
72 | - catch (\Exception $ex) { } |
|
73 | - return false; |
|
74 | - } |
|
63 | + /** |
|
64 | + * {@inheritDoc} |
|
65 | + * @see \MyArtJaub\Webtrees\Module\DependentInterface::validatePrerequisites() |
|
66 | + */ |
|
67 | + public function validatePrerequisites() { |
|
68 | + try { |
|
69 | + Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
70 | + return true; |
|
71 | + } |
|
72 | + catch (\Exception $ex) { } |
|
73 | + return false; |
|
74 | + } |
|
75 | 75 | |
76 | 76 | |
77 | 77 | } |
@@ -22,389 +22,389 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class SosaProvider { |
24 | 24 | |
25 | - /** |
|
26 | - * Maximum number of generation the database is able to hold. |
|
27 | - * @var int MAX_DB_GENERATIONS |
|
28 | - */ |
|
29 | - const MAX_DB_GENERATIONS = 64; |
|
30 | - |
|
31 | - /** |
|
32 | - * System's default user (ID -1 in the database |
|
33 | - * @var User $default_user |
|
34 | - */ |
|
35 | - protected static $default_user; |
|
36 | - |
|
37 | - /** |
|
38 | - * Reference user |
|
39 | - * @var User $user |
|
40 | - */ |
|
41 | - protected $user; |
|
42 | - |
|
43 | - /** |
|
44 | - * Reference tree |
|
45 | - * @var Tree $tree |
|
46 | - */ |
|
47 | - protected $tree; |
|
48 | - |
|
49 | - /** |
|
50 | - * Cached list of Sosa Individuals by generation |
|
51 | - * Format: key = generation, value = array ( sosa => Individual ID) |
|
52 | - * @var array $sosa_list_by_gen |
|
53 | - */ |
|
54 | - protected $sosa_list_by_gen; |
|
55 | - |
|
56 | - /** |
|
57 | - * Cached list of Sosa Families by generation |
|
58 | - * Format: key = generation, value = array ( sosa => Family ID) |
|
59 | - * @var unknown $sosa_fam_list_by_gen |
|
60 | - */ |
|
61 | - protected $sosa_fam_list_by_gen; |
|
62 | - |
|
63 | - /** |
|
64 | - * Cached array of statistics by generation |
|
65 | - * Format: key = generation, |
|
66 | - * value = array( |
|
67 | - * sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth |
|
68 | - * ) |
|
69 | - * @var array $statistics_tab |
|
70 | - */ |
|
71 | - protected $statistics_tab; |
|
72 | - |
|
73 | - /** |
|
74 | - * Has the provider's initialisation completed |
|
75 | - * @var bool $is_setup |
|
76 | - */ |
|
77 | - protected $is_setup; |
|
78 | - |
|
79 | - /** |
|
80 | - * Constructor for Sosa Provider. |
|
81 | - * A provider is defined in relation to a specific tree and reference user. |
|
82 | - * |
|
83 | - * @param Tree $tree |
|
84 | - * @param User $user |
|
85 | - */ |
|
86 | - public function __construct(Tree $tree, User $user = null) { |
|
87 | - if(self::$default_user === null) |
|
88 | - self::$default_user = User::find(-1); |
|
25 | + /** |
|
26 | + * Maximum number of generation the database is able to hold. |
|
27 | + * @var int MAX_DB_GENERATIONS |
|
28 | + */ |
|
29 | + const MAX_DB_GENERATIONS = 64; |
|
30 | + |
|
31 | + /** |
|
32 | + * System's default user (ID -1 in the database |
|
33 | + * @var User $default_user |
|
34 | + */ |
|
35 | + protected static $default_user; |
|
36 | + |
|
37 | + /** |
|
38 | + * Reference user |
|
39 | + * @var User $user |
|
40 | + */ |
|
41 | + protected $user; |
|
42 | + |
|
43 | + /** |
|
44 | + * Reference tree |
|
45 | + * @var Tree $tree |
|
46 | + */ |
|
47 | + protected $tree; |
|
48 | + |
|
49 | + /** |
|
50 | + * Cached list of Sosa Individuals by generation |
|
51 | + * Format: key = generation, value = array ( sosa => Individual ID) |
|
52 | + * @var array $sosa_list_by_gen |
|
53 | + */ |
|
54 | + protected $sosa_list_by_gen; |
|
55 | + |
|
56 | + /** |
|
57 | + * Cached list of Sosa Families by generation |
|
58 | + * Format: key = generation, value = array ( sosa => Family ID) |
|
59 | + * @var unknown $sosa_fam_list_by_gen |
|
60 | + */ |
|
61 | + protected $sosa_fam_list_by_gen; |
|
62 | + |
|
63 | + /** |
|
64 | + * Cached array of statistics by generation |
|
65 | + * Format: key = generation, |
|
66 | + * value = array( |
|
67 | + * sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth |
|
68 | + * ) |
|
69 | + * @var array $statistics_tab |
|
70 | + */ |
|
71 | + protected $statistics_tab; |
|
72 | + |
|
73 | + /** |
|
74 | + * Has the provider's initialisation completed |
|
75 | + * @var bool $is_setup |
|
76 | + */ |
|
77 | + protected $is_setup; |
|
78 | + |
|
79 | + /** |
|
80 | + * Constructor for Sosa Provider. |
|
81 | + * A provider is defined in relation to a specific tree and reference user. |
|
82 | + * |
|
83 | + * @param Tree $tree |
|
84 | + * @param User $user |
|
85 | + */ |
|
86 | + public function __construct(Tree $tree, User $user = null) { |
|
87 | + if(self::$default_user === null) |
|
88 | + self::$default_user = User::find(-1); |
|
89 | 89 | |
90 | - $this->tree = $tree; |
|
91 | - $this->user = $user; |
|
92 | - $this->is_setup = true; |
|
93 | - if($this->user === null) $this->user = Auth::user(); |
|
94 | - if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
90 | + $this->tree = $tree; |
|
91 | + $this->user = $user; |
|
92 | + $this->is_setup = true; |
|
93 | + if($this->user === null) $this->user = Auth::user(); |
|
94 | + if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
95 | 95 | |
96 | - // Check if the user, or the default user, has a root already setup; |
|
97 | - if(empty($this->getRootIndiId())) { |
|
98 | - if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | - $this->is_setup = false; |
|
100 | - } |
|
101 | - else { |
|
102 | - $this->user = self::$default_user; |
|
103 | - $this->is_setup = $this->getRootIndiId() === null; |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns is the Provider has been successfully set up |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isSetup() { |
|
113 | - return $this->is_setup; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Return the root individual ID for the reference tree and user. |
|
118 | - * @return string Individual ID |
|
119 | - */ |
|
120 | - public function getRootIndiId() { |
|
121 | - return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Return the root individual for the reference tree and user. |
|
126 | - * @return Individual Individual |
|
127 | - */ |
|
128 | - public function getRootIndi() { |
|
129 | - $root_indi_id = $this->getRootIndiId(); |
|
130 | - if(!empty($root_indi_id)) { |
|
131 | - return Individual::getInstance($root_indi_id, $this->tree); |
|
132 | - } |
|
133 | - return null; |
|
134 | - } |
|
96 | + // Check if the user, or the default user, has a root already setup; |
|
97 | + if(empty($this->getRootIndiId())) { |
|
98 | + if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | + $this->is_setup = false; |
|
100 | + } |
|
101 | + else { |
|
102 | + $this->user = self::$default_user; |
|
103 | + $this->is_setup = $this->getRootIndiId() === null; |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns is the Provider has been successfully set up |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isSetup() { |
|
113 | + return $this->is_setup; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Return the root individual ID for the reference tree and user. |
|
118 | + * @return string Individual ID |
|
119 | + */ |
|
120 | + public function getRootIndiId() { |
|
121 | + return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Return the root individual for the reference tree and user. |
|
126 | + * @return Individual Individual |
|
127 | + */ |
|
128 | + public function getRootIndi() { |
|
129 | + $root_indi_id = $this->getRootIndiId(); |
|
130 | + if(!empty($root_indi_id)) { |
|
131 | + return Individual::getInstance($root_indi_id, $this->tree); |
|
132 | + } |
|
133 | + return null; |
|
134 | + } |
|
135 | 135 | |
136 | - /***************** |
|
136 | + /***************** |
|
137 | 137 | * DATA CRUD LAYER |
138 | 138 | *****************/ |
139 | 139 | |
140 | - /** |
|
141 | - * Remove all Sosa entries related to the gedcom file and user |
|
142 | - */ |
|
143 | - public function deleteAll() { |
|
144 | - if(!$this->is_setup) return; |
|
145 | - Database::prepare( |
|
146 | - 'DELETE FROM `##maj_sosa`'. |
|
147 | - ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
148 | - ->execute(array( |
|
149 | - 'tree_id' => $this->tree->getTreeId(), |
|
150 | - 'user_id' => $this->user->getUserId() |
|
151 | - )); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Remove all ancestors of a sosa number |
|
156 | - * |
|
157 | - * @param int $sosa |
|
158 | - */ |
|
159 | - public function deleteAncestors($sosa) { |
|
160 | - if(!$this->is_setup) return; |
|
161 | - $gen = Functions::getGeneration($sosa); |
|
162 | - Database::prepare( |
|
163 | - 'DELETE FROM `##maj_sosa`'. |
|
164 | - ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | - ' AND majs_gen >= :gen' . |
|
166 | - ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
167 | - )->execute(array( |
|
168 | - 'tree_id' => $this->tree->getTreeId(), |
|
169 | - 'user_id' => $this->user->getUserId(), |
|
170 | - 'gen' => $gen, |
|
171 | - 'sosa' => $sosa |
|
172 | - )); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Insert (or update if already existing) a list of Sosa individuals |
|
177 | - * @param array $sosa_records |
|
178 | - */ |
|
179 | - public function insertOrUpdate($sosa_records) { |
|
180 | - if(!$this->is_setup) return; |
|
140 | + /** |
|
141 | + * Remove all Sosa entries related to the gedcom file and user |
|
142 | + */ |
|
143 | + public function deleteAll() { |
|
144 | + if(!$this->is_setup) return; |
|
145 | + Database::prepare( |
|
146 | + 'DELETE FROM `##maj_sosa`'. |
|
147 | + ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
148 | + ->execute(array( |
|
149 | + 'tree_id' => $this->tree->getTreeId(), |
|
150 | + 'user_id' => $this->user->getUserId() |
|
151 | + )); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Remove all ancestors of a sosa number |
|
156 | + * |
|
157 | + * @param int $sosa |
|
158 | + */ |
|
159 | + public function deleteAncestors($sosa) { |
|
160 | + if(!$this->is_setup) return; |
|
161 | + $gen = Functions::getGeneration($sosa); |
|
162 | + Database::prepare( |
|
163 | + 'DELETE FROM `##maj_sosa`'. |
|
164 | + ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | + ' AND majs_gen >= :gen' . |
|
166 | + ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
167 | + )->execute(array( |
|
168 | + 'tree_id' => $this->tree->getTreeId(), |
|
169 | + 'user_id' => $this->user->getUserId(), |
|
170 | + 'gen' => $gen, |
|
171 | + 'sosa' => $sosa |
|
172 | + )); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Insert (or update if already existing) a list of Sosa individuals |
|
177 | + * @param array $sosa_records |
|
178 | + */ |
|
179 | + public function insertOrUpdate($sosa_records) { |
|
180 | + if(!$this->is_setup) return; |
|
181 | 181 | |
182 | - $treeid = $this->tree->getTreeId(); |
|
183 | - $userid = $this->user->getUserId(); |
|
184 | - $questionmarks_table = array(); |
|
185 | - $values_table = array(); |
|
182 | + $treeid = $this->tree->getTreeId(); |
|
183 | + $userid = $this->user->getUserId(); |
|
184 | + $questionmarks_table = array(); |
|
185 | + $values_table = array(); |
|
186 | 186 | |
187 | - $i = 0; |
|
188 | - foreach ($sosa_records as $row) { |
|
189 | - $gen = Functions::getGeneration($row['sosa']); |
|
190 | - if($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | - $questionmarks_table[] = |
|
192 | - '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
193 | - $values_table = array_merge( |
|
194 | - $values_table, |
|
195 | - array( |
|
196 | - 'tree_id'.$i => $treeid, |
|
197 | - 'user_id'.$i => $userid, |
|
198 | - 'sosa'.$i => $row['sosa'], |
|
199 | - 'indi_id'.$i => $row['indi'], |
|
200 | - 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
201 | - 'byear'.$i => $row['birth_year'], |
|
202 | - 'dyear'.$i => $row['death_year'] |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - $i++; |
|
207 | - } |
|
187 | + $i = 0; |
|
188 | + foreach ($sosa_records as $row) { |
|
189 | + $gen = Functions::getGeneration($row['sosa']); |
|
190 | + if($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | + $questionmarks_table[] = |
|
192 | + '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
193 | + $values_table = array_merge( |
|
194 | + $values_table, |
|
195 | + array( |
|
196 | + 'tree_id'.$i => $treeid, |
|
197 | + 'user_id'.$i => $userid, |
|
198 | + 'sosa'.$i => $row['sosa'], |
|
199 | + 'indi_id'.$i => $row['indi'], |
|
200 | + 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
201 | + 'byear'.$i => $row['birth_year'], |
|
202 | + 'dyear'.$i => $row['death_year'] |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + $i++; |
|
207 | + } |
|
208 | 208 | |
209 | - $sql = 'REPLACE INTO `##maj_sosa`' . |
|
210 | - ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
211 | - ' VALUES '. implode(',', $questionmarks_table); |
|
212 | - Database::prepare($sql)->execute($values_table); |
|
213 | - } |
|
209 | + $sql = 'REPLACE INTO `##maj_sosa`' . |
|
210 | + ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
211 | + ' VALUES '. implode(',', $questionmarks_table); |
|
212 | + Database::prepare($sql)->execute($values_table); |
|
213 | + } |
|
214 | 214 | |
215 | - /**************** |
|
215 | + /**************** |
|
216 | 216 | * SIMPLE QUERIES |
217 | 217 | ****************/ |
218 | 218 | |
219 | - /** |
|
220 | - * Returns the list of Sosa numbers to which an individual is related. |
|
221 | - * Format: key = sosa number, value = generation for the Sosa number |
|
222 | - * |
|
223 | - * @param Individual $indi |
|
224 | - * @return array Array of sosa numbers |
|
225 | - */ |
|
226 | - public function getSosaNumbers(Individual $indi) { |
|
227 | - if(!$this->is_setup) return array(); |
|
228 | - return Database::prepare( |
|
229 | - 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
230 | - ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
231 | - )->execute(array( |
|
232 | - 'indi_id' => $indi->getXref(), |
|
233 | - 'tree_id' => $this->tree->getTreeId(), |
|
234 | - 'user_id' => $this->user->getUserId() |
|
235 | - ))->fetchAssoc(); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Get the last generation of Sosa ancestors |
|
240 | - * |
|
241 | - * @return number Last generation if found, 1 otherwise |
|
242 | - */ |
|
243 | - public function getLastGeneration() { |
|
244 | - if(!$this->is_setup) return; |
|
245 | - return Database::prepare( |
|
246 | - 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
247 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
248 | - )->execute(array( |
|
249 | - 'tree_id' => $this->tree->getTreeId(), |
|
250 | - 'user_id' => $this->user->getUserId() |
|
251 | - ))->fetchOne() ?: 1; |
|
252 | - } |
|
253 | - |
|
254 | - /************* |
|
219 | + /** |
|
220 | + * Returns the list of Sosa numbers to which an individual is related. |
|
221 | + * Format: key = sosa number, value = generation for the Sosa number |
|
222 | + * |
|
223 | + * @param Individual $indi |
|
224 | + * @return array Array of sosa numbers |
|
225 | + */ |
|
226 | + public function getSosaNumbers(Individual $indi) { |
|
227 | + if(!$this->is_setup) return array(); |
|
228 | + return Database::prepare( |
|
229 | + 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
230 | + ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
231 | + )->execute(array( |
|
232 | + 'indi_id' => $indi->getXref(), |
|
233 | + 'tree_id' => $this->tree->getTreeId(), |
|
234 | + 'user_id' => $this->user->getUserId() |
|
235 | + ))->fetchAssoc(); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Get the last generation of Sosa ancestors |
|
240 | + * |
|
241 | + * @return number Last generation if found, 1 otherwise |
|
242 | + */ |
|
243 | + public function getLastGeneration() { |
|
244 | + if(!$this->is_setup) return; |
|
245 | + return Database::prepare( |
|
246 | + 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
247 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
248 | + )->execute(array( |
|
249 | + 'tree_id' => $this->tree->getTreeId(), |
|
250 | + 'user_id' => $this->user->getUserId() |
|
251 | + ))->fetchOne() ?: 1; |
|
252 | + } |
|
253 | + |
|
254 | + /************* |
|
255 | 255 | * SOSA LISTS |
256 | 256 | *************/ |
257 | 257 | |
258 | - /** |
|
259 | - * Return the list of all sosas, with the generations it belongs to |
|
260 | - * |
|
261 | - * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
262 | - */ |
|
263 | - public function getAllSosaWithGenerations(){ |
|
264 | - if(!$this->is_setup) return array(); |
|
265 | - return Database::prepare( |
|
266 | - 'SELECT majs_i_id AS indi,' . |
|
267 | - ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
268 | - ' FROM `##maj_sosa`' . |
|
269 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
270 | - ' GROUP BY majs_i_id' |
|
271 | - )->execute(array( |
|
272 | - 'tree_id' => $this->tree->getTreeId(), |
|
273 | - 'user_id' => $this->user->getUserId() |
|
274 | - ))->fetchAssoc(); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
279 | - * |
|
280 | - * @param number $gen Generation |
|
281 | - * @return array Array of Sosa individuals |
|
282 | - */ |
|
283 | - public function getSosaListAtGeneration($gen){ |
|
284 | - if(!$this->is_setup) return array(); |
|
285 | - if(!$this->sosa_list_by_gen) |
|
286 | - $this->sosa_list_by_gen = array(); |
|
258 | + /** |
|
259 | + * Return the list of all sosas, with the generations it belongs to |
|
260 | + * |
|
261 | + * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
262 | + */ |
|
263 | + public function getAllSosaWithGenerations(){ |
|
264 | + if(!$this->is_setup) return array(); |
|
265 | + return Database::prepare( |
|
266 | + 'SELECT majs_i_id AS indi,' . |
|
267 | + ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
268 | + ' FROM `##maj_sosa`' . |
|
269 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
270 | + ' GROUP BY majs_i_id' |
|
271 | + )->execute(array( |
|
272 | + 'tree_id' => $this->tree->getTreeId(), |
|
273 | + 'user_id' => $this->user->getUserId() |
|
274 | + ))->fetchAssoc(); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
279 | + * |
|
280 | + * @param number $gen Generation |
|
281 | + * @return array Array of Sosa individuals |
|
282 | + */ |
|
283 | + public function getSosaListAtGeneration($gen){ |
|
284 | + if(!$this->is_setup) return array(); |
|
285 | + if(!$this->sosa_list_by_gen) |
|
286 | + $this->sosa_list_by_gen = array(); |
|
287 | 287 | |
288 | - if($gen){ |
|
289 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
290 | - $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
291 | - 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
292 | - ' FROM `##maj_sosa`'. |
|
293 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
294 | - ' AND majs_gen = :gen'. |
|
295 | - ' ORDER BY majs_sosa ASC') |
|
296 | - ->execute(array( |
|
297 | - 'tree_id' => $this->tree->getTreeId(), |
|
298 | - 'user_id' => $this->user->getUserId(), |
|
299 | - 'gen' => $gen |
|
300 | - )) |
|
301 | - ->fetchAssoc(); |
|
302 | - } |
|
303 | - return $this->sosa_list_by_gen[$gen]; |
|
304 | - } |
|
305 | - return array(); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
310 | - * |
|
311 | - * @param number $gen Generation |
|
312 | - * @return array Array of Sosa families |
|
313 | - */ |
|
314 | - public function getFamilySosaListAtGeneration($gen){ |
|
315 | - if(!$this->is_setup) return array(); |
|
316 | - if(!$this->sosa_fam_list_by_gen) |
|
317 | - $this->sosa_fam_list_by_gen = array(); |
|
288 | + if($gen){ |
|
289 | + if(!isset($this->sosa_list_by_gen[$gen])){ |
|
290 | + $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
291 | + 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
292 | + ' FROM `##maj_sosa`'. |
|
293 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
294 | + ' AND majs_gen = :gen'. |
|
295 | + ' ORDER BY majs_sosa ASC') |
|
296 | + ->execute(array( |
|
297 | + 'tree_id' => $this->tree->getTreeId(), |
|
298 | + 'user_id' => $this->user->getUserId(), |
|
299 | + 'gen' => $gen |
|
300 | + )) |
|
301 | + ->fetchAssoc(); |
|
302 | + } |
|
303 | + return $this->sosa_list_by_gen[$gen]; |
|
304 | + } |
|
305 | + return array(); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
310 | + * |
|
311 | + * @param number $gen Generation |
|
312 | + * @return array Array of Sosa families |
|
313 | + */ |
|
314 | + public function getFamilySosaListAtGeneration($gen){ |
|
315 | + if(!$this->is_setup) return array(); |
|
316 | + if(!$this->sosa_fam_list_by_gen) |
|
317 | + $this->sosa_fam_list_by_gen = array(); |
|
318 | 318 | |
319 | - if($gen){ |
|
320 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
321 | - $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
322 | - 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
323 | - ' FROM `##families`'. |
|
324 | - ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
325 | - ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
326 | - ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
327 | - ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
328 | - ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
329 | - ' AND s1.majs_gen = :gen'. |
|
330 | - ' ORDER BY s1.majs_sosa ASC' |
|
331 | - ) |
|
332 | - ->execute(array( |
|
333 | - 'tree_id' => $this->tree->getTreeId(), |
|
334 | - 'user_id' => $this->user->getUserId(), |
|
335 | - 'gen' => $gen |
|
336 | - )) |
|
337 | - ->fetchAssoc(); |
|
338 | - } |
|
339 | - return $this->sosa_fam_list_by_gen[$gen]; |
|
340 | - } |
|
341 | - return array(); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
346 | - * |
|
347 | - * @param number $gen Generation |
|
348 | - * @return array Array of Sosa individuals |
|
349 | - */ |
|
350 | - public function getMissingSosaListAtGeneration($gen){ |
|
351 | - if(!$this->is_setup) return array(); |
|
352 | - if($gen){ |
|
353 | - return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
354 | - 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
|
355 | - ' FROM `##maj_sosa` schild'. |
|
356 | - ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'. |
|
357 | - ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'. |
|
358 | - ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
359 | - ' AND schild.majs_gen = :gen'. |
|
360 | - ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
361 | - ' ORDER BY schild.majs_sosa ASC') |
|
362 | - ->execute(array( |
|
363 | - 'tree_id' => $this->tree->getTreeId(), |
|
364 | - 'user_id' => $this->user->getUserId(), |
|
365 | - 'gen' => $gen - 1 |
|
366 | - ))->fetchAll(\PDO::FETCH_ASSOC); |
|
367 | - } |
|
368 | - return array(); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /************* |
|
319 | + if($gen){ |
|
320 | + if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
321 | + $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
322 | + 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
323 | + ' FROM `##families`'. |
|
324 | + ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
325 | + ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
326 | + ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
327 | + ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
328 | + ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
329 | + ' AND s1.majs_gen = :gen'. |
|
330 | + ' ORDER BY s1.majs_sosa ASC' |
|
331 | + ) |
|
332 | + ->execute(array( |
|
333 | + 'tree_id' => $this->tree->getTreeId(), |
|
334 | + 'user_id' => $this->user->getUserId(), |
|
335 | + 'gen' => $gen |
|
336 | + )) |
|
337 | + ->fetchAssoc(); |
|
338 | + } |
|
339 | + return $this->sosa_fam_list_by_gen[$gen]; |
|
340 | + } |
|
341 | + return array(); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
346 | + * |
|
347 | + * @param number $gen Generation |
|
348 | + * @return array Array of Sosa individuals |
|
349 | + */ |
|
350 | + public function getMissingSosaListAtGeneration($gen){ |
|
351 | + if(!$this->is_setup) return array(); |
|
352 | + if($gen){ |
|
353 | + return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
354 | + 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
|
355 | + ' FROM `##maj_sosa` schild'. |
|
356 | + ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'. |
|
357 | + ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'. |
|
358 | + ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
359 | + ' AND schild.majs_gen = :gen'. |
|
360 | + ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
361 | + ' ORDER BY schild.majs_sosa ASC') |
|
362 | + ->execute(array( |
|
363 | + 'tree_id' => $this->tree->getTreeId(), |
|
364 | + 'user_id' => $this->user->getUserId(), |
|
365 | + 'gen' => $gen - 1 |
|
366 | + ))->fetchAll(\PDO::FETCH_ASSOC); |
|
367 | + } |
|
368 | + return array(); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /************* |
|
374 | 374 | * STATISTICS |
375 | 375 | *************/ |
376 | - /** |
|
377 | - * Get the statistic array detailed by generation. |
|
378 | - * Statistics for each generation are: |
|
379 | - * - The number of Sosa in generation |
|
380 | - * - The number of Sosa up to generation |
|
381 | - * - The number of distinct Sosa up to generation |
|
382 | - * - The year of the first birth in generation |
|
383 | - * - The year of the last birth in generation |
|
384 | - * - The average year of birth in generation |
|
385 | - * |
|
386 | - * @return array Statistics array |
|
387 | - */ |
|
388 | - public function getStatisticsByGeneration() { |
|
389 | - if(!$this->is_setup) return array(); |
|
390 | - if(!$this->statistics_tab) { |
|
391 | - $this->statistics_tab = array(); |
|
392 | - if($maxGeneration = $this->getLastGeneration()) { |
|
393 | - for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
394 | - $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
395 | - $this->statistics_tab[$gen] = array( |
|
396 | - 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
397 | - 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
398 | - 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
399 | - 'firstBirth' => $birthStats['first'], |
|
400 | - 'lastBirth' => $birthStats['last'], |
|
401 | - 'avgBirth' => $birthStats['avg'] |
|
402 | - ); |
|
403 | - } |
|
404 | - } |
|
405 | - } |
|
406 | - return $this->statistics_tab; |
|
407 | - } |
|
376 | + /** |
|
377 | + * Get the statistic array detailed by generation. |
|
378 | + * Statistics for each generation are: |
|
379 | + * - The number of Sosa in generation |
|
380 | + * - The number of Sosa up to generation |
|
381 | + * - The number of distinct Sosa up to generation |
|
382 | + * - The year of the first birth in generation |
|
383 | + * - The year of the last birth in generation |
|
384 | + * - The average year of birth in generation |
|
385 | + * |
|
386 | + * @return array Statistics array |
|
387 | + */ |
|
388 | + public function getStatisticsByGeneration() { |
|
389 | + if(!$this->is_setup) return array(); |
|
390 | + if(!$this->statistics_tab) { |
|
391 | + $this->statistics_tab = array(); |
|
392 | + if($maxGeneration = $this->getLastGeneration()) { |
|
393 | + for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
394 | + $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
395 | + $this->statistics_tab[$gen] = array( |
|
396 | + 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
397 | + 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
398 | + 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
399 | + 'firstBirth' => $birthStats['first'], |
|
400 | + 'lastBirth' => $birthStats['last'], |
|
401 | + 'avgBirth' => $birthStats['avg'] |
|
402 | + ); |
|
403 | + } |
|
404 | + } |
|
405 | + } |
|
406 | + return $this->statistics_tab; |
|
407 | + } |
|
408 | 408 | |
409 | 409 | /** |
410 | 410 | * How many individuals exist in the tree. |
@@ -412,205 +412,205 @@ discard block |
||
412 | 412 | * @return int |
413 | 413 | */ |
414 | 414 | public function getTotalIndividuals() { |
415 | - if(!$this->is_setup) return 0; |
|
416 | - return Database::prepare( |
|
417 | - 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
|
418 | - ' WHERE i_file = :tree_id') |
|
419 | - ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
420 | - ->fetchOne() ?: 0; |
|
415 | + if(!$this->is_setup) return 0; |
|
416 | + return Database::prepare( |
|
417 | + 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
|
418 | + ' WHERE i_file = :tree_id') |
|
419 | + ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
420 | + ->fetchOne() ?: 0; |
|
421 | 421 | } |
422 | 422 | |
423 | - /** |
|
424 | - * Get the total Sosa count for all generations |
|
425 | - * |
|
426 | - * @return number Number of Sosas |
|
427 | - */ |
|
428 | - public function getSosaCount(){ |
|
429 | - if(!$this->is_setup) return 0; |
|
430 | - return Database::prepare( |
|
431 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
432 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
433 | - ->execute(array( |
|
434 | - 'tree_id' => $this->tree->getTreeId(), |
|
435 | - 'user_id' => $this->user->getUserId() |
|
436 | - ))->fetchOne() ?: 0; |
|
437 | - } |
|
438 | - |
|
439 | - /** |
|
440 | - * Get the number of Sosa in a specific generation. |
|
441 | - * |
|
442 | - * @param number $gen Generation |
|
443 | - * @return number Number of Sosas in generation |
|
444 | - */ |
|
445 | - public function getSosaCountAtGeneration($gen){ |
|
446 | - if(!$this->is_setup) return 0; |
|
447 | - return Database::prepare( |
|
448 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
449 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
450 | - ' AND majs_gen= :gen') |
|
451 | - ->execute(array( |
|
452 | - 'tree_id' => $this->tree->getTreeId(), |
|
453 | - 'user_id' => $this->user->getUserId(), |
|
454 | - 'gen' => $gen |
|
455 | - ))->fetchOne() ?: 0; |
|
456 | - } |
|
457 | - |
|
458 | - /** |
|
459 | - * Get the total number of Sosa up to a specific generation. |
|
460 | - * |
|
461 | - * @param number $gen Generation |
|
462 | - * @return number Total number of Sosas up to generation |
|
463 | - */ |
|
464 | - public function getSosaCountUpToGeneration($gen){ |
|
465 | - if(!$this->is_setup) return 0; |
|
466 | - return Database::prepare( |
|
467 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
468 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
469 | - ' AND majs_gen <= :gen') |
|
470 | - ->execute(array( |
|
471 | - 'tree_id' => $this->tree->getTreeId(), |
|
472 | - 'user_id' => $this->user->getUserId(), |
|
473 | - 'gen' => $gen |
|
474 | - ))->fetchOne() ?: 0; |
|
475 | - } |
|
476 | - |
|
477 | - /** |
|
478 | - * Get the total number of distinct Sosa individual for all generations. |
|
479 | - * |
|
480 | - * @return number Total number of distinct individual |
|
481 | - */ |
|
482 | - public function getDifferentSosaCount(){ |
|
483 | - if(!$this->is_setup) return 0; |
|
484 | - return Database::prepare( |
|
485 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
486 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
487 | - ->execute(array( |
|
488 | - 'tree_id' => $this->tree->getTreeId(), |
|
489 | - 'user_id' => $this->user->getUserId() |
|
490 | - ))->fetchOne() ?: 0; |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Get the number of distinct Sosa individual up to a specific generation. |
|
495 | - * |
|
496 | - * @param number $gen Generation |
|
497 | - * @return number Number of distinct Sosa individuals up to generation |
|
498 | - */ |
|
499 | - public function getDifferentSosaCountUpToGeneration($gen){ |
|
500 | - if(!$this->is_setup) return 0; |
|
501 | - return Database::prepare( |
|
502 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
503 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
504 | - ' AND majs_gen <= :gen') |
|
505 | - ->execute(array( |
|
506 | - 'tree_id' => $this->tree->getTreeId(), |
|
507 | - 'user_id' => $this->user->getUserId(), |
|
508 | - 'gen' => $gen |
|
509 | - ))->fetchOne() ?: 0; |
|
510 | - } |
|
511 | - |
|
512 | - /** |
|
513 | - * Get an array of birth statistics for a specific generation |
|
514 | - * Statistics are : |
|
515 | - * - first : First birth year in generation |
|
516 | - * - last : Last birth year in generation |
|
517 | - * - avg : Average birth year |
|
518 | - * |
|
519 | - * @param number $gen Generation |
|
520 | - * @return array Birth statistics array |
|
521 | - */ |
|
522 | - public function getStatsBirthYearInGeneration($gen){ |
|
523 | - if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
524 | - return Database::prepare( |
|
525 | - 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
|
526 | - ' FROM `##maj_sosa`' . |
|
527 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
528 | - ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
|
529 | - ->execute(array( |
|
530 | - 'tree_id' => $this->tree->getTreeId(), |
|
531 | - 'user_id' => $this->user->getUserId(), |
|
532 | - 'gen' => $gen, |
|
533 | - 'birth_year' => 0)) |
|
534 | - ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0); |
|
535 | - } |
|
536 | - |
|
537 | - /** |
|
538 | - * Get the mean generation time, based on a linear regression of birth years and generations |
|
539 | - * |
|
540 | - * @return number|NULL Mean generation time |
|
541 | - */ |
|
542 | - public function getMeanGenerationTime(){ |
|
543 | - if(!$this->is_setup) return; |
|
544 | - if(!$this->statistics_tab){ |
|
545 | - $this->getStatisticsByGeneration(); |
|
546 | - } |
|
547 | - //Linear regression on x=generation and y=birthdate |
|
548 | - $sum_xy = 0; |
|
549 | - $sum_x=0; |
|
550 | - $sum_y=0; |
|
551 | - $sum_x2=0; |
|
552 | - $n=count($this->statistics_tab); |
|
553 | - foreach($this->statistics_tab as $gen=>$stats){ |
|
554 | - $sum_xy+=$gen*$stats['avgBirth']; |
|
555 | - $sum_x+=$gen; |
|
556 | - $sum_y+=$stats['avgBirth']; |
|
557 | - $sum_x2+=$gen*$gen; |
|
558 | - } |
|
559 | - $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
560 | - if($denom!=0){ |
|
561 | - return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
562 | - } |
|
563 | - return null; |
|
564 | - } |
|
565 | - |
|
566 | - /** |
|
567 | - * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
568 | - * at a specified generation. |
|
569 | - * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
570 | - * |
|
571 | - * Format: |
|
572 | - * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
573 | - * -1 is used for shared ancestors |
|
574 | - * For instance base2(0100) = base10(4) represent the maternal grand father |
|
575 | - * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
576 | - * |
|
577 | - * For instance a result at generation 3 could be : |
|
578 | - * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
579 | - * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
580 | - * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
581 | - * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
582 | - * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
583 | - * ) |
|
584 | - * |
|
585 | - * @param int $gen Reference generation |
|
586 | - * @return array |
|
587 | - */ |
|
588 | - public function getAncestorDispersionForGen($gen) { |
|
589 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
590 | - return Database::prepare( |
|
591 | - 'SELECT branches, count(i_id)'. |
|
592 | - ' FROM ('. |
|
593 | - ' SELECT i_id,'. |
|
594 | - ' CASE'. |
|
595 | - ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
596 | - ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
597 | - ' END branches'. |
|
598 | - ' FROM ('. |
|
599 | - ' SELECT DISTINCT majs_i_id i_id,'. |
|
600 | - ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
601 | - ' FROM `##maj_sosa`'. |
|
602 | - ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
603 | - ' AND majs_gen >= :gen'. |
|
604 | - ' ) indistat'. |
|
605 | - ' GROUP BY i_id'. |
|
606 | - ') grouped'. |
|
607 | - ' GROUP BY branches') |
|
608 | - ->execute(array( |
|
609 | - 'tree_id' => $this->tree->getTreeId(), |
|
610 | - 'user_id' => $this->user->getUserId(), |
|
611 | - 'gen' => $gen |
|
612 | - ))->fetchAssoc() ?: array(); |
|
613 | - } |
|
423 | + /** |
|
424 | + * Get the total Sosa count for all generations |
|
425 | + * |
|
426 | + * @return number Number of Sosas |
|
427 | + */ |
|
428 | + public function getSosaCount(){ |
|
429 | + if(!$this->is_setup) return 0; |
|
430 | + return Database::prepare( |
|
431 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
432 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
433 | + ->execute(array( |
|
434 | + 'tree_id' => $this->tree->getTreeId(), |
|
435 | + 'user_id' => $this->user->getUserId() |
|
436 | + ))->fetchOne() ?: 0; |
|
437 | + } |
|
438 | + |
|
439 | + /** |
|
440 | + * Get the number of Sosa in a specific generation. |
|
441 | + * |
|
442 | + * @param number $gen Generation |
|
443 | + * @return number Number of Sosas in generation |
|
444 | + */ |
|
445 | + public function getSosaCountAtGeneration($gen){ |
|
446 | + if(!$this->is_setup) return 0; |
|
447 | + return Database::prepare( |
|
448 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
449 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
450 | + ' AND majs_gen= :gen') |
|
451 | + ->execute(array( |
|
452 | + 'tree_id' => $this->tree->getTreeId(), |
|
453 | + 'user_id' => $this->user->getUserId(), |
|
454 | + 'gen' => $gen |
|
455 | + ))->fetchOne() ?: 0; |
|
456 | + } |
|
457 | + |
|
458 | + /** |
|
459 | + * Get the total number of Sosa up to a specific generation. |
|
460 | + * |
|
461 | + * @param number $gen Generation |
|
462 | + * @return number Total number of Sosas up to generation |
|
463 | + */ |
|
464 | + public function getSosaCountUpToGeneration($gen){ |
|
465 | + if(!$this->is_setup) return 0; |
|
466 | + return Database::prepare( |
|
467 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
468 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
469 | + ' AND majs_gen <= :gen') |
|
470 | + ->execute(array( |
|
471 | + 'tree_id' => $this->tree->getTreeId(), |
|
472 | + 'user_id' => $this->user->getUserId(), |
|
473 | + 'gen' => $gen |
|
474 | + ))->fetchOne() ?: 0; |
|
475 | + } |
|
476 | + |
|
477 | + /** |
|
478 | + * Get the total number of distinct Sosa individual for all generations. |
|
479 | + * |
|
480 | + * @return number Total number of distinct individual |
|
481 | + */ |
|
482 | + public function getDifferentSosaCount(){ |
|
483 | + if(!$this->is_setup) return 0; |
|
484 | + return Database::prepare( |
|
485 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
486 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
487 | + ->execute(array( |
|
488 | + 'tree_id' => $this->tree->getTreeId(), |
|
489 | + 'user_id' => $this->user->getUserId() |
|
490 | + ))->fetchOne() ?: 0; |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Get the number of distinct Sosa individual up to a specific generation. |
|
495 | + * |
|
496 | + * @param number $gen Generation |
|
497 | + * @return number Number of distinct Sosa individuals up to generation |
|
498 | + */ |
|
499 | + public function getDifferentSosaCountUpToGeneration($gen){ |
|
500 | + if(!$this->is_setup) return 0; |
|
501 | + return Database::prepare( |
|
502 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
503 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
504 | + ' AND majs_gen <= :gen') |
|
505 | + ->execute(array( |
|
506 | + 'tree_id' => $this->tree->getTreeId(), |
|
507 | + 'user_id' => $this->user->getUserId(), |
|
508 | + 'gen' => $gen |
|
509 | + ))->fetchOne() ?: 0; |
|
510 | + } |
|
511 | + |
|
512 | + /** |
|
513 | + * Get an array of birth statistics for a specific generation |
|
514 | + * Statistics are : |
|
515 | + * - first : First birth year in generation |
|
516 | + * - last : Last birth year in generation |
|
517 | + * - avg : Average birth year |
|
518 | + * |
|
519 | + * @param number $gen Generation |
|
520 | + * @return array Birth statistics array |
|
521 | + */ |
|
522 | + public function getStatsBirthYearInGeneration($gen){ |
|
523 | + if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
524 | + return Database::prepare( |
|
525 | + 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
|
526 | + ' FROM `##maj_sosa`' . |
|
527 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
528 | + ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
|
529 | + ->execute(array( |
|
530 | + 'tree_id' => $this->tree->getTreeId(), |
|
531 | + 'user_id' => $this->user->getUserId(), |
|
532 | + 'gen' => $gen, |
|
533 | + 'birth_year' => 0)) |
|
534 | + ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'avg' => 0, 'last' => 0); |
|
535 | + } |
|
536 | + |
|
537 | + /** |
|
538 | + * Get the mean generation time, based on a linear regression of birth years and generations |
|
539 | + * |
|
540 | + * @return number|NULL Mean generation time |
|
541 | + */ |
|
542 | + public function getMeanGenerationTime(){ |
|
543 | + if(!$this->is_setup) return; |
|
544 | + if(!$this->statistics_tab){ |
|
545 | + $this->getStatisticsByGeneration(); |
|
546 | + } |
|
547 | + //Linear regression on x=generation and y=birthdate |
|
548 | + $sum_xy = 0; |
|
549 | + $sum_x=0; |
|
550 | + $sum_y=0; |
|
551 | + $sum_x2=0; |
|
552 | + $n=count($this->statistics_tab); |
|
553 | + foreach($this->statistics_tab as $gen=>$stats){ |
|
554 | + $sum_xy+=$gen*$stats['avgBirth']; |
|
555 | + $sum_x+=$gen; |
|
556 | + $sum_y+=$stats['avgBirth']; |
|
557 | + $sum_x2+=$gen*$gen; |
|
558 | + } |
|
559 | + $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
560 | + if($denom!=0){ |
|
561 | + return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
562 | + } |
|
563 | + return null; |
|
564 | + } |
|
565 | + |
|
566 | + /** |
|
567 | + * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
568 | + * at a specified generation. |
|
569 | + * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
570 | + * |
|
571 | + * Format: |
|
572 | + * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
573 | + * -1 is used for shared ancestors |
|
574 | + * For instance base2(0100) = base10(4) represent the maternal grand father |
|
575 | + * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
576 | + * |
|
577 | + * For instance a result at generation 3 could be : |
|
578 | + * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
579 | + * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
580 | + * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
581 | + * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
582 | + * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
583 | + * ) |
|
584 | + * |
|
585 | + * @param int $gen Reference generation |
|
586 | + * @return array |
|
587 | + */ |
|
588 | + public function getAncestorDispersionForGen($gen) { |
|
589 | + if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
590 | + return Database::prepare( |
|
591 | + 'SELECT branches, count(i_id)'. |
|
592 | + ' FROM ('. |
|
593 | + ' SELECT i_id,'. |
|
594 | + ' CASE'. |
|
595 | + ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
596 | + ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
597 | + ' END branches'. |
|
598 | + ' FROM ('. |
|
599 | + ' SELECT DISTINCT majs_i_id i_id,'. |
|
600 | + ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
601 | + ' FROM `##maj_sosa`'. |
|
602 | + ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
603 | + ' AND majs_gen >= :gen'. |
|
604 | + ' ) indistat'. |
|
605 | + ' GROUP BY i_id'. |
|
606 | + ') grouped'. |
|
607 | + ' GROUP BY branches') |
|
608 | + ->execute(array( |
|
609 | + 'tree_id' => $this->tree->getTreeId(), |
|
610 | + 'user_id' => $this->user->getUserId(), |
|
611 | + 'gen' => $gen |
|
612 | + ))->fetchAssoc() ?: array(); |
|
613 | + } |
|
614 | 614 | |
615 | 615 | |
616 | 616 | } |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | * {@inhericDoc} |
25 | 25 | * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent() |
26 | 26 | */ |
27 | - protected function renderContent() { |
|
27 | + protected function renderContent() { |
|
28 | 28 | |
29 | - ?> |
|
29 | + ?> |
|
30 | 30 | |
31 | 31 | <div id="maj-sosa-config-page"> |
32 | 32 | <h2><?php echo $this->data->get('title'); ?></h2> |
@@ -46,9 +46,9 @@ discard block |
||
46 | 46 | </div> |
47 | 47 | <div class="value"> |
48 | 48 | <?php |
49 | - $users = $this->data->get('users_settings'); |
|
50 | - if(count($users) == 1) { |
|
51 | - $root_indi = $users[0]['rootid']; ?> |
|
49 | + $users = $this->data->get('users_settings'); |
|
50 | + if(count($users) == 1) { |
|
51 | + $root_indi = $users[0]['rootid']; ?> |
|
52 | 52 | <label> |
53 | 53 | <input id="maj_sosa_input_userid" type="hidden" name="userid" value="<?php echo $users[0]['user']->getUserId(); ?>" /> |
54 | 54 | <?php echo $users[0]['user']->getRealNameHtml() ?> |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | <?php } else if(count($users) > 1) { ?> |
57 | 57 | <select id='maj-sosa-config-select' name="userid"> |
58 | 58 | <?php |
59 | - $root_indi = $users[0]['rootid']; |
|
60 | - foreach ($this->data->get('users_settings') as $user) { ?> |
|
59 | + $root_indi = $users[0]['rootid']; |
|
60 | + foreach ($this->data->get('users_settings') as $user) { ?> |
|
61 | 61 | <option value="<?php echo $user['user']->getUserId(); ?>"><?php echo $user['user']->getRealNameHtml() ?></option> |
62 | 62 | <?php } ?> |
63 | 63 | </select> |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | </form> |
81 | 81 | |
82 | 82 | <?php |
83 | - } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | } |
86 | 86 | |
87 | 87 | \ No newline at end of file |
@@ -43,11 +43,11 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public static function getInstance() |
45 | 45 | { |
46 | - if (null === static::$instance) { |
|
47 | - static::$instance = new static(); |
|
48 | - } |
|
46 | + if (null === static::$instance) { |
|
47 | + static::$instance = new static(); |
|
48 | + } |
|
49 | 49 | |
50 | - return static::$instance; |
|
50 | + return static::$instance; |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | /** |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | * @see \MyArtJaub\Webtrees\Hook\HookProviderInterface::get() |
56 | 56 | */ |
57 | 57 | public function get($hook_function, $hook_context = null) { |
58 | - return new Hook($hook_function, $hook_context); |
|
58 | + return new Hook($hook_function, $hook_context); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -73,20 +73,20 @@ discard block |
||
73 | 73 | public function getPossibleHooks() { |
74 | 74 | static $hooks=null; |
75 | 75 | if ($hooks === null) { |
76 | - $hooks = array(); |
|
76 | + $hooks = array(); |
|
77 | 77 | |
78 | - // Cannot use the same logic as the core Module loading, |
|
79 | - // as this forces a new include of the module.php file. |
|
80 | - // This causes issue when classes are defined in this file. |
|
81 | - // Cannot use Module::getActiveModules as well, as this is private. |
|
82 | - $module_names = Database::prepare( |
|
83 | - 'SELECT SQL_CACHE module_name FROM `##module`' |
|
84 | - )->fetchOneColumn(); |
|
78 | + // Cannot use the same logic as the core Module loading, |
|
79 | + // as this forces a new include of the module.php file. |
|
80 | + // This causes issue when classes are defined in this file. |
|
81 | + // Cannot use Module::getActiveModules as well, as this is private. |
|
82 | + $module_names = Database::prepare( |
|
83 | + 'SELECT SQL_CACHE module_name FROM `##module`' |
|
84 | + )->fetchOneColumn(); |
|
85 | 85 | |
86 | - foreach($module_names as $module_name) { |
|
87 | - $module = Module::getModuleByName($module_name); |
|
86 | + foreach($module_names as $module_name) { |
|
87 | + $module = Module::getModuleByName($module_name); |
|
88 | 88 | |
89 | - if($module instanceof HookSubscriberInterface){ |
|
89 | + if($module instanceof HookSubscriberInterface){ |
|
90 | 90 | $subscribedhooks = $module->getSubscribedHooks(); |
91 | 91 | if(is_array($subscribedhooks)){ |
92 | 92 | foreach($subscribedhooks as $key => $value){ |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | } |
112 | 112 | } |
113 | 113 | } |
114 | - } |
|
114 | + } |
|
115 | 115 | } |
116 | 116 | } |
117 | 117 | return $hooks; |
@@ -153,33 +153,33 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public function updateHooks() { |
155 | 155 | |
156 | - if(Auth::isAdmin()){ |
|
157 | - $ihooks = self::getInstalledHooks(); |
|
158 | - $phooks = self::getPossibleHooks(); |
|
156 | + if(Auth::isAdmin()){ |
|
157 | + $ihooks = self::getInstalledHooks(); |
|
158 | + $phooks = self::getPossibleHooks(); |
|
159 | 159 | |
160 | - // Insert hooks not existing yet in the DB |
|
161 | - if($phooks !== null){ |
|
162 | - foreach($phooks as $phook => $priority){ |
|
163 | - $array_hook = explode('#', $phook); |
|
164 | - if($ihooks === null || !array_key_exists($phook, $ihooks)){ |
|
165 | - $chook = new Hook($array_hook[1], $array_hook[2]); |
|
166 | - $chook->subscribe($array_hook[0]); |
|
167 | - $chook->setPriority($array_hook[0], $priority); |
|
168 | - } |
|
169 | - } |
|
170 | - } |
|
160 | + // Insert hooks not existing yet in the DB |
|
161 | + if($phooks !== null){ |
|
162 | + foreach($phooks as $phook => $priority){ |
|
163 | + $array_hook = explode('#', $phook); |
|
164 | + if($ihooks === null || !array_key_exists($phook, $ihooks)){ |
|
165 | + $chook = new Hook($array_hook[1], $array_hook[2]); |
|
166 | + $chook->subscribe($array_hook[0]); |
|
167 | + $chook->setPriority($array_hook[0], $priority); |
|
168 | + } |
|
169 | + } |
|
170 | + } |
|
171 | 171 | |
172 | - //Remove hooks not existing any more in the file system |
|
173 | - if($ihooks !== null){ |
|
174 | - foreach(array_keys($ihooks) as $ihook){ |
|
175 | - $array_hook = explode('#', $ihook); |
|
176 | - if($phooks === null || !array_key_exists($ihook, $phooks)){ |
|
177 | - $chook = new Hook($array_hook[1], $array_hook[2]); |
|
178 | - $chook->remove($array_hook[0]); |
|
179 | - } |
|
180 | - } |
|
181 | - } |
|
182 | - } |
|
172 | + //Remove hooks not existing any more in the file system |
|
173 | + if($ihooks !== null){ |
|
174 | + foreach(array_keys($ihooks) as $ihook){ |
|
175 | + $array_hook = explode('#', $ihook); |
|
176 | + if($phooks === null || !array_key_exists($ihook, $phooks)){ |
|
177 | + $chook = new Hook($array_hook[1], $array_hook[2]); |
|
178 | + $chook->remove($array_hook[0]); |
|
179 | + } |
|
180 | + } |
|
181 | + } |
|
182 | + } |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | } |
186 | 186 | \ No newline at end of file |
@@ -18,50 +18,50 @@ |
||
18 | 18 | */ |
19 | 19 | class JsonController extends BaseController { |
20 | 20 | |
21 | - /** |
|
22 | - * {@inheritDoc} |
|
23 | - * @see \Fisharebest\Webtrees\Controller\BaseController::pageHeader() |
|
24 | - */ |
|
25 | - public function pageHeader() { |
|
26 | - header('Content-Type: application/json'); |
|
27 | - header('Cache-Control: no-cache, must-revalidate'); |
|
28 | - header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
|
29 | - // We've displayed the header - display the footer automatically |
|
30 | - register_shutdown_function(array($this, 'pageFooter')); |
|
21 | + /** |
|
22 | + * {@inheritDoc} |
|
23 | + * @see \Fisharebest\Webtrees\Controller\BaseController::pageHeader() |
|
24 | + */ |
|
25 | + public function pageHeader() { |
|
26 | + header('Content-Type: application/json'); |
|
27 | + header('Cache-Control: no-cache, must-revalidate'); |
|
28 | + header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
|
29 | + // We've displayed the header - display the footer automatically |
|
30 | + register_shutdown_function(array($this, 'pageFooter')); |
|
31 | 31 | |
32 | - return $this; |
|
33 | - } |
|
32 | + return $this; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritDoc} |
|
37 | - * @see \Fisharebest\Webtrees\Controller\BaseController::pageFooter() |
|
38 | - */ |
|
39 | - public function pageFooter() { |
|
40 | - return $this; |
|
41 | - } |
|
35 | + /** |
|
36 | + * {@inheritDoc} |
|
37 | + * @see \Fisharebest\Webtrees\Controller\BaseController::pageFooter() |
|
38 | + */ |
|
39 | + public function pageFooter() { |
|
40 | + return $this; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * Restrict access. |
|
45 | - * |
|
46 | - * @param bool $condition |
|
47 | - * |
|
48 | - * @return $this |
|
49 | - */ |
|
50 | - public function restrictAccess($condition) { |
|
51 | - if ($condition !== true) { |
|
52 | - throw new MvcException(403); |
|
53 | - } |
|
43 | + /** |
|
44 | + * Restrict access. |
|
45 | + * |
|
46 | + * @param bool $condition |
|
47 | + * |
|
48 | + * @return $this |
|
49 | + */ |
|
50 | + public function restrictAccess($condition) { |
|
51 | + if ($condition !== true) { |
|
52 | + throw new MvcException(403); |
|
53 | + } |
|
54 | 54 | |
55 | - return $this; |
|
56 | - } |
|
55 | + return $this; |
|
56 | + } |
|
57 | 57 | |
58 | - /** |
|
59 | - * Encode the data to JSON format. |
|
60 | - * |
|
61 | - * @param array $data Data to encode |
|
62 | - * @param number $options JSON options mask. See http://php.net/manual/fr/json.constants.php |
|
63 | - */ |
|
64 | - public function encode(array $data, $options = 0) { |
|
65 | - echo json_encode($data, $options); |
|
66 | - } |
|
58 | + /** |
|
59 | + * Encode the data to JSON format. |
|
60 | + * |
|
61 | + * @param array $data Data to encode |
|
62 | + * @param number $options JSON options mask. See http://php.net/manual/fr/json.constants.php |
|
63 | + */ |
|
64 | + public function encode(array $data, $options = 0) { |
|
65 | + echo json_encode($data, $options); |
|
66 | + } |
|
67 | 67 | } |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class Cache{ |
24 | 24 | |
25 | - /** |
|
26 | - * Underlying Cache object |
|
27 | - * @var CacheItemPoolInterface $cache |
|
28 | - */ |
|
25 | + /** |
|
26 | + * Underlying Cache object |
|
27 | + * @var CacheItemPoolInterface $cache |
|
28 | + */ |
|
29 | 29 | protected $cache=null; |
30 | 30 | |
31 | 31 | /** |
@@ -47,11 +47,11 @@ discard block |
||
47 | 47 | */ |
48 | 48 | protected static function getInstance() |
49 | 49 | { |
50 | - if (null === static::$instance) { |
|
51 | - static::$instance = new static(); |
|
52 | - } |
|
50 | + if (null === static::$instance) { |
|
51 | + static::$instance = new static(); |
|
52 | + } |
|
53 | 53 | |
54 | - return static::$instance; |
|
54 | + return static::$instance; |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | /** |
@@ -59,8 +59,8 @@ discard block |
||
59 | 59 | * |
60 | 60 | */ |
61 | 61 | protected function init() { |
62 | - if(Apc::isAvailable()) { |
|
63 | - $driver = new Apc(); |
|
62 | + if(Apc::isAvailable()) { |
|
63 | + $driver = new Apc(); |
|
64 | 64 | } else { |
65 | 65 | if (!is_dir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')) { |
66 | 66 | // We may not have permission - especially during setup, before we instruct |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | @mkdir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache'); |
69 | 69 | } |
70 | 70 | if (is_dir(WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')) { |
71 | - $driver = new FileSystem(array('path' => WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')); |
|
71 | + $driver = new FileSystem(array('path' => WT_DATA_DIR.DIRECTORY_SEPARATOR.'cache')); |
|
72 | 72 | } else { |
73 | 73 | // No cache available, let's just use a basic one :-( |
74 | 74 | $driver = new Ephemeral(); |
@@ -95,7 +95,7 @@ discard block |
||
95 | 95 | * @return string Cached key name |
96 | 96 | */ |
97 | 97 | protected function getKeyName($value, AbstractModule $mod = null){ |
98 | - $this->checkInit(); |
|
98 | + $this->checkInit(); |
|
99 | 99 | $mod_name = 'myartjaub'; |
100 | 100 | if($mod !== null) $mod_name = $mod->getName(); |
101 | 101 | return $mod_name.'_'.$value; |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | * @return \Psr\Cache\CacheItemInterface |
110 | 110 | */ |
111 | 111 | public function getI($value, AbstractModule $mod = null){ |
112 | - $this->checkInit(); |
|
112 | + $this->checkInit(); |
|
113 | 113 | return $this->cache->getItem($this->getKeyName($value, $mod)); |
114 | 114 | } |
115 | 115 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return \Psr\Cache\CacheItemInterface |
122 | 122 | */ |
123 | 123 | public static function get($value, AbstractModule $mod = null){ |
124 | - return self::getInstance()->getI($value, $mod); |
|
124 | + return self::getInstance()->getI($value, $mod); |
|
125 | 125 | } |
126 | 126 | |
127 | 127 | /** |
@@ -136,8 +136,8 @@ discard block |
||
136 | 136 | |
137 | 137 | $item = $value; |
138 | 138 | if(!($value instanceof CacheItemInterface)) { |
139 | - $item = new \Stash\Item(); |
|
140 | - $item->setKey($this->getKeyName($value, $mod)); |
|
139 | + $item = new \Stash\Item(); |
|
140 | + $item->setKey($this->getKeyName($value, $mod)); |
|
141 | 141 | } |
142 | 142 | $item->set($data); |
143 | 143 | $this->cache->save($item); |
@@ -151,7 +151,7 @@ discard block |
||
151 | 151 | * @param AbstractModule $mod Calling module |
152 | 152 | */ |
153 | 153 | public static function save($value, $data, AbstractModule $mod = null){ |
154 | - self::getInstance()->saveI($value, $data, $mod); |
|
154 | + self::getInstance()->saveI($value, $data, $mod); |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | /** |
@@ -162,8 +162,8 @@ discard block |
||
162 | 162 | * @return bool Deletion successful? |
163 | 163 | */ |
164 | 164 | public function deleteI($value, AbstractModule $mod = null){ |
165 | - $this->checkInit(); |
|
166 | - return $this->cache->deleteItem($this->getKeyName($value, $mod)); |
|
165 | + $this->checkInit(); |
|
166 | + return $this->cache->deleteItem($this->getKeyName($value, $mod)); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -174,7 +174,7 @@ discard block |
||
174 | 174 | * @return bool Deletion successful? |
175 | 175 | */ |
176 | 176 | public static function delete($value, AbstractModule $mod = null){ |
177 | - return self::getInstance()->deleteI($value, $mod); |
|
177 | + return self::getInstance()->deleteI($value, $mod); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * |
183 | 183 | */ |
184 | 184 | public function cleanI(){ |
185 | - $this->checkInit(); |
|
185 | + $this->checkInit(); |
|
186 | 186 | $this->cache->clear(); |
187 | 187 | } |
188 | 188 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | * Static invocation of the *clean* method. |
191 | 191 | */ |
192 | 192 | public static function clean() { |
193 | - self::getInstance()->cleanI(); |
|
193 | + self::getInstance()->cleanI(); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | } |
197 | 197 | \ No newline at end of file |