/** * Build all patronymic lineages for the reference surname. * * @return array List of root patronymic lineages */ public function buildLineages() { $indis = \Fisharebest\Webtrees\Query\QueryName::individuals($this->tree, $this->surname, null, null, false, false); if (count($indis) == 0) { return null; } $root_lineages = array(); foreach ($indis as $indi) { $pid = $indi->getXref(); if (!isset($this->used_indis[$pid])) { //Find the root of the lineage /** @var Fisharebest\Webtrees\Individual $indiFirst */ $indiFirst = $this->getLineageRootIndividual($indi); if ($indiFirst) { $this->used_indis[$indiFirst->getXref()] = true; if ($indiFirst->canShow()) { //Check if the root individual has brothers and sisters, without parents $indiChildFamily = $indiFirst->getPrimaryChildFamily(); if ($indiChildFamily !== null) { $root_node = new LineageRootNode(null); $root_node->addFamily($indiChildFamily); } else { $root_node = new LineageRootNode($indiFirst); } $root_node = $this->buildLineage($root_node); if ($root_node) { $root_lineages[] = $root_node; } } } } } return $root_lineages; }
/** * Format a list of individuals. * * @param Tree $tree * @param string $alpha * @param string $surname * * @return string */ private function getSurnameIndis(Tree $tree, $alpha, $surname) { $indis = QueryName::individuals($tree, $surname, $alpha, '', true, false); $out = '<ul>'; foreach ($indis as $person) { if ($person->canShowName()) { $out .= '<li><a href="' . $person->getHtmlUrl() . '">' . $person->getSexImage() . ' ' . $person->getFullName() . ' '; if ($person->canShow()) { $bd = $person->getLifeSpan(); if (!empty($bd)) { $out .= ' (' . $bd . ')'; } } $out .= '</a></li>'; } } $out .= '</ul>'; return $out; }
/** * Create a chart showing where events occurred. * * @param string[] $params * * @return string */ public function chartDistribution($params = array()) { $WT_STATS_CHART_COLOR1 = Theme::theme()->parameter('distribution-chart-no-values'); $WT_STATS_CHART_COLOR2 = Theme::theme()->parameter('distribution-chart-high-values'); $WT_STATS_CHART_COLOR3 = Theme::theme()->parameter('distribution-chart-low-values'); $WT_STATS_MAP_X = Theme::theme()->parameter('distribution-chart-x'); $WT_STATS_MAP_Y = Theme::theme()->parameter('distribution-chart-y'); if (isset($params[0])) { $chart_shows = $params[0]; } else { $chart_shows = 'world'; } if (isset($params[1])) { $chart_type = $params[1]; } else { $chart_type = ''; } if (isset($params[2])) { $surname = $params[2]; } else { $surname = ''; } if ($this->totalPlacesQuery() == 0) { return ''; } // Get the country names for each language $country_to_iso3166 = array(); foreach (I18N::activeLocales() as $locale) { I18N::init($locale->languageTag()); $countries = $this->getAllCountries(); foreach ($this->iso3166() as $three => $two) { $country_to_iso3166[$three] = $two; $country_to_iso3166[$countries[$three]] = $two; } } I18N::init(WT_LOCALE); switch ($chart_type) { case 'surname_distribution_chart': if ($surname == "") { $surname = $this->getCommonSurname(); } $chart_title = I18N::translate('Surname distribution chart') . ': ' . $surname; // Count how many people are events in each country $surn_countries = array(); $indis = QueryName::individuals($this->tree, I18N::strtoupper($surname), '', '', false, false); foreach ($indis as $person) { if (preg_match_all('/^2 PLAC (?:.*, *)*(.*)/m', $person->getGedcom(), $matches)) { // webtrees uses 3 letter country codes and localised country names, but google uses 2 letter codes. foreach ($matches[1] as $country) { if (array_key_exists($country, $country_to_iso3166)) { if (array_key_exists($country_to_iso3166[$country], $surn_countries)) { $surn_countries[$country_to_iso3166[$country]]++; } else { $surn_countries[$country_to_iso3166[$country]] = 1; } } } } } break; case 'birth_distribution_chart': $chart_title = I18N::translate('Birth by country'); // Count how many people were born in each country $surn_countries = array(); $b_countries = $this->statsPlaces('INDI', 'BIRT', 0, true); foreach ($b_countries as $place => $count) { $country = $place; if (array_key_exists($country, $country_to_iso3166)) { if (!isset($surn_countries[$country_to_iso3166[$country]])) { $surn_countries[$country_to_iso3166[$country]] = $count; } else { $surn_countries[$country_to_iso3166[$country]] += $count; } } } break; case 'death_distribution_chart': $chart_title = I18N::translate('Death by country'); // Count how many people were death in each country $surn_countries = array(); $d_countries = $this->statsPlaces('INDI', 'DEAT', 0, true); foreach ($d_countries as $place => $count) { $country = $place; if (array_key_exists($country, $country_to_iso3166)) { if (!isset($surn_countries[$country_to_iso3166[$country]])) { $surn_countries[$country_to_iso3166[$country]] = $count; } else { $surn_countries[$country_to_iso3166[$country]] += $count; } } } break; case 'marriage_distribution_chart': $chart_title = I18N::translate('Marriage by country'); // Count how many families got marriage in each country $surn_countries = array(); $m_countries = $this->statsPlaces('FAM'); // webtrees uses 3 letter country codes and localised country names, but google uses 2 letter codes. foreach ($m_countries as $place) { $country = $place['country']; if (array_key_exists($country, $country_to_iso3166)) { if (!isset($surn_countries[$country_to_iso3166[$country]])) { $surn_countries[$country_to_iso3166[$country]] = $place['tot']; } else { $surn_countries[$country_to_iso3166[$country]] += $place['tot']; } } } break; case 'indi_distribution_chart': default: $chart_title = I18N::translate('Individual distribution chart'); // Count how many people have events in each country $surn_countries = array(); $a_countries = $this->statsPlaces('INDI'); // webtrees uses 3 letter country codes and localised country names, but google uses 2 letter codes. foreach ($a_countries as $place) { $country = $place['country']; if (array_key_exists($country, $country_to_iso3166)) { if (!isset($surn_countries[$country_to_iso3166[$country]])) { $surn_countries[$country_to_iso3166[$country]] = $place['tot']; } else { $surn_countries[$country_to_iso3166[$country]] += $place['tot']; } } } break; } $chart_url = "https://chart.googleapis.com/chart?cht=t&chtm=" . $chart_shows; $chart_url .= "&chco=" . $WT_STATS_CHART_COLOR1 . "," . $WT_STATS_CHART_COLOR3 . "," . $WT_STATS_CHART_COLOR2; // country colours $chart_url .= "&chf=bg,s,ECF5FF"; // sea colour $chart_url .= "&chs=" . $WT_STATS_MAP_X . "x" . $WT_STATS_MAP_Y; $chart_url .= "&chld=" . implode('', array_keys($surn_countries)) . "&chd=s:"; foreach ($surn_countries as $count) { $chart_url .= substr(WT_GOOGLE_CHART_ENCODING, (int) ($count / max($surn_countries) * 61), 1); } $chart = '<div id="google_charts" class="center">'; $chart .= '<b>' . $chart_title . '</b><br><br>'; $chart .= '<div align="center"><img src="' . $chart_url . '" alt="' . $chart_title . '" title="' . $chart_title . '" class="gchart" /><br>'; $chart .= '<table class="center"><tr>'; $chart .= '<td bgcolor="#' . $WT_STATS_CHART_COLOR2 . '" width="12"></td><td>' . I18N::translate('Highest population') . ' </td>'; $chart .= '<td bgcolor="#' . $WT_STATS_CHART_COLOR3 . '" width="12"></td><td>' . I18N::translate('Lowest population') . ' </td>'; $chart .= '<td bgcolor="#' . $WT_STATS_CHART_COLOR1 . '" width="12"></td><td>' . I18N::translate('Nobody at all') . ' </td>'; $chart .= '</tr></table></div></div>'; return $chart; }
break; } if ($count) { if ($show === 'indi' && $givn_initial === $falpha && $show_all_firstnames === 'no') { $list[] = '<a class="warning" href="' . $url . '&falpha=' . rawurlencode($givn_initial) . '" title="' . I18N::number($count) . '">' . $html . '</a>'; } else { $list[] = '<a href="' . $url . '&falpha=' . rawurlencode($givn_initial) . '" title="' . I18N::number($count) . '">' . $html . '</a>'; } } else { $list[] = $html; } } // Search spiders don't get the "show all" option as the other links give them everything. if (!Auth::isSearchEngine()) { if ($show_all_firstnames === 'yes') { $list[] = '<span class="warning">' . I18N::translate('All') . '</span>'; } else { $list[] = '<a href="' . $url . '&show_all_firstnames=yes">' . I18N::translate('All') . '</a>'; } } if ($show_all === 'no') { echo '<h2 class="center">', I18N::translate('Individuals with surname %s', $legend), '</h2>'; } echo '<p class="center alpha_index">', implode(' | ', $list), '</p>'; } } if ($show === 'indi') { echo FunctionsPrintLists::individualTable(QueryName::individuals($WT_TREE, $surname, $alpha, $falpha, $show_marnm === 'yes', false)); } } }