@@ -12,34 +12,34 @@ discard block |
||
| 12 | 12 | class GedcomController extends Controller |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /* |
|
| 15 | + /* |
|
| 16 | 16 | * Api end-point for Gedcom api/gedcom/store |
| 17 | 17 | * Saving uploaded file to storage and starting to read |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | - public function store(Request $request) |
|
| 21 | - { |
|
| 20 | + public function store(Request $request) |
|
| 21 | + { |
|
| 22 | 22 | if($request->hasFile('file')){ |
| 23 | - if ($request->file('file')->isValid()) { |
|
| 23 | + if ($request->file('file')->isValid()) { |
|
| 24 | 24 | $request->file->storeAs('gedcom', 'file.ged'); |
| 25 | 25 | $this->readData(); |
| 26 | 26 | return ['File uploaded']; |
| 27 | - } |
|
| 28 | - return ['File corrupted']; |
|
| 27 | + } |
|
| 28 | + return ['File corrupted']; |
|
| 29 | 29 | } |
| 30 | 30 | return ['Not uploaded']; |
| 31 | - } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - /* |
|
| 33 | + /* |
|
| 34 | 34 | * Read ged file |
| 35 | 35 | */ |
| 36 | 36 | |
| 37 | - protected $persons_id = array(); |
|
| 38 | - protected $list = array(); |
|
| 39 | - protected $familylist = array(); |
|
| 37 | + protected $persons_id = array(); |
|
| 38 | + protected $list = array(); |
|
| 39 | + protected $familylist = array(); |
|
| 40 | 40 | |
| 41 | - private function readData() |
|
| 42 | - { |
|
| 41 | + private function readData() |
|
| 42 | + { |
|
| 43 | 43 | $parser = new \PhpGedcom\Parser(); |
| 44 | 44 | $gedcom = $parser->parse(storage_path('app/gedcom/file.ged')); |
| 45 | 45 | |
@@ -51,114 +51,114 @@ discard block |
||
| 51 | 51 | foreach ($families as $family) { |
| 52 | 52 | $this->get_Family($family); |
| 53 | 53 | } |
| 54 | - } |
|
| 55 | - |
|
| 56 | - private function get_Person($individual){ |
|
| 57 | - $g_id = $individual->getId(); |
|
| 58 | - $surn = current($individual->getName())->getSurn(); |
|
| 59 | - $givn = current($individual->getName())->getGivn(); |
|
| 60 | - $name = current($individual->getName())->getName(); |
|
| 61 | - $sex = $individual->getSex(); |
|
| 62 | - $attr = $individual->getAttr(); |
|
| 63 | - $events = $individual->getEven(); |
|
| 64 | - $media = $individual->getObje(); |
|
| 65 | - |
|
| 66 | - if($givn == "") { |
|
| 67 | - $givn = $name; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $sex = $sex === 'F' ? 'female' : 'male'; |
|
| 71 | - $surn = isset($surn) ? $surn : 'No Surname'; |
|
| 72 | - |
|
| 73 | - foreach($events as $event){ |
|
| 74 | - $date = $this->get_date($event->getDate()); |
|
| 75 | - $place = $this->get_place($event->getPlac()); |
|
| 76 | - if(isset($date) || isset($place)){ |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + private function get_Person($individual){ |
|
| 57 | + $g_id = $individual->getId(); |
|
| 58 | + $surn = current($individual->getName())->getSurn(); |
|
| 59 | + $givn = current($individual->getName())->getGivn(); |
|
| 60 | + $name = current($individual->getName())->getName(); |
|
| 61 | + $sex = $individual->getSex(); |
|
| 62 | + $attr = $individual->getAttr(); |
|
| 63 | + $events = $individual->getEven(); |
|
| 64 | + $media = $individual->getObje(); |
|
| 65 | + |
|
| 66 | + if($givn == "") { |
|
| 67 | + $givn = $name; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $sex = $sex === 'F' ? 'female' : 'male'; |
|
| 71 | + $surn = isset($surn) ? $surn : 'No Surname'; |
|
| 72 | + |
|
| 73 | + foreach($events as $event){ |
|
| 74 | + $date = $this->get_date($event->getDate()); |
|
| 75 | + $place = $this->get_place($event->getPlac()); |
|
| 76 | + if(isset($date) || isset($place)){ |
|
| 77 | 77 | $place = isset($place) ? $place : 'No place'; |
| 78 | 78 | Event::create([ |
| 79 | - 'event_type' => 'App\Individual', |
|
| 80 | - 'event_date' => $date, |
|
| 81 | - 'event_id' => 1, |
|
| 82 | - 'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 83 | - 'description' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 84 | - 'event_type_id' => 1 |
|
| 79 | + 'event_type' => 'App\Individual', |
|
| 80 | + 'event_date' => $date, |
|
| 81 | + 'event_id' => 1, |
|
| 82 | + 'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 83 | + 'description' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 84 | + 'event_type_id' => 1 |
|
| 85 | 85 | ]); |
| 86 | - } |
|
| 87 | - }; |
|
| 88 | - |
|
| 89 | - foreach($attr as $event){ |
|
| 90 | - $date = $this->get_date($event->getDate()); |
|
| 91 | - $place = $this->get_place($event->getPlac()); |
|
| 92 | - if(count($event->getNote())>0){ |
|
| 93 | - $note = current($event->getNote())->getNote(); |
|
| 94 | - } |
|
| 95 | - else{ |
|
| 96 | - $note = ''; |
|
| 97 | - } |
|
| 98 | - if(isset($date) || isset($place)){ |
|
| 86 | + } |
|
| 87 | + }; |
|
| 88 | + |
|
| 89 | + foreach($attr as $event){ |
|
| 90 | + $date = $this->get_date($event->getDate()); |
|
| 91 | + $place = $this->get_place($event->getPlac()); |
|
| 92 | + if(count($event->getNote())>0){ |
|
| 93 | + $note = current($event->getNote())->getNote(); |
|
| 94 | + } |
|
| 95 | + else{ |
|
| 96 | + $note = ''; |
|
| 97 | + } |
|
| 98 | + if(isset($date) || isset($place)){ |
|
| 99 | 99 | $place = isset($place) ? $place : 'No place'; |
| 100 | 100 | Note::create([ |
| 101 | - 'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 102 | - 'date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'), |
|
| 103 | - 'description' => mb_convert_encoding($note, 'UTF-8', 'UTF-8'), |
|
| 101 | + 'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 102 | + 'date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'), |
|
| 103 | + 'description' => mb_convert_encoding($note, 'UTF-8', 'UTF-8'), |
|
| 104 | 104 | ]); |
| 105 | - } |
|
| 106 | - }; |
|
| 107 | - foreach ($media as $mediafile){ |
|
| 108 | - $title = $mediafile->getTitl(); |
|
| 109 | - $file = $mediafile->getFile(); |
|
| 110 | - if(isset($title) || isset($file)){ |
|
| 105 | + } |
|
| 106 | + }; |
|
| 107 | + foreach ($media as $mediafile){ |
|
| 108 | + $title = $mediafile->getTitl(); |
|
| 109 | + $file = $mediafile->getFile(); |
|
| 110 | + if(isset($title) || isset($file)){ |
|
| 111 | 111 | Note::create([ |
| 112 | - 'name' => mb_convert_encoding($title, 'UTF-8', 'UTF-8'), |
|
| 113 | - 'description' => mb_convert_encoding($file, 'UTF-8', 'UTF-8') |
|
| 112 | + 'name' => mb_convert_encoding($title, 'UTF-8', 'UTF-8'), |
|
| 113 | + 'description' => mb_convert_encoding($file, 'UTF-8', 'UTF-8') |
|
| 114 | 114 | ]); |
| 115 | - } |
|
| 116 | - }; |
|
| 117 | - Individual::create([ |
|
| 115 | + } |
|
| 116 | + }; |
|
| 117 | + Individual::create([ |
|
| 118 | 118 | 'first_name' => $name, |
| 119 | 119 | 'last_name' => $surn, |
| 120 | 120 | 'gender' => $sex, |
| 121 | 121 | 'is_active' => false |
| 122 | - ]); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - private function get_Family($family){ |
|
| 126 | - $g_id = $family->getId() ; |
|
| 127 | - $husb = $family->getHusb(); |
|
| 128 | - $wife = $family->getWife(); |
|
| 129 | - $children = $family->getChil(); |
|
| 130 | - $events =$family->getEven(); |
|
| 131 | - $husband_id = (isset($this->persons_id[$husb])) ? $this->persons_id[$husb]: 0; |
|
| 132 | - $wife_id = (isset($this->persons_id[$wife])) ? $this->persons_id[$wife]: 0; |
|
| 133 | - |
|
| 134 | - Family::create([ |
|
| 122 | + ]); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + private function get_Family($family){ |
|
| 126 | + $g_id = $family->getId() ; |
|
| 127 | + $husb = $family->getHusb(); |
|
| 128 | + $wife = $family->getWife(); |
|
| 129 | + $children = $family->getChil(); |
|
| 130 | + $events =$family->getEven(); |
|
| 131 | + $husband_id = (isset($this->persons_id[$husb])) ? $this->persons_id[$husb]: 0; |
|
| 132 | + $wife_id = (isset($this->persons_id[$wife])) ? $this->persons_id[$wife]: 0; |
|
| 133 | + |
|
| 134 | + Family::create([ |
|
| 135 | 135 | 'father_id' => rand(1,100), |
| 136 | 136 | 'mother_id' => rand(1,100), |
| 137 | 137 | 'description' => $g_id . ' family', |
| 138 | 138 | 'type_id' => 1 |
| 139 | - ]); //father and mother id should be gedcom(string) type, not integer |
|
| 140 | - |
|
| 141 | - foreach($children as $child){ |
|
| 142 | - if (isset($this->persons_id[$child])){ |
|
| 143 | - $individual = Individual::find($this->persons_id[$child]); |
|
| 144 | - $individual->children()->save($individual); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - foreach ($events as $event){ |
|
| 148 | - $date = $this->get_date($event->getDate()); |
|
| 149 | - $place = $this->get_place($event->getPlac()); |
|
| 150 | - if(isset($date) || isset($place)){ |
|
| 139 | + ]); //father and mother id should be gedcom(string) type, not integer |
|
| 140 | + |
|
| 141 | + foreach($children as $child){ |
|
| 142 | + if (isset($this->persons_id[$child])){ |
|
| 143 | + $individual = Individual::find($this->persons_id[$child]); |
|
| 144 | + $individual->children()->save($individual); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + foreach ($events as $event){ |
|
| 148 | + $date = $this->get_date($event->getDate()); |
|
| 149 | + $place = $this->get_place($event->getPlac()); |
|
| 150 | + if(isset($date) || isset($place)){ |
|
| 151 | 151 | $place = isset($place) ? $place : 'No place'; |
| 152 | 152 | Event::create([ |
| 153 | - 'event_type' => 'App\Family', |
|
| 154 | - 'event_date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'), |
|
| 155 | - 'event_id' => 1, |
|
| 156 | - 'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 157 | - 'description' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 158 | - 'event_type_id' => 1 |
|
| 153 | + 'event_type' => 'App\Family', |
|
| 154 | + 'event_date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'), |
|
| 155 | + 'event_id' => 1, |
|
| 156 | + 'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 157 | + 'description' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
|
| 158 | + 'event_type_id' => 1 |
|
| 159 | 159 | ]); |
| 160 | - } |
|
| 161 | - }; |
|
| 160 | + } |
|
| 161 | + }; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | private function get_date($input_date){ |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public function store(Request $request) |
| 21 | 21 | { |
| 22 | - if($request->hasFile('file')){ |
|
| 22 | + if ($request->hasFile('file')) { |
|
| 23 | 23 | if ($request->file('file')->isValid()) { |
| 24 | 24 | $request->file->storeAs('gedcom', 'file.ged'); |
| 25 | 25 | $this->readData(); |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - private function get_Person($individual){ |
|
| 56 | + private function get_Person($individual) { |
|
| 57 | 57 | $g_id = $individual->getId(); |
| 58 | 58 | $surn = current($individual->getName())->getSurn(); |
| 59 | 59 | $givn = current($individual->getName())->getGivn(); |
@@ -63,17 +63,17 @@ discard block |
||
| 63 | 63 | $events = $individual->getEven(); |
| 64 | 64 | $media = $individual->getObje(); |
| 65 | 65 | |
| 66 | - if($givn == "") { |
|
| 66 | + if ($givn == "") { |
|
| 67 | 67 | $givn = $name; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | $sex = $sex === 'F' ? 'female' : 'male'; |
| 71 | 71 | $surn = isset($surn) ? $surn : 'No Surname'; |
| 72 | 72 | |
| 73 | - foreach($events as $event){ |
|
| 73 | + foreach ($events as $event) { |
|
| 74 | 74 | $date = $this->get_date($event->getDate()); |
| 75 | 75 | $place = $this->get_place($event->getPlac()); |
| 76 | - if(isset($date) || isset($place)){ |
|
| 76 | + if (isset($date) || isset($place)) { |
|
| 77 | 77 | $place = isset($place) ? $place : 'No place'; |
| 78 | 78 | Event::create([ |
| 79 | 79 | 'event_type' => 'App\Individual', |
@@ -86,16 +86,16 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | }; |
| 88 | 88 | |
| 89 | - foreach($attr as $event){ |
|
| 89 | + foreach ($attr as $event) { |
|
| 90 | 90 | $date = $this->get_date($event->getDate()); |
| 91 | 91 | $place = $this->get_place($event->getPlac()); |
| 92 | - if(count($event->getNote())>0){ |
|
| 92 | + if (count($event->getNote()) > 0) { |
|
| 93 | 93 | $note = current($event->getNote())->getNote(); |
| 94 | 94 | } |
| 95 | - else{ |
|
| 95 | + else { |
|
| 96 | 96 | $note = ''; |
| 97 | 97 | } |
| 98 | - if(isset($date) || isset($place)){ |
|
| 98 | + if (isset($date) || isset($place)) { |
|
| 99 | 99 | $place = isset($place) ? $place : 'No place'; |
| 100 | 100 | Note::create([ |
| 101 | 101 | 'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'), |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | ]); |
| 105 | 105 | } |
| 106 | 106 | }; |
| 107 | - foreach ($media as $mediafile){ |
|
| 107 | + foreach ($media as $mediafile) { |
|
| 108 | 108 | $title = $mediafile->getTitl(); |
| 109 | 109 | $file = $mediafile->getFile(); |
| 110 | - if(isset($title) || isset($file)){ |
|
| 110 | + if (isset($title) || isset($file)) { |
|
| 111 | 111 | Note::create([ |
| 112 | 112 | 'name' => mb_convert_encoding($title, 'UTF-8', 'UTF-8'), |
| 113 | 113 | 'description' => mb_convert_encoding($file, 'UTF-8', 'UTF-8') |
@@ -122,32 +122,32 @@ discard block |
||
| 122 | 122 | ]); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - private function get_Family($family){ |
|
| 126 | - $g_id = $family->getId() ; |
|
| 125 | + private function get_Family($family) { |
|
| 126 | + $g_id = $family->getId(); |
|
| 127 | 127 | $husb = $family->getHusb(); |
| 128 | 128 | $wife = $family->getWife(); |
| 129 | 129 | $children = $family->getChil(); |
| 130 | - $events =$family->getEven(); |
|
| 131 | - $husband_id = (isset($this->persons_id[$husb])) ? $this->persons_id[$husb]: 0; |
|
| 132 | - $wife_id = (isset($this->persons_id[$wife])) ? $this->persons_id[$wife]: 0; |
|
| 130 | + $events = $family->getEven(); |
|
| 131 | + $husband_id = (isset($this->persons_id[$husb])) ? $this->persons_id[$husb] : 0; |
|
| 132 | + $wife_id = (isset($this->persons_id[$wife])) ? $this->persons_id[$wife] : 0; |
|
| 133 | 133 | |
| 134 | 134 | Family::create([ |
| 135 | - 'father_id' => rand(1,100), |
|
| 136 | - 'mother_id' => rand(1,100), |
|
| 137 | - 'description' => $g_id . ' family', |
|
| 135 | + 'father_id' => rand(1, 100), |
|
| 136 | + 'mother_id' => rand(1, 100), |
|
| 137 | + 'description' => $g_id.' family', |
|
| 138 | 138 | 'type_id' => 1 |
| 139 | 139 | ]); //father and mother id should be gedcom(string) type, not integer |
| 140 | 140 | |
| 141 | - foreach($children as $child){ |
|
| 142 | - if (isset($this->persons_id[$child])){ |
|
| 141 | + foreach ($children as $child) { |
|
| 142 | + if (isset($this->persons_id[$child])) { |
|
| 143 | 143 | $individual = Individual::find($this->persons_id[$child]); |
| 144 | 144 | $individual->children()->save($individual); |
| 145 | 145 | } |
| 146 | 146 | } |
| 147 | - foreach ($events as $event){ |
|
| 147 | + foreach ($events as $event) { |
|
| 148 | 148 | $date = $this->get_date($event->getDate()); |
| 149 | 149 | $place = $this->get_place($event->getPlac()); |
| 150 | - if(isset($date) || isset($place)){ |
|
| 150 | + if (isset($date) || isset($place)) { |
|
| 151 | 151 | $place = isset($place) ? $place : 'No place'; |
| 152 | 152 | Event::create([ |
| 153 | 153 | 'event_type' => 'App\Family', |
@@ -161,12 +161,12 @@ discard block |
||
| 161 | 161 | }; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - private function get_date($input_date){ |
|
| 164 | + private function get_date($input_date) { |
|
| 165 | 165 | return "$input_date"; |
| 166 | 166 | } |
| 167 | 167 | |
| 168 | - private function get_place($place){ |
|
| 169 | - if(is_object($place)){ |
|
| 168 | + private function get_place($place) { |
|
| 169 | + if (is_object($place)) { |
|
| 170 | 170 | $place = $place->getPlac(); |
| 171 | 171 | } |
| 172 | 172 | return $place; |
@@ -91,8 +91,7 @@ |
||
| 91 | 91 | $place = $this->get_place($event->getPlac()); |
| 92 | 92 | if(count($event->getNote())>0){ |
| 93 | 93 | $note = current($event->getNote())->getNote(); |
| 94 | - } |
|
| 95 | - else{ |
|
| 94 | + } else{ |
|
| 96 | 95 | $note = ''; |
| 97 | 96 | } |
| 98 | 97 | if(isset($date) || isset($place)){ |