|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* webtrees-lib: MyArtJaub library for webtrees |
|
5
|
|
|
* |
|
6
|
|
|
* @package MyArtJaub\Webtrees |
|
7
|
|
|
* @subpackage IsSourced |
|
8
|
|
|
* @author Jonathan Jaubart <[email protected]> |
|
9
|
|
|
* @copyright Copyright (c) 2009-2021, Jonathan Jaubart |
|
10
|
|
|
* @license https://www.gnu.org/licenses/gpl.html GNU General Public License, version 3 |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
declare(strict_types=1); |
|
14
|
|
|
|
|
15
|
|
|
namespace MyArtJaub\Webtrees\Module\IsSourced\Data; |
|
16
|
|
|
|
|
17
|
|
|
use Fisharebest\Webtrees\I18N; |
|
18
|
|
|
use Fisharebest\Webtrees\Registry; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Data class for holding source status for facts. |
|
22
|
|
|
*/ |
|
23
|
|
|
class FactSourceStatus extends SourceStatus |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var boolean $has_date |
|
27
|
|
|
*/ |
|
28
|
|
|
private $has_date = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var boolean $has_precise_date |
|
32
|
|
|
*/ |
|
33
|
|
|
private $has_precise_date = false; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var boolean $has_source_date |
|
37
|
|
|
*/ |
|
38
|
|
|
private $has_source_date = false; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @var boolean $source_date_match |
|
42
|
|
|
*/ |
|
43
|
|
|
private $source_date_match = false; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Return whether the fact is dated. |
|
47
|
|
|
* |
|
48
|
|
|
* @return bool |
|
49
|
|
|
*/ |
|
50
|
|
|
public function factHasDate(): bool |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->has_date; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Set whether the fact is dated. |
|
57
|
|
|
* |
|
58
|
|
|
* @param bool $has_date |
|
59
|
|
|
* @return $this |
|
60
|
|
|
*/ |
|
61
|
|
|
public function setFactHasDate(bool $has_date): self |
|
62
|
|
|
{ |
|
63
|
|
|
$this->has_date = $has_date; |
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Combinate whether the fact is dated with the previous status. |
|
69
|
|
|
* |
|
70
|
|
|
* @param bool $has_date |
|
71
|
|
|
* @return $this |
|
72
|
|
|
*/ |
|
73
|
|
|
public function addFactHasDate(bool $has_date): self |
|
74
|
|
|
{ |
|
75
|
|
|
$this->has_date = $this->has_date || $has_date; |
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Return whether the fact is dated with a precise day. |
|
81
|
|
|
* Any date modifier will be considered as not precise. |
|
82
|
|
|
* A month or year will be considered as not precise. |
|
83
|
|
|
* |
|
84
|
|
|
* @return bool |
|
85
|
|
|
*/ |
|
86
|
|
|
public function factHasPreciseDate(): bool |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->has_date && $this->has_precise_date; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
/** |
|
92
|
|
|
* Set whather the fact is dated with a precise day. |
|
93
|
|
|
* |
|
94
|
|
|
* @param bool $has_precise_date |
|
95
|
|
|
* @return $this |
|
96
|
|
|
*/ |
|
97
|
|
|
public function setFactHasPreciseDate(bool $has_precise_date): self |
|
98
|
|
|
{ |
|
99
|
|
|
$this->has_precise_date = $has_precise_date; |
|
100
|
|
|
return $this; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Combine whether the fact is dated with a precise day. |
|
105
|
|
|
* |
|
106
|
|
|
* @param bool $has_precise_date |
|
107
|
|
|
* @return $this |
|
108
|
|
|
*/ |
|
109
|
|
|
public function addFactHasPreciseDate(bool $has_precise_date): self |
|
110
|
|
|
{ |
|
111
|
|
|
$this->has_precise_date = $this->has_precise_date || $has_precise_date; |
|
112
|
|
|
return $this; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Return whether the source citation is dated. |
|
117
|
|
|
* |
|
118
|
|
|
* @return bool |
|
119
|
|
|
*/ |
|
120
|
|
|
public function sourceHasDate(): bool |
|
121
|
|
|
{ |
|
122
|
|
|
return $this->has_source_date; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Set whether the source citation is dated. |
|
127
|
|
|
* |
|
128
|
|
|
* @param bool $has_source_date |
|
129
|
|
|
* @return $this |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setSourceHasDate(bool $has_source_date): self |
|
132
|
|
|
{ |
|
133
|
|
|
$this->has_source_date = $has_source_date; |
|
134
|
|
|
return $this; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* Combine whether the source citation is dated with the previous status. |
|
139
|
|
|
* |
|
140
|
|
|
* @param bool $has_source_date |
|
141
|
|
|
* @return $this |
|
142
|
|
|
*/ |
|
143
|
|
|
public function addSourceHasDate(bool $has_source_date): self |
|
144
|
|
|
{ |
|
145
|
|
|
$this->has_source_date = $this->has_source_date || $has_source_date; |
|
146
|
|
|
return $this; |
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
/** |
|
150
|
|
|
* Return whether the source citation date is close to the fact date. |
|
151
|
|
|
* |
|
152
|
|
|
* @return bool |
|
153
|
|
|
*/ |
|
154
|
|
|
public function sourceMatchesFactDate(): bool |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->has_precise_date && $this->has_source_date && $this->source_date_match; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
/** |
|
160
|
|
|
* Set whether the source citation date is close to the fact date. |
|
161
|
|
|
* |
|
162
|
|
|
* @param bool $source_date_match |
|
163
|
|
|
* @return $this |
|
164
|
|
|
*/ |
|
165
|
|
|
public function setSourceMatchesFactDate(bool $source_date_match): self |
|
166
|
|
|
{ |
|
167
|
|
|
$this->source_date_match = $source_date_match; |
|
168
|
|
|
return $this; |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
/** |
|
172
|
|
|
* Combine whether the source citation date is close to the fact date with the previous status. |
|
173
|
|
|
* |
|
174
|
|
|
* @param bool $source_date_match |
|
175
|
|
|
* @return $this |
|
176
|
|
|
*/ |
|
177
|
|
|
public function addSourceMatchesFactDate(bool $source_date_match): self |
|
178
|
|
|
{ |
|
179
|
|
|
$this->source_date_match = $this->source_date_match || $source_date_match; |
|
180
|
|
|
return $this; |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
/** |
|
184
|
|
|
* {@inheritDoc} |
|
185
|
|
|
* @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::isFullySourced() |
|
186
|
|
|
*/ |
|
187
|
|
|
public function isFullySourced(): bool |
|
188
|
|
|
{ |
|
189
|
|
|
return parent::isFullySourced() && $this->sourceMatchesFactDate(); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* {@inheritDoc} |
|
194
|
|
|
* @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::label() |
|
195
|
|
|
*/ |
|
196
|
|
|
public function label(string $context): string |
|
197
|
|
|
{ |
|
198
|
|
|
$context_label = Registry::elementFactory()->make($context)->label(); |
|
199
|
|
|
|
|
200
|
|
|
if ($this->factHasPreciseDate()) { |
|
201
|
|
|
if ($this->hasSource()) { |
|
202
|
|
|
if ($this->hasSupportingDocument()) { |
|
203
|
|
|
if ($this->sourceMatchesFactDate()) { |
|
204
|
|
|
return I18N::translate('%s sourced with exact certificate', $context_label); |
|
205
|
|
|
} else { |
|
206
|
|
|
return I18N::translate('%s sourced with a certificate', $context_label); |
|
207
|
|
|
} |
|
208
|
|
|
} |
|
209
|
|
|
|
|
210
|
|
|
if ($this->sourceMatchesFactDate()) { |
|
211
|
|
|
return I18N::translate('%s precisely sourced', $context_label); |
|
212
|
|
|
} |
|
213
|
|
|
return I18N::translate('%s sourced', $context_label); |
|
214
|
|
|
} |
|
215
|
|
|
return I18N::translate('%s not sourced', $context_label); |
|
216
|
|
|
} |
|
217
|
|
|
|
|
218
|
|
|
if ($this->factHasDate()) { |
|
219
|
|
|
return I18N::translate('%s not precise', $context_label); |
|
220
|
|
|
} |
|
221
|
|
|
return I18N::translate('%s not found', $context_label); |
|
222
|
|
|
} |
|
223
|
|
|
|
|
224
|
|
|
/** |
|
225
|
|
|
* {@inheritDoc} |
|
226
|
|
|
* @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::order() |
|
227
|
|
|
*/ |
|
228
|
|
|
public function order(): int |
|
229
|
|
|
{ |
|
230
|
|
|
return ($this->factHasDate() ? 1 : 0) * ($this->hasSource() ? 1 : -1) * |
|
231
|
|
|
( 1 + ($this->factHasPreciseDate() ? 1 : 0) * (1 + |
|
232
|
|
|
0b010 * ($this->sourceMatchesFactDate() ? 1 : 0) + |
|
233
|
|
|
0b100 * ($this->hasSupportingDocument() ? 1 : 0) |
|
234
|
|
|
) |
|
235
|
|
|
); |
|
236
|
|
|
} |
|
237
|
|
|
|
|
238
|
|
|
/** |
|
239
|
|
|
* {@inheritDoc} |
|
240
|
|
|
* @see \MyArtJaub\Webtrees\Module\IsSourced\Data\SourceStatus::combineWith() |
|
241
|
|
|
*/ |
|
242
|
|
|
public function combineWith(SourceStatus $other) |
|
243
|
|
|
{ |
|
244
|
|
|
if ($other instanceof FactSourceStatus) { |
|
245
|
|
|
$this->addFactHasDate($other->factHasDate()); |
|
246
|
|
|
$this->addFactHasPreciseDate($other->factHasPreciseDate()); |
|
247
|
|
|
$this->addSourceHasDate($other->sourceHasDate()); |
|
248
|
|
|
$this->addSourceMatchesFactDate($other->sourceMatchesFactDate()); |
|
249
|
|
|
} |
|
250
|
|
|
return parent::combineWith($other); |
|
251
|
|
|
} |
|
252
|
|
|
} |
|
253
|
|
|
|