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