phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
HtmlTD.php
Go to the documentation of this file.
1 <?php
3 
11 use Ajax\JsUtils;
12 
15 
16  private $_container;
17 
18  private $_row;
19 
20  private $_col;
21 
22  private $_colMerged = false;
23 
24  private $_rowMerged = false;
25 
26  private $_deleted = false;
27 
34  public function __construct($identifier, $content = NULL, $tagName = "td") {
35  parent::__construct($identifier, $tagName, "", $content);
36  $this->_variations = [
38  ];
39  $this->_states = [
46  ];
47  }
48 
49  public function setContainer($container, $row, $col) {
50  $this->_container = $container;
51  $this->_row = $row;
52  $this->_col = $col;
53  }
54 
55  public function setValue($value) {
56  $this->content = $value;
57  return $this;
58  }
59 
60  public function addValue($value) {
61  $this->addContent($value);
62  return $this;
63  }
64 
65  public function setRowspan($rowspan) {
66  $to = min($this->_container->count(), $this->_row + $rowspan - 1);
67  for ($i = $to; $i > $this->_row; $i --) {
68  $this->_container->toDelete($i, $this->_col);
69  }
70  $this->setProperty("rowspan", $rowspan);
71  return $this->_container->_setMerged(true);
72  }
73 
74  public function setRowspanned($rowspan) {
75  $to = min($this->_container->count(), $this->_row + $rowspan - 1);
76  for ($i = $to; $i > $this->_row; $i --) {
77  $this->_container->toRowspanned($i, $this->_col);
78  }
79  $this->setProperty("rowspan", $rowspan);
80  return $this->_container->_setMerged(true);
81  }
82 
83  public function mergeRow() {
84  if (! $this->_rowMerged) {
85  $this->_rowMerged = true;
86  return $this->setRowspan($this->_container->count());
87  }
88  return $this->_container;
89  }
90 
91  public function mergeCol() {
92  if (! $this->_colMerged) {
93  $this->_colMerged = true;
94  return $this->setColspan($this->_container->getRow($this->_row)
95  ->count());
96  }
97  return $this->_container;
98  }
99 
100  public function setColspan($colspan) {
101  $to = min($this->_container->getRow($this->_row)->count(), $this->_col + $colspan - 1);
102  for ($i = $to; $i > $this->_col; $i --) {
103  $this->_container->delete($this->_row, $this->_col + 1);
104  }
105  $this->setProperty("colspan", $colspan);
106  return $this->_container;
107  }
108 
109  public function getColspan() {
110  $colspan = 1;
111  if (\array_key_exists("colspan", $this->properties))
112  $colspan = $this->getProperty("colspan");
113  return $colspan;
114  }
115 
116  public function getRowspan() {
117  $rowspan = 1;
118  if (\array_key_exists("rowspan", $this->properties))
119  $rowspan = $this->getProperty("rowspan");
120  return $rowspan;
121  }
122 
123  public function conditionalCellFormat($callback, $format) {
124  if ($callback($this)) {
125  $this->addToProperty("class", $format);
126  }
127  return $this;
128  }
129 
130  public function apply($callback) {
131  $callback($this);
132  return $this;
133  }
134 
135  public function setSelectable($href = "#") {
136  if (\is_string($this->content)) {
137  $this->content = new HtmlLink("", $href, $this->content);
138  }
139  return $this->addToProperty("class", "selectable");
140  }
141 
142  public function setWidth($width) {
143  if (\is_int($width)) {
144  $width = Wide::getConstants()["W" . $width];
145  }
146  $this->addToPropertyCtrl("class", $width, Wide::getConstants());
147  return $this->addToPropertyCtrl("class", "wide", array(
148  "wide"
149  ));
150  }
151 
152  public function toDelete() {
153  $this->_deleted = true;
154  return $this;
155  }
156 
157  public function compile(JsUtils $js = NULL, &$view = NULL) {
158  if (! $this->_deleted)
159  return parent::compile($js, $view);
160  }
161 }
addToProperty($name, $value, $separator=" ")
static getConstants()
Definition: BaseEnum.php:17
addContent($content, $before=false)
conditionalCellFormat($callback, $format)
Definition: HtmlTD.php:123
Base class for Semantic double elements.
JQuery PHP library.
Definition: JsUtils.php:23
__construct($identifier, $content=NULL, $tagName="td")
Definition: HtmlTD.php:34
compile(JsUtils $js=NULL, &$view=NULL)
Definition: HtmlTD.php:157
setContainer($container, $row, $col)
Definition: HtmlTD.php:49
addToPropertyCtrl($name, $value, $typeCtrl)