/** * **/ public function readFromFile() { $marriageStack = array(); $file = fopen('FAMTREE.TXT', 'r'); while ($line = fgets($file)) { // print $line . "\n"; if (strstr($line, ':')) { // it's an attrib - parse it. add it. list($attrName, $attrValue) = $currentPerson->addAttribute($line); // SOME attributes pertain to the marriage, not the individual. detect this - apply as needed. if ($attrName == 'TREEHINT') { if ($attrValue == 'SUPPRESS_INDIVIDUAL') { $currentPerson->suppress = 1; } else { if ($attrValue == 'SUPPRESS_UNION') { $currentMarriage->suppress = 1; } else { echo "\n***ERROR: Unknown TREEHINT: " . $attrValue; } } } continue; } if (strstr($line, '>')) { // print $line; // it's a person with lichauco blood $gen = strpos($line, '>'); $ordinal = intval(ltrim(substr($line, 0, $gen))); $pLine = substr($line, $gen + 1); $currentPerson = Person::create($pLine); $currentPerson->isSpouseRecord = 0; $currentPerson->ordinal = $ordinal; $gen2 = ($gen - 2) / 6 + 1; // print $gen . " " . $gen2 . " " . $currentPerson->id . " " . $currentPerson->name; // now set the union from which this guy came... if ($gen2 > 1) { // we're >1st gen. let's set the parent union $currentPerson->cameFromUnion = $marriageStack[$gen2 - 1]; } $this->personStack[$gen2] = $currentPerson; } else { // it's a person who married into the lichauco clan // create the person. then create the union.... $gen = strpos($line, '^'); $ordinal = ord(substr($line, $gen - 1, 1)) - ord('a') + 1; $pLine = substr($line, $gen + 1); $currentPerson = $person2 = Person::Create($pLine); $currentPerson->isSpouseRecord = 1; $currentPerson->ordinal = $ordinal; $gen2 = ($gen - 5) / 6 + 1; // print $gen . " " . $gen2 . " " . $person2->id . " " . $person2->name; $person1 = $this->personStack[$gen2]; // check if person2 is a dupe if ($person2->id != Person::$theCount) { // do any special processing for dupe here... // TODO: find the marriage featuring person2->id and person1->id $currentMarriage = Marriage::getExactMarriage($person1->id, $person2->id); $person1->unions[] = $currentMarriage; } else { //print "\nAdding Marrage between " . $person1->name . " and " . $person2->name . " gen2 = " . $gen2; $currentMarriage = Marriage::create($person1->id, $person2->id); $marriageStack[$gen2] = $currentMarriage; } // add the union to the lichauco blood person... $person1->unions[] = $currentMarriage; } } fclose($file); }