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