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){ |
|
|
|
|
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
|
|
|
public function setValues($values,$force=false){ |
79
|
|
|
$count=$this->count(); |
80
|
|
|
if($force===true){ |
81
|
|
|
for($i=$count;$i<\sizeof($values);$i++){ |
|
|
|
|
82
|
|
|
$this->addItem(new HtmlGridCol($this->identifier."-col-".($this->count()+1),null)); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
$count=\min(array($this->count(),\sizeof($values))); |
86
|
|
|
for($i=0;$i<$count;$i++){ |
87
|
|
|
$this->content[$i]->setValue($values[$i]); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritDoc} |
93
|
|
|
* @see \Ajax\common\html\HtmlCollection::createItem() |
94
|
|
|
*/ |
95
|
|
|
protected function createItem($value){ |
96
|
|
|
$col=new HtmlGridCol($this->identifier."-col-".($this->count()+1),$value); |
97
|
|
|
return $col; |
98
|
|
|
} |
99
|
|
|
} |
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.