@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | * @property InstanceViewer $_instanceViewer |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | -trait FieldAsTrait{ |
|
| 20 | +trait FieldAsTrait { |
|
| 21 | 21 | |
| 22 | 22 | abstract protected function _getFieldIdentifier($prefix); |
| 23 | - abstract public function setValueFunction($index,$callback); |
|
| 23 | + abstract public function setValueFunction($index, $callback); |
|
| 24 | 24 | |
| 25 | - private function _getLabelField($caption,$icon=NULL){ |
|
| 26 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
| 25 | + private function _getLabelField($caption, $icon=NULL) { |
|
| 26 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
| 27 | 27 | return $label; |
| 28 | 28 | } |
| 29 | 29 | |
@@ -31,11 +31,11 @@ discard block |
||
| 31 | 31 | * @param HtmlSemDoubleElement $element |
| 32 | 32 | * @param array $attributes |
| 33 | 33 | */ |
| 34 | - protected function _applyAttributes($element,&$attributes,$index){ |
|
| 35 | - if(isset($attributes["callback"])){ |
|
| 34 | + protected function _applyAttributes($element, &$attributes, $index) { |
|
| 35 | + if (isset($attributes["callback"])) { |
|
| 36 | 36 | $callback=$attributes["callback"]; |
| 37 | - if(\is_callable($callback)){ |
|
| 38 | - $callback($element,$this->_modelInstance,$index); |
|
| 37 | + if (\is_callable($callback)) { |
|
| 38 | + $callback($element, $this->_modelInstance, $index); |
|
| 39 | 39 | unset($attributes["callback"]); |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -43,60 +43,60 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
| 46 | - public function fieldAsProgress($index,$label=NULL, $attributes=array()){ |
|
| 47 | - $this->setValueFunction($index,function($value) use($label,$attributes){ |
|
| 48 | - $pb=new HtmlProgress($this->_getFieldIdentifier("pb"),$value,$label,$attributes); |
|
| 46 | + public function fieldAsProgress($index, $label=NULL, $attributes=array()) { |
|
| 47 | + $this->setValueFunction($index, function($value) use($label, $attributes){ |
|
| 48 | + $pb=new HtmlProgress($this->_getFieldIdentifier("pb"), $value, $label, $attributes); |
|
| 49 | 49 | return $pb; |
| 50 | 50 | }); |
| 51 | 51 | return $this; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function fieldAsRating($index,$max=5, $icon=""){ |
|
| 55 | - $this->setValueFunction($index,function($value) use($max,$icon){ |
|
| 56 | - $rating=new HtmlRating($this->_getFieldIdentifier("rat"),$value,$max,$icon); |
|
| 54 | + public function fieldAsRating($index, $max=5, $icon="") { |
|
| 55 | + $this->setValueFunction($index, function($value) use($max, $icon){ |
|
| 56 | + $rating=new HtmlRating($this->_getFieldIdentifier("rat"), $value, $max, $icon); |
|
| 57 | 57 | return $rating; |
| 58 | 58 | }); |
| 59 | 59 | return $this; |
| 60 | 60 | } |
| 61 | 61 | |
| 62 | - public function fieldAsLabel($index,$icon=NULL){ |
|
| 63 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
| 64 | - $lbl=$this->_getLabelField($caption,$icon); |
|
| 62 | + public function fieldAsLabel($index, $icon=NULL) { |
|
| 63 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
| 64 | + $lbl=$this->_getLabelField($caption, $icon); |
|
| 65 | 65 | return $lbl; |
| 66 | 66 | }); |
| 67 | 67 | return $this; |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
|
| 71 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
| 72 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
| 70 | + public function fieldAsImage($index, $size=Size::SMALL, $circular=false) { |
|
| 71 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
| 72 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
| 73 | 73 | return $image; |
| 74 | 74 | }); |
| 75 | 75 | return $this; |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - public function fieldAsAvatar($index){ |
|
| 79 | - $this->setValueFunction($index,function($img){return (new HtmlImage("",$img))->asAvatar();}); |
|
| 78 | + public function fieldAsAvatar($index) { |
|
| 79 | + $this->setValueFunction($index, function($img) {return (new HtmlImage("", $img))->asAvatar(); }); |
|
| 80 | 80 | return $this; |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | |
| 84 | - public function fieldAsRadio($index,$attributes=NULL){ |
|
| 85 | - $this->setValueFunction($index,function($value)use ($index,$attributes){ |
|
| 86 | - if(isset($attributes["name"])===false){ |
|
| 84 | + public function fieldAsRadio($index, $attributes=NULL) { |
|
| 85 | + $this->setValueFunction($index, function($value)use ($index, $attributes){ |
|
| 86 | + if (isset($attributes["name"])===false) { |
|
| 87 | 87 | $attributes["name"]=$this->_instanceViewer->getCaption($index)."[]"; |
| 88 | 88 | } |
| 89 | - $radio=new HtmlRadio($this->_getFieldIdentifier("radio"),$attributes["name"],$value,$value); |
|
| 89 | + $radio=new HtmlRadio($this->_getFieldIdentifier("radio"), $attributes["name"], $value, $value); |
|
| 90 | 90 | $this->_applyAttributes($radio, $attributes, $index); |
| 91 | 91 | return $radio; |
| 92 | 92 | }); |
| 93 | 93 | return $this; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function fieldAsInput($index,$attributes=NULL){ |
|
| 97 | - $this->setValueFunction($index,function($value) use($index,$attributes){ |
|
| 98 | - $input=new HtmlInput($this->_getFieldIdentifier("input"),"text",$value); |
|
| 99 | - if(isset($attributes["name"])===false){ |
|
| 96 | + public function fieldAsInput($index, $attributes=NULL) { |
|
| 97 | + $this->setValueFunction($index, function($value) use($index, $attributes){ |
|
| 98 | + $input=new HtmlInput($this->_getFieldIdentifier("input"), "text", $value); |
|
| 99 | + if (isset($attributes["name"])===false) { |
|
| 100 | 100 | $attributes["name"]=$this->_instanceViewer->getCaption($index)."[]"; |
| 101 | 101 | } |
| 102 | 102 | $input->getField()->setProperty("name", $attributes["name"]); |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | return $this; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function fieldAsCheckbox($index,$attributes=NULL){ |
|
| 110 | - $this->setValueFunction($index,function($value) use($index,$attributes){ |
|
| 111 | - $checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"),"",$value); |
|
| 109 | + public function fieldAsCheckbox($index, $attributes=NULL) { |
|
| 110 | + $this->setValueFunction($index, function($value) use($index, $attributes){ |
|
| 111 | + $checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"), "", $value); |
|
| 112 | 112 | $checkbox->setChecked(JString::isBooleanTrue($value)); |
| 113 | - if(isset($attributes["name"])===false){ |
|
| 113 | + if (isset($attributes["name"])===false) { |
|
| 114 | 114 | $attributes["name"]=$this->_instanceViewer->getCaption($index)."[]"; |
| 115 | 115 | } |
| 116 | 116 | $checkbox->getField()->setProperty("name", $attributes["name"]); |
@@ -120,13 +120,13 @@ discard block |
||
| 120 | 120 | return $this; |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){ |
|
| 124 | - $this->setValueFunction($index,function($value) use($index,$elements,$multiple,$attributes){ |
|
| 125 | - $dd=new HtmlDropdown($this->_getFieldIdentifier("dd"),$value,$elements); |
|
| 126 | - if(isset($attributes["name"])===false){ |
|
| 123 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) { |
|
| 124 | + $this->setValueFunction($index, function($value) use($index, $elements, $multiple, $attributes){ |
|
| 125 | + $dd=new HtmlDropdown($this->_getFieldIdentifier("dd"), $value, $elements); |
|
| 126 | + if (isset($attributes["name"])===false) { |
|
| 127 | 127 | $attributes["name"]=$this->_instanceViewer->getCaption($index)."[]"; |
| 128 | 128 | } |
| 129 | - $dd->asSelect($attributes["name"],$multiple); |
|
| 129 | + $dd->asSelect($attributes["name"], $multiple); |
|
| 130 | 130 | $this->_applyAttributes($dd, $attributes, $index); |
| 131 | 131 | return $dd; |
| 132 | 132 | }); |