function add_descendancy(&$list, $pid, $parents = false, $generations = -1) { $person = Person::getInstance($pid); if ($person == null) { return; } if (!isset($list[$pid])) { $list[$pid] = $person; } if (!isset($list[$pid]->generation)) { $list[$pid]->generation = 0; } $famids = $person->getSpouseFamilies(); if (count($famids) > 0) { foreach ($famids as $famid => $family) { if ($family) { if ($parents) { $husband = $family->getHusband(); $wife = $family->getWife(); if ($husband) { $list[$husband->getXref()] = $husband; if (isset($list[$pid]->generation)) { $list[$husband->getXref()]->generation = $list[$pid]->generation - 1; } else { $list[$husband->getXref()]->generation = 1; } } if ($wife) { $list[$wife->getXref()] = $wife; if (isset($list[$pid]->generation)) { $list[$wife->getXref()]->generation = $list[$pid]->generation - 1; } else { $list[$wife->getXref()]->generation = 1; } } } $children = $family->getChildren(); foreach ($children as $child) { if ($child) { $list[$child->getXref()] = $child; if (isset($list[$pid]->generation)) { $list[$child->getXref()]->generation = $list[$pid]->generation + 1; } else { $list[$child->getXref()]->generation = 2; } } } if ($generations == -1 || $list[$pid]->generation + 1 < $generations) { foreach ($children as $child) { add_descendancy($list, $child->getXref(), $parents, $generations); // recurse on the childs family } } } } } }
/** * @todo add info * @param array $attrs an array of key value pairs for the attributes * @see PGVRRelativesEHandler() */ function PGVRRelativesSHandler($attrs) { global $pgvreport, $gedrec, $repeats, $repeatBytes, $list, $repeatsStack, $processRepeats, $parser, $vars, $sortby; $processRepeats++; if ($processRepeats > 1) { return; } $sortby = "NAME"; if (isset($attrs["sortby"])) { $sortby = $attrs["sortby"]; } $vmatch = array(); if (preg_match("/\\\$(\\w+)/", $sortby, $vmatch) > 0) { $sortby = $vars[$vmatch[1]]["id"]; $sortby = trim($sortby); } $maxgen = -1; if (isset($attrs["maxgen"])) { $maxgen = $attrs["maxgen"]; } if ($maxgen == "*") { $maxgen = -1; } $group = "child-family"; if (isset($attrs["group"])) { $group = $attrs["group"]; } if (preg_match("/\\\$(\\w+)/", $group, $vmatch) > 0) { $group = $vars[$vmatch[1]]["id"]; $group = trim($group); } $id = ""; if (isset($attrs["id"])) { $id = $attrs["id"]; } if (preg_match("/\\\$(\\w+)/", $id, $vmatch) > 0) { $id = $vars[$vmatch[1]]["id"]; $id = trim($id); } $showempty = false; if (isset($attrs["showempty"])) { $showempty = $attrs["showempty"]; } if (preg_match("/\\\$(\\w+)/", $showempty, $vmatch) > 0) { $showempty = $vars[$vmatch[1]]["id"]; $showempty = trim($showempty); } $list = array(); $person = Person::getInstance($id); if (!empty($person)) { $list[$id] = $person; switch ($group) { case "child-family": $famids = $person->getChildFamilies(); foreach ($famids as $family) { $husband = $family->getHusband(); $wife = $family->getWife(); if (!empty($husband)) { $list[$husband->getXref()] = $husband; } if (!empty($wife)) { $list[$wife->getXref()] = $wife; } $children = $family->getChildren(); foreach ($children as $child) { if (!empty($child)) { $list[$child->getXref()] = $child; } } } break; case "spouse-family": $famids = $person->getSpouseFamilies(); foreach ($famids as $family) { $husband = $family->getHusband(); $wife = $family->getWife(); if (!empty($husband)) { $list[$husband->getXref()] = $husband; } if (!empty($wife)) { $list[$wife->getXref()] = $wife; } $children = $family->getChildren(); foreach ($children as $child) { if (!empty($child)) { $list[$child->getXref()] = $child; } } } break; case "direct-ancestors": add_ancestors($list, $id, false, $maxgen, $showempty); break; case "ancestors": add_ancestors($list, $id, true, $maxgen, $showempty); break; case "descendants": $list[$id]->generation = 1; add_descendancy($list, $id, false, $maxgen); break; case "all": add_ancestors($list, $id, true, $maxgen, $showempty); add_descendancy($list, $id, true, $maxgen); break; } } switch ($sortby) { case 'NAME': uasort($list, array('GedcomRecord', 'Compare')); break; case 'ID': uasort($list, array('GedcomRecord', 'CompareId')); break; case 'BIRT:DATE': uasort($list, array('PGVReportBase', 'CompareBirthDate')); break; case 'DEAT:DATE': uasort($list, array('PGVReportBase', 'CompareDeathDate')); break; case 'generation': $newarray = array(); reset($list); $genCounter = 1; while (count($newarray) < count($list)) { foreach ($list as $key => $value) { $generation = $value->generation; if ($generation == $genCounter) { $newarray[$key]->generation = $generation; } } $genCounter++; } $list = $newarray; break; default: // unsorted break; } array_push($repeatsStack, array($repeats, $repeatBytes)); $repeatBytes = xml_get_current_line_number($parser) + 1; }