1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* The MIT License |
6
|
|
|
* |
7
|
|
|
* Copyright 2018 Peter Gee <https://github.com/pgee70>. |
8
|
|
|
* |
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
11
|
|
|
* in the Software without restriction, including without limitation the rights |
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
14
|
|
|
* furnished to do so, subject to the following conditions: |
15
|
|
|
* |
16
|
|
|
* The above copyright notice and this permission notice shall be included in |
17
|
|
|
* all copies or substantial portions of the Software. |
18
|
|
|
* |
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE |
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25
|
|
|
* THE SOFTWARE. |
26
|
|
|
*/ |
27
|
|
|
|
28
|
|
|
namespace i3Soft\CDA\Elements\Html; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The MIT License |
32
|
|
|
* |
33
|
|
|
* Copyright 2017 Julien Fastré <[email protected]>. |
34
|
|
|
* |
35
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
36
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
37
|
|
|
* in the Software without restriction, including without limitation the rights |
38
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
39
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
40
|
|
|
* furnished to do so, subject to the following conditions: |
41
|
|
|
* |
42
|
|
|
* The above copyright notice and this permission notice shall be included in |
43
|
|
|
* all copies or substantial portions of the Software. |
44
|
|
|
* |
45
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
46
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
47
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE |
48
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
49
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
50
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
51
|
|
|
* THE SOFTWARE. |
52
|
|
|
*/ |
53
|
|
|
|
54
|
|
|
use i3Soft\CDA\DataType\ReferenceType; |
55
|
|
|
use i3Soft\CDA\Elements\AbstractElement; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @author Julien Fastré <[email protected]> |
59
|
|
|
*/ |
60
|
|
|
class TableCell extends AbstractElement |
61
|
|
|
{ |
62
|
|
|
/** |
63
|
|
|
* |
64
|
|
|
*/ |
65
|
|
|
const TH = 'th'; |
66
|
|
|
/** |
67
|
|
|
* |
68
|
|
|
*/ |
69
|
|
|
const TD = 'td'; |
70
|
|
|
/** |
71
|
|
|
* |
72
|
|
|
* @var string |
73
|
|
|
*/ |
74
|
|
|
private $content; |
75
|
|
|
/** |
76
|
|
|
* |
77
|
|
|
* @var ReferenceType |
78
|
|
|
*/ |
79
|
|
|
private $reference; |
80
|
|
|
/** |
81
|
|
|
* |
82
|
|
|
* @var TableRow |
83
|
|
|
*/ |
84
|
|
|
private $row; |
85
|
|
|
/** |
86
|
|
|
* a string determining if the row is th or td |
87
|
|
|
* |
88
|
|
|
* @var string |
89
|
|
|
*/ |
90
|
|
|
private $level; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* TableCell constructor. |
94
|
|
|
* |
95
|
|
|
* @param $level |
96
|
|
|
* @param TableRow $row |
97
|
|
|
* @param string $content |
98
|
|
|
*/ |
99
|
|
|
public function __construct ($level, TableRow $row = NULL, $content = '') |
100
|
|
|
{ |
101
|
|
|
$this->setContent($content); |
102
|
|
|
if (FALSE === \in_array($level, array(self::TH, self::TD), TRUE)) |
103
|
|
|
{ |
104
|
|
|
throw new \InvalidArgumentException("The level supplied was '{$level}' it must be th or td,"); |
105
|
|
|
} |
106
|
|
|
$this->level = $level; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* |
111
|
|
|
* @return TableRow |
112
|
|
|
*/ |
113
|
|
|
public function getRow (): TableRow |
114
|
|
|
{ |
115
|
|
|
return $this->row; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* |
120
|
|
|
* @param TableRow $row |
121
|
|
|
* |
122
|
|
|
* @return self |
123
|
|
|
*/ |
124
|
|
|
public function setRow (TableRow $row): self |
125
|
|
|
{ |
126
|
|
|
$this->row = $row; |
127
|
|
|
|
128
|
|
|
return $this; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* |
133
|
|
|
* @return boolean |
134
|
|
|
*/ |
135
|
|
|
public function isEmpty (): bool |
136
|
|
|
{ |
137
|
|
|
return empty($this->getContent()); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* |
142
|
|
|
* @return string |
143
|
|
|
*/ |
144
|
|
|
public function getContent (): string |
145
|
|
|
{ |
146
|
|
|
return $this->content; |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* |
151
|
|
|
* @param string $content |
152
|
|
|
* |
153
|
|
|
* @return self |
154
|
|
|
*/ |
155
|
|
|
public function setContent ($content): self |
156
|
|
|
{ |
157
|
|
|
$this->content = $content; |
158
|
|
|
|
159
|
|
|
return $this; |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @param \DOMDocument $doc |
164
|
|
|
* |
165
|
|
|
* @return \DOMElement |
166
|
|
|
*/ |
167
|
|
|
public function toDOMElement (\DOMDocument $doc): \DOMElement |
168
|
|
|
{ |
169
|
|
|
$el = $this->createElement($doc); |
170
|
|
|
|
171
|
|
|
if ($this->hasReference()) |
172
|
|
|
{ |
173
|
|
|
$this->getReference()->setValueToElement($el, $doc); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
$el->appendChild($doc->createTextNode($this->getContent())); |
177
|
|
|
|
178
|
|
|
return $el; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
/** |
182
|
|
|
* @return bool |
183
|
|
|
*/ |
184
|
|
|
public function hasReference (): bool |
185
|
|
|
{ |
186
|
|
|
return NULL !== $this->reference; |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
/** |
190
|
|
|
* |
191
|
|
|
* @return ReferenceType |
192
|
|
|
*/ |
193
|
|
|
public function getReference (): ReferenceType |
194
|
|
|
{ |
195
|
|
|
return $this->reference; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* |
200
|
|
|
* @param ReferenceType $reference |
201
|
|
|
* |
202
|
|
|
* @return self |
203
|
|
|
*/ |
204
|
|
|
public function setReference (ReferenceType $reference): self |
205
|
|
|
{ |
206
|
|
|
$this->reference = $reference; |
207
|
|
|
|
208
|
|
|
return $this; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* @return string |
213
|
|
|
*/ |
214
|
|
|
protected function getElementTag (): string |
215
|
|
|
{ |
216
|
|
|
return $this->level; |
217
|
|
|
} |
218
|
|
|
} |
219
|
|
|
|