name = $name; $this->all_partners = 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 WT_Individual $root_person the id of the root person * @param int $generations number of generations to draw * * @return string */ public function drawViewport(WT_Individual $root_person, $generations) { if (WT_SCRIPT_NAME == 'individual.php') { $path = $root_person->getHtmlUrl(); } elseif (WT_SCRIPT_NAME == 'index.php') { $path = WT_SCRIPT_NAME . '?ctype=user&ged=' . WT_GEDURL; } else { $path = 'module.php?mod=tree&mod_action=treeview&rootid=' . $root_person->getXref(); } $html = '
'; // Add the toolbar $html .= '
'; $html .= '

' . WT_I18N::translate('Interactive tree of %s', $root_person->getFullName()) . '

'; $html .= $this->drawPerson($root_person, $generations, 0, null, null, true); $html .= '
'; // Close the tv_in and the tv_out div return array($html, 'var ' . $this->name . 'Handler = new TreeViewHandler("' . $this->name . '");'); } /** * 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) { $firstLetter = substr($jsonRequest, 0, 1); $jsonRequest = substr($jsonRequest, 1); switch ($firstLetter) { case 'c': $fidlist = explode(',', $jsonRequest); $flist = array(); foreach ($fidlist as $fid) { $flist[] = WT_Family::getInstance($fid); } $r[] = $this->drawChildren($flist, 1, true); break; case 'p': $params = explode('@', $jsonRequest); $fid = $params[0]; $order = $params[1]; $f = WT_Family::getInstance($fid); if ($f->getHusband()) { $r[] = $this->drawPerson($f->getHusband(), 0, 1, $f, $order); } break; } } return json_encode($r); } /** * Get the details for a person and their life partner(s) * * @param WT_Individual $individual the individual to return the details for * * @return string */ public function getDetails(WT_Individual $individual) { $html = $this->getPersonDetails($individual, null); foreach ($individual->getSpouseFamilies() as $family) { $spouse = $family->getSpouse($individual); if ($spouse) { $html .= $this->getPersonDetails($spouse, $family); } } return $html; } /** * Return the details for a person */ private function getPersonDetails(WT_Individual $individual, WT_Family $family = null) { $hmtl = $this->getThumbnail($individual); $hmtl .= '' . $individual->getFullName() . ' '; foreach ($individual->getFacts(WT_EVENTS_BIRT, true) as $fact) { $hmtl .= $fact->summary(); } if ($family) { foreach ($family->getFacts(WT_EVENTS_MARR, true) as $fact) { $hmtl .= $fact->summary(); } } foreach ($individual->getFacts(WT_EVENTS_DEAT, true) as $fact) { $hmtl .= $fact->summary(); } return '
' . $hmtl . '
'; } /** * 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(array $familyList, $gen = 1, $ajax = false) { $html = ''; $children2draw = array(); $f2load = array(); foreach ($familyList as $f) { if (empty($f)) { continue; } $children = $f->getChildren(); if ($children) { $f2load[] = $f->getXref(); foreach ($children as $child) { // Eliminate duplicates - e.g. when adopted by a step-parent $children2draw[$child->getXref()] = $child; } } } $tc = count($children2draw); if ($tc) { $f2load = implode(',', $f2load); $nbc = 0; foreach ($children2draw as $child) { $nbc++; if ($tc == 1) { $co = 'c'; // unique } elseif ($nbc == 1) { $co = 't'; // first } elseif ($nbc == $tc) { $co = 'b'; //last } else { $co = 'h'; } $html .= $this->drawPerson($child, $gen - 1, -1, null, $co); } if (!$ajax) { $html = '' . $html . '' . $this->drawHorizontalLine(); } } return $html; } /** * 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 = null, $order = null, $isRoot = false) { global $TEXT_DIRECTION; if ($gen < 0) { return ''; } if (!empty($pfamily)) { $partner = $pfamily->getSpouse($person); } else { $partner = $person->getCurrentSpouse(); } if ($isRoot) { $html = '
'; } else { $html = ''; } /* height 1% : this hack enable the div auto-dimensioning in td for FF & Chrome */ $html .= ''; if ($state <= 0) { // draw children $html .= $this->drawChildren($person->getSpouseFamilies(), $gen); } else { // draw the parent’s lines $html .= $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. $html .= '
'; $html .= $this->drawPersonName($person); $fop = array(); // $fop is fathers of partners if (!is_null($partner)) { $dashed = ''; foreach ($person->getSpouseFamilies() as $family) { $spouse = $family->getSpouse($person); if ($spouse) { if ($spouse === $partner || $this->all_partners === 'true') { $spouse_parents = $spouse->getPrimaryChildFamily(); if ($spouse_parents && $spouse_parents->getHusband()) { $fop[] = array($spouse_parents->getHusband(), $spouse_parents); } $html .= $this->drawPersonName($spouse, $dashed); if ($this->all_partners !== 'true') { break; // we can stop here the foreach loop } $dashed = 'dashed'; } } } } $html .= '
'; $primaryChildFamily = $person->getPrimaryChildFamily(); if (!empty($primaryChildFamily)) { $parent = $primaryChildFamily->getHusband(); if (empty($parent)) { $parent = $primaryChildFamily->getWife(); } } if (!empty($parent) || count($fop) || ($state < 0)) { $html .= $this->drawHorizontalLine(); } /* draw the parents */ if ($state >= 0 && (!empty($parent) || count($fop))) { $unique = (empty($parent) || count($fop) == 0); $html .= '
'; } if ($state < 0) { $html .= $this->drawVerticalLine($order); } $html .= '
'; if (!empty($parent)) { $u = $unique ? 'c' : 't'; $html .= ''; } if (count($fop)) { $n = 0; $nb = count($fop); foreach ($fop as $p) { $n++; $u = $unique ? 'c' : ($n == $nb || empty($p[1]) ? 'b' : 'h'); $html .= ''; } } $html .= '
'; $html .= $this->drawPerson($parent, $gen - 1, 1, $primaryChildFamily, $u); $html .= '
' . $this->drawPerson($p[0], $gen - 1, 1, $p[1], $u) . '
'; if ($isRoot) { $html .= '
'; } return $html; } /** * Draw a person name preceded by sex icon, with parents as tooltip * * @param WT_Individual $individual an individual * @param string $dashed if = 'dashed' print dashed top border to separate multiple spuses * * @return string */ private function drawPersonName(WT_Individual $individual, $dashed = '') { if ($this->all_partners === 'true') { $family = $individual->getPrimaryChildFamily(); if ($family) { switch ($individual->getSex()) { case 'M': $title = ' title="' . strip_tags( /* I18N: e.g. “Son of [father name & mother name]” */ WT_I18N::translate('Son of %s', $family->getFullName()) ) . '"'; break; case 'F': $title = ' title="' . strip_tags( /* I18N: e.g. “Daughter of [father name & mother name]” */ WT_I18N::translate('Daughter of %s', $family->getFullName()) ) . '"'; break; case 'U': $title = ' title="' . strip_tags( /* I18N: e.g. “Child of [father name & mother name]” */ WT_I18N::translate('Child of %s', $family->getFullName()) ) . '"'; break; } } else { $title = ''; } } else { $title = ''; } $sex = $individual->getSex(); return '
' . $individual->getFullName() . ' ' . $individual->getLifeSpan() . '
'; } /** * Get the thumbnail image for the given person * * @param WT_Individual $individual * * @return string */ private function getThumbnail(WT_Individual $individual) { global $SHOW_HIGHLIGHT_IMAGES; if ($SHOW_HIGHLIGHT_IMAGES) { return $individual->displayImage(); } else { return ''; } } /** * 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
tag, which have no size limit in height * Therefore, Firefox is a good choice to print very big trees. */ private function drawVerticalLine($order) { return '
'; } /** * Draw an horizontal line */ private function drawHorizontalLine() { return '
'; } }