|
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 |
|
22
|
|
|
*/ |
|
23
|
|
|
class SourceStatus |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var boolean $source_exist |
|
27
|
|
|
*/ |
|
28
|
|
|
private $source_exist = false; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var boolean $has_document |
|
32
|
|
|
*/ |
|
33
|
|
|
private $has_document = false; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Return whether the SourceStatus object contains relevant data. |
|
37
|
|
|
* |
|
38
|
|
|
* @return bool |
|
39
|
|
|
*/ |
|
40
|
|
|
public function isSet(): bool |
|
41
|
|
|
{ |
|
42
|
|
|
return true; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Returns whether the record contains a source. |
|
47
|
|
|
* |
|
48
|
|
|
* @return bool |
|
49
|
|
|
*/ |
|
50
|
|
|
public function hasSource(): bool |
|
51
|
|
|
{ |
|
52
|
|
|
return $this->source_exist; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* Set whether the record contains a source. |
|
57
|
|
|
* |
|
58
|
|
|
* @param bool $source_exist |
|
59
|
|
|
* @return self |
|
60
|
|
|
*/ |
|
61
|
|
|
public function setHasSource(bool $source_exist): self |
|
62
|
|
|
{ |
|
63
|
|
|
$this->source_exist = $source_exist; |
|
64
|
|
|
return $this; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Combine whether the record contains a source with the previous status. |
|
69
|
|
|
* |
|
70
|
|
|
* @param bool $source_exist |
|
71
|
|
|
* @return self |
|
72
|
|
|
*/ |
|
73
|
|
|
public function addHasSource(bool $source_exist): self |
|
74
|
|
|
{ |
|
75
|
|
|
$this->source_exist = $this->source_exist || $source_exist; |
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Return whether the source citation is supported by a document. |
|
81
|
|
|
* Uses the _ACT tag from the MyArtJaub Certificates module. |
|
82
|
|
|
* |
|
83
|
|
|
* @return bool |
|
84
|
|
|
*/ |
|
85
|
|
|
public function hasSupportingDocument(): bool |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->hasSource() && $this->has_document; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Set whether the source citation is supported by a document. |
|
92
|
|
|
* |
|
93
|
|
|
* @param bool $has_document |
|
94
|
|
|
* @return self |
|
95
|
|
|
*/ |
|
96
|
|
|
public function setHasSupportingDocument(bool $has_document): self |
|
97
|
|
|
{ |
|
98
|
|
|
$this->has_document = $has_document; |
|
99
|
|
|
return $this; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Combine whether the source citation is supported by a document with the previous status. |
|
104
|
|
|
* |
|
105
|
|
|
* @param bool $has_document |
|
106
|
|
|
* @return self |
|
107
|
|
|
*/ |
|
108
|
|
|
public function addHasSupportingDocument(bool $has_document): self |
|
109
|
|
|
{ |
|
110
|
|
|
$this->has_document = $this->has_document || $has_document; |
|
111
|
|
|
return $this; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* Check whether all possible criteria for defining a sourced element have been met. |
|
116
|
|
|
* |
|
117
|
|
|
* @return bool |
|
118
|
|
|
*/ |
|
119
|
|
|
public function isFullySourced(): bool |
|
120
|
|
|
{ |
|
121
|
|
|
return $this->hasSupportingDocument(); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
/** |
|
125
|
|
|
* Get the label to display to describe the source status. |
|
126
|
|
|
* |
|
127
|
|
|
* @param string $context |
|
128
|
|
|
* @return string |
|
129
|
|
|
*/ |
|
130
|
|
|
public function label(string $context): string |
|
131
|
|
|
{ |
|
132
|
|
|
$context_label = Registry::elementFactory()->make($context)->label(); |
|
133
|
|
|
|
|
134
|
|
|
if (!$this->hasSource()) { |
|
135
|
|
|
return I18N::translate('%s not sourced', $context_label); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
if ($this->hasSupportingDocument()) { |
|
139
|
|
|
return I18N::translate('%s sourced with a certificate', $context_label); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
return I18N::translate('%s sourced', $context_label); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
/** |
|
146
|
|
|
* Return an element combining properties of the current object with another SourceStatus. |
|
147
|
|
|
* Do not use the initial object anymore, it may not appropriately describe the status anymore. |
|
148
|
|
|
* |
|
149
|
|
|
* @param SourceStatus $other |
|
150
|
|
|
* @return self |
|
151
|
|
|
*/ |
|
152
|
|
|
public function combineWith(SourceStatus $other): self |
|
153
|
|
|
{ |
|
154
|
|
|
$this->addHasSource($other->hasSource()); |
|
155
|
|
|
$this->addHasSupportingDocument($other->hasSource()); |
|
156
|
|
|
return $this; |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|