Passed
Push — master ( 9e563a...cb22e7 )
by Jean-Christophe
02:15
created
Ajax/semantic/html/modules/HtmlDropdown.php 1 patch
Spacing   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -14,29 +14,29 @@  discard block
 block discarded – undo
14 14
 use Ajax\common\html\HtmlDoubleElement;
15 15
 
16 16
 class HtmlDropdown extends HtmlSemDoubleElement {
17
-	use FieldTrait,LabeledIconTrait {
17
+	use FieldTrait, LabeledIconTrait {
18 18
 		addIcon as addIconP;
19 19
 	}
20 20
 	protected $mClass="menu";
21 21
 	protected $mTagName="div";
22
-	protected $items=array ();
23
-	protected $_params=array("action"=>"nothing","on"=>"hover","showOnFocus"=>false);
22
+	protected $items=array();
23
+	protected $_params=array("action"=>"nothing", "on"=>"hover", "showOnFocus"=>false);
24 24
 	protected $input;
25 25
 	protected $value;
26 26
 	protected $_associative;
27 27
 	protected $_multiple;
28 28
 
29
-	public function __construct($identifier, $value="", $items=array(),$associative=true) {
29
+	public function __construct($identifier, $value="", $items=array(), $associative=true) {
30 30
 		parent::__construct($identifier, "div");
31 31
 		$this->_template=include dirname(__FILE__).'/../templates/tplDropdown.php';
32 32
 		$this->setProperty("class", "ui dropdown");
33 33
 		$this->_multiple=false;
34 34
 		$content=[];
35
-		if(isset($value)){
36
-			if($value instanceof HtmlSemDoubleElement){
35
+		if (isset($value)) {
36
+			if ($value instanceof HtmlSemDoubleElement) {
37 37
 				$text=$value;
38
-			}else{
39
-				$text=new HtmlSemDoubleElement("text-".$this->identifier,"div");
38
+			} else {
39
+				$text=new HtmlSemDoubleElement("text-".$this->identifier, "div");
40 40
 				$text->setClass("text");
41 41
 				$this->setValue($value);
42 42
 			}
@@ -49,33 +49,33 @@  discard block
 block discarded – undo
49 49
 		$this->addItems($items);
50 50
 	}
51 51
 
52
-	public function getField(){
52
+	public function getField() {
53 53
 		return $this->input;
54 54
 	}
55 55
 
56
-	public function getDataField(){
56
+	public function getDataField() {
57 57
 		return $this->input;
58 58
 	}
59 59
 
60
-	public function addItem($item,$value=NULL,$image=NULL,$description=NULL){
61
-		$itemO=$this->beforeAddItem($item,$value,$image,$description);
60
+	public function addItem($item, $value=NULL, $image=NULL, $description=NULL) {
61
+		$itemO=$this->beforeAddItem($item, $value, $image, $description);
62 62
 		$this->items[]=$itemO;
63 63
 		return $itemO;
64 64
 	}
65 65
 
66
-	public function addIcon($icon,$before=true,$labeled=false){
66
+	public function addIcon($icon, $before=true, $labeled=false) {
67 67
 		$this->removeArrow();
68
-		$this->addIconP($icon,$before,$labeled);
68
+		$this->addIconP($icon, $before, $labeled);
69 69
 		$elm=$this->getElementById("text-".$this->identifier, $this->content);
70
-		if(isset($elm)){
70
+		if (isset($elm)) {
71 71
 			$elm->setWrapAfter("");
72 72
 		}
73 73
 		return $this;
74 74
 	}
75 75
 
76
-	public function addIcons($icons){
76
+	public function addIcons($icons) {
77 77
 		$count=$this->count();
78
-		for ($i=0;$i<\sizeof($icons) && $i<$count;$i++){
78
+		for ($i=0; $i<\sizeof($icons) && $i<$count; $i++) {
79 79
 			$this->getItem($i)->addIcon($icons[$i]);
80 80
 		}
81 81
 	}
@@ -86,33 +86,33 @@  discard block
 block discarded – undo
86 86
 	 * @param int $position
87 87
 	 * @return HtmlDropdownItem
88 88
 	 */
89
-	public function insertItem($item,$position=0){
89
+	public function insertItem($item, $position=0) {
90 90
 		$itemO=$this->beforeAddItem($item);
91
-		 $start = array_slice($this->items, 0, $position);
92
-		 $end = array_slice($this->items, $position);
93
-		 $start[] = $item;
91
+		 $start=array_slice($this->items, 0, $position);
92
+		 $end=array_slice($this->items, $position);
93
+		 $start[]=$item;
94 94
 		 $this->items=array_merge($start, $end);
95 95
 		 return $itemO;
96 96
 	}
97 97
 
98
-	protected function removeArrow(){
99
-		if(\sizeof($this->content)>1){
98
+	protected function removeArrow() {
99
+		if (\sizeof($this->content)>1) {
100 100
 			unset($this->content["arrow"]);
101 101
 			$this->content=\array_values($this->content);
102 102
 		}
103 103
 	}
104 104
 
105
-	protected function beforeAddItem($item,$value=NULL,$image=NULL,$description=NULL){
105
+	protected function beforeAddItem($item, $value=NULL, $image=NULL, $description=NULL) {
106 106
 		$itemO=$item;
107
-		if(\is_array($item)){
107
+		if (\is_array($item)) {
108 108
 			$description=JArray::getValue($item, "description", 3);
109 109
 			$value=JArray::getValue($item, "value", 1);
110 110
 			$image=JArray::getValue($item, "image", 2);
111 111
 			$item=JArray::getValue($item, "item", 0);
112 112
 		}
113
-		if(!$item instanceof HtmlDropdownItem){
114
-			$itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items),$item,$value,$image,$description);
115
-		}elseif($itemO instanceof HtmlDropdownItem){
113
+		if (!$item instanceof HtmlDropdownItem) {
114
+			$itemO=new HtmlDropdownItem("dd-item-".$this->identifier."-".\sizeof($this->items), $item, $value, $image, $description);
115
+		}elseif ($itemO instanceof HtmlDropdownItem) {
116 116
 			$this->addToProperty("class", "vertical");
117 117
 		}
118 118
 		return $itemO;
@@ -125,11 +125,11 @@  discard block
 block discarded – undo
125 125
 		$this->addItem($function($object));
126 126
 	}
127 127
 
128
-	public function addInput($name){
129
-		if(!isset($name))
128
+	public function addInput($name) {
129
+		if (!isset($name))
130 130
 			$name="input-".$this->identifier;
131 131
 		$this->setAction("activate");
132
-		$this->input=new HtmlInput($name,"hidden");
132
+		$this->input=new HtmlInput($name, "hidden");
133 133
 		$this->input->setIdentifier("input-".$this->identifier);
134 134
 		return $this->input;
135 135
 	}
@@ -140,15 +140,15 @@  discard block
 block discarded – undo
140 140
 	 * @param string $icon
141 141
 	 * @return HtmlDropdownItem
142 142
 	 */
143
-	public function addSearchInputItem($placeHolder=NULL,$icon=NULL){
144
-		return $this->addItem(HtmlDropdownItem::searchInput($placeHolder,$icon));
143
+	public function addSearchInputItem($placeHolder=NULL, $icon=NULL) {
144
+		return $this->addItem(HtmlDropdownItem::searchInput($placeHolder, $icon));
145 145
 	}
146 146
 
147 147
 	/**
148 148
 	 * Adds a divider item
149 149
 	 * @return HtmlDropdownItem
150 150
 	 */
151
-	public function addDividerItem(){
151
+	public function addDividerItem() {
152 152
 		return $this->addItem(HtmlDropdownItem::divider());
153 153
 	}
154 154
 
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @param string $icon
159 159
 	 * @return HtmlDropdownItem
160 160
 	 */
161
-	public function addHeaderItem($caption=NULL,$icon=NULL){
162
-		return $this->addItem(HtmlDropdownItem::header($caption,$icon));
161
+	public function addHeaderItem($caption=NULL, $icon=NULL) {
162
+		return $this->addItem(HtmlDropdownItem::header($caption, $icon));
163 163
 	}
164 164
 
165 165
 	/**
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
 	 * @param string $color
169 169
 	 * @return HtmlDropdownItem
170 170
 	 */
171
-	public function addCircularLabelItem($caption,$color){
171
+	public function addCircularLabelItem($caption, $color) {
172 172
 		return $this->addItem(HtmlDropdownItem::circular($caption, $color));
173 173
 	}
174 174
 
@@ -177,17 +177,17 @@  discard block
 block discarded – undo
177 177
 	 * @param string $image
178 178
 	 * @return \Ajax\semantic\html\content\HtmlDropdownItem
179 179
 	 */
180
-	public function addMiniAvatarImageItem($caption,$image){
180
+	public function addMiniAvatarImageItem($caption, $image) {
181 181
 		return $this->addItem(HtmlDropdownItem::avatar($caption, $image));
182 182
 	}
183 183
 
184
-	public function addItems($items){
185
-		if(\is_array($items) && $this->_associative){
186
-			foreach ($items as $k=>$v){
184
+	public function addItems($items) {
185
+		if (\is_array($items) && $this->_associative) {
186
+			foreach ($items as $k=>$v) {
187 187
 				$this->addItem($v)->setData($k);
188 188
 			}
189
-		}else{
190
-			foreach ($items as $item){
189
+		} else {
190
+			foreach ($items as $item) {
191 191
 				$this->addItem($item);
192 192
 			}
193 193
 		}
@@ -199,98 +199,98 @@  discard block
 block discarded – undo
199 199
 	 * @param array|mixed $values
200 200
 	 * @return $this
201 201
 	 */
202
-	public function setPropertyValues($property,$values){
202
+	public function setPropertyValues($property, $values) {
203 203
 		$i=0;
204
-		if(\is_array($values)===false){
205
-			$values=\array_fill(0, $this->count(),$values);
204
+		if (\is_array($values)===false) {
205
+			$values=\array_fill(0, $this->count(), $values);
206 206
 		}
207
-		foreach ($values as $value){
207
+		foreach ($values as $value) {
208 208
 			$c=$this->items[$i++];
209
-			if(isset($c)){
210
-				$c->setProperty($property,$value);
209
+			if (isset($c)) {
210
+				$c->setProperty($property, $value);
211 211
 			}
212
-			else{
212
+			else {
213 213
 				return $this;
214 214
 			}
215 215
 		}
216 216
 		return $this;
217 217
 	}
218 218
 
219
-	public function each($callBack){
220
-		foreach ($this->items as $index=>$value){
221
-			$callBack($index,$value);
219
+	public function each($callBack) {
220
+		foreach ($this->items as $index=>$value) {
221
+			$callBack($index, $value);
222 222
 		}
223 223
 		return $this;
224 224
 	}
225 225
 
226
-	public function getItem($index){
226
+	public function getItem($index) {
227 227
 		return $this->items[$index];
228 228
 	}
229 229
 
230 230
 	/**
231 231
 	 * @return int
232 232
 	 */
233
-	public function count(){
233
+	public function count() {
234 234
 		return \sizeof($this->items);
235 235
 	}
236 236
 	/**
237 237
 	 * @param boolean $dropdown
238 238
 	 */
239
-	public function asDropdown($dropdown){
240
-		if($dropdown===false){
239
+	public function asDropdown($dropdown) {
240
+		if ($dropdown===false) {
241 241
 			$this->_template=include dirname(__FILE__).'/../templates/tplDropdownMenu.php';
242 242
 			$dropdown="menu";
243
-		}else{
243
+		} else {
244 244
 			$dropdown="dropdown";
245 245
 			$this->mClass="menu";
246 246
 		}
247
-		return $this->addToPropertyCtrl("class", $dropdown,array("menu","dropdown"));
247
+		return $this->addToPropertyCtrl("class", $dropdown, array("menu", "dropdown"));
248 248
 	}
249 249
 
250
-	public function setVertical(){
251
-		return $this->addToPropertyCtrl("class", "vertical",array("vertical"));
250
+	public function setVertical() {
251
+		return $this->addToPropertyCtrl("class", "vertical", array("vertical"));
252 252
 	}
253 253
 
254
-	public function setInline(){
255
-		return $this->addToPropertyCtrl("class", "inline",["inline"]);
254
+	public function setInline() {
255
+		return $this->addToPropertyCtrl("class", "inline", ["inline"]);
256 256
 	}
257 257
 
258
-	public function setSimple(){
259
-		return $this->addToPropertyCtrl("class", "simple",array("simple"));
258
+	public function setSimple() {
259
+		return $this->addToPropertyCtrl("class", "simple", array("simple"));
260 260
 	}
261 261
 
262
-	public function asButton($floating=false){
262
+	public function asButton($floating=false) {
263 263
 		$this->removeArrow();
264
-		if($floating)
264
+		if ($floating)
265 265
 			$this->addToProperty("class", "floating");
266 266
 		$this->removePropertyValue("class", "selection");
267 267
 		return $this->addToProperty("class", "button");
268 268
 	}
269 269
 
270
-	public function asSelect($name=NULL,$multiple=false,$selection=true){
270
+	public function asSelect($name=NULL, $multiple=false, $selection=true) {
271 271
 		$this->_multiple=$multiple;
272
-		if(isset($name))
272
+		if (isset($name))
273 273
 			$this->addInput($name);
274
-		if($multiple){
274
+		if ($multiple) {
275 275
 			$this->addToProperty("class", "multiple");
276 276
 		}
277
-		if ($selection){
278
-			if($this->propertyContains("class", "button")===false)
279
-				$this->addToPropertyCtrl("class", "selection",array("selection"));
277
+		if ($selection) {
278
+			if ($this->propertyContains("class", "button")===false)
279
+				$this->addToPropertyCtrl("class", "selection", array("selection"));
280 280
 		}
281 281
 		return $this;
282 282
 	}
283 283
 
284
-	public function asSearch($name=NULL,$multiple=false,$selection=true){
285
-		$this->asSelect($name,$multiple,$selection);
284
+	public function asSearch($name=NULL, $multiple=false, $selection=true) {
285
+		$this->asSelect($name, $multiple, $selection);
286 286
 		return $this->addToProperty("class", "search");
287 287
 	}
288 288
 
289
-	public function setSelect($name=NULL,$multiple=false){
290
-		if(!isset($name))
289
+	public function setSelect($name=NULL, $multiple=false) {
290
+		if (!isset($name))
291 291
 			$name="select-".$this->identifier;
292 292
 		$this->input=null;
293
-		if($multiple){
293
+		if ($multiple) {
294 294
 			$this->setProperty("multiple", true);
295 295
 			$this->addToProperty("class", "multiple");
296 296
 		}
@@ -298,42 +298,42 @@  discard block
 block discarded – undo
298 298
 		$this->tagName="select";
299 299
 		$this->setProperty("name", $name);
300 300
 		$this->content=null;
301
-		foreach ($this->items as $item){
301
+		foreach ($this->items as $item) {
302 302
 			$item->asOption();
303 303
 		}
304 304
 		return $this;
305 305
 	}
306 306
 
307
-	public function asSubmenu($pointing=NULL){
307
+	public function asSubmenu($pointing=NULL) {
308 308
 		$this->setClass("ui dropdown link item");
309
-		if(isset($pointing)){
309
+		if (isset($pointing)) {
310 310
 			$this->setPointing($pointing);
311 311
 		}
312 312
 		return $this;
313 313
 	}
314 314
 
315
-	public function setPointing($value=Direction::NONE){
316
-		return $this->addToPropertyCtrl("class", $value." pointing",Direction::getConstantValues("pointing"));
315
+	public function setPointing($value=Direction::NONE) {
316
+		return $this->addToPropertyCtrl("class", $value." pointing", Direction::getConstantValues("pointing"));
317 317
 	}
318 318
 
319
-	public function setValue($value){
319
+	public function setValue($value) {
320 320
 		$this->value=$value;
321 321
 		return $this;
322 322
 	}
323 323
 	
324
-	public function setDefaultText($text){
325
-		$this->content["text"]=new HtmlSemDoubleElement("","div","default text",$text);
324
+	public function setDefaultText($text) {
325
+		$this->content["text"]=new HtmlSemDoubleElement("", "div", "default text", $text);
326 326
 	}
327 327
 	
328
-	private function applyValue(){
328
+	private function applyValue() {
329 329
 		$value=$this->value;
330
-		if(isset($this->input) && isset($value)){
330
+		if (isset($this->input) && isset($value)) {
331 331
 			$this->input->setProperty("value", $value);
332
-		}else{
332
+		} else {
333 333
 			$this->setProperty("value", $value);
334 334
 		}
335 335
 			$textElement=$this->getElementById("text-".$this->identifier, $this->content);
336
-			if(isset($textElement) && ($textElement instanceof HtmlDoubleElement) && !$this->_multiple)
336
+			if (isset($textElement) && ($textElement instanceof HtmlDoubleElement) && !$this->_multiple)
337 337
 				$textElement->setContent($value);
338 338
 		return $this;
339 339
 	}
@@ -343,9 +343,9 @@  discard block
 block discarded – undo
343 343
 	 * @see BaseHtml::run()
344 344
 	 */
345 345
 	public function run(JsUtils $js) {
346
-		if($this->propertyContains("class", "simple")===false){
347
-			if(isset($this->_bsComponent)===false){
348
-				$this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier,$this->_params);
346
+		if ($this->propertyContains("class", "simple")===false) {
347
+			if (isset($this->_bsComponent)===false) {
348
+				$this->_bsComponent=$js->semantic()->dropdown("#".$this->identifier, $this->_params);
349 349
 				$this->_bsComponent->setItemSelector(".item");
350 350
 			}
351 351
 			$this->addEventsOnRun($js);
@@ -353,41 +353,41 @@  discard block
 block discarded – undo
353 353
 		}
354 354
 	}
355 355
 
356
-	public function setCompact(){
356
+	public function setCompact() {
357 357
 		return $this->addToPropertyCtrl("class", "compact", array("compact"));
358 358
 	}
359 359
 
360
-	public function setAction($action){
360
+	public function setAction($action) {
361 361
 		$this->_params["action"]=$action;
362 362
 	}
363 363
 
364
-	public function setOn($on){
364
+	public function setOn($on) {
365 365
 		$this->_params["on"]=$on;
366 366
 	}
367 367
 
368
-	public function setShowOnFocus($value){
368
+	public function setShowOnFocus($value) {
369 369
 		$this->_params["showOnFocus"]=$value;
370 370
 	}
371 371
 
372
-	public function setFullTextSearch($value){
372
+	public function setFullTextSearch($value) {
373 373
 		$this->_params["fullTextSearch"]=$value;
374 374
 	}
375 375
 
376 376
 	public function compile(JsUtils $js=NULL, &$view=NULL) {
377 377
 		$this->applyValue();
378
-		return parent::compile($js,$view);
378
+		return parent::compile($js, $view);
379 379
 	}
380 380
 
381 381
 	public function getInput() {
382 382
 		return $this->input;
383 383
 	}
384 384
 
385
-	public function setIcon($icon="dropdown"){
385
+	public function setIcon($icon="dropdown") {
386 386
 		$this->content["arrow"]=new HtmlIcon($this->identifier."-icon", $icon);
387 387
 		return $this;
388 388
 	}
389 389
 
390
-	public function jsAddItem($caption){
390
+	public function jsAddItem($caption) {
391 391
 		$js="var first=$('#{$this->identifier} .item').first();if(first!=undefined){var new =first.clone();first.parent().append(new);first.html('{$caption}};')";
392 392
 		return $js;
393 393
 	}
Please login to merge, or discard this patch.