-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGenealogy_Gedcom.php
247 lines (234 loc) · 6.38 KB
/
Genealogy_Gedcom.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<?php
/**
* Genealogy_Gedcom
*
* PHP Versions 4 and 5
*
* @category Genealogy
* @package Genealogy_Gedcom
* @author Olivier Vanhoucke <[email protected]>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version CVS: $Id$
* @link http://pear.php.net/package/Genealogy_Gedcom
*/
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP Version 4 |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.02 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | [email protected] so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Olivier Vanhoucke <[email protected]> |
// +----------------------------------------------------------------------+
//
// $Id$
//
require_once 'Gedcom/Parser.php';
/**
* Genealogy_Gedcom
*
* Example:
*
* require_once 'Genealogy/Gedcom.php';
* $ged =& new Genealogy_Gedcom('test.ged');
*
* echo 'Number of individuals : '. $ged->getNumberOfIndividuals().'<br>';
* echo 'Number of families : '. $ged->getNumberOfFamilies(). '<br>';
* echo 'Number of objects :' . $ged->getNumberOfObjects(). '<br>';
* echo 'Last Update :'. $ged->getLastUpdate(). '<br>';
* echo '<br>';
*
* echo '<pre>';
* print_r($ged->GedcomIndividualsTreeObjects);
* print_r($ged->GedcomFamiliesTreeObjects);
* print_r($ged->GedcomObjectsTreeObjects);
* print_r($ged->GedcomHeaderTreeObject);
* print_r($ged->getIndividual('I1'));
* print_r($ged->getFamily('F1'));
* print_r($ged->getObject('O1'));
* echo '</pre>';
*
* display all firstname and lastname of individuals
*
* foreach ($ged->GedcomIndividualsTreeObjects as $obj) {
* echo $obj->Firstname.' '.$obj->Lastname.'<br>';
* }
*
* Contributors:
*
* @category Genealogy
* @package Genealogy_Gedcom
* @author Olivier Vanhoucke <[email protected]>
* @license http://www.php.net/license/3_01.txt PHP License 3.0.1
* @version Release: @PACKAGE_VERSION@
* @access public
* @link http://pear.php.net/package/Genealogy_Gedcom
*/
class Genealogy_Gedcom extends Genealogy_Parser
{
/**
* Constructor
*
* Creates a new Genealogy_Gedcom Object
*
* @param string $filename Gedcom filename
*
* @access public
* @return object Genealogy_Gedcom the new Genealogy_Gedcom object
*/
function Genealogy_Gedcom($filename)
{
$this->_GedcomFile = $filename;
parent::parse();
}
/**
* return the number of individual
*
* @access public
* @return integer
*/
function getNumberOfIndividuals()
{
return count($this->_GedcomIndividualsTree);
}
/**
* return the number of family
*
* @access public
* @return integer
*/
function getNumberOfFamilies()
{
return count($this->_GedcomFamiliesTree);
}
/**
* return the number of object
*
* @access public
* @return integer
*/
function getNumberOfObjects()
{
return count($this->_GedcomObjectsTree);
}
/**
* return the last update
*
* @access public
* @return string
*/
function getLastUpdate()
{
return $this->GedcomHeaderTreeObject->Date;
}
/**
* Get an Individual (object) from an identifier
*
* @param string $identifier Identifier
*
* @access public
* @return mixed object or boolean (error)
*/
function getIndividual($identifier)
{
foreach ($this->GedcomIndividualsTreeObjects as $obj) {
if ($obj->Identifier == $identifier) {
return $obj;
}
}
return false;
}
/**
* Get a family (object) from an identifier
*
* @param string $identifier Identifier
*
* @access public
* @return mixed object or false on error.
*/
function getFamily($identifier)
{
foreach ($this->GedcomFamiliesTreeObjects as $obj) {
if ($obj->Identifier == $identifier) {
return $obj;
}
}
return false;
}
/**
* Get an object (object) from an identifier
*
* @param string $identifier Identifier
*
* @access public
* @return mixed object or false on error.
*/
function getObject($identifier)
{
foreach ($this->GedcomObjectsTreeObjects as $obj) {
if ($obj->Identifier == $identifier) {
return $obj;
}
}
return false;
}
/**
* test if an individual exists
*
* @param string $identifier Identifier
*
* @access public
* @return boolean
*/
function isIndividual($identifier)
{
foreach ($this->GedcomIndividualsTreeObjects as $obj) {
if ($obj->Identifier == $identifier) {
return true;
}
}
return false;
}
/**
* test if a family exists
*
* @param string $identifier Identifier
*
* @access public
* @return boolean
*/
function isFamily($identifier)
{
foreach ($this->GedcomFamiliesTreeObjects as $obj) {
if ($obj->Identifier == $identifier) {
return true;
}
}
return false;
}
/**
* test if an object exists
*
* @param string $identifier Identifier
*
* @access public
* @return boolean
*/
function isObject($identifier)
{
foreach ($this->GedcomObjectsTreeObjects as $obj) {
if ($obj->Identifier == $identifier) {
return true;
}
}
return false;
}
}
?>