|
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
|
|
|
trait FieldsTrait { |
|
12
|
|
|
protected function createItem($value){ |
|
13
|
|
|
if(\is_array($value)){ |
|
14
|
|
|
$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))); |
|
15
|
|
|
return $itemO; |
|
16
|
|
|
}else |
|
17
|
|
|
return new HtmlFormInput($value); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function addInputs($inputs,$fieldslabel=null){ |
|
21
|
|
|
$fields=array(); |
|
22
|
|
|
foreach ($inputs as $input){ |
|
23
|
|
|
\extract($input); |
|
24
|
|
|
$f=new HtmlFormInput("",""); |
|
25
|
|
|
$f->fromArray($input); |
|
26
|
|
|
$fields[]=$f; |
|
27
|
|
|
} |
|
28
|
|
|
return $this->addFields($fields,$fieldslabel); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @param string $identifier |
|
33
|
|
|
* @param array $items |
|
34
|
|
|
* @param string $label |
|
35
|
|
|
* @param string $value |
|
36
|
|
|
* @param string $multiple |
|
37
|
|
|
* @return \Ajax\common\html\HtmlDoubleElement |
|
38
|
|
|
*/ |
|
39
|
|
|
public function addDropdown($identifier,$items=array(), $label=NULL,$value=NULL,$multiple=false){ |
|
40
|
|
|
return $this->addItem(new HtmlFormDropdown($identifier,$items,$label,$value,$multiple)); |
|
|
|
|
|
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function addInput($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL){ |
|
44
|
|
|
return $this->addItem(new HtmlFormInput($identifier,$label,$type,$value,$placeholder)); |
|
|
|
|
|
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function addButton($identifier,$value,$cssStyle=NULL,$onClick=NULL){ |
|
48
|
|
|
return $this->addItem(new HtmlButton($identifier,$value,$cssStyle,$onClick)); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
public function addCheckbox($identifier, $label=NULL,$value=NULL,$type=NULL){ |
|
52
|
|
|
return $this->addItem(new HtmlFormCheckbox($identifier,$label,$value,$type)); |
|
|
|
|
|
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
public function addRadio($identifier, $name,$label=NULL,$value=NULL){ |
|
56
|
|
|
return $this->addItem(new HtmlFormRadio($identifier,$name,$label,$value)); |
|
|
|
|
|
|
57
|
|
|
} |
|
58
|
|
|
} |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idableprovides a methodequalsIdthat in turn relies on the methodgetId(). If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()as an abstract method to the trait will make sure it is available.