|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* php-gedcom. |
|
4
|
|
|
* |
|
5
|
|
|
* php-gedcom is a library for parsing, manipulating, importing and exporting |
|
6
|
|
|
* GEDCOM 5.5 files in PHP 5.3+. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Kristopher Wilson <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2010-2013, Kristopher Wilson |
|
10
|
|
|
* @license MIT |
|
11
|
|
|
* |
|
12
|
|
|
* @link http://github.com/mrkrstphr/php-gedcom |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace Gedcom\Record; |
|
16
|
|
|
|
|
17
|
|
|
use Gedcom\Record; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Chan. |
|
21
|
|
|
*/ |
|
22
|
|
|
class Chr extends \Gedcom\Record |
|
23
|
|
|
{ |
|
24
|
|
|
private $months = [ |
|
25
|
|
|
'JAN' => '01', 'FEB' => '02', 'MAR' => '03', 'APR' => '04', 'MAY' => '05', 'JUN' => '06', |
|
26
|
|
|
'JUL' => '07', 'AUG' => '08', 'SEP' => '09', 'OCT' => '10', 'NOV' => '11', 'DEC' => '12', |
|
27
|
|
|
]; |
|
28
|
|
|
|
|
29
|
|
|
public $date; |
|
30
|
|
|
|
|
31
|
|
|
public $dateFormatted = null; |
|
32
|
|
|
|
|
33
|
|
|
public $plac; |
|
34
|
|
|
|
|
35
|
|
|
public function setDate($date) { |
|
36
|
|
|
$this->date = $date; |
|
37
|
|
|
$this->dateFormatted = $this->getYear() .'-'. $this->getMonth() .'-'. substr("0{$this->getDay()}", -2); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function getDateFormatted() { |
|
41
|
|
|
return $this->dateFormatted; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function getDate() { |
|
45
|
|
|
return $this->date; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function setPlac($plac) { |
|
49
|
|
|
$this->plac = $plac; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function getPlac() { |
|
53
|
|
|
return $this->plac; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getDay() |
|
57
|
|
|
{ |
|
58
|
|
|
$record = explode(' ', $this->date); |
|
59
|
|
|
if (!empty($record[0])) { |
|
60
|
|
|
if ($this->isPrefix($record[0])) { |
|
61
|
|
|
unset($record[0]); |
|
62
|
|
|
} |
|
63
|
|
|
if (count($record) > 0) { |
|
64
|
|
|
$day = (int) reset($record); |
|
65
|
|
|
if ($day >= 1 && $day <= 31) { |
|
66
|
|
|
return $day; |
|
67
|
|
|
} |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return null; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function getMonth() |
|
75
|
|
|
{ |
|
76
|
|
|
$record = explode(' ', $this->date); |
|
77
|
|
|
if (count($record) > 0) { |
|
78
|
|
|
if ($this->isPrefix($record[0])) { |
|
79
|
|
|
unset($record[0]); |
|
80
|
|
|
} |
|
81
|
|
|
foreach ($record as $part) { |
|
82
|
|
|
if (isset($this->months[trim($part)])) { |
|
83
|
|
|
return $this->months[trim($part)]; |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
return null; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function getYear() |
|
92
|
|
|
{ |
|
93
|
|
|
$record = explode(' ', $this->date); |
|
94
|
|
|
if (count($record) > 0) { |
|
95
|
|
|
if ($this->isPrefix($record[0])) { |
|
96
|
|
|
unset($record[0]); |
|
97
|
|
|
} |
|
98
|
|
|
if (count($record) > 0) { |
|
99
|
|
|
return (int) end($record); |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
return null; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
private function isPrefix($datePart) |
|
107
|
|
|
{ |
|
108
|
|
|
return in_array($datePart, ['FROM', 'TO', 'BEF', 'AFT', 'BET', 'AND', 'ABT', 'EST', 'CAL', 'INT']); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|