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