Completed
Push — master ( 8af853...e6529d )
by Jean-Christophe
03:39
created

HtmlGridRow::setColor()   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
3
namespace Ajax\semantic\html\content;
4
5
use Ajax\common\html\HtmlCollection;
6
use Ajax\semantic\html\base\Wide;
7
use Ajax\semantic\html\base\Color;
8
use Ajax\semantic\html\base\TextAlignment;
9
10
/**
11
 * A row for the Semantic Grid component
12
 * @see http://semantic-ui.com/collections/grid.html
13
 * @author jc
14
 * @version 1.001
15
 */
16
class HtmlGridRow extends HtmlCollection{
17
18
	private $_colSize;
19
	public function __construct( $identifier,$numCols=NULL,$colSizing=false){
20
		parent::__construct( $identifier,"div");
21
		$this->setClass("row");
22
		$width=null;
23
		if(isset($numCols)){
24
			$numCols=min(16,$numCols);
25
			$numCols=max(1,$numCols);
26
			if($colSizing)
27
				$width=(int)(16/$numCols);
28
			else
29
				$this->_colSize=16/$numCols;
30
			for ($i=0;$i<$numCols;$i++){
31
				$this->addItem($width);
32
			}
33
		}
34
	}
35
36
	/**
37
	 * Defines the row width
38
	 * @param int $width
39
	 * @return \Ajax\semantic\html\content\HtmlGridRow
40
	 */
41 View Code Duplication
	public function setWidth($width){
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
42
		if(\is_int($width)){
43
			$width=Wide::getConstants()["W".$width];
44
		}
45
		$this->addToPropertyCtrl("class", $width, Wide::getConstants());
46
		return $this->addToPropertyCtrl("class", "column",array("column"));
47
	}
48
49
	/**
50
	 * return the col at $index
51
	 * @param int $index
52
	 * @return \Ajax\semantic\html\collections\HtmlGridCol
53
	 */
54
	public function getCol($index){
55
		return $this->getItem($index);
56
	}
57
58
	/**
59
	 * stretch the row contents to take up the entire column height
60
	 * @return \Ajax\semantic\html\content\HtmlGridRow
61
	 */
62
	public function setStretched(){
63
		return $this->addToProperty("class", "stretched");
64
	}
65
66
	/**
67
	 * @param string $color
68
	 * @return \Ajax\semantic\html\content\HtmlGridRow
69
	 */
70
	public function setColor($color){
71
		return $this->addToPropertyCtrl("class", $color,Color::getConstants());
72
	}
73
74
	public function setTextAlignment($value=TextAlignment::LEFT){
75
		return $this->addToPropertyCtrl("class", $value,TextAlignment::getConstants());
76
	}
77
78
	/**
79
	 * {@inheritDoc}
80
	 * @see \Ajax\common\html\HtmlCollection::createItem()
81
	 */
82
	protected function createItem($value){
83
		$col=new HtmlGridCol($this->identifier."-col-".($this->count()+1),$value);
84
		return $col;
85
	}
86
}