1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
4
|
|
|
* |
5
|
|
|
* @package MyArtJaub\Webtrees |
6
|
|
|
* @author Jonathan Jaubart <[email protected]> |
7
|
|
|
* @copyright Copyright (c) 2011-2016, Jonathan Jaubart |
8
|
|
|
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace MyArtJaub\Webtrees; |
12
|
|
|
|
13
|
|
|
use MyArtJaub\Webtrees\Globals; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Decorator class to extend native webtrees GedcomRecord class. |
17
|
|
|
* |
18
|
|
|
* @see \Fisharebest\Webtrees\GedcomRecord |
19
|
|
|
*/ |
20
|
|
|
class GedcomRecord { |
21
|
|
|
|
22
|
|
|
/** @var \Fisharebest\Webtrees\GedcomRecord Underlying base GedcomRecord */ |
23
|
|
|
protected $gedcomrecord; |
24
|
|
|
|
25
|
|
|
/** @var bool Is the GedcomRecord sourced (cache) */ |
26
|
|
|
protected $_issourced=null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Contructor for the decorator |
30
|
|
|
* |
31
|
|
|
* @param \Fisharebest\Webtrees\GedcomRecord $gedcomrecord_in The GedcomRecord to extend |
32
|
|
|
*/ |
33
|
|
|
public function __construct(\Fisharebest\Webtrees\GedcomRecord $gedcomrecord_in){ |
34
|
|
|
$this->gedcomrecord = $gedcomrecord_in; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Return the native gedcom record embedded within the decorator |
39
|
|
|
* |
40
|
|
|
* @return \Fisharebest\Webtrees\GedcomRecord Embedded gedcom record |
41
|
|
|
*/ |
42
|
|
|
public function getDerivedRecord(){ |
43
|
|
|
return $this->gedcomrecord; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Return whether the record is a new addition (and not just a modification) |
48
|
|
|
* |
49
|
|
|
* @return boolean True id new addition |
50
|
|
|
*/ |
51
|
|
|
public function isNewAddition() { |
52
|
|
|
return $this->gedcomrecord->isPendingAddtion() |
53
|
|
|
&& $this->gedcomrecord->privatizeGedcom(\Fisharebest\Webtrees\Auth::PRIV_HIDE) === null; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Add additional options to the core formatFirstMajorFact function. |
58
|
|
|
* If no option is suitable, it will try returning the core function. |
59
|
|
|
* |
60
|
|
|
* Option 10 : display <i>factLabel shortFactDate shortFactPlace</i> |
61
|
|
|
* |
62
|
|
|
* @uses \MyArtJaub\Webtrees\Functions\FunctionsPrint |
63
|
|
|
* @param string $facts List of facts to find information from |
64
|
|
|
* @param int $style Style to apply to the information. Number >= 10 should be used in this function, lower number will return the core function. |
65
|
|
|
* @return string Formatted fact description |
66
|
|
|
*/ |
67
|
|
|
public function formatFirstMajorFact($facts, $style) { |
68
|
|
|
foreach ($this->gedcomrecord->getFacts($facts) as $fact) { |
69
|
|
|
// Only display if it has a date or place (or both) |
70
|
|
|
if (($fact->getDate() || $fact->getPlace()) && $fact->canShow()) { |
71
|
|
|
switch ($style) { |
72
|
|
|
case 10: |
73
|
|
|
return '<i>'.$fact->getLabel().' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactDateShort($fact) .' '. \MyArtJaub\Webtrees\Functions\FunctionsPrint::formatFactPlaceShort($fact, '%1') .'</i>'; |
74
|
|
|
default: |
75
|
|
|
return $this->gedcomrecord->formatFirstMajorFact($facts, $style); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
return ''; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Check if the IsSourced information can be displayed |
84
|
|
|
* |
85
|
|
|
* @param int $access_level |
86
|
|
|
* @return boolean |
87
|
|
|
*/ |
88
|
|
|
public function canDisplayIsSourced($access_level = null){ |
89
|
|
|
if(!$this->gedcomrecord->canShow($access_level)) return false; |
90
|
|
|
if($access_level === null ) |
91
|
|
|
$access_level = \Fisharebest\Webtrees\Auth::accessLevel($this->gedcomrecord->getTree()); |
92
|
|
|
|
93
|
|
|
$global_facts = Globals::getGlobalFacts(); |
94
|
|
|
if (isset($global_facts['SOUR'])) { |
95
|
|
|
return $global_facts['SOUR'] >= $access_level; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return true; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Check if a gedcom record is sourced |
103
|
|
|
* Values: |
104
|
|
|
* - -1, if the record has no sources attached |
105
|
|
|
* - 1, if the record has a source attached |
106
|
|
|
* - 2, if the record has a source, and a certificate supporting it |
107
|
|
|
* |
108
|
|
|
* @return int Level of sources |
109
|
|
|
*/ |
110
|
|
|
public function isSourced(){ |
111
|
|
|
if($this->_issourced !== null) return $this->_issourced; |
|
|
|
|
112
|
|
|
$this->_issourced=-1; |
|
|
|
|
113
|
|
|
$sourcesfacts = $this->gedcomrecord->getFacts('SOUR'); |
114
|
|
|
foreach($sourcesfacts as $sourcefact){ |
115
|
|
|
$this->_issourced=max($this->_issourced, 1); |
116
|
|
|
if($sourcefact->getAttribute('_ACT')){ |
117
|
|
|
$this->_issourced=max($this->_issourced, 2); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
return $this->_issourced; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* Check is an event associated to this record is sourced |
125
|
|
|
* |
126
|
|
|
* @param string $eventslist |
127
|
|
|
* @return int Level of sources |
128
|
|
|
*/ |
129
|
|
|
public function isFactSourced($eventslist){ |
130
|
|
|
if(empty($eventslist)) return 0; |
131
|
|
|
$isSourced=0; |
132
|
|
|
$facts = $this->gedcomrecord->getFacts($eventslist); |
133
|
|
|
foreach($facts as $fact){ |
134
|
|
|
if($isSourced < Fact::MAX_IS_SOURCED_LEVEL){ |
135
|
|
|
$dfact = new Fact($fact); |
136
|
|
|
$tmpIsSourced = $dfact->isSourced(); |
137
|
|
|
if($tmpIsSourced != 0) { |
138
|
|
|
if($isSourced==0) { |
139
|
|
|
$isSourced = $tmpIsSourced; |
140
|
|
|
} |
141
|
|
|
else{ |
142
|
|
|
$isSourced = max($isSourced, $tmpIsSourced); |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
return $isSourced; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
?> |
|
|
|
|