Completed
Push — master ( 1d23a1...916f6f )
by Jean-Christophe
03:30
created

HtmlTable::setCollapsing()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 0
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 setColValues($colIndex, $values=array()) {
99
		$this->getBody()->setColValues($colIndex, $values);
100
		return $this;
101
	}
102
103
	public function setRowValues($rowIndex, $values=array()) {
104
		$this->getBody()->setRowValues($rowIndex, $values);
105
		return $this;
106
	}
107
108
	public function colCenter($colIndex) {
109
		if ($this->hasPart("thead"))
110
			$this->getHeader()->colCenter($colIndex);
111
		$this->getBody()->colCenter($colIndex);
112
		return $this;
113
	}
114
115
	public function colRight($colIndex) {
116
		if ($this->hasPart("thead"))
117
			$this->getHeader()->colRight($colIndex);
118
		$this->getBody()->colRight($colIndex);
119
		return $this;
120
	}
121
122
	public function setCelled() {
123
		return $this->addToProperty("class", "celled");
124
	}
125
126
	public function setBasic($very=false) {
127
		if ($very)
128
			$this->addToPropertyCtrl("class", "very", array ("very" ));
129
		return $this->addToPropertyCtrl("class", "basic", array ("basic" ));
130
	}
131
132
	public function setCollapsing() {
133
		return $this->addToProperty("class", "collapsing");
134
	}
135
}