@@ -30,87 +30,87 @@ discard block |
||
30 | 30 | */ |
31 | 31 | class AdminConfigController extends MvcController |
32 | 32 | { |
33 | - /** |
|
34 | - * Manage updates sent from the AdminConfig@index form. |
|
35 | - */ |
|
36 | - protected function update() { |
|
37 | - if(Auth::isAdmin()){ |
|
38 | - $ihooks = HookProvider::getInstance()->getInstalledHooks(); |
|
33 | + /** |
|
34 | + * Manage updates sent from the AdminConfig@index form. |
|
35 | + */ |
|
36 | + protected function update() { |
|
37 | + if(Auth::isAdmin()){ |
|
38 | + $ihooks = HookProvider::getInstance()->getInstalledHooks(); |
|
39 | 39 | |
40 | - $module_names= Database::prepare( |
|
41 | - "SELECT module_name FROM `##module` WHERE status='disabled'" |
|
42 | - )->fetchOneColumn(); |
|
40 | + $module_names= Database::prepare( |
|
41 | + "SELECT module_name FROM `##module` WHERE status='disabled'" |
|
42 | + )->fetchOneColumn(); |
|
43 | 43 | |
44 | - if($ihooks !== null){ |
|
45 | - foreach ($ihooks as $ihook => $params) { |
|
46 | - if(Filter::post('hook-' . $params['id']) === 'yes') { |
|
47 | - $array_hook = explode('#', $ihook); |
|
48 | - //Update status |
|
49 | - $new_status= Filter::postBool('status-' . $params['id']); |
|
50 | - if(in_array($array_hook[0], $module_names)) $new_status = false; |
|
51 | - $previous_status = $params['status']; |
|
52 | - if ($new_status !== null) { |
|
53 | - $new_status= $new_status ? 'enabled' : 'disabled'; |
|
54 | - if($new_status != $previous_status){ |
|
55 | - $chook = new Hook($array_hook[1], $array_hook[2]); |
|
56 | - switch($new_status){ |
|
57 | - case 'enabled': |
|
58 | - $chook->enable($array_hook[0]); |
|
59 | - break; |
|
60 | - case 'disabled': |
|
61 | - $chook->disable($array_hook[0]); |
|
62 | - break; |
|
63 | - default: |
|
64 | - break; |
|
65 | - } |
|
66 | - } |
|
67 | - } |
|
44 | + if($ihooks !== null){ |
|
45 | + foreach ($ihooks as $ihook => $params) { |
|
46 | + if(Filter::post('hook-' . $params['id']) === 'yes') { |
|
47 | + $array_hook = explode('#', $ihook); |
|
48 | + //Update status |
|
49 | + $new_status= Filter::postBool('status-' . $params['id']); |
|
50 | + if(in_array($array_hook[0], $module_names)) $new_status = false; |
|
51 | + $previous_status = $params['status']; |
|
52 | + if ($new_status !== null) { |
|
53 | + $new_status= $new_status ? 'enabled' : 'disabled'; |
|
54 | + if($new_status != $previous_status){ |
|
55 | + $chook = new Hook($array_hook[1], $array_hook[2]); |
|
56 | + switch($new_status){ |
|
57 | + case 'enabled': |
|
58 | + $chook->enable($array_hook[0]); |
|
59 | + break; |
|
60 | + case 'disabled': |
|
61 | + $chook->disable($array_hook[0]); |
|
62 | + break; |
|
63 | + default: |
|
64 | + break; |
|
65 | + } |
|
66 | + } |
|
67 | + } |
|
68 | 68 | |
69 | - //Update priority |
|
70 | - $new_priority = Filter::postInteger("moduleorder-{$params['id']}"); |
|
71 | - $previous_priority = $params['priority']; |
|
72 | - if ($new_priority !== null) { |
|
73 | - if($new_priority != $previous_priority){ |
|
74 | - $chook = new Hook($array_hook[1], $array_hook[2]); |
|
75 | - $chook->setPriority($array_hook[0], $new_priority); |
|
76 | - } |
|
77 | - } |
|
78 | - } |
|
79 | - } |
|
80 | - } |
|
81 | - } |
|
82 | - } |
|
69 | + //Update priority |
|
70 | + $new_priority = Filter::postInteger("moduleorder-{$params['id']}"); |
|
71 | + $previous_priority = $params['priority']; |
|
72 | + if ($new_priority !== null) { |
|
73 | + if($new_priority != $previous_priority){ |
|
74 | + $chook = new Hook($array_hook[1], $array_hook[2]); |
|
75 | + $chook->setPriority($array_hook[0], $new_priority); |
|
76 | + } |
|
77 | + } |
|
78 | + } |
|
79 | + } |
|
80 | + } |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - /** |
|
85 | - * Pages |
|
86 | - */ |
|
84 | + /** |
|
85 | + * Pages |
|
86 | + */ |
|
87 | 87 | |
88 | - /** |
|
89 | - * AdminConfig@index |
|
90 | - */ |
|
91 | - public function index() { |
|
92 | - HookProvider::getInstance()->updateHooks(); |
|
88 | + /** |
|
89 | + * AdminConfig@index |
|
90 | + */ |
|
91 | + public function index() { |
|
92 | + HookProvider::getInstance()->updateHooks(); |
|
93 | 93 | |
94 | - $action = Filter::post('action'); |
|
95 | - if($action == 'update' && Filter::checkCsrf()) $this->update(); |
|
94 | + $action = Filter::post('action'); |
|
95 | + if($action == 'update' && Filter::checkCsrf()) $this->update(); |
|
96 | 96 | |
97 | - Theme::theme(new AdministrationTheme)->init(Globals::getTree()); |
|
98 | - $ctrl = new PageController(); |
|
99 | - $ctrl |
|
100 | - ->restrictAccess(Auth::isAdmin()) |
|
101 | - ->setPageTitle($this->module->getTitle()); |
|
97 | + Theme::theme(new AdministrationTheme)->init(Globals::getTree()); |
|
98 | + $ctrl = new PageController(); |
|
99 | + $ctrl |
|
100 | + ->restrictAccess(Auth::isAdmin()) |
|
101 | + ->setPageTitle($this->module->getTitle()); |
|
102 | 102 | |
103 | - $table_id = 'table-installedhooks-' . Uuid::uuid4(); |
|
103 | + $table_id = 'table-installedhooks-' . Uuid::uuid4(); |
|
104 | 104 | |
105 | - $view_bag = new ViewBag(); |
|
106 | - $view_bag->set('title', $ctrl->getPageTitle()); |
|
107 | - $view_bag->set('table_id', $table_id); |
|
108 | - $view_bag->set('hook_list', HookProvider::getInstance()->getRawInstalledHooks()); |
|
105 | + $view_bag = new ViewBag(); |
|
106 | + $view_bag->set('title', $ctrl->getPageTitle()); |
|
107 | + $view_bag->set('table_id', $table_id); |
|
108 | + $view_bag->set('hook_list', HookProvider::getInstance()->getRawInstalledHooks()); |
|
109 | 109 | |
110 | - $ctrl |
|
111 | - ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) |
|
112 | - ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL) |
|
113 | - ->addInlineJavascript(' |
|
110 | + $ctrl |
|
111 | + ->addExternalJavascript(WT_JQUERY_DATATABLES_JS_URL) |
|
112 | + ->addExternalJavascript(WT_DATATABLES_BOOTSTRAP_JS_URL) |
|
113 | + ->addInlineJavascript(' |
|
114 | 114 | jQuery(document).ready(function() { |
115 | 115 | jQuery("#'.$table_id.'").dataTable( { |
116 | 116 | '.I18N::datatablesI18N().', |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | }); |
131 | 131 | '); |
132 | 132 | |
133 | - ViewFactory::make('AdminConfig', $this, $ctrl, $view_bag)->render(); |
|
134 | - } |
|
133 | + ViewFactory::make('AdminConfig', $this, $ctrl, $view_bag)->render(); |
|
134 | + } |
|
135 | 135 | |
136 | 136 | } |
137 | 137 | \ No newline at end of file |
@@ -34,26 +34,26 @@ discard block |
||
34 | 34 | * Manage updates sent from the AdminConfig@index form. |
35 | 35 | */ |
36 | 36 | protected function update() { |
37 | - if(Auth::isAdmin()){ |
|
37 | + if (Auth::isAdmin()) { |
|
38 | 38 | $ihooks = HookProvider::getInstance()->getInstalledHooks(); |
39 | 39 | |
40 | - $module_names= Database::prepare( |
|
40 | + $module_names = Database::prepare( |
|
41 | 41 | "SELECT module_name FROM `##module` WHERE status='disabled'" |
42 | 42 | )->fetchOneColumn(); |
43 | 43 | |
44 | - if($ihooks !== null){ |
|
44 | + if ($ihooks !== null) { |
|
45 | 45 | foreach ($ihooks as $ihook => $params) { |
46 | - if(Filter::post('hook-' . $params['id']) === 'yes') { |
|
46 | + if (Filter::post('hook-'.$params['id']) === 'yes') { |
|
47 | 47 | $array_hook = explode('#', $ihook); |
48 | 48 | //Update status |
49 | - $new_status= Filter::postBool('status-' . $params['id']); |
|
50 | - if(in_array($array_hook[0], $module_names)) $new_status = false; |
|
49 | + $new_status = Filter::postBool('status-'.$params['id']); |
|
50 | + if (in_array($array_hook[0], $module_names)) $new_status = false; |
|
51 | 51 | $previous_status = $params['status']; |
52 | 52 | if ($new_status !== null) { |
53 | - $new_status= $new_status ? 'enabled' : 'disabled'; |
|
54 | - if($new_status != $previous_status){ |
|
53 | + $new_status = $new_status ? 'enabled' : 'disabled'; |
|
54 | + if ($new_status != $previous_status) { |
|
55 | 55 | $chook = new Hook($array_hook[1], $array_hook[2]); |
56 | - switch($new_status){ |
|
56 | + switch ($new_status) { |
|
57 | 57 | case 'enabled': |
58 | 58 | $chook->enable($array_hook[0]); |
59 | 59 | break; |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | $new_priority = Filter::postInteger("moduleorder-{$params['id']}"); |
71 | 71 | $previous_priority = $params['priority']; |
72 | 72 | if ($new_priority !== null) { |
73 | - if($new_priority != $previous_priority){ |
|
73 | + if ($new_priority != $previous_priority) { |
|
74 | 74 | $chook = new Hook($array_hook[1], $array_hook[2]); |
75 | 75 | $chook->setPriority($array_hook[0], $new_priority); |
76 | 76 | } |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | HookProvider::getInstance()->updateHooks(); |
93 | 93 | |
94 | 94 | $action = Filter::post('action'); |
95 | - if($action == 'update' && Filter::checkCsrf()) $this->update(); |
|
95 | + if ($action == 'update' && Filter::checkCsrf()) $this->update(); |
|
96 | 96 | |
97 | 97 | Theme::theme(new AdministrationTheme)->init(Globals::getTree()); |
98 | 98 | $ctrl = new PageController(); |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | ->restrictAccess(Auth::isAdmin()) |
101 | 101 | ->setPageTitle($this->module->getTitle()); |
102 | 102 | |
103 | - $table_id = 'table-installedhooks-' . Uuid::uuid4(); |
|
103 | + $table_id = 'table-installedhooks-'.Uuid::uuid4(); |
|
104 | 104 | |
105 | 105 | $view_bag = new ViewBag(); |
106 | 106 | $view_bag->set('title', $ctrl->getPageTitle()); |
@@ -47,7 +47,9 @@ discard block |
||
47 | 47 | $array_hook = explode('#', $ihook); |
48 | 48 | //Update status |
49 | 49 | $new_status= Filter::postBool('status-' . $params['id']); |
50 | - if(in_array($array_hook[0], $module_names)) $new_status = false; |
|
50 | + if(in_array($array_hook[0], $module_names)) { |
|
51 | + $new_status = false; |
|
52 | + } |
|
51 | 53 | $previous_status = $params['status']; |
52 | 54 | if ($new_status !== null) { |
53 | 55 | $new_status= $new_status ? 'enabled' : 'disabled'; |
@@ -92,7 +94,9 @@ discard block |
||
92 | 94 | HookProvider::getInstance()->updateHooks(); |
93 | 95 | |
94 | 96 | $action = Filter::post('action'); |
95 | - if($action == 'update' && Filter::checkCsrf()) $this->update(); |
|
97 | + if($action == 'update' && Filter::checkCsrf()) { |
|
98 | + $this->update(); |
|
99 | + } |
|
96 | 100 | |
97 | 101 | Theme::theme(new AdministrationTheme)->init(Globals::getTree()); |
98 | 102 | $ctrl = new PageController(); |
@@ -32,49 +32,49 @@ discard block |
||
32 | 32 | class MiscExtensionsModule extends AbstractModule |
33 | 33 | implements HookSubscriberInterface, IndividualHeaderExtenderInterface, PageHeaderExtenderInterface, PageFooterExtenderInterface, ModuleConfigInterface |
34 | 34 | { |
35 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
36 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
35 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
36 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
37 | 37 | |
38 | - /** |
|
39 | - * {@inheritDoc} |
|
40 | - * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle() |
|
41 | - */ |
|
42 | - public function getTitle() { |
|
43 | - return I18N::translate('Miscellaneous extensions'); |
|
44 | - } |
|
38 | + /** |
|
39 | + * {@inheritDoc} |
|
40 | + * @see \Fisharebest\Webtrees\Module\AbstractModule::getTitle() |
|
41 | + */ |
|
42 | + public function getTitle() { |
|
43 | + return I18N::translate('Miscellaneous extensions'); |
|
44 | + } |
|
45 | 45 | |
46 | 46 | /** |
47 | 47 | * {@inheritDoc} |
48 | 48 | * @see \Fisharebest\Webtrees\Module\AbstractModule::getDescription() |
49 | 49 | */ |
50 | - public function getDescription() { |
|
51 | - return I18N::translate('Miscellaneous extensions for <strong>webtrees</strong>.'); |
|
52 | - } |
|
50 | + public function getDescription() { |
|
51 | + return I18N::translate('Miscellaneous extensions for <strong>webtrees</strong>.'); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inhericDoc} |
|
56 | - */ |
|
57 | - public function modAction($mod_action) { |
|
58 | - \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
59 | - } |
|
54 | + /** |
|
55 | + * {@inhericDoc} |
|
56 | + */ |
|
57 | + public function modAction($mod_action) { |
|
58 | + \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * {@inhericDoc} |
|
63 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
64 | - */ |
|
65 | - public function getConfigLink() { |
|
66 | - return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
67 | - } |
|
61 | + /** |
|
62 | + * {@inhericDoc} |
|
63 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
64 | + */ |
|
65 | + public function getConfigLink() { |
|
66 | + return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * {@inheritDoc} |
|
71 | - * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
72 | - */ |
|
69 | + /** |
|
70 | + * {@inheritDoc} |
|
71 | + * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
72 | + */ |
|
73 | 73 | public function getSubscribedHooks() { |
74 | 74 | return array( |
75 | - 'hExtendIndiHeaderLeft' => 20, |
|
76 | - 'hPrintHeader' => 20, |
|
77 | - 'hPrintFooter' => 20 |
|
75 | + 'hExtendIndiHeaderLeft' => 20, |
|
76 | + 'hPrintHeader' => 20, |
|
77 | + 'hPrintFooter' => 20 |
|
78 | 78 | ); |
79 | 79 | } |
80 | 80 | |
@@ -89,22 +89,22 @@ discard block |
||
89 | 89 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderLeft() |
90 | 90 | */ |
91 | 91 | public function hExtendIndiHeaderLeft(IndividualController $ctrlIndi) { |
92 | - $res = ''; |
|
93 | - $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
94 | - $titles = $dindi->getTitles(); |
|
95 | - if(count($titles)>0){ |
|
96 | - $res = ' |
|
92 | + $res = ''; |
|
93 | + $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
94 | + $titles = $dindi->getTitles(); |
|
95 | + if(count($titles)>0){ |
|
96 | + $res = ' |
|
97 | 97 | <dl> |
98 | 98 | <dt class="label">'.I18N::translate('Titles').'</dt>'; |
99 | - foreach($titles as $title=>$props){ |
|
100 | - $res .= |
|
101 | - '<dd class="field">' . $title. ' ' . |
|
102 | - FunctionsPrint::getListFromArray($props) . |
|
103 | - '</dd>'; |
|
104 | - } |
|
105 | - $res .= '</dl>'; |
|
106 | - } |
|
107 | - return array( 'indi-header-titles' , $res); |
|
99 | + foreach($titles as $title=>$props){ |
|
100 | + $res .= |
|
101 | + '<dd class="field">' . $title. ' ' . |
|
102 | + FunctionsPrint::getListFromArray($props) . |
|
103 | + '</dd>'; |
|
104 | + } |
|
105 | + $res .= '</dl>'; |
|
106 | + } |
|
107 | + return array( 'indi-header-titles' , $res); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -118,13 +118,13 @@ discard block |
||
118 | 118 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\PageHeaderExtenderInterface::hPrintHeader() |
119 | 119 | */ |
120 | 120 | public function hPrintHeader() { |
121 | - $html = ''; |
|
122 | - if($this->getSetting('MAJ_ADD_HTML_HEADER', 0) == 1){ |
|
123 | - if(Auth::accessLevel(Globals::getTree()) >= $this->getSetting('MAJ_SHOW_HTML_HEADER', Auth::PRIV_HIDE) && !Filter::getBool('noheader')){ |
|
124 | - $html .= $this->getSetting('MAJ_HTML_HEADER', ''); |
|
125 | - } |
|
126 | - } |
|
127 | - return $html; |
|
121 | + $html = ''; |
|
122 | + if($this->getSetting('MAJ_ADD_HTML_HEADER', 0) == 1){ |
|
123 | + if(Auth::accessLevel(Globals::getTree()) >= $this->getSetting('MAJ_SHOW_HTML_HEADER', Auth::PRIV_HIDE) && !Filter::getBool('noheader')){ |
|
124 | + $html .= $this->getSetting('MAJ_HTML_HEADER', ''); |
|
125 | + } |
|
126 | + } |
|
127 | + return $html; |
|
128 | 128 | } |
129 | 129 | |
130 | 130 | /** |
@@ -132,26 +132,26 @@ discard block |
||
132 | 132 | * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\PageFooterExtenderInterface::hPrintFooter() |
133 | 133 | */ |
134 | 134 | public function hPrintFooter() { |
135 | - $wt_tree = Globals::getTree(); |
|
136 | - $html = ''; |
|
137 | - if($this->getSetting('MAJ_DISPLAY_CNIL', 0) == 1){ |
|
138 | - $html .= '<br/>'; |
|
139 | - $html .= '<div class="center">'; |
|
140 | - $cnil_ref = $this->getSetting('MAJ_CNIL_REFERENCE', ''); |
|
141 | - if($cnil_ref != ''){ |
|
142 | - $html .= I18N::translate('This site has been notified to the French National Commission for Data protection (CNIL) and registered under number %s. ', $cnil_ref); |
|
143 | - } |
|
144 | - $html .= I18N::translate('In accordance with the French Data protection Act (<em>Loi Informatique et Libertés</em>) of January 6th, 1978, you have the right to access, modify, rectify and delete personal information that pertains to you. To exercice this right, please contact %s, and provide your name, address and a proof of your identity.', |
|
145 | - Theme::theme()->contactLink(User::find($wt_tree->getPreference('WEBMASTER_USER_ID')))); |
|
146 | - $html .= '</div>'; |
|
147 | - } |
|
135 | + $wt_tree = Globals::getTree(); |
|
136 | + $html = ''; |
|
137 | + if($this->getSetting('MAJ_DISPLAY_CNIL', 0) == 1){ |
|
138 | + $html .= '<br/>'; |
|
139 | + $html .= '<div class="center">'; |
|
140 | + $cnil_ref = $this->getSetting('MAJ_CNIL_REFERENCE', ''); |
|
141 | + if($cnil_ref != ''){ |
|
142 | + $html .= I18N::translate('This site has been notified to the French National Commission for Data protection (CNIL) and registered under number %s. ', $cnil_ref); |
|
143 | + } |
|
144 | + $html .= I18N::translate('In accordance with the French Data protection Act (<em>Loi Informatique et Libertés</em>) of January 6th, 1978, you have the right to access, modify, rectify and delete personal information that pertains to you. To exercice this right, please contact %s, and provide your name, address and a proof of your identity.', |
|
145 | + Theme::theme()->contactLink(User::find($wt_tree->getPreference('WEBMASTER_USER_ID')))); |
|
146 | + $html .= '</div>'; |
|
147 | + } |
|
148 | 148 | |
149 | - if($this->getSetting('MAJ_ADD_HTML_FOOTER', 0) == 1){ |
|
150 | - if(Auth::accessLevel($wt_tree) >= $this->getSetting('MAJ_SHOW_HTML_FOOTER', Auth::PRIV_HIDE) && !Filter::getBool('nofooter')){ |
|
151 | - $html .= $this->getSetting('MAJ_HTML_FOOTER', ''); |
|
152 | - } |
|
153 | - } |
|
154 | - return $html; |
|
149 | + if($this->getSetting('MAJ_ADD_HTML_FOOTER', 0) == 1){ |
|
150 | + if(Auth::accessLevel($wt_tree) >= $this->getSetting('MAJ_SHOW_HTML_FOOTER', Auth::PRIV_HIDE) && !Filter::getBool('nofooter')){ |
|
151 | + $html .= $this->getSetting('MAJ_HTML_FOOTER', ''); |
|
152 | + } |
|
153 | + } |
|
154 | + return $html; |
|
155 | 155 | } |
156 | 156 | |
157 | 157 | } |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
64 | 64 | */ |
65 | 65 | public function getConfigLink() { |
66 | - return 'module.php?mod=' . $this->getName() . '&mod_action=AdminConfig'; |
|
66 | + return 'module.php?mod='.$this->getName().'&mod_action=AdminConfig'; |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | /** |
@@ -92,19 +92,19 @@ discard block |
||
92 | 92 | $res = ''; |
93 | 93 | $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
94 | 94 | $titles = $dindi->getTitles(); |
95 | - if(count($titles)>0){ |
|
95 | + if (count($titles) > 0) { |
|
96 | 96 | $res = ' |
97 | 97 | <dl> |
98 | 98 | <dt class="label">'.I18N::translate('Titles').'</dt>'; |
99 | - foreach($titles as $title=>$props){ |
|
99 | + foreach ($titles as $title=>$props) { |
|
100 | 100 | $res .= |
101 | - '<dd class="field">' . $title. ' ' . |
|
102 | - FunctionsPrint::getListFromArray($props) . |
|
101 | + '<dd class="field">'.$title.' '. |
|
102 | + FunctionsPrint::getListFromArray($props). |
|
103 | 103 | '</dd>'; |
104 | 104 | } |
105 | - $res .= '</dl>'; |
|
105 | + $res .= '</dl>'; |
|
106 | 106 | } |
107 | - return array( 'indi-header-titles' , $res); |
|
107 | + return array('indi-header-titles', $res); |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | /** |
@@ -119,8 +119,8 @@ discard block |
||
119 | 119 | */ |
120 | 120 | public function hPrintHeader() { |
121 | 121 | $html = ''; |
122 | - if($this->getSetting('MAJ_ADD_HTML_HEADER', 0) == 1){ |
|
123 | - if(Auth::accessLevel(Globals::getTree()) >= $this->getSetting('MAJ_SHOW_HTML_HEADER', Auth::PRIV_HIDE) && !Filter::getBool('noheader')){ |
|
122 | + if ($this->getSetting('MAJ_ADD_HTML_HEADER', 0) == 1) { |
|
123 | + if (Auth::accessLevel(Globals::getTree()) >= $this->getSetting('MAJ_SHOW_HTML_HEADER', Auth::PRIV_HIDE) && !Filter::getBool('noheader')) { |
|
124 | 124 | $html .= $this->getSetting('MAJ_HTML_HEADER', ''); |
125 | 125 | } |
126 | 126 | } |
@@ -134,11 +134,11 @@ discard block |
||
134 | 134 | public function hPrintFooter() { |
135 | 135 | $wt_tree = Globals::getTree(); |
136 | 136 | $html = ''; |
137 | - if($this->getSetting('MAJ_DISPLAY_CNIL', 0) == 1){ |
|
137 | + if ($this->getSetting('MAJ_DISPLAY_CNIL', 0) == 1) { |
|
138 | 138 | $html .= '<br/>'; |
139 | 139 | $html .= '<div class="center">'; |
140 | 140 | $cnil_ref = $this->getSetting('MAJ_CNIL_REFERENCE', ''); |
141 | - if($cnil_ref != ''){ |
|
141 | + if ($cnil_ref != '') { |
|
142 | 142 | $html .= I18N::translate('This site has been notified to the French National Commission for Data protection (CNIL) and registered under number %s. ', $cnil_ref); |
143 | 143 | } |
144 | 144 | $html .= I18N::translate('In accordance with the French Data protection Act (<em>Loi Informatique et Libertés</em>) of January 6th, 1978, you have the right to access, modify, rectify and delete personal information that pertains to you. To exercice this right, please contact %s, and provide your name, address and a proof of your identity.', |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | $html .= '</div>'; |
147 | 147 | } |
148 | 148 | |
149 | - if($this->getSetting('MAJ_ADD_HTML_FOOTER', 0) == 1){ |
|
150 | - if(Auth::accessLevel($wt_tree) >= $this->getSetting('MAJ_SHOW_HTML_FOOTER', Auth::PRIV_HIDE) && !Filter::getBool('nofooter')){ |
|
149 | + if ($this->getSetting('MAJ_ADD_HTML_FOOTER', 0) == 1) { |
|
150 | + if (Auth::accessLevel($wt_tree) >= $this->getSetting('MAJ_SHOW_HTML_FOOTER', Auth::PRIV_HIDE) && !Filter::getBool('nofooter')) { |
|
151 | 151 | $html .= $this->getSetting('MAJ_HTML_FOOTER', ''); |
152 | 152 | } |
153 | 153 | } |
@@ -16,48 +16,48 @@ |
||
16 | 16 | */ |
17 | 17 | class Globals { |
18 | 18 | |
19 | - /** |
|
20 | - * Get global $WT_TREE variable. |
|
21 | - * |
|
22 | - * @return \Fisharebest\Webtrees\Tree |
|
23 | - */ |
|
24 | - public static function getTree() { |
|
25 | - global $WT_TREE; |
|
19 | + /** |
|
20 | + * Get global $WT_TREE variable. |
|
21 | + * |
|
22 | + * @return \Fisharebest\Webtrees\Tree |
|
23 | + */ |
|
24 | + public static function getTree() { |
|
25 | + global $WT_TREE; |
|
26 | 26 | |
27 | - return $WT_TREE; |
|
28 | - } |
|
27 | + return $WT_TREE; |
|
28 | + } |
|
29 | 29 | |
30 | - /** |
|
31 | - * Check whether the visitor is a bot. |
|
32 | - * |
|
33 | - * @return boolean |
|
34 | - */ |
|
35 | - public static function isSearchSpider() { |
|
36 | - global $SEARCH_SPIDER; |
|
30 | + /** |
|
31 | + * Check whether the visitor is a bot. |
|
32 | + * |
|
33 | + * @return boolean |
|
34 | + */ |
|
35 | + public static function isSearchSpider() { |
|
36 | + global $SEARCH_SPIDER; |
|
37 | 37 | |
38 | - return $SEARCH_SPIDER; |
|
39 | - } |
|
38 | + return $SEARCH_SPIDER; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Get the current controller. |
|
43 | - * |
|
44 | - * @return \Fisharebest\Webtrees\BaseController |
|
45 | - */ |
|
46 | - public static function getController() { |
|
47 | - global $controller; |
|
41 | + /** |
|
42 | + * Get the current controller. |
|
43 | + * |
|
44 | + * @return \Fisharebest\Webtrees\BaseController |
|
45 | + */ |
|
46 | + public static function getController() { |
|
47 | + global $controller; |
|
48 | 48 | |
49 | - return $controller; |
|
50 | - } |
|
49 | + return $controller; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Get the global facts |
|
54 | - * |
|
55 | - * @return array |
|
56 | - */ |
|
57 | - public static function getGlobalFacts() { |
|
58 | - global $global_facts; |
|
52 | + /** |
|
53 | + * Get the global facts |
|
54 | + * |
|
55 | + * @return array |
|
56 | + */ |
|
57 | + public static function getGlobalFacts() { |
|
58 | + global $global_facts; |
|
59 | 59 | |
60 | - return $global_facts; |
|
61 | - } |
|
60 | + return $global_facts; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | } |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | /** |
278 | 278 | * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
279 | 279 | * |
280 | - * @param number $gen Generation |
|
280 | + * @param integer $gen Generation |
|
281 | 281 | * @return array Array of Sosa individuals |
282 | 282 | */ |
283 | 283 | public function getSosaListAtGeneration($gen){ |
@@ -308,7 +308,7 @@ discard block |
||
308 | 308 | /** |
309 | 309 | * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
310 | 310 | * |
311 | - * @param number $gen Generation |
|
311 | + * @param integer $gen Generation |
|
312 | 312 | * @return array Array of Sosa families |
313 | 313 | */ |
314 | 314 | public function getFamilySosaListAtGeneration($gen){ |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | /** |
345 | 345 | * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
346 | 346 | * |
347 | - * @param number $gen Generation |
|
347 | + * @param integer $gen Generation |
|
348 | 348 | * @return array Array of Sosa individuals |
349 | 349 | */ |
350 | 350 | public function getMissingSosaListAtGeneration($gen){ |
@@ -439,8 +439,8 @@ discard block |
||
439 | 439 | /** |
440 | 440 | * Get the number of Sosa in a specific generation. |
441 | 441 | * |
442 | - * @param number $gen Generation |
|
443 | - * @return number Number of Sosas in generation |
|
442 | + * @param integer $gen Generation |
|
443 | + * @return integer Number of Sosas in generation |
|
444 | 444 | */ |
445 | 445 | public function getSosaCountAtGeneration($gen){ |
446 | 446 | if(!$this->is_setup) return 0; |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | /** |
459 | 459 | * Get the total number of Sosa up to a specific generation. |
460 | 460 | * |
461 | - * @param number $gen Generation |
|
461 | + * @param integer $gen Generation |
|
462 | 462 | * @return number Total number of Sosas up to generation |
463 | 463 | */ |
464 | 464 | public function getSosaCountUpToGeneration($gen){ |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | /** |
494 | 494 | * Get the number of distinct Sosa individual up to a specific generation. |
495 | 495 | * |
496 | - * @param number $gen Generation |
|
496 | + * @param integer $gen Generation |
|
497 | 497 | * @return number Number of distinct Sosa individuals up to generation |
498 | 498 | */ |
499 | 499 | public function getDifferentSosaCountUpToGeneration($gen){ |
@@ -516,7 +516,7 @@ discard block |
||
516 | 516 | * - last : Last birth year in generation |
517 | 517 | * - avg : Average birth year |
518 | 518 | * |
519 | - * @param number $gen Generation |
|
519 | + * @param integer $gen Generation |
|
520 | 520 | * @return array Birth statistics array |
521 | 521 | */ |
522 | 522 | public function getStatsBirthYearInGeneration($gen){ |
@@ -622,7 +622,7 @@ discard block |
||
622 | 622 | * - key : root Sosa individual |
623 | 623 | * - value: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
624 | 624 | * |
625 | - * @param number $limit Maximum number of individuals to return |
|
625 | + * @param integer $limit Maximum number of individuals to return |
|
626 | 626 | * @return array |
627 | 627 | */ |
628 | 628 | public function getTopMultiSosaAncestorsNoTies($limit) { |
@@ -22,389 +22,389 @@ discard block |
||
22 | 22 | */ |
23 | 23 | class SosaProvider { |
24 | 24 | |
25 | - /** |
|
26 | - * Maximum number of generation the database is able to hold. |
|
27 | - * @var int MAX_DB_GENERATIONS |
|
28 | - */ |
|
29 | - const MAX_DB_GENERATIONS = 64; |
|
30 | - |
|
31 | - /** |
|
32 | - * System's default user (ID -1 in the database |
|
33 | - * @var User $default_user |
|
34 | - */ |
|
35 | - protected static $default_user; |
|
36 | - |
|
37 | - /** |
|
38 | - * Reference user |
|
39 | - * @var User $user |
|
40 | - */ |
|
41 | - protected $user; |
|
42 | - |
|
43 | - /** |
|
44 | - * Reference tree |
|
45 | - * @var Tree $tree |
|
46 | - */ |
|
47 | - protected $tree; |
|
48 | - |
|
49 | - /** |
|
50 | - * Cached list of Sosa Individuals by generation |
|
51 | - * Format: key = generation, value = array ( sosa => Individual ID) |
|
52 | - * @var array $sosa_list_by_gen |
|
53 | - */ |
|
54 | - protected $sosa_list_by_gen; |
|
55 | - |
|
56 | - /** |
|
57 | - * Cached list of Sosa Families by generation |
|
58 | - * Format: key = generation, value = array ( sosa => Family ID) |
|
59 | - * @var unknown $sosa_fam_list_by_gen |
|
60 | - */ |
|
61 | - protected $sosa_fam_list_by_gen; |
|
62 | - |
|
63 | - /** |
|
64 | - * Cached array of statistics by generation |
|
65 | - * Format: key = generation, |
|
66 | - * value = array( |
|
67 | - * sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth |
|
68 | - * ) |
|
69 | - * @var array $statistics_tab |
|
70 | - */ |
|
71 | - protected $statistics_tab; |
|
72 | - |
|
73 | - /** |
|
74 | - * Has the provider's initialisation completed |
|
75 | - * @var bool $is_setup |
|
76 | - */ |
|
77 | - protected $is_setup; |
|
78 | - |
|
79 | - /** |
|
80 | - * Constructor for Sosa Provider. |
|
81 | - * A provider is defined in relation to a specific tree and reference user. |
|
82 | - * |
|
83 | - * @param Tree $tree |
|
84 | - * @param User $user |
|
85 | - */ |
|
86 | - public function __construct(Tree $tree, User $user = null) { |
|
87 | - if(self::$default_user === null) |
|
88 | - self::$default_user = User::find(-1); |
|
25 | + /** |
|
26 | + * Maximum number of generation the database is able to hold. |
|
27 | + * @var int MAX_DB_GENERATIONS |
|
28 | + */ |
|
29 | + const MAX_DB_GENERATIONS = 64; |
|
30 | + |
|
31 | + /** |
|
32 | + * System's default user (ID -1 in the database |
|
33 | + * @var User $default_user |
|
34 | + */ |
|
35 | + protected static $default_user; |
|
36 | + |
|
37 | + /** |
|
38 | + * Reference user |
|
39 | + * @var User $user |
|
40 | + */ |
|
41 | + protected $user; |
|
42 | + |
|
43 | + /** |
|
44 | + * Reference tree |
|
45 | + * @var Tree $tree |
|
46 | + */ |
|
47 | + protected $tree; |
|
48 | + |
|
49 | + /** |
|
50 | + * Cached list of Sosa Individuals by generation |
|
51 | + * Format: key = generation, value = array ( sosa => Individual ID) |
|
52 | + * @var array $sosa_list_by_gen |
|
53 | + */ |
|
54 | + protected $sosa_list_by_gen; |
|
55 | + |
|
56 | + /** |
|
57 | + * Cached list of Sosa Families by generation |
|
58 | + * Format: key = generation, value = array ( sosa => Family ID) |
|
59 | + * @var unknown $sosa_fam_list_by_gen |
|
60 | + */ |
|
61 | + protected $sosa_fam_list_by_gen; |
|
62 | + |
|
63 | + /** |
|
64 | + * Cached array of statistics by generation |
|
65 | + * Format: key = generation, |
|
66 | + * value = array( |
|
67 | + * sosaCount, sosaTotalCount, diffSosaTotalCount, firstBirth, lastBirth, avgBirth |
|
68 | + * ) |
|
69 | + * @var array $statistics_tab |
|
70 | + */ |
|
71 | + protected $statistics_tab; |
|
72 | + |
|
73 | + /** |
|
74 | + * Has the provider's initialisation completed |
|
75 | + * @var bool $is_setup |
|
76 | + */ |
|
77 | + protected $is_setup; |
|
78 | + |
|
79 | + /** |
|
80 | + * Constructor for Sosa Provider. |
|
81 | + * A provider is defined in relation to a specific tree and reference user. |
|
82 | + * |
|
83 | + * @param Tree $tree |
|
84 | + * @param User $user |
|
85 | + */ |
|
86 | + public function __construct(Tree $tree, User $user = null) { |
|
87 | + if(self::$default_user === null) |
|
88 | + self::$default_user = User::find(-1); |
|
89 | 89 | |
90 | - $this->tree = $tree; |
|
91 | - $this->user = $user; |
|
92 | - $this->is_setup = true; |
|
93 | - if($this->user === null) $this->user = Auth::user(); |
|
94 | - if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
90 | + $this->tree = $tree; |
|
91 | + $this->user = $user; |
|
92 | + $this->is_setup = true; |
|
93 | + if($this->user === null) $this->user = Auth::user(); |
|
94 | + if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
95 | 95 | |
96 | - // Check if the user, or the default user, has a root already setup; |
|
97 | - if(empty($this->getRootIndiId())) { |
|
98 | - if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | - $this->is_setup = false; |
|
100 | - } |
|
101 | - else { |
|
102 | - $this->user = self::$default_user; |
|
103 | - $this->is_setup = $this->getRootIndiId() === null; |
|
104 | - } |
|
105 | - } |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * Returns is the Provider has been successfully set up |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isSetup() { |
|
113 | - return $this->is_setup; |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Return the root individual ID for the reference tree and user. |
|
118 | - * @return string Individual ID |
|
119 | - */ |
|
120 | - public function getRootIndiId() { |
|
121 | - return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | - } |
|
123 | - |
|
124 | - /** |
|
125 | - * Return the root individual for the reference tree and user. |
|
126 | - * @return Individual Individual |
|
127 | - */ |
|
128 | - public function getRootIndi() { |
|
129 | - $root_indi_id = $this->getRootIndiId(); |
|
130 | - if(!empty($root_indi_id)) { |
|
131 | - return Individual::getInstance($root_indi_id, $this->tree); |
|
132 | - } |
|
133 | - return null; |
|
134 | - } |
|
96 | + // Check if the user, or the default user, has a root already setup; |
|
97 | + if(empty($this->getRootIndiId())) { |
|
98 | + if($this->user == self::$default_user) { // If the default user is not setup |
|
99 | + $this->is_setup = false; |
|
100 | + } |
|
101 | + else { |
|
102 | + $this->user = self::$default_user; |
|
103 | + $this->is_setup = $this->getRootIndiId() === null; |
|
104 | + } |
|
105 | + } |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * Returns is the Provider has been successfully set up |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isSetup() { |
|
113 | + return $this->is_setup; |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Return the root individual ID for the reference tree and user. |
|
118 | + * @return string Individual ID |
|
119 | + */ |
|
120 | + public function getRootIndiId() { |
|
121 | + return $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
122 | + } |
|
123 | + |
|
124 | + /** |
|
125 | + * Return the root individual for the reference tree and user. |
|
126 | + * @return Individual Individual |
|
127 | + */ |
|
128 | + public function getRootIndi() { |
|
129 | + $root_indi_id = $this->getRootIndiId(); |
|
130 | + if(!empty($root_indi_id)) { |
|
131 | + return Individual::getInstance($root_indi_id, $this->tree); |
|
132 | + } |
|
133 | + return null; |
|
134 | + } |
|
135 | 135 | |
136 | - /***************** |
|
136 | + /***************** |
|
137 | 137 | * DATA CRUD LAYER |
138 | 138 | *****************/ |
139 | 139 | |
140 | - /** |
|
141 | - * Remove all Sosa entries related to the gedcom file and user |
|
142 | - */ |
|
143 | - public function deleteAll() { |
|
144 | - if(!$this->is_setup) return; |
|
145 | - Database::prepare( |
|
146 | - 'DELETE FROM `##maj_sosa`'. |
|
147 | - ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
148 | - ->execute(array( |
|
149 | - 'tree_id' => $this->tree->getTreeId(), |
|
150 | - 'user_id' => $this->user->getUserId() |
|
151 | - )); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Remove all ancestors of a sosa number |
|
156 | - * |
|
157 | - * @param int $sosa |
|
158 | - */ |
|
159 | - public function deleteAncestors($sosa) { |
|
160 | - if(!$this->is_setup) return; |
|
161 | - $gen = Functions::getGeneration($sosa); |
|
162 | - Database::prepare( |
|
163 | - 'DELETE FROM `##maj_sosa`'. |
|
164 | - ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | - ' AND majs_gen >= :gen' . |
|
166 | - ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
167 | - )->execute(array( |
|
168 | - 'tree_id' => $this->tree->getTreeId(), |
|
169 | - 'user_id' => $this->user->getUserId(), |
|
170 | - 'gen' => $gen, |
|
171 | - 'sosa' => $sosa |
|
172 | - )); |
|
173 | - } |
|
174 | - |
|
175 | - /** |
|
176 | - * Insert (or update if already existing) a list of Sosa individuals |
|
177 | - * @param array $sosa_records |
|
178 | - */ |
|
179 | - public function insertOrUpdate($sosa_records) { |
|
180 | - if(!$this->is_setup) return; |
|
140 | + /** |
|
141 | + * Remove all Sosa entries related to the gedcom file and user |
|
142 | + */ |
|
143 | + public function deleteAll() { |
|
144 | + if(!$this->is_setup) return; |
|
145 | + Database::prepare( |
|
146 | + 'DELETE FROM `##maj_sosa`'. |
|
147 | + ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
|
148 | + ->execute(array( |
|
149 | + 'tree_id' => $this->tree->getTreeId(), |
|
150 | + 'user_id' => $this->user->getUserId() |
|
151 | + )); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Remove all ancestors of a sosa number |
|
156 | + * |
|
157 | + * @param int $sosa |
|
158 | + */ |
|
159 | + public function deleteAncestors($sosa) { |
|
160 | + if(!$this->is_setup) return; |
|
161 | + $gen = Functions::getGeneration($sosa); |
|
162 | + Database::prepare( |
|
163 | + 'DELETE FROM `##maj_sosa`'. |
|
164 | + ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | + ' AND majs_gen >= :gen' . |
|
166 | + ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
|
167 | + )->execute(array( |
|
168 | + 'tree_id' => $this->tree->getTreeId(), |
|
169 | + 'user_id' => $this->user->getUserId(), |
|
170 | + 'gen' => $gen, |
|
171 | + 'sosa' => $sosa |
|
172 | + )); |
|
173 | + } |
|
174 | + |
|
175 | + /** |
|
176 | + * Insert (or update if already existing) a list of Sosa individuals |
|
177 | + * @param array $sosa_records |
|
178 | + */ |
|
179 | + public function insertOrUpdate($sosa_records) { |
|
180 | + if(!$this->is_setup) return; |
|
181 | 181 | |
182 | - $treeid = $this->tree->getTreeId(); |
|
183 | - $userid = $this->user->getUserId(); |
|
184 | - $questionmarks_table = array(); |
|
185 | - $values_table = array(); |
|
182 | + $treeid = $this->tree->getTreeId(); |
|
183 | + $userid = $this->user->getUserId(); |
|
184 | + $questionmarks_table = array(); |
|
185 | + $values_table = array(); |
|
186 | 186 | |
187 | - $i = 0; |
|
188 | - foreach ($sosa_records as $row) { |
|
189 | - $gen = Functions::getGeneration($row['sosa']); |
|
190 | - if($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | - $questionmarks_table[] = |
|
192 | - '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
193 | - $values_table = array_merge( |
|
194 | - $values_table, |
|
195 | - array( |
|
196 | - 'tree_id'.$i => $treeid, |
|
197 | - 'user_id'.$i => $userid, |
|
198 | - 'sosa'.$i => $row['sosa'], |
|
199 | - 'indi_id'.$i => $row['indi'], |
|
200 | - 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
201 | - 'byear'.$i => $row['birth_year'], |
|
202 | - 'dyear'.$i => $row['death_year'] |
|
203 | - ) |
|
204 | - ); |
|
205 | - } |
|
206 | - $i++; |
|
207 | - } |
|
187 | + $i = 0; |
|
188 | + foreach ($sosa_records as $row) { |
|
189 | + $gen = Functions::getGeneration($row['sosa']); |
|
190 | + if($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | + $questionmarks_table[] = |
|
192 | + '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
|
193 | + $values_table = array_merge( |
|
194 | + $values_table, |
|
195 | + array( |
|
196 | + 'tree_id'.$i => $treeid, |
|
197 | + 'user_id'.$i => $userid, |
|
198 | + 'sosa'.$i => $row['sosa'], |
|
199 | + 'indi_id'.$i => $row['indi'], |
|
200 | + 'gen'.$i => Functions::getGeneration($row['sosa']), |
|
201 | + 'byear'.$i => $row['birth_year'], |
|
202 | + 'dyear'.$i => $row['death_year'] |
|
203 | + ) |
|
204 | + ); |
|
205 | + } |
|
206 | + $i++; |
|
207 | + } |
|
208 | 208 | |
209 | - $sql = 'REPLACE INTO `##maj_sosa`' . |
|
210 | - ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
211 | - ' VALUES '. implode(',', $questionmarks_table); |
|
212 | - Database::prepare($sql)->execute($values_table); |
|
213 | - } |
|
209 | + $sql = 'REPLACE INTO `##maj_sosa`' . |
|
210 | + ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_death_year)' . |
|
211 | + ' VALUES '. implode(',', $questionmarks_table); |
|
212 | + Database::prepare($sql)->execute($values_table); |
|
213 | + } |
|
214 | 214 | |
215 | - /**************** |
|
215 | + /**************** |
|
216 | 216 | * SIMPLE QUERIES |
217 | 217 | ****************/ |
218 | 218 | |
219 | - /** |
|
220 | - * Returns the list of Sosa numbers to which an individual is related. |
|
221 | - * Format: key = sosa number, value = generation for the Sosa number |
|
222 | - * |
|
223 | - * @param Individual $indi |
|
224 | - * @return array Array of sosa numbers |
|
225 | - */ |
|
226 | - public function getSosaNumbers(Individual $indi) { |
|
227 | - if(!$this->is_setup) return array(); |
|
228 | - return Database::prepare( |
|
229 | - 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
230 | - ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
231 | - )->execute(array( |
|
232 | - 'indi_id' => $indi->getXref(), |
|
233 | - 'tree_id' => $this->tree->getTreeId(), |
|
234 | - 'user_id' => $this->user->getUserId() |
|
235 | - ))->fetchAssoc(); |
|
236 | - } |
|
237 | - |
|
238 | - /** |
|
239 | - * Get the last generation of Sosa ancestors |
|
240 | - * |
|
241 | - * @return number Last generation if found, 1 otherwise |
|
242 | - */ |
|
243 | - public function getLastGeneration() { |
|
244 | - if(!$this->is_setup) return; |
|
245 | - return Database::prepare( |
|
246 | - 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
247 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
248 | - )->execute(array( |
|
249 | - 'tree_id' => $this->tree->getTreeId(), |
|
250 | - 'user_id' => $this->user->getUserId() |
|
251 | - ))->fetchOne() ?: 1; |
|
252 | - } |
|
253 | - |
|
254 | - /************* |
|
219 | + /** |
|
220 | + * Returns the list of Sosa numbers to which an individual is related. |
|
221 | + * Format: key = sosa number, value = generation for the Sosa number |
|
222 | + * |
|
223 | + * @param Individual $indi |
|
224 | + * @return array Array of sosa numbers |
|
225 | + */ |
|
226 | + public function getSosaNumbers(Individual $indi) { |
|
227 | + if(!$this->is_setup) return array(); |
|
228 | + return Database::prepare( |
|
229 | + 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
230 | + ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
231 | + )->execute(array( |
|
232 | + 'indi_id' => $indi->getXref(), |
|
233 | + 'tree_id' => $this->tree->getTreeId(), |
|
234 | + 'user_id' => $this->user->getUserId() |
|
235 | + ))->fetchAssoc(); |
|
236 | + } |
|
237 | + |
|
238 | + /** |
|
239 | + * Get the last generation of Sosa ancestors |
|
240 | + * |
|
241 | + * @return number Last generation if found, 1 otherwise |
|
242 | + */ |
|
243 | + public function getLastGeneration() { |
|
244 | + if(!$this->is_setup) return; |
|
245 | + return Database::prepare( |
|
246 | + 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
247 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
248 | + )->execute(array( |
|
249 | + 'tree_id' => $this->tree->getTreeId(), |
|
250 | + 'user_id' => $this->user->getUserId() |
|
251 | + ))->fetchOne() ?: 1; |
|
252 | + } |
|
253 | + |
|
254 | + /************* |
|
255 | 255 | * SOSA LISTS |
256 | 256 | *************/ |
257 | 257 | |
258 | - /** |
|
259 | - * Return the list of all sosas, with the generations it belongs to |
|
260 | - * |
|
261 | - * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
262 | - */ |
|
263 | - public function getAllSosaWithGenerations(){ |
|
264 | - if(!$this->is_setup) return array(); |
|
265 | - return Database::prepare( |
|
266 | - 'SELECT majs_i_id AS indi,' . |
|
267 | - ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
268 | - ' FROM `##maj_sosa`' . |
|
269 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
270 | - ' GROUP BY majs_i_id' |
|
271 | - )->execute(array( |
|
272 | - 'tree_id' => $this->tree->getTreeId(), |
|
273 | - 'user_id' => $this->user->getUserId() |
|
274 | - ))->fetchAssoc(); |
|
275 | - } |
|
276 | - |
|
277 | - /** |
|
278 | - * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
279 | - * |
|
280 | - * @param number $gen Generation |
|
281 | - * @return array Array of Sosa individuals |
|
282 | - */ |
|
283 | - public function getSosaListAtGeneration($gen){ |
|
284 | - if(!$this->is_setup) return array(); |
|
285 | - if(!$this->sosa_list_by_gen) |
|
286 | - $this->sosa_list_by_gen = array(); |
|
258 | + /** |
|
259 | + * Return the list of all sosas, with the generations it belongs to |
|
260 | + * |
|
261 | + * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
262 | + */ |
|
263 | + public function getAllSosaWithGenerations(){ |
|
264 | + if(!$this->is_setup) return array(); |
|
265 | + return Database::prepare( |
|
266 | + 'SELECT majs_i_id AS indi,' . |
|
267 | + ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
268 | + ' FROM `##maj_sosa`' . |
|
269 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
270 | + ' GROUP BY majs_i_id' |
|
271 | + )->execute(array( |
|
272 | + 'tree_id' => $this->tree->getTreeId(), |
|
273 | + 'user_id' => $this->user->getUserId() |
|
274 | + ))->fetchAssoc(); |
|
275 | + } |
|
276 | + |
|
277 | + /** |
|
278 | + * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
279 | + * |
|
280 | + * @param number $gen Generation |
|
281 | + * @return array Array of Sosa individuals |
|
282 | + */ |
|
283 | + public function getSosaListAtGeneration($gen){ |
|
284 | + if(!$this->is_setup) return array(); |
|
285 | + if(!$this->sosa_list_by_gen) |
|
286 | + $this->sosa_list_by_gen = array(); |
|
287 | 287 | |
288 | - if($gen){ |
|
289 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
290 | - $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
291 | - 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
292 | - ' FROM `##maj_sosa`'. |
|
293 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
294 | - ' AND majs_gen = :gen'. |
|
295 | - ' ORDER BY majs_sosa ASC') |
|
296 | - ->execute(array( |
|
297 | - 'tree_id' => $this->tree->getTreeId(), |
|
298 | - 'user_id' => $this->user->getUserId(), |
|
299 | - 'gen' => $gen |
|
300 | - )) |
|
301 | - ->fetchAssoc(); |
|
302 | - } |
|
303 | - return $this->sosa_list_by_gen[$gen]; |
|
304 | - } |
|
305 | - return array(); |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
310 | - * |
|
311 | - * @param number $gen Generation |
|
312 | - * @return array Array of Sosa families |
|
313 | - */ |
|
314 | - public function getFamilySosaListAtGeneration($gen){ |
|
315 | - if(!$this->is_setup) return array(); |
|
316 | - if(!$this->sosa_fam_list_by_gen) |
|
317 | - $this->sosa_fam_list_by_gen = array(); |
|
288 | + if($gen){ |
|
289 | + if(!isset($this->sosa_list_by_gen[$gen])){ |
|
290 | + $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
291 | + 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
292 | + ' FROM `##maj_sosa`'. |
|
293 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
294 | + ' AND majs_gen = :gen'. |
|
295 | + ' ORDER BY majs_sosa ASC') |
|
296 | + ->execute(array( |
|
297 | + 'tree_id' => $this->tree->getTreeId(), |
|
298 | + 'user_id' => $this->user->getUserId(), |
|
299 | + 'gen' => $gen |
|
300 | + )) |
|
301 | + ->fetchAssoc(); |
|
302 | + } |
|
303 | + return $this->sosa_list_by_gen[$gen]; |
|
304 | + } |
|
305 | + return array(); |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
310 | + * |
|
311 | + * @param number $gen Generation |
|
312 | + * @return array Array of Sosa families |
|
313 | + */ |
|
314 | + public function getFamilySosaListAtGeneration($gen){ |
|
315 | + if(!$this->is_setup) return array(); |
|
316 | + if(!$this->sosa_fam_list_by_gen) |
|
317 | + $this->sosa_fam_list_by_gen = array(); |
|
318 | 318 | |
319 | - if($gen){ |
|
320 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
321 | - $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
322 | - 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
323 | - ' FROM `##families`'. |
|
324 | - ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
325 | - ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
326 | - ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
327 | - ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
328 | - ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
329 | - ' AND s1.majs_gen = :gen'. |
|
330 | - ' ORDER BY s1.majs_sosa ASC' |
|
331 | - ) |
|
332 | - ->execute(array( |
|
333 | - 'tree_id' => $this->tree->getTreeId(), |
|
334 | - 'user_id' => $this->user->getUserId(), |
|
335 | - 'gen' => $gen |
|
336 | - )) |
|
337 | - ->fetchAssoc(); |
|
338 | - } |
|
339 | - return $this->sosa_fam_list_by_gen[$gen]; |
|
340 | - } |
|
341 | - return array(); |
|
342 | - } |
|
343 | - |
|
344 | - /** |
|
345 | - * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
346 | - * |
|
347 | - * @param number $gen Generation |
|
348 | - * @return array Array of Sosa individuals |
|
349 | - */ |
|
350 | - public function getMissingSosaListAtGeneration($gen){ |
|
351 | - if(!$this->is_setup) return array(); |
|
352 | - if($gen){ |
|
353 | - return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
354 | - 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
|
355 | - ' FROM `##maj_sosa` schild'. |
|
356 | - ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'. |
|
357 | - ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'. |
|
358 | - ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
359 | - ' AND schild.majs_gen = :gen'. |
|
360 | - ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
361 | - ' ORDER BY schild.majs_sosa ASC') |
|
362 | - ->execute(array( |
|
363 | - 'tree_id' => $this->tree->getTreeId(), |
|
364 | - 'user_id' => $this->user->getUserId(), |
|
365 | - 'gen' => $gen - 1 |
|
366 | - ))->fetchAll(\PDO::FETCH_ASSOC); |
|
367 | - } |
|
368 | - return array(); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /************* |
|
319 | + if($gen){ |
|
320 | + if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
321 | + $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
322 | + 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
323 | + ' FROM `##families`'. |
|
324 | + ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
325 | + ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
326 | + ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
327 | + ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
328 | + ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
329 | + ' AND s1.majs_gen = :gen'. |
|
330 | + ' ORDER BY s1.majs_sosa ASC' |
|
331 | + ) |
|
332 | + ->execute(array( |
|
333 | + 'tree_id' => $this->tree->getTreeId(), |
|
334 | + 'user_id' => $this->user->getUserId(), |
|
335 | + 'gen' => $gen |
|
336 | + )) |
|
337 | + ->fetchAssoc(); |
|
338 | + } |
|
339 | + return $this->sosa_fam_list_by_gen[$gen]; |
|
340 | + } |
|
341 | + return array(); |
|
342 | + } |
|
343 | + |
|
344 | + /** |
|
345 | + * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
346 | + * |
|
347 | + * @param number $gen Generation |
|
348 | + * @return array Array of Sosa individuals |
|
349 | + */ |
|
350 | + public function getMissingSosaListAtGeneration($gen){ |
|
351 | + if(!$this->is_setup) return array(); |
|
352 | + if($gen){ |
|
353 | + return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
354 | + 'SELECT schild.majs_sosa sosa, schild.majs_i_id indi, sfat.majs_sosa IS NOT NULL has_father, smot.majs_sosa IS NOT NULL has_mother'. |
|
355 | + ' FROM `##maj_sosa` schild'. |
|
356 | + ' LEFT JOIN `##maj_sosa` sfat ON ((schild.majs_sosa * 2) = sfat.majs_sosa AND schild.majs_gedcom_id = sfat.majs_gedcom_id AND schild.majs_user_id = sfat.majs_user_id)'. |
|
357 | + ' LEFT JOIN `##maj_sosa` smot ON ((schild.majs_sosa * 2 + 1) = smot.majs_sosa AND schild.majs_gedcom_id = smot.majs_gedcom_id AND schild.majs_user_id = smot.majs_user_id)'. |
|
358 | + ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
359 | + ' AND schild.majs_gen = :gen'. |
|
360 | + ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
361 | + ' ORDER BY schild.majs_sosa ASC') |
|
362 | + ->execute(array( |
|
363 | + 'tree_id' => $this->tree->getTreeId(), |
|
364 | + 'user_id' => $this->user->getUserId(), |
|
365 | + 'gen' => $gen - 1 |
|
366 | + ))->fetchAll(\PDO::FETCH_ASSOC); |
|
367 | + } |
|
368 | + return array(); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /************* |
|
374 | 374 | * STATISTICS |
375 | 375 | *************/ |
376 | - /** |
|
377 | - * Get the statistic array detailed by generation. |
|
378 | - * Statistics for each generation are: |
|
379 | - * - The number of Sosa in generation |
|
380 | - * - The number of Sosa up to generation |
|
381 | - * - The number of distinct Sosa up to generation |
|
382 | - * - The year of the first birth in generation |
|
383 | - * - The year of the last birth in generation |
|
384 | - * - The average year of birth in generation |
|
385 | - * |
|
386 | - * @return array Statistics array |
|
387 | - */ |
|
388 | - public function getStatisticsByGeneration() { |
|
389 | - if(!$this->is_setup) return array(); |
|
390 | - if(!$this->statistics_tab) { |
|
391 | - $this->statistics_tab = array(); |
|
392 | - if($maxGeneration = $this->getLastGeneration()) { |
|
393 | - for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
394 | - $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
395 | - $this->statistics_tab[$gen] = array( |
|
396 | - 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
397 | - 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
398 | - 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
399 | - 'firstBirth' => $birthStats['first'], |
|
400 | - 'lastBirth' => $birthStats['last'], |
|
401 | - 'avgBirth' => $birthStats['avg'] |
|
402 | - ); |
|
403 | - } |
|
404 | - } |
|
405 | - } |
|
406 | - return $this->statistics_tab; |
|
407 | - } |
|
376 | + /** |
|
377 | + * Get the statistic array detailed by generation. |
|
378 | + * Statistics for each generation are: |
|
379 | + * - The number of Sosa in generation |
|
380 | + * - The number of Sosa up to generation |
|
381 | + * - The number of distinct Sosa up to generation |
|
382 | + * - The year of the first birth in generation |
|
383 | + * - The year of the last birth in generation |
|
384 | + * - The average year of birth in generation |
|
385 | + * |
|
386 | + * @return array Statistics array |
|
387 | + */ |
|
388 | + public function getStatisticsByGeneration() { |
|
389 | + if(!$this->is_setup) return array(); |
|
390 | + if(!$this->statistics_tab) { |
|
391 | + $this->statistics_tab = array(); |
|
392 | + if($maxGeneration = $this->getLastGeneration()) { |
|
393 | + for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
394 | + $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
395 | + $this->statistics_tab[$gen] = array( |
|
396 | + 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
397 | + 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
398 | + 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
399 | + 'firstBirth' => $birthStats['first'], |
|
400 | + 'lastBirth' => $birthStats['last'], |
|
401 | + 'avgBirth' => $birthStats['avg'] |
|
402 | + ); |
|
403 | + } |
|
404 | + } |
|
405 | + } |
|
406 | + return $this->statistics_tab; |
|
407 | + } |
|
408 | 408 | |
409 | 409 | /** |
410 | 410 | * How many individuals exist in the tree. |
@@ -412,258 +412,258 @@ discard block |
||
412 | 412 | * @return int |
413 | 413 | */ |
414 | 414 | public function getTotalIndividuals() { |
415 | - if(!$this->is_setup) return 0; |
|
416 | - return Database::prepare( |
|
417 | - 'SELECT 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 | + } |
|
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; |
|
421 | 456 | } |
422 | 457 | |
423 | - /** |
|
424 | - * Get the total Sosa count for all generations |
|
425 | - * |
|
426 | - * @return number Number of Sosas |
|
427 | - */ |
|
428 | - public function getSosaCount(){ |
|
429 | - if(!$this->is_setup) return 0; |
|
430 | - return Database::prepare( |
|
431 | - 'SELECT 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 | - |
|
615 | - /** |
|
616 | - * Return an array of the most duplicated root Sosa ancestors. |
|
617 | - * The number of ancestors to return is limited by the parameter $limit. |
|
618 | - * If several individuals are tied when reaching the limit, none of them are returned, |
|
619 | - * which means that there can be less individuals returned than requested. |
|
620 | - * |
|
621 | - * Format: |
|
622 | - * - key : root Sosa individual |
|
623 | - * - value: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
624 | - * |
|
625 | - * @param number $limit Maximum number of individuals to return |
|
626 | - * @return array |
|
627 | - */ |
|
628 | - public function getTopMultiSosaAncestorsNoTies($limit) { |
|
629 | - if(!$this->is_setup) return array(); |
|
630 | - return Database::prepare( |
|
631 | - 'SELECT sosa_i_id, sosa_count FROM ('. |
|
632 | - ' SELECT'. |
|
633 | - ' top_sosa.sosa_i_id, top_sosa.sosa_count, top_sosa.sosa_min,'. |
|
634 | - ' @keep := IF(@prev_count = 0 OR sosa_count = @prev_count, @keep, 1) AS keep,'. |
|
635 | - ' @prev_count := top_sosa.sosa_count AS prev_count'. |
|
636 | - ' FROM ('. |
|
637 | - ' SELECT'. |
|
638 | - ' sosa.majs_i_id sosa_i_id,'. |
|
639 | - ' COUNT(sosa.majs_sosa) sosa_count,'. |
|
640 | - ' MIN(sosa.majs_sosa) sosa_min'. |
|
641 | - ' FROM ##maj_sosa AS sosa'. |
|
642 | - ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'. // Link to sosa's father |
|
643 | - ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
644 | - ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
645 | - ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'. // Link to sosa's mother |
|
646 | - ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
647 | - ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
648 | - ' WHERE sosa.majs_gedcom_id = :tree_id'. |
|
649 | - ' AND sosa.majs_user_id = :user_id'. |
|
650 | - ' AND sosa_fat.majs_sosa IS NULL'. // We keep only root individuals, i.e. those with no father or mother |
|
651 | - ' AND sosa_mot.majs_sosa IS NULL'. |
|
652 | - ' GROUP BY sosa.majs_i_id'. |
|
653 | - ' HAVING COUNT(sosa.majs_sosa) > 1'. // Limit to the duplicate sosas. |
|
654 | - ' ORDER BY COUNT(sosa.majs_sosa) DESC'. |
|
655 | - ' LIMIT ' . ($limit + 1) . // We want to select one more than required |
|
656 | - ' ) AS top_sosa,'. |
|
657 | - ' (SELECT @prev_count := 0, @keep := 0) x'. |
|
658 | - ' ORDER BY top_sosa.sosa_count ASC'. |
|
659 | - ' ) top_sosa_list'. |
|
660 | - ' WHERE keep = 1'. |
|
661 | - ' ORDER BY sosa_count DESC, sosa_min ASC' |
|
662 | - )->execute(array( |
|
663 | - 'tree_id' => $this->tree->getTreeId(), |
|
664 | - 'user_id' => $this->user->getUserId() |
|
665 | - ))->fetchAssoc() ?: array(); |
|
666 | - } |
|
458 | + /** |
|
459 | + * Get the total number of Sosa up to a specific generation. |
|
460 | + * |
|
461 | + * @param number $gen Generation |
|
462 | + * @return number Total number of Sosas up to generation |
|
463 | + */ |
|
464 | + public function getSosaCountUpToGeneration($gen){ |
|
465 | + if(!$this->is_setup) return 0; |
|
466 | + return Database::prepare( |
|
467 | + 'SELECT 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 | + |
|
615 | + /** |
|
616 | + * Return an array of the most duplicated root Sosa ancestors. |
|
617 | + * The number of ancestors to return is limited by the parameter $limit. |
|
618 | + * If several individuals are tied when reaching the limit, none of them are returned, |
|
619 | + * which means that there can be less individuals returned than requested. |
|
620 | + * |
|
621 | + * Format: |
|
622 | + * - key : root Sosa individual |
|
623 | + * - value: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
624 | + * |
|
625 | + * @param number $limit Maximum number of individuals to return |
|
626 | + * @return array |
|
627 | + */ |
|
628 | + public function getTopMultiSosaAncestorsNoTies($limit) { |
|
629 | + if(!$this->is_setup) return array(); |
|
630 | + return Database::prepare( |
|
631 | + 'SELECT sosa_i_id, sosa_count FROM ('. |
|
632 | + ' SELECT'. |
|
633 | + ' top_sosa.sosa_i_id, top_sosa.sosa_count, top_sosa.sosa_min,'. |
|
634 | + ' @keep := IF(@prev_count = 0 OR sosa_count = @prev_count, @keep, 1) AS keep,'. |
|
635 | + ' @prev_count := top_sosa.sosa_count AS prev_count'. |
|
636 | + ' FROM ('. |
|
637 | + ' SELECT'. |
|
638 | + ' sosa.majs_i_id sosa_i_id,'. |
|
639 | + ' COUNT(sosa.majs_sosa) sosa_count,'. |
|
640 | + ' MIN(sosa.majs_sosa) sosa_min'. |
|
641 | + ' FROM ##maj_sosa AS sosa'. |
|
642 | + ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'. // Link to sosa's father |
|
643 | + ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
644 | + ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
645 | + ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'. // Link to sosa's mother |
|
646 | + ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
647 | + ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
648 | + ' WHERE sosa.majs_gedcom_id = :tree_id'. |
|
649 | + ' AND sosa.majs_user_id = :user_id'. |
|
650 | + ' AND sosa_fat.majs_sosa IS NULL'. // We keep only root individuals, i.e. those with no father or mother |
|
651 | + ' AND sosa_mot.majs_sosa IS NULL'. |
|
652 | + ' GROUP BY sosa.majs_i_id'. |
|
653 | + ' HAVING COUNT(sosa.majs_sosa) > 1'. // Limit to the duplicate sosas. |
|
654 | + ' ORDER BY COUNT(sosa.majs_sosa) DESC'. |
|
655 | + ' LIMIT ' . ($limit + 1) . // We want to select one more than required |
|
656 | + ' ) AS top_sosa,'. |
|
657 | + ' (SELECT @prev_count := 0, @keep := 0) x'. |
|
658 | + ' ORDER BY top_sosa.sosa_count ASC'. |
|
659 | + ' ) top_sosa_list'. |
|
660 | + ' WHERE keep = 1'. |
|
661 | + ' ORDER BY sosa_count DESC, sosa_min ASC' |
|
662 | + )->execute(array( |
|
663 | + 'tree_id' => $this->tree->getTreeId(), |
|
664 | + 'user_id' => $this->user->getUserId() |
|
665 | + ))->fetchAssoc() ?: array(); |
|
666 | + } |
|
667 | 667 | |
668 | 668 | |
669 | 669 | } |
@@ -84,18 +84,18 @@ discard block |
||
84 | 84 | * @param User $user |
85 | 85 | */ |
86 | 86 | public function __construct(Tree $tree, User $user = null) { |
87 | - if(self::$default_user === null) |
|
87 | + if (self::$default_user === null) |
|
88 | 88 | self::$default_user = User::find(-1); |
89 | 89 | |
90 | 90 | $this->tree = $tree; |
91 | 91 | $this->user = $user; |
92 | 92 | $this->is_setup = true; |
93 | - if($this->user === null) $this->user = Auth::user(); |
|
94 | - if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
93 | + if ($this->user === null) $this->user = Auth::user(); |
|
94 | + if (strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
95 | 95 | |
96 | 96 | // Check if the user, or the default user, has a root already setup; |
97 | - if(empty($this->getRootIndiId())) { |
|
98 | - if($this->user == self::$default_user) { // If the default user is not setup |
|
97 | + if (empty($this->getRootIndiId())) { |
|
98 | + if ($this->user == self::$default_user) { // If the default user is not setup |
|
99 | 99 | $this->is_setup = false; |
100 | 100 | } |
101 | 101 | else { |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | public function getRootIndi() { |
129 | 129 | $root_indi_id = $this->getRootIndiId(); |
130 | - if(!empty($root_indi_id)) { |
|
130 | + if (!empty($root_indi_id)) { |
|
131 | 131 | return Individual::getInstance($root_indi_id, $this->tree); |
132 | 132 | } |
133 | 133 | return null; |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | * Remove all Sosa entries related to the gedcom file and user |
142 | 142 | */ |
143 | 143 | public function deleteAll() { |
144 | - if(!$this->is_setup) return; |
|
144 | + if (!$this->is_setup) return; |
|
145 | 145 | Database::prepare( |
146 | 146 | 'DELETE FROM `##maj_sosa`'. |
147 | 147 | ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
@@ -157,12 +157,12 @@ discard block |
||
157 | 157 | * @param int $sosa |
158 | 158 | */ |
159 | 159 | public function deleteAncestors($sosa) { |
160 | - if(!$this->is_setup) return; |
|
160 | + if (!$this->is_setup) return; |
|
161 | 161 | $gen = Functions::getGeneration($sosa); |
162 | 162 | Database::prepare( |
163 | 163 | 'DELETE FROM `##maj_sosa`'. |
164 | - ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id' . |
|
165 | - ' AND majs_gen >= :gen' . |
|
164 | + ' WHERE majs_gedcom_id=:tree_id and majs_user_id = :user_id'. |
|
165 | + ' AND majs_gen >= :gen'. |
|
166 | 166 | ' AND FLOOR(majs_sosa / (POW(2, (majs_gen - :gen)))) = :sosa' |
167 | 167 | )->execute(array( |
168 | 168 | 'tree_id' => $this->tree->getTreeId(), |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | * @param array $sosa_records |
178 | 178 | */ |
179 | 179 | public function insertOrUpdate($sosa_records) { |
180 | - if(!$this->is_setup) return; |
|
180 | + if (!$this->is_setup) return; |
|
181 | 181 | |
182 | 182 | $treeid = $this->tree->getTreeId(); |
183 | 183 | $userid = $this->user->getUserId(); |
@@ -185,9 +185,9 @@ discard block |
||
185 | 185 | $values_table = array(); |
186 | 186 | |
187 | 187 | $i = 0; |
188 | - foreach ($sosa_records as $row) { |
|
188 | + foreach ($sosa_records as $row) { |
|
189 | 189 | $gen = Functions::getGeneration($row['sosa']); |
190 | - if($gen <= self::MAX_DB_GENERATIONS) { |
|
190 | + if ($gen <= self::MAX_DB_GENERATIONS) { |
|
191 | 191 | $questionmarks_table[] = |
192 | 192 | '(:tree_id'.$i.', :user_id'.$i.', :sosa'.$i.', :indi_id'.$i.', :gen'.$i.', :byear'.$i.', :dyear'.$i.')'; |
193 | 193 | $values_table = array_merge( |
@@ -206,9 +206,9 @@ discard block |
||
206 | 206 | $i++; |
207 | 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); |
|
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 | 212 | Database::prepare($sql)->execute($values_table); |
213 | 213 | } |
214 | 214 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @return array Array of sosa numbers |
225 | 225 | */ |
226 | 226 | public function getSosaNumbers(Individual $indi) { |
227 | - if(!$this->is_setup) return array(); |
|
227 | + if (!$this->is_setup) return array(); |
|
228 | 228 | return Database::prepare( |
229 | 229 | 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
230 | 230 | ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | * @return number Last generation if found, 1 otherwise |
242 | 242 | */ |
243 | 243 | public function getLastGeneration() { |
244 | - if(!$this->is_setup) return; |
|
244 | + if (!$this->is_setup) return; |
|
245 | 245 | return Database::prepare( |
246 | 246 | 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
247 | 247 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -260,13 +260,13 @@ discard block |
||
260 | 260 | * |
261 | 261 | * @return array Associative array of Sosa ancestors, with their generation, comma separated |
262 | 262 | */ |
263 | - public function getAllSosaWithGenerations(){ |
|
264 | - if(!$this->is_setup) return array(); |
|
263 | + public function getAllSosaWithGenerations() { |
|
264 | + if (!$this->is_setup) return array(); |
|
265 | 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' . |
|
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 | 270 | ' GROUP BY majs_i_id' |
271 | 271 | )->execute(array( |
272 | 272 | 'tree_id' => $this->tree->getTreeId(), |
@@ -280,13 +280,13 @@ discard block |
||
280 | 280 | * @param number $gen Generation |
281 | 281 | * @return array Array of Sosa individuals |
282 | 282 | */ |
283 | - public function getSosaListAtGeneration($gen){ |
|
284 | - if(!$this->is_setup) return array(); |
|
285 | - if(!$this->sosa_list_by_gen) |
|
283 | + public function getSosaListAtGeneration($gen) { |
|
284 | + if (!$this->is_setup) return array(); |
|
285 | + if (!$this->sosa_list_by_gen) |
|
286 | 286 | $this->sosa_list_by_gen = array(); |
287 | 287 | |
288 | - if($gen){ |
|
289 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
288 | + if ($gen) { |
|
289 | + if (!isset($this->sosa_list_by_gen[$gen])) { |
|
290 | 290 | $this->sosa_list_by_gen[$gen] = Database::prepare( |
291 | 291 | 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
292 | 292 | ' FROM `##maj_sosa`'. |
@@ -311,13 +311,13 @@ discard block |
||
311 | 311 | * @param number $gen Generation |
312 | 312 | * @return array Array of Sosa families |
313 | 313 | */ |
314 | - public function getFamilySosaListAtGeneration($gen){ |
|
315 | - if(!$this->is_setup) return array(); |
|
316 | - if(!$this->sosa_fam_list_by_gen) |
|
314 | + public function getFamilySosaListAtGeneration($gen) { |
|
315 | + if (!$this->is_setup) return array(); |
|
316 | + if (!$this->sosa_fam_list_by_gen) |
|
317 | 317 | $this->sosa_fam_list_by_gen = array(); |
318 | 318 | |
319 | - if($gen){ |
|
320 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
319 | + if ($gen) { |
|
320 | + if (!isset($this->sosa_fam_list_by_gen[$gen])) { |
|
321 | 321 | $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
322 | 322 | 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
323 | 323 | ' FROM `##families`'. |
@@ -347,9 +347,9 @@ discard block |
||
347 | 347 | * @param number $gen Generation |
348 | 348 | * @return array Array of Sosa individuals |
349 | 349 | */ |
350 | - public function getMissingSosaListAtGeneration($gen){ |
|
351 | - if(!$this->is_setup) return array(); |
|
352 | - if($gen){ |
|
350 | + public function getMissingSosaListAtGeneration($gen) { |
|
351 | + if (!$this->is_setup) return array(); |
|
352 | + if ($gen) { |
|
353 | 353 | return $this->sosa_list_by_gen[$gen] = Database::prepare( |
354 | 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 | 355 | ' FROM `##maj_sosa` schild'. |
@@ -386,10 +386,10 @@ discard block |
||
386 | 386 | * @return array Statistics array |
387 | 387 | */ |
388 | 388 | public function getStatisticsByGeneration() { |
389 | - if(!$this->is_setup) return array(); |
|
390 | - if(!$this->statistics_tab) { |
|
389 | + if (!$this->is_setup) return array(); |
|
390 | + if (!$this->statistics_tab) { |
|
391 | 391 | $this->statistics_tab = array(); |
392 | - if($maxGeneration = $this->getLastGeneration()) { |
|
392 | + if ($maxGeneration = $this->getLastGeneration()) { |
|
393 | 393 | for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
394 | 394 | $birthStats = $this->getStatsBirthYearInGeneration($gen); |
395 | 395 | $this->statistics_tab[$gen] = array( |
@@ -412,9 +412,9 @@ discard block |
||
412 | 412 | * @return int |
413 | 413 | */ |
414 | 414 | public function getTotalIndividuals() { |
415 | - if(!$this->is_setup) return 0; |
|
415 | + if (!$this->is_setup) return 0; |
|
416 | 416 | return Database::prepare( |
417 | - 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
|
417 | + 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`'. |
|
418 | 418 | ' WHERE i_file = :tree_id') |
419 | 419 | ->execute(array('tree_id' => $this->tree->getTreeId())) |
420 | 420 | ->fetchOne() ?: 0; |
@@ -425,10 +425,10 @@ discard block |
||
425 | 425 | * |
426 | 426 | * @return number Number of Sosas |
427 | 427 | */ |
428 | - public function getSosaCount(){ |
|
429 | - if(!$this->is_setup) return 0; |
|
428 | + public function getSosaCount() { |
|
429 | + if (!$this->is_setup) return 0; |
|
430 | 430 | return Database::prepare( |
431 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
431 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
432 | 432 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
433 | 433 | ->execute(array( |
434 | 434 | 'tree_id' => $this->tree->getTreeId(), |
@@ -442,10 +442,10 @@ discard block |
||
442 | 442 | * @param number $gen Generation |
443 | 443 | * @return number Number of Sosas in generation |
444 | 444 | */ |
445 | - public function getSosaCountAtGeneration($gen){ |
|
446 | - if(!$this->is_setup) return 0; |
|
445 | + public function getSosaCountAtGeneration($gen) { |
|
446 | + if (!$this->is_setup) return 0; |
|
447 | 447 | return Database::prepare( |
448 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
448 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
449 | 449 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
450 | 450 | ' AND majs_gen= :gen') |
451 | 451 | ->execute(array( |
@@ -461,10 +461,10 @@ discard block |
||
461 | 461 | * @param number $gen Generation |
462 | 462 | * @return number Total number of Sosas up to generation |
463 | 463 | */ |
464 | - public function getSosaCountUpToGeneration($gen){ |
|
465 | - if(!$this->is_setup) return 0; |
|
464 | + public function getSosaCountUpToGeneration($gen) { |
|
465 | + if (!$this->is_setup) return 0; |
|
466 | 466 | return Database::prepare( |
467 | - 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
467 | + 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
468 | 468 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
469 | 469 | ' AND majs_gen <= :gen') |
470 | 470 | ->execute(array( |
@@ -479,10 +479,10 @@ discard block |
||
479 | 479 | * |
480 | 480 | * @return number Total number of distinct individual |
481 | 481 | */ |
482 | - public function getDifferentSosaCount(){ |
|
483 | - if(!$this->is_setup) return 0; |
|
482 | + public function getDifferentSosaCount() { |
|
483 | + if (!$this->is_setup) return 0; |
|
484 | 484 | return Database::prepare( |
485 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
485 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'. |
|
486 | 486 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
487 | 487 | ->execute(array( |
488 | 488 | 'tree_id' => $this->tree->getTreeId(), |
@@ -496,10 +496,10 @@ discard block |
||
496 | 496 | * @param number $gen Generation |
497 | 497 | * @return number Number of distinct Sosa individuals up to generation |
498 | 498 | */ |
499 | - public function getDifferentSosaCountUpToGeneration($gen){ |
|
500 | - if(!$this->is_setup) return 0; |
|
499 | + public function getDifferentSosaCountUpToGeneration($gen) { |
|
500 | + if (!$this->is_setup) return 0; |
|
501 | 501 | return Database::prepare( |
502 | - 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
502 | + 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'. |
|
503 | 503 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
504 | 504 | ' AND majs_gen <= :gen') |
505 | 505 | ->execute(array( |
@@ -519,11 +519,11 @@ discard block |
||
519 | 519 | * @param number $gen Generation |
520 | 520 | * @return array Birth statistics array |
521 | 521 | */ |
522 | - public function getStatsBirthYearInGeneration($gen){ |
|
523 | - if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
522 | + public function getStatsBirthYearInGeneration($gen) { |
|
523 | + if (!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
524 | 524 | return Database::prepare( |
525 | 525 | 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
526 | - ' FROM `##maj_sosa`' . |
|
526 | + ' FROM `##maj_sosa`'. |
|
527 | 527 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
528 | 528 | ' AND majs_gen=:gen AND NOT majs_birth_year = :birth_year') |
529 | 529 | ->execute(array( |
@@ -539,26 +539,26 @@ discard block |
||
539 | 539 | * |
540 | 540 | * @return number|NULL Mean generation time |
541 | 541 | */ |
542 | - public function getMeanGenerationTime(){ |
|
543 | - if(!$this->is_setup) return; |
|
544 | - if(!$this->statistics_tab){ |
|
542 | + public function getMeanGenerationTime() { |
|
543 | + if (!$this->is_setup) return; |
|
544 | + if (!$this->statistics_tab) { |
|
545 | 545 | $this->getStatisticsByGeneration(); |
546 | 546 | } |
547 | 547 | //Linear regression on x=generation and y=birthdate |
548 | 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; |
|
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 | 558 | } |
559 | - $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
560 | - if($denom!=0){ |
|
561 | - return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
559 | + $denom = ($n * $sum_x2) - ($sum_x * $sum_x); |
|
560 | + if ($denom != 0) { |
|
561 | + return -(($n * $sum_xy) - ($sum_x * $sum_y)) / ($denom); |
|
562 | 562 | } |
563 | 563 | return null; |
564 | 564 | } |
@@ -586,14 +586,14 @@ discard block |
||
586 | 586 | * @return array |
587 | 587 | */ |
588 | 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 |
|
589 | + if (!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
590 | 590 | return Database::prepare( |
591 | 591 | 'SELECT branches, count(i_id)'. |
592 | 592 | ' FROM ('. |
593 | 593 | ' SELECT i_id,'. |
594 | 594 | ' CASE'. |
595 | 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 |
|
596 | + ' ELSE -1'.// We put all ancestors shared between some branches in the same bucket |
|
597 | 597 | ' END branches'. |
598 | 598 | ' FROM ('. |
599 | 599 | ' SELECT DISTINCT majs_i_id i_id,'. |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | * @return array |
627 | 627 | */ |
628 | 628 | public function getTopMultiSosaAncestorsNoTies($limit) { |
629 | - if(!$this->is_setup) return array(); |
|
629 | + if (!$this->is_setup) return array(); |
|
630 | 630 | return Database::prepare( |
631 | 631 | 'SELECT sosa_i_id, sosa_count FROM ('. |
632 | 632 | ' SELECT'. |
@@ -639,20 +639,20 @@ discard block |
||
639 | 639 | ' COUNT(sosa.majs_sosa) sosa_count,'. |
640 | 640 | ' MIN(sosa.majs_sosa) sosa_min'. |
641 | 641 | ' FROM ##maj_sosa AS sosa'. |
642 | - ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'. // Link to sosa's father |
|
642 | + ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'.// Link to sosa's father |
|
643 | 643 | ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
644 | 644 | ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
645 | - ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'. // Link to sosa's mother |
|
645 | + ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'.// Link to sosa's mother |
|
646 | 646 | ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
647 | 647 | ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
648 | 648 | ' WHERE sosa.majs_gedcom_id = :tree_id'. |
649 | 649 | ' AND sosa.majs_user_id = :user_id'. |
650 | - ' AND sosa_fat.majs_sosa IS NULL'. // We keep only root individuals, i.e. those with no father or mother |
|
650 | + ' AND sosa_fat.majs_sosa IS NULL'.// We keep only root individuals, i.e. those with no father or mother |
|
651 | 651 | ' AND sosa_mot.majs_sosa IS NULL'. |
652 | 652 | ' GROUP BY sosa.majs_i_id'. |
653 | - ' HAVING COUNT(sosa.majs_sosa) > 1'. // Limit to the duplicate sosas. |
|
653 | + ' HAVING COUNT(sosa.majs_sosa) > 1'.// Limit to the duplicate sosas. |
|
654 | 654 | ' ORDER BY COUNT(sosa.majs_sosa) DESC'. |
655 | - ' LIMIT ' . ($limit + 1) . // We want to select one more than required |
|
655 | + ' LIMIT '.($limit + 1).// We want to select one more than required |
|
656 | 656 | ' ) AS top_sosa,'. |
657 | 657 | ' (SELECT @prev_count := 0, @keep := 0) x'. |
658 | 658 | ' ORDER BY top_sosa.sosa_count ASC'. |
@@ -84,21 +84,25 @@ discard block |
||
84 | 84 | * @param User $user |
85 | 85 | */ |
86 | 86 | public function __construct(Tree $tree, User $user = null) { |
87 | - if(self::$default_user === null) |
|
88 | - self::$default_user = User::find(-1); |
|
87 | + if(self::$default_user === null) { |
|
88 | + self::$default_user = User::find(-1); |
|
89 | + } |
|
89 | 90 | |
90 | 91 | $this->tree = $tree; |
91 | 92 | $this->user = $user; |
92 | 93 | $this->is_setup = true; |
93 | - if($this->user === null) $this->user = Auth::user(); |
|
94 | - if(strlen($this->user->getUserId()) == 0) $this->user = self::$default_user; |
|
94 | + if($this->user === null) { |
|
95 | + $this->user = Auth::user(); |
|
96 | + } |
|
97 | + if(strlen($this->user->getUserId()) == 0) { |
|
98 | + $this->user = self::$default_user; |
|
99 | + } |
|
95 | 100 | |
96 | 101 | // Check if the user, or the default user, has a root already setup; |
97 | 102 | if(empty($this->getRootIndiId())) { |
98 | 103 | if($this->user == self::$default_user) { // If the default user is not setup |
99 | 104 | $this->is_setup = false; |
100 | - } |
|
101 | - else { |
|
105 | + } else { |
|
102 | 106 | $this->user = self::$default_user; |
103 | 107 | $this->is_setup = $this->getRootIndiId() === null; |
104 | 108 | } |
@@ -141,7 +145,9 @@ discard block |
||
141 | 145 | * Remove all Sosa entries related to the gedcom file and user |
142 | 146 | */ |
143 | 147 | public function deleteAll() { |
144 | - if(!$this->is_setup) return; |
|
148 | + if(!$this->is_setup) { |
|
149 | + return; |
|
150 | + } |
|
145 | 151 | Database::prepare( |
146 | 152 | 'DELETE FROM `##maj_sosa`'. |
147 | 153 | ' WHERE majs_gedcom_id= :tree_id and majs_user_id = :user_id ') |
@@ -157,7 +163,9 @@ discard block |
||
157 | 163 | * @param int $sosa |
158 | 164 | */ |
159 | 165 | public function deleteAncestors($sosa) { |
160 | - if(!$this->is_setup) return; |
|
166 | + if(!$this->is_setup) { |
|
167 | + return; |
|
168 | + } |
|
161 | 169 | $gen = Functions::getGeneration($sosa); |
162 | 170 | Database::prepare( |
163 | 171 | 'DELETE FROM `##maj_sosa`'. |
@@ -177,7 +185,9 @@ discard block |
||
177 | 185 | * @param array $sosa_records |
178 | 186 | */ |
179 | 187 | public function insertOrUpdate($sosa_records) { |
180 | - if(!$this->is_setup) return; |
|
188 | + if(!$this->is_setup) { |
|
189 | + return; |
|
190 | + } |
|
181 | 191 | |
182 | 192 | $treeid = $this->tree->getTreeId(); |
183 | 193 | $userid = $this->user->getUserId(); |
@@ -224,7 +234,9 @@ discard block |
||
224 | 234 | * @return array Array of sosa numbers |
225 | 235 | */ |
226 | 236 | public function getSosaNumbers(Individual $indi) { |
227 | - if(!$this->is_setup) return array(); |
|
237 | + if(!$this->is_setup) { |
|
238 | + return array(); |
|
239 | + } |
|
228 | 240 | return Database::prepare( |
229 | 241 | 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
230 | 242 | ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -241,7 +253,9 @@ discard block |
||
241 | 253 | * @return number Last generation if found, 1 otherwise |
242 | 254 | */ |
243 | 255 | public function getLastGeneration() { |
244 | - if(!$this->is_setup) return; |
|
256 | + if(!$this->is_setup) { |
|
257 | + return; |
|
258 | + } |
|
245 | 259 | return Database::prepare( |
246 | 260 | 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
247 | 261 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -261,7 +275,9 @@ discard block |
||
261 | 275 | * @return array Associative array of Sosa ancestors, with their generation, comma separated |
262 | 276 | */ |
263 | 277 | public function getAllSosaWithGenerations(){ |
264 | - if(!$this->is_setup) return array(); |
|
278 | + if(!$this->is_setup) { |
|
279 | + return array(); |
|
280 | + } |
|
265 | 281 | return Database::prepare( |
266 | 282 | 'SELECT majs_i_id AS indi,' . |
267 | 283 | ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
@@ -281,9 +297,12 @@ discard block |
||
281 | 297 | * @return array Array of Sosa individuals |
282 | 298 | */ |
283 | 299 | 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(); |
|
300 | + if(!$this->is_setup) { |
|
301 | + return array(); |
|
302 | + } |
|
303 | + if(!$this->sosa_list_by_gen) { |
|
304 | + $this->sosa_list_by_gen = array(); |
|
305 | + } |
|
287 | 306 | |
288 | 307 | if($gen){ |
289 | 308 | if(!isset($this->sosa_list_by_gen[$gen])){ |
@@ -312,9 +331,12 @@ discard block |
||
312 | 331 | * @return array Array of Sosa families |
313 | 332 | */ |
314 | 333 | 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(); |
|
334 | + if(!$this->is_setup) { |
|
335 | + return array(); |
|
336 | + } |
|
337 | + if(!$this->sosa_fam_list_by_gen) { |
|
338 | + $this->sosa_fam_list_by_gen = array(); |
|
339 | + } |
|
318 | 340 | |
319 | 341 | if($gen){ |
320 | 342 | if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
@@ -348,7 +370,9 @@ discard block |
||
348 | 370 | * @return array Array of Sosa individuals |
349 | 371 | */ |
350 | 372 | public function getMissingSosaListAtGeneration($gen){ |
351 | - if(!$this->is_setup) return array(); |
|
373 | + if(!$this->is_setup) { |
|
374 | + return array(); |
|
375 | + } |
|
352 | 376 | if($gen){ |
353 | 377 | return $this->sosa_list_by_gen[$gen] = Database::prepare( |
354 | 378 | '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'. |
@@ -386,7 +410,9 @@ discard block |
||
386 | 410 | * @return array Statistics array |
387 | 411 | */ |
388 | 412 | public function getStatisticsByGeneration() { |
389 | - if(!$this->is_setup) return array(); |
|
413 | + if(!$this->is_setup) { |
|
414 | + return array(); |
|
415 | + } |
|
390 | 416 | if(!$this->statistics_tab) { |
391 | 417 | $this->statistics_tab = array(); |
392 | 418 | if($maxGeneration = $this->getLastGeneration()) { |
@@ -412,7 +438,9 @@ discard block |
||
412 | 438 | * @return int |
413 | 439 | */ |
414 | 440 | public function getTotalIndividuals() { |
415 | - if(!$this->is_setup) return 0; |
|
441 | + if(!$this->is_setup) { |
|
442 | + return 0; |
|
443 | + } |
|
416 | 444 | return Database::prepare( |
417 | 445 | 'SELECT SQL_CACHE COUNT(*) FROM `##individuals`' . |
418 | 446 | ' WHERE i_file = :tree_id') |
@@ -426,7 +454,9 @@ discard block |
||
426 | 454 | * @return number Number of Sosas |
427 | 455 | */ |
428 | 456 | public function getSosaCount(){ |
429 | - if(!$this->is_setup) return 0; |
|
457 | + if(!$this->is_setup) { |
|
458 | + return 0; |
|
459 | + } |
|
430 | 460 | return Database::prepare( |
431 | 461 | 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
432 | 462 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
@@ -443,7 +473,9 @@ discard block |
||
443 | 473 | * @return number Number of Sosas in generation |
444 | 474 | */ |
445 | 475 | public function getSosaCountAtGeneration($gen){ |
446 | - if(!$this->is_setup) return 0; |
|
476 | + if(!$this->is_setup) { |
|
477 | + return 0; |
|
478 | + } |
|
447 | 479 | return Database::prepare( |
448 | 480 | 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
449 | 481 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -462,7 +494,9 @@ discard block |
||
462 | 494 | * @return number Total number of Sosas up to generation |
463 | 495 | */ |
464 | 496 | public function getSosaCountUpToGeneration($gen){ |
465 | - if(!$this->is_setup) return 0; |
|
497 | + if(!$this->is_setup) { |
|
498 | + return 0; |
|
499 | + } |
|
466 | 500 | return Database::prepare( |
467 | 501 | 'SELECT SQL_CACHE COUNT(majs_sosa) FROM `##maj_sosa`' . |
468 | 502 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -480,7 +514,9 @@ discard block |
||
480 | 514 | * @return number Total number of distinct individual |
481 | 515 | */ |
482 | 516 | public function getDifferentSosaCount(){ |
483 | - if(!$this->is_setup) return 0; |
|
517 | + if(!$this->is_setup) { |
|
518 | + return 0; |
|
519 | + } |
|
484 | 520 | return Database::prepare( |
485 | 521 | 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
486 | 522 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
@@ -497,7 +533,9 @@ discard block |
||
497 | 533 | * @return number Number of distinct Sosa individuals up to generation |
498 | 534 | */ |
499 | 535 | public function getDifferentSosaCountUpToGeneration($gen){ |
500 | - if(!$this->is_setup) return 0; |
|
536 | + if(!$this->is_setup) { |
|
537 | + return 0; |
|
538 | + } |
|
501 | 539 | return Database::prepare( |
502 | 540 | 'SELECT SQL_CACHE COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
503 | 541 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -520,7 +558,9 @@ discard block |
||
520 | 558 | * @return array Birth statistics array |
521 | 559 | */ |
522 | 560 | public function getStatsBirthYearInGeneration($gen){ |
523 | - if(!$this->is_setup) return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
561 | + if(!$this->is_setup) { |
|
562 | + return array('first' => 0, 'avg' => 0, 'last' => 0); |
|
563 | + } |
|
524 | 564 | return Database::prepare( |
525 | 565 | 'SELECT MIN(majs_birth_year) AS first, AVG(majs_birth_year) AS avg, MAX(majs_birth_year) AS last'. |
526 | 566 | ' FROM `##maj_sosa`' . |
@@ -540,7 +580,9 @@ discard block |
||
540 | 580 | * @return number|NULL Mean generation time |
541 | 581 | */ |
542 | 582 | public function getMeanGenerationTime(){ |
543 | - if(!$this->is_setup) return; |
|
583 | + if(!$this->is_setup) { |
|
584 | + return; |
|
585 | + } |
|
544 | 586 | if(!$this->statistics_tab){ |
545 | 587 | $this->getStatisticsByGeneration(); |
546 | 588 | } |
@@ -586,7 +628,10 @@ discard block |
||
586 | 628 | * @return array |
587 | 629 | */ |
588 | 630 | 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 |
|
631 | + if(!$this->is_setup || $gen > 11) { |
|
632 | + return array(); |
|
633 | + } |
|
634 | + // Going further than 11 gen will be out of range in the query |
|
590 | 635 | return Database::prepare( |
591 | 636 | 'SELECT branches, count(i_id)'. |
592 | 637 | ' FROM ('. |
@@ -626,7 +671,9 @@ discard block |
||
626 | 671 | * @return array |
627 | 672 | */ |
628 | 673 | public function getTopMultiSosaAncestorsNoTies($limit) { |
629 | - if(!$this->is_setup) return array(); |
|
674 | + if(!$this->is_setup) { |
|
675 | + return array(); |
|
676 | + } |
|
630 | 677 | return Database::prepare( |
631 | 678 | 'SELECT sosa_i_id, sosa_count FROM ('. |
632 | 679 | ' SELECT'. |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * {@inhericDoc} |
24 | 24 | * @see \MyArtJaub\Webtrees\Mvc\View\AbstractView::renderContent() |
25 | 25 | */ |
26 | - protected function renderContent() { |
|
27 | - ?> |
|
26 | + protected function renderContent() { |
|
27 | + ?> |
|
28 | 28 | <div id="maj-sosa-stats-page"> |
29 | 29 | <h2><?php echo $this->data->get('title'); ?></h2> |
30 | 30 | |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | <?php } ?> |
37 | 37 | |
38 | 38 | <?php if($this->data->get('is_setup')) { |
39 | - $general_stats = $this->data->get('general_stats'); ?> |
|
39 | + $general_stats = $this->data->get('general_stats'); ?> |
|
40 | 40 | <h3><?php echo I18N::translate('General statistics'); ?></h3> |
41 | 41 | <div class="maj-table"> |
42 | 42 | <div class="maj-row"> |
@@ -140,13 +140,13 @@ discard block |
||
140 | 140 | <div class="maj-row"> |
141 | 141 | <div class="label"><?= I18N::translate('%s times', I18N::number($count)); ?></div> |
142 | 142 | <div class="value"><?php |
143 | - echo implode( |
|
144 | - I18N::$list_separator, |
|
145 | - array_map(function(Individual $indi) { |
|
146 | - return '<a href="'. $indi->getHtmlUrl(). '">'. $indi->getFullName() . ' ' . $indi->getSexImage() . '</a>'; |
|
147 | - }, $indis) |
|
148 | - ); |
|
149 | - ?></div> |
|
143 | + echo implode( |
|
144 | + I18N::$list_separator, |
|
145 | + array_map(function(Individual $indi) { |
|
146 | + return '<a href="'. $indi->getHtmlUrl(). '">'. $indi->getFullName() . ' ' . $indi->getSexImage() . '</a>'; |
|
147 | + }, $indis) |
|
148 | + ); |
|
149 | + ?></div> |
|
150 | 150 | </div> |
151 | 151 | <?php } ?> |
152 | 152 | </div> |
@@ -162,6 +162,6 @@ discard block |
||
162 | 162 | <?php } else { ?> |
163 | 163 | <div class="center warning"><?php echo I18N::translate('No Sosa root individual has been defined.'); ?></div> |
164 | 164 | <?php } |
165 | - } |
|
165 | + } |
|
166 | 166 | |
167 | 167 | } |
168 | 168 | \ No newline at end of file |
@@ -31,11 +31,11 @@ discard block |
||
31 | 31 | <?php |
32 | 32 | /** @var \Fisharebest\Webtrees\Individual $root_indi */ |
33 | 33 | $root_indi = $this->data->get('root_indi'); |
34 | - if($root_indi !== null && $root_indi->canShowName()) { ?> |
|
34 | + if ($root_indi !== null && $root_indi->canShowName()) { ?> |
|
35 | 35 | <h4 class="center"><?= I18N::translate('%s: %s', I18N::translate('Root individual'), $root_indi->getFullName()); ?><h4> |
36 | 36 | <?php } ?> |
37 | 37 | |
38 | - <?php if($this->data->get('is_setup')) { |
|
38 | + <?php if ($this->data->get('is_setup')) { |
|
39 | 39 | $general_stats = $this->data->get('general_stats'); ?> |
40 | 40 | <h3><?php echo I18N::translate('General statistics'); ?></h3> |
41 | 41 | <div class="maj-table"> |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | </div> |
58 | 58 | <div class="maj-row"> |
59 | 59 | <div class="label"><?php echo I18N::translate('Mean generation time'); ?></div> |
60 | - <div class="value"><?php echo I18N::plural('%s year', '%s years', $general_stats['mean_gen_time'], I18N::number($general_stats['mean_gen_time'], 1)); ?></div> |
|
60 | + <div class="value"><?php echo I18N::plural('%s year', '%s years', $general_stats['mean_gen_time'], I18N::number($general_stats['mean_gen_time'], 1)); ?></div> |
|
61 | 61 | </div> |
62 | 62 | </div> |
63 | 63 | |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | </tr> |
98 | 98 | </thead> |
99 | 99 | <tbody> |
100 | - <?php foreach($this->data->get('generation_stats') as $gen => $row) { ?> |
|
100 | + <?php foreach ($this->data->get('generation_stats') as $gen => $row) { ?> |
|
101 | 101 | <tr class="maj-row"> |
102 | 102 | <td class="label"><?php echo I18N::translate('<strong>G%d</strong>', $gen); ?></td> |
103 | 103 | <td class="label"><?php echo I18N::translate('%1$s <> %2$s', $row['gen_min_birth'], $row['gen_max_birth']); ?></td> |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | <td class="value"><?php echo I18N::number($row['different']); ?></td> |
112 | 112 | <td class="value left percent_container"> |
113 | 113 | <div class="percent_frame"> |
114 | - <div class="percent_cell" style="width:<?php echo 100*$row['perc_different'] ?>%;"> |
|
114 | + <div class="percent_cell" style="width:<?php echo 100 * $row['perc_different'] ?>%;"> |
|
115 | 115 | <?php echo I18N::percentage($row['perc_different']); ?> |
116 | 116 | </div> |
117 | 117 | </div> |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | <tfoot> |
125 | 125 | <tr class="maj-row"> |
126 | 126 | <td class="label" colspan="13"> |
127 | - <?php echo I18N::translate('Generation-equivalent: %s generations', I18N::number($this->data->get('equivalent_gen'),2)); ?> |
|
127 | + <?php echo I18N::translate('Generation-equivalent: %s generations', I18N::number($this->data->get('equivalent_gen'), 2)); ?> |
|
128 | 128 | </td> |
129 | 129 | </tr> |
130 | 130 | </tfoot> |
@@ -133,17 +133,17 @@ discard block |
||
133 | 133 | |
134 | 134 | <?php |
135 | 135 | $top10_multi_ancestors = $this->data->get('top10multiancestors'); |
136 | - if(count($top10_multi_ancestors) > 0) { ?> |
|
136 | + if (count($top10_multi_ancestors) > 0) { ?> |
|
137 | 137 | <h3><?= I18N::translate('Most duplicated root Sosa ancestors'); ?></h3> |
138 | 138 | <div class="maj-table"> |
139 | - <?php foreach($top10_multi_ancestors as $count => $indis) { ?> |
|
139 | + <?php foreach ($top10_multi_ancestors as $count => $indis) { ?> |
|
140 | 140 | <div class="maj-row"> |
141 | 141 | <div class="label"><?= I18N::translate('%s times', I18N::number($count)); ?></div> |
142 | 142 | <div class="value"><?php |
143 | 143 | echo implode( |
144 | 144 | I18N::$list_separator, |
145 | 145 | array_map(function(Individual $indi) { |
146 | - return '<a href="'. $indi->getHtmlUrl(). '">'. $indi->getFullName() . ' ' . $indi->getSexImage() . '</a>'; |
|
146 | + return '<a href="'.$indi->getHtmlUrl().'">'.$indi->getFullName().' '.$indi->getSexImage().'</a>'; |
|
147 | 147 | }, $indis) |
148 | 148 | ); |
149 | 149 | ?></div> |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | |
155 | 155 | <h3><?php echo I18N::translate('Known Sosa ancestors\' family dispersion'); ?></h3> |
156 | 156 | <div class="center"> |
157 | - <?php echo $this->data->get('chart_img_g2') ?: '' ; ?> |
|
158 | - <?php echo $this->data->get('chart_img_g3') ?: '' ; ?> |
|
157 | + <?php echo $this->data->get('chart_img_g2') ?: ''; ?> |
|
158 | + <?php echo $this->data->get('chart_img_g3') ?: ''; ?> |
|
159 | 159 | <!-- <canvas id="chart_ancestors_g2" width="300" height="300"></canvas> --> |
160 | 160 | </div> |
161 | 161 |
@@ -129,11 +129,11 @@ discard block |
||
129 | 129 | * @return string Encryption key |
130 | 130 | */ |
131 | 131 | protected static function getBase64EncryptionKey() { |
132 | - $key = 'STANDARDKEYIFNOSERVER'; |
|
133 | - if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
134 | - $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
132 | + $key = 'STANDARDKEYIFNOSERVER'; |
|
133 | + if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
134 | + $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
135 | 135 | |
136 | - return $key; |
|
136 | + return $key; |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | /** |
@@ -172,20 +172,20 @@ discard block |
||
172 | 172 | throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
173 | 173 | |
174 | 174 | if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) |
175 | - throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
175 | + throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
176 | 176 | |
177 | - $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); |
|
178 | - $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); |
|
177 | + $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); |
|
178 | + $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); |
|
179 | 179 | |
180 | - $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); |
|
180 | + $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); |
|
181 | 181 | |
182 | - if($decrypted === false) { |
|
183 | - throw new \InvalidArgumentException('The message has been tampered with in transit.'); |
|
184 | - } |
|
182 | + if($decrypted === false) { |
|
183 | + throw new \InvalidArgumentException('The message has been tampered with in transit.'); |
|
184 | + } |
|
185 | 185 | |
186 | - //sodium_memzero($encrypted); // Requires PHP 7.2 |
|
186 | + //sodium_memzero($encrypted); // Requires PHP 7.2 |
|
187 | 187 | |
188 | - return $decrypted; |
|
188 | + return $decrypted; |
|
189 | 189 | } |
190 | 190 | |
191 | 191 | /** |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | */ |
197 | 197 | public static function encodeFileSystemToUtf8($string){ |
198 | 198 | if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
199 | - return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
199 | + return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
200 | 200 | } |
201 | 201 | return $string; |
202 | 202 | } |
@@ -261,20 +261,20 @@ discard block |
||
261 | 261 | * @return boolean|string Is supported? |
262 | 262 | */ |
263 | 263 | public static function isImageTypeSupported($reqtype) { |
264 | - $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
|
265 | - $reqtype = strtolower($reqtype); |
|
264 | + $supportByGD = array('jpg'=>'jpeg', 'jpeg'=>'jpeg', 'gif'=>'gif', 'png'=>'png'); |
|
265 | + $reqtype = strtolower($reqtype); |
|
266 | 266 | |
267 | - if (empty($supportByGD[$reqtype])) { |
|
268 | - return false; |
|
269 | - } |
|
267 | + if (empty($supportByGD[$reqtype])) { |
|
268 | + return false; |
|
269 | + } |
|
270 | 270 | |
271 | - $type = $supportByGD[$reqtype]; |
|
271 | + $type = $supportByGD[$reqtype]; |
|
272 | 272 | |
273 | - if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { |
|
274 | - return $type; |
|
275 | - } |
|
273 | + if (function_exists('imagecreatefrom'.$type) && function_exists('image'.$type)) { |
|
274 | + return $type; |
|
275 | + } |
|
276 | 276 | |
277 | - return false; |
|
277 | + return false; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | } |
@@ -32,9 +32,9 @@ discard block |
||
32 | 32 | * |
33 | 33 | * @param string $text Text to display |
34 | 34 | */ |
35 | - static public function promptAlert($text){ |
|
35 | + static public function promptAlert($text) { |
|
36 | 36 | echo '<script>'; |
37 | - echo 'alert("',fw\Filter::escapeHtml($text),'")'; |
|
37 | + echo 'alert("', fw\Filter::escapeHtml($text), '")'; |
|
38 | 38 | echo '</script>'; |
39 | 39 | } |
40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @return float Result of the safe division |
48 | 48 | */ |
49 | 49 | public static function safeDivision($num, $denom, $default = 0) { |
50 | - if($denom && $denom!=0){ |
|
50 | + if ($denom && $denom != 0) { |
|
51 | 51 | return $num / $denom; |
52 | 52 | } |
53 | 53 | return $default; |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | * @param float $default Default value if denominator null or 0 |
62 | 62 | * @return float Percentage |
63 | 63 | */ |
64 | - public static function getPercentage($num, $denom, $default = 0){ |
|
64 | + public static function getPercentage($num, $denom, $default = 0) { |
|
65 | 65 | return 100 * self::safeDivision($num, $denom, $default); |
66 | 66 | } |
67 | 67 | |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | * @param int $target The final max width/height |
73 | 73 | * @return array array of ($width, $height). One of them must be $target |
74 | 74 | */ |
75 | - static public function getResizedImageSize($file, $target=25){ |
|
76 | - list($width, $height, , ) = getimagesize($file); |
|
75 | + static public function getResizedImageSize($file, $target = 25) { |
|
76 | + list($width, $height,,) = getimagesize($file); |
|
77 | 77 | $max = max($width, $height); |
78 | 78 | $rapp = $target / $max; |
79 | 79 | $width = intval($rapp * $width); |
@@ -103,21 +103,21 @@ discard block |
||
103 | 103 | * @param int $length Length of the token, default to 32 |
104 | 104 | * @return string Random token |
105 | 105 | */ |
106 | - public static function generateRandomToken($length=32) { |
|
106 | + public static function generateRandomToken($length = 32) { |
|
107 | 107 | $chars = str_split('abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); |
108 | 108 | $len_chars = count($chars); |
109 | 109 | $token = ''; |
110 | 110 | |
111 | 111 | for ($i = 0; $i < $length; $i++) |
112 | - $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
112 | + $token .= $chars[mt_rand(0, $len_chars - 1)]; |
|
113 | 113 | |
114 | 114 | # Number of 32 char chunks |
115 | - $chunks = ceil( strlen($token) / 32 ); |
|
115 | + $chunks = ceil(strlen($token) / 32); |
|
116 | 116 | $md5token = ''; |
117 | 117 | |
118 | 118 | # Run each chunk through md5 |
119 | - for ( $i=1; $i<=$chunks; $i++ ) |
|
120 | - $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
119 | + for ($i = 1; $i <= $chunks; $i++) |
|
120 | + $md5token .= md5(substr($token, $i * 32 - 32, 32)); |
|
121 | 121 | |
122 | 122 | # Trim the token |
123 | 123 | return substr($md5token, 0, $length); |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | protected static function getBase64EncryptionKey() { |
132 | 132 | $key = 'STANDARDKEYIFNOSERVER'; |
133 | - if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
133 | + if (!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
134 | 134 | $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
135 | 135 | |
136 | 136 | return $key; |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | * @param string $data Text to encrypt |
144 | 144 | * @return string Encrypted and encoded text |
145 | 145 | */ |
146 | - public static function encryptToSafeBase64($data){ |
|
146 | + public static function encryptToSafeBase64($data) { |
|
147 | 147 | $nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES); |
148 | 148 | $id = sodium_crypto_secretbox($data, $nonce, self::getBase64EncryptionKey()); |
149 | 149 | $encrypted = base64_encode($nonce.$id); |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | * @param string $encrypted Text to decrypt |
164 | 164 | * @return string Decrypted text |
165 | 165 | */ |
166 | - public static function decryptFromSafeBase64($encrypted){ |
|
166 | + public static function decryptFromSafeBase64($encrypted) { |
|
167 | 167 | $encrypted = str_replace('-', '+', $encrypted); |
168 | 168 | $encrypted = str_replace('_', '/', $encrypted); |
169 | 169 | $encrypted = str_replace('*', '=', $encrypted); |
170 | 170 | $encrypted = base64_decode($encrypted); |
171 | - if($encrypted === false) |
|
171 | + if ($encrypted === false) |
|
172 | 172 | throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
173 | 173 | |
174 | 174 | if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | |
180 | 180 | $decrypted = sodium_crypto_secretbox_open($ciphertext, $nonce, self::getBase64EncryptionKey()); |
181 | 181 | |
182 | - if($decrypted === false) { |
|
182 | + if ($decrypted === false) { |
|
183 | 183 | throw new \InvalidArgumentException('The message has been tampered with in transit.'); |
184 | 184 | } |
185 | 185 | |
@@ -194,9 +194,9 @@ discard block |
||
194 | 194 | * @param string $string Filesystem encoded string to encode |
195 | 195 | * @return string UTF-8 encoded string |
196 | 196 | */ |
197 | - public static function encodeFileSystemToUtf8($string){ |
|
197 | + public static function encodeFileSystemToUtf8($string) { |
|
198 | 198 | if (strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
199 | - return iconv('cp1252', 'utf-8//IGNORE',$string); |
|
199 | + return iconv('cp1252', 'utf-8//IGNORE', $string); |
|
200 | 200 | } |
201 | 201 | return $string; |
202 | 202 | } |
@@ -207,9 +207,9 @@ discard block |
||
207 | 207 | * @param string $string UTF-8 encoded string to encode |
208 | 208 | * @return string Filesystem encoded string |
209 | 209 | */ |
210 | - public static function encodeUtf8ToFileSystem($string){ |
|
210 | + public static function encodeUtf8ToFileSystem($string) { |
|
211 | 211 | if (preg_match('//u', $string) && strtoupper(substr(php_uname('s'), 0, 7)) === 'WINDOWS') { |
212 | - return iconv('utf-8', 'cp1252//IGNORE' , $string); |
|
212 | + return iconv('utf-8', 'cp1252//IGNORE', $string); |
|
213 | 213 | } |
214 | 214 | return $string; |
215 | 215 | } |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @return boolean True if path valid |
223 | 223 | */ |
224 | 224 | public static function isValidPath($filename, $acceptfolder = FALSE) { |
225 | - if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
225 | + if (strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
226 | 226 | return false; |
227 | 227 | } |
228 | 228 | |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | * @return array Array of month short names |
235 | 235 | */ |
236 | 236 | public static function getCalendarShortMonths($calendarId = 0) { |
237 | - if(!isset(self::$calendarShortMonths[$calendarId])) { |
|
237 | + if (!isset(self::$calendarShortMonths[$calendarId])) { |
|
238 | 238 | $calendar_info = cal_info($calendarId); |
239 | 239 | self::$calendarShortMonths[$calendarId] = $calendar_info['abbrevmonths']; |
240 | 240 | } |
@@ -247,8 +247,8 @@ discard block |
||
247 | 247 | * @param int $sosa Sosa number |
248 | 248 | * @return number |
249 | 249 | */ |
250 | - public static function getGeneration($sosa){ |
|
251 | - return(int)log($sosa, 2)+1; |
|
250 | + public static function getGeneration($sosa) { |
|
251 | + return(int)log($sosa, 2) + 1; |
|
252 | 252 | } |
253 | 253 | |
254 | 254 |
@@ -108,16 +108,18 @@ discard block |
||
108 | 108 | $len_chars = count($chars); |
109 | 109 | $token = ''; |
110 | 110 | |
111 | - for ($i = 0; $i < $length; $i++) |
|
112 | - $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
111 | + for ($i = 0; $i < $length; $i++) { |
|
112 | + $token .= $chars[ mt_rand(0, $len_chars - 1) ]; |
|
113 | + } |
|
113 | 114 | |
114 | 115 | # Number of 32 char chunks |
115 | 116 | $chunks = ceil( strlen($token) / 32 ); |
116 | 117 | $md5token = ''; |
117 | 118 | |
118 | 119 | # Run each chunk through md5 |
119 | - for ( $i=1; $i<=$chunks; $i++ ) |
|
120 | - $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
120 | + for ( $i=1; $i<=$chunks; $i++ ) { |
|
121 | + $md5token .= md5( substr($token, $i * 32 - 32, 32) ); |
|
122 | + } |
|
121 | 123 | |
122 | 124 | # Trim the token |
123 | 125 | return substr($md5token, 0, $length); |
@@ -130,8 +132,9 @@ discard block |
||
130 | 132 | */ |
131 | 133 | protected static function getBase64EncryptionKey() { |
132 | 134 | $key = 'STANDARDKEYIFNOSERVER'; |
133 | - if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) |
|
134 | - $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
135 | + if(!empty(Filter::server('SERVER_NAME')) && !empty(Filter::server('SERVER_SOFTWARE'))) { |
|
136 | + $key = md5(Filter::server('SERVER_NAME').Filter::server('SERVER_SOFTWARE')); |
|
137 | + } |
|
135 | 138 | |
136 | 139 | return $key; |
137 | 140 | } |
@@ -168,11 +171,13 @@ discard block |
||
168 | 171 | $encrypted = str_replace('_', '/', $encrypted); |
169 | 172 | $encrypted = str_replace('*', '=', $encrypted); |
170 | 173 | $encrypted = base64_decode($encrypted); |
171 | - if($encrypted === false) |
|
172 | - throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
|
174 | + if($encrypted === false) { |
|
175 | + throw new \InvalidArgumentException('The encrypted value is not in correct base64 format.'); |
|
176 | + } |
|
173 | 177 | |
174 | - if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) |
|
175 | - throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
178 | + if (mb_strlen($encrypted, '8bit') < (SODIUM_CRYPTO_SECRETBOX_NONCEBYTES + SODIUM_CRYPTO_SECRETBOX_MACBYTES)) { |
|
179 | + throw new \InvalidArgumentException('The encrypted value does not contain enough characters for the key.'); |
|
180 | + } |
|
176 | 181 | |
177 | 182 | $nonce = mb_substr($encrypted, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit'); |
178 | 183 | $ciphertext = mb_substr($encrypted, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit'); |
@@ -222,7 +227,9 @@ discard block |
||
222 | 227 | * @return boolean True if path valid |
223 | 228 | */ |
224 | 229 | public static function isValidPath($filename, $acceptfolder = FALSE) { |
225 | - if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) return true; |
|
230 | + if(strpbrk($filename, $acceptfolder ? '?%*:|"<>' : '\\/?%*:|"<>') === FALSE) { |
|
231 | + return true; |
|
232 | + } |
|
226 | 233 | return false; |
227 | 234 | } |
228 | 235 |