Completed
Push — master ( 22ba15...552305 )
by Jean-Christophe
03:10
created
Ajax/semantic/widgets/base/InstanceViewer.php 1 patch
Spacing   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -14,144 +14,144 @@  discard block
 block discarded – undo
14 14
 
15 15
 	public static $index=0;
16 16
 
17
-	public function __construct($instance=NULL,$captions=NULL){
17
+	public function __construct($instance=NULL, $captions=NULL) {
18 18
 		$this->values=[];
19 19
 		$this->afterCompile=[];
20
-		if(isset($instance))
20
+		if (isset($instance))
21 21
 			$this->setInstance($instance);
22 22
 		$this->setCaptions($captions);
23 23
 	}
24 24
 
25
-	public function getValues(){
25
+	public function getValues() {
26 26
 		$values=[];
27 27
 		$index=0;
28 28
 		$count=$this->count();
29
-		while($index<$count){
29
+		while ($index<$count) {
30 30
 			$values[]=$this->getValue($index++);
31 31
 		}
32 32
 		return $values;
33 33
 	}
34 34
 
35
-	public function getIdentifier(){
35
+	public function getIdentifier() {
36 36
 		$value=self::$index;
37
-		if(isset($this->values["identifier"]))
38
-			$value=$this->values["identifier"](self::$index,$this->instance);
37
+		if (isset($this->values["identifier"]))
38
+			$value=$this->values["identifier"](self::$index, $this->instance);
39 39
 		return $value;
40 40
 	}
41 41
 
42
-	public function getValue($index){
42
+	public function getValue($index) {
43 43
 		$property=$this->properties[$index];
44 44
 		return $this->_getValue($property, $index);
45 45
 	}
46 46
 
47
-	protected function _beforeAddProperty($index,&$field){
47
+	protected function _beforeAddProperty($index, &$field) {
48 48
 
49 49
 	}
50 50
 
51
-	protected function _getDefaultValue($name,$value,$index){
51
+	protected function _getDefaultValue($name, $value, $index) {
52 52
 		return $value;
53 53
 	}
54 54
 
55
-	protected function _getValue($property,$index){
56
-		if($property instanceof \ReflectionProperty){
55
+	protected function _getValue($property, $index) {
56
+		if ($property instanceof \ReflectionProperty) {
57 57
 			$property->setAccessible(true);
58 58
 			$value=$property->getValue($this->instance);
59
-			if(isset($this->values[$index])){
60
-				$value= $this->values[$index]($value,$this->instance,$index);
61
-			}else{
62
-				$value=$this->_getDefaultValue($property->getName(),$value, $index);
59
+			if (isset($this->values[$index])) {
60
+				$value=$this->values[$index]($value, $this->instance, $index);
61
+			} else {
62
+				$value=$this->_getDefaultValue($property->getName(), $value, $index);
63 63
 			}
64
-		}else{
65
-			if(\is_callable($property))
64
+		} else {
65
+			if (\is_callable($property))
66 66
 				$value=$property($this->instance);
67
-			elseif(\is_array($property)){
68
-				$values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property);
67
+			elseif (\is_array($property)) {
68
+				$values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property);
69 69
 				$value=\implode("", $values);
70
-			}else{
71
-				if(isset($this->values[$index])){
72
-					$value= $this->values[$index]($property,$this->instance,$index);
73
-				}else{
70
+			} else {
71
+				if (isset($this->values[$index])) {
72
+					$value=$this->values[$index]($property, $this->instance, $index);
73
+				} else {
74 74
 					$value=$property;
75 75
 				}
76 76
 			}
77 77
 		}
78
-		if(isset($this->afterCompile[$index])){
79
-			if(\is_callable($this->afterCompile[$index])){
80
-				$this->afterCompile[$index]($value,$this->instance,$index);
78
+		if (isset($this->afterCompile[$index])) {
79
+			if (\is_callable($this->afterCompile[$index])) {
80
+				$this->afterCompile[$index]($value, $this->instance, $index);
81 81
 			}
82 82
 		}
83 83
 		return $value;
84 84
 	}
85 85
 
86
-	public function insertField($index,$field){
87
-		array_splice( $this->visibleProperties, $index, 0, $field );
86
+	public function insertField($index, $field) {
87
+		array_splice($this->visibleProperties, $index, 0, $field);
88 88
 		return $this;
89 89
 	}
90 90
 
91
-	public function insertInField($index,$field){
91
+	public function insertInField($index, $field) {
92 92
 		$vb=$this->visibleProperties;
93
-		if(isset($vb[$index])){
94
-			if(\is_array($vb[$index])){
93
+		if (isset($vb[$index])) {
94
+			if (\is_array($vb[$index])) {
95 95
 				$this->visibleProperties[$index][]=$field;
96
-			}else{
97
-				$this->visibleProperties[$index]=[$vb[$index],$field];
96
+			} else {
97
+				$this->visibleProperties[$index]=[$vb[$index], $field];
98 98
 			}
99
-		}else{
99
+		} else {
100 100
 			return $this->insertField($index, $field);
101 101
 		}
102 102
 		return $this;
103 103
 	}
104 104
 
105
-	public function addField($field){
105
+	public function addField($field) {
106 106
 		$this->visibleProperties[]=$field;
107 107
 		return $this;
108 108
 	}
109 109
 
110
-	public function count(){
110
+	public function count() {
111 111
 		return \sizeof($this->properties);
112 112
 	}
113 113
 
114
-	public function visiblePropertiesCount(){
114
+	public function visiblePropertiesCount() {
115 115
 		return \sizeof($this->visibleProperties);
116 116
 	}
117 117
 
118
-	public function getProperty($index){
118
+	public function getProperty($index) {
119 119
 		return $this->properties[$index];
120 120
 	}
121 121
 
122
-	protected function showableProperty(\ReflectionProperty $rProperty){
123
-		return JString::startswith($rProperty->getName(),"_")===false;
122
+	protected function showableProperty(\ReflectionProperty $rProperty) {
123
+		return JString::startswith($rProperty->getName(), "_")===false;
124 124
 	}
125 125
 
126 126
 	public function setInstance($instance) {
127
-		if(\is_string($instance)){
127
+		if (\is_string($instance)) {
128 128
 			$instance=new $instance();
129 129
 		}
130 130
 		$this->instance=$instance;
131 131
 		$this->properties=[];
132 132
 		$this->reflect=new \ReflectionClass($instance);
133
-		if(\sizeof($this->visibleProperties)===0){
133
+		if (\sizeof($this->visibleProperties)===0) {
134 134
 			$this->properties=$this->getDefaultProperties();
135
-		}else{
136
-			foreach ($this->visibleProperties as $property){
137
-				if(\is_callable($property)){
135
+		} else {
136
+			foreach ($this->visibleProperties as $property) {
137
+				if (\is_callable($property)) {
138 138
 					$this->properties[]=$property;
139
-				}elseif(\is_string($property)){
140
-					try{
139
+				}elseif (\is_string($property)) {
140
+					try {
141 141
 						$this->_beforeAddProperty(\sizeof($this->properties), $property);
142 142
 						$rProperty=$this->reflect->getProperty($property);
143 143
 						$this->properties[]=$rProperty;
144
-					}catch(\Exception $e){
144
+					}catch (\Exception $e) {
145 145
 						$this->_beforeAddProperty(\sizeof($this->properties), $property);
146 146
 						$this->properties[]=$property;
147 147
 					}
148
-				}elseif(\is_int($property)){
148
+				}elseif (\is_int($property)) {
149 149
 					$props=$this->getDefaultProperties();
150
-					if(isset($props[$property]))
150
+					if (isset($props[$property]))
151 151
 						$this->properties[]=$props[$property];
152 152
 					else
153 153
 						$this->properties[]=$property;
154
-				}else{
154
+				} else {
155 155
 					$this->properties[]=$property;
156 156
 				}
157 157
 			}
@@ -159,12 +159,12 @@  discard block
 block discarded – undo
159 159
 		return $this;
160 160
 	}
161 161
 
162
-	protected function getDefaultProperties(){
162
+	protected function getDefaultProperties() {
163 163
 		$result=[];
164 164
 		$properties=$this->reflect->getProperties();
165
-		foreach ($properties as $property){
165
+		foreach ($properties as $property) {
166 166
 			$showable=$this->showableProperty($property);
167
-			if($showable!==false){
167
+			if ($showable!==false) {
168 168
 				$result[]=$property;
169 169
 			}
170 170
 		}
@@ -176,12 +176,12 @@  discard block
 block discarded – undo
176 176
 		return $this;
177 177
 	}
178 178
 
179
-	public function setValueFunction($index,$callback){
179
+	public function setValueFunction($index, $callback) {
180 180
 		$this->values[$index]=$callback;
181 181
 		return $this;
182 182
 	}
183 183
 
184
-	public function setIdentifierFunction($callback){
184
+	public function setIdentifierFunction($callback) {
185 185
 		$this->values["identifier"]=$callback;
186 186
 		return $this;
187 187
 	}
@@ -194,22 +194,22 @@  discard block
 block discarded – undo
194 194
 		return $this->properties;
195 195
 	}
196 196
 
197
-	public function getCaption($index){
198
-		if(isset($this->captions[$index])){
197
+	public function getCaption($index) {
198
+		if (isset($this->captions[$index])) {
199 199
 			return $this->captions[$index];
200 200
 		}
201
-		if($this->properties[$index] instanceof \ReflectionProperty)
201
+		if ($this->properties[$index] instanceof \ReflectionProperty)
202 202
 			return $this->properties[$index]->getName();
203
-		elseif(\is_callable($this->properties[$index]))
203
+		elseif (\is_callable($this->properties[$index]))
204 204
 			return "";
205 205
 		else
206 206
 			return $this->properties[$index];
207 207
 	}
208 208
 
209
-	public function getCaptions(){
210
-		if(isset($this->captions)){
211
-			$result= $this->captions;
212
-			for($i=\sizeof($result);$i<$this->count();$i++){
209
+	public function getCaptions() {
210
+		if (isset($this->captions)) {
211
+			$result=$this->captions;
212
+			for ($i=\sizeof($result); $i<$this->count(); $i++) {
213 213
 				$result[]="";
214 214
 			}
215 215
 			return $result;
@@ -217,14 +217,14 @@  discard block
 block discarded – undo
217 217
 		$captions=[];
218 218
 		$index=0;
219 219
 		$count=$this->count();
220
-		while($index<$count){
220
+		while ($index<$count) {
221 221
 			$captions[]=$this->getCaption($index++);
222 222
 		}
223 223
 		return $captions;
224 224
 	}
225 225
 
226
-	public function setCaption($index,$caption){
227
-		if(isset($this->captions)===false)
226
+	public function setCaption($index, $caption) {
227
+		if (isset($this->captions)===false)
228 228
 			$this->captions=[];
229 229
 		$this->captions[$index]=$caption;
230 230
 		return $this;
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 	 * @param callable $callback function called after the field compilation
243 243
 	 * @return \Ajax\semantic\widgets\datatable\InstanceViewer
244 244
 	 */
245
-	public function afterCompile($index,$callback){
245
+	public function afterCompile($index, $callback) {
246 246
 		$this->afterCompile[$index]=$callback;
247 247
 		return $this;
248 248
 	}
Please login to merge, or discard this patch.
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.