|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace GenealogiaWebsite\LaravelGedcom\Utils; |
| 4 | + |
| 5 | +use GenealogiaWebsite\LaravelGedcom\Models\Family; |
| 6 | +use GenealogiaWebsite\LaravelGedcom\Models\Person; |
| 7 | +use GenealogiaWebsite\LaravelGedcom\Utils\Importer\Chan; |
| 8 | +use GenealogiaWebsite\LaravelGedcom\Utils\Importer\Fam\Even; |
| 9 | +use GenealogiaWebsite\LaravelGedcom\Utils\Importer\Fam\Slgs; |
| 10 | +use GenealogiaWebsite\LaravelGedcom\Utils\Importer\NoteRef; |
| 11 | +use GenealogiaWebsite\LaravelGedcom\Utils\Importer\ObjeRef; |
| 12 | +use GenealogiaWebsite\LaravelGedcom\Utils\Importer\Refn; |
| 13 | +use GenealogiaWebsite\LaravelGedcom\Utils\Importer\SourRef; |
| 14 | +use GenealogiaWebsite\LaravelGedcom\Utils\Importer\Subm; |
| 15 | + |
| 16 | +class FamilyData |
| 17 | +{ |
| 18 | + /** |
| 19 | + * Array of persons ID |
| 20 | + * key - old GEDCOM ID |
| 21 | + * value - new autoincrement ID. |
| 22 | + * |
| 23 | + * @var string |
| 24 | + */ |
| 25 | + protected $persons_id = []; |
| 26 | + protected $subm_ids = []; |
| 27 | + protected $sour_ids = []; |
| 28 | + protected $obje_ids = []; |
| 29 | + protected $note_ids = []; |
| 30 | + protected $repo_ids = []; |
| 31 | + protected $conn = ''; |
| 32 | + |
| 33 | + public static function getFamily($conn, $family, $obje_ids) |
| 34 | + { |
| 35 | + $g_id = $family->getId(); |
| 36 | + $resn = $family->getResn(); |
| 37 | + $husb = $family->getHusb(); |
| 38 | + $wife = $family->getWife(); |
| 39 | + |
| 40 | + // string |
| 41 | + $nchi = $family->getNchi(); |
| 42 | + $rin = $family->getRin(); |
| 43 | + |
| 44 | + // array |
| 45 | + $subm = $family->getSubm(); |
| 46 | + $_slgs = $family->getSlgs(); |
| 47 | + |
| 48 | + $description = null; |
| 49 | + $type_id = 0; |
| 50 | + |
| 51 | + $children = $family->getChil(); |
| 52 | + $events = $family->getAllEven(); |
| 53 | + $_note = $family->getNote(); |
| 54 | + $_obje = $family->getObje(); |
| 55 | + $_sour = $family->getSour(); |
| 56 | + $_refn = $family->getRefn(); |
| 57 | + |
| 58 | + $chan = $family->getChan(); |
| 59 | + |
| 60 | + $husband_id = (isset($persons_id[$husb])) ? $persons_id[$husb] : 0; |
| 61 | + $wife_id = (isset($persons_id[$wife])) ? $persons_id[$wife] : 0; |
| 62 | + |
| 63 | + $family = Family::on($conn)->updateOrCreate( |
| 64 | + compact('husband_id', 'wife_id'), |
| 65 | + compact('husband_id', 'wife_id', 'description', 'type_id', 'nchi', 'rin') |
| 66 | + ); |
| 67 | + |
| 68 | + if ($children !== null) { |
| 69 | + foreach ($children as $child) { |
| 70 | + if (isset($persons_id[$child])) { |
| 71 | + $person = Person::on($conn)->find($persons_id[$child]); |
| 72 | + $person->child_in_family_id = $family->id; |
| 73 | + $person->save(); |
| 74 | + } |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + if ($events !== null && count($events) > 0) { |
| 79 | + foreach ($events as $item) { |
| 80 | + if ($item) { |
| 81 | + Even::read($conn, $item, $family, $obje_ids); |
| 82 | + } |
| 83 | + // $date = $getDate($item->getDate()); |
| 84 | + // $place = $getPlace($item->getPlac()); |
| 85 | + // $family->addEvent($item->getType(), $date, $place); |
| 86 | + } |
| 87 | + } |
| 88 | + $_group = 'fam'; |
| 89 | + $_gid = $family->id; |
| 90 | + if ($_note != null && count($_note) > 0) { |
| 91 | + foreach ($_note as $item) { |
| 92 | + NoteRef::read($conn, $item, $_group, $_gid); |
| 93 | + } |
| 94 | + } |
| 95 | + if ($_obje && count($_obje) > 0) { |
| 96 | + foreach ($_obje as $item) { |
| 97 | + if ($item) { |
| 98 | + ObjeRef::read($conn, $item, $_group, $_gid, $obje_ids); |
| 99 | + } |
| 100 | + } |
| 101 | + } |
| 102 | + if ($_refn && count($_refn) > 0) { |
| 103 | + foreach ($_refn as $item) { |
| 104 | + if ($item) { |
| 105 | + Refn::read($conn, $item, $_group, $_gid); |
| 106 | + } |
| 107 | + } |
| 108 | + } |
| 109 | + if ($_sour && count($_sour) > 0) { |
| 110 | + foreach ($_sour as $item) { |
| 111 | + if ($item) { |
| 112 | + SourRef::read($conn, $item, $_group, $_gid, $sour_ids, $obje_ids); |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + if ($_slgs && count($_slgs) > 0) { |
| 117 | + foreach ($_slgs as $item) { |
| 118 | + if ($item) { |
| 119 | + Slgs::read($conn, $item, $family); |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + if ($subm && count($subm) > 0) { |
| 124 | + foreach ($subm as $item) { |
| 125 | + if ($item) { |
| 126 | + Subm::read($conn, $item, $_group, $_gid, $obje_ids); |
| 127 | + } |
| 128 | + } |
| 129 | + } |
| 130 | + if ($chan) { |
| 131 | + Chan::read($conn, $chan, 'family', $family->id); |
| 132 | + } |
| 133 | + } |
| 134 | +} |
0 commit comments