diff options
| author | Greg Roach <fisharebest@gmail.com> | 2014-05-02 22:23:08 +0100 |
|---|---|---|
| committer | Greg Roach <fisharebest@gmail.com> | 2014-05-02 22:23:08 +0100 |
| commit | d9b643e398a51aed74feb8d1882004506c3e7114 (patch) | |
| tree | 220624fd918ec82d7a6b8e0d9beceefbd8b1cac5 | |
| parent | 76978972c6d9afde4587899dc2299f9220f75a0d (diff) | |
| download | webtrees-d9b643e398a51aed74feb8d1882004506c3e7114.tar.gz webtrees-d9b643e398a51aed74feb8d1882004506c3e7114.tar.bz2 webtrees-d9b643e398a51aed74feb8d1882004506c3e7114.zip | |
Fix problem with connecting lines on interactive tree. Tidy code a little
| -rw-r--r-- | modules_v3/tree/class_treeview.php | 227 |
1 files changed, 125 insertions, 102 deletions
diff --git a/modules_v3/tree/class_treeview.php b/modules_v3/tree/class_treeview.php index f6cf96732c..14bc95fb91 100644 --- a/modules_v3/tree/class_treeview.php +++ b/modules_v3/tree/class_treeview.php @@ -28,58 +28,65 @@ class TreeView { private $allPartners; /** - * Treeview Constructor - * @param string $name the name of the TreeView object’s instance - */ - function __construct($name='tree') { + * Treeview Constructor + * + * @param string $name the name of the TreeView object’s instance + */ + function __construct($name = 'tree') { $this->name = $name; $this->allPartners = WT_Filter::cookie('allPartners', 'true|false', 'true'); } /** - * Draw the viewport which creates the draggable/zoomable framework - * Size is set by the container, as the viewport can scale itself automatically - * @param string $rootPersonId the id of the root person - * @param int $generations number of generations to draw - */ + * Draw the viewport which creates the draggable/zoomable framework + * Size is set by the container, as the viewport can scale itself automatically + * + * @param WT_Individual $rootPerson the id of the root person + * @param int $generations number of generations to draw + * + * @return string + */ public function drawViewport(WT_Individual $rootPerson, $generations) { if (WT_SCRIPT_NAME == 'individual.php') { $path = $rootPerson->getHtmlUrl(); } else { $path = 'module.php?mod=tree&mod_action=treeview&rootid=' . $rootPerson->getXref(); } - $r = '<a name="tv_content"></a><div id="'.$this->name.'_out" class="tv_out">'; + $r = '<a name="tv_content"></a><div id="' . $this->name . '_out" class="tv_out">'; // Add the toolbar - $r.='<div id="tv_tools" class="noprint"><ul>'. - '<li id="tvbCompact" class="tv_button"><img src="'.WT_STATIC_URL.WT_MODULES_DIR.'tree/images/compact.png" alt="'.WT_I18N::translate('Use compact layout').'" title="'.WT_I18N::translate('Use compact layout').'"></li>'. - '<li id="tvbAllPartners" class="tv_button' . ($this->allPartners === 'true' ? ' tvPressed' : '') . '"><a class="icon-sfamily" href="' . $path . '" title="'.WT_I18N::translate('Show all spouses and ancestors').'"></a></li>'; + $r .= '<div id="tv_tools" class="noprint"><ul>' . + '<li id="tvbCompact" class="tv_button"><img src="' . WT_STATIC_URL . WT_MODULES_DIR . 'tree/images/compact.png" alt="' . WT_I18N::translate('Use compact layout') . '" title="' . WT_I18N::translate('Use compact layout') . '"></li>' . + '<li id="tvbAllPartners" class="tv_button' . ($this->allPartners === 'true' ? ' tvPressed' : '') . '"><a class="icon-sfamily" href="' . $path . '" title="' . WT_I18N::translate('Show all spouses and ancestors') . '"></a></li>'; // Hidden loading image - $r.='<li class="tv_button" id="'.$this->name.'_loading"><i class="icon-loading-small"></i></li></ul>'; - $r.='</div><h2 id="tree-title">'. - WT_I18N::translate('Interactive tree of %s',$rootPerson->getFullName()). - '</h2><div id="'.$this->name.'_in" class="tv_in" dir="ltr">'; + $r .= '<li class="tv_button" id="' . $this->name . '_loading"><i class="icon-loading-small"></i></li></ul>'; + $r .= '</div><h2 id="tree-title">' . + WT_I18N::translate('Interactive tree of %s', $rootPerson->getFullName()) . + '</h2><div id="' . $this->name . '_in" class="tv_in" dir="ltr">'; $parent = null; - $r.=$this->drawPerson($rootPerson, $generations, 0, $parent, '', true); - $r.='</div></div>'; // Close the tv_in and the tv_out div - return array($r, 'var ' . $this->name . 'Handler = new TreeViewHandler("' . $this->name.'");'); + $r .= $this->drawPerson($rootPerson, $generations, 0, $parent, '', true); + $r .= '</div></div>'; // Close the tv_in and the tv_out div + return array($r, 'var ' . $this->name . 'Handler = new TreeViewHandler("' . $this->name . '");'); } /** - * Return a JSON structure to a JSON request - * @param string $list list of JSON requests - */ + * Return a JSON structure to a JSON request + * + * @param string $list list of JSON requests + * + * @return string + */ public function getPersons($list) { $list = explode(';', $list); $r = array(); - foreach($list as $jsonRequest) { + foreach ($list as $jsonRequest) { $firstLetter = substr($jsonRequest, 0, 1); $jsonRequest = substr($jsonRequest, 1); - switch($firstLetter) { + switch ($firstLetter) { case 'c': $fidlist = explode(',', $jsonRequest); $flist = array(); - foreach($fidlist as $fid) { + foreach ($fidlist as $fid) { $flist[] = WT_Family::getInstance($fid); } $r[] = $this->drawChildren($flist, 1, true); @@ -89,7 +96,6 @@ class TreeView { $fid = $params[0]; $order = $params[1]; $f = WT_Family::getInstance($fid); - $p = $f->getHusband(); $r[] = $this->drawPerson($f->getHusband(), 0, 1, $f, $order); break; } @@ -98,28 +104,31 @@ class TreeView { } /** - * Get the details for a person and their life partner(s) - * @param string $pid the person id to return the details for - */ + * Get the details for a person and their life partner(s) + * + * @param string $pid the person id to return the details for + * + * @return string + */ public function getDetails($pid) { $person = WT_Individual::getInstance($pid); - $r = $this->getPersonDetails($person, $person, null); + $r = $this->getPersonDetails($person, null); foreach ($person->getSpouseFamilies() as $family) { $spouse = $family->getSpouse($person); if ($spouse) { - $r .= $this->getPersonDetails($person, $spouse, $family); + $r .= $this->getPersonDetails($spouse, $family); } } return $r; } /** - * Return the details for a person - */ - private function getPersonDetails($personGroup, $individual, $family) { - $r = $this->getThumbnail($personGroup, $individual); - $r .= '<a class="tv_link" href="'.$individual->getHtmlUrl().'">'.$individual->getFullName().'</a> <a href="module.php?mod=tree&mod_action=treeview&rootid='.$individual->getXref().'" title="'.WT_I18N::translate('Interactive tree of %s', strip_tags($individual->getFullName())).'" class="icon-button_indi tv_link tv_treelink"></a>'; + * Return the details for a person + */ + private function getPersonDetails($individual, $family) { + $r = $this->getThumbnail($individual); + $r .= '<a class="tv_link" href="' . $individual->getHtmlUrl() . '">' . $individual->getFullName() . '</a> <a href="module.php?mod=tree&mod_action=treeview&rootid=' . $individual->getXref() . '" title="' . WT_I18N::translate('Interactive tree of %s', strip_tags($individual->getFullName())) . '" class="icon-button_indi tv_link tv_treelink"></a>'; foreach ($individual->getFacts(WT_EVENTS_BIRT, true) as $fact) { $r .= $fact->summary(); } @@ -131,21 +140,24 @@ class TreeView { foreach ($individual->getFacts(WT_EVENTS_DEAT, true) as $fact) { $r .= $fact->summary(); } - return '<div class="tv'.$individual->getSex().' tv_person_expanded">' . $r . '</div>'; + return '<div class="tv' . $individual->getSex() . ' tv_person_expanded">' . $r . '</div>'; } /** - * Draw the children for some families - * @param Array $familyList array of families to draw the children for - * @param int $gen number of generations to draw - * @param boolean $ajax setted to true for an ajax call - */ - private function drawChildren($familyList, $gen=1, $ajax=false) { - $r =''; + * Draw the children for some families + * + * @param Array $familyList array of families to draw the children for + * @param int $gen number of generations to draw + * @param boolean $ajax setted to true for an ajax call + * + * @return string + */ + private function drawChildren($familyList, $gen = 1, $ajax = false) { + $r = ''; $children2draw = array(); $f2load = array(); - foreach($familyList as $f) { + foreach ($familyList as $f) { if (empty($f)) { continue; } @@ -153,7 +165,7 @@ class TreeView { if (count($children) > 0) { $f2load[] = $f->getXref(); foreach ($children as $ch) { - // Eliminate duplicates - e.g. when adopted by a step-parent + // Eliminate duplicates - e.g. when adopted by a step-parent $children2draw[$ch->getXref()] = $ch; } } @@ -173,28 +185,32 @@ class TreeView { } else { $co = 'h'; } - $r .= $this->drawPerson($child, $gen-1, -1, null, $co); + $r .= $this->drawPerson($child, $gen - 1, -1, null, $co); } if (!$ajax) { - $r = '<td align="right"' . ($gen == 0 ? ' abbr="c'.$f2load.'"' : '') . '>' . $r . '</td>'.$this->drawHorizontalLine(); + $r = '<td align="right"' . ($gen == 0 ? ' abbr="c' . $f2load . '"' : '') . '>' . $r . '</td>' . $this->drawHorizontalLine(); } } return $r; } /** - * Draw a person in the tree - * @param Person $person The Person object to draw the box for - * @param int $gen The number of generations up or down to print - * @param int $state Whether we are going up or down the tree, -1 for descendents +1 for ancestors - * @param Family $pfamily - * @param string $order first (1), last(2), unique(0), or empty. Required for drawing lines between boxes - * - * Notes : "spouse" means explicitely married partners. Thus, the word "partner" - * (for "life partner") here fits much better than "spouse" or "mate" - * to translate properly the modern french meaning of "conjoint" - */ - private function drawPerson($person, $gen, $state=0, $pfamily, $order, $isRoot=false) { + * Draw a person in the tree + * + * @param WT_Individual $person The Person object to draw the box for + * @param int $gen The number of generations up or down to print + * @param int $state Whether we are going up or down the tree, -1 for descendents +1 for ancestors + * @param WT_Family $pfamily + * @param string $order first (1), last(2), unique(0), or empty. Required for drawing lines between boxes + * @param boolean $isRoot + * + * @return string + * + * Notes : "spouse" means explicitely married partners. Thus, the word "partner" + * (for "life partner") here fits much better than "spouse" or "mate" + * to translate properly the modern french meaning of "conjoint" + */ + private function drawPerson(WT_Individual $person, $gen, $state, WT_Family $pfamily, $order, $isRoot = false) { global $TEXT_DIRECTION; if ($gen < 0 || empty($person)) { @@ -204,8 +220,6 @@ class TreeView { $partner = $pfamily->getSpouse($person); } else { $partner = $person->getCurrentSpouse(); - $fams = $person->getSpouseFamilies(); - $pfamily = end($fams); } if ($isRoot) { $r = '<table id="tvTreeBorder" class="tv_tree"><tbody><tr><td id="tv_tree_topleft"></td><td id="tv_tree_top"></td><td id="tv_tree_topright"></td></tr><tr><td id="tv_tree_left"></td><td>'; @@ -213,25 +227,25 @@ class TreeView { $r = ''; } /* height 1% : this hack enable the div auto-dimensionning in td for FF & Chrome */ - $r .= '<table class="tv_tree"'.($isRoot ? ' id="tv_tree"' : '').' style="height: 1%"><tbody><tr>'; + $r .= '<table class="tv_tree"' . ($isRoot ? ' id="tv_tree"' : '') . ' style="height: 1%"><tbody><tr>'; - if ($state<=0) { + if ($state <= 0) { // draw children - $r.=$this->drawChildren($person->getSpouseFamilies(), $gen); + $r .= $this->drawChildren($person->getSpouseFamilies(), $gen); } else { // draw the parent’s lines - $r .= $this->drawVerticalLine($order).$this->drawHorizontalLine(); + $r .= $this->drawVerticalLine($order) . $this->drawHorizontalLine(); } /* draw the person. Do NOT add person or family id as an id, since a same person could appear more than once in the tree !!! */ // Fixing the width for td to the box initial width when the person is the root person fix a rare bug that happen when a person without child and without known parents is the root person : an unwanted white rectangle appear at the right of the person’s boxes, otherwise. - $r .= '<td'.($isRoot ? ' style="width:1px"' : '').'><div class="tv_box'.($isRoot ? ' rootPerson' : '').'" dir="'.$TEXT_DIRECTION.'" style="text-align: '.($TEXT_DIRECTION=="rtl" ? "right":"left").'; direction: '.$TEXT_DIRECTION.'" abbr="'.$person->getXref().'" onclick="'.$this->name.'Handler.expandBox(this, event);">'; + $r .= '<td' . ($isRoot ? ' style="width:1px"' : '') . '><div class="tv_box' . ($isRoot ? ' rootPerson' : '') . '" dir="' . $TEXT_DIRECTION . '" style="text-align: ' . ($TEXT_DIRECTION == "rtl" ? "right" : "left") . '; direction: ' . $TEXT_DIRECTION . '" abbr="' . $person->getXref() . '" onclick="' . $this->name . 'Handler.expandBox(this, event);">'; $r .= $this->drawPersonName($person); $fop = Array(); // $fop is fathers of partners if (!is_null($partner)) { $sfams = $person->getSpouseFamilies(); $dashed = ''; - foreach ($sfams as $famid=>$family) { + foreach ($sfams as $family) { $p = $family->getSpouse($person); if ($p) { if (($p === $partner) || $this->allPartners === 'true') { @@ -265,18 +279,18 @@ class TreeView { $unique = (empty($parent) || count($fop) == 0); $r .= '<td align="left"><table class="tv_tree"><tbody>'; if (!empty($parent)) { - $u = ($unique ? 'c' : 't'); - $r .= '<tr><td '.($gen == 0 ? ' abbr="p'.$primaryChildFamily->getXref().'@'.$u.'"' : '').'>'; - $r .= $this->drawPerson($parent, $gen-1, 1, $primaryChildFamily, $u); + $u = $unique ? 'c' : 't'; + $r .= '<tr><td ' . ($gen == 0 ? ' abbr="p' . $primaryChildFamily->getXref() . '@' . $u . '"' : '') . '>'; + $r .= $this->drawPerson($parent, $gen - 1, 1, $primaryChildFamily, $u); $r .= '</td></tr>'; } if (count($fop)) { $n = 0; $nb = count($fop); - foreach($fop as $p) { + foreach ($fop as $p) { $n++; - $u = ($unique ? 'c' : ($n == $nb || empty($p[1]) || $this->allPartners === 'true' ? 'h' : 'b')); - $r .= '<tr><td '.($gen == 0 ? ' abbr="p'.$p[1]->getXref().'@'.$u.'"' : '').'>'.$this->drawPerson($p[0], $gen-1, 1, $p[1], $u).'</td></tr>'; + $u = $unique ? 'c' : ($n == $nb || empty($p[1]) ? 'b' : 'h'); + $r .= '<tr><td ' . ($gen == 0 ? ' abbr="p' . $p[1]->getXref() . '@' . $u . '"' : '') . '>' . $this->drawPerson($p[0], $gen - 1, 1, $p[1], $u) . '</td></tr>'; } } $r .= '</tbody></table></td>'; @@ -292,43 +306,50 @@ class TreeView { } /** - * Draw a person name preceded by sex icon, with parents as tooltip - * @param WT_Individual $p a person - * @param $dashed if = 'dashed' print dashed top border to separate multiple spuses - */ - private function drawPersonName($p, $dashed='') { + * Draw a person name preceded by sex icon, with parents as tooltip + * + * @param WT_Individual $p a person + * @param string $dashed if = 'dashed' print dashed top border to separate multiple spuses + * + * @return string + */ + private function drawPersonName(WT_Individual $p, $dashed = '') { if ($this->allPartners === 'true') { $f = $p->getPrimaryChildFamily(); if ($f) { switch ($p->getSex()) { case 'M': - $title=' title="'.strip_tags(/* I18N: e.g. “Son of [father name & mother name]” */ WT_I18N::translate('Son of %s', $f->getFullName())).'"'; + $title = ' title="' . strip_tags( /* I18N: e.g. “Son of [father name & mother name]” */ + WT_I18N::translate('Son of %s', $f->getFullName())) . '"'; break; case 'F': - $title=' title="'.strip_tags(/* I18N: e.g. “Daughter of [father name & mother name]” */ WT_I18N::translate('Daughter of %s', $f->getFullName())).'"'; + $title = ' title="' . strip_tags( /* I18N: e.g. “Daughter of [father name & mother name]” */ + WT_I18N::translate('Daughter of %s', $f->getFullName())) . '"'; break; case 'U': - $title=' title="'.strip_tags(/* I18N: e.g. “Child of [father name & mother name]” */ WT_I18N::translate('Child of %s', $f->getFullName())).'"'; + $title = ' title="' . strip_tags( /* I18N: e.g. “Child of [father name & mother name]” */ + WT_I18N::translate('Child of %s', $f->getFullName())) . '"'; break; } } else { - $title=''; + $title = ''; } } else { $title = ''; } $sex = $p->getSex(); - $r = '<div class="tv'.$sex.' '.$dashed.'"'.$title.'><a href="'.$p->getHtmlUrl().'"></a>'.$p->getFullName().' <span class="dates">'.$p->getLifeSpan().'</span></div>'; + $r = '<div class="tv' . $sex . ' ' . $dashed . '"' . $title . '><a href="' . $p->getHtmlUrl() . '"></a>' . $p->getFullName() . ' <span class="dates">' . $p->getLifeSpan() . '</span></div>'; return $r; } /** - * Get the thumbnail image for the given person - * - * @param Person $person - * @return string - */ - private function getThumbnail($personGroup, $person) { + * Get the thumbnail image for the given person + * + * @param WT_Individual $person + * + * @return string + */ + private function getThumbnail(WT_Individual $person) { global $SHOW_HIGHLIGHT_IMAGES; if ($SHOW_HIGHLIGHT_IMAGES) { @@ -339,22 +360,24 @@ class TreeView { } /** - * Draw a vertical line - * @param string order $order A parameter that set how to draw this line - * with auto-redimensionning capabilities - * WARNING : some tricky hacks are required in CSS to ensure cross-browser compliance - * some browsers shows an image, which imply a size limit in height, - * and some other browsers (ex: firefox) shows a <div> tag, which have no size limit in height - * Therefore, Firefox is a good choice to print very big trees. - */ + * Draw a vertical line + * + * @param string $order A parameter that set how to draw this line with auto-redimensionning capabilities + * + * @return string + * WARNING : some tricky hacks are required in CSS to ensure cross-browser compliance + * some browsers shows an image, which imply a size limit in height, + * and some other browsers (ex: firefox) shows a <div> tag, which have no size limit in height + * Therefore, Firefox is a good choice to print very big trees. + */ private function drawVerticalLine($order) { - $r = '<td class="tv_vline tv_vline_'.$order.'"><div class="tv_vline tv_vline_'.$order.'"></div></td>'; + $r = '<td class="tv_vline tv_vline_' . $order . '"><div class="tv_vline tv_vline_' . $order . '"></div></td>'; return $r; } /** - * Draw an horizontal line - */ + * Draw an horizontal line + */ private function drawHorizontalLine() { $r = '<td class="tv_hline"><div class="tv_hline"></div></td>'; return $r; |
