Completed
Push — master ( bbe42f...a98604 )
by Jean-Christophe
03:13
created

BaseTrait::floatRight()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
use Ajax\service\JString;
10
use Ajax\semantic\html\base\HtmlSemDoubleElement;
11
12
/**
13
 * @author jc
14
 * @property string $identifier
15
 * @property HtmlSemDoubleElement $_self
16
 */
17
trait BaseTrait {
18
	protected $_variations=[ ];
19
	protected $_states=[ ];
20
	protected $_baseClass;
21
22
	abstract protected function setPropertyCtrl($name, $value, $typeCtrl);
23
24
	abstract protected function addToPropertyCtrl($name, $value, $typeCtrl);
25
26
	abstract protected function addToPropertyCtrlCheck($name, $value, $typeCtrl);
27
28
	abstract public function addToProperty($name, $value, $separator=" ");
29
30
	abstract public function setProperty($name, $value);
31
32
	abstract public function addContent($content,$before=false);
33
34
	abstract public function onCreate($jsCode);
35
36
	public function addVariation($variation) {
37
		return $this->_self->addToPropertyCtrlCheck("class", $variation, $this->_self->getVariations());
38
	}
39
40
	public function addState($state) {
41
		return $this->_self->addToPropertyCtrlCheck("class", $state, $this->_self->getStates());
42
	}
43
44
	public function setVariation($variation) {
45
		$this->_self->setPropertyCtrl("class", $variation, $this->_self->getVariations());
46
		return $this->_self->addToProperty("class", $this->_self->getBaseClass());
47
	}
48
49 View Code Duplication
	public function setVariations($variations) {
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...
50
		$this->_self->setProperty("class", $this->_self->getBaseClass());
51
		if (\is_string($variations))
52
			$variations=\explode(" ", $variations);
53
		foreach ( $variations as $variation ) {
54
			$this->_self->addVariation($variation);
55
		}
56
		return $this;
57
	}
58
59
	public function setState($state) {
60
		$this->_self->setPropertyCtrl("class", $state, $this->_self->getStates());
61
		return $this->_self->addToProperty("class", $this->_self->getBaseClass());
62
	}
63
64
	public function addVariations($variations=array()) {
65
		if (\is_string($variations))
66
			$variations=\explode(" ", $variations);
67
		foreach ( $variations as $variation ) {
68
			$this->_self->addVariation($variation);
69
		}
70
		return $this;
71
	}
72
73
	public function addStates($states=array()) {
74
		if (\is_string($states))
75
			$states=\explode(" ", $states);
76
		foreach ( $states as $state ) {
77
			$this->_self->addState($state);
78
		}
79
		return $this;
80
	}
81
82 View Code Duplication
	public function setStates($states) {
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...
83
		$this->_self->setProperty("class", $this->_self->getBaseClass());
84
		if (\is_string($states))
85
			$states=\explode(" ", $states);
86
		foreach ( $states as $state ) {
87
			$this->_self->addState($state);
88
		}
89
		return $this;
90
	}
91
92
	public function addIcon($icon, $before=true) {
93
		return $this->_self->addContent(new HtmlIcon("icon-" . $this->_self->getIdentifier(), $icon), $before);
94
	}
95
96
	public function addSticky($context="body"){
97
		$this->_self->onCreate("$('#".$this->_self->getIdentifier()."').sticky({ context: '".$context."'});");
98
		return $this;
99
	}
100
101
	/**
102
	 *
103
	 * {@inheritDoc}
104
	 *
105
	 * @see \Ajax\common\html\HtmlSingleElement::setSize()
106
	 */
107
	public function setSize($size) {
108
		return $this->_self->addToPropertyCtrl("class", $size, Size::getConstants());
109
	}
110
111
	/**
112
	 * show it is currently unable to be interacted with
113
	 * @param boolean $disable
114
	 * @return HtmlSemDoubleElement
115
	 */
116
	public function setDisabled($disable=true) {
117
		if($disable)
118
			$this->_self->addToProperty("class", "disabled");
119
		return $this;
120
	}
121
122
	/**
123
	 *
124
	 * @param string $color
125
	 * @return HtmlSemDoubleElement
126
	 */
127
	public function setColor($color) {
128
		return $this->_self->addToPropertyCtrl("class", $color, Color::getConstants());
129
	}
130
131
	/**
132
	 *
133
	 * @return HtmlSemDoubleElement
134
	 */
135
	public function setFluid() {
136
		return $this->_self->addToProperty("class", "fluid");
137
	}
138
139
	/**
140
	 *
141
	 * @return HtmlSemDoubleElement
142
	 */
143
	public function asHeader(){
144
		return $this->_self->addToProperty("class", "header");
145
	}
146
147
	/**
148
	 * show it is currently the active user selection
149
	 * @return HtmlSemDoubleElement
150
	 */
151
	public function setActive($value=true){
152
		if($value)
153
			$this->_self->addToProperty("class", "active");
154
		return $this;
155
	}
156
157
	public function setAttached($value=true){
158
		if($value)
159
			$this->_self->addToPropertyCtrl("class", "attached", array ("attached" ));
160
		return $this;
161
	}
162
163
	/**
164
	 * can be formatted to appear on dark backgrounds
165
	 */
166
	public function setInverted($recursive=true) {
167
		if($recursive===true){
168
			$content=$this->_self->getContent();
169
			if($content instanceof HtmlSemDoubleElement)
170
				$content->setInverted($recursive);
171
			elseif(\is_array($content) || $content instanceof \Traversable){
172
				foreach ($content as $elm){
173
					if($elm instanceof  HtmlSemDoubleElement){
174
						$elm->setInverted($recursive);
175
					}
176
				}
177
			}
178
		}
179
		return $this->_self->addToProperty("class", "inverted");
180
	}
181
182
	public function setCircular() {
183
		return $this->_self->addToProperty("class", "circular");
184
	}
185
186
	public function setFloated($direction="right") {
187
		return $this->_self->addToPropertyCtrl("class", $direction . " floated", Direction::getConstantValues("floated"));
188
	}
189
190
	public function floatRight() {
191
		return $this->_self->setFloated();
192
	}
193
194
	public function floatLeft() {
195
		return $this->_self->setFloated("left");
196
	}
197
198
	public function getBaseClass() {
199
		return $this->_baseClass;
200
	}
201
202
	protected function addBehavior(&$array,$key,$value,$before="",$after=""){
203
		if(\is_string($value)){
204
			if(isset($array[$key])){
205
				$p=JString::replaceAtFirstAndLast($array[$key], $before, "", $after, "");
206
				$array[$key]=$before.$p.$value.$after;
207
			}else
208
				$array[$key]=$before.$value.$after;
209
		}else{
210
			$array[$key]=$value;
211
		}
212
		return $this;
213
	}
214
215
	public function getVariations() {
216
	return $this->_variations;
217
}
218
219
	public function getStates() {
220
	return $this->_states;
221
}
222
223
	/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
224
	 protected function addBehavior(&$array,$key,$value,$before="",$after=""){
225
	 echo $key.":".$this->_self->identifier."<br>";
226
227
	 if(\is_string($value)){
228
	 if(isset($array[$key])){
229
	 $p=JString::replaceAtFirstAndLast($array[$key], $before, "", $after, "");
230
	 $array[$key]=$before.$p.$value.$after;
231
	 }else
232
	 	$array[$key]=$before.$value.$after;
233
	 	}else{
234
	 	if(isset($array[$key])){
235
	 	if(!\is_array($array[$key])){
236
	 	$array[$key]=[$array[$key]];
237
	 	}
238
	 	$array[$key][]=$value;
239
	 	}else{
240
	 	$array[$key]=$value;
241
	 	}
242
	 	}
243
	 	return $this;
244
	 	}*/
245
}
246