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