From 3763c3f2dff6a4360b7b8810b6250e372dded805 Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Sun, 8 Mar 2015 21:51:25 +0000 Subject: Create test harnesses for modules --- app/Module/FamiliesSidebarModule.php | 268 ------------- app/Module/FamiliesSidebarSidebarModule.php | 268 +++++++++++++ app/Module/IndividualFactsModule.php | 529 -------------------------- app/Module/IndividualFactsTabModule.php | 529 ++++++++++++++++++++++++++ app/Module/MissingFactsReportModule.php | 54 +++ app/Module/MissingFactsReportModuleModule.php | 54 --- app/Module/TopGivenNamesModule.php | 153 ++++++++ app/Module/TopGivenNamesModuleModule.php | 153 -------- 8 files changed, 1004 insertions(+), 1004 deletions(-) delete mode 100644 app/Module/FamiliesSidebarModule.php create mode 100644 app/Module/FamiliesSidebarSidebarModule.php delete mode 100644 app/Module/IndividualFactsModule.php create mode 100644 app/Module/IndividualFactsTabModule.php create mode 100644 app/Module/MissingFactsReportModule.php delete mode 100644 app/Module/MissingFactsReportModuleModule.php create mode 100644 app/Module/TopGivenNamesModule.php delete mode 100644 app/Module/TopGivenNamesModuleModule.php (limited to 'app') diff --git a/app/Module/FamiliesSidebarModule.php b/app/Module/FamiliesSidebarModule.php deleted file mode 100644 index a50a7d475e..0000000000 --- a/app/Module/FamiliesSidebarModule.php +++ /dev/null @@ -1,268 +0,0 @@ -. - */ - -use Zend_Session; - -/** - * Class FamiliesModule - */ -class FamiliesModule extends Module implements ModuleSidebarInterface { - /** {@inheritdoc} */ - public function getTitle() { - return /* I18N: Name of a module/sidebar */ I18N::translate('Family list'); - } - - /** {@inheritdoc} */ - public function getDescription() { - return /* I18N: Description of the “Families” module */ I18N::translate('A sidebar showing an alphabetic list of all the families in the family tree.'); - } - - /** {@inheritdoc} */ - public function modAction($modAction) { - switch ($modAction) { - case 'ajax': - Zend_Session::writeClose(); - header('Content-Type: text/html; charset=UTF-8'); - echo $this->getSidebarAjaxContent(); - break; - default: - http_response_code(404); - break; - } - } - - /** {@inheritdoc} */ - public function defaultSidebarOrder() { - return 50; - } - - /** {@inheritdoc} */ - public function hasSidebarContent() { - return !Auth::isSearchEngine(); - } - - /** {@inheritdoc} */ - public function getSidebarAjaxContent() { - $alpha = Filter::get('alpha'); // All surnames beginning with this letter where "@"=unknown and ","=none - $surname = Filter::get('surname'); // All indis with this surname. - $search = Filter::get('search'); - - if ($search) { - return $this->search($search); - } elseif ($alpha == '@' || $alpha == ',' || $surname) { - return $this->getSurnameFams($alpha, $surname); - } elseif ($alpha) { - return $this->getAlphaSurnames($alpha, $surname); - } else { - return ''; - } - } - - /** {@inheritdoc} */ - public function getSidebarContent() { - global $UNKNOWN_NN, $controller; - - // Fetch a list of the initial letters of all surnames in the database - $initials = QueryName::surnameAlpha(true, false, WT_GED_ID, false); - - $controller->addInlineJavascript(' - var famloadedNames = new Array(); - - function fsearchQ() { - var query = jQuery("#sb_fam_name").val(); - if (query.length>1) { - jQuery("#sb_fam_content").load("module.php?mod=' . $this->getName() . '&mod_action=ajax&sb_action=families&search="+query); - } - } - - var famtimerid = null; - jQuery("#sb_fam_name").keyup(function(e) { - if (famtimerid) window.clearTimeout(famtimerid); - famtimerid = window.setTimeout("fsearchQ()", 500); - }); - jQuery("#sb_content_families").on("click", ".sb_fam_letter", function() { - jQuery("#sb_fam_content").load(this.href); - return false; - }); - jQuery("#sb_content_families").on("click", ".sb_fam_surname", function() { - var surname = jQuery(this).attr("title"); - var alpha = jQuery(this).attr("alt"); - - if (!famloadedNames[surname]) { - jQuery.ajax({ - url: "module.php?mod='.$this->getName() . '&mod_action=ajax&sb_action=families&alpha="+alpha+"&surname="+surname, - cache: false, - success: function(html) { - jQuery("#sb_fam_"+surname+" div").html(html); - jQuery("#sb_fam_"+surname+" div").show(); - jQuery("#sb_fam_"+surname).css("list-style-image", "url(' . Theme::theme()->parameter('image-minus') . ')"); - famloadedNames[surname]=2; - } - }); - } - else if (famloadedNames[surname]==1) { - famloadedNames[surname]=2; - jQuery("#sb_fam_"+surname+" div").show(); - jQuery("#sb_fam_"+surname).css("list-style-image", "url(' . Theme::theme()->parameter('image-minus') . ')"); - } - else { - famloadedNames[surname]=1; - jQuery("#sb_fam_"+surname+" div").hide(); - jQuery("#sb_fam_"+surname).css("list-style-image", "url(' . Theme::theme()->parameter('image-plus') . ')"); - } - return false; - }); - '); - $out = - '
' . - '' . - '

'; - foreach ($initials as $letter=>$count) { - switch ($letter) { - case '@': - $html = $UNKNOWN_NN; - break; - case ',': - $html = I18N::translate('None'); - break; - case ' ': - $html = ' '; - break; - default: - $html = $letter; - break; - } - $html = '' . $html . ''; - $out .= $html . " "; - } - - $out .= '

'; - $out .= '
'; - $out .= '
'; - return $out; - } - - /** - * @param string $alpha - * @param string $surname1 - * - * @return string - */ - public function getAlphaSurnames($alpha, $surname1 = '') { - $surnames = QueryName::surnames('', $alpha, true, true, WT_GED_ID); - $out = ''; - return $out; - } - - /** - * @param string $alpha - * @param string $surname - * - * @return string - */ - public function getSurnameFams($alpha, $surname) { - $families = QueryName::families($surname, $alpha, '', true, WT_GED_ID); - $out = ''; - return $out; - } - - /** - * @param string $query - * - * @return string - */ - public function search($query) { - if (strlen($query) < 2) { - return ''; - } - - //-- search for INDI names - $rows = Database::prepare( - "SELECT i_id AS xref" . - " FROM `##individuals`, `##name`" . - " WHERE (i_id LIKE ? OR n_sort LIKE ?)" . - " AND i_id=n_id AND i_file=n_file AND i_file=?" . - " ORDER BY n_sort" - ) - ->execute(array("%{$query}%", "%{$query}%", WT_GED_ID)) - ->fetchAll(); - $ids = array(); - foreach ($rows as $row) { - $ids[] = $row->xref; - } - - $vars = array(); - if (empty($ids)) { - //-- no match : search for FAM id - $where = "f_id LIKE ?"; - $vars[] = "%{$query}%"; - } else { - //-- search for spouses - $qs = implode(',', array_fill(0, count($ids), '?')); - $where = "(f_husb IN ($qs) OR f_wife IN ($qs))"; - $vars = array_merge($vars, $ids, $ids); - } - - $vars[] = WT_GED_ID; - $rows = Database::prepare("SELECT f_id AS xref, f_file AS gedcom_id, f_gedcom AS gedcom FROM `##families` WHERE {$where} AND f_file=?") - ->execute($vars) - ->fetchAll(); - - $out = ''; - return $out; - } -} diff --git a/app/Module/FamiliesSidebarSidebarModule.php b/app/Module/FamiliesSidebarSidebarModule.php new file mode 100644 index 0000000000..847b753059 --- /dev/null +++ b/app/Module/FamiliesSidebarSidebarModule.php @@ -0,0 +1,268 @@ +. + */ + +use Zend_Session; + +/** + * Class FamiliesSidebarModule + */ +class FamiliesSidebarModule extends Module implements ModuleSidebarInterface { + /** {@inheritdoc} */ + public function getTitle() { + return /* I18N: Name of a module/sidebar */ I18N::translate('Family list'); + } + + /** {@inheritdoc} */ + public function getDescription() { + return /* I18N: Description of the “Families” module */ I18N::translate('A sidebar showing an alphabetic list of all the families in the family tree.'); + } + + /** {@inheritdoc} */ + public function modAction($modAction) { + switch ($modAction) { + case 'ajax': + Zend_Session::writeClose(); + header('Content-Type: text/html; charset=UTF-8'); + echo $this->getSidebarAjaxContent(); + break; + default: + http_response_code(404); + break; + } + } + + /** {@inheritdoc} */ + public function defaultSidebarOrder() { + return 50; + } + + /** {@inheritdoc} */ + public function hasSidebarContent() { + return !Auth::isSearchEngine(); + } + + /** {@inheritdoc} */ + public function getSidebarAjaxContent() { + $alpha = Filter::get('alpha'); // All surnames beginning with this letter where "@"=unknown and ","=none + $surname = Filter::get('surname'); // All indis with this surname. + $search = Filter::get('search'); + + if ($search) { + return $this->search($search); + } elseif ($alpha == '@' || $alpha == ',' || $surname) { + return $this->getSurnameFams($alpha, $surname); + } elseif ($alpha) { + return $this->getAlphaSurnames($alpha, $surname); + } else { + return ''; + } + } + + /** {@inheritdoc} */ + public function getSidebarContent() { + global $UNKNOWN_NN, $controller; + + // Fetch a list of the initial letters of all surnames in the database + $initials = QueryName::surnameAlpha(true, false, WT_GED_ID, false); + + $controller->addInlineJavascript(' + var famloadedNames = new Array(); + + function fsearchQ() { + var query = jQuery("#sb_fam_name").val(); + if (query.length>1) { + jQuery("#sb_fam_content").load("module.php?mod=' . $this->getName() . '&mod_action=ajax&sb_action=families&search="+query); + } + } + + var famtimerid = null; + jQuery("#sb_fam_name").keyup(function(e) { + if (famtimerid) window.clearTimeout(famtimerid); + famtimerid = window.setTimeout("fsearchQ()", 500); + }); + jQuery("#sb_content_families").on("click", ".sb_fam_letter", function() { + jQuery("#sb_fam_content").load(this.href); + return false; + }); + jQuery("#sb_content_families").on("click", ".sb_fam_surname", function() { + var surname = jQuery(this).attr("title"); + var alpha = jQuery(this).attr("alt"); + + if (!famloadedNames[surname]) { + jQuery.ajax({ + url: "module.php?mod='.$this->getName() . '&mod_action=ajax&sb_action=families&alpha="+alpha+"&surname="+surname, + cache: false, + success: function(html) { + jQuery("#sb_fam_"+surname+" div").html(html); + jQuery("#sb_fam_"+surname+" div").show(); + jQuery("#sb_fam_"+surname).css("list-style-image", "url(' . Theme::theme()->parameter('image-minus') . ')"); + famloadedNames[surname]=2; + } + }); + } + else if (famloadedNames[surname]==1) { + famloadedNames[surname]=2; + jQuery("#sb_fam_"+surname+" div").show(); + jQuery("#sb_fam_"+surname).css("list-style-image", "url(' . Theme::theme()->parameter('image-minus') . ')"); + } + else { + famloadedNames[surname]=1; + jQuery("#sb_fam_"+surname+" div").hide(); + jQuery("#sb_fam_"+surname).css("list-style-image", "url(' . Theme::theme()->parameter('image-plus') . ')"); + } + return false; + }); + '); + $out = + '
' . + '' . + '

'; + foreach ($initials as $letter=>$count) { + switch ($letter) { + case '@': + $html = $UNKNOWN_NN; + break; + case ',': + $html = I18N::translate('None'); + break; + case ' ': + $html = ' '; + break; + default: + $html = $letter; + break; + } + $html = '' . $html . ''; + $out .= $html . " "; + } + + $out .= '

'; + $out .= '
'; + $out .= '
'; + return $out; + } + + /** + * @param string $alpha + * @param string $surname1 + * + * @return string + */ + public function getAlphaSurnames($alpha, $surname1 = '') { + $surnames = QueryName::surnames('', $alpha, true, true, WT_GED_ID); + $out = ''; + return $out; + } + + /** + * @param string $alpha + * @param string $surname + * + * @return string + */ + public function getSurnameFams($alpha, $surname) { + $families = QueryName::families($surname, $alpha, '', true, WT_GED_ID); + $out = ''; + return $out; + } + + /** + * @param string $query + * + * @return string + */ + public function search($query) { + if (strlen($query) < 2) { + return ''; + } + + //-- search for INDI names + $rows = Database::prepare( + "SELECT i_id AS xref" . + " FROM `##individuals`, `##name`" . + " WHERE (i_id LIKE ? OR n_sort LIKE ?)" . + " AND i_id=n_id AND i_file=n_file AND i_file=?" . + " ORDER BY n_sort" + ) + ->execute(array("%{$query}%", "%{$query}%", WT_GED_ID)) + ->fetchAll(); + $ids = array(); + foreach ($rows as $row) { + $ids[] = $row->xref; + } + + $vars = array(); + if (empty($ids)) { + //-- no match : search for FAM id + $where = "f_id LIKE ?"; + $vars[] = "%{$query}%"; + } else { + //-- search for spouses + $qs = implode(',', array_fill(0, count($ids), '?')); + $where = "(f_husb IN ($qs) OR f_wife IN ($qs))"; + $vars = array_merge($vars, $ids, $ids); + } + + $vars[] = WT_GED_ID; + $rows = Database::prepare("SELECT f_id AS xref, f_file AS gedcom_id, f_gedcom AS gedcom FROM `##families` WHERE {$where} AND f_file=?") + ->execute($vars) + ->fetchAll(); + + $out = ''; + return $out; + } +} diff --git a/app/Module/IndividualFactsModule.php b/app/Module/IndividualFactsModule.php deleted file mode 100644 index 00c8df867e..0000000000 --- a/app/Module/IndividualFactsModule.php +++ /dev/null @@ -1,529 +0,0 @@ -. - */ - -/** - * Class IndividualFactsTabModule - */ -class IndividualFactsTabModule extends Module implements ModuleTabInterface { - /** {@inheritdoc} */ - public function getTitle() { - return /* I18N: Name of a module/tab on the individual page. */ I18N::translate('Facts and events'); - } - - /** {@inheritdoc} */ - public function getDescription() { - return /* I18N: Description of the “Facts and events” module */ I18N::translate('A tab showing the facts and events of an individual.'); - } - - /** {@inheritdoc} */ - public function defaultTabOrder() { - return 10; - } - - /** {@inheritdoc} */ - public function isGrayedOut() { - return false; - } - - /** {@inheritdoc} */ - public function getTabContent() { - global $controller; - $EXPAND_HISTO_EVENTS = false; - - $indifacts = array(); - // The individual’s own facts - foreach ($controller->record->getFacts() as $fact) { - switch ($fact->getTag()) { - case 'SEX': - case 'NAME': - case 'SOUR': - case 'OBJE': - case 'NOTE': - case 'FAMC': - case 'FAMS': - break; - default: - if (!array_key_exists('extra_info', Module::getActiveSidebars($controller->record->getTree())) || !ExtraInformationModule::showFact($fact)) { - $indifacts[] = $fact; - } - break; - } - } - - // Add spouse-family facts - foreach ($controller->record->getSpouseFamilies() as $family) { - foreach ($family->getFacts() as $fact) { - switch ($fact->getTag()) { - case 'SOUR': - case 'NOTE': - case 'OBJE': - case 'CHAN': - case '_UID': - case 'RIN': - case 'HUSB': - case 'WIFE': - case 'CHIL': - break; - default: - $indifacts[] = $fact; - break; - } - } - $spouse = $family->getSpouse($controller->record); - if ($spouse) { - foreach (self::spouseFacts($controller->record, $spouse) as $fact) { - $indifacts[] = $fact; - } - } - foreach (self::childFacts($controller->record, $family, '_CHIL', '') as $fact) { - $indifacts[] = $fact; - } - } - - foreach (self::parentFacts($controller->record, 1) as $fact) { - $indifacts[] = $fact; - } - foreach (self::historicalFacts($controller->record) as $fact) { - $indifacts[] = $fact; - } - foreach (self::associateFacts($controller->record) as $fact) { - $indifacts[] = $fact; - } - - sort_facts($indifacts); - - ob_start(); - - echo ''; - echo ''; - if (!$indifacts) { - echo ''; - } - - echo ''; - - foreach ($indifacts as $fact) { - print_fact($fact, $controller->record); - } - - //-- new fact link - if ($controller->record->canEdit()) { - print_add_new_fact($controller->record->getXref(), $indifacts, 'INDI'); - } - echo ''; - echo '
', I18N::translate('There are no facts for this individual.'), '
record->getTree()->getPreference('EXPAND_RELATIVES_EVENTS') ? 'checked' : ''; - echo ' onclick="jQuery(\'tr.rela\').toggle();">'; - if (file_exists(Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php')) { - echo ' '; - } - echo '
'; - - if (!$controller->record->getTree()->getPreference('EXPAND_RELATIVES_EVENTS')) { - echo ''; - } - if (!$EXPAND_HISTO_EVENTS) { - echo ''; - } - - - return '
' . ob_get_clean() . '
'; - } - - /** {@inheritdoc} */ - public function hasTabContent() { - return true; - } - - /** {@inheritdoc} */ - public function canLoadAjax() { - return !Auth::isSearchEngine(); // Search engines cannot use AJAX - } - - /** {@inheritdoc} */ - public function getPreLoadContent() { - return ''; - } - - /** - * Spouse facts that are shown on an individual’s page. - * - * @param Individual $individual Show events that occured during the lifetime of this individual - * @param Individual $spouse Show events of this individual - * - * @return Fact[] - */ - private static function spouseFacts(Individual $individual, Individual $spouse) { - $SHOW_RELATIVES_EVENTS = $individual->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); - - $facts = array(); - if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT_SPOU')) { - // Only include events between birth and death - $birt_date = $individual->getEstimatedBirthDate(); - $deat_date = $individual->getEstimatedDeathDate(); - - foreach ($spouse->getFacts(WT_EVENTS_DEAT) as $fact) { - - $fact_date = $fact->getDate(); - if ($fact_date->isOK() && Date::compare($birt_date, $fact_date) <= 0 && Date::compare($fact_date, $deat_date) <= 0) { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_SPOU'); - $facts[] = $rela_fact; - } - } - } - - return $facts; - } - - /** - * Get the events of children and grandchildren. - * - * @param Individual $person - * @param Family $family - * @param string $option - * @param string $relation - * - * @return Fact[] - */ - private static function childFacts(Individual $person, Family $family, $option, $relation) { - global $controller; - - $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); - - $facts = array(); - - // Only include events between birth and death - $birt_date = $controller->record->getEstimatedBirthDate(); - $deat_date = $controller->record->getEstimatedDeathDate(); - - // Deal with recursion. - switch ($option) { - case '_CHIL': - // Add grandchildren - foreach ($family->getChildren() as $child) { - foreach ($child->getSpouseFamilies() as $cfamily) { - switch ($child->getSex()) { - case 'M': - foreach (self::childFacts($person, $cfamily, '_GCHI', 'son') as $fact) { - $facts[] = $fact; - } - break; - case 'F': - foreach (self::childFacts($person, $cfamily, '_GCHI', 'dau') as $fact) { - $facts[] = $fact; - } - break; - default: - foreach (self::childFacts($person, $cfamily, '_GCHI', 'chi') as $fact) { - $facts[] = $fact; - } - break; - } - } - } - break; - } - - // For each child in the family - foreach ($family->getChildren() as $child) { - if ($child->getXref() == $person->getXref()) { - // We are not our own sibling! - continue; - } - // add child’s birth - if (strpos($SHOW_RELATIVES_EVENTS, '_BIRT' . str_replace('_HSIB', '_SIBL', $option)) !== false) { - foreach ($child->getFacts(WT_EVENTS_BIRT) as $fact) { - $sgdate = $fact->getDate(); - // Always show _BIRT_CHIL, even if the dates are not known - if ($option == '_CHIL' || $sgdate->isOK() && Date::compare($birt_date, $sgdate) <= 0 && Date::compare($sgdate, $deat_date) <= 0) { - if ($option == '_GCHI' && $relation == 'dau') { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); - $facts[] = $rela_fact; - } elseif ($option == '_GCHI' && $relation == 'son') { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); - $facts[] = $rela_fact; - } else { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . $option); - $facts[] = $rela_fact; - } - } - } - } - // add child’s death - if (strpos($SHOW_RELATIVES_EVENTS, '_DEAT' . str_replace('_HSIB', '_SIBL', $option)) !== false) { - foreach ($child->getFacts(WT_EVENTS_DEAT) as $fact) { - $sgdate = $fact->getDate(); - if ($sgdate->isOK() && Date::compare($birt_date, $sgdate) <= 0 && Date::compare($sgdate, $deat_date) <= 0) { - if ($option == '_GCHI' && $relation == 'dau') { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); - $facts[] = $rela_fact; - } elseif ($option == '_GCHI' && $relation == 'son') { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); - $facts[] = $rela_fact; - } else { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . $option); - $facts[] = $rela_fact; - } - } - } - } - // add child’s marriage - if (strstr($SHOW_RELATIVES_EVENTS, '_MARR' . str_replace('_HSIB', '_SIBL', $option))) { - foreach ($child->getSpouseFamilies() as $sfamily) { - foreach ($sfamily->getFacts(WT_EVENTS_MARR) as $fact) { - $sgdate = $fact->getDate(); - if ($sgdate->isOK() && Date::compare($birt_date, $sgdate) <= 0 && Date::compare($sgdate, $deat_date) <= 0) { - if ($option == '_GCHI' && $relation == 'dau') { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); - $facts[] = $rela_fact; - } elseif ($option == '_GCHI' && $relation == 'son') { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); - $facts[] = $rela_fact; - } else { - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . $option); - $facts[] = $rela_fact; - } - } - } - } - } - } - - return $facts; - } - - /** - * Get the events of parents and grandparents. - * - * @param Individual $person - * @param integer $sosa - * - * @return Fact[] - */ - private static function parentFacts(Individual $person, $sosa) { - global $controller; - - $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); - - $facts = array(); - - // Only include events between birth and death - $birt_date = $controller->record->getEstimatedBirthDate(); - $deat_date = $controller->record->getEstimatedDeathDate(); - - if ($sosa == 1) { - foreach ($person->getChildFamilies() as $family) { - // Add siblings - foreach (self::childFacts($person, $family, '_SIBL', '') as $fact) { - $facts[] = $fact; - } - foreach ($family->getSpouses() as $spouse) { - foreach ($spouse->getSpouseFamilies() as $sfamily) { - if ($family !== $sfamily) { - // Add half-siblings - foreach (self::childFacts($person, $sfamily, '_HSIB', '') as $fact) { - $facts[] = $fact; - } - } - } - // Add grandparents - foreach (self::parentFacts($spouse, $spouse->getSex() == 'F' ? 3 : 2) as $fact) { - $facts[] = $fact; - } - } - } - - if (strstr($SHOW_RELATIVES_EVENTS, '_MARR_PARE')) { - // add father/mother marriages - foreach ($person->getChildFamilies() as $sfamily) { - foreach ($sfamily->getFacts(WT_EVENTS_MARR) as $fact) { - if ($fact->getDate()->isOK() && Date::compare($birt_date, $fact->getDate()) <= 0 && Date::compare($fact->getDate(), $deat_date) <= 0) { - // marriage of parents (to each other) - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_FAMC'); - $facts[] = $rela_fact; - } - } - } - foreach ($person->getChildStepFamilies() as $sfamily) { - foreach ($sfamily->getFacts(WT_EVENTS_MARR) as $fact) { - if ($fact->getDate()->isOK() && Date::compare($birt_date, $fact->getDate()) <= 0 && Date::compare($fact->getDate(), $deat_date) <= 0) { - // marriage of a parent (to another spouse) - // Convert the event to a close relatives event - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_PARE'); - $facts[] = $rela_fact; - } - } - } - } - } - - foreach ($person->getChildFamilies() as $family) { - foreach ($family->getSpouses() as $parent) { - if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT' . ($sosa == 1 ? '_PARE' : '_GPAR'))) { - foreach ($parent->getFacts(WT_EVENTS_DEAT) as $fact) { - if ($fact->getDate()->isOK() && Date::compare($birt_date, $fact->getDate()) <= 0 && Date::compare($fact->getDate(), $deat_date) <= 0) { - switch ($sosa) { - case 1: - // Convert the event to a close relatives event. - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_PARE'); - $facts[] = $rela_fact; - break; - case 2: - // Convert the event to a close relatives event - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_GPA1'); - $facts[] = $rela_fact; - break; - case 3: - // Convert the event to a close relatives event - $rela_fact = clone($fact); - $rela_fact->setTag('_' . $fact->getTag() . '_GPA2'); - $facts[] = $rela_fact; - break; - } - } - } - } - } - } - - return $facts; - } - - /** - * Get any historical events. - * - * @param Individual $person - * - * @return Fact[] - */ - private static function historicalFacts(Individual $person) { - $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); - - $facts = array(); - - if ($SHOW_RELATIVES_EVENTS) { - // Only include events between birth and death - $birt_date = $person->getEstimatedBirthDate(); - $deat_date = $person->getEstimatedDeathDate(); - - if (file_exists(Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php')) { - $histo = array(); - require Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php'; - foreach ($histo as $hist) { - // Earlier versions of the WIKI encouraged people to use HTML entities, - // rather than UTF8 encoding. - $hist = html_entity_decode($hist, ENT_QUOTES, 'UTF-8'); - - $fact = new Fact($hist, $person, 'histo'); - $sdate = $fact->getDate(); - if ($sdate->isOK() && Date::compare($birt_date, $sdate) <= 0 && Date::compare($sdate, $deat_date) <= 0) { - $facts[] = $fact; - } - } - } - } - - return $facts; - } - - /** - * Get the events of associates. - * - * @param Individual $person - * - * @return Fact[] - */ - private static function associateFacts(Individual $person) { - $facts = array(); - - $associates = array_merge( - $person->linkedIndividuals('ASSO'), - $person->linkedIndividuals('_ASSO'), - $person->linkedFamilies('ASSO'), - $person->linkedFamilies('_ASSO') - ); - foreach ($associates as $associate) { - foreach ($associate->getFacts() as $fact) { - $arec = $fact->getAttribute('_ASSO'); - if (!$arec) { - $arec = $fact->getAttribute('ASSO'); - } - if ($arec && trim($arec, '@') === $person->getXref()) { - // Extract the important details from the fact - $factrec = '1 ' . $fact->getTag(); - if (preg_match('/\n2 DATE .*/', $fact->getGedcom(), $match)) { - $factrec .= $match[0]; - } - if (preg_match('/\n2 PLAC .*/', $fact->getGedcom(), $match)) { - $factrec .= $match[0]; - } - if ($associate instanceof Family) { - foreach ($associate->getSpouses() as $spouse) { - $factrec .= "\n2 _ASSO @" . $spouse->getXref() . '@'; - } - } else { - $factrec .= "\n2 _ASSO @" . $associate->getXref() . '@'; - // CHR/BAPM events are commonly used. Generate the reverse relationship - if (preg_match('/^(?:BAPM|CHR)$/', $fact->getTag()) && preg_match('/2 _?ASSO @(' . $person->getXref() . ')@\n3 RELA god(?:parent|mother|father)/', $fact->getGedcom())) { - switch ($associate->getSex()) { - case 'M': - $factrec .= "\n3 RELA godson"; - break; - case 'F': - $factrec .= "\n3 RELA goddaughter"; - break; - default: - $factrec .= "\n3 RELA godchild"; - break; - } - } - } - $facts[] = new Fact($factrec, $associate, 'asso'); - } - } - } - - return $facts; - } -} diff --git a/app/Module/IndividualFactsTabModule.php b/app/Module/IndividualFactsTabModule.php new file mode 100644 index 0000000000..00c8df867e --- /dev/null +++ b/app/Module/IndividualFactsTabModule.php @@ -0,0 +1,529 @@ +. + */ + +/** + * Class IndividualFactsTabModule + */ +class IndividualFactsTabModule extends Module implements ModuleTabInterface { + /** {@inheritdoc} */ + public function getTitle() { + return /* I18N: Name of a module/tab on the individual page. */ I18N::translate('Facts and events'); + } + + /** {@inheritdoc} */ + public function getDescription() { + return /* I18N: Description of the “Facts and events” module */ I18N::translate('A tab showing the facts and events of an individual.'); + } + + /** {@inheritdoc} */ + public function defaultTabOrder() { + return 10; + } + + /** {@inheritdoc} */ + public function isGrayedOut() { + return false; + } + + /** {@inheritdoc} */ + public function getTabContent() { + global $controller; + $EXPAND_HISTO_EVENTS = false; + + $indifacts = array(); + // The individual’s own facts + foreach ($controller->record->getFacts() as $fact) { + switch ($fact->getTag()) { + case 'SEX': + case 'NAME': + case 'SOUR': + case 'OBJE': + case 'NOTE': + case 'FAMC': + case 'FAMS': + break; + default: + if (!array_key_exists('extra_info', Module::getActiveSidebars($controller->record->getTree())) || !ExtraInformationModule::showFact($fact)) { + $indifacts[] = $fact; + } + break; + } + } + + // Add spouse-family facts + foreach ($controller->record->getSpouseFamilies() as $family) { + foreach ($family->getFacts() as $fact) { + switch ($fact->getTag()) { + case 'SOUR': + case 'NOTE': + case 'OBJE': + case 'CHAN': + case '_UID': + case 'RIN': + case 'HUSB': + case 'WIFE': + case 'CHIL': + break; + default: + $indifacts[] = $fact; + break; + } + } + $spouse = $family->getSpouse($controller->record); + if ($spouse) { + foreach (self::spouseFacts($controller->record, $spouse) as $fact) { + $indifacts[] = $fact; + } + } + foreach (self::childFacts($controller->record, $family, '_CHIL', '') as $fact) { + $indifacts[] = $fact; + } + } + + foreach (self::parentFacts($controller->record, 1) as $fact) { + $indifacts[] = $fact; + } + foreach (self::historicalFacts($controller->record) as $fact) { + $indifacts[] = $fact; + } + foreach (self::associateFacts($controller->record) as $fact) { + $indifacts[] = $fact; + } + + sort_facts($indifacts); + + ob_start(); + + echo ''; + echo ''; + if (!$indifacts) { + echo ''; + } + + echo ''; + + foreach ($indifacts as $fact) { + print_fact($fact, $controller->record); + } + + //-- new fact link + if ($controller->record->canEdit()) { + print_add_new_fact($controller->record->getXref(), $indifacts, 'INDI'); + } + echo ''; + echo '
', I18N::translate('There are no facts for this individual.'), '
record->getTree()->getPreference('EXPAND_RELATIVES_EVENTS') ? 'checked' : ''; + echo ' onclick="jQuery(\'tr.rela\').toggle();">'; + if (file_exists(Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php')) { + echo ' '; + } + echo '
'; + + if (!$controller->record->getTree()->getPreference('EXPAND_RELATIVES_EVENTS')) { + echo ''; + } + if (!$EXPAND_HISTO_EVENTS) { + echo ''; + } + + + return '
' . ob_get_clean() . '
'; + } + + /** {@inheritdoc} */ + public function hasTabContent() { + return true; + } + + /** {@inheritdoc} */ + public function canLoadAjax() { + return !Auth::isSearchEngine(); // Search engines cannot use AJAX + } + + /** {@inheritdoc} */ + public function getPreLoadContent() { + return ''; + } + + /** + * Spouse facts that are shown on an individual’s page. + * + * @param Individual $individual Show events that occured during the lifetime of this individual + * @param Individual $spouse Show events of this individual + * + * @return Fact[] + */ + private static function spouseFacts(Individual $individual, Individual $spouse) { + $SHOW_RELATIVES_EVENTS = $individual->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); + + $facts = array(); + if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT_SPOU')) { + // Only include events between birth and death + $birt_date = $individual->getEstimatedBirthDate(); + $deat_date = $individual->getEstimatedDeathDate(); + + foreach ($spouse->getFacts(WT_EVENTS_DEAT) as $fact) { + + $fact_date = $fact->getDate(); + if ($fact_date->isOK() && Date::compare($birt_date, $fact_date) <= 0 && Date::compare($fact_date, $deat_date) <= 0) { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_SPOU'); + $facts[] = $rela_fact; + } + } + } + + return $facts; + } + + /** + * Get the events of children and grandchildren. + * + * @param Individual $person + * @param Family $family + * @param string $option + * @param string $relation + * + * @return Fact[] + */ + private static function childFacts(Individual $person, Family $family, $option, $relation) { + global $controller; + + $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); + + $facts = array(); + + // Only include events between birth and death + $birt_date = $controller->record->getEstimatedBirthDate(); + $deat_date = $controller->record->getEstimatedDeathDate(); + + // Deal with recursion. + switch ($option) { + case '_CHIL': + // Add grandchildren + foreach ($family->getChildren() as $child) { + foreach ($child->getSpouseFamilies() as $cfamily) { + switch ($child->getSex()) { + case 'M': + foreach (self::childFacts($person, $cfamily, '_GCHI', 'son') as $fact) { + $facts[] = $fact; + } + break; + case 'F': + foreach (self::childFacts($person, $cfamily, '_GCHI', 'dau') as $fact) { + $facts[] = $fact; + } + break; + default: + foreach (self::childFacts($person, $cfamily, '_GCHI', 'chi') as $fact) { + $facts[] = $fact; + } + break; + } + } + } + break; + } + + // For each child in the family + foreach ($family->getChildren() as $child) { + if ($child->getXref() == $person->getXref()) { + // We are not our own sibling! + continue; + } + // add child’s birth + if (strpos($SHOW_RELATIVES_EVENTS, '_BIRT' . str_replace('_HSIB', '_SIBL', $option)) !== false) { + foreach ($child->getFacts(WT_EVENTS_BIRT) as $fact) { + $sgdate = $fact->getDate(); + // Always show _BIRT_CHIL, even if the dates are not known + if ($option == '_CHIL' || $sgdate->isOK() && Date::compare($birt_date, $sgdate) <= 0 && Date::compare($sgdate, $deat_date) <= 0) { + if ($option == '_GCHI' && $relation == 'dau') { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); + $facts[] = $rela_fact; + } elseif ($option == '_GCHI' && $relation == 'son') { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); + $facts[] = $rela_fact; + } else { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . $option); + $facts[] = $rela_fact; + } + } + } + } + // add child’s death + if (strpos($SHOW_RELATIVES_EVENTS, '_DEAT' . str_replace('_HSIB', '_SIBL', $option)) !== false) { + foreach ($child->getFacts(WT_EVENTS_DEAT) as $fact) { + $sgdate = $fact->getDate(); + if ($sgdate->isOK() && Date::compare($birt_date, $sgdate) <= 0 && Date::compare($sgdate, $deat_date) <= 0) { + if ($option == '_GCHI' && $relation == 'dau') { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); + $facts[] = $rela_fact; + } elseif ($option == '_GCHI' && $relation == 'son') { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); + $facts[] = $rela_fact; + } else { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . $option); + $facts[] = $rela_fact; + } + } + } + } + // add child’s marriage + if (strstr($SHOW_RELATIVES_EVENTS, '_MARR' . str_replace('_HSIB', '_SIBL', $option))) { + foreach ($child->getSpouseFamilies() as $sfamily) { + foreach ($sfamily->getFacts(WT_EVENTS_MARR) as $fact) { + $sgdate = $fact->getDate(); + if ($sgdate->isOK() && Date::compare($birt_date, $sgdate) <= 0 && Date::compare($sgdate, $deat_date) <= 0) { + if ($option == '_GCHI' && $relation == 'dau') { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_GCH1'); + $facts[] = $rela_fact; + } elseif ($option == '_GCHI' && $relation == 'son') { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_GCH2'); + $facts[] = $rela_fact; + } else { + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . $option); + $facts[] = $rela_fact; + } + } + } + } + } + } + + return $facts; + } + + /** + * Get the events of parents and grandparents. + * + * @param Individual $person + * @param integer $sosa + * + * @return Fact[] + */ + private static function parentFacts(Individual $person, $sosa) { + global $controller; + + $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); + + $facts = array(); + + // Only include events between birth and death + $birt_date = $controller->record->getEstimatedBirthDate(); + $deat_date = $controller->record->getEstimatedDeathDate(); + + if ($sosa == 1) { + foreach ($person->getChildFamilies() as $family) { + // Add siblings + foreach (self::childFacts($person, $family, '_SIBL', '') as $fact) { + $facts[] = $fact; + } + foreach ($family->getSpouses() as $spouse) { + foreach ($spouse->getSpouseFamilies() as $sfamily) { + if ($family !== $sfamily) { + // Add half-siblings + foreach (self::childFacts($person, $sfamily, '_HSIB', '') as $fact) { + $facts[] = $fact; + } + } + } + // Add grandparents + foreach (self::parentFacts($spouse, $spouse->getSex() == 'F' ? 3 : 2) as $fact) { + $facts[] = $fact; + } + } + } + + if (strstr($SHOW_RELATIVES_EVENTS, '_MARR_PARE')) { + // add father/mother marriages + foreach ($person->getChildFamilies() as $sfamily) { + foreach ($sfamily->getFacts(WT_EVENTS_MARR) as $fact) { + if ($fact->getDate()->isOK() && Date::compare($birt_date, $fact->getDate()) <= 0 && Date::compare($fact->getDate(), $deat_date) <= 0) { + // marriage of parents (to each other) + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_FAMC'); + $facts[] = $rela_fact; + } + } + } + foreach ($person->getChildStepFamilies() as $sfamily) { + foreach ($sfamily->getFacts(WT_EVENTS_MARR) as $fact) { + if ($fact->getDate()->isOK() && Date::compare($birt_date, $fact->getDate()) <= 0 && Date::compare($fact->getDate(), $deat_date) <= 0) { + // marriage of a parent (to another spouse) + // Convert the event to a close relatives event + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_PARE'); + $facts[] = $rela_fact; + } + } + } + } + } + + foreach ($person->getChildFamilies() as $family) { + foreach ($family->getSpouses() as $parent) { + if (strstr($SHOW_RELATIVES_EVENTS, '_DEAT' . ($sosa == 1 ? '_PARE' : '_GPAR'))) { + foreach ($parent->getFacts(WT_EVENTS_DEAT) as $fact) { + if ($fact->getDate()->isOK() && Date::compare($birt_date, $fact->getDate()) <= 0 && Date::compare($fact->getDate(), $deat_date) <= 0) { + switch ($sosa) { + case 1: + // Convert the event to a close relatives event. + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_PARE'); + $facts[] = $rela_fact; + break; + case 2: + // Convert the event to a close relatives event + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_GPA1'); + $facts[] = $rela_fact; + break; + case 3: + // Convert the event to a close relatives event + $rela_fact = clone($fact); + $rela_fact->setTag('_' . $fact->getTag() . '_GPA2'); + $facts[] = $rela_fact; + break; + } + } + } + } + } + } + + return $facts; + } + + /** + * Get any historical events. + * + * @param Individual $person + * + * @return Fact[] + */ + private static function historicalFacts(Individual $person) { + $SHOW_RELATIVES_EVENTS = $person->getTree()->getPreference('SHOW_RELATIVES_EVENTS'); + + $facts = array(); + + if ($SHOW_RELATIVES_EVENTS) { + // Only include events between birth and death + $birt_date = $person->getEstimatedBirthDate(); + $deat_date = $person->getEstimatedDeathDate(); + + if (file_exists(Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php')) { + $histo = array(); + require Site::getPreference('INDEX_DIRECTORY') . 'histo.' . WT_LOCALE . '.php'; + foreach ($histo as $hist) { + // Earlier versions of the WIKI encouraged people to use HTML entities, + // rather than UTF8 encoding. + $hist = html_entity_decode($hist, ENT_QUOTES, 'UTF-8'); + + $fact = new Fact($hist, $person, 'histo'); + $sdate = $fact->getDate(); + if ($sdate->isOK() && Date::compare($birt_date, $sdate) <= 0 && Date::compare($sdate, $deat_date) <= 0) { + $facts[] = $fact; + } + } + } + } + + return $facts; + } + + /** + * Get the events of associates. + * + * @param Individual $person + * + * @return Fact[] + */ + private static function associateFacts(Individual $person) { + $facts = array(); + + $associates = array_merge( + $person->linkedIndividuals('ASSO'), + $person->linkedIndividuals('_ASSO'), + $person->linkedFamilies('ASSO'), + $person->linkedFamilies('_ASSO') + ); + foreach ($associates as $associate) { + foreach ($associate->getFacts() as $fact) { + $arec = $fact->getAttribute('_ASSO'); + if (!$arec) { + $arec = $fact->getAttribute('ASSO'); + } + if ($arec && trim($arec, '@') === $person->getXref()) { + // Extract the important details from the fact + $factrec = '1 ' . $fact->getTag(); + if (preg_match('/\n2 DATE .*/', $fact->getGedcom(), $match)) { + $factrec .= $match[0]; + } + if (preg_match('/\n2 PLAC .*/', $fact->getGedcom(), $match)) { + $factrec .= $match[0]; + } + if ($associate instanceof Family) { + foreach ($associate->getSpouses() as $spouse) { + $factrec .= "\n2 _ASSO @" . $spouse->getXref() . '@'; + } + } else { + $factrec .= "\n2 _ASSO @" . $associate->getXref() . '@'; + // CHR/BAPM events are commonly used. Generate the reverse relationship + if (preg_match('/^(?:BAPM|CHR)$/', $fact->getTag()) && preg_match('/2 _?ASSO @(' . $person->getXref() . ')@\n3 RELA god(?:parent|mother|father)/', $fact->getGedcom())) { + switch ($associate->getSex()) { + case 'M': + $factrec .= "\n3 RELA godson"; + break; + case 'F': + $factrec .= "\n3 RELA goddaughter"; + break; + default: + $factrec .= "\n3 RELA godchild"; + break; + } + } + } + $facts[] = new Fact($factrec, $associate, 'asso'); + } + } + } + + return $facts; + } +} diff --git a/app/Module/MissingFactsReportModule.php b/app/Module/MissingFactsReportModule.php new file mode 100644 index 0000000000..144b2d9438 --- /dev/null +++ b/app/Module/MissingFactsReportModule.php @@ -0,0 +1,54 @@ +. + */ + +/** + * Class MissingFactsReportModule + */ +class MissingFactsReportModule extends Module implements ModuleReportInterface { + /** {@inheritdoc} */ + public function getTitle() { + // This text also appears in the .XML file - update both together + return /* I18N: Name of a module/report */ I18N::translate('Missing data'); + } + + /** {@inheritdoc} */ + public function getDescription() { + // This text also appears in the .XML file - update both together + return /* I18N: Description of the “Missing data” */ I18N::translate('A report of the information that is missing for an individual and their relatives.'); + } + + /** {@inheritdoc} */ + public function defaultAccessLevel() { + return Auth::PRIV_USER; + } + + /** {@inheritdoc} */ + public function getReportMenus() { + global $WT_TREE; + + $menus = array(); + $menu = new Menu( + $this->getTitle(), + 'reportengine.php?ged=' . $WT_TREE->getNameUrl() . '&action=setup&report=' . WT_MODULES_DIR . $this->getName() . '/report.xml', + 'menu-report-' . $this->getName() + ); + $menus[] = $menu; + + return $menus; + } +} diff --git a/app/Module/MissingFactsReportModuleModule.php b/app/Module/MissingFactsReportModuleModule.php deleted file mode 100644 index 144b2d9438..0000000000 --- a/app/Module/MissingFactsReportModuleModule.php +++ /dev/null @@ -1,54 +0,0 @@ -. - */ - -/** - * Class MissingFactsReportModule - */ -class MissingFactsReportModule extends Module implements ModuleReportInterface { - /** {@inheritdoc} */ - public function getTitle() { - // This text also appears in the .XML file - update both together - return /* I18N: Name of a module/report */ I18N::translate('Missing data'); - } - - /** {@inheritdoc} */ - public function getDescription() { - // This text also appears in the .XML file - update both together - return /* I18N: Description of the “Missing data” */ I18N::translate('A report of the information that is missing for an individual and their relatives.'); - } - - /** {@inheritdoc} */ - public function defaultAccessLevel() { - return Auth::PRIV_USER; - } - - /** {@inheritdoc} */ - public function getReportMenus() { - global $WT_TREE; - - $menus = array(); - $menu = new Menu( - $this->getTitle(), - 'reportengine.php?ged=' . $WT_TREE->getNameUrl() . '&action=setup&report=' . WT_MODULES_DIR . $this->getName() . '/report.xml', - 'menu-report-' . $this->getName() - ); - $menus[] = $menu; - - return $menus; - } -} diff --git a/app/Module/TopGivenNamesModule.php b/app/Module/TopGivenNamesModule.php new file mode 100644 index 0000000000..c4bc8bf4de --- /dev/null +++ b/app/Module/TopGivenNamesModule.php @@ -0,0 +1,153 @@ +. + */ + +/** + * Class TopGivenNamesModule + */ +class TopGivenNamesModule extends Module implements ModuleBlockInterface { + /** {@inheritdoc} */ + public function getTitle() { + return /* I18N: Name of a module. Top=Most common */ I18N::translate('Top given names'); + } + + /** {@inheritdoc} */ + public function getDescription() { + return /* I18N: Description of the “Top given names” module */ I18N::translate('A list of the most popular given names.'); + } + + /** {@inheritdoc} */ + public function getBlock($block_id, $template = true, $cfg = null) { + global $ctype, $WT_TREE; + + $num = get_block_setting($block_id, 'num', '10'); + $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); + $block = get_block_setting($block_id, 'block', '0'); + + if ($cfg) { + foreach (array('num', 'infoStyle', 'block') as $name) { + if (array_key_exists($name, $cfg)) { + $$name = $cfg[$name]; + } + } + } + + $stats = new Stats($WT_TREE); + + $id = $this->getName() . $block_id; + $class = $this->getName() . '_block'; + if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { + $title = ''; + } else { + $title = ''; + } + if ($num == 1) { + // I18N: i.e. most popular given name. + $title .= I18N::translate('Top given name'); + } else { + // I18N: Title for a list of the most common given names, %s is a number. Note that a separate translation exists when %s is 1 + $title .= I18N::plural('Top %s given name', 'Top %s given names', $num, I18N::number($num)); + } + + $content = '
'; + //Select List or Table + switch ($infoStyle) { + case "list": // Output style 1: Simple list style. Better suited to left side of page. + if (I18N::direction() === 'ltr') { + $padding = 'padding-left: 15px'; + } else { + $padding = 'padding-right: 15px'; + } + $params = array(1, $num, 'rcount'); + // List Female names + $totals = $stats->commonGivenFemaleTotals($params); + if ($totals) { + $content .= '' . I18N::translate('Females') . '
' . $totals . '

'; + } + // List Male names + $totals = $stats->commonGivenMaleTotals($params); + if ($totals) { + $content .= '' . I18N::translate('Males') . '
' . $totals . '

'; + } + break; + case "table": // Style 2: Tabular format. Narrow, 2 or 3 column table, good on right side of page + $params = array(1, $num, 'rcount'); + $content .= ' + + + '; + $content .= '
'.$stats->commonGivenFemaleTable($params) . ''.$stats->commonGivenMaleTable($params) . '
'; + break; + } + $content .= "
"; + + if ($template) { + if ($block) { + $class .= ' small_inner_block'; + } + 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, 'num', Filter::postInteger('num', 1, 10000, 10)); + set_block_setting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); + set_block_setting($block_id, 'block', Filter::postBool('block')); + } + + $num = get_block_setting($block_id, 'num', '10'); + $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); + $block = get_block_setting($block_id, 'block', '0'); + + echo ''; + echo I18N::translate('Number of items to show'); + echo ''; + echo ''; + echo ''; + + echo ''; + echo I18N::translate('Presentation style'); + echo ''; + echo select_edit_control('infoStyle', array('list'=> I18N::translate('list'), 'table'=> I18N::translate('table')), null, $infoStyle, ''); + echo ''; + + echo ''; + echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); + echo ''; + echo edit_field_yes_no('block', $block); + echo ''; + } +} diff --git a/app/Module/TopGivenNamesModuleModule.php b/app/Module/TopGivenNamesModuleModule.php deleted file mode 100644 index c4bc8bf4de..0000000000 --- a/app/Module/TopGivenNamesModuleModule.php +++ /dev/null @@ -1,153 +0,0 @@ -. - */ - -/** - * Class TopGivenNamesModule - */ -class TopGivenNamesModule extends Module implements ModuleBlockInterface { - /** {@inheritdoc} */ - public function getTitle() { - return /* I18N: Name of a module. Top=Most common */ I18N::translate('Top given names'); - } - - /** {@inheritdoc} */ - public function getDescription() { - return /* I18N: Description of the “Top given names” module */ I18N::translate('A list of the most popular given names.'); - } - - /** {@inheritdoc} */ - public function getBlock($block_id, $template = true, $cfg = null) { - global $ctype, $WT_TREE; - - $num = get_block_setting($block_id, 'num', '10'); - $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); - $block = get_block_setting($block_id, 'block', '0'); - - if ($cfg) { - foreach (array('num', 'infoStyle', 'block') as $name) { - if (array_key_exists($name, $cfg)) { - $$name = $cfg[$name]; - } - } - } - - $stats = new Stats($WT_TREE); - - $id = $this->getName() . $block_id; - $class = $this->getName() . '_block'; - if ($ctype === 'gedcom' && Auth::isManager($WT_TREE) || $ctype === 'user' && Auth::check()) { - $title = ''; - } else { - $title = ''; - } - if ($num == 1) { - // I18N: i.e. most popular given name. - $title .= I18N::translate('Top given name'); - } else { - // I18N: Title for a list of the most common given names, %s is a number. Note that a separate translation exists when %s is 1 - $title .= I18N::plural('Top %s given name', 'Top %s given names', $num, I18N::number($num)); - } - - $content = '
'; - //Select List or Table - switch ($infoStyle) { - case "list": // Output style 1: Simple list style. Better suited to left side of page. - if (I18N::direction() === 'ltr') { - $padding = 'padding-left: 15px'; - } else { - $padding = 'padding-right: 15px'; - } - $params = array(1, $num, 'rcount'); - // List Female names - $totals = $stats->commonGivenFemaleTotals($params); - if ($totals) { - $content .= '' . I18N::translate('Females') . '
' . $totals . '

'; - } - // List Male names - $totals = $stats->commonGivenMaleTotals($params); - if ($totals) { - $content .= '' . I18N::translate('Males') . '
' . $totals . '

'; - } - break; - case "table": // Style 2: Tabular format. Narrow, 2 or 3 column table, good on right side of page - $params = array(1, $num, 'rcount'); - $content .= ' - - - '; - $content .= '
'.$stats->commonGivenFemaleTable($params) . ''.$stats->commonGivenMaleTable($params) . '
'; - break; - } - $content .= "
"; - - if ($template) { - if ($block) { - $class .= ' small_inner_block'; - } - 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, 'num', Filter::postInteger('num', 1, 10000, 10)); - set_block_setting($block_id, 'infoStyle', Filter::post('infoStyle', 'list|table', 'table')); - set_block_setting($block_id, 'block', Filter::postBool('block')); - } - - $num = get_block_setting($block_id, 'num', '10'); - $infoStyle = get_block_setting($block_id, 'infoStyle', 'table'); - $block = get_block_setting($block_id, 'block', '0'); - - echo ''; - echo I18N::translate('Number of items to show'); - echo ''; - echo ''; - echo ''; - - echo ''; - echo I18N::translate('Presentation style'); - echo ''; - echo select_edit_control('infoStyle', array('list'=> I18N::translate('list'), 'table'=> I18N::translate('table')), null, $infoStyle, ''); - echo ''; - - echo ''; - echo /* I18N: label for a yes/no option */ I18N::translate('Add a scrollbar when block contents grow'); - echo ''; - echo edit_field_yes_no('block', $block); - echo ''; - } -} -- cgit v1.3