1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\semantic\html\base\traits; |
4
|
|
|
|
5
|
|
|
use Ajax\semantic\html\base\constants\Size; |
6
|
|
|
use Ajax\semantic\html\base\constants\Color; |
7
|
|
|
use Ajax\semantic\html\base\constants\Direction; |
8
|
|
|
use Ajax\semantic\html\elements\HtmlIcon; |
9
|
|
|
|
10
|
|
|
trait BaseTrait { |
11
|
|
|
protected $_variations=[ ]; |
12
|
|
|
protected $_states=[ ]; |
13
|
|
|
protected $_baseClass; |
14
|
|
|
|
15
|
|
|
protected abstract function setPropertyCtrl($name, $value, $typeCtrl); |
16
|
|
|
|
17
|
|
|
protected abstract function addToPropertyCtrl($name, $value, $typeCtrl); |
18
|
|
|
|
19
|
|
|
protected abstract function addToPropertyCtrlCheck($name, $value, $typeCtrl); |
20
|
|
|
|
21
|
|
|
public abstract function addToProperty($name, $value, $separator=" "); |
22
|
|
|
|
23
|
|
|
public function addVariation($variation) { |
24
|
|
|
return $this->addToPropertyCtrlCheck("class", $variation, $this->_variations); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function addState($state) { |
28
|
|
|
return $this->addToPropertyCtrlCheck("class", $state, $this->_states); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function setVariation($variation) { |
32
|
|
|
$this->setPropertyCtrl("class", $variation, $this->_variations); |
33
|
|
|
return $this->addToProperty("class", $this->_baseClass); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
View Code Duplication |
public function setVariations($variations) { |
|
|
|
|
37
|
|
|
$this->setProperty("class", $this->_baseClass); |
|
|
|
|
38
|
|
|
if (\is_string($variations)) |
39
|
|
|
$variations=\explode(" ", $variations); |
40
|
|
|
foreach ( $variations as $variation ) { |
41
|
|
|
$this->addVariation($variation); |
42
|
|
|
} |
43
|
|
|
return $this; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function setState($state) { |
47
|
|
|
$this->setPropertyCtrl("class", $state, $this->_states); |
48
|
|
|
return $this->addToProperty("class", $this->_baseClass); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function addVariations($variations=array()) { |
52
|
|
|
if (\is_string($variations)) |
53
|
|
|
$variations=\explode(" ", $variations); |
54
|
|
|
foreach ( $variations as $variation ) { |
55
|
|
|
$this->addVariation($variation); |
56
|
|
|
} |
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function addStates($states=array()) { |
61
|
|
|
if (\is_string($states)) |
62
|
|
|
$states=\explode(" ", $states); |
63
|
|
|
foreach ( $states as $state ) { |
64
|
|
|
$this->addState($state); |
65
|
|
|
} |
66
|
|
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
View Code Duplication |
public function setStates($states) { |
|
|
|
|
70
|
|
|
$this->setProperty("class", $this->_baseClass); |
|
|
|
|
71
|
|
|
if (\is_string($states)) |
72
|
|
|
$states=\explode(" ", $states); |
73
|
|
|
foreach ( $states as $state ) { |
74
|
|
|
$this->addState($state); |
75
|
|
|
} |
76
|
|
|
return $this; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function addIcon($icon, $before=true) { |
80
|
|
|
return $this->addContent(new HtmlIcon("icon-" . $this->identifier, $icon), $before); |
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* |
85
|
|
|
* {@inheritDoc} |
86
|
|
|
* |
87
|
|
|
* @see \Ajax\common\html\HtmlSingleElement::setSize() |
88
|
|
|
*/ |
89
|
|
|
public function setSize($size) { |
90
|
|
|
return $this->addToPropertyCtrl("class", $size, Size::getConstants()); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* show it is currently unable to be interacted with |
95
|
|
|
* @return \Ajax\semantic\html\elements\HtmlSemDoubleElement |
96
|
|
|
*/ |
97
|
|
|
public function setDisabled() { |
98
|
|
|
return $this->addToProperty("class", "disabled"); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* |
103
|
|
|
* @param string $color |
104
|
|
|
* @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
105
|
|
|
*/ |
106
|
|
|
public function setColor($color) { |
107
|
|
|
return $this->addToPropertyCtrl("class", $color, Color::getConstants()); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* |
112
|
|
|
* @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
113
|
|
|
*/ |
114
|
|
|
public function setFluid() { |
115
|
|
|
return $this->addToProperty("class", "fluid"); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* show it is currently the active user selection |
120
|
|
|
* @return \Ajax\semantic\html\base\HtmlSemDoubleElement |
121
|
|
|
*/ |
122
|
|
|
public function setActive($value=true){ |
|
|
|
|
123
|
|
|
return $this->addToProperty("class", "active"); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* can be formatted to appear on dark backgrounds |
128
|
|
|
*/ |
129
|
|
|
public function setInverted() { |
130
|
|
|
return $this->addToProperty("class", "inverted"); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function setCircular() { |
134
|
|
|
return $this->addToProperty("class", "circular"); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
public function setFloated($direction="right") { |
138
|
|
|
return $this->addToPropertyCtrl("class", $direction . " floated", Direction::getConstantValues("floated")); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function floatRight() { |
142
|
|
|
return $this->setFloated(); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
public function floatLeft() { |
146
|
|
|
return $this->setFloated("left"); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
public function getBaseClass() { |
150
|
|
|
return $this->_baseClass; |
151
|
|
|
} |
152
|
|
|
} |
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.