예제 #1
0
 public static function readFamilyData($titleString, &$data, &$gedcomData, $includeRelativeData = false, $includeNonCompareData = false, $revid = 0, $timestamp = '')
 {
     $children = array();
     $data['familyTitle'][] = $titleString;
     if (GedcomUtil::isGedcomTitle($titleString)) {
         $title = null;
         $data['Exists'] = true;
         $xml = GedcomUtil::getGedcomXml($gedcomData, $titleString);
         $data['GedcomMatchTitle'] = (string) $xml['match'];
         $contents = GedcomUtil::getGedcomContents($gedcomData, $titleString);
     } else {
         $title = Title::newFromText($titleString, NS_FAMILY);
         $data['Exists'] = $title->exists();
         $p = new Family($titleString);
         $p->loadPage($revid);
         if ($revid) {
             $data['Revid'][] = $revid;
         }
         // for consistency with readPersonData
         $xml = $p->getPageXml();
         $contents = $p->getPageContents();
     }
     $husbandFound = $wifeFound = false;
     if ($includeRelativeData) {
         CompareForm::initPersonData('husband', $data);
         CompareForm::initPersonData('wife', $data);
     }
     if (isset($xml)) {
         foreach ($xml->event_fact as $ef) {
             $type = (string) $ef['type'];
             if ($type == Family::$MARRIAGE_TAG || $type == Family::$ALT_MARRIAGE_TAG) {
                 CompareForm::getDatePlace($ef, 'Marriagedate', 'Marriageplace', $data);
             } else {
                 if ($includeNonCompareData) {
                     CompareForm::getOtherEvent($ef, '', $data);
                 }
             }
         }
         if ($includeNonCompareData) {
             CompareForm::getSINContents($xml, $contents, '', $data);
         }
         if ($includeRelativeData) {
             $husbandFound = CompareForm::readRelativeData('husband', $xml->husband, $data, $gedcomData, true, false, $includeNonCompareData, $timestamp);
             $wifeFound = CompareForm::readRelativeData('wife', $xml->wife, $data, $gedcomData, true, false, $includeNonCompareData, $timestamp);
             $i = 0;
             foreach ($xml->child as $c) {
                 $childTitle = (string) $c['title'];
                 if ($childTitle) {
                     $children[$i] = array();
                     CompareForm::initPersonData('child', $children[$i]);
                     if (GedcomUtil::isGedcomTitle($childTitle)) {
                         $childRevid = 0;
                     } else {
                         $t = Title::newFromText($childTitle, NS_PERSON);
                         $childRevid = $timestamp ? StructuredData::getRevidForTimestamp($t, $timestamp) : 0;
                     }
                     CompareForm::readPersonData('child', $childTitle, $children[$i], $gedcomData, false, false, true, $includeNonCompareData, $childRevid);
                     $i++;
                 }
             }
         } else {
             $data['husbandTitle'] = array();
             foreach ($xml->husband as $m) {
                 $data['husbandTitle'][] = (string) $m['title'];
             }
             $data['wifeTitle'] = array();
             foreach ($xml->wife as $m) {
                 $data['wifeTitle'][] = (string) $m['title'];
             }
             $data['childTitle'] = array();
             foreach ($xml->child as $m) {
                 $data['childTitle'][] = (string) $m['title'];
             }
         }
     } else {
         if ($title && StructuredData::isRedirect($contents)) {
             $data['Redirect'] = true;
         }
     }
     if ($includeRelativeData && (!$husbandFound || !$wifeFound)) {
         list($fg, $fs, $mg, $ms) = StructuredData::parseFamilyTitle($titleString);
         if (!$husbandFound) {
             if ($fg) {
                 $data['husbandGiven'][] = $fg;
             }
             if ($fs) {
                 $data['husbandSurname'][] = $fs;
             }
         }
         if (!$wifeFound) {
             if ($mg) {
                 $data['wifeGiven'][] = $mg;
             }
             if ($ms) {
                 $data['wifeSurname'][] = $ms;
             }
         }
     }
     $data['Nomerge'] = CompareForm::getNomergeTitleStrings($title);
     if ($title) {
         $data['Updatable'] = CompareForm::isUpdatable($title, $contents);
     }
     return $children;
 }
예제 #2
0
 private function readData()
 {
     $first = true;
     $familyMembers = array();
     foreach ($this->data as &$datai) {
         $j = 0;
         while ($j < count($datai)) {
             $dataij =& $datai[$j];
             if (GedcomUtil::isGedcomTitle($dataij['title'])) {
                 $xml = GedcomUtil::getGedcomXml($this->gedcomData, $dataij['title']);
                 if ($xml['merged'] == 'true' && (string) $xml['match'] == (string) $datai[count($datai) - 1]['title']) {
                     $this->redirects[] = Title::newFromText($dataij['title'], $this->namespace == 'Family' && $first ? NS_FAMILY : NS_PERSON);
                     array_splice($datai, $j, 1);
                     // remove this page from the merge
                     $j--;
                 } else {
                     $dataij['gedcom'] = true;
                     $dataij['object'] = null;
                     $dataij['revid'] = false;
                     $dataij['talkrevid'] = false;
                     MergeForm::readXmlData($this->namespace == 'Family' && $first, $xml, $dataij);
                     $dataij['contents'] = GedcomUtil::getGedcomContents($this->gedcomData, $dataij['title']);
                 }
             } else {
                 $dataij['gedcom'] = false;
                 if ($this->namespace == 'Family' && $first) {
                     $title = Title::newFromText($dataij['title'], NS_FAMILY);
                     $dataij['object'] = new Family($dataij['title']);
                 } else {
                     $title = Title::newFromText($dataij['title'], NS_PERSON);
                     $dataij['object'] = new Person($dataij['title']);
                 }
                 $dataij['revid'] = $title->getLatestRevID(GAID_FOR_UPDATE);
                 // make sure you read the master db
                 $dataij['object']->loadPage($dataij['revid']);
                 $xml = $dataij['object']->getPageXml();
                 $talkTitle = $title->getTalkPage();
                 $dataij['talkrevid'] = $talkTitle->getLatestRevID(GAID_FOR_UPDATE);
                 // make sure you read the master db
                 // this must be a family member
                 // non-family members can appear in gedcom updates -- gedcom page has been matched to a page in another family
                 // or they can appear when the family is do not merge
                 if ($this->namespace == 'Family' && !$first && !@$familyMembers[$dataij['title']]) {
                     array_splice($datai, $j, 1);
                     // remove this page from the merge
                     $j--;
                 } else {
                     if ($this->doNotMerge($datai, $title)) {
                         $this->nomerges[] = $title;
                     } else {
                         if (isset($xml)) {
                             MergeForm::readXmlData($this->namespace == 'Family' && $first, $xml, $dataij);
                             $dataij['contents'] =& $dataij['object']->getPageContents();
                             if ($this->namespace == 'Family' && $first) {
                                 foreach ($xml->husband as $m) {
                                     $familyMembers[(string) $m['title']] = 1;
                                 }
                                 $data['wifeTitle'] = array();
                                 foreach ($xml->wife as $m) {
                                     $familyMembers[(string) $m['title']] = 1;
                                 }
                                 $data['childTitle'] = array();
                                 foreach ($xml->child as $m) {
                                     $familyMembers[(string) $m['title']] = 1;
                                 }
                             }
                         } else {
                             if (StructuredData::isRedirect($dataij['object']->getPageContents())) {
                                 $this->redirects[] = $title;
                                 array_splice($datai, $j, 1);
                                 // remove this page from the merge
                                 $j--;
                             } else {
                                 if ($dataij['revid']) {
                                     // page exists but doesn't have xml and is not a redirect
                                     array_splice($datai, $j, 1);
                                     // remove this page from the merge
                                     $j--;
                                     error_log("ERROR: Merging page exists without XML: " . $title->getPrefixedText() . "\n");
                                 }
                             }
                         }
                     }
                 }
             }
             $j++;
         }
         $first = false;
     }
     $this->removeSingletonFamilyMemberRows();
 }