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\Wide; |
8
|
|
|
use Ajax\semantic\html\base\TextAlignment; |
9
|
|
|
use Ajax\semantic\html\base\VerticalAlignment; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Semantic Grid component |
13
|
|
|
* @see http://semantic-ui.com/collections/grid.html |
14
|
|
|
* @author jc |
15
|
|
|
* @version 1.001 |
16
|
|
|
*/ |
17
|
|
|
class HtmlGrid extends HtmlCollection{ |
18
|
|
|
|
19
|
|
|
private $_createCols; |
20
|
|
|
private $_colSizing=true; |
21
|
|
|
public function __construct( $identifier,$numRows=1,$numCols=NULL,$createCols=true){ |
22
|
|
|
parent::__construct( $identifier, "div"); |
23
|
|
|
$this->_createCols=$createCols; |
24
|
|
|
if(isset($numCols)){ |
25
|
|
|
//if($this->_createCols){ |
|
|
|
|
26
|
|
|
$this->_colSizing=false; |
27
|
|
|
//} |
28
|
|
|
$cols=Wide::getConstants()["W".$numCols]; |
29
|
|
|
$this->setClass($cols." column"); |
30
|
|
|
} |
31
|
|
|
$this->addToProperty("class","ui grid"); |
32
|
|
|
$this->setNumRows($numRows,$numCols); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Create $numRows rows |
37
|
|
|
* @param int $numRows |
38
|
|
|
* @param int $numCols |
39
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
40
|
|
|
*/ |
41
|
|
|
public function setNumRows($numRows,$numCols=NULL){ |
42
|
|
|
$count=$this->count(); |
43
|
|
|
for($i=$count;$i<$numRows;$i++){ |
44
|
|
|
$this->addItem($numCols); |
45
|
|
|
} |
46
|
|
|
return $this; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* return the row at $index |
51
|
|
|
* @param int $index |
52
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGridRow |
53
|
|
|
*/ |
54
|
|
|
public function getRow($index){ |
55
|
|
|
return $this->getItem($index); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @param int $row |
60
|
|
|
* @param int $col |
61
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGridCol |
62
|
|
|
*/ |
63
|
|
|
public function getCell($row,$col){ |
64
|
|
|
$row=$this->getItem($row); |
65
|
|
|
if(isset($row)){ |
66
|
|
|
$col=$row->getItem($col); |
67
|
|
|
} |
68
|
|
|
return $col; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Adds dividers between columns ($vertically=false) or between rows ($vertically=true) |
73
|
|
|
* @param boolean $vertically |
74
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
75
|
|
|
*/ |
76
|
|
|
public function setDivided($vertically=false){ |
77
|
|
|
$value=($vertically===true)?"vertically divided":"divided"; |
78
|
|
|
return $this->addToProperty("class", $value); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Divides rows into cells |
83
|
|
|
* @param boolean $internal true for internal cells |
84
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
85
|
|
|
*/ |
86
|
|
|
public function setCelled($internal=false){ |
87
|
|
|
$value=($internal===true)?"internal celled":"celled"; |
88
|
|
|
return $this->addToProperty("class", $value); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* automatically resize all elements to split the available width evenly |
93
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
94
|
|
|
*/ |
95
|
|
|
public function setEqualWidth(){ |
96
|
|
|
return $this->addToProperty("class", "equal width"); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Adds vertical or/and horizontal gutters |
101
|
|
|
* @param string $value |
102
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
103
|
|
|
*/ |
104
|
|
|
public function setPadded($value=NULL){ |
105
|
|
|
if(isset($value)) |
106
|
|
|
$this->addToPropertyCtrl("class", $value,array("vertically","horizontally")); |
107
|
|
|
return $this->addToProperty("class", "padded"); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* @param boolean $very |
112
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
113
|
|
|
*/ |
114
|
|
|
public function setRelaxed($very=false){ |
115
|
|
|
$value=($very===true)?"very relaxed":"relaxed"; |
116
|
|
|
return $this->addToProperty("class", $value); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function setTextAlignment($value=TextAlignment::LEFT){ |
120
|
|
|
return $this->addToPropertyCtrl("class", $value,TextAlignment::getConstants()); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
public function setVerticalAlignment($value=VerticalAlignment::MIDDLE){ |
124
|
|
|
return $this->addToPropertyCtrl("class", $value,VerticalAlignment::getConstants()); |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* {@inheritDoc} |
129
|
|
|
* @see \Ajax\common\html\HtmlCollection::createItem() |
130
|
|
|
*/ |
131
|
|
|
protected function createItem($value){ |
132
|
|
|
if($this->_createCols===false) |
133
|
|
|
$value=null; |
134
|
|
|
$item=new HtmlGridRow($this->identifier."-row-".($this->count()+1),$value,$this->_colSizing); |
135
|
|
|
return $item; |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
public function setValues($values){ |
139
|
|
|
$count=$this->count(); |
140
|
|
|
if($this->_createCols===false){ |
141
|
|
|
for($i=$count;$i<\sizeof($values);$i++){ |
|
|
|
|
142
|
|
|
$colSize=\sizeof($values[$i]); |
143
|
|
|
$this->addItem(new HtmlGridRow($this->identifier."-row-".($this->count()+1),$colSize,$this->_colSizing)); |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
$count=\min(array($this->count(),\sizeof($values))); |
147
|
|
|
for($i=0;$i<$count;$i++){ |
148
|
|
|
$this->content[$i]->setValues($values[$i],$this->_createCols===false); |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
} |
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.