. */ /** * Class FamilyTreeStatisticsModule */ class FamilyTreeStatisticsModule extends Module implements ModuleBlockInterface { /** {@inheritdoc} */ public function getTitle() { return /* I18N: Name of a module */ I18N::translate('Statistics'); } /** {@inheritdoc} */ public function getDescription() { return /* I18N: Description of “Statistics” module */ I18N::translate('The size of the family tree, earliest and latest events, common names, etc.'); } /** {@inheritdoc} */ public function getBlock($block_id, $template = true, $cfg = null) { global $WT_TREE, $ctype; $show_last_update = get_block_setting($block_id, 'show_last_update', '1'); $show_common_surnames = get_block_setting($block_id, 'show_common_surnames', '1'); $stat_indi = get_block_setting($block_id, 'stat_indi', '1'); $stat_fam = get_block_setting($block_id, 'stat_fam', '1'); $stat_sour = get_block_setting($block_id, 'stat_sour', '1'); $stat_media = get_block_setting($block_id, 'stat_media', '1'); $stat_repo = get_block_setting($block_id, 'stat_repo', '1'); $stat_surname = get_block_setting($block_id, 'stat_surname', '1'); $stat_events = get_block_setting($block_id, 'stat_events', '1'); $stat_users = get_block_setting($block_id, 'stat_users', '1'); $stat_first_birth = get_block_setting($block_id, 'stat_first_birth', '1'); $stat_last_birth = get_block_setting($block_id, 'stat_last_birth', '1'); $stat_first_death = get_block_setting($block_id, 'stat_first_death', '1'); $stat_last_death = get_block_setting($block_id, 'stat_last_death', '1'); $stat_long_life = get_block_setting($block_id, 'stat_long_life', '1'); $stat_avg_life = get_block_setting($block_id, 'stat_avg_life', '1'); $stat_most_chil = get_block_setting($block_id, 'stat_most_chil', '1'); $stat_avg_chil = get_block_setting($block_id, 'stat_avg_chil', '1'); // This can be overriden when embedding in an HTML block $block = '0'; $stat_link = '1'; if ($cfg) { foreach (array('show_common_surnames', 'stat_indi', 'stat_fam', 'stat_sour', 'stat_media', 'stat_surname', 'stat_events', 'stat_users', 'stat_first_birth', 'stat_last_birth', 'stat_first_death', 'stat_last_death', 'stat_long_life', 'stat_avg_life', 'stat_most_chil', 'stat_avg_chil', 'stat_link', 'block') as $name) { if (array_key_exists($name, $cfg)) { $$name = $cfg[$name]; } } } $id = $this->getName() . $block_id; $class = $this->getName() . '_block'; if ($ctype === 'gedcom' && WT_USER_GEDCOM_ADMIN || $ctype === 'user' && Auth::check()) { $title = ''; } else { $title = ''; } $title .= $this->getTitle(); $stats = new Stats($WT_TREE); $content = '' . WT_TREE_TITLE . '
'; if ($show_last_update) { $content .= '
' . /* I18N: %s is a date */ I18N::translate('This family tree was last updated on %s.', strip_tags($stats->gedcomUpdated())) . '
'; } /** Responsive Design */ $content .= '
'; if ($stat_indi) { $content .= '
' . I18N::translate('Individuals') . '
'; $content .= '
' . I18N::translate('Males') . '
' . $stats->totalSexMales() . '
' . $stats->totalSexMalesPercentage() . '
'; $content .= '
' . I18N::translate('Females') . '
' . $stats->totalSexFemales() . '
' . $stats->totalSexFemalesPercentage() . '
'; } if ($stat_surname) { $content .= '
' . I18N::translate('Total surnames') . '
'; } if ($stat_fam) { $content .= '
' . I18N::translate('Families') . '
'; } if ($stat_sour) { $content .= '
' . I18N::translate('Sources') . '
'; } if ($stat_media) { $content .= '
' . I18N::translate('Media objects') . '
'; } if ($stat_repo) { $content .= '
' . I18N::translate('Repositories') . '
'; } if ($stat_events) { $content .= '
' . I18N::translate('Total events') . '
' . $stats->totalEvents() . '
'; } if ($stat_users) { $content .= '
' . I18N::translate('Total users') . '
'; if (WT_USER_GEDCOM_ADMIN) { $content .= '' . $stats->totalUsers() . ''; } else { $content .= $stats->totalUsers(); } $content .= '
'; } if (!$block) { $content .= '
'; } if ($stat_first_birth) { $content .= '
' . I18N::translate('Earliest birth year') . '
' . $stats->firstBirthYear() . '
'; if (!$block) { $content .= '
' . $stats->firstBirth() . '
'; } $content .= '
'; } if ($stat_last_birth) { $content .= '
' . I18N::translate('Latest birth year') . '
' . $stats->lastBirthYear() . '
'; if (!$block) { $content .= '
' . $stats->lastBirth() . '
'; } $content .= '
'; } if ($stat_first_death) { $content .= '
' . I18N::translate('Earliest death year') . '
' . $stats->firstDeathYear() . '
'; if (!$block) { $content .= '
' . $stats->firstDeath() . '
'; } $content .= '
'; } if ($stat_last_death) { $content .= '
' . I18N::translate('Latest death year') . '
' . $stats->lastDeathYear() . '
'; if (!$block) { $content .= '
' . $stats->lastDeath() . '
'; } $content .= '
'; } if ($stat_long_life) { $content .= '
' . I18N::translate('Individual who lived the longest') . '
' . $stats->LongestLifeAge() . '
'; if (!$block) { $content .= '
' . $stats->LongestLife() . '
'; } $content .= '
'; } if ($stat_avg_life) { $content .= '
' . I18N::translate('Average age at death') . '
' . $stats->averageLifespan() . '
'; if (!$block) { $content .= '
' . I18N::translate('Males') . ': ' . $stats->averageLifespanMale(); $content .= '   ' . I18N::translate('Females') . ': ' . $stats->averageLifespanFemale() . '
'; } $content .= '
'; } if ($stat_most_chil && !$block) { $content .= '
' . I18N::translate('Family with the most children') . '
' . $stats->largestFamilySize() . '
'; if (!$block) { $content .= '
' . $stats->largestFamily() . '
'; } $content .= '
'; } if ($stat_avg_chil) { $content .= '
' . I18N::translate('Average number of children per family') . '
' . $stats->averageChildren() . '
'; if (!$block) { $content .= '
'; } $content .= '
'; } if ($stat_link) { $content .= '
' . I18N::translate('View statistics as graphs') . '
'; } // NOTE: Print the most common surnames if ($show_common_surnames) { $surnames = get_common_surnames($WT_TREE->getPreference('COMMON_NAMES_THRESHOLD'), $WT_TREE); if (count($surnames) > 0) { $content .= '

' . I18N::translate('Most common surnames') . '

'; $content .= '
'; $i = 0; foreach ($surnames as $indexval => $surname) { if (stristr($surname['name'], '@N.N') === false) { if ($i > 0) { $content .= ', '; } $content .= '' . $surname['name'] . ''; $i++; } } $content .= '
'; } } if ($template) { return Theme::theme()->formatBlock($id, $title, $class, $content); } else { return $content; } } /** {@inheritdoc} */ public function loadAjax() { return true; } /** {@inheritdoc} */ public function isUserBlock() { return true; } /** {@inheritdoc} */ public function isGedcomBlock() { return true; } /** {@inheritdoc} */ public function configureBlock($block_id) { if (Filter::postBool('save') && Filter::checkCsrf()) { set_block_setting($block_id, 'show_last_update', Filter::postBool('show_last_update')); set_block_setting($block_id, 'show_common_surnames', Filter::postBool('show_common_surnames')); set_block_setting($block_id, 'stat_indi', Filter::postBool('stat_indi')); set_block_setting($block_id, 'stat_fam', Filter::postBool('stat_fam')); set_block_setting($block_id, 'stat_sour', Filter::postBool('stat_sour')); set_block_setting($block_id, 'stat_other', Filter::postBool('stat_other')); set_block_setting($block_id, 'stat_media', Filter::postBool('stat_media')); set_block_setting($block_id, 'stat_repo', Filter::postBool('stat_repo')); set_block_setting($block_id, 'stat_surname', Filter::postBool('stat_surname')); set_block_setting($block_id, 'stat_events', Filter::postBool('stat_events')); set_block_setting($block_id, 'stat_users', Filter::postBool('stat_users')); set_block_setting($block_id, 'stat_first_birth', Filter::postBool('stat_first_birth')); set_block_setting($block_id, 'stat_last_birth', Filter::postBool('stat_last_birth')); set_block_setting($block_id, 'stat_first_death', Filter::postBool('stat_first_death')); set_block_setting($block_id, 'stat_last_death', Filter::postBool('stat_last_death')); set_block_setting($block_id, 'stat_long_life', Filter::postBool('stat_long_life')); set_block_setting($block_id, 'stat_avg_life', Filter::postBool('stat_avg_life')); set_block_setting($block_id, 'stat_most_chil', Filter::postBool('stat_most_chil')); set_block_setting($block_id, 'stat_avg_chil', Filter::postBool('stat_avg_chil')); } $show_last_update = get_block_setting($block_id, 'show_last_update', '1'); $show_common_surnames = get_block_setting($block_id, 'show_common_surnames', '1'); $stat_indi = get_block_setting($block_id, 'stat_indi', '1'); $stat_fam = get_block_setting($block_id, 'stat_fam', '1'); $stat_sour = get_block_setting($block_id, 'stat_sour', '1'); $stat_media = get_block_setting($block_id, 'stat_media', '1'); $stat_repo = get_block_setting($block_id, 'stat_repo', '1'); $stat_surname = get_block_setting($block_id, 'stat_surname', '1'); $stat_events = get_block_setting($block_id, 'stat_events', '1'); $stat_users = get_block_setting($block_id, 'stat_users', '1'); $stat_first_birth = get_block_setting($block_id, 'stat_first_birth', '1'); $stat_last_birth = get_block_setting($block_id, 'stat_last_birth', '1'); $stat_first_death = get_block_setting($block_id, 'stat_first_death', '1'); $stat_last_death = get_block_setting($block_id, 'stat_last_death', '1'); $stat_long_life = get_block_setting($block_id, 'stat_long_life', '1'); $stat_avg_life = get_block_setting($block_id, 'stat_avg_life', '1'); $stat_most_chil = get_block_setting($block_id, 'stat_most_chil', '1'); $stat_avg_chil = get_block_setting($block_id, 'stat_avg_chil', '1'); echo ''; echo /* I18N: label for yes/no option */ I18N::translate('Show date of last update?'); echo ''; echo edit_field_yes_no('show_last_update', $show_last_update); echo ''; echo ''; echo I18N::translate('Show common surnames?'); echo ''; echo edit_field_yes_no('show_common_surnames', $show_common_surnames); echo ''; ?>