/** * 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; }