|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace FamilyTree365\LaravelGedcom\Utils\Exporter; |
|
4
|
|
|
|
|
5
|
|
|
use FamilyTree365\LaravelGedcom\Models\Repository; |
|
6
|
|
|
|
|
7
|
|
|
class Repo |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Gedcom\Record\Repo $repo |
|
11
|
|
|
* String $group |
|
12
|
|
|
* Integer $group_id. |
|
13
|
|
|
*/ |
|
14
|
|
|
public static function read($conn, \Gedcom\Record\Repo $repo, $group = '', $group_id = 0) |
|
15
|
|
|
{ |
|
16
|
|
|
if ($repo == null) { |
|
17
|
|
|
return; |
|
18
|
|
|
} |
|
19
|
|
|
$name = $repo->getName(); // string |
|
20
|
|
|
$rin = $repo->getRin(); // string |
|
21
|
|
|
$addr = $repo->getAddr(); // Record/Addr |
|
22
|
|
|
$addr_id = \FamilyTree365\LaravelGedcom\Utils\Importer\Addr::read($conn, $addr); |
|
23
|
|
|
$_phon = $repo->getPhon(); // Record/Phon array |
|
24
|
|
|
$phon = implode(',', $_phon); |
|
25
|
|
|
$_email = $repo->getEmail(); |
|
26
|
|
|
$email = implode(',', $_email); |
|
27
|
|
|
$_fax = $repo->getFax(); |
|
28
|
|
|
$fax = implode(',', $_fax); |
|
29
|
|
|
$_www = $repo->getWww(); |
|
30
|
|
|
$www = implode(',', $_www); |
|
31
|
|
|
// store Source |
|
32
|
|
|
$key = [ |
|
33
|
|
|
'group' => $group, |
|
34
|
|
|
'gid' => $group_id, |
|
35
|
|
|
'name' => $name, |
|
36
|
|
|
'rin' => $rin, |
|
37
|
|
|
'addr_id' => $addr_id, |
|
38
|
|
|
'phon' => $phon, |
|
39
|
|
|
'email' => $email, |
|
40
|
|
|
'fax' => $fax, |
|
41
|
|
|
'www' => $www, |
|
42
|
|
|
]; |
|
43
|
|
|
$data = [ |
|
44
|
|
|
'group' => $group, |
|
45
|
|
|
'gid' => $group_id, |
|
46
|
|
|
'name' => $name, |
|
47
|
|
|
'rin' => $rin, |
|
48
|
|
|
'addr_id' => $addr_id, |
|
49
|
|
|
'phon' => $phon, |
|
50
|
|
|
'email' => $email, |
|
51
|
|
|
'fax' => $fax, |
|
52
|
|
|
'www' => $www, |
|
53
|
|
|
]; |
|
54
|
|
|
|
|
55
|
|
|
$record = Repository::on($conn)->updateOrCreate($key, $data); |
|
56
|
|
|
|
|
57
|
|
|
$_group = 'repo'; |
|
58
|
|
|
$_gid = $record->id; |
|
59
|
|
|
// store Note |
|
60
|
|
|
$note = $repo->getNote(); // Record/NoteRef array |
|
61
|
|
|
if ($note && count($note) > 0) { |
|
|
|
|
|
|
62
|
|
|
foreach ($note as $item) { |
|
63
|
|
|
NoteRef::read($conn, $item, $_group, $_gid); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
$refn = $repo->getRefn(); // Record/Refn array |
|
67
|
|
|
if ($refn && count($refn) > 0) { |
|
|
|
|
|
|
68
|
|
|
foreach ($refn as $item) { |
|
69
|
|
|
Refn::read($conn, $item, $_group, $_gid); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
$chan = $repo->getChan(); // Recore/Chan |
|
74
|
|
|
if ($chan !== null) { |
|
75
|
|
|
\FamilyTree365\LaravelGedcom\Utils\Importer\Chan::read($conn, $chan, $_group, $_gid); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $_gid; |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.