Completed
Push — master ( 09bbc1...c831e1 )
by Jean-Christophe
03:24
created

HtmlGridCol::getOffest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 2
nc 1
nop 1
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 setWidth($size=CssSize::SIZE_MD,$width=1){
66
		$this->positions[$size]=$width;
67
		return $this;	
68
	}
69
	
70
	public function setPosition($size=CssSize::SIZE_MD,$width=1){
71
		return $this->addPosition($size,$width);
72
	}
73
	
74
	public function getWidth($size){
75
		return @$this->positions[$size];
76
	}
77
	
78
	public function getOffest($size){
79
		return @$this->offsets[$size];
80
	}
81
	
82
	public function addClear(){
83
		$this->wrap("","<div class='clearfix'></div>");
84
	}
85
	public function setOffsets($offsets) {
86
		$this->offsets = $offsets;
87
		return $this;
88
	}
89
	
90
	public function copy($identifier){
91
		$result=new HtmlGridCol($identifier);
92
		$result->setPositions($this->positions);
93
		$result->setOffsets($this->offsets);
94
		return $result;
95
	}
96
	public function setPositions($positions) {
97
		$this->positions = $positions;
98
		return $this;
99
	}
100
	public function getOffsets() {
101
		return $this->offsets;
102
	}
103
	
104
	
105
	
106
}