summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ancestry.php41
-rw-r--r--compact.php2
-rw-r--r--descendancy.php2
-rw-r--r--fanchart.php2
-rw-r--r--includes/functions/functions_charts.php38
-rw-r--r--includes/functions/functions_print_lists.php18
-rw-r--r--library/WT/Controller/Chart.php57
-rw-r--r--library/WT/Controller/Compact.php9
-rw-r--r--library/WT/Controller/Fanchart.php10
-rw-r--r--library/WT/Controller/Pedigree.php10
-rw-r--r--modules_v3/googlemap/module.php2
-rw-r--r--pedigree.php10
-rw-r--r--tests/includes/functions/FunctionsChartsTest.php9
13 files changed, 90 insertions, 120 deletions
diff --git a/ancestry.php b/ancestry.php
index e7aa48fdc4..06bd484e0a 100644
--- a/ancestry.php
+++ b/ancestry.php
@@ -135,7 +135,7 @@ $controller
if ($controller->error_message) {
echo '<p class="ui-state-error">', $controller->error_message, '</p>';
- exit;
+ return;
}
switch ($controller->chart_style) {
@@ -149,20 +149,17 @@ case 0:
break;
case 1:
// TODO: this should be a parameter to a function, not a global
- $show_cousins=$controller->show_cousins;
+ $show_cousins = $controller->show_cousins;
echo '<div id="ancestry_chart">';
// Booklet
// first page : show indi facts
print_pedigree_person($controller->root);
// process the tree
- $treeid=ancestry_array($controller->root->getXref(), $PEDIGREE_GENERATIONS-1);
- foreach ($treeid as $i=>$pid) {
- if ($pid) {
- $person=WT_Individual::getInstance($pid);
- if ($person) {
- foreach ($person->getChildFamilies() as $family) {
- print_sosa_family($family->getXref(), $pid, $i);
- }
+ $ancestors = $controller->sosaAncestors($PEDIGREE_GENERATIONS-1);
+ foreach ($ancestors as $sosa => $individual) {
+ if ($individual) {
+ foreach ($individual->getChildFamilies() as $family) {
+ print_sosa_family($family->getXref(), $individual, $sosa);
}
}
}
@@ -170,23 +167,21 @@ case 1:
break;
case 2:
// Individual list
- $treeid=ancestry_array($controller->root->getXref(), $PEDIGREE_GENERATIONS);
- echo '<div id="ancestry-list">', format_indi_table($treeid, 'sosa'), '</div>';
+ $ancestors = $controller->sosaAncestors($PEDIGREE_GENERATIONS);
+ echo '<div id="ancestry-list">', format_indi_table($ancestors, 'sosa'), '</div>';
break;
case 3:
// Family list
- $treeid=ancestry_array($controller->root->getXref(), $PEDIGREE_GENERATIONS-1);
- $famlist=array();
- foreach ($treeid as $pid) {
- $person = WT_Individual::getInstance($pid);
- if (!$person) {
- continue;
- }
- foreach ($person->getChildFamilies() as $famc) {
- $famlist[$famc->getXref()]=$famc;
+ $ancestors = $controller->sosaAncestors($PEDIGREE_GENERATIONS-1);
+ $families = array();
+ foreach ($ancestors as $individual) {
+ if ($individual) {
+ foreach ($individual->getChildFamilies() as $family) {
+ $families[$family->getXref()] = $family;
+ }
}
}
- echo '<div id="ancestry-list">', format_fam_table($famlist), '</div>';
+ echo '<div id="ancestry-list">', format_fam_table($families), '</div>';
break;
}
-echo '</div>'; // close #ancestry-page
+echo '</div>';
diff --git a/compact.php b/compact.php
index 41d4b7eb77..52310c7576 100644
--- a/compact.php
+++ b/compact.php
@@ -41,7 +41,7 @@ $controller
<?php echo WT_I18N::translate('Individual'); ?>
</td>
<td class="optionbox vmiddle">
- <input class="pedigree_form" data-autocomplete-type="INDI" type="text" name="rootid" id="rootid" size="3" value="<?php echo $controller->rootid; ?>">
+ <input class="pedigree_form" data-autocomplete-type="INDI" type="text" name="rootid" id="rootid" size="3" value="<?php echo $controller->root->getXref(); ?>">
<?php echo print_findindi_link('rootid'); ?>
</td>
<td <?php echo $SHOW_HIGHLIGHT_IMAGES ? 'rowspan="2"' : ''; ?> class="facts_label03">
diff --git a/descendancy.php b/descendancy.php
index 7b287406ca..6c70c5a23f 100644
--- a/descendancy.php
+++ b/descendancy.php
@@ -43,7 +43,7 @@ $controller
<?php echo WT_I18N::translate('Individual'); ?>
</td>
<td class="optionbox">
- <input class="pedigree_form" data-autocomplete-type="INDI" type="text" id="rootid" name="rootid" size="3" value="<?php echo $controller->rootid; ?>">
+ <input class="pedigree_form" data-autocomplete-type="INDI" type="text" id="rootid" name="rootid" size="3" value="<?php echo $controller->root->getXref(); ?>">
<?php echo print_findindi_link('rootid'); ?>
</td>
<td class="descriptionbox">
diff --git a/fanchart.php b/fanchart.php
index 93e5b6cbdd..82fd9bddaf 100644
--- a/fanchart.php
+++ b/fanchart.php
@@ -80,7 +80,7 @@ $controller
</label>
</td>
<td class="optionbox">
- <input class="pedigree_form" data-autocomplete-type="INDI" type="text" name="rootid" id="rootid" size="3" value="<?php echo $controller->rootid; ?>">
+ <input class="pedigree_form" data-autocomplete-type="INDI" type="text" name="rootid" id="rootid" size="3" value="<?php echo $controller->root->getXref(); ?>">
<?php echo print_findindi_link('rootid'); ?>
</td>
<td class="descriptionbox">
diff --git a/includes/functions/functions_charts.php b/includes/functions/functions_charts.php
index fa75d5726a..995fc2eed5 100644
--- a/includes/functions/functions_charts.php
+++ b/includes/functions/functions_charts.php
@@ -401,44 +401,6 @@ function print_sosa_family($famid, $childid, $sosa, $label="", $parid="", $gpari
}
/**
- * creates an array with all of the individual ids to be displayed on an ascendancy chart
- *
- * the id in position 1 is the root person. The other positions are filled according to the following algorithm
- * if an individual is at position $i then individual $i’s father will occupy position ($i*2) and $i’s mother
- * will occupy ($i*2)+1
- *
- * @param string $rootid
- * @param integer $generations
- *
- * @return string[] $treeid
- */
-function ancestry_array($rootid, $generations) {
- $ancestors = array(
- 1 => $rootid
- );
-
- $max = pow(2, $generations - 1);
- for ($i = 1; $i < $max; $i++) {
- $ancestors[$i * 2] = null;
- $ancestors[$i * 2 + 1] = null;
- $person = WT_Individual::getInstance($ancestors[$i]);
- if ($person) {
- $family = $person->getPrimaryChildFamily();
- if ($family) {
- if ($family->getHusband()) {
- $ancestors[$i * 2] = $family->getHusband()->getXref();
- }
- if ($family->getWife()) {
- $ancestors[$i * 2 + 1] = $family->getWife()->getXref();
- }
- }
- }
- }
-
- return $ancestors;
-}
-
-/**
* print an arrow to a new url
*
* @param string $url target url
diff --git a/includes/functions/functions_print_lists.php b/includes/functions/functions_print_lists.php
index 12f2986d43..e51021eb8e 100644
--- a/includes/functions/functions_print_lists.php
+++ b/includes/functions/functions_print_lists.php
@@ -298,22 +298,8 @@ function format_indi_table($datalist, $option = '') {
$d100y = new WT_Date(date('Y') - 100); // 100 years ago
$unique_indis = array(); // Don't double-count indis with multiple names.
- foreach ($datalist as $key => $value) {
- if (is_object($value)) { // Array of objects
- $person = $value;
- } elseif (!is_array($value)) { // Array of IDs
- $person = WT_Individual::getInstance($value);
- } else { // Array of search results
- $gid = $key;
- if (isset($value['gid'])) {
- $gid = $value['gid'];
- } // from indilist
- if (isset($value[4])) {
- $gid = $value[4];
- } // from indilist ALL
- $person = WT_Individual::getInstance($gid);
- }
- if (!$person || !$person->canShowName()) {
+ foreach ($datalist as $key => $person) {
+ if (!$person->canShowName()) {
continue;
}
if ($person->isPendingAddtion()) {
diff --git a/library/WT/Controller/Chart.php b/library/WT/Controller/Chart.php
index 1ae5cec9fb..5a730bc6be 100644
--- a/library/WT/Controller/Chart.php
+++ b/library/WT/Controller/Chart.php
@@ -19,26 +19,28 @@
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class WT_Controller_Chart extends WT_Controller_Page {
+ /** @var WT_Individual Who is chart about? */
public $root;
- public $rootid;
- public $error_message=null;
+ /** @var string An error message, in case we cannot construct the chart */
+ public $error_message;
+
+ /**
+ *
+ */
public function __construct() {
parent::__construct();
- $this->rootid = WT_Filter::get('rootid', WT_REGEX_XREF);
- if ($this->rootid) {
- $this->root = WT_Individual::getInstance($this->rootid);
- } else {
- // Missing rootid parameter? Do something.
+ $rootid = WT_Filter::get('rootid', WT_REGEX_XREF);
+ $this->root = WT_Individual::getInstance($rootid);
+ if (!$this->root) {
+ // Missing root individual? Show the chart for someone.
$this->root = $this->getSignificantIndividual();
- $this->rootid = $this->root->getXref();
}
if (!$this->root || !$this->root->canShowName()) {
header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
- $this->error_message=WT_I18N::translate('This individual does not exist or you do not have permission to view it.');
- $this->rootid=null;
+ $this->error_message = WT_I18N::translate('This individual does not exist or you do not have permission to view it.');
}
}
@@ -49,4 +51,39 @@ class WT_Controller_Chart extends WT_Controller_Page {
return parent::getSignificantIndividual();
}
}
+
+ /**
+ * Find the direct-line ancestors of an individual. Array indexes are SOSA numbers.
+ *
+ * @param integer $generations
+ *
+ * @return WT_Individual[]
+ */
+ public function sosaAncestors($generations) {
+ $ancestors = array(
+ 1 => $this->root
+ );
+
+ // Subtract one generation, as this algorithm includes parents.
+ $max = pow(2, $generations - 1);
+
+ for ($i = 1; $i < $max; $i++) {
+ $ancestors[$i * 2] = null;
+ $ancestors[$i * 2 + 1] = null;
+ $person = $ancestors[$i];
+ if ($person) {
+ $family = $person->getPrimaryChildFamily();
+ if ($family) {
+ if ($family->getHusband()) {
+ $ancestors[$i * 2] = $family->getHusband();
+ }
+ if ($family->getWife()) {
+ $ancestors[$i * 2 + 1] = $family->getWife();
+ }
+ }
+ }
+ }
+
+ return $ancestors;
+ }
}
diff --git a/library/WT/Controller/Compact.php b/library/WT/Controller/Compact.php
index 2a762607ef..6a0237831c 100644
--- a/library/WT/Controller/Compact.php
+++ b/library/WT/Controller/Compact.php
@@ -42,13 +42,13 @@ class WT_Controller_Compact extends WT_Controller_Chart {
} else {
$this->setPageTitle(WT_I18N::translate('Compact tree'));
}
- $this->treeid=ancestry_array($this->rootid, 5);
+ $this->treeid = $this->sosaAncestors(5);
}
function sosa_person($n) {
global $SHOW_HIGHLIGHT_IMAGES;
- $indi=WT_Individual::getInstance($this->treeid[$n]);
+ $indi = $this->treeid[$n];
if ($indi && $indi->canShowName()) {
$name=$indi->getFullName();
@@ -94,7 +94,7 @@ class WT_Controller_Compact extends WT_Controller_Chart {
function sosa_arrow($n, $arrow_dir) {
global $TEXT_DIRECTION;
- $pid = $this->treeid[$n];
+ $indi = $this->treeid[$n];
$arrow_dir = substr($arrow_dir, 0, 1);
if ($TEXT_DIRECTION == 'rtl') {
@@ -105,10 +105,9 @@ class WT_Controller_Compact extends WT_Controller_Chart {
}
}
- $indi = WT_Individual::getInstance($pid);
if ($indi) {
$title = WT_I18N::translate('Compact tree of %s', $indi->getFullName());
- $text = '<a class="icon-' . $arrow_dir . 'arrow" title="' . strip_tags($title) . '" href="?rootid=' . $pid;
+ $text = '<a class="icon-' . $arrow_dir . 'arrow" title="' . strip_tags($title) . '" href="?rootid=' . $indi->getXref();
if ($this->show_thumbs) {
$text .= "&amp;show_thumbs=".$this->show_thumbs;
}
diff --git a/library/WT/Controller/Fanchart.php b/library/WT/Controller/Fanchart.php
index 477e797052..b4363b9387 100644
--- a/library/WT/Controller/Fanchart.php
+++ b/library/WT/Controller/Fanchart.php
@@ -142,12 +142,12 @@ class WT_Controller_Fanchart extends WT_Controller_Chart {
* @return string
*/
public function generateFanChart($what, $fanChart) {
- $treeid = ancestry_array($this->root->getXref(), $this->generations);
+ $treeid = $this->sosaAncestors($this->generations);
$fanw = 640 * $this->fan_width / 100;
$fandeg = 90 * $this->fan_style;
$html = '';
- $treesize = count($treeid);
+ $treesize = count($treeid) + 1;
// generations count
$gen = log($treesize) / log(2) - 1;
@@ -207,8 +207,7 @@ class WT_Controller_Fanchart extends WT_Controller_Chart {
// draw each cell
while ($sosa >= $p2) {
- $pid = $treeid[$sosa];
- $person = WT_Individual::getInstance($pid);
+ $person = $treeid[$sosa];
if ($person) {
$name = $person->getFullName();
$addname = $person->getAddName();
@@ -305,6 +304,7 @@ class WT_Controller_Fanchart extends WT_Controller_Chart {
$ty = round($cy - $mr * -sin($rad));
$imagemap .= "$tx,$ty";
// add action url
+ $pid = $person->getXref();
$imagemap .= '" href="#' . $pid . '"';
$tempURL = 'fanchart.php?rootid=' . $pid . '&amp;generations=' . $this->generations . '&amp;fan_width=' . $this->fan_width . '&amp;fan_style=' . $this->fan_style . '&amp;ged=' . WT_GEDURL;
$html .= '<div id="' . $pid . '" class="fan_chart_menu">';
@@ -379,7 +379,7 @@ class WT_Controller_Fanchart extends WT_Controller_Chart {
switch ($what) {
case 'html':
- return $html . $imagemap . '<div id="fan_chart_img"><img src="' . WT_SCRIPT_NAME . '?rootid=' . $this->rootid . '&amp;fan_style=' . $this->fan_style . '&amp;generations=' . $this->generations . '&amp;fan_width=' . $this->fan_width.'&amp;img=1" width="' . $fanw . '" height="' . $fanh . '" alt="' . WT_I18N::translate('Fan chart of %s', strip_tags($person->getFullName())) . '" usemap="#fanmap"></div>';
+ return $html . $imagemap . '<div id="fan_chart_img"><img src="' . WT_SCRIPT_NAME . '?rootid=' . $this->root->getXref() . '&amp;fan_style=' . $this->fan_style . '&amp;generations=' . $this->generations . '&amp;fan_width=' . $this->fan_width.'&amp;img=1" width="' . $fanw . '" height="' . $fanh . '" alt="' . WT_I18N::translate('Fan chart of %s', strip_tags($person->getFullName())) . '" usemap="#fanmap"></div>';
case 'png':
ImageStringUp($image, 1, $fanw - 10, $fanh / 3, WT_SERVER_NAME . WT_SCRIPT_PATH, $color);
diff --git a/library/WT/Controller/Pedigree.php b/library/WT/Controller/Pedigree.php
index 5837811e1d..907c5b7394 100644
--- a/library/WT/Controller/Pedigree.php
+++ b/library/WT/Controller/Pedigree.php
@@ -30,7 +30,7 @@ class WT_Controller_Pedigree extends WT_Controller_Chart {
var $PEDIGREE_GENERATIONS;
var $pbwidth;
var $pbheight;
- var $treeid;
+ var $ancestors;
var $treesize;
var $curgen;
var $yoffset;
@@ -101,12 +101,12 @@ class WT_Controller_Pedigree extends WT_Controller_Chart {
$this->pbwidth = $bwidth+6;
$this->pbheight = $bheight+5;
- $this->treeid = ancestry_array($this->rootid, $PEDIGREE_GENERATIONS);
+ $this->ancestors = $this->sosaAncestors($PEDIGREE_GENERATIONS);
$this->treesize = pow(2, (int)($this->PEDIGREE_GENERATIONS))-1;
- //-- ancestry_array puts everyone at $i+1
+ // sosaAncestors() puts everyone at $i+1
for ($i=0; $i<$this->treesize; $i++) {
- $this->treeid[$i] = $this->treeid[$i+1];
+ $this->ancestors[$i] = $this->ancestors[$i+1];
}
if (!$this->show_full) {
@@ -220,7 +220,7 @@ class WT_Controller_Pedigree extends WT_Controller_Chart {
//-- calculate the smallest yoffset and adjust the tree to that offset
$minyoffset = 0;
- for ($i=0; $i<count($this->treeid); $i++) {
+ for ($i=0; $i<count($this->ancestors); $i++) {
if (!empty($offsetarray[$i])) {
if (($minyoffset==0)||($minyoffset>$this->offsetarray[$i]["y"])) $minyoffset = $this->offsetarray[$i]["y"];
}
diff --git a/modules_v3/googlemap/module.php b/modules_v3/googlemap/module.php
index d63ef2089b..8ea8da7ec1 100644
--- a/modules_v3/googlemap/module.php
+++ b/modules_v3/googlemap/module.php
@@ -781,7 +781,7 @@ class googlemap_WT_Module extends WT_Module implements WT_Module_Config, WT_Modu
for ($i=0; $i<($controller->treesize); $i++) {
// -- check to see if we have moved to the next generation
if ($i+1 >= pow(2, $curgen)) {$curgen++;}
- $person = WT_Individual::getInstance($controller->treeid[$i]);
+ $person = WT_Individual::getInstance($controller->ancestors[$i]);
if (!empty($person)) {
$name = $person->getFullName();
if ($name == WT_I18N::translate('Private')) $priv++;
diff --git a/pedigree.php b/pedigree.php
index 9dec81792b..752d1a23a9 100644
--- a/pedigree.php
+++ b/pedigree.php
@@ -124,7 +124,7 @@ for ($i = ($controller->treesize - 1); $i >= 0; $i--) {
$maxyoffset = $yoffset;
}
// Can we go back to an earlier generation?
- $can_go_back = $curgen == 1 && WT_Individual::getInstance($controller->treeid[$i]) && WT_Individual::getInstance($controller->treeid[$i])->getChildFamilies();
+ $can_go_back = $curgen == 1 && $controller->ancestors[$i] && $controller->ancestors[$i]->getChildFamilies();
if ($talloffset == 2) { // oldest at top
if ($can_go_back) {
@@ -133,7 +133,7 @@ for ($i = ($controller->treesize - 1); $i >= 0; $i--) {
if ($i > (int)($controller->treesize / 2) + (int)($controller->treesize / 4)) {
$did++;
}
- printf(MENU_ITEM, $controller->treeid[$did], $controller->show_full, $controller->PEDIGREE_GENERATIONS, $talloffset, 'icon-uarrow noprint', '');
+ printf(MENU_ITEM, $controller->ancestors[$did]->getXref(), $controller->show_full, $controller->PEDIGREE_GENERATIONS, $talloffset, 'icon-uarrow noprint', '');
echo '</div>';
}
}
@@ -149,7 +149,7 @@ for ($i = ($controller->treesize - 1); $i >= 0; $i--) {
printf(BOX_WRAPPER, $posn, $xoffset, $yoffset, $controller->pbwidth, $controller->pbheight);
- print_pedigree_person(WT_Individual::getInstance($controller->treeid[$i]));
+ print_pedigree_person($controller->ancestors[$i]);
if ($can_go_back) {
$did = 1;
if ($i > (int)($controller->treesize / 2) + (int)($controller->treesize / 4)) {
@@ -162,11 +162,11 @@ for ($i = ($controller->treesize - 1); $i >= 0; $i--) {
}
if ($talloffset == 3) {
printf(ARROW_WRAPPER, $posn, $controller->pbwidth / 2, $controller->pbheight+5);
- printf(MENU_ITEM, $controller->treeid[$did], $controller->show_full, $controller->PEDIGREE_GENERATIONS, $talloffset, 'icon-darrow noprint', '');
+ printf(MENU_ITEM, $controller->ancestors[$did]->getXref(), $controller->show_full, $controller->PEDIGREE_GENERATIONS, $talloffset, 'icon-darrow noprint', '');
echo '</div>';
} elseif ($talloffset < 2) {
printf(ARROW_WRAPPER, $posn, $controller->pbwidth +5, $controller->pbheight / 2 - 10);
- printf(MENU_ITEM, $controller->treeid[$did], $controller->show_full, $controller->PEDIGREE_GENERATIONS, $talloffset, "$arrow noprint", '');
+ printf(MENU_ITEM, $controller->ancestors[$did]->getXref(), $controller->show_full, $controller->PEDIGREE_GENERATIONS, $talloffset, "$arrow noprint", '');
echo '</div>';
}
}
diff --git a/tests/includes/functions/FunctionsChartsTest.php b/tests/includes/functions/FunctionsChartsTest.php
index 2e32e612c0..67e2bed2f4 100644
--- a/tests/includes/functions/FunctionsChartsTest.php
+++ b/tests/includes/functions/FunctionsChartsTest.php
@@ -59,15 +59,6 @@ class FunctionsChartsTest extends PHPUnit_Framework_TestCase {
}
/**
- * Test that function ancestry_array() exists in the global namespace.
- *
- * @return void
- */
- public function testFunctionAncestryArrayExists() {
- $this->assertEquals(function_exists('\\ancestry_array'), true);
- }
-
- /**
* Test that function print_url_arrow() exists in the global namespace.
*
* @return void