Completed
Push — master ( 63bf24...09bbc1 )
by Jean-Christophe
03:16
created

HtmlGridCol::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4286
cc 1
eloc 5
nc 1
nop 3
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 col
11
 * @see http://getbootstrap.com/css/#grid
12
 * @author jc
13
 * @version 1.001
14
 */
15
class HtmlGridCol extends HtmlDoubleElement {
16
	private $positions;
17
	private $offsets;
18
	public function __construct($identifier,$size=CssSize::SIZE_MD,$width=1){
19
		parent::__construct($identifier,"div");
20
		$this->positions=array();
21
		$this->offsets=array();
22
		$this->addPosition($size,$width);
23
	}
24
	public function addPosition($size=CssSize::SIZE_MD,$width=1){
25
		$this->positions[$size]=$width;
26
		return $this;
27
	}
28
	private function _generateClass(){
29
		$result=array();
30
		foreach ($this->positions as $size=>$width){
31
			$result[]="col-".$size."-".$width;
32
		}
33
		foreach ($this->offsets as $size=>$offset){
34
			$result[]="col-".$size."-offset-".$offset;
35
		}
36
		return implode(" ", $result);
37
	}
38
	
39
	public function compile(JsUtils $js=NULL, View $view=NULL) {
40
		$this->setProperty("class", $this->_generateClass());
41
		return parent::compile($js,$view);
42
	}
43
	
44
	public function setOffset($size,$offset){
45
		$this->offsets[$size]=$offset;
46
		return $this;
47
	}
48
49
	public function setOffsetForAll($newOffset){
50
		foreach ($this->offsets as &$value){
51
			$value=$newOffset;
52
		}
53
		unset($value);
54
		return $this;
55
	}
56
	
57
	public function setWidthForAll($newWidth){
58
		foreach ($this->positions as &$pos){
59
			$pos=$newWidth;
60
		}
61
		unset($pos);
62
		return $this;
63
	}
64
	
65
	public function setPosition($size=CssSize::SIZE_MD,$width=1){
66
		return $this->addPosition($size,$width);
67
	}
68
	
69
	public function getPosition($size){
70
		return @$this->positions[$size];
71
	}
72
	
73
	public function addClear(){
74
		$this->wrap("","<div class='clearfix'></div>");
75
	}
76
	public function setOffsets($offsets) {
77
		$this->offsets = $offsets;
78
		return $this;
79
	}
80
	
81
	public function copy($identifier){
82
		$result=new HtmlGridCol($identifier);
83
		$result->setPositions($this->positions);
84
		$result->setOffsets($this->offsets);
85
		return $result;
86
	}
87
	public function setPositions($positions) {
88
		$this->positions = $positions;
89
		return $this;
90
	}
91
	public function getOffsets() {
92
		return $this->offsets;
93
	}
94
	
95
	
96
	
97
}