diff options
Diffstat (limited to 'library/WT/Controller')
| -rw-r--r-- | library/WT/Controller/Chart.php | 57 | ||||
| -rw-r--r-- | library/WT/Controller/Compact.php | 9 | ||||
| -rw-r--r-- | library/WT/Controller/Fanchart.php | 10 | ||||
| -rw-r--r-- | library/WT/Controller/Pedigree.php | 10 |
4 files changed, 61 insertions, 25 deletions
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 .= "&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 . '&generations=' . $this->generations . '&fan_width=' . $this->fan_width . '&fan_style=' . $this->fan_style . '&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 . '&fan_style=' . $this->fan_style . '&generations=' . $this->generations . '&fan_width=' . $this->fan_width.'&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() . '&fan_style=' . $this->fan_style . '&generations=' . $this->generations . '&fan_width=' . $this->fan_width.'&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"]; } |
