1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\content; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\constants\Wide; |
6
|
|
|
use Ajax\semantic\html\base\constants\Color; |
7
|
|
|
use Ajax\JsUtils; |
8
|
|
|
use Phalcon\Mvc\View; |
9
|
|
|
use Ajax\semantic\html\base\HtmlSemCollection; |
10
|
|
|
use Ajax\semantic\html\base\traits\TextAlignmentTrait; |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* A row for the Semantic Grid component |
15
|
|
|
* @see http://semantic-ui.com/collections/grid.html |
16
|
|
|
* @author jc |
17
|
|
|
* @version 1.001 |
18
|
|
|
*/ |
19
|
|
|
class HtmlGridRow extends HtmlSemCollection{ |
20
|
|
|
use TextAlignmentTrait; |
21
|
|
|
|
22
|
|
|
private $_colSize; |
23
|
|
|
private $_implicite=false; |
24
|
|
|
|
25
|
|
|
public function __construct( $identifier,$numCols=NULL,$colSizing=false,$implicite=false){ |
26
|
|
|
parent::__construct( $identifier,"div","row"); |
27
|
|
|
$this->_implicite=$implicite; |
28
|
|
|
$width=null; |
29
|
|
|
if(isset($numCols)){ |
30
|
|
|
$numCols=min(16,$numCols); |
31
|
|
|
$numCols=max(1,$numCols); |
32
|
|
|
if($colSizing) |
33
|
|
|
$width=(int)(16/$numCols); |
34
|
|
|
else |
35
|
|
|
$this->_colSize=16/$numCols; |
36
|
|
|
for ($i=0;$i<$numCols;$i++){ |
37
|
|
|
$this->addItem($width); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Defines the row width |
44
|
|
|
* @param int $width |
45
|
|
|
* @return \Ajax\semantic\html\content\HtmlGridRow |
46
|
|
|
*/ |
47
|
|
View Code Duplication |
public function setWidth($width){ |
|
|
|
|
48
|
|
|
if(\is_int($width)){ |
49
|
|
|
$width=Wide::getConstants()["W".$width]; |
50
|
|
|
} |
51
|
|
|
$this->addToPropertyCtrl("class", $width, Wide::getConstants()); |
52
|
|
|
return $this->addToPropertyCtrl("class", "column",array("column")); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* return the col at $index |
57
|
|
|
* @param int $index |
58
|
|
|
* @return \Ajax\semantic\html\collections\HtmlGridCol |
59
|
|
|
*/ |
60
|
|
|
public function getCol($index){ |
61
|
|
|
return $this->getItem($index); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function setColsCount($colsCount,$toCreate=true){ |
65
|
|
|
$this->setWidth($colsCount); |
66
|
|
|
if($toCreate===true){ |
67
|
|
|
$count=$this->count(); |
68
|
|
|
for($i=$count;$i<$colsCount;$i++){ |
69
|
|
|
$this->addItem(null); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function addCols($colCount){ |
76
|
|
|
for($i=0;$i<$colCount;$i++){ |
77
|
|
|
$this->addItem(null); |
78
|
|
|
} |
79
|
|
|
return $this; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function addCol($width=NULL){ |
83
|
|
|
return $this->addItem($width); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* stretch the row contents to take up the entire column height |
88
|
|
|
* @return \Ajax\semantic\html\content\HtmlGridRow |
89
|
|
|
*/ |
90
|
|
|
public function setStretched(){ |
91
|
|
|
return $this->addToProperty("class", "stretched"); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @param string $color |
96
|
|
|
* @return \Ajax\semantic\html\content\HtmlGridRow |
97
|
|
|
*/ |
98
|
|
|
public function setColor($color){ |
99
|
|
|
return $this->addToPropertyCtrl("class", $color,Color::getConstants()); |
|
|
|
|
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function setValues($values,$force=false){ |
103
|
|
|
$count=$this->count(); |
104
|
|
|
if($force===true){ |
105
|
|
|
for($i=$count;$i<\sizeof($values);$i++){ |
|
|
|
|
106
|
|
|
$this->addItem(new HtmlGridCol($this->identifier."-col-".($this->count()+1),null)); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
$count=\min(array($this->count(),\sizeof($values))); |
110
|
|
|
for($i=0;$i<$count;$i++){ |
111
|
|
|
$this->content[$i]->setValue($values[$i]); |
112
|
|
|
} |
113
|
|
|
return $this; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* {@inheritDoc} |
118
|
|
|
* @see \Ajax\common\html\HtmlCollection::createItem() |
119
|
|
|
*/ |
120
|
|
|
protected function createItem($value){ |
121
|
|
|
$col=new HtmlGridCol($this->identifier."-col-".($this->count()+1),$value); |
122
|
|
|
return $col; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function compile(JsUtils $js=NULL,View $view=NULL){ |
126
|
|
|
if($this->_implicite===true){ |
127
|
|
|
$this->_template="%wrapContentBefore%%content%%wrapContentAfter%"; |
128
|
|
|
} |
129
|
|
|
return parent::compile($js,$view); |
130
|
|
|
} |
131
|
|
|
} |
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.