Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'master' into tree_api
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisdelicata authored Jun 28, 2018
2 parents cbf6804 + 7b789d4 commit 34fd30e
Show file tree
Hide file tree
Showing 164 changed files with 3,969 additions and 559 deletions.
15 changes: 11 additions & 4 deletions app/Family.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,18 @@ public function getIndividualListAttribute()
->pluck('individuals.id');
}

public function info(){
return $this->belongsTo(Individual::class,'father_id','id');
public function info()
{
return $this->belongsTo(Individual::class, 'father_id', 'id');
}

public function spouse(){
return $this->hasOne(Individual::class,'id','mother_id');
public function spouse()
{
return $this->hasOne(Individual::class, 'id', 'mother_id');
}

public function gedcom()
{
return $this->morphMany('App\Gedcom', 'gedcom');
}
}
16 changes: 16 additions & 0 deletions app/Gedcom.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Gedcom extends Model
{
protected $guarded = [];
public $timestamps = false;

public function gedcom()
{
$this->morphTo();
}
}
251 changes: 170 additions & 81 deletions app/Http/Controllers/Gedcom/GedcomController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Event;
use App\Family;
use App\Gedcom;
use App\Http\Controllers\Controller;
use App\Individual;
use App\Note;
Expand Down Expand Up @@ -36,134 +37,222 @@ public function store(Request $request)
* Read ged file
*/

protected $persons_id = [];
protected $list = [];
protected $familylist = [];

private function readData()
public function readData()
{
$parser = new \PhpGedcom\Parser();
$gedcom = $parser->parse(storage_path('app/gedcom/file.ged'));

$individuals = $gedcom->getIndi();
$families = $gedcom->getFam();
$sources = $gedcom->getSour();
$repositories = $gedcom->getRepo();

foreach ($individuals as $individual) {
$this->get_Person($individual);
$this->getIndividual($individual);
}
foreach ($families as $family) {
$this->get_Family($family);
$this->getFamily($family);
}

foreach ($sources as $source) {
$this->getSource($source);
}

foreach ($repositories as $repo) {
// echo "<pre>";
// print_r($repo);
// echo "</pre>";
}
}

private function get_Person($individual)
private function getIndividual($individual)
{
$g_id = $individual->getId();
$surn = current($individual->getName())->getSurn();
$givn = current($individual->getName())->getGivn();
$name = current($individual->getName())->getName();
$sex = $individual->getSex();
$attr = $individual->getAttr();
$events = $individual->getEven();
$media = $individual->getObje();

if ($givn == '') {
$givn = $name;
}
$g_id = preg_replace('/[^A-Za-z0-9\-]/', '', $individual->getId()); // Get individual id
$surn = preg_replace('/[^A-Za-z0-9\-]/', '', current($individual->getName())->getSurn()); // Get individual surname
$givn = preg_replace('/[^A-Za-z0-9\-]/', '', current($individual->getName())->getGivn()); // Get individual Givn
$name = preg_replace('/[^A-Za-z0-9\-]/', '', current($individual->getName())->getName()); // Get individual name
$sex = preg_replace('/[^A-Za-z0-9\-]/', '', $individual->getSex()); // Get individual sex
$attrs = $individual->getAttr(); // Get individual attributes
$events = $individual->getEven(); // Get individual events
$media = $individual->getObje(); // Get individual media
$notes = $individual->getNote(); // Get individual notes
$sources = $individual->getSour(); // Get individual sources

$givn = isset($givn) ? $givn : $name;
$sex = $sex == 'F' ? 'female' : 'male';

$sex = $sex === 'F' ? 'female' : 'male';
$surn = isset($surn) ? $surn : 'No Surname';
$ind = Individual::create([
'first_name' => mb_convert_encoding($givn, 'UTF-8', 'UTF-8'),
'last_name' => mb_convert_encoding($surn, 'UTF-8', 'UTF-8'),
'gender' => mb_convert_encoding($sex, 'UTF-8', 'UTF-8'),
'is_active' => true,
]);

Gedcom::create([
'g_id' => mb_convert_encoding($g_id, 'UTF-8', 'UTF-8'),
'gedcom_id' => $ind->id,
'gedcom_type' => 'App\Individual',
]);

foreach ($events as $event) {
$type = $event->getType(); // Example types "BIRT" "DEAT" "BURI" should be defined at db http://wiki-en.genealogy.net/GEDCOM-Tags
$date = $this->get_date($event->getDate());
$place = $this->get_place($event->getPlac());
if (isset($date) ||  isset($place)) {
$place = isset($place) ? $place : 'No place';
$place = isset($place) ? $place : 'Unknown Place';
$date = isset($date) ? $date : 'Unknown Date';
if ($type == 'BIRT') {
$eventname = $givn.' '.$surn.'\'s birth';
$eventdescription = $eventname.' at '.$date.' and '.$place;
Event::create([
'event_type' => 'App\Individual',
'event_date' => $date,
'event_id' => 1,
'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'),
'description' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'),
'event_type_id' => 1,
]);
'event_type' => 'App\Individual',
'event_id' => $ind->id,
'name' => mb_convert_encoding($eventname, 'UTF-8', 'UTF-8'),
'description' => mb_convert_encoding($eventdescription, 'UTF-8', 'UTF-8'),
'date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'),
'event_type_id' => 1,
'is_active' => true,
]);
}
if ($type == 'DEAT') {
$eventname = $givn.' '.$surn.'\'s death';
$eventdescription = $eventname.' at '.$date.' and '.$place;
Event::create([
'event_type' => 'App\Individual',
'event_id' => $ind->id,
'name' => mb_convert_encoding($eventname, 'UTF-8', 'UTF-8'),
'description' => mb_convert_encoding($eventdescription, 'UTF-8', 'UTF-8'),
'date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'),
'event_type_id' => 3,
'is_active' => true,
]);
}
}

foreach ($attr as $event) {
$date = $this->get_date($event->getDate());
$place = $this->get_place($event->getPlac());
if (count($event->getNote()) > 0) {
$note = current($event->getNote())->getNote();
foreach ($attrs as $attr) {
$attrtype = $attr->getType();
$att = $attr->getAttr();
$date = $this->get_date($attr->getDate());
$place = $this->get_place($attr->getPlac());
if (count($attr->getNote()) > 0) {
$note = current($attr->getNote())->getNote();
} else {
$note = '';
}
if (isset($date) ||  isset($place)) {
$place = isset($place) ? $place : 'No place';

if ($attrtype == 'TITL') {
$attrname = $givn.' '.$surn.'\'s title';
$attrdescription = $attrname.' was '.$att; // add to notes
$attrdescription = $note === '' ? $attrdescription : $attrdescription.' Note: '.$note;
Note::create([
'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'),
'date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'),
'description' => mb_convert_encoding($note, 'UTF-8', 'UTF-8'),
]);
'name' => mb_convert_encoding($attrname, 'UTF-8', 'UTF-8'),
'description' => mb_convert_encoding($attrdescription, 'UTF-8', 'UTF-8'),
'date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'),
'type_id' => 1,
'is_active' => true,
]);
}
}

foreach ($media as $mediafile) {
$title = $mediafile->getTitl();
$file = $mediafile->getFile();
if (isset($title) ||  isset($file)) {
Note::create([
'name' => mb_convert_encoding($title, 'UTF-8', 'UTF-8'),
'description' => mb_convert_encoding($file, 'UTF-8', 'UTF-8'),
]);
$file = isset($file) ? $file : 'not available';
if (isset($mediafile)) {
$medianame = $givn.' '.$surn.'\'s media title is'.$title.' file is'.$file;
}
}
Individual::create([
'first_name' => $name,
'last_name' => $surn,
'gender' => $sex,
'is_active' => false,
]);
}

private function get_Family($family)
private function getFamily($family)
{
$g_id = $family->getId();
$g_id = preg_replace('/[^A-Za-z0-9\-]/', '', $family->getId());
$husb = $family->getHusb();
$wife = $family->getWife();
$children = $family->getChil();
$childs = $family->getChil();
$events = $family->getEven();
$husband_id = (isset($this->persons_id[$husb])) ? $this->persons_id[$husb] : 0;
$wife_id = (isset($this->persons_id[$wife])) ? $this->persons_id[$wife] : 0;

Family::create([
'father_id' => rand(1, 100),
'mother_id' => rand(1, 100),
'description' => $g_id.' family',
'type_id' => 1,
]); //father and mother id should be gedcom(string) type, not integer

foreach ($children as $child) {
if (isset($this->persons_id[$child])) {
$individual = Individual::find($this->persons_id[$child]);
$individual->children()->save($individual);

$gFather = Gedcom::where('g_id', $husb)->first();
$gMother = Gedcom::where('g_id', $wife)->first();

if (isset($gFather->gedcom_id) && isset($gMother->gedcom_id)) {
$father = Individual::where('id', $gFather->gedcom_id)->first();
$mother = Individual::where('id', $gMother->gedcom_id)->first();

if (isset($father) && isset($mother)) {
$fName = "{$father->first_name} {$father->last_name}";
$mName = "{$mother->first_name} {$mother->last_name}";
} else {
$fName = 'Database error';
$mName = 'Database error';
}

$description = $fName.' and '.$mName.' family';
$fam = Family::create([
'father_id' => $father->id,
'mother_id' => $mother->id,
'type_id' => 1,
'description' => $description,
'is_active' => true,
]);

Gedcom::create([
'g_id' => $g_id,
'gedcom_id' => $fam->id,
'gedcom_type' => 'App\Family',
]);

$fam->individuals()->save($father, ['type_id' => 1]);

$fam->individuals()->save($mother, ['type_id' => 2]);

foreach ($childs as $child) {
if (isset($child)) {
$childId = Gedcom::where('g_id', $child)->first();
if ($childId) {
$childInd = Individual::where('id', $childId->gedcom_id)->first();
}

if ($childInd) {
$childInd->families()->save($fam, ['type_id' => 0]);
}
}
}
}

foreach ($events as $event) {
$eventtype = $event->getType();
$date = $this->get_date($event->getDate());
$place = $this->get_place($event->getPlac());
if (isset($date) ||  isset($place)) {
$place = isset($place) ? $place : 'No place';
Event::create([
'event_type' => 'App\Family',
'date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'),
'event_id' => 1,
'name' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'),
'description' => mb_convert_encoding($place, 'UTF-8', 'UTF-8'),
'event_type_id' => 1,
]);
$date = isset($date) ? $date : 'Unknown';
if ($eventtype == 'MARR') {
$name = 'Marriage of '.$fName.' and '.$mName;
$description = $fName.' and '.$mName.' are married at '.$date;
if (isset($fam)) {
Event::create([
'event_type' => 'App\Family',
'event_id' => $fam->id,
'name' => $name,
'description' => $description,
'date' => mb_convert_encoding($date, 'UTF-8', 'UTF-8'),
'event_type_id' => 2,
'is_active' => false,
]);
}
}
}
}

private function getSource($source)
{
$g_id = $source->getId();
$title = $source->getTitl();
$author = $source->getAuth();
$publication = $source->getPubl();
$repo = $source->getRepo();

$name = $title;
$description = $title.' source belongs to '.$author;
}

private function get_date($input_date)
{
return "$input_date";
Expand Down
Loading

0 comments on commit 34fd30e

Please sign in to comment.