1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\collections; |
4
|
|
|
|
5
|
|
|
use Ajax\common\html\HtmlCollection; |
6
|
|
|
use Ajax\semantic\html\content\HtmlGridRow; |
7
|
|
|
use Ajax\semantic\html\base\constants\Wide; |
8
|
|
|
use Ajax\semantic\html\base\constants\VerticalAlignment; |
9
|
|
|
use Ajax\semantic\html\base\HtmlSemCollection; |
10
|
|
|
use Ajax\semantic\html\base\traits\TextAlignmentTrait; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Semantic Grid component |
14
|
|
|
* @see http://semantic-ui.com/collections/grid.html |
15
|
|
|
* @author jc |
16
|
|
|
* @version 1.001 |
17
|
|
|
*/ |
18
|
|
|
class HtmlGrid extends HtmlSemCollection{ |
19
|
|
|
use TextAlignmentTrait; |
20
|
|
|
private $_createCols; |
21
|
|
|
private $_colSizing=true; |
22
|
|
|
private $_implicitRows=false; |
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
|
|
|
//if($this->_createCols){ |
|
|
|
|
29
|
|
|
$this->_colSizing=false; |
30
|
|
|
//} |
31
|
|
|
$this->setWide($numCols); |
32
|
|
|
} |
33
|
|
|
$this->setNumRows($numRows,$numCols); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function setWide($wide){ |
37
|
|
|
$wide=Wide::getConstants()["W".$wide]; |
38
|
|
|
$this->addToPropertyCtrl("class", $wide, Wide::getConstants()); |
39
|
|
|
return $this->addToPropertyCtrl("class","column",array("column")); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Create $numRows rows |
44
|
|
|
* @param int $numRows |
45
|
|
|
* @param int $numCols |
46
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function setNumRows($numRows,$numCols=NULL){ |
|
|
|
|
49
|
|
|
$count=$this->count(); |
50
|
|
|
for($i=$count;$i<$numRows;$i++){ |
51
|
|
|
$this->addItem($numCols); |
52
|
|
|
} |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function setNumCols($numCols){ |
57
|
|
|
$count=$this->count(); |
58
|
|
|
for($i=0;$i<$count;$i++){ |
59
|
|
|
$this->getItem($i)->setNumCols($numCols); |
|
|
|
|
60
|
|
|
} |
61
|
|
|
//if($this->_colSizing===false) |
|
|
|
|
62
|
|
|
$this->setWide($numCols); |
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* return the row at $index |
68
|
|
|
* @param int $index |
69
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGridRow |
70
|
|
|
*/ |
71
|
|
|
public function getRow($index){ |
72
|
|
|
return $this->getItem($index); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @param int $row |
77
|
|
|
* @param int $col |
78
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGridCol |
79
|
|
|
*/ |
80
|
|
|
public function getCell($row,$col){ |
81
|
|
|
$row=$this->getItem($row); |
82
|
|
|
if(isset($row)){ |
83
|
|
|
$col=$row->getItem($col); |
84
|
|
|
} |
85
|
|
|
return $col; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Adds dividers between columns ($vertically=false) or between rows ($vertically=true) |
90
|
|
|
* @param boolean $vertically |
91
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
92
|
|
|
*/ |
93
|
|
|
public function setDivided($vertically=false){ |
94
|
|
|
$value=($vertically===true)?"vertically divided":"divided"; |
95
|
|
|
return $this->addToPropertyCtrl("class", $value,array("divided")); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Divides rows into cells |
100
|
|
|
* @param boolean $internal true for internal cells |
101
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
102
|
|
|
*/ |
103
|
|
|
public function setCelled($internal=false){ |
104
|
|
|
$value=($internal===true)?"internal celled":"celled"; |
105
|
|
|
return $this->addToProperty("class", $value); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* automatically resize all elements to split the available width evenly |
110
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
111
|
|
|
*/ |
112
|
|
|
public function setEqualWidth(){ |
113
|
|
|
return $this->addToProperty("class", "equal width"); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Adds vertical or/and horizontal gutters |
118
|
|
|
* @param string $value |
119
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
120
|
|
|
*/ |
121
|
|
|
public function setPadded($value=NULL){ |
122
|
|
|
if(isset($value)) |
123
|
|
|
$this->addToPropertyCtrl("class", $value,array("vertically","horizontally")); |
124
|
|
|
return $this->addToProperty("class", "padded"); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param boolean $very |
129
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
130
|
|
|
*/ |
131
|
|
|
public function setRelaxed($very=false){ |
132
|
|
|
$value=($very===true)?"very relaxed":"relaxed"; |
133
|
|
|
return $this->addToProperty("class", $value); |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function setVerticalAlignment($value=VerticalAlignment::MIDDLE){ |
137
|
|
|
return $this->addToPropertyCtrl("class", $value." aligned",VerticalAlignment::getConstantValues("aligned")); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* {@inheritDoc} |
142
|
|
|
* @see \Ajax\common\html\HtmlCollection::createItem() |
143
|
|
|
*/ |
144
|
|
|
protected function createItem($value){ |
145
|
|
|
if($this->_createCols===false) |
146
|
|
|
$value=null; |
147
|
|
|
$item=new HtmlGridRow($this->identifier."-row-".($this->count()+1),$value,$this->_colSizing,$this->_implicitRows); |
148
|
|
|
return $item; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function setValues($values){ |
152
|
|
|
$count=$this->count(); |
153
|
|
|
if($this->_createCols===false){ |
154
|
|
|
for($i=$count;$i<\sizeof($values);$i++){ |
|
|
|
|
155
|
|
|
$colSize=\sizeof($values[$i]); |
156
|
|
|
$this->addItem(new HtmlGridRow($this->identifier."-row-".($this->count()+1),$colSize,$this->_colSizing,$this->_implicitRows)); |
157
|
|
|
} |
158
|
|
|
} |
159
|
|
|
$count=\min(array($this->count(),\sizeof($values))); |
160
|
|
|
for($i=0;$i<$count;$i++){ |
161
|
|
|
$this->content[$i]->setValues($values[$i],$this->_createCols===false); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function rowCount(){ |
166
|
|
|
return $this->count(); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
public function colCount(){ |
170
|
|
|
$result=0; |
171
|
|
|
if($this->count()>0){ |
172
|
|
|
$result=$this->content[0]->count(); |
173
|
|
|
} |
174
|
|
|
return $result; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
} |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.