@@ -32,116 +32,116 @@ discard block |
||
32 | 32 | * Sosa Module. |
33 | 33 | */ |
34 | 34 | class SosaModule |
35 | - extends AbstractModule |
|
36 | - implements ModuleMenuInterface, |
|
37 | - ModuleConfigInterface, |
|
38 | - HookSubscriberInterface, |
|
39 | - IndividualHeaderExtenderInterface, |
|
40 | - RecordNameTextExtenderInterface |
|
35 | + extends AbstractModule |
|
36 | + implements ModuleMenuInterface, |
|
37 | + ModuleConfigInterface, |
|
38 | + HookSubscriberInterface, |
|
39 | + IndividualHeaderExtenderInterface, |
|
40 | + RecordNameTextExtenderInterface |
|
41 | 41 | { |
42 | - // How to update the database schema for this module |
|
43 | - const SCHEMA_TARGET_VERSION = 2; |
|
44 | - const SCHEMA_SETTING_NAME = 'MAJ_SOSA_SCHEMA_VERSION'; |
|
45 | - const SCHEMA_MIGRATION_PREFIX = '\MyArtJaub\Webtrees\Module\Sosa\Schema'; |
|
42 | + // How to update the database schema for this module |
|
43 | + const SCHEMA_TARGET_VERSION = 2; |
|
44 | + const SCHEMA_SETTING_NAME = 'MAJ_SOSA_SCHEMA_VERSION'; |
|
45 | + const SCHEMA_MIGRATION_PREFIX = '\MyArtJaub\Webtrees\Module\Sosa\Schema'; |
|
46 | 46 | |
47 | - /** @var string For custom modules - link for support, upgrades, etc. */ |
|
48 | - const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
49 | - |
|
50 | - /** |
|
51 | - * {@inhericDoc} |
|
52 | - */ |
|
53 | - public function getTitle() { |
|
54 | - return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa'); |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * {@inhericDoc} |
|
59 | - */ |
|
60 | - public function getDescription() { |
|
61 | - return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.'); |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * {@inhericDoc} |
|
66 | - */ |
|
67 | - public function modAction($mod_action) { |
|
68 | - Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
47 | + /** @var string For custom modules - link for support, upgrades, etc. */ |
|
48 | + const CUSTOM_WEBSITE = 'https://github.com/jon48/webtrees-lib'; |
|
49 | + |
|
50 | + /** |
|
51 | + * {@inhericDoc} |
|
52 | + */ |
|
53 | + public function getTitle() { |
|
54 | + return /* I18N: Name of the “Sosa” module */ I18N::translate('Sosa'); |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * {@inhericDoc} |
|
59 | + */ |
|
60 | + public function getDescription() { |
|
61 | + return /* I18N: Description of the “Sosa” module */ I18N::translate('Calculate and display Sosa ancestors of the root person.'); |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * {@inhericDoc} |
|
66 | + */ |
|
67 | + public function modAction($mod_action) { |
|
68 | + Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
69 | 69 | |
70 | - \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
71 | - } |
|
70 | + \MyArtJaub\Webtrees\Mvc\Dispatcher::getInstance()->handle($this, $mod_action); |
|
71 | + } |
|
72 | 72 | |
73 | - /********** |
|
73 | + /********** |
|
74 | 74 | * ModuleConfigInterface |
75 | 75 | **********/ |
76 | 76 | |
77 | - /** |
|
78 | - * {@inhericDoc} |
|
79 | - * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
80 | - */ |
|
81 | - public function getConfigLink() { |
|
82 | - Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
77 | + /** |
|
78 | + * {@inhericDoc} |
|
79 | + * @see \Fisharebest\Webtrees\Module\ModuleConfigInterface::getConfigLink() |
|
80 | + */ |
|
81 | + public function getConfigLink() { |
|
82 | + Database::updateSchema(self::SCHEMA_MIGRATION_PREFIX, self::SCHEMA_SETTING_NAME, self::SCHEMA_TARGET_VERSION); |
|
83 | 83 | |
84 | - return 'module.php?mod=' . $this->getName() . '&mod_action=SosaConfig'; |
|
85 | - } |
|
84 | + return 'module.php?mod=' . $this->getName() . '&mod_action=SosaConfig'; |
|
85 | + } |
|
86 | 86 | |
87 | - /********** |
|
87 | + /********** |
|
88 | 88 | * ModuleMenuInterface |
89 | 89 | **********/ |
90 | 90 | |
91 | - /** |
|
92 | - * {@inhericDoc} |
|
93 | - * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder() |
|
94 | - */ |
|
95 | - public function defaultMenuOrder() { |
|
96 | - return 5; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * {@inhericDoc} |
|
101 | - * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu() |
|
102 | - */ |
|
103 | - public function getMenu() { |
|
104 | - $wt_tree = Globals::getTree(); |
|
105 | - $menu = null; |
|
106 | - if(ModuleManager::getInstance()->isOperational($this->getName())) { |
|
91 | + /** |
|
92 | + * {@inhericDoc} |
|
93 | + * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::defaultMenuOrder() |
|
94 | + */ |
|
95 | + public function defaultMenuOrder() { |
|
96 | + return 5; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * {@inhericDoc} |
|
101 | + * @see \Fisharebest\Webtrees\Module\ModuleMenuInterface::getMenu() |
|
102 | + */ |
|
103 | + public function getMenu() { |
|
104 | + $wt_tree = Globals::getTree(); |
|
105 | + $menu = null; |
|
106 | + if(ModuleManager::getInstance()->isOperational($this->getName())) { |
|
107 | 107 | |
108 | - $root_url = 'module.php?mod=' . $this->getName() . '&ged=' . $wt_tree->getNameUrl() . '&'; |
|
109 | - $sosa_stat_menu = new Menu(I18N::translate('Sosa Statistics'), $root_url . 'mod_action=SosaStats', 'menu-maj-sosa-stats'); |
|
108 | + $root_url = 'module.php?mod=' . $this->getName() . '&ged=' . $wt_tree->getNameUrl() . '&'; |
|
109 | + $sosa_stat_menu = new Menu(I18N::translate('Sosa Statistics'), $root_url . 'mod_action=SosaStats', 'menu-maj-sosa-stats'); |
|
110 | 110 | |
111 | - $menu = clone $sosa_stat_menu; |
|
112 | - $menu->setClass('menu-maj-sosa'); |
|
111 | + $menu = clone $sosa_stat_menu; |
|
112 | + $menu->setClass('menu-maj-sosa'); |
|
113 | 113 | |
114 | - $submenus = array_filter(array( |
|
115 | - new Menu(I18N::translate('Sosa Ancestors'), $root_url . 'mod_action=SosaList', 'menu-maj-sosa-list', array('rel' => 'nofollow')), |
|
116 | - new Menu(I18N::translate('Missing Ancestors'), $root_url . 'mod_action=SosaList@missing', 'menu-maj-sosa-missing', array('rel' => 'nofollow')), |
|
117 | - $sosa_stat_menu |
|
118 | - )); |
|
114 | + $submenus = array_filter(array( |
|
115 | + new Menu(I18N::translate('Sosa Ancestors'), $root_url . 'mod_action=SosaList', 'menu-maj-sosa-list', array('rel' => 'nofollow')), |
|
116 | + new Menu(I18N::translate('Missing Ancestors'), $root_url . 'mod_action=SosaList@missing', 'menu-maj-sosa-missing', array('rel' => 'nofollow')), |
|
117 | + $sosa_stat_menu |
|
118 | + )); |
|
119 | 119 | |
120 | 120 | |
121 | - if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_GEODISP_NAME) |
|
122 | - && $ga_list = Module::getModuleByName(Constants::MODULE_MAJ_GEODISP_NAME)->getProvider()->getGeoAnalysisList() |
|
123 | - ) |
|
124 | - { |
|
125 | - if(count($ga_list) > 0) { |
|
126 | - $submenus[] = new Menu(I18N::translate('Geographical Dispersion'), 'module.php?mod=' . Constants::MODULE_MAJ_GEODISP_NAME . '&ged=' . $wt_tree->getNameUrl() . '&mod_action=GeoAnalysis@listAll', 'menu-maj-sosa-geodispersion'); |
|
127 | - } |
|
128 | - } |
|
121 | + if (ModuleManager::getInstance()->isOperational(Constants::MODULE_MAJ_GEODISP_NAME) |
|
122 | + && $ga_list = Module::getModuleByName(Constants::MODULE_MAJ_GEODISP_NAME)->getProvider()->getGeoAnalysisList() |
|
123 | + ) |
|
124 | + { |
|
125 | + if(count($ga_list) > 0) { |
|
126 | + $submenus[] = new Menu(I18N::translate('Geographical Dispersion'), 'module.php?mod=' . Constants::MODULE_MAJ_GEODISP_NAME . '&ged=' . $wt_tree->getNameUrl() . '&mod_action=GeoAnalysis@listAll', 'menu-maj-sosa-geodispersion'); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | |
130 | - if(Auth::check()) { |
|
131 | - $submenus[] = new Menu( |
|
132 | - I18N::translate('Sosa Configuration'), |
|
133 | - $this->getConfigLink(), |
|
134 | - 'menu-maj-sosa-configuration', |
|
135 | - array('rel' => 'nofollow')); |
|
136 | - } |
|
130 | + if(Auth::check()) { |
|
131 | + $submenus[] = new Menu( |
|
132 | + I18N::translate('Sosa Configuration'), |
|
133 | + $this->getConfigLink(), |
|
134 | + 'menu-maj-sosa-configuration', |
|
135 | + array('rel' => 'nofollow')); |
|
136 | + } |
|
137 | 137 | |
138 | - //-- recompute Sosa submenu |
|
139 | - $controller = Globals::getController(); |
|
140 | - if (!empty($controller) && $controller instanceof IndividualController |
|
141 | - && Auth::check() && $wt_tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID') |
|
142 | - ) { |
|
143 | - $controller |
|
144 | - ->addInlineJavascript(' |
|
138 | + //-- recompute Sosa submenu |
|
139 | + $controller = Globals::getController(); |
|
140 | + if (!empty($controller) && $controller instanceof IndividualController |
|
141 | + && Auth::check() && $wt_tree->getUserPreference(Auth::user(), 'MAJ_SOSA_ROOT_ID') |
|
142 | + ) { |
|
143 | + $controller |
|
144 | + ->addInlineJavascript(' |
|
145 | 145 | function majComputeSosaFromIndi(){ |
146 | 146 | if($("#computesosadlg").length == 0) { |
147 | 147 | $("body").append("<div id=\"computesosadlg\" title=\"'. I18N::translate('Sosas computation') .'\"><div id=\"sosaloadingarea\"></div></div>"); |
@@ -164,87 +164,87 @@ discard block |
||
164 | 164 | }); |
165 | 165 | }'); |
166 | 166 | |
167 | - $submenus[] = new Menu( |
|
168 | - I18N::translate('Complete Sosas'), |
|
169 | - '#', |
|
170 | - 'menu-maj-sosa-recompute', |
|
171 | - array( |
|
172 | - 'rel' => 'nofollow', |
|
173 | - 'onclick' => 'return majComputeSosaFromIndi();' |
|
174 | - )); |
|
175 | - } |
|
167 | + $submenus[] = new Menu( |
|
168 | + I18N::translate('Complete Sosas'), |
|
169 | + '#', |
|
170 | + 'menu-maj-sosa-recompute', |
|
171 | + array( |
|
172 | + 'rel' => 'nofollow', |
|
173 | + 'onclick' => 'return majComputeSosaFromIndi();' |
|
174 | + )); |
|
175 | + } |
|
176 | 176 | |
177 | - } |
|
177 | + } |
|
178 | 178 | |
179 | - $menu->setSubmenus($submenus); |
|
179 | + $menu->setSubmenus($submenus); |
|
180 | 180 | |
181 | - return $menu; |
|
181 | + return $menu; |
|
182 | 182 | |
183 | - } |
|
183 | + } |
|
184 | 184 | |
185 | - /********** |
|
185 | + /********** |
|
186 | 186 | * Hooks |
187 | 187 | **********/ |
188 | 188 | |
189 | - /** |
|
190 | - * {@inhericDoc} |
|
191 | - * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
192 | - */ |
|
193 | - public function getSubscribedHooks() { |
|
194 | - return array( |
|
195 | - 'hExtendIndiHeaderIcons' => 20, |
|
196 | - 'hExtendIndiHeaderRight' => 20, |
|
197 | - 'hRecordNameAppend' => 20 |
|
198 | - ); |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * {@inhericDoc} |
|
203 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderIcons() |
|
204 | - */ |
|
205 | - public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) { |
|
206 | - if($ctrlIndi){ |
|
207 | - $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
208 | - return FunctionsPrint::formatSosaNumbers($dindi->getSosaNumbers(), 1, 'large'); |
|
209 | - } |
|
210 | - return ''; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * {@inhericDoc} |
|
215 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderLeft() |
|
216 | - */ |
|
217 | - public function hExtendIndiHeaderLeft(IndividualController $ctrlIndi) { } |
|
218 | - |
|
219 | - /** |
|
220 | - * {@inhericDoc} |
|
221 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderRight() |
|
222 | - */ |
|
223 | - public function hExtendIndiHeaderRight(IndividualController $ctrlIndi) { |
|
224 | - if($ctrlIndi){ |
|
225 | - $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
226 | - return array('indi-header-sosa', FunctionsPrint::formatSosaNumbers($dindi->getSosaNumbers(), 2, 'normal')); |
|
227 | - } |
|
228 | - return ''; |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * {@inhericDoc} |
|
233 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtenderInterface::hRecordNameAppend() |
|
234 | - */ |
|
235 | - public function hRecordNameAppend(GedcomRecord $grec, $size = 'small') { |
|
236 | - if($grec instanceof \Fisharebest\Webtrees\Individual){ // Only apply to individuals |
|
237 | - $dindi = new Individual($grec); |
|
238 | - return FunctionsPrint::formatSosaNumbers($dindi->getSosaNumbers(), 1, $size); |
|
239 | - } |
|
240 | - return ''; |
|
241 | - } |
|
242 | - |
|
243 | - /** |
|
244 | - * {@inhericDoc} |
|
245 | - * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtenderInterface::hRecordNamePrepend() |
|
246 | - */ |
|
247 | - public function hRecordNamePrepend(GedcomRecord $grec, $size) {} |
|
189 | + /** |
|
190 | + * {@inhericDoc} |
|
191 | + * @see \MyArtJaub\Webtrees\Hook\HookSubscriberInterface::getSubscribedHooks() |
|
192 | + */ |
|
193 | + public function getSubscribedHooks() { |
|
194 | + return array( |
|
195 | + 'hExtendIndiHeaderIcons' => 20, |
|
196 | + 'hExtendIndiHeaderRight' => 20, |
|
197 | + 'hRecordNameAppend' => 20 |
|
198 | + ); |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * {@inhericDoc} |
|
203 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderIcons() |
|
204 | + */ |
|
205 | + public function hExtendIndiHeaderIcons(IndividualController $ctrlIndi) { |
|
206 | + if($ctrlIndi){ |
|
207 | + $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
208 | + return FunctionsPrint::formatSosaNumbers($dindi->getSosaNumbers(), 1, 'large'); |
|
209 | + } |
|
210 | + return ''; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * {@inhericDoc} |
|
215 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderLeft() |
|
216 | + */ |
|
217 | + public function hExtendIndiHeaderLeft(IndividualController $ctrlIndi) { } |
|
218 | + |
|
219 | + /** |
|
220 | + * {@inhericDoc} |
|
221 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\IndividualHeaderExtenderInterface::hExtendIndiHeaderRight() |
|
222 | + */ |
|
223 | + public function hExtendIndiHeaderRight(IndividualController $ctrlIndi) { |
|
224 | + if($ctrlIndi){ |
|
225 | + $dindi = new Individual($ctrlIndi->getSignificantIndividual()); |
|
226 | + return array('indi-header-sosa', FunctionsPrint::formatSosaNumbers($dindi->getSosaNumbers(), 2, 'normal')); |
|
227 | + } |
|
228 | + return ''; |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * {@inhericDoc} |
|
233 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtenderInterface::hRecordNameAppend() |
|
234 | + */ |
|
235 | + public function hRecordNameAppend(GedcomRecord $grec, $size = 'small') { |
|
236 | + if($grec instanceof \Fisharebest\Webtrees\Individual){ // Only apply to individuals |
|
237 | + $dindi = new Individual($grec); |
|
238 | + return FunctionsPrint::formatSosaNumbers($dindi->getSosaNumbers(), 1, $size); |
|
239 | + } |
|
240 | + return ''; |
|
241 | + } |
|
242 | + |
|
243 | + /** |
|
244 | + * {@inhericDoc} |
|
245 | + * @see \MyArtJaub\Webtrees\Hook\HookInterfaces\RecordNameTextExtenderInterface::hRecordNamePrepend() |
|
246 | + */ |
|
247 | + public function hRecordNamePrepend(GedcomRecord $grec, $size) {} |
|
248 | 248 | |
249 | 249 | |
250 | 250 |
@@ -27,229 +27,229 @@ |
||
27 | 27 | */ |
28 | 28 | class SosaStatsController extends MvcController |
29 | 29 | { |
30 | - /** |
|
31 | - * Sosa Provider for the controller |
|
32 | - * @var SosaProvider $sosa_provider |
|
33 | - */ |
|
34 | - protected $sosa_provider; |
|
30 | + /** |
|
31 | + * Sosa Provider for the controller |
|
32 | + * @var SosaProvider $sosa_provider |
|
33 | + */ |
|
34 | + protected $sosa_provider; |
|
35 | 35 | |
36 | - /** |
|
37 | - * Constructor for SosaStatsController |
|
38 | - * @param AbstractModule $module |
|
39 | - */ |
|
40 | - public function __construct(AbstractModule $module) { |
|
41 | - parent::__construct($module); |
|
36 | + /** |
|
37 | + * Constructor for SosaStatsController |
|
38 | + * @param AbstractModule $module |
|
39 | + */ |
|
40 | + public function __construct(AbstractModule $module) { |
|
41 | + parent::__construct($module); |
|
42 | 42 | |
43 | - $this->sosa_provider = new SosaProvider(Globals::getTree(), Auth::user()); |
|
44 | - } |
|
43 | + $this->sosa_provider = new SosaProvider(Globals::getTree(), Auth::user()); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * Pages |
|
48 | - */ |
|
46 | + /** |
|
47 | + * Pages |
|
48 | + */ |
|
49 | 49 | |
50 | - /** |
|
51 | - * SosaStats@index |
|
52 | - */ |
|
53 | - public function index() { |
|
54 | - $wt_tree = Globals::getTree(); |
|
55 | - $controller = new PageController(); |
|
56 | - $controller |
|
57 | - ->setPageTitle(I18N::translate('Sosa Statistics')) |
|
58 | - ->addInlineJavascript('$(".help_tooltip").tooltip();') |
|
59 | - ; |
|
50 | + /** |
|
51 | + * SosaStats@index |
|
52 | + */ |
|
53 | + public function index() { |
|
54 | + $wt_tree = Globals::getTree(); |
|
55 | + $controller = new PageController(); |
|
56 | + $controller |
|
57 | + ->setPageTitle(I18N::translate('Sosa Statistics')) |
|
58 | + ->addInlineJavascript('$(".help_tooltip").tooltip();') |
|
59 | + ; |
|
60 | 60 | |
61 | - $view_bag = new ViewBag(); |
|
62 | - $view_bag->set('title', $controller->getPageTitle()); |
|
63 | - $view_bag->set('is_setup', false); |
|
61 | + $view_bag = new ViewBag(); |
|
62 | + $view_bag->set('title', $controller->getPageTitle()); |
|
63 | + $view_bag->set('is_setup', false); |
|
64 | 64 | |
65 | - if($this->sosa_provider->isSetup()) { |
|
66 | - $view_bag->set('is_setup', true); |
|
65 | + if($this->sosa_provider->isSetup()) { |
|
66 | + $view_bag->set('is_setup', true); |
|
67 | 67 | |
68 | - $view_bag->set('root_indi', $this->sosa_provider->getRootIndi()); |
|
68 | + $view_bag->set('root_indi', $this->sosa_provider->getRootIndi()); |
|
69 | 69 | |
70 | - $sosaCount = $this->sosa_provider->getSosaCount(); |
|
71 | - $diffSosaCount = $this->sosa_provider->getDifferentSosaCount(); |
|
70 | + $sosaCount = $this->sosa_provider->getSosaCount(); |
|
71 | + $diffSosaCount = $this->sosa_provider->getDifferentSosaCount(); |
|
72 | 72 | |
73 | - $general_stats = array( |
|
74 | - 'sosa_count' => $sosaCount, |
|
75 | - 'distinct_count' => $diffSosaCount, |
|
76 | - 'sosa_rate' => Functions::safeDivision($diffSosaCount, $this->sosa_provider->getTotalIndividuals()), |
|
77 | - 'pedi_collapse' => 1 - Functions::safeDivision($diffSosaCount, $sosaCount), |
|
78 | - 'mean_gen_time' => $this->sosa_provider->getMeanGenerationTime() |
|
79 | - ); |
|
80 | - $view_bag->set('general_stats', $general_stats); |
|
73 | + $general_stats = array( |
|
74 | + 'sosa_count' => $sosaCount, |
|
75 | + 'distinct_count' => $diffSosaCount, |
|
76 | + 'sosa_rate' => Functions::safeDivision($diffSosaCount, $this->sosa_provider->getTotalIndividuals()), |
|
77 | + 'pedi_collapse' => 1 - Functions::safeDivision($diffSosaCount, $sosaCount), |
|
78 | + 'mean_gen_time' => $this->sosa_provider->getMeanGenerationTime() |
|
79 | + ); |
|
80 | + $view_bag->set('general_stats', $general_stats); |
|
81 | 81 | |
82 | - $stats_gen = $this->sosa_provider->getStatisticsByGeneration(); |
|
83 | - $view_bag->set('missinganc_url', 'module.php?mod='.$this->module->getName().'&mod_action=SosaList@missing&ged='.$wt_tree->getNameUrl().'&gen='); |
|
84 | - $view_bag->set('sosaanc_url', 'module.php?mod='.$this->module->getName().'&mod_action=SosaList&ged='.$wt_tree->getNameUrl().'&gen='); |
|
82 | + $stats_gen = $this->sosa_provider->getStatisticsByGeneration(); |
|
83 | + $view_bag->set('missinganc_url', 'module.php?mod='.$this->module->getName().'&mod_action=SosaList@missing&ged='.$wt_tree->getNameUrl().'&gen='); |
|
84 | + $view_bag->set('sosaanc_url', 'module.php?mod='.$this->module->getName().'&mod_action=SosaList&ged='.$wt_tree->getNameUrl().'&gen='); |
|
85 | 85 | |
86 | - $gen_theoretical=1; |
|
87 | - $total_theoretical=0; |
|
88 | - $prev_diff=0; |
|
89 | - $prev_known=0.5; |
|
90 | - $gen_equiv=0; |
|
91 | - $generation_stats = array(); |
|
86 | + $gen_theoretical=1; |
|
87 | + $total_theoretical=0; |
|
88 | + $prev_diff=0; |
|
89 | + $prev_known=0.5; |
|
90 | + $gen_equiv=0; |
|
91 | + $generation_stats = array(); |
|
92 | 92 | |
93 | - foreach($stats_gen as $gen => $tab){ |
|
94 | - $genY1= I18N::translate('-'); |
|
95 | - $genY2= I18N::translate('-'); |
|
96 | - if($tab['firstBirth']>0) $genY1=$tab['firstEstimatedBirth']; |
|
97 | - if($tab['lastBirth']>0) $genY2=$tab['lastEstimatedBirth']; |
|
98 | - $total_theoretical += $gen_theoretical; |
|
99 | - $perc_sosa_count_theor = Functions::safeDivision($tab['sosaCount'], $gen_theoretical); |
|
100 | - $gen_equiv += $perc_sosa_count_theor; |
|
101 | - $missing=2*$prev_known - $tab['sosaCount']; |
|
102 | - $gen_diff=$tab['diffSosaTotalCount']-$prev_diff; |
|
93 | + foreach($stats_gen as $gen => $tab){ |
|
94 | + $genY1= I18N::translate('-'); |
|
95 | + $genY2= I18N::translate('-'); |
|
96 | + if($tab['firstBirth']>0) $genY1=$tab['firstEstimatedBirth']; |
|
97 | + if($tab['lastBirth']>0) $genY2=$tab['lastEstimatedBirth']; |
|
98 | + $total_theoretical += $gen_theoretical; |
|
99 | + $perc_sosa_count_theor = Functions::safeDivision($tab['sosaCount'], $gen_theoretical); |
|
100 | + $gen_equiv += $perc_sosa_count_theor; |
|
101 | + $missing=2*$prev_known - $tab['sosaCount']; |
|
102 | + $gen_diff=$tab['diffSosaTotalCount']-$prev_diff; |
|
103 | 103 | |
104 | - $generation_stats[$gen] = array( |
|
105 | - 'gen_min_birth' => $genY1, |
|
106 | - 'gen_max_birth' => $genY2, |
|
107 | - 'theoretical' => $gen_theoretical, |
|
108 | - 'known' => $tab['sosaCount'], |
|
109 | - 'perc_known' => $perc_sosa_count_theor, |
|
110 | - 'missing' => $missing, |
|
111 | - 'perc_missing' => 1-Functions::safeDivision($tab['sosaCount'], 2*$prev_known), |
|
112 | - 'total_known' => $tab['sosaTotalCount'], |
|
113 | - 'perc_total_known' => Functions::safeDivision($tab['sosaTotalCount'], $total_theoretical), |
|
114 | - 'different' => $gen_diff, |
|
115 | - 'perc_different' => Functions::safeDivision($gen_diff, $tab['sosaCount']), |
|
116 | - 'total_different' => $tab['diffSosaTotalCount'], |
|
117 | - 'pedi_collapse' => 1 - Functions::safeDivision($tab['diffSosaTotalCount'], $tab['sosaTotalCount']) |
|
118 | - ); |
|
104 | + $generation_stats[$gen] = array( |
|
105 | + 'gen_min_birth' => $genY1, |
|
106 | + 'gen_max_birth' => $genY2, |
|
107 | + 'theoretical' => $gen_theoretical, |
|
108 | + 'known' => $tab['sosaCount'], |
|
109 | + 'perc_known' => $perc_sosa_count_theor, |
|
110 | + 'missing' => $missing, |
|
111 | + 'perc_missing' => 1-Functions::safeDivision($tab['sosaCount'], 2*$prev_known), |
|
112 | + 'total_known' => $tab['sosaTotalCount'], |
|
113 | + 'perc_total_known' => Functions::safeDivision($tab['sosaTotalCount'], $total_theoretical), |
|
114 | + 'different' => $gen_diff, |
|
115 | + 'perc_different' => Functions::safeDivision($gen_diff, $tab['sosaCount']), |
|
116 | + 'total_different' => $tab['diffSosaTotalCount'], |
|
117 | + 'pedi_collapse' => 1 - Functions::safeDivision($tab['diffSosaTotalCount'], $tab['sosaTotalCount']) |
|
118 | + ); |
|
119 | 119 | |
120 | - $gen_theoretical = $gen_theoretical * 2; |
|
121 | - $prev_known=$tab['sosaCount']; |
|
122 | - $prev_diff=$tab['diffSosaTotalCount']; |
|
123 | - } |
|
120 | + $gen_theoretical = $gen_theoretical * 2; |
|
121 | + $prev_known=$tab['sosaCount']; |
|
122 | + $prev_diff=$tab['diffSosaTotalCount']; |
|
123 | + } |
|
124 | 124 | |
125 | - $view_bag->set('generation_stats', $generation_stats); |
|
126 | - $view_bag->set('equivalent_gen', $gen_equiv); |
|
125 | + $view_bag->set('generation_stats', $generation_stats); |
|
126 | + $view_bag->set('equivalent_gen', $gen_equiv); |
|
127 | 127 | |
128 | - $top10multiancestors = $this->sosa_provider->getTopMultiSosaAncestorsNoTies(10); |
|
129 | - $top10ancestors = array(); |
|
130 | - if($top10multiancestors !== null && count($top10multiancestors)) { |
|
131 | - foreach($top10multiancestors as $pid => $count) { |
|
132 | - $indi = Individual::getInstance($pid, $wt_tree); |
|
133 | - if($indi !== null && $indi->canShowName()) { |
|
134 | - array_key_exists($count, $top10ancestors) ? |
|
135 | - $top10ancestors[$count][] = $indi: |
|
136 | - $top10ancestors[$count] = array($count => $indi); |
|
137 | - } |
|
138 | - } |
|
139 | - } |
|
140 | - $view_bag->set('top10multiancestors', $top10ancestors); |
|
128 | + $top10multiancestors = $this->sosa_provider->getTopMultiSosaAncestorsNoTies(10); |
|
129 | + $top10ancestors = array(); |
|
130 | + if($top10multiancestors !== null && count($top10multiancestors)) { |
|
131 | + foreach($top10multiancestors as $pid => $count) { |
|
132 | + $indi = Individual::getInstance($pid, $wt_tree); |
|
133 | + if($indi !== null && $indi->canShowName()) { |
|
134 | + array_key_exists($count, $top10ancestors) ? |
|
135 | + $top10ancestors[$count][] = $indi: |
|
136 | + $top10ancestors[$count] = array($count => $indi); |
|
137 | + } |
|
138 | + } |
|
139 | + } |
|
140 | + $view_bag->set('top10multiancestors', $top10ancestors); |
|
141 | 141 | |
142 | - $view_bag->set('chart_img_g2', $this->htmlAncestorDispersionG2()); |
|
143 | - $view_bag->set('chart_img_g3', $this->htmlAncestorDispersionG3()); |
|
142 | + $view_bag->set('chart_img_g2', $this->htmlAncestorDispersionG2()); |
|
143 | + $view_bag->set('chart_img_g3', $this->htmlAncestorDispersionG3()); |
|
144 | 144 | |
145 | - } |
|
145 | + } |
|
146 | 146 | |
147 | - ViewFactory::make('SosaStats', $this, $controller, $view_bag)->render(); |
|
148 | - } |
|
147 | + ViewFactory::make('SosaStats', $this, $controller, $view_bag)->render(); |
|
148 | + } |
|
149 | 149 | |
150 | - /** |
|
151 | - * Returns HTML code for a graph showing the dispersion of ancestors across father & mother |
|
152 | - * @return string HTML code |
|
153 | - */ |
|
154 | - private function htmlAncestorDispersionG2() |
|
155 | - { |
|
156 | - $ancestorsDispGen2 = $this->sosa_provider->getAncestorDispersionForGen(2); |
|
157 | - if(count($ancestorsDispGen2) == 0) return; |
|
150 | + /** |
|
151 | + * Returns HTML code for a graph showing the dispersion of ancestors across father & mother |
|
152 | + * @return string HTML code |
|
153 | + */ |
|
154 | + private function htmlAncestorDispersionG2() |
|
155 | + { |
|
156 | + $ancestorsDispGen2 = $this->sosa_provider->getAncestorDispersionForGen(2); |
|
157 | + if(count($ancestorsDispGen2) == 0) return; |
|
158 | 158 | |
159 | - $size = '600x300'; |
|
159 | + $size = '600x300'; |
|
160 | 160 | |
161 | - $total = array_sum($ancestorsDispGen2); |
|
162 | - $father_count = array_key_exists(1, $ancestorsDispGen2) ? $ancestorsDispGen2[1] : 0; |
|
163 | - $father = array ( |
|
164 | - 'color' => '84beff', |
|
165 | - 'count' => $father_count, |
|
166 | - 'perc' => Functions::safeDivision($father_count, $total), |
|
167 | - 'name' => \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fat') |
|
168 | - ); |
|
169 | - $mother_count = array_key_exists(2, $ancestorsDispGen2) ? $ancestorsDispGen2[2] : 0; |
|
170 | - $mother = array ( |
|
171 | - 'color' => 'ffd1dc', |
|
172 | - 'count' => $mother_count, |
|
173 | - 'perc' => Functions::safeDivision($mother_count, $total), |
|
174 | - 'name' => \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('mot') |
|
175 | - ); |
|
176 | - $shared_count = array_key_exists(-1, $ancestorsDispGen2) ? $ancestorsDispGen2[-1] : 0; |
|
177 | - $shared = array ( |
|
178 | - 'color' => '777777', |
|
179 | - 'count' => $shared_count, |
|
180 | - 'perc' => Functions::safeDivision($shared_count, $total), |
|
181 | - 'name' => I18N::translate('Shared') |
|
182 | - ); |
|
161 | + $total = array_sum($ancestorsDispGen2); |
|
162 | + $father_count = array_key_exists(1, $ancestorsDispGen2) ? $ancestorsDispGen2[1] : 0; |
|
163 | + $father = array ( |
|
164 | + 'color' => '84beff', |
|
165 | + 'count' => $father_count, |
|
166 | + 'perc' => Functions::safeDivision($father_count, $total), |
|
167 | + 'name' => \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fat') |
|
168 | + ); |
|
169 | + $mother_count = array_key_exists(2, $ancestorsDispGen2) ? $ancestorsDispGen2[2] : 0; |
|
170 | + $mother = array ( |
|
171 | + 'color' => 'ffd1dc', |
|
172 | + 'count' => $mother_count, |
|
173 | + 'perc' => Functions::safeDivision($mother_count, $total), |
|
174 | + 'name' => \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('mot') |
|
175 | + ); |
|
176 | + $shared_count = array_key_exists(-1, $ancestorsDispGen2) ? $ancestorsDispGen2[-1] : 0; |
|
177 | + $shared = array ( |
|
178 | + 'color' => '777777', |
|
179 | + 'count' => $shared_count, |
|
180 | + 'perc' => Functions::safeDivision($shared_count, $total), |
|
181 | + 'name' => I18N::translate('Shared') |
|
182 | + ); |
|
183 | 183 | |
184 | - $chd = $this->arrayToExtendedEncoding(array(4095 * $father['perc'], 4095 * $shared['perc'], 4095 * $mother['perc'])); |
|
185 | - $chart_title = I18N::translate('Known Sosa ancestors\' dispersion'); |
|
186 | - $chl = |
|
187 | - $father['name'] . ' - ' . I18N::percentage($father['perc'], 1) . '|' . |
|
188 | - $shared['name'] . ' - ' . I18N::percentage($shared['perc'], 1) . '|' . |
|
189 | - $mother['name'] . ' - ' . I18N::percentage($mother['perc'], 1); |
|
190 | - return "<img src=\"https://chart.googleapis.com/chart?cht=p&chp=1.5708&chd=e:{$chd}&chs={$size}&chco={$father['color']},{$shared['color']},{$mother['color']}&chf=bg,s,ffffff00&chl={$chl}\" alt=\"" . $chart_title . "\" title=\"" . $chart_title . "\" />"; |
|
191 | - } |
|
184 | + $chd = $this->arrayToExtendedEncoding(array(4095 * $father['perc'], 4095 * $shared['perc'], 4095 * $mother['perc'])); |
|
185 | + $chart_title = I18N::translate('Known Sosa ancestors\' dispersion'); |
|
186 | + $chl = |
|
187 | + $father['name'] . ' - ' . I18N::percentage($father['perc'], 1) . '|' . |
|
188 | + $shared['name'] . ' - ' . I18N::percentage($shared['perc'], 1) . '|' . |
|
189 | + $mother['name'] . ' - ' . I18N::percentage($mother['perc'], 1); |
|
190 | + return "<img src=\"https://chart.googleapis.com/chart?cht=p&chp=1.5708&chd=e:{$chd}&chs={$size}&chco={$father['color']},{$shared['color']},{$mother['color']}&chf=bg,s,ffffff00&chl={$chl}\" alt=\"" . $chart_title . "\" title=\"" . $chart_title . "\" />"; |
|
191 | + } |
|
192 | 192 | |
193 | - /** |
|
194 | - * Returns HTML code for a graph showing the dispersion of ancestors across grand-parents |
|
195 | - * @return string HTML code |
|
196 | - */ |
|
197 | - private function htmlAncestorDispersionG3() |
|
198 | - { |
|
199 | - $ancestorsDispGen2 = $this->sosa_provider->getAncestorDispersionForGen(3); |
|
193 | + /** |
|
194 | + * Returns HTML code for a graph showing the dispersion of ancestors across grand-parents |
|
195 | + * @return string HTML code |
|
196 | + */ |
|
197 | + private function htmlAncestorDispersionG3() |
|
198 | + { |
|
199 | + $ancestorsDispGen2 = $this->sosa_provider->getAncestorDispersionForGen(3); |
|
200 | 200 | |
201 | - $size = '700x300'; |
|
201 | + $size = '700x300'; |
|
202 | 202 | |
203 | - $color_motmot = 'ffd1dc'; |
|
204 | - $color_motfat = 'b998a0'; |
|
205 | - $color_fatfat = '577292'; |
|
206 | - $color_fatmot = '84beff'; |
|
207 | - $color_shared = '777777'; |
|
203 | + $color_motmot = 'ffd1dc'; |
|
204 | + $color_motfat = 'b998a0'; |
|
205 | + $color_fatfat = '577292'; |
|
206 | + $color_fatmot = '84beff'; |
|
207 | + $color_shared = '777777'; |
|
208 | 208 | |
209 | - $total_fatfat = array_key_exists(1, $ancestorsDispGen2) ? $ancestorsDispGen2[1] : 0; |
|
210 | - $total_fatmot = array_key_exists(2, $ancestorsDispGen2) ? $ancestorsDispGen2[2] : 0; |
|
211 | - $total_motfat = array_key_exists(4, $ancestorsDispGen2) ? $ancestorsDispGen2[4] : 0; |
|
212 | - $total_motmot = array_key_exists(8, $ancestorsDispGen2) ? $ancestorsDispGen2[8] : 0; |
|
213 | - $total_sha = array_key_exists(-1, $ancestorsDispGen2) ? $ancestorsDispGen2[-1] : 0; |
|
214 | - $total = $total_fatfat + $total_fatmot + $total_motfat+ $total_motmot + $total_sha; |
|
209 | + $total_fatfat = array_key_exists(1, $ancestorsDispGen2) ? $ancestorsDispGen2[1] : 0; |
|
210 | + $total_fatmot = array_key_exists(2, $ancestorsDispGen2) ? $ancestorsDispGen2[2] : 0; |
|
211 | + $total_motfat = array_key_exists(4, $ancestorsDispGen2) ? $ancestorsDispGen2[4] : 0; |
|
212 | + $total_motmot = array_key_exists(8, $ancestorsDispGen2) ? $ancestorsDispGen2[8] : 0; |
|
213 | + $total_sha = array_key_exists(-1, $ancestorsDispGen2) ? $ancestorsDispGen2[-1] : 0; |
|
214 | + $total = $total_fatfat + $total_fatmot + $total_motfat+ $total_motmot + $total_sha; |
|
215 | 215 | |
216 | - $chd = $this->arrayToExtendedEncoding(array( |
|
217 | - 4095 * Functions::safeDivision($total_fatfat, $total), |
|
218 | - 4095 * Functions::safeDivision($total_fatmot, $total), |
|
219 | - 4095 * Functions::safeDivision($total_sha, $total), |
|
220 | - 4095 * Functions::safeDivision($total_motfat, $total), |
|
221 | - 4095 * Functions::safeDivision($total_motmot, $total) |
|
222 | - )); |
|
223 | - $chart_title = I18N::translate('Known Sosa ancestors\' dispersion - G3'); |
|
224 | - $chl = |
|
225 | - \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fatfat') . ' - ' . I18N::percentage(Functions::safeDivision($total_fatfat, $total), 1) . '|' . |
|
226 | - \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fatmot') . ' - ' . I18N::percentage(Functions::safeDivision($total_fatmot, $total), 1) . '|' . |
|
227 | - I18N::translate('Shared') . ' - ' . I18N::percentage(Functions::safeDivision($total_sha, $total), 1) . '|' . |
|
228 | - \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('motfat') . ' - ' . I18N::percentage(Functions::safeDivision($total_motfat, $total), 1) . '|' . |
|
229 | - \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('motmot') . ' - ' . I18N::percentage(Functions::safeDivision($total_motmot, $total), 1); |
|
230 | - return "<img src=\"https://chart.googleapis.com/chart?cht=p&chp=1.5708&chd=e:{$chd}&chs={$size}&chco={$color_fatfat},{$color_fatmot},{$color_shared},{$color_motfat},{$color_motmot}&chf=bg,s,ffffff00&chl={$chl}\" alt=\"" . $chart_title . "\" title=\"" . $chart_title . "\" />"; |
|
231 | - } |
|
216 | + $chd = $this->arrayToExtendedEncoding(array( |
|
217 | + 4095 * Functions::safeDivision($total_fatfat, $total), |
|
218 | + 4095 * Functions::safeDivision($total_fatmot, $total), |
|
219 | + 4095 * Functions::safeDivision($total_sha, $total), |
|
220 | + 4095 * Functions::safeDivision($total_motfat, $total), |
|
221 | + 4095 * Functions::safeDivision($total_motmot, $total) |
|
222 | + )); |
|
223 | + $chart_title = I18N::translate('Known Sosa ancestors\' dispersion - G3'); |
|
224 | + $chl = |
|
225 | + \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fatfat') . ' - ' . I18N::percentage(Functions::safeDivision($total_fatfat, $total), 1) . '|' . |
|
226 | + \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fatmot') . ' - ' . I18N::percentage(Functions::safeDivision($total_fatmot, $total), 1) . '|' . |
|
227 | + I18N::translate('Shared') . ' - ' . I18N::percentage(Functions::safeDivision($total_sha, $total), 1) . '|' . |
|
228 | + \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('motfat') . ' - ' . I18N::percentage(Functions::safeDivision($total_motfat, $total), 1) . '|' . |
|
229 | + \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('motmot') . ' - ' . I18N::percentage(Functions::safeDivision($total_motmot, $total), 1); |
|
230 | + return "<img src=\"https://chart.googleapis.com/chart?cht=p&chp=1.5708&chd=e:{$chd}&chs={$size}&chco={$color_fatfat},{$color_fatmot},{$color_shared},{$color_motfat},{$color_motmot}&chf=bg,s,ffffff00&chl={$chl}\" alt=\"" . $chart_title . "\" title=\"" . $chart_title . "\" />"; |
|
231 | + } |
|
232 | 232 | |
233 | - /** |
|
234 | - * Convert an array to Google Chart encoding |
|
235 | - * @param arrat $a Array to encode |
|
236 | - * @return string |
|
237 | - */ |
|
238 | - private function arrayToExtendedEncoding($a) { |
|
239 | - $xencoding = WT_GOOGLE_CHART_ENCODING; |
|
233 | + /** |
|
234 | + * Convert an array to Google Chart encoding |
|
235 | + * @param arrat $a Array to encode |
|
236 | + * @return string |
|
237 | + */ |
|
238 | + private function arrayToExtendedEncoding($a) { |
|
239 | + $xencoding = WT_GOOGLE_CHART_ENCODING; |
|
240 | 240 | |
241 | - $encoding = ''; |
|
242 | - foreach ($a as $value) { |
|
243 | - if ($value < 0) { |
|
244 | - $value = 0; |
|
245 | - } |
|
246 | - $first = (int) ($value / 64); |
|
247 | - $second = $value % 64; |
|
248 | - $encoding .= $xencoding[(int) $first] . $xencoding[(int) $second]; |
|
249 | - } |
|
241 | + $encoding = ''; |
|
242 | + foreach ($a as $value) { |
|
243 | + if ($value < 0) { |
|
244 | + $value = 0; |
|
245 | + } |
|
246 | + $first = (int) ($value / 64); |
|
247 | + $second = $value % 64; |
|
248 | + $encoding .= $xencoding[(int) $first] . $xencoding[(int) $second]; |
|
249 | + } |
|
250 | 250 | |
251 | - return $encoding; |
|
252 | - } |
|
251 | + return $encoding; |
|
252 | + } |
|
253 | 253 | |
254 | 254 | |
255 | 255 | } |
256 | 256 | \ No newline at end of file |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $view_bag->set('title', $controller->getPageTitle()); |
63 | 63 | $view_bag->set('is_setup', false); |
64 | 64 | |
65 | - if($this->sosa_provider->isSetup()) { |
|
65 | + if ($this->sosa_provider->isSetup()) { |
|
66 | 66 | $view_bag->set('is_setup', true); |
67 | 67 | |
68 | 68 | $view_bag->set('root_indi', $this->sosa_provider->getRootIndi()); |
@@ -83,23 +83,23 @@ discard block |
||
83 | 83 | $view_bag->set('missinganc_url', 'module.php?mod='.$this->module->getName().'&mod_action=SosaList@missing&ged='.$wt_tree->getNameUrl().'&gen='); |
84 | 84 | $view_bag->set('sosaanc_url', 'module.php?mod='.$this->module->getName().'&mod_action=SosaList&ged='.$wt_tree->getNameUrl().'&gen='); |
85 | 85 | |
86 | - $gen_theoretical=1; |
|
87 | - $total_theoretical=0; |
|
88 | - $prev_diff=0; |
|
89 | - $prev_known=0.5; |
|
90 | - $gen_equiv=0; |
|
86 | + $gen_theoretical = 1; |
|
87 | + $total_theoretical = 0; |
|
88 | + $prev_diff = 0; |
|
89 | + $prev_known = 0.5; |
|
90 | + $gen_equiv = 0; |
|
91 | 91 | $generation_stats = array(); |
92 | 92 | |
93 | - foreach($stats_gen as $gen => $tab){ |
|
94 | - $genY1= I18N::translate('-'); |
|
95 | - $genY2= I18N::translate('-'); |
|
96 | - if($tab['firstBirth']>0) $genY1=$tab['firstEstimatedBirth']; |
|
97 | - if($tab['lastBirth']>0) $genY2=$tab['lastEstimatedBirth']; |
|
93 | + foreach ($stats_gen as $gen => $tab) { |
|
94 | + $genY1 = I18N::translate('-'); |
|
95 | + $genY2 = I18N::translate('-'); |
|
96 | + if ($tab['firstBirth'] > 0) $genY1 = $tab['firstEstimatedBirth']; |
|
97 | + if ($tab['lastBirth'] > 0) $genY2 = $tab['lastEstimatedBirth']; |
|
98 | 98 | $total_theoretical += $gen_theoretical; |
99 | 99 | $perc_sosa_count_theor = Functions::safeDivision($tab['sosaCount'], $gen_theoretical); |
100 | 100 | $gen_equiv += $perc_sosa_count_theor; |
101 | - $missing=2*$prev_known - $tab['sosaCount']; |
|
102 | - $gen_diff=$tab['diffSosaTotalCount']-$prev_diff; |
|
101 | + $missing = 2 * $prev_known - $tab['sosaCount']; |
|
102 | + $gen_diff = $tab['diffSosaTotalCount'] - $prev_diff; |
|
103 | 103 | |
104 | 104 | $generation_stats[$gen] = array( |
105 | 105 | 'gen_min_birth' => $genY1, |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'known' => $tab['sosaCount'], |
109 | 109 | 'perc_known' => $perc_sosa_count_theor, |
110 | 110 | 'missing' => $missing, |
111 | - 'perc_missing' => 1-Functions::safeDivision($tab['sosaCount'], 2*$prev_known), |
|
111 | + 'perc_missing' => 1 - Functions::safeDivision($tab['sosaCount'], 2 * $prev_known), |
|
112 | 112 | 'total_known' => $tab['sosaTotalCount'], |
113 | 113 | 'perc_total_known' => Functions::safeDivision($tab['sosaTotalCount'], $total_theoretical), |
114 | 114 | 'different' => $gen_diff, |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | ); |
119 | 119 | |
120 | 120 | $gen_theoretical = $gen_theoretical * 2; |
121 | - $prev_known=$tab['sosaCount']; |
|
122 | - $prev_diff=$tab['diffSosaTotalCount']; |
|
121 | + $prev_known = $tab['sosaCount']; |
|
122 | + $prev_diff = $tab['diffSosaTotalCount']; |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | $view_bag->set('generation_stats', $generation_stats); |
@@ -127,13 +127,12 @@ discard block |
||
127 | 127 | |
128 | 128 | $top10multiancestors = $this->sosa_provider->getTopMultiSosaAncestorsNoTies(10); |
129 | 129 | $top10ancestors = array(); |
130 | - if($top10multiancestors !== null && count($top10multiancestors)) { |
|
131 | - foreach($top10multiancestors as $pid => $count) { |
|
130 | + if ($top10multiancestors !== null && count($top10multiancestors)) { |
|
131 | + foreach ($top10multiancestors as $pid => $count) { |
|
132 | 132 | $indi = Individual::getInstance($pid, $wt_tree); |
133 | - if($indi !== null && $indi->canShowName()) { |
|
133 | + if ($indi !== null && $indi->canShowName()) { |
|
134 | 134 | array_key_exists($count, $top10ancestors) ? |
135 | - $top10ancestors[$count][] = $indi: |
|
136 | - $top10ancestors[$count] = array($count => $indi); |
|
135 | + $top10ancestors[$count][] = $indi : $top10ancestors[$count] = array($count => $indi); |
|
137 | 136 | } |
138 | 137 | } |
139 | 138 | } |
@@ -154,27 +153,27 @@ discard block |
||
154 | 153 | private function htmlAncestorDispersionG2() |
155 | 154 | { |
156 | 155 | $ancestorsDispGen2 = $this->sosa_provider->getAncestorDispersionForGen(2); |
157 | - if(count($ancestorsDispGen2) == 0) return; |
|
156 | + if (count($ancestorsDispGen2) == 0) return; |
|
158 | 157 | |
159 | 158 | $size = '600x300'; |
160 | 159 | |
161 | 160 | $total = array_sum($ancestorsDispGen2); |
162 | 161 | $father_count = array_key_exists(1, $ancestorsDispGen2) ? $ancestorsDispGen2[1] : 0; |
163 | - $father = array ( |
|
162 | + $father = array( |
|
164 | 163 | 'color' => '84beff', |
165 | 164 | 'count' => $father_count, |
166 | 165 | 'perc' => Functions::safeDivision($father_count, $total), |
167 | 166 | 'name' => \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fat') |
168 | 167 | ); |
169 | 168 | $mother_count = array_key_exists(2, $ancestorsDispGen2) ? $ancestorsDispGen2[2] : 0; |
170 | - $mother = array ( |
|
169 | + $mother = array( |
|
171 | 170 | 'color' => 'ffd1dc', |
172 | 171 | 'count' => $mother_count, |
173 | 172 | 'perc' => Functions::safeDivision($mother_count, $total), |
174 | 173 | 'name' => \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('mot') |
175 | 174 | ); |
176 | 175 | $shared_count = array_key_exists(-1, $ancestorsDispGen2) ? $ancestorsDispGen2[-1] : 0; |
177 | - $shared = array ( |
|
176 | + $shared = array( |
|
178 | 177 | 'color' => '777777', |
179 | 178 | 'count' => $shared_count, |
180 | 179 | 'perc' => Functions::safeDivision($shared_count, $total), |
@@ -184,10 +183,10 @@ discard block |
||
184 | 183 | $chd = $this->arrayToExtendedEncoding(array(4095 * $father['perc'], 4095 * $shared['perc'], 4095 * $mother['perc'])); |
185 | 184 | $chart_title = I18N::translate('Known Sosa ancestors\' dispersion'); |
186 | 185 | $chl = |
187 | - $father['name'] . ' - ' . I18N::percentage($father['perc'], 1) . '|' . |
|
188 | - $shared['name'] . ' - ' . I18N::percentage($shared['perc'], 1) . '|' . |
|
189 | - $mother['name'] . ' - ' . I18N::percentage($mother['perc'], 1); |
|
190 | - return "<img src=\"https://chart.googleapis.com/chart?cht=p&chp=1.5708&chd=e:{$chd}&chs={$size}&chco={$father['color']},{$shared['color']},{$mother['color']}&chf=bg,s,ffffff00&chl={$chl}\" alt=\"" . $chart_title . "\" title=\"" . $chart_title . "\" />"; |
|
186 | + $father['name'].' - '.I18N::percentage($father['perc'], 1).'|'. |
|
187 | + $shared['name'].' - '.I18N::percentage($shared['perc'], 1).'|'. |
|
188 | + $mother['name'].' - '.I18N::percentage($mother['perc'], 1); |
|
189 | + return "<img src=\"https://chart.googleapis.com/chart?cht=p&chp=1.5708&chd=e:{$chd}&chs={$size}&chco={$father['color']},{$shared['color']},{$mother['color']}&chf=bg,s,ffffff00&chl={$chl}\" alt=\"".$chart_title."\" title=\"".$chart_title."\" />"; |
|
191 | 190 | } |
192 | 191 | |
193 | 192 | /** |
@@ -211,7 +210,7 @@ discard block |
||
211 | 210 | $total_motfat = array_key_exists(4, $ancestorsDispGen2) ? $ancestorsDispGen2[4] : 0; |
212 | 211 | $total_motmot = array_key_exists(8, $ancestorsDispGen2) ? $ancestorsDispGen2[8] : 0; |
213 | 212 | $total_sha = array_key_exists(-1, $ancestorsDispGen2) ? $ancestorsDispGen2[-1] : 0; |
214 | - $total = $total_fatfat + $total_fatmot + $total_motfat+ $total_motmot + $total_sha; |
|
213 | + $total = $total_fatfat + $total_fatmot + $total_motfat + $total_motmot + $total_sha; |
|
215 | 214 | |
216 | 215 | $chd = $this->arrayToExtendedEncoding(array( |
217 | 216 | 4095 * Functions::safeDivision($total_fatfat, $total), |
@@ -222,12 +221,12 @@ discard block |
||
222 | 221 | )); |
223 | 222 | $chart_title = I18N::translate('Known Sosa ancestors\' dispersion - G3'); |
224 | 223 | $chl = |
225 | - \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fatfat') . ' - ' . I18N::percentage(Functions::safeDivision($total_fatfat, $total), 1) . '|' . |
|
226 | - \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fatmot') . ' - ' . I18N::percentage(Functions::safeDivision($total_fatmot, $total), 1) . '|' . |
|
227 | - I18N::translate('Shared') . ' - ' . I18N::percentage(Functions::safeDivision($total_sha, $total), 1) . '|' . |
|
228 | - \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('motfat') . ' - ' . I18N::percentage(Functions::safeDivision($total_motfat, $total), 1) . '|' . |
|
229 | - \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('motmot') . ' - ' . I18N::percentage(Functions::safeDivision($total_motmot, $total), 1); |
|
230 | - return "<img src=\"https://chart.googleapis.com/chart?cht=p&chp=1.5708&chd=e:{$chd}&chs={$size}&chco={$color_fatfat},{$color_fatmot},{$color_shared},{$color_motfat},{$color_motmot}&chf=bg,s,ffffff00&chl={$chl}\" alt=\"" . $chart_title . "\" title=\"" . $chart_title . "\" />"; |
|
224 | + \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fatfat').' - '.I18N::percentage(Functions::safeDivision($total_fatfat, $total), 1).'|'. |
|
225 | + \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('fatmot').' - '.I18N::percentage(Functions::safeDivision($total_fatmot, $total), 1).'|'. |
|
226 | + I18N::translate('Shared').' - '.I18N::percentage(Functions::safeDivision($total_sha, $total), 1).'|'. |
|
227 | + \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('motfat').' - '.I18N::percentage(Functions::safeDivision($total_motfat, $total), 1).'|'. |
|
228 | + \Fisharebest\Webtrees\Functions\Functions::getRelationshipNameFromPath('motmot').' - '.I18N::percentage(Functions::safeDivision($total_motmot, $total), 1); |
|
229 | + return "<img src=\"https://chart.googleapis.com/chart?cht=p&chp=1.5708&chd=e:{$chd}&chs={$size}&chco={$color_fatfat},{$color_fatmot},{$color_shared},{$color_motfat},{$color_motmot}&chf=bg,s,ffffff00&chl={$chl}\" alt=\"".$chart_title."\" title=\"".$chart_title."\" />"; |
|
231 | 230 | } |
232 | 231 | |
233 | 232 | /** |
@@ -243,9 +242,9 @@ discard block |
||
243 | 242 | if ($value < 0) { |
244 | 243 | $value = 0; |
245 | 244 | } |
246 | - $first = (int) ($value / 64); |
|
245 | + $first = (int)($value / 64); |
|
247 | 246 | $second = $value % 64; |
248 | - $encoding .= $xencoding[(int) $first] . $xencoding[(int) $second]; |
|
247 | + $encoding .= $xencoding[(int)$first].$xencoding[(int)$second]; |
|
249 | 248 | } |
250 | 249 | |
251 | 250 | return $encoding; |
@@ -93,8 +93,12 @@ discard block |
||
93 | 93 | foreach($stats_gen as $gen => $tab){ |
94 | 94 | $genY1= I18N::translate('-'); |
95 | 95 | $genY2= I18N::translate('-'); |
96 | - if($tab['firstBirth']>0) $genY1=$tab['firstEstimatedBirth']; |
|
97 | - if($tab['lastBirth']>0) $genY2=$tab['lastEstimatedBirth']; |
|
96 | + if($tab['firstBirth']>0) { |
|
97 | + $genY1=$tab['firstEstimatedBirth']; |
|
98 | + } |
|
99 | + if($tab['lastBirth']>0) { |
|
100 | + $genY2=$tab['lastEstimatedBirth']; |
|
101 | + } |
|
98 | 102 | $total_theoretical += $gen_theoretical; |
99 | 103 | $perc_sosa_count_theor = Functions::safeDivision($tab['sosaCount'], $gen_theoretical); |
100 | 104 | $gen_equiv += $perc_sosa_count_theor; |
@@ -154,7 +158,9 @@ discard block |
||
154 | 158 | private function htmlAncestorDispersionG2() |
155 | 159 | { |
156 | 160 | $ancestorsDispGen2 = $this->sosa_provider->getAncestorDispersionForGen(2); |
157 | - if(count($ancestorsDispGen2) == 0) return; |
|
161 | + if(count($ancestorsDispGen2) == 0) { |
|
162 | + return; |
|
163 | + } |
|
158 | 164 | |
159 | 165 | $size = '600x300'; |
160 | 166 |
@@ -22,9 +22,9 @@ |
||
22 | 22 | public function upgrade() { |
23 | 23 | |
24 | 24 | Database::exec( |
25 | - 'ALTER TABLE `##maj_sosa`' . |
|
26 | - ' ADD COLUMN majs_birth_year_est SMALLINT NULL AFTER majs_birth_year,' . |
|
27 | - ' ADD COLUMN majs_death_year_est SMALLINT NULL AFTER majs_death_year' |
|
25 | + 'ALTER TABLE `##maj_sosa`' . |
|
26 | + ' ADD COLUMN majs_birth_year_est SMALLINT NULL AFTER majs_birth_year,' . |
|
27 | + ' ADD COLUMN majs_death_year_est SMALLINT NULL AFTER majs_death_year' |
|
28 | 28 | ); |
29 | 29 | } |
30 | 30 | } |
@@ -22,8 +22,8 @@ |
||
22 | 22 | public function upgrade() { |
23 | 23 | |
24 | 24 | Database::exec( |
25 | - 'ALTER TABLE `##maj_sosa`' . |
|
26 | - ' ADD COLUMN majs_birth_year_est SMALLINT NULL AFTER majs_birth_year,' . |
|
25 | + 'ALTER TABLE `##maj_sosa`'. |
|
26 | + ' ADD COLUMN majs_birth_year_est SMALLINT NULL AFTER majs_birth_year,'. |
|
27 | 27 | ' ADD COLUMN majs_death_year_est SMALLINT NULL AFTER majs_death_year' |
28 | 28 | ); |
29 | 29 | } |
@@ -22,395 +22,395 @@ 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.', :byearest'.$i.', :dyear'.$i.', :dyearest'.$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 | - 'byearest'.$i => $row['birth_year_est'], |
|
203 | - 'dyear'.$i => $row['death_year'], |
|
204 | - 'dyearest'.$i => $row['death_year_est'] |
|
205 | - ) |
|
206 | - ); |
|
207 | - } |
|
208 | - $i++; |
|
209 | - } |
|
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.', :byearest'.$i.', :dyear'.$i.', :dyearest'.$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 | + 'byearest'.$i => $row['birth_year_est'], |
|
203 | + 'dyear'.$i => $row['death_year'], |
|
204 | + 'dyearest'.$i => $row['death_year_est'] |
|
205 | + ) |
|
206 | + ); |
|
207 | + } |
|
208 | + $i++; |
|
209 | + } |
|
210 | 210 | |
211 | - $sql = 'REPLACE INTO `##maj_sosa`' . |
|
212 | - ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
213 | - ' VALUES '. implode(',', $questionmarks_table); |
|
214 | - Database::prepare($sql)->execute($values_table); |
|
215 | - } |
|
211 | + $sql = 'REPLACE INTO `##maj_sosa`' . |
|
212 | + ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
213 | + ' VALUES '. implode(',', $questionmarks_table); |
|
214 | + Database::prepare($sql)->execute($values_table); |
|
215 | + } |
|
216 | 216 | |
217 | - /**************** |
|
217 | + /**************** |
|
218 | 218 | * SIMPLE QUERIES |
219 | 219 | ****************/ |
220 | 220 | |
221 | - /** |
|
222 | - * Returns the list of Sosa numbers to which an individual is related. |
|
223 | - * Format: key = sosa number, value = generation for the Sosa number |
|
224 | - * |
|
225 | - * @param Individual $indi |
|
226 | - * @return array Array of sosa numbers |
|
227 | - */ |
|
228 | - public function getSosaNumbers(Individual $indi) { |
|
229 | - if(!$this->is_setup) return array(); |
|
230 | - return Database::prepare( |
|
231 | - 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
232 | - ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
233 | - )->execute(array( |
|
234 | - 'indi_id' => $indi->getXref(), |
|
235 | - 'tree_id' => $this->tree->getTreeId(), |
|
236 | - 'user_id' => $this->user->getUserId() |
|
237 | - ))->fetchAssoc(); |
|
238 | - } |
|
239 | - |
|
240 | - /** |
|
241 | - * Get the last generation of Sosa ancestors |
|
242 | - * |
|
243 | - * @return number Last generation if found, 1 otherwise |
|
244 | - */ |
|
245 | - public function getLastGeneration() { |
|
246 | - if(!$this->is_setup) return; |
|
247 | - return Database::prepare( |
|
248 | - 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
249 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
250 | - )->execute(array( |
|
251 | - 'tree_id' => $this->tree->getTreeId(), |
|
252 | - 'user_id' => $this->user->getUserId() |
|
253 | - ))->fetchOne() ?: 1; |
|
254 | - } |
|
255 | - |
|
256 | - /************* |
|
221 | + /** |
|
222 | + * Returns the list of Sosa numbers to which an individual is related. |
|
223 | + * Format: key = sosa number, value = generation for the Sosa number |
|
224 | + * |
|
225 | + * @param Individual $indi |
|
226 | + * @return array Array of sosa numbers |
|
227 | + */ |
|
228 | + public function getSosaNumbers(Individual $indi) { |
|
229 | + if(!$this->is_setup) return array(); |
|
230 | + return Database::prepare( |
|
231 | + 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
|
232 | + ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
233 | + )->execute(array( |
|
234 | + 'indi_id' => $indi->getXref(), |
|
235 | + 'tree_id' => $this->tree->getTreeId(), |
|
236 | + 'user_id' => $this->user->getUserId() |
|
237 | + ))->fetchAssoc(); |
|
238 | + } |
|
239 | + |
|
240 | + /** |
|
241 | + * Get the last generation of Sosa ancestors |
|
242 | + * |
|
243 | + * @return number Last generation if found, 1 otherwise |
|
244 | + */ |
|
245 | + public function getLastGeneration() { |
|
246 | + if(!$this->is_setup) return; |
|
247 | + return Database::prepare( |
|
248 | + 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
|
249 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
|
250 | + )->execute(array( |
|
251 | + 'tree_id' => $this->tree->getTreeId(), |
|
252 | + 'user_id' => $this->user->getUserId() |
|
253 | + ))->fetchOne() ?: 1; |
|
254 | + } |
|
255 | + |
|
256 | + /************* |
|
257 | 257 | * SOSA LISTS |
258 | 258 | *************/ |
259 | 259 | |
260 | - /** |
|
261 | - * Return the list of all sosas, with the generations it belongs to |
|
262 | - * |
|
263 | - * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
264 | - */ |
|
265 | - public function getAllSosaWithGenerations(){ |
|
266 | - if(!$this->is_setup) return array(); |
|
267 | - return Database::prepare( |
|
268 | - 'SELECT majs_i_id AS indi,' . |
|
269 | - ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
270 | - ' FROM `##maj_sosa`' . |
|
271 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
272 | - ' GROUP BY majs_i_id' |
|
273 | - )->execute(array( |
|
274 | - 'tree_id' => $this->tree->getTreeId(), |
|
275 | - 'user_id' => $this->user->getUserId() |
|
276 | - ))->fetchAssoc(); |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
281 | - * |
|
282 | - * @param number $gen Generation |
|
283 | - * @return array Array of Sosa individuals |
|
284 | - */ |
|
285 | - public function getSosaListAtGeneration($gen){ |
|
286 | - if(!$this->is_setup) return array(); |
|
287 | - if(!$this->sosa_list_by_gen) |
|
288 | - $this->sosa_list_by_gen = array(); |
|
260 | + /** |
|
261 | + * Return the list of all sosas, with the generations it belongs to |
|
262 | + * |
|
263 | + * @return array Associative array of Sosa ancestors, with their generation, comma separated |
|
264 | + */ |
|
265 | + public function getAllSosaWithGenerations(){ |
|
266 | + if(!$this->is_setup) return array(); |
|
267 | + return Database::prepare( |
|
268 | + 'SELECT majs_i_id AS indi,' . |
|
269 | + ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
270 | + ' FROM `##maj_sosa`' . |
|
271 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
272 | + ' GROUP BY majs_i_id' |
|
273 | + )->execute(array( |
|
274 | + 'tree_id' => $this->tree->getTreeId(), |
|
275 | + 'user_id' => $this->user->getUserId() |
|
276 | + ))->fetchAssoc(); |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Get an associative array of Sosa individuals in generation G. Keys are Sosa numbers, values individuals. |
|
281 | + * |
|
282 | + * @param number $gen Generation |
|
283 | + * @return array Array of Sosa individuals |
|
284 | + */ |
|
285 | + public function getSosaListAtGeneration($gen){ |
|
286 | + if(!$this->is_setup) return array(); |
|
287 | + if(!$this->sosa_list_by_gen) |
|
288 | + $this->sosa_list_by_gen = array(); |
|
289 | 289 | |
290 | - if($gen){ |
|
291 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
292 | - $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
293 | - 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
294 | - ' FROM `##maj_sosa`'. |
|
295 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
296 | - ' AND majs_gen = :gen'. |
|
297 | - ' ORDER BY majs_sosa ASC') |
|
298 | - ->execute(array( |
|
299 | - 'tree_id' => $this->tree->getTreeId(), |
|
300 | - 'user_id' => $this->user->getUserId(), |
|
301 | - 'gen' => $gen |
|
302 | - )) |
|
303 | - ->fetchAssoc(); |
|
304 | - } |
|
305 | - return $this->sosa_list_by_gen[$gen]; |
|
306 | - } |
|
307 | - return array(); |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
312 | - * |
|
313 | - * @param number $gen Generation |
|
314 | - * @return array Array of Sosa families |
|
315 | - */ |
|
316 | - public function getFamilySosaListAtGeneration($gen){ |
|
317 | - if(!$this->is_setup) return array(); |
|
318 | - if(!$this->sosa_fam_list_by_gen) |
|
319 | - $this->sosa_fam_list_by_gen = array(); |
|
290 | + if($gen){ |
|
291 | + if(!isset($this->sosa_list_by_gen[$gen])){ |
|
292 | + $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
293 | + 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
|
294 | + ' FROM `##maj_sosa`'. |
|
295 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
296 | + ' AND majs_gen = :gen'. |
|
297 | + ' ORDER BY majs_sosa ASC') |
|
298 | + ->execute(array( |
|
299 | + 'tree_id' => $this->tree->getTreeId(), |
|
300 | + 'user_id' => $this->user->getUserId(), |
|
301 | + 'gen' => $gen |
|
302 | + )) |
|
303 | + ->fetchAssoc(); |
|
304 | + } |
|
305 | + return $this->sosa_list_by_gen[$gen]; |
|
306 | + } |
|
307 | + return array(); |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get an associative array of Sosa families in generation G. Keys are Sosa numbers for the husband, values families. |
|
312 | + * |
|
313 | + * @param number $gen Generation |
|
314 | + * @return array Array of Sosa families |
|
315 | + */ |
|
316 | + public function getFamilySosaListAtGeneration($gen){ |
|
317 | + if(!$this->is_setup) return array(); |
|
318 | + if(!$this->sosa_fam_list_by_gen) |
|
319 | + $this->sosa_fam_list_by_gen = array(); |
|
320 | 320 | |
321 | - if($gen){ |
|
322 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
323 | - $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
324 | - 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
325 | - ' FROM `##families`'. |
|
326 | - ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
327 | - ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
328 | - ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
329 | - ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
330 | - ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
331 | - ' AND s1.majs_gen = :gen'. |
|
332 | - ' ORDER BY s1.majs_sosa ASC' |
|
333 | - ) |
|
334 | - ->execute(array( |
|
335 | - 'tree_id' => $this->tree->getTreeId(), |
|
336 | - 'user_id' => $this->user->getUserId(), |
|
337 | - 'gen' => $gen |
|
338 | - )) |
|
339 | - ->fetchAssoc(); |
|
340 | - } |
|
341 | - return $this->sosa_fam_list_by_gen[$gen]; |
|
342 | - } |
|
343 | - return array(); |
|
344 | - } |
|
345 | - |
|
346 | - /** |
|
347 | - * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
348 | - * |
|
349 | - * @param number $gen Generation |
|
350 | - * @return array Array of Sosa individuals |
|
351 | - */ |
|
352 | - public function getMissingSosaListAtGeneration($gen){ |
|
353 | - if(!$this->is_setup) return array(); |
|
354 | - if($gen){ |
|
355 | - return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
356 | - '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'. |
|
357 | - ' FROM `##maj_sosa` schild'. |
|
358 | - ' 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)'. |
|
359 | - ' 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)'. |
|
360 | - ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
361 | - ' AND schild.majs_gen = :gen'. |
|
362 | - ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
363 | - ' ORDER BY schild.majs_sosa ASC') |
|
364 | - ->execute(array( |
|
365 | - 'tree_id' => $this->tree->getTreeId(), |
|
366 | - 'user_id' => $this->user->getUserId(), |
|
367 | - 'gen' => $gen - 1 |
|
368 | - ))->fetchAll(\PDO::FETCH_ASSOC); |
|
369 | - } |
|
370 | - return array(); |
|
371 | - } |
|
372 | - |
|
373 | - |
|
374 | - |
|
375 | - /************* |
|
321 | + if($gen){ |
|
322 | + if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
323 | + $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
|
324 | + 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
|
325 | + ' FROM `##families`'. |
|
326 | + ' INNER JOIN `##maj_sosa` AS s1 ON (`##families`.f_husb = s1.majs_i_id AND `##families`.f_file = s1.majs_gedcom_id)'. |
|
327 | + ' INNER JOIN `##maj_sosa` AS s2 ON (`##families`.f_wife = s2.majs_i_id AND `##families`.f_file = s2.majs_gedcom_id)'. |
|
328 | + ' WHERE s1.majs_sosa + 1 = s2.majs_sosa'. |
|
329 | + ' AND s1.majs_gedcom_id= :tree_id AND s1.majs_user_id=:user_id'. |
|
330 | + ' AND s2.majs_gedcom_id= :tree_id AND s2.majs_user_id=:user_id'. |
|
331 | + ' AND s1.majs_gen = :gen'. |
|
332 | + ' ORDER BY s1.majs_sosa ASC' |
|
333 | + ) |
|
334 | + ->execute(array( |
|
335 | + 'tree_id' => $this->tree->getTreeId(), |
|
336 | + 'user_id' => $this->user->getUserId(), |
|
337 | + 'gen' => $gen |
|
338 | + )) |
|
339 | + ->fetchAssoc(); |
|
340 | + } |
|
341 | + return $this->sosa_fam_list_by_gen[$gen]; |
|
342 | + } |
|
343 | + return array(); |
|
344 | + } |
|
345 | + |
|
346 | + /** |
|
347 | + * Get an associative array of Sosa individuals in generation G who are missing parents. Keys are Sosa numbers, values individuals. |
|
348 | + * |
|
349 | + * @param number $gen Generation |
|
350 | + * @return array Array of Sosa individuals |
|
351 | + */ |
|
352 | + public function getMissingSosaListAtGeneration($gen){ |
|
353 | + if(!$this->is_setup) return array(); |
|
354 | + if($gen){ |
|
355 | + return $this->sosa_list_by_gen[$gen] = Database::prepare( |
|
356 | + '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'. |
|
357 | + ' FROM `##maj_sosa` schild'. |
|
358 | + ' 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)'. |
|
359 | + ' 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)'. |
|
360 | + ' WHERE schild.majs_gedcom_id = :tree_id AND schild.majs_user_id = :user_id'. |
|
361 | + ' AND schild.majs_gen = :gen'. |
|
362 | + ' AND (sfat.majs_sosa IS NULL OR smot.majs_sosa IS NULL)'. |
|
363 | + ' ORDER BY schild.majs_sosa ASC') |
|
364 | + ->execute(array( |
|
365 | + 'tree_id' => $this->tree->getTreeId(), |
|
366 | + 'user_id' => $this->user->getUserId(), |
|
367 | + 'gen' => $gen - 1 |
|
368 | + ))->fetchAll(\PDO::FETCH_ASSOC); |
|
369 | + } |
|
370 | + return array(); |
|
371 | + } |
|
372 | + |
|
373 | + |
|
374 | + |
|
375 | + /************* |
|
376 | 376 | * STATISTICS |
377 | 377 | *************/ |
378 | - /** |
|
379 | - * Get the statistic array detailed by generation. |
|
380 | - * Statistics for each generation are: |
|
381 | - * - The number of Sosa in generation |
|
382 | - * - The number of Sosa up to generation |
|
383 | - * - The number of distinct Sosa up to generation |
|
384 | - * - The year of the first birth in generation |
|
385 | - * - The year of the first estimated birth in generation |
|
386 | - * - The year of the last birth in generation |
|
387 | - * - The year of the last estimated birth in generation |
|
388 | - * - The average year of birth in generation |
|
389 | - * |
|
390 | - * @return array Statistics array |
|
391 | - */ |
|
392 | - public function getStatisticsByGeneration() { |
|
393 | - if(!$this->is_setup) return array(); |
|
394 | - if(!$this->statistics_tab) { |
|
395 | - $this->statistics_tab = array(); |
|
396 | - if($maxGeneration = $this->getLastGeneration()) { |
|
397 | - for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
398 | - $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
399 | - $this->statistics_tab[$gen] = array( |
|
400 | - 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
401 | - 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
402 | - 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
403 | - 'firstBirth' => $birthStats['first'], |
|
404 | - 'firstEstimatedBirth' => $birthStats['first_est'], |
|
405 | - 'lastBirth' => $birthStats['last'], |
|
406 | - 'lastEstimatedBirth' => $birthStats['last_est'], |
|
407 | - 'avgBirth' => $birthStats['avg'] |
|
408 | - ); |
|
409 | - } |
|
410 | - } |
|
411 | - } |
|
412 | - return $this->statistics_tab; |
|
413 | - } |
|
378 | + /** |
|
379 | + * Get the statistic array detailed by generation. |
|
380 | + * Statistics for each generation are: |
|
381 | + * - The number of Sosa in generation |
|
382 | + * - The number of Sosa up to generation |
|
383 | + * - The number of distinct Sosa up to generation |
|
384 | + * - The year of the first birth in generation |
|
385 | + * - The year of the first estimated birth in generation |
|
386 | + * - The year of the last birth in generation |
|
387 | + * - The year of the last estimated birth in generation |
|
388 | + * - The average year of birth in generation |
|
389 | + * |
|
390 | + * @return array Statistics array |
|
391 | + */ |
|
392 | + public function getStatisticsByGeneration() { |
|
393 | + if(!$this->is_setup) return array(); |
|
394 | + if(!$this->statistics_tab) { |
|
395 | + $this->statistics_tab = array(); |
|
396 | + if($maxGeneration = $this->getLastGeneration()) { |
|
397 | + for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
|
398 | + $birthStats = $this->getStatsBirthYearInGeneration($gen); |
|
399 | + $this->statistics_tab[$gen] = array( |
|
400 | + 'sosaCount' => $this->getSosaCountAtGeneration($gen), |
|
401 | + 'sosaTotalCount' => $this->getSosaCountUpToGeneration($gen), |
|
402 | + 'diffSosaTotalCount' => $this->getDifferentSosaCountUpToGeneration($gen), |
|
403 | + 'firstBirth' => $birthStats['first'], |
|
404 | + 'firstEstimatedBirth' => $birthStats['first_est'], |
|
405 | + 'lastBirth' => $birthStats['last'], |
|
406 | + 'lastEstimatedBirth' => $birthStats['last_est'], |
|
407 | + 'avgBirth' => $birthStats['avg'] |
|
408 | + ); |
|
409 | + } |
|
410 | + } |
|
411 | + } |
|
412 | + return $this->statistics_tab; |
|
413 | + } |
|
414 | 414 | |
415 | 415 | /** |
416 | 416 | * How many individuals exist in the tree. |
@@ -418,262 +418,262 @@ discard block |
||
418 | 418 | * @return int |
419 | 419 | */ |
420 | 420 | public function getTotalIndividuals() { |
421 | - if(!$this->is_setup) return 0; |
|
422 | - return Database::prepare( |
|
423 | - 'SELECT COUNT(*) FROM `##individuals`' . |
|
424 | - ' WHERE i_file = :tree_id') |
|
425 | - ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
426 | - ->fetchOne() ?: 0; |
|
421 | + if(!$this->is_setup) return 0; |
|
422 | + return Database::prepare( |
|
423 | + 'SELECT COUNT(*) FROM `##individuals`' . |
|
424 | + ' WHERE i_file = :tree_id') |
|
425 | + ->execute(array('tree_id' => $this->tree->getTreeId())) |
|
426 | + ->fetchOne() ?: 0; |
|
427 | + } |
|
428 | + |
|
429 | + /** |
|
430 | + * Get the total Sosa count for all generations |
|
431 | + * |
|
432 | + * @return number Number of Sosas |
|
433 | + */ |
|
434 | + public function getSosaCount(){ |
|
435 | + if(!$this->is_setup) return 0; |
|
436 | + return Database::prepare( |
|
437 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
438 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
439 | + ->execute(array( |
|
440 | + 'tree_id' => $this->tree->getTreeId(), |
|
441 | + 'user_id' => $this->user->getUserId() |
|
442 | + ))->fetchOne() ?: 0; |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Get the number of Sosa in a specific generation. |
|
447 | + * |
|
448 | + * @param number $gen Generation |
|
449 | + * @return number Number of Sosas in generation |
|
450 | + */ |
|
451 | + public function getSosaCountAtGeneration($gen){ |
|
452 | + if(!$this->is_setup) return 0; |
|
453 | + return Database::prepare( |
|
454 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
455 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
456 | + ' AND majs_gen= :gen') |
|
457 | + ->execute(array( |
|
458 | + 'tree_id' => $this->tree->getTreeId(), |
|
459 | + 'user_id' => $this->user->getUserId(), |
|
460 | + 'gen' => $gen |
|
461 | + ))->fetchOne() ?: 0; |
|
427 | 462 | } |
428 | 463 | |
429 | - /** |
|
430 | - * Get the total Sosa count for all generations |
|
431 | - * |
|
432 | - * @return number Number of Sosas |
|
433 | - */ |
|
434 | - public function getSosaCount(){ |
|
435 | - if(!$this->is_setup) return 0; |
|
436 | - return Database::prepare( |
|
437 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
438 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
439 | - ->execute(array( |
|
440 | - 'tree_id' => $this->tree->getTreeId(), |
|
441 | - 'user_id' => $this->user->getUserId() |
|
442 | - ))->fetchOne() ?: 0; |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Get the number of Sosa in a specific generation. |
|
447 | - * |
|
448 | - * @param number $gen Generation |
|
449 | - * @return number Number of Sosas in generation |
|
450 | - */ |
|
451 | - public function getSosaCountAtGeneration($gen){ |
|
452 | - if(!$this->is_setup) return 0; |
|
453 | - return Database::prepare( |
|
454 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
455 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
456 | - ' AND majs_gen= :gen') |
|
457 | - ->execute(array( |
|
458 | - 'tree_id' => $this->tree->getTreeId(), |
|
459 | - 'user_id' => $this->user->getUserId(), |
|
460 | - 'gen' => $gen |
|
461 | - ))->fetchOne() ?: 0; |
|
462 | - } |
|
463 | - |
|
464 | - /** |
|
465 | - * Get the total number of Sosa up to a specific generation. |
|
466 | - * |
|
467 | - * @param number $gen Generation |
|
468 | - * @return number Total number of Sosas up to generation |
|
469 | - */ |
|
470 | - public function getSosaCountUpToGeneration($gen){ |
|
471 | - if(!$this->is_setup) return 0; |
|
472 | - return Database::prepare( |
|
473 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
474 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
475 | - ' AND majs_gen <= :gen') |
|
476 | - ->execute(array( |
|
477 | - 'tree_id' => $this->tree->getTreeId(), |
|
478 | - 'user_id' => $this->user->getUserId(), |
|
479 | - 'gen' => $gen |
|
480 | - ))->fetchOne() ?: 0; |
|
481 | - } |
|
482 | - |
|
483 | - /** |
|
484 | - * Get the total number of distinct Sosa individual for all generations. |
|
485 | - * |
|
486 | - * @return number Total number of distinct individual |
|
487 | - */ |
|
488 | - public function getDifferentSosaCount(){ |
|
489 | - if(!$this->is_setup) return 0; |
|
490 | - return Database::prepare( |
|
491 | - 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
492 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
493 | - ->execute(array( |
|
494 | - 'tree_id' => $this->tree->getTreeId(), |
|
495 | - 'user_id' => $this->user->getUserId() |
|
496 | - ))->fetchOne() ?: 0; |
|
497 | - } |
|
498 | - |
|
499 | - /** |
|
500 | - * Get the number of distinct Sosa individual up to a specific generation. |
|
501 | - * |
|
502 | - * @param number $gen Generation |
|
503 | - * @return number Number of distinct Sosa individuals up to generation |
|
504 | - */ |
|
505 | - public function getDifferentSosaCountUpToGeneration($gen){ |
|
506 | - if(!$this->is_setup) return 0; |
|
507 | - return Database::prepare( |
|
508 | - 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
509 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
510 | - ' AND majs_gen <= :gen') |
|
511 | - ->execute(array( |
|
512 | - 'tree_id' => $this->tree->getTreeId(), |
|
513 | - 'user_id' => $this->user->getUserId(), |
|
514 | - 'gen' => $gen |
|
515 | - ))->fetchOne() ?: 0; |
|
516 | - } |
|
517 | - |
|
518 | - /** |
|
519 | - * Get an array of birth statistics for a specific generation |
|
520 | - * Statistics are : |
|
521 | - * - first : First birth year in generation |
|
522 | - * - first_est: First estimated birth year in generation |
|
523 | - * - last : Last birth year in generation |
|
524 | - * - last_est : Last estimated birth year in generation |
|
525 | - * - avg : Average birth year (based on non-estimated birth date) |
|
526 | - * |
|
527 | - * @param number $gen Generation |
|
528 | - * @return array Birth statistics array |
|
529 | - */ |
|
530 | - public function getStatsBirthYearInGeneration($gen){ |
|
531 | - if(!$this->is_setup) return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0); |
|
532 | - return Database::prepare( |
|
533 | - 'SELECT'. |
|
534 | - ' MIN(majs_birth_year) AS first, MIN(majs_birth_year_est) AS first_est,'. |
|
535 | - ' AVG(majs_birth_year) AS avg,'. |
|
536 | - ' MAX(majs_birth_year) AS last, MAX(majs_birth_year_est) AS last_est'. |
|
537 | - ' FROM `##maj_sosa`'. |
|
538 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
539 | - ' AND majs_gen=:gen') |
|
540 | - ->execute(array( |
|
541 | - 'tree_id' => $this->tree->getTreeId(), |
|
542 | - 'user_id' => $this->user->getUserId(), |
|
543 | - 'gen' => $gen)) |
|
544 | - ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0); |
|
545 | - } |
|
546 | - |
|
547 | - /** |
|
548 | - * Get the mean generation time, based on a linear regression of birth years and generations |
|
549 | - * |
|
550 | - * @return number|NULL Mean generation time |
|
551 | - */ |
|
552 | - public function getMeanGenerationTime(){ |
|
553 | - if(!$this->is_setup) return; |
|
554 | - if(!$this->statistics_tab){ |
|
555 | - $this->getStatisticsByGeneration(); |
|
556 | - } |
|
557 | - //Linear regression on x=generation and y=birthdate |
|
558 | - $sum_xy = 0; |
|
559 | - $sum_x=0; |
|
560 | - $sum_y=0; |
|
561 | - $sum_x2=0; |
|
562 | - $n=count($this->statistics_tab); |
|
563 | - foreach($this->statistics_tab as $gen=>$stats){ |
|
564 | - $sum_xy+=$gen*$stats['avgBirth']; |
|
565 | - $sum_x+=$gen; |
|
566 | - $sum_y+=$stats['avgBirth']; |
|
567 | - $sum_x2+=$gen*$gen; |
|
568 | - } |
|
569 | - $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
570 | - if($denom!=0){ |
|
571 | - return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
572 | - } |
|
573 | - return null; |
|
574 | - } |
|
575 | - |
|
576 | - /** |
|
577 | - * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
578 | - * at a specified generation. |
|
579 | - * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
580 | - * |
|
581 | - * Format: |
|
582 | - * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
583 | - * -1 is used for shared ancestors |
|
584 | - * For instance base2(0100) = base10(4) represent the maternal grand father |
|
585 | - * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
586 | - * |
|
587 | - * For instance a result at generation 3 could be : |
|
588 | - * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
589 | - * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
590 | - * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
591 | - * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
592 | - * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
593 | - * ) |
|
594 | - * |
|
595 | - * @param int $gen Reference generation |
|
596 | - * @return array |
|
597 | - */ |
|
598 | - public function getAncestorDispersionForGen($gen) { |
|
599 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
600 | - return Database::prepare( |
|
601 | - 'SELECT branches, count(i_id)'. |
|
602 | - ' FROM ('. |
|
603 | - ' SELECT i_id,'. |
|
604 | - ' CASE'. |
|
605 | - ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
606 | - ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
607 | - ' END branches'. |
|
608 | - ' FROM ('. |
|
609 | - ' SELECT DISTINCT majs_i_id i_id,'. |
|
610 | - ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
611 | - ' FROM `##maj_sosa`'. |
|
612 | - ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
613 | - ' AND majs_gen >= :gen'. |
|
614 | - ' ) indistat'. |
|
615 | - ' GROUP BY i_id'. |
|
616 | - ') grouped'. |
|
617 | - ' GROUP BY branches') |
|
618 | - ->execute(array( |
|
619 | - 'tree_id' => $this->tree->getTreeId(), |
|
620 | - 'user_id' => $this->user->getUserId(), |
|
621 | - 'gen' => $gen |
|
622 | - ))->fetchAssoc() ?: array(); |
|
623 | - } |
|
624 | - |
|
625 | - /** |
|
626 | - * Return an array of the most duplicated root Sosa ancestors. |
|
627 | - * The number of ancestors to return is limited by the parameter $limit. |
|
628 | - * If several individuals are tied when reaching the limit, none of them are returned, |
|
629 | - * which means that there can be less individuals returned than requested. |
|
630 | - * |
|
631 | - * Format: |
|
632 | - * - key : root Sosa individual |
|
633 | - * - value: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
634 | - * |
|
635 | - * @param number $limit Maximum number of individuals to return |
|
636 | - * @return array |
|
637 | - */ |
|
638 | - public function getTopMultiSosaAncestorsNoTies($limit) { |
|
639 | - if(!$this->is_setup) return array(); |
|
640 | - return Database::prepare( |
|
641 | - 'SELECT sosa_i_id, sosa_count FROM ('. |
|
642 | - ' SELECT'. |
|
643 | - ' top_sosa.sosa_i_id, top_sosa.sosa_count, top_sosa.sosa_min,'. |
|
644 | - ' @keep := IF(@prev_count = 0 OR sosa_count = @prev_count, @keep, 1) AS keep,'. |
|
645 | - ' @prev_count := top_sosa.sosa_count AS prev_count'. |
|
646 | - ' FROM ('. |
|
647 | - ' SELECT'. |
|
648 | - ' sosa.majs_i_id sosa_i_id,'. |
|
649 | - ' COUNT(sosa.majs_sosa) sosa_count,'. |
|
650 | - ' MIN(sosa.majs_sosa) sosa_min'. |
|
651 | - ' FROM ##maj_sosa AS sosa'. |
|
652 | - ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'. // Link to sosa's father |
|
653 | - ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
654 | - ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
655 | - ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'. // Link to sosa's mother |
|
656 | - ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
657 | - ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
658 | - ' WHERE sosa.majs_gedcom_id = :tree_id'. |
|
659 | - ' AND sosa.majs_user_id = :user_id'. |
|
660 | - ' AND sosa_fat.majs_sosa IS NULL'. // We keep only root individuals, i.e. those with no father or mother |
|
661 | - ' AND sosa_mot.majs_sosa IS NULL'. |
|
662 | - ' GROUP BY sosa.majs_i_id'. |
|
663 | - ' HAVING COUNT(sosa.majs_sosa) > 1'. // Limit to the duplicate sosas. |
|
664 | - ' ORDER BY COUNT(sosa.majs_sosa) DESC'. |
|
665 | - ' LIMIT ' . ($limit + 1) . // We want to select one more than required |
|
666 | - ' ) AS top_sosa,'. |
|
667 | - ' (SELECT @prev_count := 0, @keep := 0) x'. |
|
668 | - ' ORDER BY top_sosa.sosa_count ASC'. |
|
669 | - ' ) top_sosa_list'. |
|
670 | - ' WHERE keep = 1'. |
|
671 | - ' ORDER BY sosa_count DESC, sosa_min ASC' |
|
672 | - )->execute(array( |
|
673 | - 'tree_id' => $this->tree->getTreeId(), |
|
674 | - 'user_id' => $this->user->getUserId() |
|
675 | - ))->fetchAssoc() ?: array(); |
|
676 | - } |
|
464 | + /** |
|
465 | + * Get the total number of Sosa up to a specific generation. |
|
466 | + * |
|
467 | + * @param number $gen Generation |
|
468 | + * @return number Total number of Sosas up to generation |
|
469 | + */ |
|
470 | + public function getSosaCountUpToGeneration($gen){ |
|
471 | + if(!$this->is_setup) return 0; |
|
472 | + return Database::prepare( |
|
473 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
474 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
475 | + ' AND majs_gen <= :gen') |
|
476 | + ->execute(array( |
|
477 | + 'tree_id' => $this->tree->getTreeId(), |
|
478 | + 'user_id' => $this->user->getUserId(), |
|
479 | + 'gen' => $gen |
|
480 | + ))->fetchOne() ?: 0; |
|
481 | + } |
|
482 | + |
|
483 | + /** |
|
484 | + * Get the total number of distinct Sosa individual for all generations. |
|
485 | + * |
|
486 | + * @return number Total number of distinct individual |
|
487 | + */ |
|
488 | + public function getDifferentSosaCount(){ |
|
489 | + if(!$this->is_setup) return 0; |
|
490 | + return Database::prepare( |
|
491 | + 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
492 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
|
493 | + ->execute(array( |
|
494 | + 'tree_id' => $this->tree->getTreeId(), |
|
495 | + 'user_id' => $this->user->getUserId() |
|
496 | + ))->fetchOne() ?: 0; |
|
497 | + } |
|
498 | + |
|
499 | + /** |
|
500 | + * Get the number of distinct Sosa individual up to a specific generation. |
|
501 | + * |
|
502 | + * @param number $gen Generation |
|
503 | + * @return number Number of distinct Sosa individuals up to generation |
|
504 | + */ |
|
505 | + public function getDifferentSosaCountUpToGeneration($gen){ |
|
506 | + if(!$this->is_setup) return 0; |
|
507 | + return Database::prepare( |
|
508 | + 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
509 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
510 | + ' AND majs_gen <= :gen') |
|
511 | + ->execute(array( |
|
512 | + 'tree_id' => $this->tree->getTreeId(), |
|
513 | + 'user_id' => $this->user->getUserId(), |
|
514 | + 'gen' => $gen |
|
515 | + ))->fetchOne() ?: 0; |
|
516 | + } |
|
517 | + |
|
518 | + /** |
|
519 | + * Get an array of birth statistics for a specific generation |
|
520 | + * Statistics are : |
|
521 | + * - first : First birth year in generation |
|
522 | + * - first_est: First estimated birth year in generation |
|
523 | + * - last : Last birth year in generation |
|
524 | + * - last_est : Last estimated birth year in generation |
|
525 | + * - avg : Average birth year (based on non-estimated birth date) |
|
526 | + * |
|
527 | + * @param number $gen Generation |
|
528 | + * @return array Birth statistics array |
|
529 | + */ |
|
530 | + public function getStatsBirthYearInGeneration($gen){ |
|
531 | + if(!$this->is_setup) return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0); |
|
532 | + return Database::prepare( |
|
533 | + 'SELECT'. |
|
534 | + ' MIN(majs_birth_year) AS first, MIN(majs_birth_year_est) AS first_est,'. |
|
535 | + ' AVG(majs_birth_year) AS avg,'. |
|
536 | + ' MAX(majs_birth_year) AS last, MAX(majs_birth_year_est) AS last_est'. |
|
537 | + ' FROM `##maj_sosa`'. |
|
538 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
539 | + ' AND majs_gen=:gen') |
|
540 | + ->execute(array( |
|
541 | + 'tree_id' => $this->tree->getTreeId(), |
|
542 | + 'user_id' => $this->user->getUserId(), |
|
543 | + 'gen' => $gen)) |
|
544 | + ->fetchOneRow(\PDO::FETCH_ASSOC) ?: array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0); |
|
545 | + } |
|
546 | + |
|
547 | + /** |
|
548 | + * Get the mean generation time, based on a linear regression of birth years and generations |
|
549 | + * |
|
550 | + * @return number|NULL Mean generation time |
|
551 | + */ |
|
552 | + public function getMeanGenerationTime(){ |
|
553 | + if(!$this->is_setup) return; |
|
554 | + if(!$this->statistics_tab){ |
|
555 | + $this->getStatisticsByGeneration(); |
|
556 | + } |
|
557 | + //Linear regression on x=generation and y=birthdate |
|
558 | + $sum_xy = 0; |
|
559 | + $sum_x=0; |
|
560 | + $sum_y=0; |
|
561 | + $sum_x2=0; |
|
562 | + $n=count($this->statistics_tab); |
|
563 | + foreach($this->statistics_tab as $gen=>$stats){ |
|
564 | + $sum_xy+=$gen*$stats['avgBirth']; |
|
565 | + $sum_x+=$gen; |
|
566 | + $sum_y+=$stats['avgBirth']; |
|
567 | + $sum_x2+=$gen*$gen; |
|
568 | + } |
|
569 | + $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
570 | + if($denom!=0){ |
|
571 | + return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
572 | + } |
|
573 | + return null; |
|
574 | + } |
|
575 | + |
|
576 | + /** |
|
577 | + * Return a computed array of statistics about the dispersion of ancestors across the ancestors |
|
578 | + * at a specified generation. |
|
579 | + * This statistics cannot be used for generations above 11, as it would cause a out of range in MySQL |
|
580 | + * |
|
581 | + * Format: |
|
582 | + * - key : a base-2 representation of the ancestor at generation G for which exclusive ancestors have been found, |
|
583 | + * -1 is used for shared ancestors |
|
584 | + * For instance base2(0100) = base10(4) represent the maternal grand father |
|
585 | + * - values: number of ancestors exclusively in the ancestors of the ancestor in key |
|
586 | + * |
|
587 | + * For instance a result at generation 3 could be : |
|
588 | + * array ( -1 => 12 -> 12 ancestors are shared by the grand-parents |
|
589 | + * base10(1) => 32 -> 32 ancestors are exclusive to the paternal grand-father |
|
590 | + * base10(2) => 25 -> 25 ancestors are exclusive to the paternal grand-mother |
|
591 | + * base10(4) => 12 -> 12 ancestors are exclusive to the maternal grand-father |
|
592 | + * base10(8) => 30 -> 30 ancestors are exclusive to the maternal grand-mother |
|
593 | + * ) |
|
594 | + * |
|
595 | + * @param int $gen Reference generation |
|
596 | + * @return array |
|
597 | + */ |
|
598 | + public function getAncestorDispersionForGen($gen) { |
|
599 | + if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
600 | + return Database::prepare( |
|
601 | + 'SELECT branches, count(i_id)'. |
|
602 | + ' FROM ('. |
|
603 | + ' SELECT i_id,'. |
|
604 | + ' CASE'. |
|
605 | + ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
|
606 | + ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
607 | + ' END branches'. |
|
608 | + ' FROM ('. |
|
609 | + ' SELECT DISTINCT majs_i_id i_id,'. |
|
610 | + ' POW(2, FLOOR(majs_sosa / POW(2, (majs_gen - :gen))) - POW(2, :gen -1)) branch'. |
|
611 | + ' FROM `##maj_sosa`'. |
|
612 | + ' WHERE majs_gedcom_id = :tree_id AND majs_user_id = :user_id'. |
|
613 | + ' AND majs_gen >= :gen'. |
|
614 | + ' ) indistat'. |
|
615 | + ' GROUP BY i_id'. |
|
616 | + ') grouped'. |
|
617 | + ' GROUP BY branches') |
|
618 | + ->execute(array( |
|
619 | + 'tree_id' => $this->tree->getTreeId(), |
|
620 | + 'user_id' => $this->user->getUserId(), |
|
621 | + 'gen' => $gen |
|
622 | + ))->fetchAssoc() ?: array(); |
|
623 | + } |
|
624 | + |
|
625 | + /** |
|
626 | + * Return an array of the most duplicated root Sosa ancestors. |
|
627 | + * The number of ancestors to return is limited by the parameter $limit. |
|
628 | + * If several individuals are tied when reaching the limit, none of them are returned, |
|
629 | + * which means that there can be less individuals returned than requested. |
|
630 | + * |
|
631 | + * Format: |
|
632 | + * - key : root Sosa individual |
|
633 | + * - value: number of duplications of the ancestor (e.g. 3 if it appears 3 times) |
|
634 | + * |
|
635 | + * @param number $limit Maximum number of individuals to return |
|
636 | + * @return array |
|
637 | + */ |
|
638 | + public function getTopMultiSosaAncestorsNoTies($limit) { |
|
639 | + if(!$this->is_setup) return array(); |
|
640 | + return Database::prepare( |
|
641 | + 'SELECT sosa_i_id, sosa_count FROM ('. |
|
642 | + ' SELECT'. |
|
643 | + ' top_sosa.sosa_i_id, top_sosa.sosa_count, top_sosa.sosa_min,'. |
|
644 | + ' @keep := IF(@prev_count = 0 OR sosa_count = @prev_count, @keep, 1) AS keep,'. |
|
645 | + ' @prev_count := top_sosa.sosa_count AS prev_count'. |
|
646 | + ' FROM ('. |
|
647 | + ' SELECT'. |
|
648 | + ' sosa.majs_i_id sosa_i_id,'. |
|
649 | + ' COUNT(sosa.majs_sosa) sosa_count,'. |
|
650 | + ' MIN(sosa.majs_sosa) sosa_min'. |
|
651 | + ' FROM ##maj_sosa AS sosa'. |
|
652 | + ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'. // Link to sosa's father |
|
653 | + ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
654 | + ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
655 | + ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'. // Link to sosa's mother |
|
656 | + ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
|
657 | + ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
|
658 | + ' WHERE sosa.majs_gedcom_id = :tree_id'. |
|
659 | + ' AND sosa.majs_user_id = :user_id'. |
|
660 | + ' AND sosa_fat.majs_sosa IS NULL'. // We keep only root individuals, i.e. those with no father or mother |
|
661 | + ' AND sosa_mot.majs_sosa IS NULL'. |
|
662 | + ' GROUP BY sosa.majs_i_id'. |
|
663 | + ' HAVING COUNT(sosa.majs_sosa) > 1'. // Limit to the duplicate sosas. |
|
664 | + ' ORDER BY COUNT(sosa.majs_sosa) DESC'. |
|
665 | + ' LIMIT ' . ($limit + 1) . // We want to select one more than required |
|
666 | + ' ) AS top_sosa,'. |
|
667 | + ' (SELECT @prev_count := 0, @keep := 0) x'. |
|
668 | + ' ORDER BY top_sosa.sosa_count ASC'. |
|
669 | + ' ) top_sosa_list'. |
|
670 | + ' WHERE keep = 1'. |
|
671 | + ' ORDER BY sosa_count DESC, sosa_min ASC' |
|
672 | + )->execute(array( |
|
673 | + 'tree_id' => $this->tree->getTreeId(), |
|
674 | + 'user_id' => $this->user->getUserId() |
|
675 | + ))->fetchAssoc() ?: array(); |
|
676 | + } |
|
677 | 677 | |
678 | 678 | |
679 | 679 | } |
@@ -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.', :byearest'.$i.', :dyear'.$i.', :dyearest'.$i.')'; |
193 | 193 | $values_table = array_merge( |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | $i++; |
209 | 209 | } |
210 | 210 | |
211 | - $sql = 'REPLACE INTO `##maj_sosa`' . |
|
212 | - ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)' . |
|
213 | - ' VALUES '. implode(',', $questionmarks_table); |
|
211 | + $sql = 'REPLACE INTO `##maj_sosa`'. |
|
212 | + ' (majs_gedcom_id, majs_user_id, majs_sosa, majs_i_id, majs_gen, majs_birth_year, majs_birth_year_est, majs_death_year, majs_death_year_est)'. |
|
213 | + ' VALUES '.implode(',', $questionmarks_table); |
|
214 | 214 | Database::prepare($sql)->execute($values_table); |
215 | 215 | } |
216 | 216 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @return array Array of sosa numbers |
227 | 227 | */ |
228 | 228 | public function getSosaNumbers(Individual $indi) { |
229 | - if(!$this->is_setup) return array(); |
|
229 | + if (!$this->is_setup) return array(); |
|
230 | 230 | return Database::prepare( |
231 | 231 | 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
232 | 232 | ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | * @return number Last generation if found, 1 otherwise |
244 | 244 | */ |
245 | 245 | public function getLastGeneration() { |
246 | - if(!$this->is_setup) return; |
|
246 | + if (!$this->is_setup) return; |
|
247 | 247 | return Database::prepare( |
248 | 248 | 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
249 | 249 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -262,13 +262,13 @@ discard block |
||
262 | 262 | * |
263 | 263 | * @return array Associative array of Sosa ancestors, with their generation, comma separated |
264 | 264 | */ |
265 | - public function getAllSosaWithGenerations(){ |
|
266 | - if(!$this->is_setup) return array(); |
|
265 | + public function getAllSosaWithGenerations() { |
|
266 | + if (!$this->is_setup) return array(); |
|
267 | 267 | return Database::prepare( |
268 | - 'SELECT majs_i_id AS indi,' . |
|
269 | - ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
|
270 | - ' FROM `##maj_sosa`' . |
|
271 | - ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' . |
|
268 | + 'SELECT majs_i_id AS indi,'. |
|
269 | + ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations'. |
|
270 | + ' FROM `##maj_sosa`'. |
|
271 | + ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
|
272 | 272 | ' GROUP BY majs_i_id' |
273 | 273 | )->execute(array( |
274 | 274 | 'tree_id' => $this->tree->getTreeId(), |
@@ -282,13 +282,13 @@ discard block |
||
282 | 282 | * @param number $gen Generation |
283 | 283 | * @return array Array of Sosa individuals |
284 | 284 | */ |
285 | - public function getSosaListAtGeneration($gen){ |
|
286 | - if(!$this->is_setup) return array(); |
|
287 | - if(!$this->sosa_list_by_gen) |
|
285 | + public function getSosaListAtGeneration($gen) { |
|
286 | + if (!$this->is_setup) return array(); |
|
287 | + if (!$this->sosa_list_by_gen) |
|
288 | 288 | $this->sosa_list_by_gen = array(); |
289 | 289 | |
290 | - if($gen){ |
|
291 | - if(!isset($this->sosa_list_by_gen[$gen])){ |
|
290 | + if ($gen) { |
|
291 | + if (!isset($this->sosa_list_by_gen[$gen])) { |
|
292 | 292 | $this->sosa_list_by_gen[$gen] = Database::prepare( |
293 | 293 | 'SELECT majs_sosa AS sosa, majs_i_id AS indi'. |
294 | 294 | ' FROM `##maj_sosa`'. |
@@ -313,13 +313,13 @@ discard block |
||
313 | 313 | * @param number $gen Generation |
314 | 314 | * @return array Array of Sosa families |
315 | 315 | */ |
316 | - public function getFamilySosaListAtGeneration($gen){ |
|
317 | - if(!$this->is_setup) return array(); |
|
318 | - if(!$this->sosa_fam_list_by_gen) |
|
316 | + public function getFamilySosaListAtGeneration($gen) { |
|
317 | + if (!$this->is_setup) return array(); |
|
318 | + if (!$this->sosa_fam_list_by_gen) |
|
319 | 319 | $this->sosa_fam_list_by_gen = array(); |
320 | 320 | |
321 | - if($gen){ |
|
322 | - if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
|
321 | + if ($gen) { |
|
322 | + if (!isset($this->sosa_fam_list_by_gen[$gen])) { |
|
323 | 323 | $this->sosa_fam_list_by_gen[$gen] = Database::prepare( |
324 | 324 | 'SELECT s1.majs_sosa AS sosa, f_id AS fam'. |
325 | 325 | ' FROM `##families`'. |
@@ -349,9 +349,9 @@ discard block |
||
349 | 349 | * @param number $gen Generation |
350 | 350 | * @return array Array of Sosa individuals |
351 | 351 | */ |
352 | - public function getMissingSosaListAtGeneration($gen){ |
|
353 | - if(!$this->is_setup) return array(); |
|
354 | - if($gen){ |
|
352 | + public function getMissingSosaListAtGeneration($gen) { |
|
353 | + if (!$this->is_setup) return array(); |
|
354 | + if ($gen) { |
|
355 | 355 | return $this->sosa_list_by_gen[$gen] = Database::prepare( |
356 | 356 | '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'. |
357 | 357 | ' FROM `##maj_sosa` schild'. |
@@ -390,10 +390,10 @@ discard block |
||
390 | 390 | * @return array Statistics array |
391 | 391 | */ |
392 | 392 | public function getStatisticsByGeneration() { |
393 | - if(!$this->is_setup) return array(); |
|
394 | - if(!$this->statistics_tab) { |
|
393 | + if (!$this->is_setup) return array(); |
|
394 | + if (!$this->statistics_tab) { |
|
395 | 395 | $this->statistics_tab = array(); |
396 | - if($maxGeneration = $this->getLastGeneration()) { |
|
396 | + if ($maxGeneration = $this->getLastGeneration()) { |
|
397 | 397 | for ($gen = 1; $gen <= $maxGeneration; $gen++) { |
398 | 398 | $birthStats = $this->getStatsBirthYearInGeneration($gen); |
399 | 399 | $this->statistics_tab[$gen] = array( |
@@ -418,9 +418,9 @@ discard block |
||
418 | 418 | * @return int |
419 | 419 | */ |
420 | 420 | public function getTotalIndividuals() { |
421 | - if(!$this->is_setup) return 0; |
|
421 | + if (!$this->is_setup) return 0; |
|
422 | 422 | return Database::prepare( |
423 | - 'SELECT COUNT(*) FROM `##individuals`' . |
|
423 | + 'SELECT COUNT(*) FROM `##individuals`'. |
|
424 | 424 | ' WHERE i_file = :tree_id') |
425 | 425 | ->execute(array('tree_id' => $this->tree->getTreeId())) |
426 | 426 | ->fetchOne() ?: 0; |
@@ -431,10 +431,10 @@ discard block |
||
431 | 431 | * |
432 | 432 | * @return number Number of Sosas |
433 | 433 | */ |
434 | - public function getSosaCount(){ |
|
435 | - if(!$this->is_setup) return 0; |
|
434 | + public function getSosaCount() { |
|
435 | + if (!$this->is_setup) return 0; |
|
436 | 436 | return Database::prepare( |
437 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
437 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
438 | 438 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
439 | 439 | ->execute(array( |
440 | 440 | 'tree_id' => $this->tree->getTreeId(), |
@@ -448,10 +448,10 @@ discard block |
||
448 | 448 | * @param number $gen Generation |
449 | 449 | * @return number Number of Sosas in generation |
450 | 450 | */ |
451 | - public function getSosaCountAtGeneration($gen){ |
|
452 | - if(!$this->is_setup) return 0; |
|
451 | + public function getSosaCountAtGeneration($gen) { |
|
452 | + if (!$this->is_setup) return 0; |
|
453 | 453 | return Database::prepare( |
454 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
454 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
455 | 455 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
456 | 456 | ' AND majs_gen= :gen') |
457 | 457 | ->execute(array( |
@@ -467,10 +467,10 @@ discard block |
||
467 | 467 | * @param number $gen Generation |
468 | 468 | * @return number Total number of Sosas up to generation |
469 | 469 | */ |
470 | - public function getSosaCountUpToGeneration($gen){ |
|
471 | - if(!$this->is_setup) return 0; |
|
470 | + public function getSosaCountUpToGeneration($gen) { |
|
471 | + if (!$this->is_setup) return 0; |
|
472 | 472 | return Database::prepare( |
473 | - 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
|
473 | + 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`'. |
|
474 | 474 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
475 | 475 | ' AND majs_gen <= :gen') |
476 | 476 | ->execute(array( |
@@ -485,10 +485,10 @@ discard block |
||
485 | 485 | * |
486 | 486 | * @return number Total number of distinct individual |
487 | 487 | */ |
488 | - public function getDifferentSosaCount(){ |
|
489 | - if(!$this->is_setup) return 0; |
|
488 | + public function getDifferentSosaCount() { |
|
489 | + if (!$this->is_setup) return 0; |
|
490 | 490 | return Database::prepare( |
491 | - 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
491 | + 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'. |
|
492 | 492 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
493 | 493 | ->execute(array( |
494 | 494 | 'tree_id' => $this->tree->getTreeId(), |
@@ -502,10 +502,10 @@ discard block |
||
502 | 502 | * @param number $gen Generation |
503 | 503 | * @return number Number of distinct Sosa individuals up to generation |
504 | 504 | */ |
505 | - public function getDifferentSosaCountUpToGeneration($gen){ |
|
506 | - if(!$this->is_setup) return 0; |
|
505 | + public function getDifferentSosaCountUpToGeneration($gen) { |
|
506 | + if (!$this->is_setup) return 0; |
|
507 | 507 | return Database::prepare( |
508 | - 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
|
508 | + 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`'. |
|
509 | 509 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
510 | 510 | ' AND majs_gen <= :gen') |
511 | 511 | ->execute(array( |
@@ -527,8 +527,8 @@ discard block |
||
527 | 527 | * @param number $gen Generation |
528 | 528 | * @return array Birth statistics array |
529 | 529 | */ |
530 | - public function getStatsBirthYearInGeneration($gen){ |
|
531 | - if(!$this->is_setup) return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0); |
|
530 | + public function getStatsBirthYearInGeneration($gen) { |
|
531 | + if (!$this->is_setup) return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0); |
|
532 | 532 | return Database::prepare( |
533 | 533 | 'SELECT'. |
534 | 534 | ' MIN(majs_birth_year) AS first, MIN(majs_birth_year_est) AS first_est,'. |
@@ -549,26 +549,26 @@ discard block |
||
549 | 549 | * |
550 | 550 | * @return number|NULL Mean generation time |
551 | 551 | */ |
552 | - public function getMeanGenerationTime(){ |
|
553 | - if(!$this->is_setup) return; |
|
554 | - if(!$this->statistics_tab){ |
|
552 | + public function getMeanGenerationTime() { |
|
553 | + if (!$this->is_setup) return; |
|
554 | + if (!$this->statistics_tab) { |
|
555 | 555 | $this->getStatisticsByGeneration(); |
556 | 556 | } |
557 | 557 | //Linear regression on x=generation and y=birthdate |
558 | 558 | $sum_xy = 0; |
559 | - $sum_x=0; |
|
560 | - $sum_y=0; |
|
561 | - $sum_x2=0; |
|
562 | - $n=count($this->statistics_tab); |
|
563 | - foreach($this->statistics_tab as $gen=>$stats){ |
|
564 | - $sum_xy+=$gen*$stats['avgBirth']; |
|
565 | - $sum_x+=$gen; |
|
566 | - $sum_y+=$stats['avgBirth']; |
|
567 | - $sum_x2+=$gen*$gen; |
|
559 | + $sum_x = 0; |
|
560 | + $sum_y = 0; |
|
561 | + $sum_x2 = 0; |
|
562 | + $n = count($this->statistics_tab); |
|
563 | + foreach ($this->statistics_tab as $gen=>$stats) { |
|
564 | + $sum_xy += $gen * $stats['avgBirth']; |
|
565 | + $sum_x += $gen; |
|
566 | + $sum_y += $stats['avgBirth']; |
|
567 | + $sum_x2 += $gen * $gen; |
|
568 | 568 | } |
569 | - $denom=($n*$sum_x2)-($sum_x*$sum_x); |
|
570 | - if($denom!=0){ |
|
571 | - return -(($n*$sum_xy)-($sum_x*$sum_y))/($denom); |
|
569 | + $denom = ($n * $sum_x2) - ($sum_x * $sum_x); |
|
570 | + if ($denom != 0) { |
|
571 | + return -(($n * $sum_xy) - ($sum_x * $sum_y)) / ($denom); |
|
572 | 572 | } |
573 | 573 | return null; |
574 | 574 | } |
@@ -596,14 +596,14 @@ discard block |
||
596 | 596 | * @return array |
597 | 597 | */ |
598 | 598 | public function getAncestorDispersionForGen($gen) { |
599 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
599 | + if (!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
600 | 600 | return Database::prepare( |
601 | 601 | 'SELECT branches, count(i_id)'. |
602 | 602 | ' FROM ('. |
603 | 603 | ' SELECT i_id,'. |
604 | 604 | ' CASE'. |
605 | 605 | ' WHEN CEIL(LOG2(SUM(branch))) = LOG2(SUM(branch)) THEN SUM(branch)'. |
606 | - ' ELSE -1'. // We put all ancestors shared between some branches in the same bucket |
|
606 | + ' ELSE -1'.// We put all ancestors shared between some branches in the same bucket |
|
607 | 607 | ' END branches'. |
608 | 608 | ' FROM ('. |
609 | 609 | ' SELECT DISTINCT majs_i_id i_id,'. |
@@ -636,7 +636,7 @@ discard block |
||
636 | 636 | * @return array |
637 | 637 | */ |
638 | 638 | public function getTopMultiSosaAncestorsNoTies($limit) { |
639 | - if(!$this->is_setup) return array(); |
|
639 | + if (!$this->is_setup) return array(); |
|
640 | 640 | return Database::prepare( |
641 | 641 | 'SELECT sosa_i_id, sosa_count FROM ('. |
642 | 642 | ' SELECT'. |
@@ -649,20 +649,20 @@ discard block |
||
649 | 649 | ' COUNT(sosa.majs_sosa) sosa_count,'. |
650 | 650 | ' MIN(sosa.majs_sosa) sosa_min'. |
651 | 651 | ' FROM ##maj_sosa AS sosa'. |
652 | - ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'. // Link to sosa's father |
|
652 | + ' LEFT JOIN ##maj_sosa AS sosa_fat ON sosa_fat.majs_sosa = 2 * sosa.majs_sosa'.// Link to sosa's father |
|
653 | 653 | ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
654 | 654 | ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
655 | - ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'. // Link to sosa's mother |
|
655 | + ' LEFT JOIN ##maj_sosa AS sosa_mot on sosa_mot.majs_sosa = (2 * sosa.majs_sosa + 1)'.// Link to sosa's mother |
|
656 | 656 | ' AND sosa.majs_gedcom_id = sosa_fat.majs_gedcom_id'. |
657 | 657 | ' AND sosa.majs_user_id = sosa_fat.majs_user_id'. |
658 | 658 | ' WHERE sosa.majs_gedcom_id = :tree_id'. |
659 | 659 | ' AND sosa.majs_user_id = :user_id'. |
660 | - ' AND sosa_fat.majs_sosa IS NULL'. // We keep only root individuals, i.e. those with no father or mother |
|
660 | + ' AND sosa_fat.majs_sosa IS NULL'.// We keep only root individuals, i.e. those with no father or mother |
|
661 | 661 | ' AND sosa_mot.majs_sosa IS NULL'. |
662 | 662 | ' GROUP BY sosa.majs_i_id'. |
663 | - ' HAVING COUNT(sosa.majs_sosa) > 1'. // Limit to the duplicate sosas. |
|
663 | + ' HAVING COUNT(sosa.majs_sosa) > 1'.// Limit to the duplicate sosas. |
|
664 | 664 | ' ORDER BY COUNT(sosa.majs_sosa) DESC'. |
665 | - ' LIMIT ' . ($limit + 1) . // We want to select one more than required |
|
665 | + ' LIMIT '.($limit + 1).// We want to select one more than required |
|
666 | 666 | ' ) AS top_sosa,'. |
667 | 667 | ' (SELECT @prev_count := 0, @keep := 0) x'. |
668 | 668 | ' 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(); |
@@ -226,7 +236,9 @@ discard block |
||
226 | 236 | * @return array Array of sosa numbers |
227 | 237 | */ |
228 | 238 | public function getSosaNumbers(Individual $indi) { |
229 | - if(!$this->is_setup) return array(); |
|
239 | + if(!$this->is_setup) { |
|
240 | + return array(); |
|
241 | + } |
|
230 | 242 | return Database::prepare( |
231 | 243 | 'SELECT majs_sosa, majs_gen FROM `##maj_sosa`'. |
232 | 244 | ' WHERE majs_i_id=:indi_id AND majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -243,7 +255,9 @@ discard block |
||
243 | 255 | * @return number Last generation if found, 1 otherwise |
244 | 256 | */ |
245 | 257 | public function getLastGeneration() { |
246 | - if(!$this->is_setup) return; |
|
258 | + if(!$this->is_setup) { |
|
259 | + return; |
|
260 | + } |
|
247 | 261 | return Database::prepare( |
248 | 262 | 'SELECT MAX(majs_gen) FROM `##maj_sosa`'. |
249 | 263 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id' |
@@ -263,7 +277,9 @@ discard block |
||
263 | 277 | * @return array Associative array of Sosa ancestors, with their generation, comma separated |
264 | 278 | */ |
265 | 279 | public function getAllSosaWithGenerations(){ |
266 | - if(!$this->is_setup) return array(); |
|
280 | + if(!$this->is_setup) { |
|
281 | + return array(); |
|
282 | + } |
|
267 | 283 | return Database::prepare( |
268 | 284 | 'SELECT majs_i_id AS indi,' . |
269 | 285 | ' GROUP_CONCAT(DISTINCT majs_gen ORDER BY majs_gen ASC SEPARATOR ",") AS generations' . |
@@ -283,9 +299,12 @@ discard block |
||
283 | 299 | * @return array Array of Sosa individuals |
284 | 300 | */ |
285 | 301 | public function getSosaListAtGeneration($gen){ |
286 | - if(!$this->is_setup) return array(); |
|
287 | - if(!$this->sosa_list_by_gen) |
|
288 | - $this->sosa_list_by_gen = array(); |
|
302 | + if(!$this->is_setup) { |
|
303 | + return array(); |
|
304 | + } |
|
305 | + if(!$this->sosa_list_by_gen) { |
|
306 | + $this->sosa_list_by_gen = array(); |
|
307 | + } |
|
289 | 308 | |
290 | 309 | if($gen){ |
291 | 310 | if(!isset($this->sosa_list_by_gen[$gen])){ |
@@ -314,9 +333,12 @@ discard block |
||
314 | 333 | * @return array Array of Sosa families |
315 | 334 | */ |
316 | 335 | public function getFamilySosaListAtGeneration($gen){ |
317 | - if(!$this->is_setup) return array(); |
|
318 | - if(!$this->sosa_fam_list_by_gen) |
|
319 | - $this->sosa_fam_list_by_gen = array(); |
|
336 | + if(!$this->is_setup) { |
|
337 | + return array(); |
|
338 | + } |
|
339 | + if(!$this->sosa_fam_list_by_gen) { |
|
340 | + $this->sosa_fam_list_by_gen = array(); |
|
341 | + } |
|
320 | 342 | |
321 | 343 | if($gen){ |
322 | 344 | if(!isset($this->sosa_fam_list_by_gen[$gen])){ |
@@ -350,7 +372,9 @@ discard block |
||
350 | 372 | * @return array Array of Sosa individuals |
351 | 373 | */ |
352 | 374 | public function getMissingSosaListAtGeneration($gen){ |
353 | - if(!$this->is_setup) return array(); |
|
375 | + if(!$this->is_setup) { |
|
376 | + return array(); |
|
377 | + } |
|
354 | 378 | if($gen){ |
355 | 379 | return $this->sosa_list_by_gen[$gen] = Database::prepare( |
356 | 380 | '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'. |
@@ -390,7 +414,9 @@ discard block |
||
390 | 414 | * @return array Statistics array |
391 | 415 | */ |
392 | 416 | public function getStatisticsByGeneration() { |
393 | - if(!$this->is_setup) return array(); |
|
417 | + if(!$this->is_setup) { |
|
418 | + return array(); |
|
419 | + } |
|
394 | 420 | if(!$this->statistics_tab) { |
395 | 421 | $this->statistics_tab = array(); |
396 | 422 | if($maxGeneration = $this->getLastGeneration()) { |
@@ -418,7 +444,9 @@ discard block |
||
418 | 444 | * @return int |
419 | 445 | */ |
420 | 446 | public function getTotalIndividuals() { |
421 | - if(!$this->is_setup) return 0; |
|
447 | + if(!$this->is_setup) { |
|
448 | + return 0; |
|
449 | + } |
|
422 | 450 | return Database::prepare( |
423 | 451 | 'SELECT COUNT(*) FROM `##individuals`' . |
424 | 452 | ' WHERE i_file = :tree_id') |
@@ -432,7 +460,9 @@ discard block |
||
432 | 460 | * @return number Number of Sosas |
433 | 461 | */ |
434 | 462 | public function getSosaCount(){ |
435 | - if(!$this->is_setup) return 0; |
|
463 | + if(!$this->is_setup) { |
|
464 | + return 0; |
|
465 | + } |
|
436 | 466 | return Database::prepare( |
437 | 467 | 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
438 | 468 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
@@ -449,7 +479,9 @@ discard block |
||
449 | 479 | * @return number Number of Sosas in generation |
450 | 480 | */ |
451 | 481 | public function getSosaCountAtGeneration($gen){ |
452 | - if(!$this->is_setup) return 0; |
|
482 | + if(!$this->is_setup) { |
|
483 | + return 0; |
|
484 | + } |
|
453 | 485 | return Database::prepare( |
454 | 486 | 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
455 | 487 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -468,7 +500,9 @@ discard block |
||
468 | 500 | * @return number Total number of Sosas up to generation |
469 | 501 | */ |
470 | 502 | public function getSosaCountUpToGeneration($gen){ |
471 | - if(!$this->is_setup) return 0; |
|
503 | + if(!$this->is_setup) { |
|
504 | + return 0; |
|
505 | + } |
|
472 | 506 | return Database::prepare( |
473 | 507 | 'SELECT COUNT(majs_sosa) FROM `##maj_sosa`' . |
474 | 508 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -486,7 +520,9 @@ discard block |
||
486 | 520 | * @return number Total number of distinct individual |
487 | 521 | */ |
488 | 522 | public function getDifferentSosaCount(){ |
489 | - if(!$this->is_setup) return 0; |
|
523 | + if(!$this->is_setup) { |
|
524 | + return 0; |
|
525 | + } |
|
490 | 526 | return Database::prepare( |
491 | 527 | 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
492 | 528 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id') |
@@ -503,7 +539,9 @@ discard block |
||
503 | 539 | * @return number Number of distinct Sosa individuals up to generation |
504 | 540 | */ |
505 | 541 | public function getDifferentSosaCountUpToGeneration($gen){ |
506 | - if(!$this->is_setup) return 0; |
|
542 | + if(!$this->is_setup) { |
|
543 | + return 0; |
|
544 | + } |
|
507 | 545 | return Database::prepare( |
508 | 546 | 'SELECT COUNT(DISTINCT majs_i_id) FROM `##maj_sosa`' . |
509 | 547 | ' WHERE majs_gedcom_id=:tree_id AND majs_user_id=:user_id'. |
@@ -528,7 +566,9 @@ discard block |
||
528 | 566 | * @return array Birth statistics array |
529 | 567 | */ |
530 | 568 | public function getStatsBirthYearInGeneration($gen){ |
531 | - if(!$this->is_setup) return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0); |
|
569 | + if(!$this->is_setup) { |
|
570 | + return array('first' => 0, 'first_est' => 0, 'avg' => 0, 'last' => 0, 'last_est' => 0); |
|
571 | + } |
|
532 | 572 | return Database::prepare( |
533 | 573 | 'SELECT'. |
534 | 574 | ' MIN(majs_birth_year) AS first, MIN(majs_birth_year_est) AS first_est,'. |
@@ -550,7 +590,9 @@ discard block |
||
550 | 590 | * @return number|NULL Mean generation time |
551 | 591 | */ |
552 | 592 | public function getMeanGenerationTime(){ |
553 | - if(!$this->is_setup) return; |
|
593 | + if(!$this->is_setup) { |
|
594 | + return; |
|
595 | + } |
|
554 | 596 | if(!$this->statistics_tab){ |
555 | 597 | $this->getStatisticsByGeneration(); |
556 | 598 | } |
@@ -596,7 +638,10 @@ discard block |
||
596 | 638 | * @return array |
597 | 639 | */ |
598 | 640 | public function getAncestorDispersionForGen($gen) { |
599 | - if(!$this->is_setup || $gen > 11) return array(); // Going further than 11 gen will be out of range in the query |
|
641 | + if(!$this->is_setup || $gen > 11) { |
|
642 | + return array(); |
|
643 | + } |
|
644 | + // Going further than 11 gen will be out of range in the query |
|
600 | 645 | return Database::prepare( |
601 | 646 | 'SELECT branches, count(i_id)'. |
602 | 647 | ' FROM ('. |
@@ -636,7 +681,9 @@ discard block |
||
636 | 681 | * @return array |
637 | 682 | */ |
638 | 683 | public function getTopMultiSosaAncestorsNoTies($limit) { |
639 | - if(!$this->is_setup) return array(); |
|
684 | + if(!$this->is_setup) { |
|
685 | + return array(); |
|
686 | + } |
|
640 | 687 | return Database::prepare( |
641 | 688 | 'SELECT sosa_i_id, sosa_count FROM ('. |
642 | 689 | ' SELECT'. |
@@ -19,121 +19,121 @@ |
||
19 | 19 | */ |
20 | 20 | class SosaCalculator { |
21 | 21 | |
22 | - /** |
|
23 | - * Maximium size for the temporary Sosa table |
|
24 | - * @var int TMP_SOSA_TABLE_LIMIT |
|
25 | - */ |
|
26 | - const TMP_SOSA_TABLE_LIMIT = 1000; |
|
22 | + /** |
|
23 | + * Maximium size for the temporary Sosa table |
|
24 | + * @var int TMP_SOSA_TABLE_LIMIT |
|
25 | + */ |
|
26 | + const TMP_SOSA_TABLE_LIMIT = 1000; |
|
27 | 27 | |
28 | - /** |
|
29 | - * Reference user |
|
30 | - * @var Fisharebest\Webtrees\User $user |
|
31 | - */ |
|
32 | - protected $user; |
|
28 | + /** |
|
29 | + * Reference user |
|
30 | + * @var Fisharebest\Webtrees\User $user |
|
31 | + */ |
|
32 | + protected $user; |
|
33 | 33 | |
34 | - /** |
|
35 | - * Reference tree |
|
36 | - * @var Fisharebest\Webtrees\Tree $tree |
|
37 | - */ |
|
38 | - protected $tree; |
|
34 | + /** |
|
35 | + * Reference tree |
|
36 | + * @var Fisharebest\Webtrees\Tree $tree |
|
37 | + */ |
|
38 | + protected $tree; |
|
39 | 39 | |
40 | - /** |
|
41 | - * Sosa Provider for the calculator |
|
42 | - * @var \MyArtJaub\Webtrees\Module\Sosa\Model\SosaCalculator $sosa_provider |
|
43 | - */ |
|
44 | - protected $sosa_provider; |
|
40 | + /** |
|
41 | + * Sosa Provider for the calculator |
|
42 | + * @var \MyArtJaub\Webtrees\Module\Sosa\Model\SosaCalculator $sosa_provider |
|
43 | + */ |
|
44 | + protected $sosa_provider; |
|
45 | 45 | |
46 | - /** |
|
47 | - * Temporary Sosa table, used during construction |
|
48 | - * @var array $tmp_sosa_table |
|
49 | - */ |
|
50 | - protected $tmp_sosa_table; |
|
46 | + /** |
|
47 | + * Temporary Sosa table, used during construction |
|
48 | + * @var array $tmp_sosa_table |
|
49 | + */ |
|
50 | + protected $tmp_sosa_table; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Constructor for the Sosa Calculator |
|
54 | - * @param Tree $tree |
|
55 | - * @param User $user |
|
56 | - */ |
|
57 | - public function __construct(Tree $tree, User $user) { |
|
58 | - $this->tree = $tree; |
|
59 | - $this->user = $user; |
|
52 | + /** |
|
53 | + * Constructor for the Sosa Calculator |
|
54 | + * @param Tree $tree |
|
55 | + * @param User $user |
|
56 | + */ |
|
57 | + public function __construct(Tree $tree, User $user) { |
|
58 | + $this->tree = $tree; |
|
59 | + $this->user = $user; |
|
60 | 60 | |
61 | - $this->sosa_provider = new SosaProvider($this->tree, $this->user);; |
|
62 | - } |
|
61 | + $this->sosa_provider = new SosaProvider($this->tree, $this->user);; |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Compute all Sosa ancestors from the user's root individual. |
|
66 | - * @return bool Result of the computation |
|
67 | - */ |
|
68 | - public function computeAll() { |
|
69 | - $root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
70 | - $indi = Individual::getInstance($root_id, $this->tree); |
|
71 | - if($indi){ |
|
72 | - $this->sosa_provider->deleteAll(); |
|
73 | - $this->addNode($indi, 1); |
|
74 | - $this->flushTmpSosaTable(true); |
|
75 | - return true; |
|
76 | - } |
|
77 | - return false; |
|
78 | - } |
|
64 | + /** |
|
65 | + * Compute all Sosa ancestors from the user's root individual. |
|
66 | + * @return bool Result of the computation |
|
67 | + */ |
|
68 | + public function computeAll() { |
|
69 | + $root_id = $this->tree->getUserPreference($this->user, 'MAJ_SOSA_ROOT_ID'); |
|
70 | + $indi = Individual::getInstance($root_id, $this->tree); |
|
71 | + if($indi){ |
|
72 | + $this->sosa_provider->deleteAll(); |
|
73 | + $this->addNode($indi, 1); |
|
74 | + $this->flushTmpSosaTable(true); |
|
75 | + return true; |
|
76 | + } |
|
77 | + return false; |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Compute all Sosa Ancestors from a specified Individual |
|
82 | - * @param Individual $indi |
|
83 | - * @return bool Result of the computation |
|
84 | - */ |
|
85 | - public function computeFromIndividual(Individual $indi) { |
|
86 | - $dindi = new \MyArtJaub\Webtrees\Individual($indi); |
|
87 | - $current_sosas = $dindi->getSosaNumbers(); |
|
88 | - foreach($current_sosas as $current_sosa => $gen) { |
|
89 | - $this->sosa_provider->deleteAncestors($current_sosa); |
|
90 | - $this->addNode($indi, $current_sosa); |
|
91 | - } |
|
92 | - $this->flushTmpSosaTable(true); |
|
93 | - return true; |
|
94 | - } |
|
80 | + /** |
|
81 | + * Compute all Sosa Ancestors from a specified Individual |
|
82 | + * @param Individual $indi |
|
83 | + * @return bool Result of the computation |
|
84 | + */ |
|
85 | + public function computeFromIndividual(Individual $indi) { |
|
86 | + $dindi = new \MyArtJaub\Webtrees\Individual($indi); |
|
87 | + $current_sosas = $dindi->getSosaNumbers(); |
|
88 | + foreach($current_sosas as $current_sosa => $gen) { |
|
89 | + $this->sosa_provider->deleteAncestors($current_sosa); |
|
90 | + $this->addNode($indi, $current_sosa); |
|
91 | + } |
|
92 | + $this->flushTmpSosaTable(true); |
|
93 | + return true; |
|
94 | + } |
|
95 | 95 | |
96 | - /** |
|
97 | - * Recursive method to add individual to the Sosa table, and flush it regularly |
|
98 | - * @param Individual $indi Individual to add |
|
99 | - * @param int $sosa Individual's sosa |
|
100 | - */ |
|
101 | - protected function addNode(Individual $indi, $sosa) { |
|
102 | - $birth_year = $indi->getBirthDate()->gregorianYear(); |
|
103 | - $birth_year_est = $birth_year === 0 ? $indi->getEstimatedBirthDate()->gregorianYear() : $birth_year; |
|
96 | + /** |
|
97 | + * Recursive method to add individual to the Sosa table, and flush it regularly |
|
98 | + * @param Individual $indi Individual to add |
|
99 | + * @param int $sosa Individual's sosa |
|
100 | + */ |
|
101 | + protected function addNode(Individual $indi, $sosa) { |
|
102 | + $birth_year = $indi->getBirthDate()->gregorianYear(); |
|
103 | + $birth_year_est = $birth_year === 0 ? $indi->getEstimatedBirthDate()->gregorianYear() : $birth_year; |
|
104 | 104 | |
105 | - $death_year = $indi->getDeathDate()->gregorianYear(); |
|
106 | - $death_year_est = $death_year === 0 ? $indi->getEstimatedDeathDate()->gregorianYear() : $death_year; |
|
105 | + $death_year = $indi->getDeathDate()->gregorianYear(); |
|
106 | + $death_year_est = $death_year === 0 ? $indi->getEstimatedDeathDate()->gregorianYear() : $death_year; |
|
107 | 107 | |
108 | - $this->tmp_sosa_table[] = array( |
|
109 | - 'indi' => $indi->getXref(), |
|
110 | - 'sosa' => $sosa, |
|
111 | - 'birth_year' => $birth_year === 0 ? null : $birth_year, |
|
112 | - 'birth_year_est' => $birth_year_est === 0 ? null : $birth_year_est, |
|
113 | - 'death_year' => $death_year === 0 ? null : $death_year, |
|
114 | - 'death_year_est' => $death_year_est === 0 ? null : $death_year_est |
|
115 | - ); |
|
108 | + $this->tmp_sosa_table[] = array( |
|
109 | + 'indi' => $indi->getXref(), |
|
110 | + 'sosa' => $sosa, |
|
111 | + 'birth_year' => $birth_year === 0 ? null : $birth_year, |
|
112 | + 'birth_year_est' => $birth_year_est === 0 ? null : $birth_year_est, |
|
113 | + 'death_year' => $death_year === 0 ? null : $death_year, |
|
114 | + 'death_year_est' => $death_year_est === 0 ? null : $death_year_est |
|
115 | + ); |
|
116 | 116 | |
117 | - $this->flushTmpSosaTable(); |
|
117 | + $this->flushTmpSosaTable(); |
|
118 | 118 | |
119 | - if($fam = $indi->getPrimaryChildFamily()) { |
|
120 | - if($husb = $fam->getHusband()) $this->addNode($husb, 2 * $sosa); |
|
121 | - if($wife = $fam->getWife()) $this->addNode($wife, 2 * $sosa + 1); |
|
122 | - } |
|
123 | - } |
|
119 | + if($fam = $indi->getPrimaryChildFamily()) { |
|
120 | + if($husb = $fam->getHusband()) $this->addNode($husb, 2 * $sosa); |
|
121 | + if($wife = $fam->getWife()) $this->addNode($wife, 2 * $sosa + 1); |
|
122 | + } |
|
123 | + } |
|
124 | 124 | |
125 | - /** |
|
126 | - * Write sosas in the table, if the number of items is superior to the limit, or if forced. |
|
127 | - * |
|
128 | - * @param bool $force Should the flush be forced |
|
129 | - */ |
|
130 | - protected function flushTmpSosaTable($force = false) { |
|
131 | - if( count($this->tmp_sosa_table)> 0 && |
|
132 | - ($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT)){ |
|
133 | - $this->sosa_provider->insertOrUpdate($this->tmp_sosa_table); |
|
134 | - $this->tmp_sosa_table = array(); |
|
135 | - } |
|
136 | - } |
|
125 | + /** |
|
126 | + * Write sosas in the table, if the number of items is superior to the limit, or if forced. |
|
127 | + * |
|
128 | + * @param bool $force Should the flush be forced |
|
129 | + */ |
|
130 | + protected function flushTmpSosaTable($force = false) { |
|
131 | + if( count($this->tmp_sosa_table)> 0 && |
|
132 | + ($force || count($this->tmp_sosa_table) >= self::TMP_SOSA_TABLE_LIMIT)){ |
|
133 | + $this->sosa_provider->insertOrUpdate($this->tmp_sosa_table); |
|
134 | + $this->tmp_sosa_table = array(); |
|
135 | + } |
|
136 | + } |
|
137 | 137 | |
138 | 138 | } |
139 | 139 | |
140 | 140 | \ No newline at end of file |