Completed
Push — master ( d8452d...fcbb8e )
by Jean-Christophe
02:56
created

FieldsTrait::createCondition()   A

Complexity

Conditions 2
Paths 2

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 2
eloc 2
nc 2
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\collections\form\traits;
4
5
use Ajax\service\JArray;
6
use Ajax\semantic\html\collections\form\HtmlFormInput;
7
use Ajax\semantic\html\collections\form\HtmlFormDropdown;
8
use Ajax\semantic\html\elements\HtmlButton;
9
use Ajax\semantic\html\collections\form\HtmlFormCheckbox;
10
use Ajax\semantic\html\collections\form\HtmlFormRadio;
11
use Ajax\semantic\html\collections\form\HtmlFormField;
12
13
trait FieldsTrait {
14
	public abstract function addFields($fields=NULL,$label=NULL);
15
	public abstract function addItem($item);
16
17
	protected function createItem($value){
18
		if(\is_array($value)){
19
			$itemO=new HtmlFormInput(JArray::getDefaultValue($value, "id",""),JArray::getDefaultValue($value, "label",null),JArray::getDefaultValue($value, "type", "text"),JArray::getDefaultValue($value, "value",""),JArray::getDefaultValue($value, "placeholder",JArray::getDefaultValue($value, "label",null)));
20
			return $itemO;
21
		}elseif(\is_object($value)){
22
			$itemO=new HtmlFormField("field-".$this->identifier, $value);
0 ignored issues
show
Bug introduced by
The property identifier does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
			return $itemO;
24
		}else
25
			return new HtmlFormInput($value);
26
	}
27
28
	protected function createCondition($value){
29
		return \is_object($value)===false || $value instanceof \Ajax\semantic\html\elements\HtmlInput;
30
	}
31
32
	public function addInputs($inputs,$fieldslabel=null){
33
		$fields=array();
34
		foreach ($inputs as $input){
35
			\extract($input);
36
			$f=new HtmlFormInput("","");
37
			$f->fromArray($input);
38
			$fields[]=$f;
39
		}
40
		return $this->addFields($fields,$fieldslabel);
41
	}
42
43
	/**
44
	 * @param string $identifier
45
	 * @param array $items
46
	 * @param string $label
47
	 * @param string $value
48
	 * @param boolean $multiple
49
	 * @return \Ajax\common\html\HtmlDoubleElement
50
	 */
51
	public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){
52
		return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple));
53
	}
54
55
	public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){
56
		return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder));
57
	}
58
59
	public function addPassword($identifier, $label=NULL){
60
		return $this->addItem(new HtmlFormInput($identifier,$label,"password","",""));
61
	}
62
63
	public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){
64
		return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick));
65
	}
66
67
	public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){
68
		return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type));
69
	}
70
71
	public function addRadio($identifier, $name,$label=NULL,$value=NULL){
72
		return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value));
73
	}
74
}