|
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
|
|
|
public function __construct($identifier, $rowCount, $colCount) { |
|
17
|
|
|
parent::__construct($identifier, "table", "ui table"); |
|
18
|
|
|
$this->content=array(); |
|
19
|
|
|
$this->setRowCount($rowCount, $colCount); |
|
20
|
|
|
$this->_variations=[Variation::CELLED,Variation::PADDED]; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Returns/create eventually a part of the table corresponding to the $key : thead, tbody or tfoot |
|
25
|
|
|
* @param string $key |
|
26
|
|
|
* @return HtmlTableContent |
|
27
|
|
|
*/ |
|
28
|
|
|
private function getPart($key){ |
|
29
|
|
|
if(\array_key_exists($key, $this->content)===false){ |
|
30
|
|
|
$this->content[$key]=new HtmlTableContent("",$key); |
|
31
|
|
|
if($key!=="tbody"){ |
|
32
|
|
|
$this->content[$key]->setRowCount(1, $this->_colCount); |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
return $this->content[$key]; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Returns/create eventually the body of the table |
|
40
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
|
41
|
|
|
*/ |
|
42
|
|
|
public function getBody(){ |
|
43
|
|
|
return $this->getPart("tbody"); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns/create eventually the header of the table |
|
48
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
|
49
|
|
|
*/ |
|
50
|
|
|
public function getHeader(){ |
|
51
|
|
|
return $this->getPart("thead"); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Returns/create eventually the footer of the table |
|
56
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getFooter(){ |
|
59
|
|
|
return $this->getPart("tfoot"); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Checks if the part corresponding to $key exists |
|
64
|
|
|
* @param string $key |
|
65
|
|
|
* @return boolean |
|
66
|
|
|
*/ |
|
67
|
|
|
public function hasPart($key){ |
|
68
|
|
|
return \array_key_exists($key, $this->content)===true; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @param int $rowCount |
|
73
|
|
|
* @param int $colCount |
|
74
|
|
|
* @return \Ajax\semantic\html\content\table\HtmlTableContent |
|
75
|
|
|
*/ |
|
76
|
|
|
public function setRowCount($rowCount, $colCount) { |
|
77
|
|
|
$this->_colCount=$colCount; |
|
78
|
|
|
return $this->getBody()->setRowCount($rowCount,$colCount); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Returns the cell (HtmlTD) at position $row,$col |
|
83
|
|
|
* @param int $row |
|
84
|
|
|
* @param int $col |
|
85
|
|
|
* @return \Ajax\semantic\html\content\HtmlTD |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getCell($row,$col){ |
|
88
|
|
|
return $this->getBody()->getCell($row,$col); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function setValues($values=array()){ |
|
92
|
|
|
$this->getBody()->setValues($values); |
|
93
|
|
|
return $this; |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function setColValues($colIndex,$values=array()){ |
|
97
|
|
|
$this->getBody()->setColValues($colIndex,$values); |
|
98
|
|
|
return $this; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public function colCenter($colIndex){ |
|
102
|
|
|
if($this->hasPart("thead")) |
|
103
|
|
|
$this->getHeader()->colCenter($colIndex); |
|
104
|
|
|
$this->getBody()->colCenter($colIndex); |
|
105
|
|
|
return $this; |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
public function setCelled(){ |
|
109
|
|
|
return $this->addToProperty("class", "celled"); |
|
110
|
|
|
} |
|
111
|
|
|
} |