summaryrefslogtreecommitdiff
path: root/app/Http/RequestHandlers/AddChildToIndividualAction.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/AddChildToIndividualAction.php
parent9b80d2d98159cfc0110760b8e215998864838ff9 (diff)
downloadwebtrees-efd4768b0eab1f325771cdbc6181ff84f85f2149.tar.gz
webtrees-efd4768b0eab1f325771cdbc6181ff84f85f2149.tar.bz2
webtrees-efd4768b0eab1f325771cdbc6181ff84f85f2149.zip
Working on GEDCOM elements
Diffstat (limited to 'app/Http/RequestHandlers/AddChildToIndividualAction.php')
-rw-r--r--app/Http/RequestHandlers/AddChildToIndividualAction.php82
1 files changed, 19 insertions, 63 deletions
diff --git a/app/Http/RequestHandlers/AddChildToIndividualAction.php b/app/Http/RequestHandlers/AddChildToIndividualAction.php
index 2d87d950ac..016367a58e 100644
--- a/app/Http/RequestHandlers/AddChildToIndividualAction.php
+++ b/app/Http/RequestHandlers/AddChildToIndividualAction.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,77 +59,33 @@ class AddChildToIndividualAction implements RequestHandlerInterface
$tree = $request->getAttribute('tree');
assert($tree instanceof Tree);
- $xref = $request->getQueryParams()['xref'];
+ $xref = $request->getAttribute('xref');
+ assert(is_string($xref));
+
+ $params = (array) $request->getParsedBody();
$individual = Registry::individualFactory()->make($xref, $tree);
$individual = Auth::checkIndividualAccess($individual, true);
- $params = (array) $request->getParsedBody();
+ $levels = $params['ilevels'] ?? [];
+ $tags = $params['itags'] ?? [];
+ $values = $params['ivalues'] ?? [];
- $PEDI = $params['PEDI'];
+ // Create the new child
+ $gedcom = "0 @@ INDI\n" . $this->gedcom_edit_service->editLinesToGedcom('INDI', $levels, $tags, $values);
+ $child = $tree->createIndividual($gedcom);
- $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'] ?? [];
-
- // Create a family
- if ($individual->sex() === 'F') {
- $gedcom = "0 @@ FAM\n1 WIFE @" . $individual->xref() . '@';
- } else {
- $gedcom = "0 @@ FAM\n1 HUSB @" . $individual->xref() . '@';
- }
+ // Create a new family
+ $link = $child->sex() === 'F' ? 'WIFE' : 'HUSB';
+ $gedcom = "0 @@ FAM\n1 " . $link . " @" . $individual->xref() . "@\n1 CHIL @" . $child->xref() . '@';
$family = $tree->createFamily($gedcom);
- // Link the parent to the family
- $individual->createFact('1 FAMS @' . $family->xref() . '@', true);
-
- // Create a child
- $this->gedcom_edit_service->splitSource(); // separate SOUR record from the rest
-
- $gedcom = '0 @@ INDI';
- $gedcom .= $this->gedcom_edit_service->addNewName($request, $tree);
- $gedcom .= $this->gedcom_edit_service->addNewSex($request);
-
- $fam_xref = $family->xref();
- switch ($PEDI) {
- case '':
- $gedcom .= "\n1 FAMC @$fam_xref@";
- break;
- case 'adopted':
- $gedcom .= "\n1 FAMC @$fam_xref@\n2 PEDI $PEDI\n1 ADOP\n2 FAMC @$fam_xref@\n3 ADOP BOTH";
- break;
- case 'sealing':
- $gedcom .= "\n1 FAMC @$fam_xref@\n2 PEDI $PEDI\n1 SLGC\n2 FAMC @$fam_xref@";
- break;
- case 'foster':
- $gedcom .= "\n1 FAMC @$fam_xref@\n2 PEDI $PEDI\n1 EVEN\n2 TYPE $PEDI";
- break;
- default:
- $gedcom .= "\n1 FAMC @$fam_xref@\n2 PEDI $PEDI";
- break;
- }
-
- if (preg_match_all('/([A-Z0-9_]+)/', $tree->getPreference('QUICK_REQUIRED_FACTS'), $matches)) {
- foreach ($matches[1] as $match) {
- $gedcom .= $this->gedcom_edit_service->addNewFact($request, $tree, $match);
- }
- }
- if ($params['SOUR_INDI'] ?? false) {
- $gedcom = $this->gedcom_edit_service->handleUpdates($gedcom);
- } else {
- $gedcom = $this->gedcom_edit_service->updateRest($gedcom);
- }
-
- $child = $tree->createIndividual($gedcom);
-
- // Link the family to the child
- $family->createFact('1 CHIL @' . $child->xref() . '@', true);
+ // Link the individual to the family
+ $individual->createFact('1 FAMS @' . $family->xref() . '@', false);
- if (($params['goto'] ?? '') === 'new') {
- return redirect($child->url());
- }
+ // Link the child to the family
+ $child->createFact('1 FAMC @' . $family->xref() . '@', false);
- return redirect($individual->url());
+ return redirect($params['url'] ?? $child->url());
}
}