phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlGrid.php
Go to the documentation of this file.
1<?php
2
4
11
19 private $_createCols;
20 private $_colSizing=true;
21 private $_implicitRows=false;
22
23 public function __construct($identifier, $numRows=1, $numCols=NULL, $createCols=true, $implicitRows=false) {
24 parent::__construct($identifier, "div", "ui grid");
25 $this->_implicitRows=$implicitRows;
26 $this->_createCols=$createCols;
27 if (isset($numCols)) {
28 $this->_colSizing=false;
29 $this->setWide($numCols);
30 }
31 if($createCols)
32 $this->setRowsCount($numRows, $numCols);
33 }
34
35 public function asSegment() {
36 return $this->addToPropertyCtrl("class", "segment", array ("segment" ));
37 }
38
39 public function asContainer() {
40 return $this->addToPropertyCtrl("class", "container", array ("container" ));
41 }
42
47 public function setWide($wide) {
48 if(isset(Wide::getConstants()["W" . $wide])){
49 $wide=Wide::getConstants()["W" . $wide];
50 $this->addToPropertyCtrl("class", $wide, Wide::getConstants());
51 return $this->addToPropertyCtrl("class", "column", array ("column" ));
52 }
53 return $this;
54 }
55
61 public function setWidth($width) {
62 return $this->setWide($width);
63 }
64
70 public function addRow($colsCount=NULL) {
71 $rowCount=$this->rowCount() + 1;
72 $this->setRowsCount($rowCount, $colsCount, true);
73 return $this->content[$rowCount - 1];
74 }
75
81 public function addCol($width=NULL) {
82 $colCount=$this->colCount() + 1;
83 $this->setColsCount($colCount, true, $width);
84 if ($this->hasOnlyCols($this->count()))
85 return $this->content[$colCount - 1];
86 return $this;
87 }
88
94 public function addCols($sizes=array()) {
95 foreach ( $sizes as $size ) {
96 $this->addCol($size);
97 }
98 return $this;
99 }
100
107 public function setRowsCount($rowsCount, $colsCount=NULL, $force=false) {
108 $count=$this->count();
109 if ($rowsCount < 2 && $force === false) {
110 for($i=$count; $i < $colsCount; $i++) {
111 $this->addItem(new HtmlGridCol("col-" . $this->identifier . "-" . $i));
112 }
113 } else {
114 if ($this->hasOnlyCols($count)) {
115 $tmpContent=$this->content;
116 $item=$this->addItem($colsCount);
117 $item->setContent($tmpContent);
118 $this->content=array ();
119 $count=1;
120 }
121 for($i=$count; $i < $rowsCount; $i++) {
122 $this->addItem($colsCount);
123 }
124 }
125 return $this;
126 }
127
128 protected function hasOnlyCols($count) {
129 return $count > 0 && $this->content[0] instanceof HtmlGridCol;
130 }
131
139 public function setColsCount($numCols, $toCreate=true, $width=NULL) {
140 if (isset($width)===false) {
141 $this->setWide($numCols);
142 }
143 if ($toCreate === true) {
144 $count=$this->count();
145 if ($count == 0 || $this->hasOnlyCols($count)) {
146 for($i=$count; $i < $numCols; $i++) {
147 $this->addItem(new HtmlGridCol("col-" . $this->identifier . "-" . $i, $width));
148 }
149 } else {
150 for($i=0; $i < $count; $i++) {
151 $this->getItem($i)->setColsCount($numCols);
152 }
153 }
154 }
155 return $this;
156 }
157
163 public function getRow($index) {
164 return $this->getItem($index);
165 }
166
170 public function getItem($index){
171 return parent::getItem($index);
172 }
173
178 public function rowCount() {
179 $count=$this->count();
180 if ($this->hasOnlyCols($count))
181 return 0;
182 return $count;
183 }
184
189 public function colCount() {
190 $count=$this->count();
191 if ($this->hasOnlyCols($count))
192 return $count;
193 if ($count > 0)
194 return $this->getItem(0)->count();
195 return 0;
196 }
197
204 public function getCell($row, $col) {
205 if ($row < 2 && $this->hasOnlyCols($this->count()))
206 return $this->getItem($col);
207 $rowO=$this->getItem($row);
208 if (isset($rowO)) {
209 $colO=$rowO->getItem($col);
210 }
211 return $colO;
212 }
213
219 public function setDivided($vertically=false) {
220 $value=($vertically === true) ? "vertically divided" : "divided";
221 return $this->addToPropertyCtrl("class", $value, array ("divided" ));
222 }
223
229 public function setCelled($internally=false) {
230 $value=($internally === true) ? "internally celled" : "celled";
231 return $this->addToPropertyCtrl("class", $value, array ("celled","internally celled" ));
232 }
233
237 public function setCentered() {
238 return $this->addToPropertyCtrl("class", "centered", array ("centered" ));
239 }
240
245 public function setEqualWidth() {
246 return $this->addToProperty("class", "equal width");
247 }
248
254 public function setPadded($value=NULL) {
255 if (isset($value))
256 $this->addToPropertyCtrl("class", $value, array ("vertically","horizontally" ));
257 return $this->addToProperty("class", "padded");
258 }
259
265 public function setRelaxed($very=false) {
266 $value=($very === true) ? "very relaxed" : "relaxed";
267 return $this->addToPropertyCtrl("class", $value, array ("relaxed","very relaxed" ));
268 }
269
271 return $this->addToPropertyCtrl("class", $value . " aligned", VerticalAlignment::getConstantValues("aligned"));
272 }
273
280 protected function createItem($value) {
281 if ($this->_createCols === false)
282 $value=null;
283 $item=new HtmlGridRow($this->identifier . "-row-" . ($this->count() + 1), $value, $this->_colSizing, $this->_implicitRows);
284 return $item;
285 }
286
291 public function setValues($values, $force=true) {
292 $count=$this->count();
293 $valuesSize=\sizeof($values);
294 if ($this->_createCols === false || $force === true) {
295 for($i=$count; $i < $valuesSize; $i++) {
296 $colSize=\sizeof($values[$i]);
297 $this->addItem(new HtmlGridRow($this->identifier . "-row-" . ($this->count() + 1), $colSize, $this->_colSizing, $this->_implicitRows));
298 }
299 }
300 $count=\min(array ($this->count(),$valuesSize ));
301 for($i=0; $i < $count; $i++) {
302 $this->content[$i]->setValues($values[$i], $this->_createCols === false);
303 }
304 }
305
306 public function setColWidth($numCol,$width){
307 foreach ($this->content as $row){
308 $row->getCol($numCol)->setWidth($width);
309 }
310 return $this;
311 }
312
317 public function setStretched() {
318 return $this->addToProperty("class", "stretched");
319 }
320
328 public function addDivider($afterColIndex, $vertical=true, $content=NULL) {
329 $col=$this->getCell(0, $afterColIndex);
330 if($col instanceof HtmlGridCol)
331 $col->addDivider($vertical, $content);
332 return $this;
333 }
334}
static getConstantValues($postFix="", $prefixBefore=false)
Definition BaseEnum.php:29
addItem($item)
adds and returns an item
Base class for Semantic Html collections.
addToProperty($name, $value, $separator=" ")
setRowsCount($rowsCount, $colsCount=NULL, $force=false)
Create $rowsCount rows.
Definition HtmlGrid.php:107
setVerticalAlignment($value=VerticalAlignment::MIDDLE)
Definition HtmlGrid.php:270
setWide($wide)
Defines the grid width (alias for setWidth)
Definition HtmlGrid.php:47
createItem($value)
The item factory.
Definition HtmlGrid.php:280
addRow($colsCount=NULL)
Adds a row with $colsCount columns.
Definition HtmlGrid.php:70
addCol($width=NULL)
Adds a col.
Definition HtmlGrid.php:81
setDivided($vertically=false)
Adds dividers between columns ($vertically=false) or between rows ($vertically=true)
Definition HtmlGrid.php:219
setCentered()
A grid can have its columns centered.
Definition HtmlGrid.php:237
__construct($identifier, $numRows=1, $numCols=NULL, $createCols=true, $implicitRows=false)
Definition HtmlGrid.php:23
colCount()
Returns the column count.
Definition HtmlGrid.php:189
addDivider($afterColIndex, $vertical=true, $content=NULL)
Adds a divider after the specified col.
Definition HtmlGrid.php:328
getCell($row, $col)
Returns the cell (HtmlGridCol) at position $row,$col.
Definition HtmlGrid.php:204
rowCount()
Returns the row count.
Definition HtmlGrid.php:178
getRow($index)
return the row at $index
Definition HtmlGrid.php:163
setEqualWidth()
automatically resize all elements to split the available width evenly
Definition HtmlGrid.php:245
setCelled($internally=false)
Divides rows into cells.
Definition HtmlGrid.php:229
setWidth($width)
Defines the grid width.
Definition HtmlGrid.php:61
setValues($values, $force=true)
Sets $values to the grid.
Definition HtmlGrid.php:291
setStretched()
stretch the row contents to take up the entire column height
Definition HtmlGrid.php:317
setColsCount($numCols, $toCreate=true, $width=NULL)
Defines the number of columns in the grid.
Definition HtmlGrid.php:139
setPadded($value=NULL)
Adds vertical or/and horizontal gutters.
Definition HtmlGrid.php:254
A col in the Semantic Grid component.
A row for the Semantic Grid component.