|
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
|
|
|
/** |
|
9
|
|
|
* Semantic Grid component |
|
10
|
|
|
* @see http://semantic-ui.com/collections/grid.html |
|
11
|
|
|
* @author jc |
|
12
|
|
|
* @version 1.001 |
|
13
|
|
|
*/ |
|
14
|
|
|
class HtmlGrid extends HtmlCollection{ |
|
15
|
|
|
|
|
16
|
|
|
private $_createCols; |
|
17
|
|
|
private $_colSizing=true; |
|
18
|
|
|
public function __construct( $identifier,$numRows=1,$numCols=NULL,$createCols=true){ |
|
19
|
|
|
parent::__construct( $identifier, "div"); |
|
20
|
|
|
$this->_createCols=$createCols; |
|
21
|
|
|
if(isset($numCols)){ |
|
22
|
|
|
if($this->_createCols){ |
|
23
|
|
|
$this->_colSizing=false; |
|
24
|
|
|
} |
|
25
|
|
|
$cols=Wide::getConstants()["W".$numCols]; |
|
26
|
|
|
$this->setClass($cols." column"); |
|
27
|
|
|
} |
|
28
|
|
|
$this->addToProperty("class","ui grid"); |
|
29
|
|
|
$this->setNumRows($numRows,$numCols); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Create $numRows rows |
|
34
|
|
|
* @param int $numRows |
|
35
|
|
|
* @param int $numCols |
|
36
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
|
37
|
|
|
*/ |
|
38
|
|
|
public function setNumRows($numRows,$numCols=NULL){ |
|
39
|
|
|
$count=$this->count(); |
|
40
|
|
|
for($i=$count;$i<$numRows;$i++){ |
|
41
|
|
|
$this->addItem($numCols); |
|
42
|
|
|
} |
|
43
|
|
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* return the row at $index |
|
48
|
|
|
* @param int $index |
|
49
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGridRow |
|
50
|
|
|
*/ |
|
51
|
|
|
public function getRow($index){ |
|
52
|
|
|
return $this->getItem($index); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param int $row |
|
57
|
|
|
* @param int $col |
|
58
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGridCol |
|
59
|
|
|
*/ |
|
60
|
|
|
public function getCell($row,$col){ |
|
61
|
|
|
$row=$this->getItem($row); |
|
62
|
|
|
if(isset($row)){ |
|
63
|
|
|
$col=$row->getItem($col); |
|
64
|
|
|
} |
|
65
|
|
|
return $col; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Adds dividers between columns ($vertically=false) or between rows ($vertically=true) |
|
70
|
|
|
* @param boolean $vertically |
|
71
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
|
72
|
|
|
*/ |
|
73
|
|
|
public function setDivided($vertically=false){ |
|
74
|
|
|
$value=($vertically===true)?"vertically divided":"divided"; |
|
75
|
|
|
return $this->addToProperty("class", $value); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Divides rows into cells |
|
80
|
|
|
* @param boolean $internal true for internal cells |
|
81
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGrid |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setCelled($internal=false){ |
|
84
|
|
|
$value=($internal===true)?"internal celled":"celled"; |
|
85
|
|
|
return $this->addToProperty("class", $value); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function setEqualWidth(){ |
|
89
|
|
|
return $this->addToProperty("class", "equal width"); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* {@inheritDoc} |
|
94
|
|
|
* @see \Ajax\common\html\HtmlCollection::createItem() |
|
95
|
|
|
*/ |
|
96
|
|
|
protected function createItem($value){ |
|
97
|
|
|
if($this->_createCols===false) |
|
98
|
|
|
$value=null; |
|
99
|
|
|
$item=new HtmlGridRow($this->identifier."-row-".($this->count()+1),$value,$this->_colSizing); |
|
100
|
|
|
return $item; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
} |