Completed
Push — master ( 04d259...772d83 )
by Jean-Christophe
03:54
created

BaseTrait::asHeader()   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
10
/**
11
 * @author jc
12
 * @property string $identifier
13
 */
14
trait BaseTrait {
15
	protected $_variations=[ ];
16
	protected $_states=[ ];
17
	protected $_baseClass;
18
19
	abstract protected function setPropertyCtrl($name, $value, $typeCtrl);
20
21
	abstract protected function addToPropertyCtrl($name, $value, $typeCtrl);
22
23
	abstract protected function addToPropertyCtrlCheck($name, $value, $typeCtrl);
24
25
	abstract public function addToProperty($name, $value, $separator=" ");
26
27
	abstract public function setProperty($name, $value);
28
29
	abstract public function addContent($content,$before=false);
30
31
	abstract public function onCreate($jsCode);
32
33
	public function addVariation($variation) {
34
		return $this->addToPropertyCtrlCheck("class", $variation, $this->_variations);
35
	}
36
37
	public function addState($state) {
38
		return $this->addToPropertyCtrlCheck("class", $state, $this->_states);
39
	}
40
41
	public function setVariation($variation) {
42
		$this->setPropertyCtrl("class", $variation, $this->_variations);
43
		return $this->addToProperty("class", $this->_baseClass);
44
	}
45
46 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...
47
		$this->setProperty("class", $this->_baseClass);
48
		if (\is_string($variations))
49
			$variations=\explode(" ", $variations);
50
		foreach ( $variations as $variation ) {
51
			$this->addVariation($variation);
52
		}
53
		return $this;
54
	}
55
56
	public function setState($state) {
57
		$this->setPropertyCtrl("class", $state, $this->_states);
58
		return $this->addToProperty("class", $this->_baseClass);
59
	}
60
61
	public function addVariations($variations=array()) {
62
		if (\is_string($variations))
63
			$variations=\explode(" ", $variations);
64
		foreach ( $variations as $variation ) {
65
			$this->addVariation($variation);
66
		}
67
		return $this;
68
	}
69
70
	public function addStates($states=array()) {
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 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...
80
		$this->setProperty("class", $this->_baseClass);
81
		if (\is_string($states))
82
			$states=\explode(" ", $states);
83
		foreach ( $states as $state ) {
84
			$this->addState($state);
85
		}
86
		return $this;
87
	}
88
89
	public function addIcon($icon, $before=true) {
90
		return $this->addContent(new HtmlIcon("icon-" . $this->identifier, $icon), $before);
91
	}
92
93
	public function addSticky($context="body"){
94
		$this->onCreate("$('#".$this->identifier."').sticky({ context: '".$context."'});");
95
		return $this;
96
	}
97
98
	/**
99
	 *
100
	 * {@inheritDoc}
101
	 *
102
	 * @see \Ajax\common\html\HtmlSingleElement::setSize()
103
	 */
104
	public function setSize($size) {
105
		return $this->addToPropertyCtrl("class", $size, Size::getConstants());
106
	}
107
108
	/**
109
	 * show it is currently unable to be interacted with
110
	 * @param boolean $disable
111
	 * @return \Ajax\semantic\html\elements\HtmlSemDoubleElement
112
	 */
113
	public function setDisabled($disable=true) {
114
		if($disable)
115
			$this->addToProperty("class", "disabled");
116
		return $this;
117
	}
118
119
	/**
120
	 *
121
	 * @param string $color
122
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
123
	 */
124
	public function setColor($color) {
125
		return $this->addToPropertyCtrl("class", $color, Color::getConstants());
126
	}
127
128
	/**
129
	 *
130
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
131
	 */
132
	public function setFluid() {
133
		return $this->addToProperty("class", "fluid");
134
	}
135
136
	/**
137
	 *
138
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
139
	 */
140
	public function asHeader(){
141
		return $this->addToProperty("class", "header");
142
	}
143
144
	/**
145
	 * show it is currently the active user selection
146
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
147
	 */
148
	public function setActive($value=true){
149
		if($value)
150
			$this->addToProperty("class", "active");
151
		return $this;
152
	}
153
154
	public function setAttached($value=true){
155
		if($value)
156
			$this->addToPropertyCtrl("class", "attached", array ("attached" ));
157
		return $this;
158
	}
159
160
	/**
161
	 * can be formatted to appear on dark backgrounds
162
	 */
163
	public function setInverted() {
164
		return $this->addToProperty("class", "inverted");
165
	}
166
167
	public function setCircular() {
168
		return $this->addToProperty("class", "circular");
169
	}
170
171
	public function setFloated($direction="right") {
172
		return $this->addToPropertyCtrl("class", $direction . " floated", Direction::getConstantValues("floated"));
173
	}
174
175
	public function floatRight() {
176
		return $this->setFloated();
177
	}
178
179
	public function floatLeft() {
180
		return $this->setFloated("left");
181
	}
182
183
	public function getBaseClass() {
184
		return $this->_baseClass;
185
	}
186
}