1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* The MIT License |
4
|
|
|
* |
5
|
|
|
* Copyright 2017 Julien Fastré <[email protected]>. |
6
|
|
|
* |
7
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
8
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
9
|
|
|
* in the Software without restriction, including without limitation the rights |
10
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
11
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
12
|
|
|
* furnished to do so, subject to the following conditions: |
13
|
|
|
* |
14
|
|
|
* The above copyright notice and this permission notice shall be included in |
15
|
|
|
* all copies or substantial portions of the Software. |
16
|
|
|
* |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
23
|
|
|
* THE SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
namespace PHPHealth\CDA\Elements; |
26
|
|
|
|
27
|
|
|
use PHPHealth\CDA\Elements\AbstractElement; |
28
|
|
|
use PHPHealth\CDA\Elements\TableCell; |
29
|
|
|
use PHPHealth\CDA\Elements\AbstractTableSection; |
30
|
|
|
use PHPHealth\CDA\Elements\TableHead; |
31
|
|
|
use PHPHealth\CDA\Elements\ReferenceType; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* |
35
|
|
|
* |
36
|
|
|
* @author Julien Fastré <[email protected]> |
37
|
|
|
*/ |
38
|
|
|
class TableRow extends AbstractElement |
39
|
|
|
{ |
40
|
|
|
/** |
41
|
|
|
* |
42
|
|
|
* @var TableCell[] |
43
|
|
|
*/ |
44
|
|
|
private $cells; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* a reference to the section this row is attached to |
48
|
|
|
* |
49
|
|
|
* @var AbstractTableSection |
50
|
|
|
*/ |
51
|
|
|
private $section; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* |
55
|
|
|
* @var Reference |
56
|
|
|
*/ |
57
|
|
|
private $reference; |
58
|
|
|
|
59
|
|
|
function __construct(AbstractTableSection $section = null) |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
$this->section = $section; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* |
66
|
|
|
* @param string $content |
67
|
|
|
* @return TableCell |
68
|
|
|
*/ |
69
|
|
|
function createCell($content) |
|
|
|
|
70
|
|
|
{ |
71
|
|
|
$cell = new TableCell( |
72
|
|
|
$this->getSection() instanceof TableHead ? TableCell::TH : TableCell::TD, |
73
|
|
|
$this, |
74
|
|
|
$content); |
75
|
|
|
|
76
|
|
|
$this->addCell($cell); |
77
|
|
|
|
78
|
|
|
return $cell; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* |
83
|
|
|
* @param TableCell $cell |
84
|
|
|
* @return $this |
85
|
|
|
*/ |
86
|
|
|
public function addCell(TableCell $cell) |
87
|
|
|
{ |
88
|
|
|
$cell->setRow($this); |
89
|
|
|
|
90
|
|
|
$this->cells[] = $cell; |
91
|
|
|
|
92
|
|
|
return $this; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* |
97
|
|
|
* @return TableCell[] |
98
|
|
|
*/ |
99
|
|
|
function getCells(): array |
|
|
|
|
100
|
|
|
{ |
101
|
|
|
return $this->cells; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
function getSection(): AbstractTableSection |
|
|
|
|
105
|
|
|
{ |
106
|
|
|
return $this->section; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
function setCells(array $cells) |
|
|
|
|
110
|
|
|
{ |
111
|
|
|
$this->cells = $cells; |
112
|
|
|
return $this; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
function setSection(AbstractTableSection $section) |
|
|
|
|
116
|
|
|
{ |
117
|
|
|
$this->section = $section; |
118
|
|
|
return $this; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* |
123
|
|
|
* @return Reference |
124
|
|
|
*/ |
125
|
|
|
function getReference() |
|
|
|
|
126
|
|
|
{ |
127
|
|
|
return $this->reference; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* |
132
|
|
|
* @param ReferenceType $reference |
133
|
|
|
* @return $this |
134
|
|
|
*/ |
135
|
|
|
function setReference(ReferenceType $reference) |
|
|
|
|
136
|
|
|
{ |
137
|
|
|
$this->reference = $reference; |
|
|
|
|
138
|
|
|
|
139
|
|
|
return $this; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* |
145
|
|
|
* @return boolean |
146
|
|
|
*/ |
147
|
|
|
public function isEmpty() |
148
|
|
|
{ |
149
|
|
|
return count($this->getCells()) > 0; |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
protected function getElementTag(): string |
154
|
|
|
{ |
155
|
|
|
return 'tr'; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
View Code Duplication |
public function toDOMElement(\DOMDocument $doc): \DOMElement |
|
|
|
|
159
|
|
|
{ |
160
|
|
|
$el = $this->createElement($doc); |
161
|
|
|
|
162
|
|
|
if ($this->getReference() !== null) { |
163
|
|
|
$this->getReference()->setValueToElement($el, $doc); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
foreach ($this->getCells() as $cell) { |
167
|
|
|
$el->appendChild($cell->toDOMElement($doc)); |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
return $el; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.