phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlTR.php
Go to the documentation of this file.
1<?php
3
8
15
16 private $_tdTagName;
17
18 private $_container;
19
20 private $_row;
21
22 public function __construct($identifier) {
23 parent::__construct($identifier, "tr", "");
24 $this->_states = [
25 State::ACTIVE,
26 State::POSITIVE,
27 State::NEGATIVE,
28 State::WARNING,
29 State::ERROR,
30 State::DISABLED
31 ];
32 }
33
34 public function setColCount($colCount) {
35 $count = $this->count();
36 for ($i = $count; $i < $colCount; $i ++) {
37 $item = $this->addItem(NULL);
38 $item->setTagName($this->_tdTagName);
39 }
40 return $this;
41 }
42
43 public function getColCount() {
44 return $this->count();
45 }
46
53 protected function createItem($value) {
54 $count = $this->count();
55 $td = new HtmlTD("", $value, $this->_tdTagName);
56 $td->setContainer($this->_container, $this->_row, $count);
57 return $td;
58 }
59
64 public function getItem($index) {
65 return parent::getItem($index);
66 }
67
68 public function setTdTagName($tagName = "td") {
69 $this->_tdTagName = $tagName;
70 }
71
78 public function setContainer($container, $row) {
79 $this->_container = $container;
80 $this->_row = $row;
81 }
82
88 public function setValues($values = array()) {
89 return $this->_addOrSetValues($values, function (HtmlTD &$cell, $value) {
90 $cell->setValue($value);
91 });
92 }
93
99 public function addValues($values = array()) {
100 return $this->_addOrSetValues($values, function (HtmlTD &$cell, $value) {
101 $cell->addValue($value);
102 });
103 }
104
110 protected function _addOrSetValues($values, $callback) {
111 $count = $this->count();
112 if (! \is_array($values)) {
113 $values = \array_fill(0, $count, $values);
114 } else {
115 if (JArray::isAssociative($values) === true) {
116 $values = \array_values($values);
117 }
118 }
119 $count = \min(\sizeof($values), $count);
120
121 for ($i = 0; $i < $count; $i ++) {
122 $cell = $this->content[$i];
123 $callback($cell, $values[$i]);
124 }
125 return $this;
126 }
127
135 public function delete($index) {
136 $this->removeItem($index);
137 return $this;
138 }
139
140 public function mergeCol($colIndex = 0) {
141 return $this->getItem($colIndex)->mergeCol();
142 }
143
144 public function mergeRow($colIndex = 0) {
145 $row = $this->getItem($colIndex);
146 if (isset($row)) {
147 $this->getItem($colIndex)->mergeRow();
148 }
149 return $this;
150 }
151
152 public function getColPosition($colIndex) {
153 if ($this->_container->_isMerged() !== true)
154 return $colIndex;
155 $pos = 0;
156 $rows = $this->_container->getContent();
157 for ($i = 0; $i < $this->_row; $i ++) {
158 $max = \min($colIndex, $rows[$i]->count());
159 for ($j = 0; $j < $max; $j ++) {
160 $rowspan = $rows[$i]->getItem($j)->getRowspan();
161 if ($rowspan + $i > $this->_row)
162 $pos ++;
163 }
164 }
165 if ($pos > $colIndex)
166 return NULL;
167 $count = $this->count();
168 for ($i = 0; $i < $count; $i ++) {
169 $pos += $this->content[$i]->getColspan();
170 if ($pos >= $colIndex + 1)
171 return $i;
172 }
173 return null;
174 }
175
176 public function conditionalCellFormat($callback, $format) {
177 $cells = $this->content;
178 foreach ($cells as $cell) {
179 $cell->conditionalCellFormat($callback, $format);
180 }
181 return $this;
182 }
183
184 public function conditionalRowFormat($callback, $format) {
185 if ($callback($this)) {
186 $this->addToProperty("class", $format);
187 }
188 return $this;
189 }
190
191 public function containsStr($needle) {
192 $cells = $this->content;
193 foreach ($cells as $cell) {
194 if (\strpos($cell->getContent(), $needle) !== false)
195 return true;
196 }
197 return false;
198 }
199
200 public function apply($callback) {
201 $callback($this);
202 return $this;
203 }
204
205 public function applyCells($callback) {
206 $cells = $this->content;
207 foreach ($cells as $cell) {
208 $cell->apply($callback);
209 }
210 return $this;
211 }
212
213 public function toDelete($colIndex) {
214 $this->getItem($colIndex)->toDelete();
215 return $this;
216 }
217
218 public function toRowspanned($colIndex) {
219 $cell = $this->getItem($colIndex);
220 $cell->addClass('rowspanned');
221 $cell->setContent('');
222 return $this;
223 }
224}
addItem($item)
adds and returns an item
Base class for Semantic Html collections.
addToProperty($name, $value, $separator=" ")
conditionalRowFormat($callback, $format)
Definition HtmlTR.php:184
createItem($value)
{The item factory.}
Definition HtmlTR.php:53
conditionalCellFormat($callback, $format)
Definition HtmlTR.php:176
_addOrSetValues($values, $callback)
Sets or adds values to the row cols.
Definition HtmlTR.php:110
addValues($values=array())
Adds values to the row cols.
Definition HtmlTR.php:99
setContainer($container, $row)
Define the container (HtmlTableContent) and the num of the row.
Definition HtmlTR.php:78
setValues($values=array())
Sets values to the row cols.
Definition HtmlTR.php:88