1
|
|
|
<?php |
2
|
|
|
namespace Ajax\bootstrap\html\content; |
3
|
|
|
|
4
|
|
|
use Ajax\bootstrap\html\base\HtmlDoubleElement; |
5
|
|
|
use Ajax\bootstrap\html\base\CssSize; |
6
|
|
|
use Ajax\JsUtils; |
7
|
|
|
use Phalcon\Mvc\View; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Inner element for Twitter Bootstrap Grid row |
11
|
|
|
* @see http://getbootstrap.com/css/#grid |
12
|
|
|
* @author jc |
13
|
|
|
* @version 1.001 |
14
|
|
|
*/ |
15
|
|
|
class HtmlGridRow extends HtmlDoubleElement { |
16
|
|
|
private $cols; |
17
|
|
|
public function __construct($identifier){ |
18
|
|
|
parent::__construct($identifier,"div"); |
19
|
|
|
$this->setProperty("class", "row"); |
20
|
|
|
$this->cols=array(); |
21
|
|
|
} |
22
|
|
|
|
23
|
|
|
public function addCol($size=CssSize::SIZE_MD,$width=1){ |
24
|
|
|
$col=new HtmlGridCol($this->identifier."-col-".(sizeof($this->cols)+1),$size,$width); |
25
|
|
|
$this->row[]=$col; |
|
|
|
|
26
|
|
|
return $col; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function addColAt($size=CssSize::SIZE_MD,$width=1,$offset=1){ |
30
|
|
|
$col=$this->addCol($size,$width); |
31
|
|
|
return $col->setOffset($size, max($offset,sizeof($this->cols)+1)); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
View Code Duplication |
public function getCol($index,$force=true){ |
|
|
|
|
35
|
|
|
if($index<sizeof($this->cols)+1){ |
36
|
|
|
$result=$this->cols[$index-1]; |
37
|
|
|
}else if ($force){ |
38
|
|
|
$result=$this->addColAt(CssSize::SIZE_MD,1,$index); |
39
|
|
|
$this->cols[]=$result; |
40
|
|
|
} |
41
|
|
|
return $result; |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getColAt($offset,$force=true){ |
45
|
|
|
$result=null; |
46
|
|
|
foreach ($this->cols as $col){ |
47
|
|
|
$offsets=$col->getOffsets(); |
48
|
|
|
if($result=array_search($offset, $offsets)){ |
49
|
|
|
break; |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
if(!isset($result)){ |
53
|
|
|
$result=$this->getCol($offset,$force); |
54
|
|
|
} |
55
|
|
|
return $result; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function compile(JsUtils $js=NULL, View $view=NULL) { |
59
|
|
|
|
60
|
|
|
foreach ($this->cols as $col){ |
61
|
|
|
$this->addContent($col); |
62
|
|
|
} |
63
|
|
|
return parent::compile($js,$view); |
64
|
|
|
} |
65
|
|
|
} |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: