public function tree2Html($tree) { // TODO: handle count of only unsuppressed marriages! if (count($tree['marriages']) > 1) { return $this->tree2Html_MultiSpouse($tree); } $li1 = '<li>' . self::$agentreeUrlXXX; $li2 = '</li>'; $a2 = '</a>'; $html = "\n" . '<ul id="famtreeMain">' . "\n"; // determine the parentId.. we know the union Id as $tree['camefrom'] list($parentId, $otherParentId) = Person::getIdsOfParents($tree['camefrom']); if ($parentId == 0) { $parentId = $otherParentId; } if (!is_array($tree['marriages'])) { // another trivial case. this guy is a leaf. $html .= "\n" . '<li id="home">' . str_replace('xxx', $parentId, self::$agentreeUrlXXX) . $tree['name'] . '</a></li></ul>'; return $html; } // create the main node on this style of tree. $marriage = reset($tree['marriages']); $dateOfBirth = Person::convertPersonDate($tree['dob']); // let's find the parentId of the spouse. it's not in our struct $parent2Id = 0; if ($marriage['cameFromUnionId'] != 0) { list($parent2Id, $dummy) = Person::getIdsOfParents($marriage['cameFromUnionId']); } // set what happens when the user clicks the root. in the normal uncollapsed case, we go to the parent // however, in the collapsed case, we want to see all this guys' marriages. $rootClickThruId = $parentId; if ($tree['isCollapsed']) { $rootClickThruId = $tree['id']; // if this was probably collapsed - and if so - return } $style = 2; self::$displayedMarriageId = $marriage['id']; self::$displayedSpouseId = $marriage['spouseId']; $html .= self::createRootNode($style, $tree['name'], $marriage['spouseName'], $rootClickThruId, $parent2Id, $dateOfBirth); $html .= "\n</ul>\n</center>\n\n"; // this sucks because I'm closing a center that I did not start. bleah. did you go to cornell or what? // create the children nodes. $html .= '<ul id="famtreeMain">' . "\n\n"; // does this tree have a spouse? bleah - trivial if not but let's check against it. if (count($tree['marriages']) == 0) { // I don't think this ever executes. this is handled above. $html .= '</a></li></ul>' . "\n"; return $html; } // if we got to here, it means we don't care about multiple level 0 marriages $marriage = reset($tree['marriages']); $gen = 1; // iterate through the children of this marriage. foreach ($marriage['children'] as $child) { $dateOfBirth = Person::convertPersonDate($child['dob']); $html .= "\n" . str_repeat(' ', $gen) . '<li>' . str_replace('xxx', $child['id'], str_replace('yyy', $dateOfBirth, self::$agentreeUrlXXX)) . $child['name']; // does the level1 child have a spouse? if so... if (isset($child['marriages']) && count($child['marriages'])) { // TODO: fix multiple level 1 marriages. // $l1Marriage = reset( $child['marriages']); // we've already opened up the first <li> for the first marriage $childMarriageCount = 0; foreach ($child['marriages'] as $l1Marriage) { $childMarriageCount++; if ($childMarriageCount > 1) { // emit the lines for this marriage..... this will come after the tree2L2Html lines $dateOfBirth = Person::convertPersonDate($child['dob']); $html .= "\n" . str_repeat(' ', $gen) . " <br /><br /><br />" . str_replace('xxx', $child['id'], str_replace('yyy', $dateOfBirth, self::$agentreeUrlXXX)); } else { $html .= '<br />'; // this means it's the first l1 marriage. we need the br/ } if (substr($l1Marriage['spouseName'], 0, 1) != '-') { $html .= "m. " . $l1Marriage['spouseName']; } $html .= '</a>'; $html .= "\n" . $this->tree2L2Html($l1Marriage['children'], $gen); } } else { $html .= "\n" . str_repeat(' ', $gen) . '</a>'; } $html .= "\n </li>"; } $html .= "\n</ul>"; return $html; }
<?php require_once 'angkan-config.php'; require 'Person.php'; require 'Marriage.php'; require 'FamilyTree.php'; $familyTree = FamilyTree::getInstance(); $familyTree->readFromFile(); //$familyTree->debug( 956 ); $familyTree->save(); print "\nTotal number of persons in the list = " . count(Person::$theList); // var_dump( Person::$theList ); print "\n";
insert_visit(); // read any options that are turned on... foreach ($_REQUEST as $optName => $optValue) { if (substr($optName, 0, 4) == 'opt_') { $realOptName = substr($optName, 4); $_SESSION[$realOptName] = $optValue; } } $opt_ShowFormalNames = isset($_SESSION['ShowFormalNames']) && $_SESSION['ShowFormalNames'] == '0' ? 0 : 1; $opt_AllowSameSexMarriages = isset($_SESSION['AllowSameSexMarriages']) && $_SESSION['AllowSameSexMarriages'] == '1' ? 1 : 0; $opt_Debug = isset($_SESSION['debug']) && $_SESSION['debug'] == 1 ? 1 : 0; $collapseToSpouseId = isset($_GET['collapseTo']) && $_GET['collapseTo'] > '1' ? $_GET['collapseTo'] : 0; $suppressionList = array(); $familyTree = FamilyTree::getInstance(); $options = array('showFormalNames' => $opt_ShowFormalNames, 'allowSameSexMarriages' => $opt_AllowSameSexMarriages, 'collapseTo' => $collapseToSpouseId, 'debug' => $opt_Debug); FamilyTree::$originalRootId = $rootId; // TODO: make this into a setter function later $mainPerson = Person::readById($rootId); $mainTitle = "The " . $mainPerson->lastName . " Family Tree"; $tree = $familyTree->genTree($rootId, 3, $options); if (!$tree) { echo "\n<br> ERROR: {$rootId} generated a NULL tree"; } //var_dump( $tree ); // $newTree = $familyTree->enforceSuppression( $tree, $suppressionList ); $tree['isCollapsed'] = $collapseToSpouseId; $htmlMeat = $familyTree->tree2Html($tree); if (is_array($tree['marriages']) && count($tree['marriages']) > 0) { $level1ChildCount = count($tree['marriages'][0]['children']); } else { $level1ChildCount = 1;