Passed
Push — master ( e7448c...858380 )
by Jean-Christophe
01:44
created
Ajax/semantic/html/collections/form/traits/FormTrait.php 1 patch
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
  * @author jc
16 16
  *
17 17
  */
18
-trait FormTrait{
18
+trait FormTrait {
19 19
 
20 20
 	/**
21 21
 	 * @return HtmlForm
@@ -23,23 +23,23 @@  discard block
 block discarded – undo
23 23
 	abstract protected function getForm();
24 24
 	
25 25
 
26
-	protected function addCompoValidation(Form $compo,HtmlFormField $field){
26
+	protected function addCompoValidation(Form $compo, HtmlFormField $field) {
27 27
 		$validation=$field->getValidation();
28
-		if(isset($validation)){
28
+		if (isset($validation)) {
29 29
 			$validation->setIdentifier($field->getDataField()->getIdentifier());
30 30
 			$compo->addFieldValidation($validation);
31 31
 		}
32 32
 	}
33 33
 	
34
-	protected function addExtraCompoValidation(Form $compo,FieldValidation $validation){
34
+	protected function addExtraCompoValidation(Form $compo, FieldValidation $validation) {
35 35
 		$compo->addFieldValidation($validation);
36 36
 	}
37 37
 
38
-	protected function _runValidationParams(Form &$compo,JsUtils $js=NULL){
38
+	protected function _runValidationParams(Form &$compo, JsUtils $js=NULL) {
39 39
 		$form=$this->getForm();
40 40
 		$params=$form->getValidationParams();
41
-		if(isset($params["_ajaxSubmit"])){
42
-			$compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"],$js);
41
+		if (isset($params["_ajaxSubmit"])) {
42
+			$compilation=$this->_compileAjaxSubmit($params["_ajaxSubmit"], $js);
43 43
 			$this->onSuccess($compilation);
44 44
 			$form->removeValidationParam("_ajaxSubmit");
45 45
 		}
@@ -48,16 +48,16 @@  discard block
 block discarded – undo
48 48
 		$form->addEventsOnRun($js);
49 49
 	}
50 50
 
51
-	protected function _compileAjaxSubmit($ajaxSubmit,JsUtils $js=null){
51
+	protected function _compileAjaxSubmit($ajaxSubmit, JsUtils $js=null) {
52 52
 		$compilation="";
53
-		if(\is_array($ajaxSubmit)){
54
-			foreach ($ajaxSubmit as $ajaxSubmitItem){
53
+		if (\is_array($ajaxSubmit)) {
54
+			foreach ($ajaxSubmit as $ajaxSubmitItem) {
55 55
 				$compilation.=$ajaxSubmitItem->compile($js);
56 56
 			}
57
-		}elseif($ajaxSubmit instanceof AjaxCall){
57
+		}elseif ($ajaxSubmit instanceof AjaxCall) {
58 58
 			$compilation=$ajaxSubmit->compile($js);
59 59
 		}
60
-		$compilation=str_ireplace("\"","%quote%", $compilation);
60
+		$compilation=str_ireplace("\"", "%quote%", $compilation);
61 61
 		return $compilation;
62 62
 	}
63 63
 
@@ -70,14 +70,14 @@  discard block
 block discarded – undo
70 70
 		return $this;
71 71
 	}
72 72
 
73
-	public function setAttached($value=true){
73
+	public function setAttached($value=true) {
74 74
 		$form=$this->getForm();
75
-		if($value)
76
-			$form->addToPropertyCtrl("class", "attached", array ("attached" ));
75
+		if ($value)
76
+			$form->addToPropertyCtrl("class", "attached", array("attached"));
77 77
 		return $form;
78 78
 	}
79 79
 
80
-	public function addErrorMessage(){
80
+	public function addErrorMessage() {
81 81
 		return $this->getForm()->addContent((new HtmlMessage(""))->setError());
82 82
 	}
83 83
 
@@ -93,48 +93,48 @@  discard block
 block discarded – undo
93 93
 	 * @param array $parameters
94 94
 	 * @return HtmlForm
95 95
 	 */
96
-	public function submitOn($event,$identifierOrElement,$url,$responseElement,$parameters=NULL){
96
+	public function submitOn($event, $identifierOrElement, $url, $responseElement, $parameters=NULL) {
97 97
 		$form=$this->getForm();
98
-		if($identifierOrElement  instanceof BaseHtml)
98
+		if ($identifierOrElement  instanceof BaseHtml)
99 99
 			$elem=$identifierOrElement;
100 100
 		else
101 101
 			$elem=$form->getElementById($identifierOrElement, $form->getContent());
102
-		if(isset($elem)){
103
-			$this->_buttonAsSubmit($elem, $event,$url,$responseElement,$parameters);
102
+		if (isset($elem)) {
103
+			$this->_buttonAsSubmit($elem, $event, $url, $responseElement, $parameters);
104 104
 		}
105 105
 		return $form;
106 106
 	}
107 107
 
108
-	public function submitOnClick($identifier,$url,$responseElement,$parameters=NULL){
109
-		return $this->submitOn("click", $identifier, $url, $responseElement,$parameters);
108
+	public function submitOnClick($identifier, $url, $responseElement, $parameters=NULL) {
109
+		return $this->submitOn("click", $identifier, $url, $responseElement, $parameters);
110 110
 	}
111 111
 
112
-	public function addSubmit($identifier,$value,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$parameters=NULL){
113
-		$bt=$this->getForm()->addButton($identifier, $value,$cssStyle);
114
-		return $this->_buttonAsSubmit($bt, "click",$url,$responseElement,$parameters);
112
+	public function addSubmit($identifier, $value, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $parameters=NULL) {
113
+		$bt=$this->getForm()->addButton($identifier, $value, $cssStyle);
114
+		return $this->_buttonAsSubmit($bt, "click", $url, $responseElement, $parameters);
115 115
 	}
116 116
 
117
-	protected function _buttonAsSubmit(BaseHtml &$button,$event,$url,$responseElement=NULL,$parameters=NULL){
117
+	protected function _buttonAsSubmit(BaseHtml &$button, $event, $url, $responseElement=NULL, $parameters=NULL) {
118 118
 		$form=$this->getForm();
119
-		if(isset($url) && isset($responseElement)){
120
-			$button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');",true,true);
121
-			$this->setSubmitParams($url,$responseElement,$parameters);
119
+		if (isset($url) && isset($responseElement)) {
120
+			$button->addEvent($event, "$('#".$form->getIdentifier()."').form('validate form');", true, true);
121
+			$this->setSubmitParams($url, $responseElement, $parameters);
122 122
 		}
123 123
 		return $button;
124 124
 	}
125 125
 
126
-	public function setSubmitParams($url,$responseElement=NULL,$parameters=NULL){
126
+	public function setSubmitParams($url, $responseElement=NULL, $parameters=NULL) {
127 127
 		$form=$this->getForm();
128
-		$params=["form"=>$form->getIdentifier(),"responseElement"=>$responseElement,"url"=>$url,"stopPropagation"=>true];
129
-		if(\is_array($parameters)){
130
-			$params=\array_merge($params,$parameters);
128
+		$params=["form"=>$form->getIdentifier(), "responseElement"=>$responseElement, "url"=>$url, "stopPropagation"=>true];
129
+		if (\is_array($parameters)) {
130
+			$params=\array_merge($params, $parameters);
131 131
 		}
132 132
 		$form->addValidationParam("_ajaxSubmit", new AjaxCall("postForm", $params));
133 133
 		return $this;
134 134
 	}
135 135
 
136
-	public function addReset($identifier,$value,$cssStyle=NULL){
137
-		$bt=$this->getForm()->addButton($identifier, $value,$cssStyle);
136
+	public function addReset($identifier, $value, $cssStyle=NULL) {
137
+		$bt=$this->getForm()->addButton($identifier, $value, $cssStyle);
138 138
 		$bt->setProperty("type", "reset");
139 139
 		return $bt;
140 140
 	}
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
 	 * @param string $jsCode
145 145
 	 * @return \Ajax\semantic\html\collections\form\HtmlForm
146 146
 	 */
147
-	public function onValid($jsCode){
147
+	public function onValid($jsCode) {
148 148
 		$form=$this->getForm();
149 149
 		$form->addValidationParam("onValid", "%function(){".$jsCode."}%");
150 150
 		return $form;
@@ -155,27 +155,27 @@  discard block
 block discarded – undo
155 155
 	 * @param string $jsCode can use event and fields parameters
156 156
 	 * @return HtmlForm
157 157
 	 */
158
-	public function onSuccess($jsCode){
158
+	public function onSuccess($jsCode) {
159 159
 		$form=$this->getForm();
160
-		$form->addValidationParam("onSuccess", $jsCode,"%function(event,fields){","}%");
160
+		$form->addValidationParam("onSuccess", $jsCode, "%function(event,fields){", "}%");
161 161
 		return $form;
162 162
 	}
163 163
 	
164
-	public function addExtraFieldRules($fieldname,$rules){
164
+	public function addExtraFieldRules($fieldname, $rules) {
165 165
 		$form=$this->getForm();
166 166
 		$fv=$form->getExtraFieldValidation($fieldname);
167
-		foreach ($rules as $rule){
167
+		foreach ($rules as $rule) {
168 168
 			$fv->addRule($rule);
169 169
 		}
170 170
 	}
171 171
 	
172
-	public function addExtraFieldRule($fieldname,$type,$prompt=NULL,$value=NULL){
172
+	public function addExtraFieldRule($fieldname, $type, $prompt=NULL, $value=NULL) {
173 173
 		$form=$this->getForm();
174 174
 		$fv=$form->getExtraFieldValidation($fieldname);
175
-		$fv->addRule($type,$prompt,$value);
175
+		$fv->addRule($type, $prompt, $value);
176 176
 	}
177 177
 	
178
-	public function setOptional($fieldname,$optional=true){
178
+	public function setOptional($fieldname, $optional=true) {
179 179
 		$form=$this->getForm();
180 180
 		$fv=$form->getExtraFieldValidation($fieldname);
181 181
 		$fv->setOptional($optional);
Please login to merge, or discard this patch.
Ajax/common/BaseGui.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 
29 29
 	public function __construct($autoCompile=true) {
30 30
 		$this->autoCompile=$autoCompile;
31
-		$this->components=array ();
32
-		$this->htmlComponents=array ();
31
+		$this->components=array();
32
+		$this->htmlComponents=array();
33 33
 	}
34 34
 
35 35
 	public function isAutoCompile() {
@@ -42,9 +42,9 @@  discard block
 block discarded – undo
42 42
 	}
43 43
 
44 44
 	public function compile($internal=false) {
45
-		if ($internal===false&&$this->autoCompile===true)
45
+		if ($internal===false && $this->autoCompile===true)
46 46
 			throw new \Exception("Impossible to compile if autoCompile is set to 'true'");
47
-		foreach ( $this->components as $component ) {
47
+		foreach ($this->components as $component) {
48 48
 			$component->compile();
49 49
 		}
50 50
 	}
@@ -54,13 +54,13 @@  discard block
 block discarded – undo
54 54
 	}
55 55
 
56 56
 	public function addComponent(SimpleComponent $component, $attachTo, $params) {
57
-		if ($this->autoCompile){
58
-			if($attachTo!=null){
59
-				if(!isset($this->components [$attachTo])){
57
+		if ($this->autoCompile) {
58
+			if ($attachTo!=null) {
59
+				if (!isset($this->components [$attachTo])) {
60 60
 					$this->components [$attachTo]=$component;
61 61
 				}
62 62
 				$component->attach($attachTo);
63
-			}else{
63
+			} else {
64 64
 				$this->components []=$component;
65 65
 			}
66 66
 		}
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 	}
77 77
 
78 78
 	public function compileHtml(JsUtils $js=NULL, &$view=NULL) {
79
-		foreach ( $this->htmlComponents as $htmlComponent ) {
79
+		foreach ($this->htmlComponents as $htmlComponent) {
80 80
 			$htmlComponent->compile($js, $view);
81 81
 		}
82 82
 	}
83 83
 	
84
-	public function matchHtmlComponents($callback){
85
-		return array_filter($this->htmlComponents,$callback);
84
+	public function matchHtmlComponents($callback) {
85
+		return array_filter($this->htmlComponents, $callback);
86 86
 	}
87 87
 }
Please login to merge, or discard this patch.
Braces   +7 added lines, -5 removed lines patch added patch discarded remove patch
@@ -42,8 +42,9 @@  discard block
 block discarded – undo
42 42
 	}
43 43
 
44 44
 	public function compile($internal=false) {
45
-		if ($internal===false&&$this->autoCompile===true)
46
-			throw new \Exception("Impossible to compile if autoCompile is set to 'true'");
45
+		if ($internal===false&&$this->autoCompile===true) {
46
+					throw new \Exception("Impossible to compile if autoCompile is set to 'true'");
47
+		}
47 48
 		foreach ( $this->components as $component ) {
48 49
 			$component->compile();
49 50
 		}
@@ -60,13 +61,14 @@  discard block
 block discarded – undo
60 61
 					$this->components [$attachTo]=$component;
61 62
 				}
62 63
 				$component->attach($attachTo);
63
-			}else{
64
+			} else{
64 65
 				$this->components []=$component;
65 66
 			}
66 67
 		}
67
-		if (isset($params))
68
-			if (\is_array($params))
68
+		if (isset($params)) {
69
+					if (\is_array($params))
69 70
 				$component->setParams($params);
71
+		}
70 72
 		return $component;
71 73
 	}
72 74
 
Please login to merge, or discard this patch.