Completed
Push — master ( ea2a7d...e9bdcb )
by Jean-Christophe
03:40
created

HtmlTable::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
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,Variation::COMPACT,Variation::DEFINITION ];
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 addColVariations($colIndex, $variations=array()) {
117
		return $this->getBody()->addColVariations($colIndex, $variations);
118
	}
119
120
	public function colCenter($colIndex) {
121
		if ($this->hasPart("thead"))
122
			$this->getHeader()->colCenter($colIndex);
123
		$this->getBody()->colCenter($colIndex);
124
		return $this;
125
	}
126
127
	public function colRight($colIndex) {
128
		if ($this->hasPart("thead"))
129
			$this->getHeader()->colRight($colIndex);
130
		$this->getBody()->colRight($colIndex);
131
		return $this;
132
	}
133
134
	public function setCelled() {
135
		return $this->addToProperty("class", "celled");
136
	}
137
138
	public function setBasic($very=false) {
139
		if ($very)
140
			$this->addToPropertyCtrl("class", "very", array ("very" ));
141
		return $this->addToPropertyCtrl("class", "basic", array ("basic" ));
142
	}
143
144
	public function setCollapsing() {
145
		return $this->addToProperty("class", "collapsing");
146
	}
147
148
	public function setDefinition() {
149
		return $this->addToProperty("class", "definition");
150
	}
151
}