1
|
|
|
<?php |
2
|
|
|
namespace Ajax\bootstrap\html; |
3
|
|
|
|
4
|
|
|
use Ajax\bootstrap\html\base\HtmlDoubleElement; |
5
|
|
|
use Ajax\bootstrap\html\content\HtmlGridRow; |
6
|
|
|
use Ajax\bootstrap\html\content\HtmlGridCol; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
use Phalcon\Mvc\View; |
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 HtmlDoubleElement { |
17
|
|
|
private $rows; |
18
|
|
|
|
19
|
|
|
public function __construct($identifier,$numRows=1){ |
20
|
|
|
parent::__construct($identifier,"div"); |
21
|
|
|
$this->setProperty("class", "container"); |
22
|
|
|
$this->rows=array(); |
23
|
|
|
$this->setNumRows($numRows); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @return \Ajax\bootstrap\html\content\HtmlGridRow |
28
|
|
|
*/ |
29
|
|
|
public function addRow(){ |
30
|
|
|
$row=new HtmlGridRow($this->identifier."-row-".(sizeof($this->rows)+1)); |
31
|
|
|
$this->rows[]=$row; |
32
|
|
|
return $row; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param int $index |
37
|
|
|
* @return \Ajax\bootstrap\html\content\HtmlGridRow |
38
|
|
|
*/ |
39
|
|
View Code Duplication |
public function getRow($index,$force=true){ |
|
|
|
|
40
|
|
|
if($index<sizeof($this->rows)){ |
41
|
|
|
$result=$this->rows[$index-1]; |
42
|
|
|
}else if ($force){ |
43
|
|
|
$this->setNumRows($index); |
44
|
|
|
$result=$this->rows[$index-1]; |
45
|
|
|
} |
46
|
|
|
return $result; |
|
|
|
|
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function setNumRows($numRows){ |
50
|
|
|
for($i=sizeof($this->rows);$i<$numRows;$i++){ |
51
|
|
|
$this->addRow(); |
52
|
|
|
} |
53
|
|
|
return $this; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @param int $row |
58
|
|
|
* @param int $col |
59
|
|
|
* @return HtmlGridCol |
60
|
|
|
*/ |
61
|
|
|
public function getCell($row,$col,$force=true){ |
62
|
|
|
$row=$this->getRow($row,$force); |
63
|
|
|
if(isset($row)){ |
64
|
|
|
$col=$row->getCol($col,$force); |
65
|
|
|
} |
66
|
|
|
return $col; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param int $row |
71
|
|
|
* @param int $col |
72
|
|
|
* @return HtmlGridCol |
73
|
|
|
*/ |
74
|
|
|
public function getCellAt($row,$col,$force=true){ |
75
|
|
|
$row=$this->getRow($row,$force); |
76
|
|
|
if(isset($row)){ |
77
|
|
|
$col=$row->getColAt($col,$force); |
78
|
|
|
} |
79
|
|
|
return $col; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function compile(JsUtils $js=NULL, View $view=NULL) { |
83
|
|
|
foreach ($this->rows as $row){ |
84
|
|
|
$this->addContent($row); |
85
|
|
|
} |
86
|
|
|
return parent::compile($js,$view); |
87
|
|
|
} |
88
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.