summaryrefslogtreecommitdiff
path: root/app/Http/RequestHandlers/AddSpouseToIndividualAction.php
diff options
context:
space:
mode:
authorGreg Roach <fisharebest@gmail.com>2021-05-11 13:48:42 +0100
committerGreg Roach <fisharebest@gmail.com>2021-05-14 14:10:37 +0100
commitefd4768b0eab1f325771cdbc6181ff84f85f2149 (patch)
tree8eb6d588142b030f6080134fbd972a61f5baf14a /app/Http/RequestHandlers/AddSpouseToIndividualAction.php
parent9b80d2d98159cfc0110760b8e215998864838ff9 (diff)
downloadwebtrees-efd4768b0eab1f325771cdbc6181ff84f85f2149.tar.gz
webtrees-efd4768b0eab1f325771cdbc6181ff84f85f2149.tar.bz2
webtrees-efd4768b0eab1f325771cdbc6181ff84f85f2149.zip
Working on GEDCOM elements
Diffstat (limited to 'app/Http/RequestHandlers/AddSpouseToIndividualAction.php')
-rw-r--r--app/Http/RequestHandlers/AddSpouseToIndividualAction.php70
1 files changed, 20 insertions, 50 deletions
diff --git a/app/Http/RequestHandlers/AddSpouseToIndividualAction.php b/app/Http/RequestHandlers/AddSpouseToIndividualAction.php
index a960c5384c..1049b14197 100644
--- a/app/Http/RequestHandlers/AddSpouseToIndividualAction.php
+++ b/app/Http/RequestHandlers/AddSpouseToIndividualAction.php
@@ -28,7 +28,7 @@ use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;
use function assert;
-use function preg_match_all;
+use function is_string;
use function redirect;
/**
@@ -59,63 +59,33 @@ class AddSpouseToIndividualAction implements RequestHandlerInterface
$tree = $request->getAttribute('tree');
assert($tree instanceof Tree);
- $xref = $request->getQueryParams()['xref'];
-
- $individual = Registry::individualFactory()->make($xref, $tree);
- $individual = Auth::checkIndividualAccess($individual, true);
+ $xref = $request->getAttribute('xref');
+ assert(is_string($xref));
$params = (array) $request->getParsedBody();
- $sex = $params['SEX'];
-
- $this->gedcom_edit_service->glevels = $params['glevels'] ?? [];
- $this->gedcom_edit_service->tag = $params['tag'] ?? [];
- $this->gedcom_edit_service->text = $params['text'] ?? [];
- $this->gedcom_edit_service->islink = $params['islink'] ?? [];
-
- $this->gedcom_edit_service->splitSource();
- $indi_gedcom = '0 @@ INDI';
- $indi_gedcom .= $this->gedcom_edit_service->addNewName($request, $tree);
- $indi_gedcom .= $this->gedcom_edit_service->addNewSex($request);
- if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
- foreach ($matches[1] as $match) {
- $indi_gedcom .= $this->gedcom_edit_service->addNewFact($request, $tree, $match);
- }
- }
- if ($params['SOUR_INDI'] ?? false) {
- $indi_gedcom = $this->gedcom_edit_service->handleUpdates($indi_gedcom);
- } else {
- $indi_gedcom = $this->gedcom_edit_service->updateRest($indi_gedcom);
- }
+ $individual = Registry::individualFactory()->make($xref, $tree);
+ $individual = Auth::checkIndividualAccess($individual, true);
- $fam_gedcom = '';
- if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FAMFACTS'), $matches)) {
- foreach ($matches[1] as $match) {
- $fam_gedcom .= $this->gedcom_edit_service->addNewFact($request, $tree, $match);
- }
- }
- if ($params['SOUR_FAM'] ?? false) {
- $fam_gedcom = $this->gedcom_edit_service->handleUpdates($fam_gedcom);
- } else {
- $fam_gedcom = $this->gedcom_edit_service->updateRest($fam_gedcom);
- }
+ $levels = $params['ilevels'] ?? [];
+ $tags = $params['itags'] ?? [];
+ $values = $params['ivalues'] ?? [];
// Create the new spouse
- $spouse = $tree->createIndividual($indi_gedcom);
+ $gedcom = $this->gedcom_edit_service->editLinesToGedcom('INDI', $levels, $tags, $values);
+ $spouse = $tree->createIndividual("0 @@ INDI\n" . $gedcom);
+
// Create a new family
- if ($sex === 'F') {
- $family = $tree->createFamily("0 @@ FAM\n1 WIFE @" . $spouse->xref() . "@\n1 HUSB @" . $individual->xref() . '@' . $fam_gedcom);
- } else {
- $family = $tree->createFamily("0 @@ FAM\n1 HUSB @" . $spouse->xref() . "@\n1 WIFE @" . $individual->xref() . '@' . $fam_gedcom);
- }
- // Link the spouses to the family
- $spouse->createFact('1 FAMS @' . $family->xref() . '@', true);
- $individual->createFact('1 FAMS @' . $family->xref() . '@', true);
+ $i_link = "\n1 " . ($individual->sex() === 'F' ? 'WIFE' : 'HUSB') . ' @' . $individual->xref() . '@';
+ $s_link = "\n1 " . ($individual->sex() !== 'F' ? 'WIFE' : 'HUSB') . ' @' . $spouse->xref() . '@';
+ $family = $tree->createFamily("0 @@ FAM\n" . $i_link . $s_link);
+
+ // Link the individual to the family
+ $individual->createFact('1 FAMS @' . $family->xref() . '@', false);
- if (($params['goto'] ?? '') === 'new') {
- return redirect($spouse->url());
- }
+ // Link the spouse to the family
+ $spouse->createFact('1 FAMS @' . $family->xref() . '@', false);
- return redirect($individual->url());
+ return redirect($params['url'] ?? $spouse->url());
}
}