From 7cfc9f7da10957bfa6bf513dabecb6e95dc9eab0 Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Fri, 9 Aug 2013 06:57:36 +0100 Subject: Replace linkMedia() / unlinkMedia() --- addmedia.php | 12 ++++---- inverselink.php | 3 +- library/WT/GedcomRecord.php | 4 +-- .../_MEDIA/media_0_inverselink.php | 33 +++------------------- 4 files changed, 14 insertions(+), 38 deletions(-) diff --git a/addmedia.php b/addmedia.php index 123d962a58..267fc7e6df 100644 --- a/addmedia.php +++ b/addmedia.php @@ -239,7 +239,8 @@ case 'create': // Save the information from the “showcreateform” action $media = WT_GedcomRecord::createRecord($newged, WT_GED_ID); if ($linktoid) { - linkMedia($media->getXref(), $linktoid, 1); + $record = WT_GedcomRecord::getInstance($linktoid); + $record->createFact('1 OBJE @' . $media->getXref() . '@', true); AddToLog('Media ID '.$media->getXref()." successfully added to $linktoid.", 'edit'); $controller->addInlineJavascript('closePopupAndReloadParent();'); } else { @@ -392,11 +393,10 @@ case 'update': // Save the information from the “editmedia” action $newrec = handle_updates($newrec); $record->updateRecord($newrec, $update_CHAN); - if ($pid && $linktoid!='') { - $link = linkMedia($pid, $linktoid, 1); - if ($link) { - AddToLog('Media ID '.$pid." successfully added to $linktoid.", 'edit'); - } + if ($pid && $linktoid) { + $record = WT_GedcomRecord::getInstance($linktoid); + $record->createFact('1 OBJE @' . $pid . '@', true); + AddToLog('Media ID '.$pid." successfully added to $linktoid.", 'edit'); } $controller->pageHeader(); if ($messages) { diff --git a/inverselink.php b/inverselink.php index cc5ede6415..84d1b415f0 100644 --- a/inverselink.php +++ b/inverselink.php @@ -168,7 +168,8 @@ if ($linkto=='manage' && array_key_exists('GEDFact_assistant', WT_Module::getAct echo ''; echo ''; } elseif ($action == "update" && $paramok) { - linkMedia($mediaid, $linktoid); + $record = WT_GedcomRecord::getInstance($linktoid); + $record->createFact('1 OBJE @' . $mediaid . '@', true); } echo ''; } diff --git a/library/WT/GedcomRecord.php b/library/WT/GedcomRecord.php index fe530a0ef3..9ee510a4c2 100644 --- a/library/WT/GedcomRecord.php +++ b/library/WT/GedcomRecord.php @@ -931,7 +931,7 @@ class WT_GedcomRecord { } // Remove all links from this record to $xref - public function removeLinks($xref) { + public function removeLinks($xref, $update_chan) { $value = '@' . $xref . '@'; foreach ($this->getFacts() as $fact) { @@ -943,7 +943,7 @@ class WT_GedcomRecord { $next_levels = '[' . $match[1]+1 . '-9]'; $gedcom = preg_replace('/' . $match[1] . '(\n' . $next_levels .'.*)*/', '', $gedcom); } - $this->updateFact($fact->factId(), $gedcom); + $this->updateFact($fact->factId(), $gedcom, $update_chan); } } } diff --git a/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php b/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php index a8a4d82e88..511858909e 100644 --- a/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php +++ b/modules_v3/GEDFact_assistant/_MEDIA/media_0_inverselink.php @@ -605,41 +605,16 @@ function shiftlinks() { // Unlink records indicated by radio button ========= if ($exist_links) { foreach (explode(',', $exist_links) as $remLinkId) { - unlinkMedia($remLinkId, 'OBJE', $mediaid, 1, $update_CHAN!='no_change'); + $indi = WT_Individual::getInstance($remLinkId); + $indi->removeLinks($media_id, $update_CHAN!='no_change'); } } // Add new Links ==================================== if ($more_links) { foreach (explode(',', $more_links) as $addLinkId) { - linkMedia($mediaid, $addLinkId, 1, $update_CHAN!='no_change'); + $indi = WT_Individual::getInstance($addLinkId); + $indi->createFact('1 OBJE @' . $addLinkId . '@', $update_CHAN!='no_change'); } } $controller->addInlineJavascript('closePopupAndReloadParent();'); } - -/** -* unLink Media ID to Indi, Family, or Source ID -* -* @param string $mediaid Media ID to be unlinked. -* @param string $linktoid Indi, Family, or Source ID that the Media ID should be unlinked from. -* @param $linenum should be ALWAYS set to 'OBJE'. -* @param int $level Level where the Media Object reference should be removed from (not used) -* @param boolean $chan Whether or not to update/add the CHAN record -* -* @return bool success or failure -*/ -function unlinkMedia($linktoid, $linenum, $mediaid, $level=1, $chan=true) { - if (empty($level)) $level = 1; - if ($level!=1) return false; // Level 2 items get unlinked elsewhere (maybe ??) - // find Indi, Family, or Source record to unlink from - $gedrec = find_gedcom_record($linktoid, WT_GED_ID, true); - - //-- when deleting/unlinking a media link - //-- $linenum comes as an OBJE and the $mediaid to delete should be set - if (!is_numeric($linenum)) { - $newged = remove_media_subrecord($gedrec, $mediaid); - } else { - $newged = remove_subline($gedrec, $linenum); - } - replace_gedrec($linktoid, WT_GED_ID, $newged, $chan); -} -- cgit v1.3