1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\content\table; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\HtmlSemDoubleElement; |
6
|
|
|
use Ajax\semantic\html\base\traits\TextAlignmentTrait; |
7
|
|
|
use Ajax\semantic\html\base\constants\Variation; |
8
|
|
|
use Ajax\semantic\html\base\constants\State; |
9
|
|
|
use Ajax\semantic\html\base\traits\TableElementTrait; |
10
|
|
|
use Ajax\semantic\html\elements\html5\HtmlLink; |
11
|
|
|
use Ajax\semantic\html\base\constants\Wide; |
12
|
|
|
use Ajax\JsUtils; |
13
|
|
|
|
14
|
|
|
class HtmlTD extends HtmlSemDoubleElement { |
15
|
|
|
use TextAlignmentTrait,TableElementTrait; |
16
|
|
|
private $_container; |
17
|
|
|
private $_row; |
18
|
|
|
private $_col; |
19
|
|
|
private $_colMerged=false; |
20
|
|
|
private $_rowMerged=false; |
21
|
|
|
private $_deleted=false; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* |
25
|
|
|
* @param string $identifier |
26
|
|
|
* @param mixed $content |
27
|
|
|
* @param string $tagName |
28
|
|
|
*/ |
29
|
|
|
public function __construct($identifier, $content=NULL, $tagName="td") { |
30
|
|
|
parent::__construct($identifier, $tagName, "", $content); |
31
|
|
|
$this->_variations=[ Variation::COLLAPSING ]; |
32
|
|
|
$this->_states=[ State::ACTIVE,State::POSITIVE,State::NEGATIVE,State::WARNING,State::ERROR,State::DISABLED ]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function setContainer($container, $row, $col) { |
36
|
|
|
$this->_container=$container; |
37
|
|
|
$this->_row=$row; |
38
|
|
|
$this->_col=$col; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function setValue($value) { |
42
|
|
|
$this->content=$value; |
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function addValue($value) { |
47
|
|
|
$this->addContent($value); |
48
|
|
|
return $this; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function setRowspan($rowspan) { |
52
|
|
|
$to=min($this->_container->count(), $this->_row + $rowspan - 1); |
53
|
|
View Code Duplication |
for($i=$to; $i > $this->_row; $i--) { |
|
|
|
|
54
|
|
|
$this->_container->toDelete($i, $this->_col); |
55
|
|
|
} |
56
|
|
|
$this->setProperty("rowspan", $rowspan); |
57
|
|
|
return $this->_container; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function mergeRow() { |
61
|
|
|
if(!$this->_rowMerged){ |
62
|
|
|
$this->_rowMerged=true; |
63
|
|
|
return $this->setRowspan($this->_container->count()); |
64
|
|
|
} |
65
|
|
|
return $this->_container; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
public function mergeCol() { |
69
|
|
|
if(!$this->_colMerged){ |
70
|
|
|
$this->_colMerged=true; |
71
|
|
|
return $this->setColspan($this->_container->getRow($this->_row)->count()); |
72
|
|
|
} |
73
|
|
|
return $this->_container; |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function setColspan($colspan) { |
77
|
|
|
$to=min($this->_container->getRow($this->_row)->count(), $this->_col + $colspan - 1); |
78
|
|
View Code Duplication |
for($i=$to; $i > $this->_col; $i--) { |
|
|
|
|
79
|
|
|
$this->_container->toDelete($this->_row, $this->_col + 1); |
80
|
|
|
} |
81
|
|
|
$this->setProperty("colspan", $colspan); |
82
|
|
|
return $this->_container; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function getColspan() { |
86
|
|
|
$colspan=1; |
87
|
|
|
if (\array_key_exists("colspan", $this->properties)) |
88
|
|
|
$colspan=$this->getProperty("colspan"); |
89
|
|
|
return $colspan; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function getRowspan() { |
93
|
|
|
$rowspan=1; |
94
|
|
|
if (\array_key_exists("rowspan", $this->properties)) |
95
|
|
|
$rowspan=$this->getProperty("rowspan"); |
96
|
|
|
return $rowspan; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
public function conditionalCellFormat($callback, $format) { |
100
|
|
|
if ($callback($this)) { |
101
|
|
|
$this->addToProperty("class", $format); |
102
|
|
|
} |
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function apply($callback) { |
107
|
|
|
$callback($this); |
108
|
|
|
return $this; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function setSelectable($href="#") { |
112
|
|
|
if (\is_string($this->content)) { |
113
|
|
|
$this->content=new HtmlLink("", $href, $this->content); |
114
|
|
|
} |
115
|
|
|
return $this->addToProperty("class", "selectable"); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
View Code Duplication |
public function setWidth($width){ |
|
|
|
|
119
|
|
|
if (\is_int($width)) { |
120
|
|
|
$width=Wide::getConstants()["W" . $width]; |
121
|
|
|
} |
122
|
|
|
$this->addToPropertyCtrl("class", $width, Wide::getConstants()); |
123
|
|
|
return $this->addToPropertyCtrl("class", "wide", array ("wide" )); |
124
|
|
|
} |
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
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.