1
|
|
|
<?php |
2
|
|
|
namespace Ajax\semantic\widgets\base; |
3
|
|
|
use Ajax\semantic\html\elements\HtmlInput; |
4
|
|
|
use Ajax\semantic\html\modules\checkbox\HtmlCheckbox; |
5
|
|
|
use Ajax\service\JString; |
6
|
|
|
use Ajax\semantic\html\modules\HtmlDropdown; |
7
|
|
|
use Ajax\semantic\html\elements\HtmlImage; |
8
|
|
|
use Ajax\semantic\html\modules\checkbox\HtmlRadio; |
9
|
|
|
use Ajax\semantic\html\base\constants\Size; |
10
|
|
|
use Ajax\semantic\widgets\datatable\InstanceViewer; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author jc |
14
|
|
|
* @property InstanceViewer $_instanceViewer |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
trait FieldAsTrait{ |
18
|
|
|
|
19
|
|
|
protected abstract function _getFieldIdentifier($prefix); |
20
|
|
|
public abstract function setValueFunction($index,$callback); |
21
|
|
|
|
22
|
|
|
public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
23
|
|
|
$this->setValueFunction($index,function($img) use($size,$circular){ |
24
|
|
|
$image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
25
|
|
|
return $image; |
26
|
|
|
} |
27
|
|
|
); |
28
|
|
|
return $this; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
public function fieldAsAvatar($index){ |
32
|
|
|
$this->setValueFunction($index,function($img){return (new HtmlImage("",$img))->asAvatar();}); |
33
|
|
|
return $this; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function fieldAsRadio($index,$name=NULL){ |
37
|
|
|
$this->setValueFunction($index,function($value)use ($index,$name){ |
38
|
|
|
if(isset($name)===false){ |
39
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
$radio=new HtmlRadio($this->_getFieldIdentifier("radio"),$name,$value,$value); |
42
|
|
|
return $radio; |
43
|
|
|
} |
44
|
|
|
); |
45
|
|
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
View Code Duplication |
public function fieldAsInput($index,$name=NULL,$type="text",$placeholder=""){ |
|
|
|
|
49
|
|
|
$this->setValueFunction($index,function($value) use($index,$name,$type,$placeholder){ |
50
|
|
|
$input=new HtmlInput($this->_getFieldIdentifier("input"),$type,$value,$placeholder); |
51
|
|
|
if(isset($name)===false){ |
52
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
53
|
|
|
} |
54
|
|
|
$input->getField()->setProperty("name", $name); |
55
|
|
|
$input->setFluid(); |
56
|
|
|
return $input; |
57
|
|
|
} |
58
|
|
|
); |
59
|
|
|
return $this; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
View Code Duplication |
public function fieldAsCheckbox($index,$name=NULL){ |
|
|
|
|
63
|
|
|
$this->setValueFunction($index,function($value) use($index,$name){ |
64
|
|
|
$checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"),"",$value); |
65
|
|
|
$checkbox->setChecked(JString::isBooleanTrue($value)); |
66
|
|
|
if(isset($name)===false){ |
67
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
$checkbox->getField()->setProperty("name", $name); |
70
|
|
|
return $checkbox;} |
71
|
|
|
); |
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function fieldAsDropDown($index,$elements=[],$multiple=false,$name=NULL){ |
76
|
|
|
$this->setValueFunction($index,function($value) use($index,$elements,$multiple,$name){ |
77
|
|
|
$dd=new HtmlDropdown($this->_getFieldIdentifier("dd"),$value,$elements); |
78
|
|
|
if(isset($name)===false){ |
79
|
|
|
$name=$this->_instanceViewer->getCaption($index)."[]"; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
$dd->asSelect($name,$multiple); |
82
|
|
|
return $dd;} |
83
|
|
|
); |
84
|
|
|
return $this; |
85
|
|
|
} |
86
|
|
|
} |
It seems like you are assigning to a variable which was imported through a
use
statement which was not imported by reference.For clarity, we suggest to use a different name or import by reference depending on whether you would like to have the change visibile in outer-scope.
Change not visible in outer-scope
Change visible in outer-scope