forked from agjmills/laravel-gedcom
-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from Next-ReactSuperStar/master
working in exporte
- Loading branch information
Showing
36 changed files
with
2,149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
} | ||
} |
Oops, something went wrong.