1
|
|
|
<?php |
2
|
|
|
namespace Ajax\bootstrap\html; |
3
|
|
|
|
4
|
|
|
use Ajax\bootstrap\html\base\HtmlBsDoubleElement; |
5
|
|
|
use Ajax\bootstrap\html\content\HtmlGridRow; |
6
|
|
|
use Ajax\bootstrap\html\content\HtmlGridCol; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Composant Twitter Bootstrap Grid system |
12
|
|
|
* @see http://getbootstrap.com/css/#grid |
13
|
|
|
* @author jc |
14
|
|
|
* @version 1.001 |
15
|
|
|
*/ |
16
|
|
|
class HtmlGridSystem extends HtmlBsDoubleElement { |
17
|
|
|
private $rows; |
18
|
|
|
|
19
|
|
|
public function __construct($identifier,$numRows=1,$numCols=NULL){ |
20
|
|
|
parent::__construct($identifier,"div"); |
21
|
|
|
$this->setProperty("class", "container-fluid"); |
22
|
|
|
$this->rows=array(); |
23
|
|
|
$this->setNumRows($numRows,$numCols); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Add a new row |
28
|
|
|
* @param int $numCols |
29
|
|
|
* @return \Ajax\bootstrap\html\content\HtmlGridRow |
30
|
|
|
*/ |
31
|
|
|
public function addRow($numCols=NULL){ |
32
|
|
|
$row=new HtmlGridRow($this->identifier."-row-".(sizeof($this->rows)+1),$numCols); |
33
|
|
|
$this->rows[]=$row; |
34
|
|
|
return $row; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* return the row at $index |
39
|
|
|
* @param int $index |
40
|
|
|
* @param boolean $force add the row at $index if true |
41
|
|
|
* @return \Ajax\bootstrap\html\content\HtmlGridRow |
42
|
|
|
*/ |
43
|
|
|
public function getRow($index,$force=true){ |
44
|
|
|
if($index<sizeof($this->rows)){ |
45
|
|
|
$result=$this->rows[$index-1]; |
46
|
|
|
}else if ($force){ |
47
|
|
|
$this->setNumRows($index); |
48
|
|
|
$result=$this->rows[$index-1]; |
49
|
|
|
} |
50
|
|
|
return $result; |
|
|
|
|
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Create $numRows rows |
55
|
|
|
* @param int $numRows |
56
|
|
|
* @param int $numCols |
57
|
|
|
* @return \Ajax\bootstrap\html\HtmlGridSystem |
58
|
|
|
*/ |
59
|
|
|
public function setNumRows($numRows,$numCols=NULL){ |
60
|
|
|
for($i=sizeof($this->rows);$i<$numRows;$i++){ |
61
|
|
|
$this->addRow($numCols); |
62
|
|
|
} |
63
|
|
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param int $row |
68
|
|
|
* @param int $col |
69
|
|
|
* @param boolean $force add the cell at $row,$col if true |
70
|
|
|
* @return HtmlGridCol |
71
|
|
|
*/ |
72
|
|
|
public function getCell($row,$col,$force=true){ |
73
|
|
|
$row=$this->getRow($row,$force); |
74
|
|
|
if(isset($row)){ |
75
|
|
|
$col=$row->getCol($col,$force); |
76
|
|
|
} |
77
|
|
|
return $col; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @param int $row |
82
|
|
|
* @param int $col |
83
|
|
|
* @return HtmlGridCol |
84
|
|
|
*/ |
85
|
|
|
public function getCellAt($row,$col,$force=true){ |
86
|
|
|
$row=$this->getRow($row,$force); |
87
|
|
|
if(isset($row)){ |
88
|
|
|
$col=$row->getColAt($col,$force); |
89
|
|
|
} |
90
|
|
|
return $col; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function compile(JsUtils $js=NULL, &$view=NULL) { |
94
|
|
|
foreach ($this->rows as $row){ |
95
|
|
|
$this->addContent($row); |
96
|
|
|
} |
97
|
|
|
return parent::compile($js,$view); |
98
|
|
|
} |
99
|
|
|
public function setContentForAll($content){ |
100
|
|
|
foreach ($this->rows as $row){ |
101
|
|
|
$row->setContentForAll($content); |
102
|
|
|
} |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|