1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\content\table; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemCollection; |
6
|
|
|
use Ajax\service\JArray; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* a table content (thead, tbody or tfoot) |
10
|
|
|
* @author jc |
11
|
|
|
* |
12
|
|
|
*/ |
13
|
|
|
class HtmlTableContent extends HtmlSemCollection { |
14
|
|
|
protected $_tdTagNames=[ "thead" => "th","tbody" => "td","tfoot" => "th" ]; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* |
18
|
|
|
* @param string $identifier |
19
|
|
|
* @param string $tagName |
20
|
|
|
* @param int $rowCount |
21
|
|
|
* @param int $colCount |
22
|
|
|
*/ |
23
|
|
|
public function __construct($identifier, $tagName="tbody", $rowCount=NULL, $colCount=NULL) { |
24
|
|
|
parent::__construct($identifier, $tagName, ""); |
25
|
|
|
if (isset($rowCount) && isset($colCount)) |
26
|
|
|
$this->setRowCount($rowCount, $colCount); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* |
31
|
|
|
* @param int $rowCount |
32
|
|
|
* @param int $colCount |
33
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
34
|
|
|
*/ |
35
|
|
|
public function setRowCount($rowCount, $colCount) { |
36
|
|
|
$count=$this->count(); |
37
|
|
|
for($i=$count; $i < $rowCount; $i++) { |
38
|
|
|
$this->addItem(NULL); |
39
|
|
|
} |
40
|
|
|
for($i=0; $i < $rowCount; $i++) { |
41
|
|
|
$item=$this->content[$i]; |
42
|
|
|
$item->setTdTagName($this->_tdTagNames[$this->tagName]); |
43
|
|
|
$this->content[$i]->setColCount($colCount); |
44
|
|
|
} |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getTdTagName($tagName) { |
|
|
|
|
49
|
|
|
return $this->_tdTagNames[$this->tagName]; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* |
54
|
|
|
* {@inheritDoc} |
55
|
|
|
* |
56
|
|
|
* @see \Ajax\common\html\HtmlCollection::createItem() |
57
|
|
|
*/ |
58
|
|
|
protected function createItem($value) { |
59
|
|
|
$count=$this->count(); |
60
|
|
|
$tr=new HtmlTR("", $value); |
|
|
|
|
61
|
|
|
$tr->setContainer($this, $count); |
62
|
|
|
$tr->setTdTagName($this->_tdTagNames[$this->tagName]); |
63
|
|
|
if (isset($value) === true) { |
64
|
|
|
$tr->setColCount($value); |
65
|
|
|
} |
66
|
|
|
return $tr; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function addRow($colCount) { |
70
|
|
|
return $this->addItem($colCount); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Returns the cell (HtmlTD) at position $row,$col |
75
|
|
|
* @param int $row |
76
|
|
|
* @param int $col |
77
|
|
|
* @return \Ajax\semantic\html\content\HtmlTD |
78
|
|
|
*/ |
79
|
|
|
public function getCell($row, $col) { |
80
|
|
|
$row=$this->getItem($row); |
81
|
|
|
if (isset($row)) { |
82
|
|
|
$col=$row->getItem($col); |
83
|
|
|
} |
84
|
|
|
return $col; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* |
89
|
|
|
* @param int $index |
90
|
|
|
* @return \Ajax\semantic\html\content\HtmlTR |
91
|
|
|
*/ |
92
|
|
|
public function getRow($index) { |
93
|
|
|
return $this->getItem($index); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* |
98
|
|
|
* @param int $row |
99
|
|
|
* @param int $col |
100
|
|
|
* @param mixed $value |
101
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
102
|
|
|
*/ |
103
|
|
|
public function setCellValue($row, $col, $value="") { |
104
|
|
|
$cell=$this->getCell($row, $col); |
105
|
|
|
if (isset($cell) === true) { |
106
|
|
|
$cell->setValue($value); |
107
|
|
|
} |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Sets the cells values |
113
|
|
|
* @param mixed $values |
114
|
|
|
*/ |
115
|
|
|
public function setValues($values=array()) { |
116
|
|
|
$count=$this->count(); |
117
|
|
|
$isArray=true; |
118
|
|
|
if (\is_array($values) === false) { |
119
|
|
|
$values=\array_fill(0, $count, $values); |
120
|
|
|
$isArray=false; |
121
|
|
|
} |
122
|
|
|
if (JArray::dimension($values) == 1 && $isArray) |
123
|
|
|
$values=[ $values ]; |
124
|
|
|
|
125
|
|
|
$count=\min(\sizeof($values), $count); |
126
|
|
|
|
127
|
|
|
for($i=0; $i < $count; $i++) { |
128
|
|
|
$row=$this->content[$i]; |
129
|
|
|
$row->setValues($values[$i]); |
130
|
|
|
} |
131
|
|
|
return $this; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
View Code Duplication |
public function setColValues($colIndex, $values=array()) { |
|
|
|
|
135
|
|
|
$count=$this->count(); |
136
|
|
|
if (\is_array($values) === false) { |
137
|
|
|
$values=\array_fill(0, $count, $values); |
138
|
|
|
} |
139
|
|
|
$count=\min(\sizeof($values), $count); |
140
|
|
|
for($i=0; $i < $count; $i++) { |
141
|
|
|
$this->getCell($i, $colIndex)->setValue($values[$i]); |
142
|
|
|
} |
143
|
|
|
return $this; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function addColVariations($colIndex, $variations=array()) { |
147
|
|
|
$count=$this->count(); |
148
|
|
|
for($i=0; $i < $count; $i++) { |
149
|
|
|
$this->getCell($i, $colIndex)->addVariations($variations); |
150
|
|
|
} |
151
|
|
|
return $this; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
public function setRowValues($rowIndex, $values=array()) { |
155
|
|
|
$count=$this->count(); |
156
|
|
|
if (\is_array($values) === false) { |
157
|
|
|
$values=\array_fill(0, $count, $values); |
158
|
|
|
} |
159
|
|
|
$this->getItem($rowIndex)->setValues($values); |
|
|
|
|
160
|
|
|
return $this; |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
public function colCenter($colIndex) { |
164
|
|
|
$count=$this->count(); |
165
|
|
|
for($i=0; $i < $count; $i++) { |
166
|
|
|
$this->getCell($i, $colIndex)->textCenterAligned(); |
167
|
|
|
} |
168
|
|
|
return $this; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function colRight($colIndex) { |
172
|
|
|
$count=$this->count(); |
173
|
|
|
for($i=0; $i < $count; $i++) { |
174
|
|
|
$this->getCell($i, $colIndex)->textRightAligned(); |
175
|
|
|
} |
176
|
|
|
return $this; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* Returns the number of rows (TR) |
181
|
|
|
* @return int |
182
|
|
|
*/ |
183
|
|
|
public function getRowCount() { |
184
|
|
|
return $this->count(); |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
/** |
188
|
|
|
* Returns the number of columns (TD) |
189
|
|
|
* @return int |
190
|
|
|
*/ |
191
|
|
|
public function getColCount() { |
192
|
|
|
$result=0; |
193
|
|
|
if ($this->count() > 0) |
194
|
|
|
$result=$this->getItem(0)->getColCount(); |
|
|
|
|
195
|
|
|
return $result; |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* Removes the cell at position $rowIndex,$colIndex |
200
|
|
|
* @param int $rowIndex |
201
|
|
|
* @param int $colIndex |
202
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
203
|
|
|
*/ |
204
|
|
|
public function delete($rowIndex, $colIndex=NULL) { |
205
|
|
|
if (isset($colIndex)) { |
206
|
|
|
$row=$this->getItem($rowIndex); |
207
|
|
|
if (isset($row) === true) { |
208
|
|
|
$row->delete($colIndex); |
209
|
|
|
} |
210
|
|
|
} else { |
211
|
|
|
$this->removeItem($rowIndex); |
212
|
|
|
} |
213
|
|
|
return $this; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function mergeCol($rowIndex=0, $colIndex=0) { |
217
|
|
|
return $this->getItem($rowIndex)->mergeCol($colIndex); |
|
|
|
|
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
public function mergeRow($rowIndex=0, $colIndex=0) { |
221
|
|
|
return $this->getItem($rowIndex)->mergeRow($colIndex); |
|
|
|
|
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
public function setFullWidth() { |
225
|
|
|
return $this->addToProperty("class", "full-width"); |
226
|
|
|
} |
227
|
|
|
} |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.