summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Module/FamiliesSidebarSidebarModule.php24
-rw-r--r--app/Module/IndividualSidebarModule.php18
-rw-r--r--app/Module/TopSurnamesModule.php2
-rw-r--r--app/Query/QueryName.php48
-rw-r--r--app/Stats.php6
-rw-r--r--famlist.php8
-rw-r--r--indilist.php8
7 files changed, 59 insertions, 55 deletions
diff --git a/app/Module/FamiliesSidebarSidebarModule.php b/app/Module/FamiliesSidebarSidebarModule.php
index 81e3a2e9d5..b1cb342e8c 100644
--- a/app/Module/FamiliesSidebarSidebarModule.php
+++ b/app/Module/FamiliesSidebarSidebarModule.php
@@ -67,9 +67,9 @@ class FamiliesSidebarModule extends Module implements ModuleSidebarInterface {
if ($search) {
return $this->search($WT_TREE, $search);
} elseif ($alpha == '@' || $alpha == ',' || $surname) {
- return $this->getSurnameFams($alpha, $surname);
+ return $this->getSurnameFams($WT_TREE, $alpha, $surname);
} elseif ($alpha) {
- return $this->getAlphaSurnames($alpha, $surname);
+ return $this->getAlphaSurnames($WT_TREE, $alpha, $surname);
} else {
return '';
}
@@ -80,7 +80,7 @@ class FamiliesSidebarModule extends Module implements ModuleSidebarInterface {
global $UNKNOWN_NN, $controller, $WT_TREE;
// Fetch a list of the initial letters of all surnames in the database
- $initials = QueryName::surnameAlpha(true, false, $WT_TREE->getTreeId(), false);
+ $initials = QueryName::surnameAlpha($WT_TREE, true, false, false);
$controller->addInlineJavascript('
var famloadedNames = new Array();
@@ -160,21 +160,20 @@ class FamiliesSidebarModule extends Module implements ModuleSidebarInterface {
}
/**
+ * @param Tree $tree
* @param string $alpha
* @param string $surname1
*
* @return string
*/
- public function getAlphaSurnames($alpha, $surname1 = '') {
- global $WT_TREE;
-
- $surnames = QueryName::surnames('', $alpha, true, true, $WT_TREE->getTreeId());
+ public function getAlphaSurnames(Tree $tree, $alpha, $surname1 = '') {
+ $surnames = QueryName::surnames($tree, '', $alpha, true, true);
$out = '<ul>';
foreach (array_keys($surnames) as $surname) {
$out .= '<li id="sb_fam_' . $surname . '" class="sb_fam_surname_li"><a href="' . $surname . '" title="' . $surname . '" alt="' . $alpha . '" class="sb_fam_surname">' . $surname . '</a>';
if (!empty($surname1) && $surname1 == $surname) {
$out .= '<div class="name_tree_div_visible">';
- $out .= $this->getSurnameFams($alpha, $surname1);
+ $out .= $this->getSurnameFams($tree, $alpha, $surname1);
$out .= '</div>';
} else {
$out .= '<div class="name_tree_div"></div>';
@@ -186,15 +185,14 @@ class FamiliesSidebarModule extends Module implements ModuleSidebarInterface {
}
/**
+ * @param Tree $tree
* @param string $alpha
* @param string $surname
*
* @return string
*/
- public function getSurnameFams($alpha, $surname) {
- global $WT_TREE;
-
- $families = QueryName::families($surname, $alpha, '', true, $WT_TREE->getTreeId());
+ public function getSurnameFams(Tree $tree, $alpha, $surname) {
+ $families = QueryName::families($tree, $surname, $alpha, '', true);
$out = '<ul>';
foreach ($families as $family) {
if ($family->canShowName()) {
@@ -209,6 +207,7 @@ class FamiliesSidebarModule extends Module implements ModuleSidebarInterface {
}
}
$out .= '</ul>';
+
return $out;
}
@@ -270,6 +269,7 @@ class FamiliesSidebarModule extends Module implements ModuleSidebarInterface {
}
}
$out .= '</ul>';
+
return $out;
}
}
diff --git a/app/Module/IndividualSidebarModule.php b/app/Module/IndividualSidebarModule.php
index 6b31eca4a5..7cd48e8a0a 100644
--- a/app/Module/IndividualSidebarModule.php
+++ b/app/Module/IndividualSidebarModule.php
@@ -67,9 +67,9 @@ class IndividualSidebarModule extends Module implements ModuleSidebarInterface {
if ($search) {
return $this->search($WT_TREE, $search);
} elseif ($alpha == '@' || $alpha == ',' || $surname) {
- return $this->getSurnameIndis($alpha, $surname);
+ return $this->getSurnameIndis($WT_TREE, $alpha, $surname);
} elseif ($alpha) {
- return $this->getAlphaSurnames($alpha, $surname);
+ return $this->getAlphaSurnames($WT_TREE, $alpha, $surname);
} else {
return '';
}
@@ -80,7 +80,7 @@ class IndividualSidebarModule extends Module implements ModuleSidebarInterface {
global $WT_IMAGES, $UNKNOWN_NN, $controller, $WT_TREE;
// Fetch a list of the initial letters of all surnames in the database
- $initials = QueryName::surnameAlpha(true, false, $WT_TREE->getTreeId(), false);
+ $initials = QueryName::surnameAlpha($WT_TREE, true, false, false);
$controller->addInlineJavascript('
var loadedNames = new Array();
@@ -160,15 +160,16 @@ class IndividualSidebarModule extends Module implements ModuleSidebarInterface {
}
/**
+ * @param Tree $tree
* @param string $alpha
* @param string $surname1
*
* @return string
*/
- public function getAlphaSurnames($alpha, $surname1 = '') {
+ private function getAlphaSurnames(Tree $tree, $alpha, $surname1 = '') {
global $WT_TREE;
- $surnames = QueryName::surnames('', $alpha, true, false, $WT_TREE->getTreeId());
+ $surnames = QueryName::surnames($WT_TREE, '', $alpha, true, false);
$out = '<ul>';
foreach (array_keys($surnames) as $surname) {
$out .= '<li id="sb_indi_' . $surname . '" class="sb_indi_surname_li"><a href="' . $surname . '" title="' . $surname . '" alt="' . $alpha . '" class="sb_indi_surname">' . $surname . '</a>';
@@ -187,15 +188,14 @@ class IndividualSidebarModule extends Module implements ModuleSidebarInterface {
}
/**
+ * @param Tree $tree
* @param string $alpha
* @param string $surname
*
* @return string
*/
- public function getSurnameIndis($alpha, $surname) {
- global $WT_TREE;
-
- $indis = QueryName::individuals($surname, $alpha, '', true, false, $WT_TREE->getTreeId());
+ private function getSurnameIndis(Tree $tree, $alpha, $surname) {
+ $indis = QueryName::individuals($tree, $surname, $alpha, '', true, false);
$out = '<ul>';
foreach ($indis as $person) {
if ($person->canShowName()) {
diff --git a/app/Module/TopSurnamesModule.php b/app/Module/TopSurnamesModule.php
index 904e7d0448..deb891bb3c 100644
--- a/app/Module/TopSurnamesModule.php
+++ b/app/Module/TopSurnamesModule.php
@@ -63,7 +63,7 @@ class TopSurnamesModule extends Module implements ModuleBlockInterface {
$all_surnames = array();
$i = 0;
foreach (array_keys($top_surnames) as $top_surname) {
- $all_surnames = array_merge($all_surnames, QueryName::surnames($top_surname, '', false, false, $WT_TREE->getTreeId()));
+ $all_surnames = array_merge($all_surnames, QueryName::surnames($WT_TREE, $top_surname, '', false, false));
if (++$i == $num) {
break;
}
diff --git a/app/Query/QueryName.php b/app/Query/QueryName.php
index 74ba7cfe00..8fe42d7c14 100644
--- a/app/Query/QueryName.php
+++ b/app/Query/QueryName.php
@@ -20,7 +20,7 @@ namespace Fisharebest\Webtrees;
* Class QueryName - generate lists for indilist.php and famlist.php
*
* @package webtrees
- * @copyright (c) 2014 webtrees development team
+ * @copyright (c) 2015 webtrees development team
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2
*/
class QueryName {
@@ -223,6 +223,7 @@ class QueryName {
}
break;
}
+
// Easy cases: the MySQL collation rules take care of it
return "$field LIKE CONCAT('@'," . Database::quote($letter) . ",'%') COLLATE " . I18N::$collation . " ESCAPE '@'";
}
@@ -230,21 +231,21 @@ class QueryName {
/**
* Get a list of initial surname letters for indilist.php and famlist.php
*
- * @param boolean $marnm if set, include married names
- * @param boolean $fams if set, only consider individuals with FAMS records
- * @param integer $ged_id only consider individuals from this tree
- * @param boolean $totals if set, count the number of names beginning with each letter
+ * @param Tree $tree Find surnames from this tree
+ * @param boolean $marnm if set, include married names
+ * @param boolean $fams if set, only consider individuals with FAMS records
+ * @param boolean $totals if set, count the number of names beginning with each letter
*
* @return integer[]
*/
- public static function surnameAlpha($marnm, $fams, $ged_id, $totals = true) {
+ public static function surnameAlpha(Tree $tree, $marnm, $fams, $totals = true) {
$alphas = array();
$sql =
"SELECT SQL_CACHE COUNT(n_id)" .
" FROM `##name` " .
($fams ? " JOIN `##link` ON (n_id=l_from AND n_file=l_file AND l_type='FAMS') " : "") .
- " WHERE n_file={$ged_id}" .
+ " WHERE n_file=" . $tree->getTreeId() .
($marnm ? "" : " AND n_type!='_MARNM'");
// Fetch all the letters in our alphabet, whether or not there
@@ -268,7 +269,7 @@ class QueryName {
($marnm ? "" : " AND n_type != '_MARNM'");
$args = array(
- 'tree_id' => $ged_id,
+ 'tree_id' => $tree->getTreeId(),
);
foreach (self::getAlphabetForLocale(WT_LOCALE) as $n => $letter) {
@@ -290,7 +291,7 @@ class QueryName {
($marnm ? "" : " AND n_type != '_MARNM'");
$args = array(
- 'tree_id' => $ged_id,
+ 'tree_id' => $tree->getTreeId(),
);
$num_none = Database::prepare($sql)->execute($args)->fetchOne();
@@ -305,6 +306,7 @@ class QueryName {
/**
* Get a list of initial given name letters for indilist.php and famlist.php
*
+ * @param Tree $tree Find names in this tree
* @param string $surn if set, only consider people with this surname
* @param string $salpha if set, only consider surnames starting with this letter
* @param boolean $marnm if set, include married names
@@ -313,14 +315,14 @@ class QueryName {
*
* @return integer[]
*/
- public static function givenAlpha($surn, $salpha, $marnm, $fams, $ged_id) {
+ public static function givenAlpha(Tree $tree, $surn, $salpha, $marnm, $fams) {
$alphas = array();
$sql =
"SELECT SQL_CACHE COUNT(DISTINCT n_id)" .
" FROM `##name`" .
($fams ? " JOIN `##link` ON (n_id=l_from AND n_file=l_file AND l_type='FAMS') " : "") .
- " WHERE n_file={$ged_id} " .
+ " WHERE n_file=" . $tree->getTreeId() . " " .
($marnm ? "" : " AND n_type!='_MARNM'");
if ($surn) {
@@ -354,7 +356,7 @@ class QueryName {
($marnm ? "" : " AND n_type != '_MARNM'");
$args = array(
- 'tree_id' => $ged_id,
+ 'tree_id' => $tree->getTreeId(),
);
if ($surn) {
@@ -387,15 +389,15 @@ class QueryName {
/**
* Get a list of actual surnames and variants, based on a "root" surname.
*
+ * @param Tree $tree only fetch individuals from this tree
* @param string $surn if set, only fetch people with this surname
* @param string $salpha if set, only consider surnames starting with this letter
* @param boolean $marnm if set, include married names
* @param boolean $fams if set, only consider individuals with FAMS records
- * @param integer $ged_id only consider individuals from this gedcom
*
* @return array
*/
- public static function surnames($surn, $salpha, $marnm, $fams, $ged_id) {
+ public static function surnames(Tree $tree, $surn, $salpha, $marnm, $fams) {
$sql =
"SELECT SQL_CACHE n2.n_surn, n1.n_surname, n1.n_id" .
" FROM `##name` n1 " .
@@ -405,7 +407,7 @@ class QueryName {
($marnm ? "" : " AND n_type != '_MARNM'");
$args = array(
- 'tree_id' => $ged_id,
+ 'tree_id' => $tree->getTreeId(),
);
if ($surn) {
@@ -430,6 +432,7 @@ class QueryName {
foreach (Database::prepare($sql)->execute($args)->fetchAll() as $row) {
$list[I18N::strtoupper($row->n_surn)][$row->n_surname][$row->n_id] = true;
}
+
return $list;
}
@@ -439,17 +442,16 @@ class QueryName {
* To search for unknown names, use $surn="@N.N.", $salpha="@" or $galpha="@"
* To search for names with no surnames, use $salpha=","
*
+ * @param Tree $tree only fetch individuals from this tree
* @param string $surn if set, only fetch people with this surname
* @param string $salpha if set, only fetch surnames starting with this letter
* @param string $galpha if set, only fetch given names starting with this letter
* @param boolean $marnm if set, include married names
* @param boolean $fams if set, only fetch individuals with FAMS records
- * @param integer $ged_id if set, only fetch individuals from this gedcom
*
* @return Individual[]
*/
- public static function individuals($surn, $salpha, $galpha, $marnm, $fams, $ged_id) {
- $tree = Tree::findById($ged_id);
+ public static function individuals(Tree $tree, $surn, $salpha, $galpha, $marnm, $fams) {
$sql =
"SELECT i_id AS xref, i_gedcom AS gedcom, n_full " .
"FROM `##individuals` " .
@@ -459,7 +461,7 @@ class QueryName {
($marnm ? "" : "AND n_type != '_MARNM'");
$args = array(
- 'tree_id' => $ged_id,
+ 'tree_id' => $tree->getTreeId(),
);
if ($surn) {
@@ -500,6 +502,7 @@ class QueryName {
}
}
}
+
return $list;
}
@@ -509,22 +512,23 @@ class QueryName {
* To search for unknown names, use $surn="@N.N.", $salpha="@" or $galpha="@"
* To search for names with no surnames, use $salpha=","
*
+ * @param Tree $tree only fetch individuals from this tree
* @param string $surn if set, only fetch people with this surname
* @param string $salpha if set, only fetch surnames starting with this letter
* @param string $galpha if set, only fetch given names starting with this letter
* @param boolean $marnm if set, include married names
- * @param integer $ged_id if set, only fetch individuals from this gedcom
*
* @return Family[]
*/
- public static function families($surn, $salpha, $galpha, $marnm, $ged_id) {
+ public static function families(Tree $tree, $surn, $salpha, $galpha, $marnm) {
$list = array();
- foreach (self::individuals($surn, $salpha, $galpha, $marnm, true, $ged_id) as $indi) {
+ foreach (self::individuals($tree, $surn, $salpha, $galpha, $marnm, true) as $indi) {
foreach ($indi->getSpouseFamilies() as $family) {
$list[$family->getXref()] = $family;
}
}
usort($list, __NAMESPACE__ . '\GedcomRecord::compare');
+
return $list;
}
}
diff --git a/app/Stats.php b/app/Stats.php
index d87fb3a81c..76bac7333f 100644
--- a/app/Stats.php
+++ b/app/Stats.php
@@ -1456,7 +1456,7 @@ class Stats {
$chart_title = I18N::translate('Surname distribution chart') . ': ' . $surname;
// Count how many people are events in each country
$surn_countries = array();
- $indis = QueryName::individuals(I18N::strtoupper($surname), '', '', false, false, $this->tree->getTreeId());
+ $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.
@@ -4833,7 +4833,7 @@ class Stats {
// Note that we count/display SPFX SURN, but sort/group under just SURN
$surnames = array();
foreach (array_keys($surname_list) as $surname) {
- $surnames = array_merge($surnames, QueryName::surnames($surname, '', false, false, $this->tree->getTreeId()));
+ $surnames = array_merge($surnames, QueryName::surnames($this->tree, $surname, '', false, false));
}
return format_surname_list($surnames, ($type == 'list' ? 1 : 2), $show_tot, 'indilist.php', $this->tree);
}
@@ -4933,7 +4933,7 @@ class Stats {
if ($n >= $maxtoshow) {
break;
}
- $all_surnames = array_merge($all_surnames, QueryName::surnames(I18N::strtoupper($surname), '', false, false, $this->tree->getTreeId()));
+ $all_surnames = array_merge($all_surnames, QueryName::surnames($this->tree, I18N::strtoupper($surname), '', false, false));
}
$tot = 0;
foreach ($surnames as $surname) {
diff --git a/famlist.php b/famlist.php
index a047707ce8..65aaf2a7f9 100644
--- a/famlist.php
+++ b/famlist.php
@@ -128,7 +128,7 @@ echo '<h2 class="center">', I18N::translate('Families'), '</h2>';
// Print a selection list of initial letters
$list = array();
-foreach (QueryName::surnameAlpha($show_marnm === 'yes', true, $WT_TREE->getTreeId()) as $letter => $count) {
+foreach (QueryName::surnameAlpha($WT_TREE, $show_marnm === 'yes', true) as $letter => $count) {
switch ($letter) {
case '@':
$html = $UNKNOWN_NN;
@@ -184,7 +184,7 @@ if (!Auth::isSearchEngine()) {
}
if ($show === 'indi' || $show === 'surn') {
- $surns = QueryName::surnames($surname, $alpha, $show_marnm === 'yes', true, $WT_TREE->getTreeId());
+ $surns = QueryName::surnames($WT_TREE, $surname, $alpha, $show_marnm === 'yes', true);
if ($show === 'surn') {
// Show the surname list
switch ($WT_TREE->getPreference('SURNAME_LIST_STYLE')) {
@@ -212,7 +212,7 @@ if ($show === 'indi' || $show === 'surn') {
$falpha = '';
$show_all_firstnames = 'no';
} else {
- $givn_initials = QueryName::givenAlpha($surname, $alpha, $show_marnm === 'yes', true, $WT_TREE->getTreeId());
+ $givn_initials = QueryName::givenAlpha($WT_TREE, $surname, $alpha, $show_marnm === 'yes', true);
// Break long lists by initial letter of given name
if ($surname || $show_all === 'yes') {
// Don't show the list until we have some filter criteria
@@ -252,7 +252,7 @@ if ($show === 'indi' || $show === 'surn') {
}
}
if ($show === 'indi') {
- echo format_fam_table(QueryName::families($surname, $alpha, $falpha, $show_marnm === 'yes', $WT_TREE->getTreeId()));
+ echo format_fam_table(QueryName::families($WT_TREE, $surname, $alpha, $falpha, $show_marnm === 'yes'));
}
}
}
diff --git a/indilist.php b/indilist.php
index 434f51ad97..426902d48b 100644
--- a/indilist.php
+++ b/indilist.php
@@ -128,7 +128,7 @@ echo '<h2 class="center">', I18N::translate('Individuals'), '</h2>';
// Print a selection list of initial letters
$list = array();
-foreach (QueryName::surnameAlpha($show_marnm === 'yes', false, $WT_TREE->getTreeId()) as $letter => $count) {
+foreach (QueryName::surnameAlpha($WT_TREE, $show_marnm === 'yes', false) as $letter => $count) {
switch ($letter) {
case '@':
$html = $UNKNOWN_NN;
@@ -184,7 +184,7 @@ if (!Auth::isSearchEngine()) {
}
if ($show === 'indi' || $show === 'surn') {
- $surns = QueryName::surnames($surname, $alpha, $show_marnm === 'yes', false, $WT_TREE->getTreeId());
+ $surns = QueryName::surnames($WT_TREE, $surname, $alpha, $show_marnm === 'yes', false);
if ($show === 'surn') {
// Show the surname list
switch ($WT_TREE->getPreference('SURNAME_LIST_STYLE')) {
@@ -212,7 +212,7 @@ if ($show === 'indi' || $show === 'surn') {
$falpha = '';
$show_all_firstnames = 'no';
} else {
- $givn_initials = QueryName::givenAlpha($surname, $alpha, $show_marnm === 'yes', false, $WT_TREE->getTreeId());
+ $givn_initials = QueryName::givenAlpha($WT_TREE, $surname, $alpha, $show_marnm === 'yes', false);
// Break long lists by initial letter of given name
if ($surname || $show_all === 'yes') {
// Don't show the list until we have some filter criteria
@@ -252,7 +252,7 @@ if ($show === 'indi' || $show === 'surn') {
}
}
if ($show === 'indi') {
- echo format_indi_table(QueryName::individuals($surname, $alpha, $falpha, $show_marnm === 'yes', false, $WT_TREE->getTreeId()));
+ echo format_indi_table(QueryName::individuals($WT_TREE, $surname, $alpha, $falpha, $show_marnm === 'yes', false));
}
}
}