1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\collections; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\content\table\HtmlTableContent; |
7
|
|
|
use Ajax\semantic\html\base\constants\Variation; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Semantic HTML Table component |
11
|
|
|
* @author jc |
12
|
|
|
* |
13
|
|
|
*/ |
14
|
|
|
class HtmlTable extends HtmlSemDoubleElement { |
15
|
|
|
private $_colCount; |
16
|
|
|
|
17
|
|
|
public function __construct($identifier, $rowCount, $colCount) { |
18
|
|
|
parent::__construct($identifier, "table", "ui table"); |
19
|
|
|
$this->content=array (); |
20
|
|
|
$this->setRowCount($rowCount, $colCount); |
21
|
|
|
$this->_variations=[ Variation::CELLED,Variation::PADDED ]; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Returns/create eventually a part of the table corresponding to the $key : thead, tbody or tfoot |
26
|
|
|
* @param string $key |
27
|
|
|
* @return HtmlTableContent |
28
|
|
|
*/ |
29
|
|
|
private function getPart($key) { |
30
|
|
|
if (\array_key_exists($key, $this->content)===false) { |
31
|
|
|
$this->content[$key]=new HtmlTableContent("", $key); |
32
|
|
|
if ($key!=="tbody") { |
33
|
|
|
$this->content[$key]->setRowCount(1, $this->_colCount); |
34
|
|
|
} |
35
|
|
|
} |
36
|
|
|
return $this->content[$key]; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Returns/create eventually the body of the table |
41
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
42
|
|
|
*/ |
43
|
|
|
public function getBody() { |
44
|
|
|
return $this->getPart("tbody"); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Returns/create eventually the header of the table |
49
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
50
|
|
|
*/ |
51
|
|
|
public function getHeader() { |
52
|
|
|
return $this->getPart("thead"); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Returns/create eventually the footer of the table |
57
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
58
|
|
|
*/ |
59
|
|
|
public function getFooter() { |
60
|
|
|
return $this->getPart("tfoot"); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Checks if the part corresponding to $key exists |
65
|
|
|
* @param string $key |
66
|
|
|
* @return boolean |
67
|
|
|
*/ |
68
|
|
|
public function hasPart($key) { |
69
|
|
|
return \array_key_exists($key, $this->content)===true; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* |
74
|
|
|
* @param int $rowCount |
75
|
|
|
* @param int $colCount |
76
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
77
|
|
|
*/ |
78
|
|
|
public function setRowCount($rowCount, $colCount) { |
79
|
|
|
$this->_colCount=$colCount; |
80
|
|
|
return $this->getBody()->setRowCount($rowCount, $colCount); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Returns the cell (HtmlTD) at position $row,$col |
85
|
|
|
* @param int $row |
86
|
|
|
* @param int $col |
87
|
|
|
* @return \Ajax\semantic\html\content\HtmlTD |
88
|
|
|
*/ |
89
|
|
|
public function getCell($row, $col) { |
90
|
|
|
return $this->getBody()->getCell($row, $col); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function setValues($values=array()) { |
94
|
|
|
$this->getBody()->setValues($values); |
95
|
|
|
return $this; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function setHeaderValues($values=array()) { |
99
|
|
|
return $this->getHeader()->setValues($values); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function setFooterValues($values=array()) { |
103
|
|
|
return $this->getFooter()->setValues($values); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function setColValues($colIndex, $values=array()) { |
107
|
|
|
$this->getBody()->setColValues($colIndex, $values); |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function setRowValues($rowIndex, $values=array()) { |
112
|
|
|
$this->getBody()->setRowValues($rowIndex, $values); |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
public function colCenter($colIndex) { |
117
|
|
|
if ($this->hasPart("thead")) |
118
|
|
|
$this->getHeader()->colCenter($colIndex); |
119
|
|
|
$this->getBody()->colCenter($colIndex); |
120
|
|
|
return $this; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function colRight($colIndex) { |
124
|
|
|
if ($this->hasPart("thead")) |
125
|
|
|
$this->getHeader()->colRight($colIndex); |
126
|
|
|
$this->getBody()->colRight($colIndex); |
127
|
|
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function setCelled() { |
131
|
|
|
return $this->addToProperty("class", "celled"); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function setBasic($very=false) { |
135
|
|
|
if ($very) |
136
|
|
|
$this->addToPropertyCtrl("class", "very", array ("very" )); |
137
|
|
|
return $this->addToPropertyCtrl("class", "basic", array ("basic" )); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function setCollapsing() { |
141
|
|
|
return $this->addToProperty("class", "collapsing"); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
public function setDefinition() { |
145
|
|
|
return $this->addToProperty("class", "definition"); |
146
|
|
|
} |
147
|
|
|
} |