Skip to content

Commit 18e8f71

Browse files
committed
mergeIdentiqualValues + toDelete on Table
1 parent 0a6efd7 commit 18e8f71

File tree

4 files changed

+58
-3
lines changed

4 files changed

+58
-3
lines changed

Ajax/semantic/html/collections/table/HtmlTable.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,4 +424,10 @@ public function setColWidths($widths){
424424
}
425425
return $this;
426426
}
427+
428+
public function mergeIdentiqualValues($colIndex,$function="strip_tags"){
429+
$body=$this->getBody();
430+
$body->mergeIdentiqualValues($colIndex,$function);
431+
return $this;
432+
}
427433
}

Ajax/semantic/html/content/table/HtmlTD.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Ajax\semantic\html\base\traits\TableElementTrait;
1010
use Ajax\semantic\html\elements\html5\HtmlLink;
1111
use Ajax\semantic\html\base\constants\Wide;
12+
use Ajax\JsUtils;
1213

1314
class HtmlTD extends HtmlSemDoubleElement {
1415
use TextAlignmentTrait,TableElementTrait;
@@ -17,6 +18,7 @@ class HtmlTD extends HtmlSemDoubleElement {
1718
private $_col;
1819
private $_colMerged=false;
1920
private $_rowMerged=false;
21+
private $_deleted=false;
2022

2123
/**
2224
*
@@ -49,7 +51,7 @@ public function addValue($value) {
4951
public function setRowspan($rowspan) {
5052
$to=min($this->_container->count(), $this->_row + $rowspan - 1);
5153
for($i=$to; $i > $this->_row; $i--) {
52-
$this->_container->delete($i, $this->_col);
54+
$this->_container->toDelete($i, $this->_col);
5355
}
5456
$this->setProperty("rowspan", $rowspan);
5557
return $this->_container;
@@ -74,7 +76,7 @@ public function mergeCol() {
7476
public function setColspan($colspan) {
7577
$to=min($this->_container->getRow($this->_row)->count(), $this->_col + $colspan - 1);
7678
for($i=$to; $i > $this->_col; $i--) {
77-
$this->_container->delete($this->_row, $this->_col + 1);
79+
$this->_container->toDelete($this->_row, $this->_col + 1);
7880
}
7981
$this->setProperty("colspan", $colspan);
8082
return $this->_container;
@@ -112,12 +114,23 @@ public function setSelectable($href="#") {
112114
}
113115
return $this->addToProperty("class", "selectable");
114116
}
115-
117+
116118
public function setWidth($width){
117119
if (\is_int($width)) {
118120
$width=Wide::getConstants()["W" . $width];
119121
}
120122
$this->addToPropertyCtrl("class", $width, Wide::getConstants());
121123
return $this->addToPropertyCtrl("class", "wide", array ("wide" ));
122124
}
125+
126+
public function toDelete(){
127+
$this->_deleted=true;
128+
return $this;
129+
}
130+
131+
public function compile(JsUtils $js=NULL, &$view=NULL) {
132+
if(!$this->_deleted)
133+
return parent::compile();
134+
return;
135+
}
123136
}

Ajax/semantic/html/content/table/HtmlTR.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,9 @@ public function applyCells($callback) {
177177
}
178178
return $this;
179179
}
180+
181+
public function toDelete($colIndex){
182+
$this->getItem($colIndex)->toDelete();
183+
return $this;
184+
}
180185
}

Ajax/semantic/html/content/table/HtmlTableContent.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,13 @@ public function delete($rowIndex, $colIndex=NULL) {
248248
return $this;
249249
}
250250

251+
public function toDelete($rowIndex, $colIndex){
252+
$row=$this->getItem($rowIndex);
253+
if (isset($row) === true)
254+
$row->toDelete($colIndex);
255+
return $this;
256+
}
257+
251258
public function mergeCol($rowIndex=0, $colIndex=0) {
252259
return $this->getItem($rowIndex)->mergeCol($colIndex);
253260
}
@@ -332,4 +339,28 @@ public function applyRows($callback) {
332339
}
333340
return $this;
334341
}
342+
343+
public function mergeIdentiqualValues($colIndex,$function="strip_tags"){
344+
$rows=$this->content;
345+
$identiqual=null;
346+
$counter=0;
347+
$cellToMerge=null;
348+
$functionExists=\function_exists($function);
349+
foreach ( $rows as $row ) {
350+
$cell=$row->getItem($colIndex);
351+
$value=$cell->getContent();
352+
if($functionExists)
353+
$value=\call_user_func($function,$value);
354+
if($value!==$identiqual){
355+
if($counter>0 && isset($cellToMerge)){
356+
$cellToMerge->setRowspan($counter);
357+
}
358+
$counter=0;
359+
$cellToMerge=$cell;
360+
$identiqual=$value;
361+
}
362+
$counter++;
363+
}
364+
return $this;
365+
}
335366
}

0 commit comments

Comments
 (0)