コード例 #1
0
 /**
  * Create a header for a (newly-created or already-imported) gedcom file.
  *
  * @param Tree $tree
  *
  * @return string
  */
 public static function gedcomHeader(Tree $tree)
 {
     // Default values for a new header
     $HEAD = "0 HEAD";
     $SOUR = "\n1 SOUR " . WT_WEBTREES . "\n2 NAME " . WT_WEBTREES . "\n2 VERS " . WT_VERSION;
     $DEST = "\n1 DEST DISKETTE";
     $DATE = "\n1 DATE " . strtoupper(date("d M Y")) . "\n2 TIME " . date("H:i:s");
     $GEDC = "\n1 GEDC\n2 VERS 5.5.1\n2 FORM Lineage-Linked";
     $CHAR = "\n1 CHAR UTF-8";
     $FILE = "\n1 FILE " . $tree->getName();
     $LANG = "";
     $PLAC = "\n1 PLAC\n2 FORM City, County, State/Province, Country";
     $COPR = "";
     $SUBN = "";
     $SUBM = "\n1 SUBM @SUBM@\n0 @SUBM@ SUBM\n1 NAME " . Auth::user()->getUserName();
     // The SUBM record is mandatory
     // Preserve some values from the original header
     $record = GedcomRecord::getInstance('HEAD', $tree);
     if ($fact = $record->getFirstFact('PLAC')) {
         $PLAC = "\n1 PLAC\n2 FORM " . $fact->getAttribute('FORM');
     }
     if ($fact = $record->getFirstFact('LANG')) {
         $LANG = $fact->getValue();
     }
     if ($fact = $record->getFirstFact('SUBN')) {
         $SUBN = $fact->getValue();
     }
     if ($fact = $record->getFirstFact('COPR')) {
         $COPR = $fact->getValue();
     }
     // Link to actual SUBM/SUBN records, if they exist
     $subn = Database::prepare("SELECT o_id FROM `##other` WHERE o_type=? AND o_file=?")->execute(array('SUBN', $tree->getTreeId()))->fetchOne();
     if ($subn) {
         $SUBN = "\n1 SUBN @{$subn}@";
     }
     $subm = Database::prepare("SELECT o_id FROM `##other` WHERE o_type=? AND o_file=?")->execute(array('SUBM', $tree->getTreeId()))->fetchOne();
     if ($subm) {
         $SUBM = "\n1 SUBM @{$subm}@";
     }
     return $HEAD . $SOUR . $DEST . $DATE . $GEDC . $CHAR . $FILE . $COPR . $LANG . $PLAC . $SUBN . $SUBM . "\n";
 }