diff options
| -rw-r--r-- | action.php | 2 | ||||
| -rw-r--r-- | edit_interface.php | 63 | ||||
| -rw-r--r-- | library/WT/Controller/GedcomRecord.php | 2 | ||||
| -rw-r--r-- | library/WT/GedcomRecord.php | 13 |
4 files changed, 44 insertions, 36 deletions
diff --git a/action.php b/action.php index 47c36f57df..9f1f42b508 100644 --- a/action.php +++ b/action.php @@ -105,7 +105,7 @@ case 'delete-fact': if ($record && $record->canShow() && $record->canEdit()) { foreach ($record->getFacts() as $fact) { if ($fact->getfactId() == $fact_id && $fact->canShow() && $fact->canEdit()) { - $record->updateFact($fact_id, '', true); + $record->deleteFact($fact_id, true); break 2; } } diff --git a/edit_interface.php b/edit_interface.php index 271a2addb5..dba3e7418f 100644 --- a/edit_interface.php +++ b/edit_interface.php @@ -619,7 +619,7 @@ case 'linkfamaction': } } if (!$edit_fact) { - $family->updateFact(null, '1 CHIL @' . $person->getXref() . '@', true); + $family->createFact('1 CHIL @' . $person->getXref() . '@', true); } $controller->addInlineJavascript('closePopupAndReloadParent();'); @@ -1091,14 +1091,14 @@ case 'addchildaction': $old_child = $fact->getTarget(); if ($old_child && WT_Date::Compare($new_child->getEstimatedBirthDate(), $old_child->getEstimatedBirthDate())<0) { // Insert before this child - $family->updateFact($fact->getFactId(), "1 CHIL @" . $new_child->getXref()."@\n" . $fact->getGedcom(), !$keep_chan); + $family->updateFact($fact->getFactId(), '1 CHIL @' . $new_child->getXref() . '@' . $fact->getGedcom(), !$keep_chan); $done = true; break; } } if (!$done) { // Append child at end - $family->updateFact(null, "1 CHIL @" . $new_child->getXref()."@\n", !$keep_chan); + $family->createFact('1 CHIL @' . $new_child->getXref() . '@', !$keep_chan); } if (safe_POST('goto')=='new') { @@ -1185,9 +1185,9 @@ case 'addspouseaction': $spouse = WT_GedcomRecord::createRecord($indi_gedcom, WT_GED_ID); // Link the family if ($sex=='F') { - $family->updateFact(null, '1 WIFE @' . $spouse->getXref() . '@' . $fam_gedcom, true); + $family->createFact('1 WIFE @' . $spouse->getXref() . '@' . $fam_gedcom, true); } else { - $family->updateFact(null, '1 HUSB @' . $spouse->getXref() . '@' . $fam_gedcom, true); + $family->createFact('1 HUSB @' . $spouse->getXref() . '@' . $fam_gedcom, true); } } else { // Create the new spouse @@ -1199,8 +1199,8 @@ case 'addspouseaction': $family = WT_GedcomRecord::createRecord("0 @NEW@ FAM\n1 HUSB @" . $spouse->getXref() . "@\n1 WIFE @" . $person->getXref() . "@" . $fam_gedcom, WT_GED_ID); } // Link the spouses to the family - $spouse->updateFact(null, '1 FAMS @' . $family->getXref() . '@', true); - $person->updateFact(null, '1 FAMS @' . $family->getXref() . '@', true); + $spouse->createFact('1 FAMS @' . $family->getXref() . '@', true); + $person->createFact('1 FAMS @' . $family->getXref() . '@', true); } if (safe_POST('goto')=='new') { @@ -1251,8 +1251,8 @@ case 'linkspouseaction': } $family = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID); - $person->updateFact(null, '1 FAMS @' . $family->getXref() .'@', true); - $spouse->updateFact(null, '1 FAMS @' . $family->getXref() .'@', true); + $person->createFact('1 FAMS @' . $family->getXref() .'@', true); + $spouse->createFact('1 FAMS @' . $family->getXref() .'@', true); $controller->addInlineJavascript('closePopupAndReloadParent();'); break; @@ -1305,8 +1305,8 @@ case 'addnewparentaction': } else { $famrec = updateRest($famrec); } - $family->updateFact(null, $famrec, true); - $parent->updateFact(null, '1 FAMS @' . $family->getXref() . '@', true); + $family->createFact($famrec, true); + $parent->createFact('1 FAMS @' . $family->getXref() . '@', true); } else { // Create a new family $famrec = '0 @new@ FAM'; @@ -1330,8 +1330,8 @@ case 'addnewparentaction': } $family = WT_GedcomRecord::createRecord($famrec, WT_GED_ID); - $person->updateFact(null, '1 FAMC @' . $family->getXref() . '@', true); - $parent->updateFact(null, '1 FAMS @' . $family->getXref() . '@', true); + $person->createFact('1 FAMC @' . $family->getXref() . '@', true); + $parent->createFact('1 FAMS @' . $family->getXref() . '@', true); } if (safe_POST('goto')=='new') { @@ -1354,21 +1354,20 @@ case 'addopfchildaction': ->pageHeader(); // Create a family - $gedcom='0 @NEW@ FAM'; if ($person->getSex()=='F') { - $gedcom.="\n1 WIFE @" . $person->getXref() . "@"; + $gedcom = "0 @NEW@ FAM\n1 WIFE @" . $person->getXref() . "@"; } else { - $gedcom.="\n1 HUSB @" . $person->getXref() . "@"; + $gedcom = "0 @NEW@ FAM\n1 HUSB @" . $person->getXref() . "@"; } $family = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID); // Link the parent to the family - $person->updateFact(null, "1 FAMS @" . $family->getXref() . "@", true); + $person->createFact('1 FAMS @' . $family->getXref() . '@', true); // Create a child splitSOUR(); // separate SOUR record from the rest - $gedcom = "0 @NEW@ INDI"; + $gedcom = '0 @NEW@ INDI'; $gedcom .= addNewName(); $gedcom .= addNewSex (); $gedcom .= "\n".WT_Gedcom_Code_Pedi::createNewFamcPedi($PEDI, $newfamxref); @@ -1387,7 +1386,7 @@ case 'addopfchildaction': $child = WT_GedcomRecord::createRecord($gedcom, WT_GED_ID); // Link the family to the child - $family->updateFact(null, '1 CHIL @' . $child->getXref() . '@', true); + $family->createFact('1 CHIL @' . $child->getXref() . '@', true); $controller->addInlineJavascript('closePopupAndReloadParent();'); break; @@ -1455,7 +1454,7 @@ case 'paste': ->setPageTitle(WT_I18N::translate('Add from clipboard')) ->pageHeader(); - $record->updateFact(null, $WT_SESSION->clipboard[$fact]['factrec']); + $record->createFact($WT_SESSION->clipboard[$fact]['factrec']); $controller->addInlineJavascript('closePopupAndReloadParent();'); break; @@ -1864,21 +1863,21 @@ case 'changefamily_update': // Remove old FAMS link foreach ($old_father->getFacts('FAMS') as $fact) { if ($fact->getTarget() == $family) { - $old_father->updateFact($fact->getFactId(), null, !$keep_chan); + $old_father->deleteFact($fact->getFactId(), !$keep_chan); } } // Remove old HUSB link foreach ($family->getFacts('HUSB|WIFE') as $fact) { if ($fact->getTarget() == $old_father) { - $family->updateFact($fact->getFactId(), null, !$keep_chan); + $family->deleteFact($fact->getFactId(), !$keep_chan); } } } if ($new_father) { // Add new FAMS link - $new_father->updateFact(null, '1 FAMS @' . $family->getXref() . '@', !$keep_chan); + $new_father->createFact('1 FAMS @' . $family->getXref() . '@', !$keep_chan); // Add new HUSB link - $family->updateFact(null, '1 HUSB @' . $new_father->getXref() . '@', !$keep_chan); + $family->createFact('1 HUSB @' . $new_father->getXref() . '@', !$keep_chan); } } @@ -1887,21 +1886,21 @@ case 'changefamily_update': // Remove old FAMS link foreach ($old_mother->getFacts('FAMS') as $fact) { if ($fact->getTarget() == $family) { - $old_mother->updateFact($fact->getFactId(), null, !$keep_chan); + $old_mother->deleteFact($fact->getFactId(), !$keep_chan); } } // Remove old WIFE link foreach ($family->getFacts('HUSB|WIFE') as $fact) { if ($fact->getTarget() == $old_mother) { - $family->updateFact($fact->getFactId(), null, !$keep_chan); + $family->deleteFact($fact->getFactId(), !$keep_chan); } } } if ($new_mother) { // Add new FAMS link - $new_mother->updateFact(null, '1 FAMS @' . $family->getXref() . '@', !$keep_chan); + $new_mother->createFact('1 FAMS @' . $family->getXref() . '@', !$keep_chan); // Add new WIFE link - $family->updateFact(null, '1 WIFE @' . $new_mother->getXref() . '@', !$keep_chan); + $family->createFact('1 WIFE @' . $new_mother->getXref() . '@', !$keep_chan); } } @@ -1910,13 +1909,13 @@ case 'changefamily_update': // Remove old FAMC link foreach ($old_child->getFacts('FAMC') as $fact) { if ($fact->getTarget() == $family) { - $old_child->updateFact($fact->getFactId(), null, !$keep_chan); + $old_child->deleteFact($fact->getFactId(), !$keep_chan); } } // Remove old CHIL link foreach ($family->getFacts('CHIL') as $fact) { if ($fact->getTarget() == $old_child) { - $family->updateFact($fact->getFactId(), null, !$keep_chan); + $family->deleteFact($fact->getFactId(), !$keep_chan); } } } @@ -1925,9 +1924,9 @@ case 'changefamily_update': foreach ($new_children as $new_child) { if (!in_array($new_child, $old_children)) { // Add new FAMC link - $new_child->updateFact(null, '1 FAMS @' . $family->getXref() . '@', !$keep_chan); + $new_child->createFact('1 FAMS @' . $family->getXref() . '@', !$keep_chan); // Add new CHIL link - $family->updateFact(null, '1 CHIL @' . $new_child->getXref() . '@', !$keep_chan); + $family->createFact('1 CHIL @' . $new_child->getXref() . '@', !$keep_chan); } } diff --git a/library/WT/Controller/GedcomRecord.php b/library/WT/Controller/GedcomRecord.php index 233c7fbaac..e123819b69 100644 --- a/library/WT/Controller/GedcomRecord.php +++ b/library/WT/Controller/GedcomRecord.php @@ -34,7 +34,7 @@ class WT_Controller_GedcomRecord extends WT_Controller_Page { $broken_links=0; foreach ($this->record->getFacts('HUSB|WIFE|CHIL|FAMS|FAMC|SOUR|REPO|OBJE') as $fact) { // Not NOTE! if (!$fact->isOld() && $fact->getTarget() === null) { - $this->record->updateFact($fact->getFactId(), null, false); + $this->record->deleteFact($fact->getFactId(), false); WT_FlashMessages::addMessage(/* I18N: %s are names of records, such as sources, repositories or individuals */ WT_I18N::translate('The link from ā%1$sā to ā%2$sā has been deleted.', $this->record->getFullName(), $fact->getValue())); $broken_links = true; } diff --git a/library/WT/GedcomRecord.php b/library/WT/GedcomRecord.php index 4dca149b37..f10104087c 100644 --- a/library/WT/GedcomRecord.php +++ b/library/WT/GedcomRecord.php @@ -758,8 +758,17 @@ class WT_GedcomRecord { // CRUD operations ////////////////////////////////////////////////////////////////////////////// - // Replace a (possibly empty) fact with a new (possibly empty) fact. - // This allows create/update/delete of individual facts + // Add a new fact to this record + public function createFact($gedcom, $update_chan) { + $this->updateFact(null, $gedcom, $update_chan); + } + + // Delete a fact from this record + public function deleteFact($fact_id, $update_chan) { + $this->updateFact($fact_id, null, $update_chan); + } + + // Replace a fact with a new gedcom data. public function updateFact($fact_id, $gedcom, $update_chan) { if (strpos("\r", $gedcom)!==false) { // MSDOS line endings will break things in horrible ways |
