Skip to content

Commit

Permalink
Merge pull request #69 from Next-ReactSuperStar/master
Browse files Browse the repository at this point in the history
working in exporte
  • Loading branch information
curtisdelicata authored Jan 16, 2022
2 parents 5189e1e + 2dd2675 commit 6f3564d
Show file tree
Hide file tree
Showing 36 changed files with 2,149 additions and 0 deletions.
92 changes: 92 additions & 0 deletions src/Commands/GedcomExporter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace FamilyTree365\LaravelGedcom\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use FamilyTree365\LaravelGedcom\Models\Person;
use FamilyTree365\LaravelGedcom\Models\Subm;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;

class GedcomExporter extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'gedcom:export {filename}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Export database data into a GEDCOM file format';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}

/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{

$dir = 'public/gedcom/exported';

$filename = $this->argument('filename').".GED";

$file_path = $dir . '/' . $filename;

if (!file_exists($dir)) {
Storage::makeDirectory($dir);
}

$query = DB::table('subms');
$query->join('addrs', 'addrs.id', '=', 'subms.addr_id');
$query->select([
'subms.name',
'addrs.adr1',
'addrs.adr2',
'addrs.city',
'addrs.stae',
'addrs.post',
'addrs.ctry',
'subms.phon',
])->get();

$people = Person::all();
$submissions = $query->get();

$data =array (
'submissions' => $submissions,
'people' => $people,
);

$source = View::make('stubs.ged', $data)->render();

$ged_doc = "HEAD \nGEDC \nVERS 5.5.5 \nFORM LINEAGE-LINKED \nVERS 5.5.5 \nCHAR UTF-8 \nSOUR GS \nVERS 5.5.5 \nCORP gedcom.org\n";

$handle = fopen($filename, 'w');

fputs($handle, $ged_doc.$source);

fclose($handle);

$headers = array(
'Content-Type' => 'text/ged',
);

}
}
13 changes: 13 additions & 0 deletions src/Facades/GedcomExpFacade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace FamilyTree365\LaravelGedcom\Facades;

use Illuminate\Support\Facades\Facade;

class GedcomParserFacade extends Facade
{
protected static function getFacadeAccessor()
{
return 'FamilyTree365/laravel-gedcom:expo';
}
}
45 changes: 45 additions & 0 deletions src/Utils/exporter/Addr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace FamilyTree365\LaravelGedcom\Utils\Importer;

use FamilyTree365\LaravelGedcom\Models\Addr as MAddr;

class Addr
{
/**
* Gedcom\Record\Refn $noteref
* String $group
* Integer $group_id.
*/
public static function read($conn, $addr)
{
$id = null;
if ($addr == null) {
return $id;
}
$adr1 = $addr->getAdr1();
$adr2 = $addr->getAdr2();
$city = $addr->getCity();
$stae = $addr->getStae();
$post = $addr->getPost();
$ctry = $addr->getCtry();

$addr = MAddr::on($conn)->where([
['adr1', '=', $adr1],
['adr2', '=', $adr2],
['city', '=', $city],

['stae', '=', $stae],
['post', '=', $post],
['ctry', '=', $ctry],
])->first();
if ($addr !== null) {
$id = $addr->id;
} else {
$addr = MAddr::on($conn)->create(compact('adr1', 'adr2', 'city', 'stae', 'post', 'ctry'));
$id = $addr->id;
}

return $id;
}
}
32 changes: 32 additions & 0 deletions src/Utils/exporter/Caln.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace FamilyTree365\LaravelGedcom\Utils\Importer;

class Caln
{
/**
* Gedcom\Record\Caln $caln
* String $group
* Integer $group_id.
*/
public static function read($conn, $caln, $group = null, $gid = null)
{
if ($caln == null || is_array($caln)) {
return;
}

$medi = $addr->getMedi();

$key = [
'group'=> $group,
'gid' => $gid,
'medi' => $medi,
];
$data = [
'group'=> $group,
'gid' => $gid,
'medi' => $medi,
];
$_caln = MCaln::on($conn)->updateOrCreate($key, $data);
}
}
37 changes: 37 additions & 0 deletions src/Utils/exporter/Chan.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace FamilyTree365\LaravelGedcom\Utils\Importer;

use FamilyTree365\LaravelGedcom\Models\Chan as MChan;

class Chan
{
/**
* Gedcom\Record\Chan $chan
* String $group
* Integer $group_id.
*/
public static function read($conn, \Gedcom\Record\Chan $chan, $group = '', $group_id = 0)
{
$date = $chan->getDate();
$time = $chan->getTime();

// store chan
$key = ['group'=>$group, 'gid'=>$group_id, 'date'=>$date, 'time'=>$time];
$data = ['group'=>$group, 'gid'=>$group_id, 'date'=>$date, 'time'=>$time];
$record = MChan::on($conn)->updateOrCreate($key, $data);

// store Sources of Note
$_group = 'chan';
$_gid = $record->id;
// SourRef array
$note = $chan->getNote();
if ($note && count($note) > 0) {
foreach ($note as $item) {
if ($item) {
NoteRef::read($conn, $item, $_group, $_gid);
}
}
}
}
}
27 changes: 27 additions & 0 deletions src/Utils/exporter/Date.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace FamilyTree365\LaravelGedcom\Utils\Importer;

use Carbon\Carbon;

class Date
{
/**
* Array of persons ID
* key - old GEDCOM ID
* value - new autoincrement ID.
*
* @var string
*/
public static function read($conn, $input_date)
{
if (is_object($input_date)) {
if (method_exists($input_date, 'getDate')) {
return $input_date->getDate();
}
} else {
// $input_date = Carbon::parse($input_date)->timestamp;
return "$input_date";
}
}
}
Loading

0 comments on commit 6f3564d

Please sign in to comment.