/** * Print a lineage node, recursively. * @param LineageNode $node */ private function printLineage(LineageNode $node) { echo '<ul>'; $fam_nodes = $node->getFamiliesNodes(); if (count($fam_nodes) > 0) { $is_first_family = true; foreach ($fam_nodes as $fam) { $node_indi = $node->getIndividual(); echo '<li>'; if ($is_first_family) { echo FunctionsPrint::htmlIndividualForList($node_indi); } else { echo FunctionsPrint::htmlIndividualForList($node_indi, false); } //Get individual's spouse $dfam = new Family($fam); $spouse = $dfam->getSpouseById($node_indi); //Print the spouse if relevant if ($spouse) { $marrdate = I18N::translate('yes'); $marryear = ''; echo ' <a href="' . $fam->getHtmlUrl() . '">'; if ($fam->getMarriageYear()) { $marrdate = strip_tags($fam->getMarriageDate()->Display()); $marryear = $fam->getMarriageYear(); } echo '<span class="details1" title="' . $marrdate . '"><i class="icon-rings"></i>' . $marryear . '</span></a> '; echo FunctionsPrint::htmlIndividualForList($spouse); } foreach ($fam_nodes[$fam] as $child_node) { if ($child_node) { $this->printLineage($child_node); } else { echo '<ul><li><strong>…</strong></li></ul>'; } } $is_first_family = false; } } else { echo '<li>'; echo \MyArtJaub\Webtrees\Functions\FunctionsPrint::htmlIndividualForList($node->getIndividual()); if ($node->hasFollowUpSurname()) { $url_base = WT_SCRIPT_NAME . '?mod=' . \MyArtJaub\Webtrees\Constants::MODULE_MAJ_PATROLIN_NAME . '&mod_action=Lineage'; echo ' ' . '<a href="' . $url_base . '&surname=' . rawurlencode($node->getFollowUpSurname()) . '&ged=' . $this->data->get('tree')->getNameUrl() . '">' . '(' . I18N::translate('Go to %s lineages', $node->getFollowUpSurname()) . ')' . '</a>'; } echo '</li>'; } echo '</ul>'; }
/** * Computes descendent Lineage from a node. * Uses recursion to build the lineage tree * * @param LineageNode $node * @return LineageNode Computed lineage */ protected function buildLineage(LineageNode $node) { if ($node === null) { return; } $indi_surname = null; $indi_node = $node->getIndividual(); if ($indi_node) { if (count($node->getFamiliesNodes()) == 0) { $indiSpouseFamilies = $indi_node->getSpouseFamilies(); foreach ($indiSpouseFamilies as $indiSpouseFamily) { $node->addFamily($indiSpouseFamily); } } $dindi_node = new \MyArtJaub\Webtrees\Individual($indi_node); $indi_surname = $dindi_node->getUnprotectedPrimarySurname(); //Get the estimated birth place and put it in the place table $place = $dindi_node->getEstimatedBirthPlace(false); if ($place && strlen($place) > 0) { $place = trim($place); $node->getRootNode()->addPlace(new Place($place, $this->tree)); } //Tag the individual as used $this->used_indis[$indi_node->getXref()] = true; } foreach ($node->getFamiliesNodes() as $family) { $spouse_surname = null; if ($indi_node && ($spouse = $family->getSpouse($indi_node))) { $dspouse = new \MyArtJaub\Webtrees\Individual($spouse); $spouse_surname = $dspouse->getUnprotectedPrimarySurname(); } $children = $family->getChildren(); $nbChildren = 0; $nbNatural = 0; foreach ($children as $child) { $dchild = new \MyArtJaub\Webtrees\Individual($child); $child_surname = $dchild->getUnprotectedPrimarySurname(); if (!$dchild->isNewAddition()) { $nbChildren++; //If the root individual is the mother if ($indi_node && I18N::strcasecmp($indi_node->getSex(), 'F') == 0) { //Print only lineages of children with the same surname as their mother (supposing they are natural children) if (!$spouse || $spouse_surname && I18N::strcasecmp($child_surname, $spouse_surname) != 0) { if (I18N::strcasecmp($child_surname, $indi_surname) == 0) { $nbNatural++; $node_child = new LineageNode($child, $node->getRootNode()); $node_child = $this->buildLineage($node_child); if ($node_child) { $node->addChild($family, $node_child); } } } } else { //Print if the children does not bear the same name as his mother (and different from his father) if (strlen($child_surname) == 0 || strlen($indi_surname) == 0 || strlen($spouse_surname) == 0 || I18N::strcasecmp($child_surname, $indi_surname) == 0 || I18N::strcasecmp($child_surname, $spouse_surname) != 0) { $nbNatural++; $node_child = new LineageNode($child, $node->getRootNode()); $node_child = $this->buildLineage($node_child); if ($node_child) { $node->addChild($family, $node_child); } } else { $nbNatural++; $node_child = new LineageNode($child, $node->getRootNode(), $child_surname); if ($node_child) { $node->addChild($family, $node_child); } } } } } //Do not print other children if ($nbChildren - $nbNatural > 0) { $node->addChild($family, null); } } return $node; }
/** * Constructor for LineageRootNode * * @param Fisharebest\Webtrees\Individual $node_indi */ public function __construct($node_indi = null) { parent::__construct($node_indi, $this); $this->places = array(); }