Completed
Push — master ( 22ba15...552305 )
by Jean-Christophe
03:10
created
Ajax/semantic/widgets/base/FieldAsTrait.php 1 patch
Spacing   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -16,111 +16,111 @@
 block discarded – undo
16 16
  * @property InstanceViewer $_instanceViewer
17 17
  */
18 18
 
19
-trait FieldAsTrait{
19
+trait FieldAsTrait {
20 20
 
21 21
 	abstract protected function _getFieldIdentifier($prefix);
22
-	abstract public function setValueFunction($index,$callback);
22
+	abstract public function setValueFunction($index, $callback);
23 23
 
24
-	private function _getLabelField($caption,$icon=NULL){
25
-		$label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon);
24
+	private function _getLabelField($caption, $icon=NULL) {
25
+		$label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon);
26 26
 		return $label;
27 27
 	}
28 28
 
29
-	protected function _addRules($element,$attributes){}
29
+	protected function _addRules($element, $attributes) {}
30 30
 
31
-	protected function _fieldAs($elementCallback,$index,$attributes=NULL,$prefix=null){
32
-		$this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback,$prefix){
31
+	protected function _fieldAs($elementCallback, $index, $attributes=NULL, $prefix=null) {
32
+		$this->setValueFunction($index, function($value) use ($index, &$attributes, $elementCallback, $prefix){
33 33
 			$name=$this->_instanceViewer->getCaption($index)."[]";
34
-			if(isset($attributes["name"])===true){
34
+			if (isset($attributes["name"])===true) {
35 35
 				$name=$attributes["name"];
36 36
 			}
37
-			$element=$elementCallback($this->_getFieldIdentifier($prefix),$name,$value,"");
38
-			if(\is_array($attributes))
39
-				$this->_applyAttributes($element, $attributes,$index);
37
+			$element=$elementCallback($this->_getFieldIdentifier($prefix), $name, $value, "");
38
+			if (\is_array($attributes))
39
+				$this->_applyAttributes($element, $attributes, $index);
40 40
 			return $element;
41 41
 		});
42 42
 			return $this;
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,$attributes=NULL){
79
-		return $this->_fieldAs(function($id,$name,$value){
80
-			$img=new HtmlImage($id,$value);
78
+	public function fieldAsAvatar($index, $attributes=NULL) {
79
+		return $this->_fieldAs(function($id, $name, $value) {
80
+			$img=new HtmlImage($id, $value);
81 81
 			$img->asAvatar();
82 82
 			return $img;
83
-		}, $index,$attributes,"avatar");
83
+		}, $index, $attributes, "avatar");
84 84
 	}
85 85
 
86
-	public function fieldAsRadio($index,$attributes=NULL){
87
-		return $this->_fieldAs(function($id,$name,$value){
88
-			$input= new HtmlRadio($id,$name,$value,$value);
86
+	public function fieldAsRadio($index, $attributes=NULL) {
87
+		return $this->_fieldAs(function($id, $name, $value) {
88
+			$input=new HtmlRadio($id, $name, $value, $value);
89 89
 			return $input;
90
-		}, $index,$attributes,"radio");
90
+		}, $index, $attributes, "radio");
91 91
 	}
92 92
 
93
-	public function fieldAsInput($index,$attributes=NULL){
94
-		return $this->_fieldAs(function($id,$name,$value){
95
-			$input= new HtmlInput($id,"text",$value);
93
+	public function fieldAsInput($index, $attributes=NULL) {
94
+		return $this->_fieldAs(function($id, $name, $value) {
95
+			$input=new HtmlInput($id, "text", $value);
96 96
 			//TODO check getField
97 97
 			$input->setName($name);
98 98
 			return $input;
99
-		}, $index,$attributes,"input");
99
+		}, $index, $attributes, "input");
100 100
 	}
101 101
 
102
-	public function fieldAsHidden($index,$attributes=NULL){
103
-		if(\is_array($attributes)===false){
102
+	public function fieldAsHidden($index, $attributes=NULL) {
103
+		if (\is_array($attributes)===false) {
104 104
 			$attributes=[];
105 105
 		}
106 106
 		$attributes["imputType"]="hidden";
107
-		return $this->fieldAsInput($index,$attributes);
107
+		return $this->fieldAsInput($index, $attributes);
108 108
 	}
109 109
 
110
-	public function fieldAsCheckbox($index,$attributes=NULL){
111
-		return $this->_fieldAs(function($id,$name,$value){
112
-			$input=new HtmlCheckbox($id,"",$this->_instanceViewer->getIdentifier());
110
+	public function fieldAsCheckbox($index, $attributes=NULL) {
111
+		return $this->_fieldAs(function($id, $name, $value) {
112
+			$input=new HtmlCheckbox($id, "", $this->_instanceViewer->getIdentifier());
113 113
 			$input->setChecked(JString::isBooleanTrue($value));
114 114
 			$input->getField()->setProperty("name", $name);
115 115
 			return $input;
116
-		}, $index,$attributes,"ck");
116
+		}, $index, $attributes, "ck");
117 117
 	}
118 118
 
119
-	public function fieldAsDropDown($index,$elements=[],$multiple=false,$attributes=NULL){
120
-		return $this->_fieldAs(function($id,$name,$value) use($elements,$multiple){
121
-			$dd=new HtmlDropdown($id,$value,$elements);
122
-			$dd->asSelect($name,$multiple);
119
+	public function fieldAsDropDown($index, $elements=[], $multiple=false, $attributes=NULL) {
120
+		return $this->_fieldAs(function($id, $name, $value) use($elements, $multiple){
121
+			$dd=new HtmlDropdown($id, $value, $elements);
122
+			$dd->asSelect($name, $multiple);
123 123
 			return $dd;
124
-		}, $index,$attributes,"dd");
124
+		}, $index, $attributes, "dd");
125 125
 	}
126 126
 }
127 127
\ No newline at end of file
Please login to merge, or discard this patch.