Completed
Push — master ( 0ed595...25ea1a )
by Jean-Christophe
03:24
created
Ajax/common/html/traits/BaseHtmlEventsTrait.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
  * @property SimpleExtComponent $_bsComponent
11 11
  * @property string identifier
12 12
  */
13
-trait BaseHtmlEventsTrait{
13
+trait BaseHtmlEventsTrait {
14 14
 
15
-	protected $_events=array ();
15
+	protected $_events=array();
16 16
 
17 17
 	public function addEvent($event, $jsCode, $stopPropagation=false, $preventDefault=false) {
18
-		if ($stopPropagation === true) {
19
-			$jsCode="event.stopPropagation();" . $jsCode;
18
+		if ($stopPropagation===true) {
19
+			$jsCode="event.stopPropagation();".$jsCode;
20 20
 		}
21
-		if ($preventDefault === true) {
22
-			$jsCode="event.preventDefault();" . $jsCode;
21
+		if ($preventDefault===true) {
22
+			$jsCode="event.preventDefault();".$jsCode;
23 23
 		}
24 24
 		return $this->_addEvent($event, $jsCode);
25 25
 	}
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 			if (is_array($this->_events[$event])) {
30 30
 				$this->_events[$event][]=$jsCode;
31 31
 			} else {
32
-				$this->_events[$event]=array ($this->_events[$event],$jsCode );
32
+				$this->_events[$event]=array($this->_events[$event], $jsCode);
33 33
 			}
34 34
 		} else {
35 35
 			$this->_events[$event]=$jsCode;
@@ -49,10 +49,10 @@  discard block
 block discarded – undo
49 49
 		return $this->onClick($jsCode);
50 50
 	}
51 51
 
52
-	public function onCreate($jsCode){
53
-		if(isset($this->_events["_create"])){
52
+	public function onCreate($jsCode) {
53
+		if (isset($this->_events["_create"])) {
54 54
 			$this->_events["_create"][]=$jsCode;
55
-		}else{
55
+		} else {
56 56
 			$this->_events["_create"]=[$jsCode];
57 57
 		}
58 58
 		return $this;
@@ -61,15 +61,15 @@  discard block
 block discarded – undo
61 61
 	public function addEventsOnRun(JsUtils $js=NULL) {
62 62
 		$this->_eventsOnCreate($js);
63 63
 		if (isset($this->_bsComponent)) {
64
-			foreach ( $this->_events as $event => $jsCode ) {
64
+			foreach ($this->_events as $event => $jsCode) {
65 65
 				$code=$jsCode;
66 66
 				if (is_array($jsCode)) {
67 67
 					$code="";
68
-					foreach ( $jsCode as $jsC ) {
68
+					foreach ($jsCode as $jsC) {
69 69
 						if ($jsC instanceof AjaxCall) {
70
-							$code.="\n" . $jsC->compile($js);
70
+							$code.="\n".$jsC->compile($js);
71 71
 						} else {
72
-							$code.="\n" . $jsC;
72
+							$code.="\n".$jsC;
73 73
 						}
74 74
 					}
75 75
 				} elseif ($jsCode instanceof AjaxCall) {
@@ -77,24 +77,24 @@  discard block
 block discarded – undo
77 77
 				}
78 78
 				$this->_bsComponent->addEvent($event, $code);
79 79
 			}
80
-			$this->_events=array ();
80
+			$this->_events=array();
81 81
 		}
82 82
 	}
83 83
 
84
-	protected function _eventsOnCreate(JsUtils $js=NULL){
85
-		if(isset($this->_events["_create"])){
84
+	protected function _eventsOnCreate(JsUtils $js=NULL) {
85
+		if (isset($this->_events["_create"])) {
86 86
 			$create=$this->_events["_create"];
87
-			if(\is_array($create)){
87
+			if (\is_array($create)) {
88 88
 				$create=\implode("", $create);
89 89
 			}
90
-			if(isset($js) && $create!=="")
91
-				$js->exec($create,true);
90
+			if (isset($js) && $create!=="")
91
+				$js->exec($create, true);
92 92
 			unset($this->_events["_create"]);
93 93
 		}
94 94
 	}
95 95
 
96 96
 	public function _ajaxOn($operation, $event, $url, $responseElement="", $parameters=array()) {
97
-		$params=array ("url" => $url,"responseElement" => $responseElement );
97
+		$params=array("url" => $url, "responseElement" => $responseElement);
98 98
 		$params=array_merge($params, $parameters);
99 99
 		$this->_addEvent($event, new AjaxCall($operation, $params));
100 100
 		return $this;
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
 	}
128 128
 
129 129
 	public function jsDoJquery($jqueryCall, $param="") {
130
-		return "$('#" . $this->identifier . "')." . $jqueryCall . "(" . Javascript::prep_value($param) . ");";
130
+		return "$('#".$this->identifier."').".$jqueryCall."(".Javascript::prep_value($param).");";
131 131
 	}
132 132
 
133 133
 	public function executeOnRun($jsCode) {
Please login to merge, or discard this patch.
Braces   +4 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	public function onCreate($jsCode){
53 53
 		if(isset($this->_events["_create"])){
54 54
 			$this->_events["_create"][]=$jsCode;
55
-		}else{
55
+		} else{
56 56
 			$this->_events["_create"]=[$jsCode];
57 57
 		}
58 58
 		return $this;
@@ -87,8 +87,9 @@  discard block
 block discarded – undo
87 87
 			if(\is_array($create)){
88 88
 				$create=\implode("", $create);
89 89
 			}
90
-			if(isset($js) && $create!=="")
91
-				$js->exec($create,true);
90
+			if(isset($js) && $create!=="") {
91
+							$js->exec($create,true);
92
+			}
92 93
 			unset($this->_events["_create"]);
93 94
 		}
94 95
 	}
Please login to merge, or discard this patch.
Ajax/semantic/widgets/base/InstanceViewer.php 2 patches
Spacing   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -16,163 +16,163 @@  discard block
 block discarded – undo
16 16
 
17 17
 	public static $index=0;
18 18
 
19
-	public function __construct($identifier,$instance=NULL,$captions=NULL){
19
+	public function __construct($identifier, $instance=NULL, $captions=NULL) {
20 20
 		$this->widgetIdentifier=$identifier;
21 21
 		$this->values=[];
22 22
 		$this->afterCompile=[];
23
-		if(isset($instance))
23
+		if (isset($instance))
24 24
 			$this->setInstance($instance);
25 25
 		$this->setCaptions($captions);
26 26
 		$this->captionCallback=NULL;
27 27
 	}
28 28
 
29
-	public function getValues(){
29
+	public function getValues() {
30 30
 		$values=[];
31 31
 		$index=0;
32 32
 		$count=$this->count();
33
-		while($index<$count){
33
+		while ($index<$count) {
34 34
 			$values[]=$this->getValue($index++);
35 35
 		}
36 36
 		return $values;
37 37
 	}
38 38
 
39
-	public function getIdentifier(){
39
+	public function getIdentifier() {
40 40
 		$value=self::$index;
41
-		if(isset($this->values["identifier"]))
42
-			$value=$this->values["identifier"](self::$index,$this->instance);
41
+		if (isset($this->values["identifier"]))
42
+			$value=$this->values["identifier"](self::$index, $this->instance);
43 43
 		return $value;
44 44
 	}
45 45
 
46
-	public function getValue($index){
46
+	public function getValue($index) {
47 47
 		$property=$this->properties[$index];
48 48
 		return $this->_getValue($property, $index);
49 49
 	}
50 50
 
51
-	protected function _beforeAddProperty($index,&$field){
51
+	protected function _beforeAddProperty($index, &$field) {
52 52
 
53 53
 	}
54 54
 
55
-	protected function _getDefaultValue($name,$value,$index){
55
+	protected function _getDefaultValue($name, $value, $index) {
56 56
 		return $value;
57 57
 	}
58 58
 
59
-	protected function _getValue($property,$index){
60
-		if($property instanceof \ReflectionProperty){
59
+	protected function _getValue($property, $index) {
60
+		if ($property instanceof \ReflectionProperty) {
61 61
 			$property->setAccessible(true);
62 62
 			$value=$property->getValue($this->instance);
63
-			if(isset($this->values[$index])){
64
-				$value= $this->values[$index]($value,$this->instance,$index);
65
-			}else{
66
-				$value=$this->_getDefaultValue($property->getName(),$value, $index);
63
+			if (isset($this->values[$index])) {
64
+				$value=$this->values[$index]($value, $this->instance, $index);
65
+			} else {
66
+				$value=$this->_getDefaultValue($property->getName(), $value, $index);
67 67
 			}
68
-		}else{
69
-			if(\is_callable($property))
68
+		} else {
69
+			if (\is_callable($property))
70 70
 				$value=$property($this->instance);
71
-			elseif(\is_array($property)){
72
-				$values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property);
71
+			elseif (\is_array($property)) {
72
+				$values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property);
73 73
 				$value=\implode("", $values);
74
-			}else{
75
-				if(isset($this->values[$index])){
76
-					$value= $this->values[$index]($property,$this->instance,$index);
77
-				}else{
74
+			} else {
75
+				if (isset($this->values[$index])) {
76
+					$value=$this->values[$index]($property, $this->instance, $index);
77
+				} else {
78 78
 					$value=$property;
79 79
 				}
80 80
 			}
81 81
 		}
82
-		if(isset($this->afterCompile[$index])){
83
-			if(\is_callable($this->afterCompile[$index])){
84
-				$this->afterCompile[$index]($value,$this->instance,$index);
82
+		if (isset($this->afterCompile[$index])) {
83
+			if (\is_callable($this->afterCompile[$index])) {
84
+				$this->afterCompile[$index]($value, $this->instance, $index);
85 85
 			}
86 86
 		}
87 87
 		return $value;
88 88
 	}
89 89
 
90
-	public function insertField($index,$field){
91
-		array_splice( $this->visibleProperties, $index, 0, $field );
90
+	public function insertField($index, $field) {
91
+		array_splice($this->visibleProperties, $index, 0, $field);
92 92
 		return $this;
93 93
 	}
94 94
 
95
-	public function insertInField($index,$field){
95
+	public function insertInField($index, $field) {
96 96
 		$vb=$this->visibleProperties;
97
-		if(isset($vb[$index])){
98
-			if(\is_array($vb[$index])){
97
+		if (isset($vb[$index])) {
98
+			if (\is_array($vb[$index])) {
99 99
 				$this->visibleProperties[$index][]=$field;
100
-			}else{
101
-				$this->visibleProperties[$index]=[$vb[$index],$field];
100
+			} else {
101
+				$this->visibleProperties[$index]=[$vb[$index], $field];
102 102
 			}
103
-		}else{
103
+		} else {
104 104
 			return $this->insertField($index, $field);
105 105
 		}
106 106
 		return $this;
107 107
 	}
108 108
 
109
-	public function addField($field){
109
+	public function addField($field) {
110 110
 		$this->visibleProperties[]=$field;
111 111
 		return $this;
112 112
 	}
113 113
 
114
-	public function count(){
114
+	public function count() {
115 115
 		return \sizeof($this->properties);
116 116
 	}
117 117
 
118
-	public function visiblePropertiesCount(){
118
+	public function visiblePropertiesCount() {
119 119
 		return \sizeof($this->visibleProperties);
120 120
 	}
121 121
 
122
-	public function getProperty($index){
122
+	public function getProperty($index) {
123 123
 		return $this->properties[$index];
124 124
 	}
125 125
 
126
-	protected function showableProperty(\ReflectionProperty $rProperty){
127
-		return JString::startswith($rProperty->getName(),"_")===false;
126
+	protected function showableProperty(\ReflectionProperty $rProperty) {
127
+		return JString::startswith($rProperty->getName(), "_")===false;
128 128
 	}
129 129
 
130 130
 	public function setInstance($instance) {
131
-		if(\is_string($instance)){
131
+		if (\is_string($instance)) {
132 132
 			$instance=new $instance();
133 133
 		}
134 134
 		$this->instance=$instance;
135 135
 		$this->properties=[];
136 136
 		$this->reflect=new \ReflectionClass($instance);
137
-		if(\sizeof($this->visibleProperties)===0){
137
+		if (\sizeof($this->visibleProperties)===0) {
138 138
 			$this->properties=$this->getDefaultProperties();
139
-		}else{
140
-			foreach ($this->visibleProperties as $property){
139
+		} else {
140
+			foreach ($this->visibleProperties as $property) {
141 141
 				$this->setInstanceProperty($property);
142 142
 			}
143 143
 		}
144 144
 		return $this;
145 145
 	}
146 146
 
147
-	private function setInstanceProperty($property){
148
-		if(\is_callable($property)){
147
+	private function setInstanceProperty($property) {
148
+		if (\is_callable($property)) {
149 149
 			$this->properties[]=$property;
150
-		}elseif(\is_string($property)){
151
-			try{
150
+		}elseif (\is_string($property)) {
151
+			try {
152 152
 				$this->_beforeAddProperty(\sizeof($this->properties), $property);
153 153
 				$rProperty=$this->reflect->getProperty($property);
154 154
 				$this->properties[]=$rProperty;
155
-			}catch(\Exception $e){
155
+			}catch (\Exception $e) {
156 156
 				$this->_beforeAddProperty(\sizeof($this->properties), $property);
157 157
 				$this->properties[]=$property;
158 158
 			}
159
-		}elseif(\is_int($property)){
159
+		}elseif (\is_int($property)) {
160 160
 			$props=$this->getDefaultProperties();
161
-			if(isset($props[$property]))
161
+			if (isset($props[$property]))
162 162
 				$this->properties[]=$props[$property];
163 163
 				else
164 164
 					$this->properties[]=$property;
165
-		}else{
165
+		} else {
166 166
 			$this->properties[]=$property;
167 167
 		}
168 168
 	}
169 169
 
170
-	protected function getDefaultProperties(){
170
+	protected function getDefaultProperties() {
171 171
 		$result=[];
172 172
 		$properties=$this->reflect->getProperties();
173
-		foreach ($properties as $property){
173
+		foreach ($properties as $property) {
174 174
 			$showable=$this->showableProperty($property);
175
-			if($showable!==false){
175
+			if ($showable!==false) {
176 176
 				$result[]=$property;
177 177
 			}
178 178
 		}
@@ -184,12 +184,12 @@  discard block
 block discarded – undo
184 184
 		return $this;
185 185
 	}
186 186
 
187
-	public function setValueFunction($index,$callback){
187
+	public function setValueFunction($index, $callback) {
188 188
 		$this->values[$index]=$callback;
189 189
 		return $this;
190 190
 	}
191 191
 
192
-	public function setIdentifierFunction($callback){
192
+	public function setIdentifierFunction($callback) {
193 193
 		$this->values["identifier"]=$callback;
194 194
 		return $this;
195 195
 	}
@@ -202,41 +202,41 @@  discard block
 block discarded – undo
202 202
 		return $this->properties;
203 203
 	}
204 204
 
205
-	public function getCaption($index){
206
-		if(isset($this->captions[$index])){
205
+	public function getCaption($index) {
206
+		if (isset($this->captions[$index])) {
207 207
 			return $this->captions[$index];
208 208
 		}
209
-		if($this->properties[$index] instanceof \ReflectionProperty)
209
+		if ($this->properties[$index] instanceof \ReflectionProperty)
210 210
 			return $this->properties[$index]->getName();
211
-		elseif(\is_callable($this->properties[$index]))
211
+		elseif (\is_callable($this->properties[$index]))
212 212
 			return "";
213 213
 		else
214 214
 			return $this->properties[$index];
215 215
 	}
216 216
 
217
-	public function getCaptions(){
218
-		if(isset($this->captions)){
219
-			$captions= $this->captions;
220
-			for($i=\sizeof($captions);$i<$this->count();$i++){
217
+	public function getCaptions() {
218
+		if (isset($this->captions)) {
219
+			$captions=$this->captions;
220
+			for ($i=\sizeof($captions); $i<$this->count(); $i++) {
221 221
 				$captions[]="";
222 222
 			}
223
-		}else{
223
+		} else {
224 224
 			$captions=[];
225 225
 			$index=0;
226 226
 			$count=$this->count();
227
-			while($index<$count){
227
+			while ($index<$count) {
228 228
 				$captions[]=$this->getCaption($index++);
229 229
 			}
230 230
 		}
231
-		if(isset($this->captionCallback) && \is_callable($this->captionCallback)){
231
+		if (isset($this->captionCallback) && \is_callable($this->captionCallback)) {
232 232
 			$callback=$this->captionCallback;
233
-			$callback($captions,$this->instance);
233
+			$callback($captions, $this->instance);
234 234
 		}
235 235
 		return $captions;
236 236
 	}
237 237
 
238
-	public function setCaption($index,$caption){
239
-		if(isset($this->captions)===false)
238
+	public function setCaption($index, $caption) {
239
+		if (isset($this->captions)===false)
240 240
 			$this->captions=[];
241 241
 		$this->captions[$index]=$caption;
242 242
 		return $this;
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	 * @param callable $callback function called after the field compilation
255 255
 	 * @return \Ajax\semantic\widgets\datatable\InstanceViewer
256 256
 	 */
257
-	public function afterCompile($index,$callback){
257
+	public function afterCompile($index, $callback) {
258 258
 		$this->afterCompile[$index]=$callback;
259 259
 		return $this;
260 260
 	}
Please login to merge, or discard this patch.
Braces   +36 added lines, -31 removed lines patch added patch discarded remove patch
@@ -20,8 +20,9 @@  discard block
 block discarded – undo
20 20
 		$this->widgetIdentifier=$identifier;
21 21
 		$this->values=[];
22 22
 		$this->afterCompile=[];
23
-		if(isset($instance))
24
-			$this->setInstance($instance);
23
+		if(isset($instance)) {
24
+					$this->setInstance($instance);
25
+		}
25 26
 		$this->setCaptions($captions);
26 27
 		$this->captionCallback=NULL;
27 28
 	}
@@ -38,8 +39,9 @@  discard block
 block discarded – undo
38 39
 
39 40
 	public function getIdentifier(){
40 41
 		$value=self::$index;
41
-		if(isset($this->values["identifier"]))
42
-			$value=$this->values["identifier"](self::$index,$this->instance);
42
+		if(isset($this->values["identifier"])) {
43
+					$value=$this->values["identifier"](self::$index,$this->instance);
44
+		}
43 45
 		return $value;
44 46
 	}
45 47
 
@@ -62,19 +64,19 @@  discard block
 block discarded – undo
62 64
 			$value=$property->getValue($this->instance);
63 65
 			if(isset($this->values[$index])){
64 66
 				$value= $this->values[$index]($value,$this->instance,$index);
65
-			}else{
67
+			} else{
66 68
 				$value=$this->_getDefaultValue($property->getName(),$value, $index);
67 69
 			}
68
-		}else{
69
-			if(\is_callable($property))
70
-				$value=$property($this->instance);
71
-			elseif(\is_array($property)){
70
+		} else{
71
+			if(\is_callable($property)) {
72
+							$value=$property($this->instance);
73
+			} elseif(\is_array($property)){
72 74
 				$values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property);
73 75
 				$value=\implode("", $values);
74
-			}else{
76
+			} else{
75 77
 				if(isset($this->values[$index])){
76 78
 					$value= $this->values[$index]($property,$this->instance,$index);
77
-				}else{
79
+				} else{
78 80
 					$value=$property;
79 81
 				}
80 82
 			}
@@ -97,10 +99,10 @@  discard block
 block discarded – undo
97 99
 		if(isset($vb[$index])){
98 100
 			if(\is_array($vb[$index])){
99 101
 				$this->visibleProperties[$index][]=$field;
100
-			}else{
102
+			} else{
101 103
 				$this->visibleProperties[$index]=[$vb[$index],$field];
102 104
 			}
103
-		}else{
105
+		} else{
104 106
 			return $this->insertField($index, $field);
105 107
 		}
106 108
 		return $this;
@@ -136,7 +138,7 @@  discard block
 block discarded – undo
136 138
 		$this->reflect=new \ReflectionClass($instance);
137 139
 		if(\sizeof($this->visibleProperties)===0){
138 140
 			$this->properties=$this->getDefaultProperties();
139
-		}else{
141
+		} else{
140 142
 			foreach ($this->visibleProperties as $property){
141 143
 				$this->setInstanceProperty($property);
142 144
 			}
@@ -147,22 +149,23 @@  discard block
 block discarded – undo
147 149
 	private function setInstanceProperty($property){
148 150
 		if(\is_callable($property)){
149 151
 			$this->properties[]=$property;
150
-		}elseif(\is_string($property)){
152
+		} elseif(\is_string($property)){
151 153
 			try{
152 154
 				$this->_beforeAddProperty(\sizeof($this->properties), $property);
153 155
 				$rProperty=$this->reflect->getProperty($property);
154 156
 				$this->properties[]=$rProperty;
155
-			}catch(\Exception $e){
157
+			} catch(\Exception $e){
156 158
 				$this->_beforeAddProperty(\sizeof($this->properties), $property);
157 159
 				$this->properties[]=$property;
158 160
 			}
159
-		}elseif(\is_int($property)){
161
+		} elseif(\is_int($property)){
160 162
 			$props=$this->getDefaultProperties();
161
-			if(isset($props[$property]))
162
-				$this->properties[]=$props[$property];
163
-				else
164
-					$this->properties[]=$property;
165
-		}else{
163
+			if(isset($props[$property])) {
164
+							$this->properties[]=$props[$property];
165
+			} else {
166
+									$this->properties[]=$property;
167
+				}
168
+		} else{
166 169
 			$this->properties[]=$property;
167 170
 		}
168 171
 	}
@@ -206,12 +209,13 @@  discard block
 block discarded – undo
206 209
 		if(isset($this->captions[$index])){
207 210
 			return $this->captions[$index];
208 211
 		}
209
-		if($this->properties[$index] instanceof \ReflectionProperty)
210
-			return $this->properties[$index]->getName();
211
-		elseif(\is_callable($this->properties[$index]))
212
-			return "";
213
-		else
214
-			return $this->properties[$index];
212
+		if($this->properties[$index] instanceof \ReflectionProperty) {
213
+					return $this->properties[$index]->getName();
214
+		} elseif(\is_callable($this->properties[$index])) {
215
+					return "";
216
+		} else {
217
+					return $this->properties[$index];
218
+		}
215 219
 	}
216 220
 
217 221
 	public function getCaptions(){
@@ -220,7 +224,7 @@  discard block
 block discarded – undo
220 224
 			for($i=\sizeof($captions);$i<$this->count();$i++){
221 225
 				$captions[]="";
222 226
 			}
223
-		}else{
227
+		} else{
224 228
 			$captions=[];
225 229
 			$index=0;
226 230
 			$count=$this->count();
@@ -236,8 +240,9 @@  discard block
 block discarded – undo
236 240
 	}
237 241
 
238 242
 	public function setCaption($index,$caption){
239
-		if(isset($this->captions)===false)
240
-			$this->captions=[];
243
+		if(isset($this->captions)===false) {
244
+					$this->captions=[];
245
+		}
241 246
 		$this->captions[$index]=$caption;
242 247
 		return $this;
243 248
 	}
Please login to merge, or discard this patch.