@@ -16,19 +16,19 @@ discard block |
||
| 16 | 16 | protected $ajaxLoader='<span></span><span></span><span></span><span></span><span></span>'; |
| 17 | 17 | |
| 18 | 18 | abstract public function getUrl($url); |
| 19 | - abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false,$immediatly=true); |
|
| 19 | + abstract public function _add_event($element, $js, $event, $preventDefault=false, $stopPropagation=false, $immediatly=true); |
|
| 20 | 20 | |
| 21 | - protected function _ajax($method,$url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 22 | - if(JString::isNull($params)){$params="{}";} |
|
| 21 | + protected function _ajax($method, $url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 22 | + if (JString::isNull($params)) {$params="{}"; } |
|
| 23 | 23 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 24 | 24 | $retour=$this->_getAjaxUrl($url, $attr); |
| 25 | 25 | $responseElement=$this->_getResponseElement($responseElement); |
| 26 | 26 | $retour.="var self=this;\n"; |
| 27 | - if($hasLoader===true){ |
|
| 27 | + if ($hasLoader===true) { |
|
| 28 | 28 | $this->addLoading($retour, $responseElement); |
| 29 | 29 | } |
| 30 | 30 | $retour.="$.".$method."(url,".$params.").done(function( data ) {\n"; |
| 31 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
| 31 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
| 32 | 32 | if ($immediatly) |
| 33 | 33 | $this->jquery_code_for_compile[]=$retour; |
| 34 | 34 | return $retour; |
@@ -36,33 +36,33 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | |
| 38 | 38 | |
| 39 | - protected function _getAjaxUrl($url,$attr){ |
|
| 39 | + protected function _getAjaxUrl($url, $attr) { |
|
| 40 | 40 | $url=$this->_correctAjaxUrl($url); |
| 41 | 41 | $retour="url='".$url."';"; |
| 42 | 42 | $slash="/"; |
| 43 | - if(JString::endswith($url, "/")===true) |
|
| 43 | + if (JString::endswith($url, "/")===true) |
|
| 44 | 44 | $slash=""; |
| 45 | - if(JString::isNotNull($attr)){ |
|
| 45 | + if (JString::isNotNull($attr)) { |
|
| 46 | 46 | if ($attr==="value") |
| 47 | 47 | $retour.="url=url+'".$slash."'+$(this).val();\n"; |
| 48 | 48 | elseif ($attr==="html") |
| 49 | 49 | $retour.="url=url+'".$slash."'+$(this).html();\n"; |
| 50 | - elseif($attr!==null && $attr!=="") |
|
| 50 | + elseif ($attr!==null && $attr!=="") |
|
| 51 | 51 | $retour.="url=url+'".$slash."'+($(this).attr('".$attr."')||'');\n"; |
| 52 | 52 | } |
| 53 | 53 | return $retour; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - protected function _getOnAjaxDone($responseElement,$jqueryDone,$ajaxTransition,$jsCallback){ |
|
| 57 | - $retour="";$call=null; |
|
| 56 | + protected function _getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback) { |
|
| 57 | + $retour=""; $call=null; |
|
| 58 | 58 | if ($responseElement!=="") { |
| 59 | - if(isset($ajaxTransition)){ |
|
| 59 | + if (isset($ajaxTransition)) { |
|
| 60 | 60 | $call=$this->setAjaxDataCall($ajaxTransition); |
| 61 | - }elseif(isset($this->ajaxTransition)){ |
|
| 61 | + }elseif (isset($this->ajaxTransition)) { |
|
| 62 | 62 | $call=$this->ajaxTransition; |
| 63 | 63 | } |
| 64 | - if(\is_callable($call)) |
|
| 65 | - $retour="\t".$call($responseElement,$jqueryDone).";\n"; |
|
| 64 | + if (\is_callable($call)) |
|
| 65 | + $retour="\t".$call($responseElement, $jqueryDone).";\n"; |
|
| 66 | 66 | else |
| 67 | 67 | $retour="\t$({$responseElement}).{$jqueryDone}( data );\n"; |
| 68 | 68 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | return $retour; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - protected function _getResponseElement($responseElement){ |
|
| 73 | + protected function _getResponseElement($responseElement) { |
|
| 74 | 74 | if ($responseElement!=="") { |
| 75 | 75 | $responseElement=Javascript::prep_value($responseElement); |
| 76 | 76 | } |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | protected function _correctAjaxUrl($url) { |
| 81 | 81 | if ($url!=="/" && JString::endsWith($url, "/")===true) |
| 82 | 82 | $url=substr($url, 0, strlen($url)-1); |
| 83 | - if (strncmp($url, 'http://', 7)!=0&&strncmp($url, 'https://', 8)!=0) { |
|
| 83 | + if (strncmp($url, 'http://', 7)!=0 && strncmp($url, 'https://', 8)!=0) { |
|
| 84 | 84 | $url=$this->getUrl($url); |
| 85 | 85 | } |
| 86 | 86 | return $url; |
@@ -98,11 +98,11 @@ discard block |
||
| 98 | 98 | $retour.="\t\t$({$responseElement}).prepend('{$loading_notifier}');\n"; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - protected function setAjaxDataCall($params){ |
|
| 101 | + protected function setAjaxDataCall($params) { |
|
| 102 | 102 | $result=null; |
| 103 | - if(!\is_callable($params)){ |
|
| 104 | - $result=function ($responseElement,$jqueryDone="html") use($params){ |
|
| 105 | - return AjaxTransition::{$params}($responseElement,$jqueryDone); |
|
| 103 | + if (!\is_callable($params)) { |
|
| 104 | + $result=function($responseElement, $jqueryDone="html") use($params){ |
|
| 105 | + return AjaxTransition::{$params}($responseElement, $jqueryDone); |
|
| 106 | 106 | }; |
| 107 | 107 | } |
| 108 | 108 | return $result; |
@@ -122,8 +122,8 @@ discard block |
||
| 122 | 122 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 123 | 123 | * @param string|callable $ajaxTransition |
| 124 | 124 | */ |
| 125 | - private function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 126 | - return $this->_ajax("get", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
| 125 | + private function _get($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 126 | + return $this->_ajax("get", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 137 | 137 | * @param string|callable $ajaxTransition |
| 138 | 138 | */ |
| 139 | - public function get($url, $responseElement="", $params="{}", $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 140 | - return $this->_get($url,$params,$responseElement,$jsCallback,null,$hasLoader,$jqueryDone,$ajaxTransition,true); |
|
| 139 | + public function get($url, $responseElement="", $params="{}", $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 140 | + return $this->_get($url, $params, $responseElement, $jsCallback, null, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @param string $context |
| 151 | 151 | * @param boolean $immediatly |
| 152 | 152 | */ |
| 153 | - private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document",$immediatly=false) { |
|
| 153 | + private function _json($url, $method="get", $params="{}", $jsCallback=NULL, $attr="id", $context="document", $immediatly=false) { |
|
| 154 | 154 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 155 | 155 | $retour=$this->_getAjaxUrl($url, $attr); |
| 156 | 156 | $retour.="$.{$method}(url,".$params.").done(function( data ) {\n"; |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * @param string $context |
| 174 | 174 | * @param boolean $immediatly |
| 175 | 175 | */ |
| 176 | - public function json($url, $method="get", $params="{}", $jsCallback=NULL,$context="document",$immediatly=false) { |
|
| 177 | - return $this->_json($url,$method,$params,$jsCallback,NULL,$context,$immediatly); |
|
| 176 | + public function json($url, $method="get", $params="{}", $jsCallback=NULL, $context="document", $immediatly=false) { |
|
| 177 | + return $this->_json($url, $method, $params, $jsCallback, NULL, $context, $immediatly); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @param string $url the request address |
| 185 | 185 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","immediatly"=>true) |
| 186 | 186 | */ |
| 187 | - public function jsonOn($event,$element, $url,$parameters=array()) { |
|
| 187 | + public function jsonOn($event, $element, $url, $parameters=array()) { |
|
| 188 | 188 | $preventDefault=true; |
| 189 | 189 | $stopPropagation=true; |
| 190 | 190 | $jsCallback=null; |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $params="{}"; |
| 195 | 195 | $immediatly=true; |
| 196 | 196 | extract($parameters); |
| 197 | - return $this->_add_event($element, $this->_json($url,$method, $params,$jsCallback, $attr,$context), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 197 | + return $this->_add_event($element, $this->_json($url, $method, $params, $jsCallback, $attr, $context), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -205,8 +205,8 @@ discard block |
||
| 205 | 205 | * @param string $jsCallback javascript code to execute after the request |
| 206 | 206 | * @param string $context jquery DOM element, array container. |
| 207 | 207 | */ |
| 208 | - public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL,$context=NULL) { |
|
| 209 | - return $this->json($url, $method, $params, $jsCallback, $context,false); |
|
| 208 | + public function jsonDeferred($url, $method="get", $params="{}", $jsCallback=NULL, $context=NULL) { |
|
| 209 | + return $this->json($url, $method, $params, $jsCallback, $context, false); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | /** |
@@ -219,22 +219,22 @@ discard block |
||
| 219 | 219 | * @param string $rowClass the css class for the new element |
| 220 | 220 | * @param boolean $immediatly |
| 221 | 221 | */ |
| 222 | - private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$attr="id",$immediatly=false) { |
|
| 222 | + private function _jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $attr="id", $immediatly=false) { |
|
| 223 | 223 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 224 | 224 | $retour=$this->_getAjaxUrl($url, $attr); |
| 225 | - if($context===null){ |
|
| 225 | + if ($context===null) { |
|
| 226 | 226 | $parent="$('".$maskSelector."').parent()"; |
| 227 | - $newElm = "$('#'+newId)"; |
|
| 228 | - }else{ |
|
| 227 | + $newElm="$('#'+newId)"; |
|
| 228 | + } else { |
|
| 229 | 229 | $parent=$context; |
| 230 | - $newElm = $context.".find('#'+newId)"; |
|
| 230 | + $newElm=$context.".find('#'+newId)"; |
|
| 231 | 231 | } |
| 232 | 232 | $appendTo="\t\tnewElm.appendTo(".$parent.");\n"; |
| 233 | 233 | $retour.="var self = $(this);\n$.{$method}(url,".$params.").done(function( data ) {\n"; |
| 234 | 234 | $retour.=$parent.".find('._json').remove();"; |
| 235 | 235 | $retour.="\tdata=$.parseJSON(data);$.each(data, function(index, value) {\n"."\tvar created=false;var maskElm=$('".$maskSelector."').first();maskElm.hide();"."\tvar newId=(maskElm.attr('id') || 'mask')+'-'+index;"."\tvar newElm=".$newElm.";\n"."\tif(!newElm.length){\n"."\t\tnewElm=maskElm.clone(); |
| 236 | 236 | newElm.attr('id',newId);\n;newElm.addClass('{$rowClass}').removeClass('_jsonArrayModel');\nnewElm.find('[id]').each(function(){ var newId=$(this).attr('id')+'-'+index;$(this).attr('id',newId).removeClass('_jsonArrayChecked');});\n"; |
| 237 | - $retour.= $appendTo; |
|
| 237 | + $retour.=$appendTo; |
|
| 238 | 238 | $retour.="\t}\n"."\tfor(var key in value){\n"."\t\t\tvar html = $('<div />').append($(newElm).clone()).html();\n"."\t\t\tif(html.indexOf('__'+key+'__')>-1){\n"."\t\t\t\tcontent=$(html.split('__'+key+'__').join(value[key]));\n"."\t\t\t\t$(newElm).replaceWith(content);newElm=content;\n"."\t\t\t}\n"."\t\tvar sel='[data-id=\"'+key+'\"]';if($(sel,newElm).length){\n"."\t\t\tvar selElm=$(sel,newElm);\n"."\t\t\t if(selElm.is('[value]')) { selElm.attr('value',value[key]);selElm.val(value[key]);} else { selElm.html(value[key]); }\n"."\t\t}\n"."}\n"."\t$(newElm).show(true);"."\n"."\t$(newElm).removeClass('hide');"."});\n"; |
| 239 | 239 | $retour.="\t$(document).trigger('jsonReady',[data]);\n"; |
| 240 | 240 | $retour.="\t".$jsCallback."\n"."});\n"; |
@@ -253,8 +253,8 @@ discard block |
||
| 253 | 253 | * @param string $context jquery DOM element, array container. |
| 254 | 254 | * @param boolean $immediatly |
| 255 | 255 | */ |
| 256 | - public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL,$immediatly=false) { |
|
| 257 | - return $this->_jsonArray($maskSelector, $url,$method,$params,$jsCallback,$rowClass,$context,NULL,$immediatly); |
|
| 256 | + public function jsonArray($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL, $immediatly=false) { |
|
| 257 | + return $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, NULL, $immediatly); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | /** |
@@ -267,8 +267,8 @@ discard block |
||
| 267 | 267 | * @param string $rowClass the css class for the new element |
| 268 | 268 | * @param string $context jquery DOM element, array container. |
| 269 | 269 | */ |
| 270 | - public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL,$rowClass="_json",$context=NULL) { |
|
| 271 | - return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback,$rowClass,$context,false); |
|
| 270 | + public function jsonArrayDeferred($maskSelector, $url, $method="get", $params="{}", $jsCallback=NULL, $rowClass="_json", $context=NULL) { |
|
| 271 | + return $this->jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, false); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -278,18 +278,18 @@ discard block |
||
| 278 | 278 | * @param string $url the request url |
| 279 | 279 | * @param array $parameters default : array("preventDefault"=>true,"stopPropagation"=>true,"jsCallback"=>NULL,"attr"=>"id","params"=>"{}","method"=>"get","rowClass"=>"_json","immediatly"=>true) |
| 280 | 280 | */ |
| 281 | - public function jsonArrayOn($event,$element,$maskSelector, $url,$parameters=array()) { |
|
| 281 | + public function jsonArrayOn($event, $element, $maskSelector, $url, $parameters=array()) { |
|
| 282 | 282 | $preventDefault=true; |
| 283 | 283 | $stopPropagation=true; |
| 284 | 284 | $jsCallback=null; |
| 285 | 285 | $attr="id"; |
| 286 | 286 | $method="get"; |
| 287 | - $context = null; |
|
| 287 | + $context=null; |
|
| 288 | 288 | $params="{}"; |
| 289 | 289 | $immediatly=true; |
| 290 | 290 | $rowClass="_json"; |
| 291 | 291 | extract($parameters); |
| 292 | - return $this->_add_event($element, $this->_jsonArray($maskSelector,$url,$method, $params,$jsCallback, $rowClass, $context,$attr), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 292 | + return $this->_add_event($element, $this->_jsonArray($maskSelector, $url, $method, $params, $jsCallback, $rowClass, $context, $attr), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | /** |
@@ -303,8 +303,8 @@ discard block |
||
| 303 | 303 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 304 | 304 | * @param string|callable $ajaxTransition |
| 305 | 305 | */ |
| 306 | - public function getDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL,$attr="id",$jqueryDone="html",$ajaxTransition=null) { |
|
| 307 | - return $this->_get($url, $params,$responseElement,$jsCallback,$attr,false,$jqueryDone,$ajaxTransition); |
|
| 306 | + public function getDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id", $jqueryDone="html", $ajaxTransition=null) { |
|
| 307 | + return $this->_get($url, $params, $responseElement, $jsCallback, $attr, false, $jqueryDone, $ajaxTransition); |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /** |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | $ajaxTransition=null; |
| 328 | 328 | $params="{}"; |
| 329 | 329 | extract($parameters); |
| 330 | - return $this->_add_event($element, $this->_get($url, $params,$responseElement,$jsCallback,$attr, $hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 330 | + return $this->_add_event($element, $this->_get($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | $ajaxTransition=null; |
| 352 | 352 | $params="{}"; |
| 353 | 353 | extract($parameters); |
| 354 | - return $this->_add_event($element, $this->_ajax($method,$url, $params,$responseElement,$jsCallback,$attr, $hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 354 | + return $this->_add_event($element, $this->_ajax($method, $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | return $this->getOn("click", $element, $url, $responseElement, $parameters); |
| 379 | 379 | } |
| 380 | 380 | |
| 381 | - private function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 382 | - return $this->_ajax("post", $url,$params,$responseElement,$jsCallback,$attr,$hasLoader,$jqueryDone,$ajaxTransition,$immediatly); |
|
| 381 | + private function _post($url, $params="{}", $responseElement="", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 382 | + return $this->_ajax("post", $url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, $immediatly); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -392,8 +392,8 @@ discard block |
||
| 392 | 392 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 393 | 393 | * @param string|callable $ajaxTransition |
| 394 | 394 | */ |
| 395 | - public function post($url, $responseElement="", $params="{}", $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 396 | - return $this->_post($url, $params, $responseElement, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
| 395 | + public function post($url, $responseElement="", $params="{}", $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 396 | + return $this->_post($url, $params, $responseElement, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 409 | 409 | * @param string|callable $ajaxTransition |
| 410 | 410 | */ |
| 411 | - public function postDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 412 | - return $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false); |
|
| 411 | + public function postDeferred($url, $responseElement="", $params="{}", $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 412 | + return $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, false); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -432,7 +432,7 @@ discard block |
||
| 432 | 432 | $jqueryDone="html"; |
| 433 | 433 | $ajaxTransition=null; |
| 434 | 434 | extract($parameters); |
| 435 | - return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 435 | + return $this->_add_event($element, $this->_post($url, $params, $responseElement, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -448,20 +448,20 @@ discard block |
||
| 448 | 448 | return $this->postOn("click", $element, $url, $params, $responseElement, $parameters); |
| 449 | 449 | } |
| 450 | 450 | |
| 451 | - private function _postForm($url, $form, $responseElement, $params=null,$validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true,$jqueryDone="html",$ajaxTransition=null,$immediatly=false) { |
|
| 451 | + private function _postForm($url, $form, $responseElement, $params=null, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null, $immediatly=false) { |
|
| 452 | 452 | $jsCallback=isset($jsCallback) ? $jsCallback : ""; |
| 453 | 453 | $retour=$this->_getAjaxUrl($url, $attr); |
| 454 | 454 | $retour.="\nvar params=$('#".$form."').serialize();\n"; |
| 455 | - if(isset($params)){ |
|
| 455 | + if (isset($params)) { |
|
| 456 | 456 | $retour.="params+='&'+$.param(".$params.");\n"; |
| 457 | 457 | } |
| 458 | 458 | $responseElement=$this->_getResponseElement($responseElement); |
| 459 | 459 | $retour.="var self=this;\n"; |
| 460 | - if($hasLoader===true){ |
|
| 460 | + if ($hasLoader===true) { |
|
| 461 | 461 | $this->addLoading($retour, $responseElement); |
| 462 | 462 | } |
| 463 | 463 | $retour.="$.post(url,params).done(function( data ) {\n"; |
| 464 | - $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone,$ajaxTransition,$jsCallback)."});\n"; |
|
| 464 | + $retour.=$this->_getOnAjaxDone($responseElement, $jqueryDone, $ajaxTransition, $jsCallback)."});\n"; |
|
| 465 | 465 | |
| 466 | 466 | if ($validation) { |
| 467 | 467 | $retour="$('#".$form."').validate({submitHandler: function(form) { |
@@ -485,8 +485,8 @@ discard block |
||
| 485 | 485 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 486 | 486 | * @param string|callable $ajaxTransition |
| 487 | 487 | */ |
| 488 | - public function postForm($url, $form, $responseElement, $params=NULL,$validation=false, $jsCallback=NULL,$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 489 | - return $this->_postForm($url, $form, $responseElement, $params,$validation, $jsCallback, NULL, $hasLoader,$jqueryDone,$ajaxTransition,true); |
|
| 488 | + public function postForm($url, $form, $responseElement, $params=NULL, $validation=false, $jsCallback=NULL, $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 489 | + return $this->_postForm($url, $form, $responseElement, $params, $validation, $jsCallback, NULL, $hasLoader, $jqueryDone, $ajaxTransition, true); |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -503,8 +503,8 @@ discard block |
||
| 503 | 503 | * @param string $jqueryDone the jquery function call on ajax data. default:html |
| 504 | 504 | * @param string|callable $ajaxTransition |
| 505 | 505 | */ |
| 506 | - public function postFormDeferred($url, $form, $responseElement, $params=NULL,$validation=false, $jsCallback=NULL,$attr="id",$hasLoader=true,$jqueryDone="html",$ajaxTransition=null) { |
|
| 507 | - return $this->_postForm($url, $form, $responseElement, $params,$validation, $jsCallback, $attr, $hasLoader,$jqueryDone,$ajaxTransition,false); |
|
| 506 | + public function postFormDeferred($url, $form, $responseElement, $params=NULL, $validation=false, $jsCallback=NULL, $attr="id", $hasLoader=true, $jqueryDone="html", $ajaxTransition=null) { |
|
| 507 | + return $this->_postForm($url, $form, $responseElement, $params, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition, false); |
|
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | /** |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | $jqueryDone="html"; |
| 530 | 530 | $ajaxTransition=null; |
| 531 | 531 | extract($parameters); |
| 532 | - return $this->_add_event($element, $this->_postForm($url, $form, $responseElement,$params, $validation, $jsCallback, $attr,$hasLoader,$jqueryDone,$ajaxTransition), $event, $preventDefault, $stopPropagation,$immediatly); |
|
| 532 | + return $this->_add_event($element, $this->_postForm($url, $form, $responseElement, $params, $validation, $jsCallback, $attr, $hasLoader, $jqueryDone, $ajaxTransition), $event, $preventDefault, $stopPropagation, $immediatly); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | trait LabeledIconTrait { |
| 14 | 14 | |
| 15 | 15 | abstract public function addToProperty($name, $value, $separator=" "); |
| 16 | - abstract public function addContent($content,$before=false); |
|
| 16 | + abstract public function addContent($content, $before=false); |
|
| 17 | 17 | |
| 18 | 18 | /** |
| 19 | 19 | * Adds an icon before or after |
@@ -22,17 +22,17 @@ discard block |
||
| 22 | 22 | * @param boolean $labeled |
| 23 | 23 | * @return \Ajax\semantic\html\elements\HtmlIcon |
| 24 | 24 | */ |
| 25 | - public function addIcon($icon,$before=true,$labeled=false){ |
|
| 25 | + public function addIcon($icon, $before=true, $labeled=false) { |
|
| 26 | 26 | $iconO=$icon; |
| 27 | - if(\is_string($icon)){ |
|
| 27 | + if (\is_string($icon)) { |
|
| 28 | 28 | $iconO=new HtmlIcon("icon-".$this->identifier, $icon); |
| 29 | 29 | } |
| 30 | - if($labeled!==false){ |
|
| 31 | - $direction=($before===true)?Direction::LEFT:Direction::RIGHT; |
|
| 30 | + if ($labeled!==false) { |
|
| 31 | + $direction=($before===true) ?Direction::LEFT : Direction::RIGHT; |
|
| 32 | 32 | $this->addToProperty("class", $direction." labeled icon"); |
| 33 | 33 | $this->tagName="div"; |
| 34 | 34 | } |
| 35 | - $this->addContent($iconO,$before); |
|
| 35 | + $this->addContent($iconO, $before); |
|
| 36 | 36 | return $iconO; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | private $pages_visibles; |
| 10 | 10 | private $row_count; |
| 11 | 11 | |
| 12 | - public function __construct($items_per_page=10,$pages_visibles=null,$page=1,$row_count=null){ |
|
| 12 | + public function __construct($items_per_page=10, $pages_visibles=null, $page=1, $row_count=null) { |
|
| 13 | 13 | $this->items_per_page=$items_per_page; |
| 14 | 14 | $this->row_count=$row_count; |
| 15 | 15 | $this->page=$page; |
@@ -17,30 +17,30 @@ discard block |
||
| 17 | 17 | $this->visible=true; |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function getObjects($objects){ |
|
| 20 | + public function getObjects($objects) { |
|
| 21 | 21 | $auto=(!isset($this->row_count)); |
| 22 | 22 | $os=$objects; |
| 23 | - if(!\is_array($os)){ |
|
| 23 | + if (!\is_array($os)) { |
|
| 24 | 24 | $os=[]; |
| 25 | - foreach ($objects as $o){ |
|
| 25 | + foreach ($objects as $o) { |
|
| 26 | 26 | $os[]=$o; |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | - $this->page_count = 0; |
|
| 30 | - $row_count=($auto)?\sizeof($os):$this->row_count; |
|
| 31 | - if (0 === $row_count) { |
|
| 29 | + $this->page_count=0; |
|
| 30 | + $row_count=($auto) ?\sizeof($os) : $this->row_count; |
|
| 31 | + if (0===$row_count) { |
|
| 32 | 32 | $this->visible=false; |
| 33 | 33 | } else { |
| 34 | 34 | |
| 35 | - $this->page_count = (int)ceil($row_count / $this->items_per_page); |
|
| 35 | + $this->page_count=(int)ceil($row_count/$this->items_per_page); |
|
| 36 | 36 | $this->visible=$this->page_count>1; |
| 37 | - if($this->page > $this->page_count+1) { |
|
| 38 | - $this->page = 1; |
|
| 37 | + if ($this->page>$this->page_count+1) { |
|
| 38 | + $this->page=1; |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | - if($auto){ |
|
| 42 | - $offset = ($this->page - 1) * $this->items_per_page; |
|
| 43 | - return array_slice($os, $offset,$this->items_per_page); |
|
| 41 | + if ($auto) { |
|
| 42 | + $offset=($this->page-1)*$this->items_per_page; |
|
| 43 | + return array_slice($os, $offset, $this->items_per_page); |
|
| 44 | 44 | } |
| 45 | 45 | return $os; |
| 46 | 46 | } |
@@ -76,22 +76,22 @@ discard block |
||
| 76 | 76 | return $this->page_count; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - public function getPagesNumbers(){ |
|
| 80 | - $middle= (int)ceil(($this->pages_visibles-1)/ 2); |
|
| 79 | + public function getPagesNumbers() { |
|
| 80 | + $middle=(int)ceil(($this->pages_visibles-1)/2); |
|
| 81 | 81 | $first=$this->page-$middle; |
| 82 | - if($first<1){ |
|
| 82 | + if ($first<1) { |
|
| 83 | 83 | $first=1; |
| 84 | 84 | } |
| 85 | 85 | $last=$first+$this->pages_visibles-1; |
| 86 | - if($last>$this->page_count){ |
|
| 86 | + if ($last>$this->page_count) { |
|
| 87 | 87 | $last=$this->page_count; |
| 88 | 88 | } |
| 89 | 89 | return \range($first, $last); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | public function setPagesVisibles($pages_visibles) { |
| 93 | - if(!isset($pages_visibles)) |
|
| 94 | - $pages_visibles=(int)ceil($this->row_count / $this->items_per_page)+1; |
|
| 93 | + if (!isset($pages_visibles)) |
|
| 94 | + $pages_visibles=(int)ceil($this->row_count/$this->items_per_page)+1; |
|
| 95 | 95 | $this->pages_visibles=$pages_visibles; |
| 96 | 96 | return $this; |
| 97 | 97 | } |
@@ -13,19 +13,19 @@ discard block |
||
| 13 | 13 | * @property boolean $_visibleHover |
| 14 | 14 | * @property InstanceViewer $_instanceViewer |
| 15 | 15 | */ |
| 16 | -trait DataTableFieldAsTrait{ |
|
| 16 | +trait DataTableFieldAsTrait { |
|
| 17 | 17 | abstract public function addField($field); |
| 18 | - abstract public function insertField($index,$field); |
|
| 19 | - abstract public function insertInField($index,$field); |
|
| 20 | - abstract public function fieldAs($index,$type,$attributes=NULL); |
|
| 18 | + abstract public function insertField($index, $field); |
|
| 19 | + abstract public function insertInField($index, $field); |
|
| 20 | + abstract public function fieldAs($index, $type, $attributes=NULL); |
|
| 21 | 21 | /** |
| 22 | 22 | * @param string $caption |
| 23 | 23 | * @param callable $callback |
| 24 | 24 | * @param boolean $visibleHover |
| 25 | 25 | * @return callable |
| 26 | 26 | */ |
| 27 | - private function getFieldButtonCallable($caption,$visibleHover=true,$callback=null){ |
|
| 28 | - return $this->getCallable("getFieldButton",[$caption,$visibleHover],$callback); |
|
| 27 | + private function getFieldButtonCallable($caption, $visibleHover=true, $callback=null) { |
|
| 28 | + return $this->getCallable("getFieldButton", [$caption, $visibleHover], $callback); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -34,19 +34,19 @@ discard block |
||
| 34 | 34 | * @param callable $callback |
| 35 | 35 | * @return callable |
| 36 | 36 | */ |
| 37 | - private function getCallable($thisCallback,$parameters,$callback=null){ |
|
| 38 | - $result=function($instance) use($thisCallback,$parameters,$callback){ |
|
| 39 | - $object=call_user_func_array(array($this,$thisCallback), $parameters); |
|
| 40 | - if(isset($callback)){ |
|
| 41 | - if(\is_callable($callback)){ |
|
| 42 | - $callback($object,$instance); |
|
| 37 | + private function getCallable($thisCallback, $parameters, $callback=null) { |
|
| 38 | + $result=function($instance) use($thisCallback, $parameters, $callback){ |
|
| 39 | + $object=call_user_func_array(array($this, $thisCallback), $parameters); |
|
| 40 | + if (isset($callback)) { |
|
| 41 | + if (\is_callable($callback)) { |
|
| 42 | + $callback($object, $instance); |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | - if($object instanceof HtmlSemDoubleElement){ |
|
| 46 | - $object->setProperty("data-ajax",$this->_instanceViewer->getIdentifier()); |
|
| 47 | - if($object->propertyContains("class","visibleover")){ |
|
| 45 | + if ($object instanceof HtmlSemDoubleElement) { |
|
| 46 | + $object->setProperty("data-ajax", $this->_instanceViewer->getIdentifier()); |
|
| 47 | + if ($object->propertyContains("class", "visibleover")) { |
|
| 48 | 48 | $this->_visibleHover=true; |
| 49 | - $object->setProperty("style","visibility:hidden;"); |
|
| 49 | + $object->setProperty("style", "visibility:hidden;"); |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | return $object; |
@@ -58,9 +58,9 @@ discard block |
||
| 58 | 58 | * @param string $caption |
| 59 | 59 | * @return HtmlButton |
| 60 | 60 | */ |
| 61 | - private function getFieldButton($caption,$visibleHover=true){ |
|
| 62 | - $bt= new HtmlButton("",$caption); |
|
| 63 | - if($visibleHover) |
|
| 61 | + private function getFieldButton($caption, $visibleHover=true) { |
|
| 62 | + $bt=new HtmlButton("", $caption); |
|
| 63 | + if ($visibleHover) |
|
| 64 | 64 | $this->_visibleOver($bt); |
| 65 | 65 | return $bt; |
| 66 | 66 | } |
@@ -74,19 +74,19 @@ discard block |
||
| 74 | 74 | * @param array $attributes associative array (<b>ajax</b> key is for ajax post) |
| 75 | 75 | * @return DataTable |
| 76 | 76 | */ |
| 77 | - public function fieldAsSubmit($index,$cssStyle=NULL,$url=NULL,$responseElement=NULL,$attributes=NULL){ |
|
| 78 | - return $this->_fieldAs(function($id,$name,$value,$caption) use ($url,$responseElement,$cssStyle,$index,$attributes){ |
|
| 79 | - $button=new HtmlButton($id,$value,$cssStyle); |
|
| 80 | - $button->postOnClick($url,"$(event.target).closest('tr').find(':input').serialize()",$responseElement,$attributes["ajax"]); |
|
| 81 | - if(!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
| 77 | + public function fieldAsSubmit($index, $cssStyle=NULL, $url=NULL, $responseElement=NULL, $attributes=NULL) { |
|
| 78 | + return $this->_fieldAs(function($id, $name, $value, $caption) use ($url, $responseElement, $cssStyle, $index, $attributes){ |
|
| 79 | + $button=new HtmlButton($id, $value, $cssStyle); |
|
| 80 | + $button->postOnClick($url, "$(event.target).closest('tr').find(':input').serialize()", $responseElement, $attributes["ajax"]); |
|
| 81 | + if (!isset($attributes["visibleHover"]) || $attributes["visibleHover"]) |
|
| 82 | 82 | $this->_visibleOver($button); |
| 83 | 83 | return $button; |
| 84 | - }, $index,$attributes); |
|
| 84 | + }, $index, $attributes); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - protected function _visibleOver(BaseHtml $element){ |
|
| 87 | + protected function _visibleOver(BaseHtml $element) { |
|
| 88 | 88 | $this->_visibleHover=true; |
| 89 | - return $element->addToProperty("class", "visibleover")->setProperty("style","visibility:hidden;"); |
|
| 89 | + return $element->addToProperty("class", "visibleover")->setProperty("style", "visibility:hidden;"); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -96,8 +96,8 @@ discard block |
||
| 96 | 96 | * @param boolean $visibleHover |
| 97 | 97 | * @return DataTable |
| 98 | 98 | */ |
| 99 | - public function addFieldButton($caption,$visibleHover=true,$callback=null){ |
|
| 100 | - $this->addField($this->getCallable("getFieldButton",[$caption,$visibleHover],$callback)); |
|
| 99 | + public function addFieldButton($caption, $visibleHover=true, $callback=null) { |
|
| 100 | + $this->addField($this->getCallable("getFieldButton", [$caption, $visibleHover], $callback)); |
|
| 101 | 101 | return $this; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | * @param callable $callback |
| 109 | 109 | * @return DataTable |
| 110 | 110 | */ |
| 111 | - public function insertFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
| 112 | - $this->insertField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
| 111 | + public function insertFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
| 112 | + $this->insertField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
| 113 | 113 | return $this; |
| 114 | 114 | } |
| 115 | 115 | |
@@ -120,25 +120,25 @@ discard block |
||
| 120 | 120 | * @param callable $callback |
| 121 | 121 | * @return DataTable |
| 122 | 122 | */ |
| 123 | - public function insertInFieldButton($index,$caption,$visibleHover=true,$callback=null){ |
|
| 124 | - $this->insertInField($index, $this->getFieldButtonCallable($caption,$visibleHover,$callback)); |
|
| 123 | + public function insertInFieldButton($index, $caption, $visibleHover=true, $callback=null) { |
|
| 124 | + $this->insertInField($index, $this->getFieldButtonCallable($caption, $visibleHover, $callback)); |
|
| 125 | 125 | return $this; |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - private function addDefaultButton($icon,$class=null,$visibleHover=true,$callback=null){ |
|
| 129 | - $this->addField($this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
| 128 | + private function addDefaultButton($icon, $class=null, $visibleHover=true, $callback=null) { |
|
| 129 | + $this->addField($this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
| 130 | 130 | return $this; |
| 131 | 131 | } |
| 132 | 132 | |
| 133 | - private function insertDefaultButtonIn($index,$icon,$class=null,$visibleHover=true,$callback=null){ |
|
| 134 | - $this->insertInField($index,$this->getCallable("getDefaultButton",[$icon,$class,$visibleHover],$callback)); |
|
| 133 | + private function insertDefaultButtonIn($index, $icon, $class=null, $visibleHover=true, $callback=null) { |
|
| 134 | + $this->insertInField($index, $this->getCallable("getDefaultButton", [$icon, $class, $visibleHover], $callback)); |
|
| 135 | 135 | return $this; |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - private function getDefaultButton($icon,$class=null,$visibleHover=true){ |
|
| 139 | - $bt=$this->getFieldButton("",$visibleHover); |
|
| 138 | + private function getDefaultButton($icon, $class=null, $visibleHover=true) { |
|
| 139 | + $bt=$this->getFieldButton("", $visibleHover); |
|
| 140 | 140 | $bt->asIcon($icon); |
| 141 | - if(isset($class)) |
|
| 141 | + if (isset($class)) |
|
| 142 | 142 | $bt->addClass($class); |
| 143 | 143 | return $bt; |
| 144 | 144 | } |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | * @param callable $callback this function takes the following arguments : $object=>the delete button, $instance : the active instance of the object |
| 151 | 151 | * @return DataTable |
| 152 | 152 | */ |
| 153 | - public function addDeleteButton($visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
| 153 | + public function addDeleteButton($visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
| 154 | 154 | $this->_deleteBehavior=$deleteBehavior; |
| 155 | - return $this->addDefaultButton("remove","_delete red basic",$visibleHover,$callback); |
|
| 155 | + return $this->addDefaultButton("remove", "_delete red basic", $visibleHover, $callback); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -162,9 +162,9 @@ discard block |
||
| 162 | 162 | * @param callable $callback this function takes the following arguments : $object=>the delete button, $instance : the active instance of the object |
| 163 | 163 | * @return DataTable |
| 164 | 164 | */ |
| 165 | - public function addEditButton($visibleHover=true,$editBehavior=[],$callback=null){ |
|
| 165 | + public function addEditButton($visibleHover=true, $editBehavior=[], $callback=null) { |
|
| 166 | 166 | $this->_editBehavior=$editBehavior; |
| 167 | - return $this->addDefaultButton("edit","_edit basic",$visibleHover,$callback); |
|
| 167 | + return $this->addDefaultButton("edit", "_edit basic", $visibleHover, $callback); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -175,20 +175,20 @@ discard block |
||
| 175 | 175 | * @param callable $callbackDelete this function takes the following arguments : $object=>the delete button, $instance : the active instance of the object |
| 176 | 176 | * @return DataTable |
| 177 | 177 | */ |
| 178 | - public function addEditDeleteButtons($visibleHover=true,$behavior=[],$callbackEdit=null,$callbackDelete=null){ |
|
| 179 | - $this->addEditButton($visibleHover,$behavior,$callbackEdit); |
|
| 178 | + public function addEditDeleteButtons($visibleHover=true, $behavior=[], $callbackEdit=null, $callbackDelete=null) { |
|
| 179 | + $this->addEditButton($visibleHover, $behavior, $callbackEdit); |
|
| 180 | 180 | $index=$this->_instanceViewer->visiblePropertiesCount()-1; |
| 181 | - $this->insertDeleteButtonIn($index,$visibleHover,$behavior,$callbackDelete); |
|
| 181 | + $this->insertDeleteButtonIn($index, $visibleHover, $behavior, $callbackDelete); |
|
| 182 | 182 | return $this; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - public function insertDeleteButtonIn($index,$visibleHover=true,$deleteBehavior=[],$callback=null){ |
|
| 185 | + public function insertDeleteButtonIn($index, $visibleHover=true, $deleteBehavior=[], $callback=null) { |
|
| 186 | 186 | $this->_deleteBehavior=$deleteBehavior; |
| 187 | - return $this->insertDefaultButtonIn($index,"remove","_delete red basic",$visibleHover,$callback); |
|
| 187 | + return $this->insertDefaultButtonIn($index, "remove", "_delete red basic", $visibleHover, $callback); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - public function insertEditButtonIn($index,$visibleHover=true,$editBehavior=[],$callback=null){ |
|
| 190 | + public function insertEditButtonIn($index, $visibleHover=true, $editBehavior=[], $callback=null) { |
|
| 191 | 191 | $this->_editBehavior=$editBehavior; |
| 192 | - return $this->insertDefaultButtonIn($index,"edit","_edit basic",$visibleHover,$callback); |
|
| 192 | + return $this->insertDefaultButtonIn($index, "edit", "_edit basic", $visibleHover, $callback); |
|
| 193 | 193 | } |
| 194 | 194 | } |
@@ -24,7 +24,7 @@ discard block |
||
| 24 | 24 | * |
| 25 | 25 | */ |
| 26 | 26 | class DataTable extends Widget { |
| 27 | - use TableTrait,DataTableFieldAsTrait,HasCheckboxesTrait,BaseTrait; |
|
| 27 | + use TableTrait, DataTableFieldAsTrait, HasCheckboxesTrait, BaseTrait; |
|
| 28 | 28 | protected $_searchField; |
| 29 | 29 | protected $_urls; |
| 30 | 30 | protected $_pagination; |
@@ -42,35 +42,35 @@ discard block |
||
| 42 | 42 | protected $_colWidths; |
| 43 | 43 | |
| 44 | 44 | |
| 45 | - public function __construct($identifier,$model,$modelInstance=NULL) { |
|
| 46 | - parent::__construct($identifier, $model,$modelInstance); |
|
| 47 | - $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0,0), false); |
|
| 45 | + public function __construct($identifier, $model, $modelInstance=NULL) { |
|
| 46 | + parent::__construct($identifier, $model, $modelInstance); |
|
| 47 | + $this->_init(new InstanceViewer($identifier), "table", new HtmlTable($identifier, 0, 0), false); |
|
| 48 | 48 | $this->_urls=[]; |
| 49 | - $this->_emptyMessage=new HtmlMessage("","nothing to display"); |
|
| 49 | + $this->_emptyMessage=new HtmlMessage("", "nothing to display"); |
|
| 50 | 50 | $this->_emptyMessage->setIcon("info circle"); |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function run(JsUtils $js){ |
|
| 54 | - if($this->_hasCheckboxes && isset($js)){ |
|
| 53 | + public function run(JsUtils $js) { |
|
| 54 | + if ($this->_hasCheckboxes && isset($js)) { |
|
| 55 | 55 | $this->_runCheckboxes($js); |
| 56 | 56 | } |
| 57 | - if($this->_visibleHover){ |
|
| 58 | - $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 59 | - $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');",["preventDefault"=>false,"stopPropagation"=>true]); |
|
| 57 | + if ($this->_visibleHover) { |
|
| 58 | + $js->execOn("mouseover", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'visible');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 59 | + $js->execOn("mouseout", "#".$this->identifier." tr", "$(event.target).closest('tr').find('.visibleover').css('visibility', 'hidden');", ["preventDefault"=>false, "stopPropagation"=>true]); |
|
| 60 | 60 | } |
| 61 | - if(\is_array($this->_deleteBehavior)) |
|
| 62 | - $this->_generateBehavior("delete",$this->_deleteBehavior, $js); |
|
| 63 | - if(\is_array($this->_editBehavior)) |
|
| 64 | - $this->_generateBehavior("edit",$this->_editBehavior,$js); |
|
| 61 | + if (\is_array($this->_deleteBehavior)) |
|
| 62 | + $this->_generateBehavior("delete", $this->_deleteBehavior, $js); |
|
| 63 | + if (\is_array($this->_editBehavior)) |
|
| 64 | + $this->_generateBehavior("edit", $this->_editBehavior, $js); |
|
| 65 | 65 | return parent::run($js); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
| 69 | 69 | |
| 70 | - protected function _generateBehavior($op,$params,JsUtils $js){ |
|
| 71 | - if(isset($this->_urls[$op])){ |
|
| 72 | - $params=\array_merge($params,["attr"=>"data-ajax"]); |
|
| 73 | - $js->ajaxOnClick("#".$this->identifier." ._".$op, $this->_urls[$op],$this->getTargetSelector($op),$params); |
|
| 70 | + protected function _generateBehavior($op, $params, JsUtils $js) { |
|
| 71 | + if (isset($this->_urls[$op])) { |
|
| 72 | + $params=\array_merge($params, ["attr"=>"data-ajax"]); |
|
| 73 | + $js->ajaxOnClick("#".$this->identifier." ._".$op, $this->_urls[$op], $this->getTargetSelector($op), $params); |
|
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
@@ -83,156 +83,156 @@ discard block |
||
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | |
| 86 | - public function compile(JsUtils $js=NULL,&$view=NULL){ |
|
| 87 | - if(!$this->_generated){ |
|
| 86 | + public function compile(JsUtils $js=NULL, &$view=NULL) { |
|
| 87 | + if (!$this->_generated) { |
|
| 88 | 88 | $this->_instanceViewer->setInstance($this->_model); |
| 89 | 89 | $captions=$this->_instanceViewer->getCaptions(); |
| 90 | 90 | $table=$this->content["table"]; |
| 91 | - if($this->_hasCheckboxes){ |
|
| 91 | + if ($this->_hasCheckboxes) { |
|
| 92 | 92 | $this->_generateMainCheckbox($captions); |
| 93 | 93 | } |
| 94 | 94 | $table->setRowCount(0, \sizeof($captions)); |
| 95 | - $this->_generateHeader($table,$captions); |
|
| 95 | + $this->_generateHeader($table, $captions); |
|
| 96 | 96 | |
| 97 | - if(isset($this->_compileParts)) |
|
| 97 | + if (isset($this->_compileParts)) |
|
| 98 | 98 | $table->setCompileParts($this->_compileParts); |
| 99 | 99 | |
| 100 | 100 | $this->_generateContent($table); |
| 101 | 101 | |
| 102 | - $this->compileExtraElements($table, $captions,$js); |
|
| 102 | + $this->compileExtraElements($table, $captions, $js); |
|
| 103 | 103 | |
| 104 | - $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE,"table",PositionInTable::AFTERTABLE]); |
|
| 104 | + $this->content=JArray::sortAssociative($this->content, [PositionInTable::BEFORETABLE, "table", PositionInTable::AFTERTABLE]); |
|
| 105 | 105 | $this->_compileForm(); |
| 106 | 106 | $this->_applyStyleAttributes($table); |
| 107 | 107 | $this->_generated=true; |
| 108 | 108 | } |
| 109 | - return parent::compile($js,$view); |
|
| 109 | + return parent::compile($js, $view); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - protected function compileExtraElements($table,$captions,JsUtils $js=NULL){ |
|
| 113 | - if(isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])){ |
|
| 114 | - $this->_searchField->postOn("change", $this->_urls["refresh"],"{'s':$(this).val()}","#".$this->identifier." tbody",["preventDefault"=>false,"jqueryDone"=>"replaceWith"]); |
|
| 112 | + protected function compileExtraElements($table, $captions, JsUtils $js=NULL) { |
|
| 113 | + if (isset($this->_searchField) && isset($js) && isset($this->_urls["refresh"])) { |
|
| 114 | + $this->_searchField->postOn("change", $this->_urls["refresh"], "{'s':$(this).val()}", "#".$this->identifier." tbody", ["preventDefault"=>false, "jqueryDone"=>"replaceWith"]); |
|
| 115 | 115 | } |
| 116 | - if($this->_hasCheckboxes && $table->hasPart("thead")){ |
|
| 116 | + if ($this->_hasCheckboxes && $table->hasPart("thead")) { |
|
| 117 | 117 | $table->getHeader()->getCell(0, 0)->addClass("no-sort"); |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - if(isset($this->_toolbar)){ |
|
| 120 | + if (isset($this->_toolbar)) { |
|
| 121 | 121 | $this->_setToolbarPosition($table, $captions); |
| 122 | 122 | } |
| 123 | - if(isset($this->_pagination) && $this->_pagination->getVisible()){ |
|
| 124 | - $this->_generatePagination($table,$js); |
|
| 123 | + if (isset($this->_pagination) && $this->_pagination->getVisible()) { |
|
| 124 | + $this->_generatePagination($table, $js); |
|
| 125 | 125 | } |
| 126 | 126 | } |
| 127 | 127 | |
| 128 | - protected function _applyStyleAttributes($table){ |
|
| 129 | - if(isset($this->_hiddenColumns)) |
|
| 128 | + protected function _applyStyleAttributes($table) { |
|
| 129 | + if (isset($this->_hiddenColumns)) |
|
| 130 | 130 | $this->_hideColumns(); |
| 131 | - if(isset($this->_colWidths)){ |
|
| 132 | - foreach ($this->_colWidths as $colIndex=>$width){ |
|
| 133 | - $table->setColWidth($colIndex,$width); |
|
| 131 | + if (isset($this->_colWidths)) { |
|
| 132 | + foreach ($this->_colWidths as $colIndex=>$width) { |
|
| 133 | + $table->setColWidth($colIndex, $width); |
|
| 134 | 134 | } |
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
| 138 | - protected function _hideColumns(){ |
|
| 139 | - foreach ($this->_hiddenColumns as $colIndex){ |
|
| 138 | + protected function _hideColumns() { |
|
| 139 | + foreach ($this->_hiddenColumns as $colIndex) { |
|
| 140 | 140 | $this->_self->hideColumn($colIndex); |
| 141 | 141 | } |
| 142 | 142 | return $this; |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - protected function _generateHeader(HtmlTable $table,$captions){ |
|
| 145 | + protected function _generateHeader(HtmlTable $table, $captions) { |
|
| 146 | 146 | $table->setHeaderValues($captions); |
| 147 | - if(isset($this->_sortable)){ |
|
| 147 | + if (isset($this->_sortable)) { |
|
| 148 | 148 | $table->setSortable($this->_sortable); |
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | |
| 153 | 153 | |
| 154 | - protected function _generateContent($table){ |
|
| 154 | + protected function _generateContent($table) { |
|
| 155 | 155 | $objects=$this->_modelInstance; |
| 156 | - if(isset($this->_pagination)){ |
|
| 156 | + if (isset($this->_pagination)) { |
|
| 157 | 157 | $objects=$this->_pagination->getObjects($this->_modelInstance); |
| 158 | 158 | } |
| 159 | 159 | InstanceViewer::setIndex(0); |
| 160 | 160 | $table->fromDatabaseObjects($objects, function($instance) use($table){ |
| 161 | 161 | return $this->_generateRow($instance, $table); |
| 162 | 162 | }); |
| 163 | - if($table->getRowCount()==0){ |
|
| 163 | + if ($table->getRowCount()==0) { |
|
| 164 | 164 | $result=$table->addRow(); |
| 165 | 165 | $result->mergeRow(); |
| 166 | 166 | $result->setValues([$this->_emptyMessage]); |
| 167 | 167 | } |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | - protected function _generateRow($instance,&$table,$checkedClass=null){ |
|
| 170 | + protected function _generateRow($instance, &$table, $checkedClass=null) { |
|
| 171 | 171 | $this->_instanceViewer->setInstance($instance); |
| 172 | 172 | InstanceViewer::$index++; |
| 173 | - $values= $this->_instanceViewer->getValues(); |
|
| 173 | + $values=$this->_instanceViewer->getValues(); |
|
| 174 | 174 | $id=$this->_instanceViewer->getIdentifier(); |
| 175 | - if($this->_hasCheckboxes){ |
|
| 176 | - $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id,""); |
|
| 175 | + if ($this->_hasCheckboxes) { |
|
| 176 | + $ck=new HtmlCheckbox("ck-".$this->identifier."-".$id, ""); |
|
| 177 | 177 | $ck->setOnChange("event.stopPropagation();"); |
| 178 | 178 | $field=$ck->getField(); |
| 179 | - $field->setProperty("value",$id); |
|
| 179 | + $field->setProperty("value", $id); |
|
| 180 | 180 | $field->setProperty("name", "selection[]"); |
| 181 | - if(isset($checkedClass)) |
|
| 181 | + if (isset($checkedClass)) |
|
| 182 | 182 | $field->setClass($checkedClass); |
| 183 | 183 | \array_unshift($values, $ck); |
| 184 | 184 | } |
| 185 | 185 | $result=$table->newRow(); |
| 186 | 186 | $result->setIdentifier($this->identifier."-tr-".$id); |
| 187 | - $result->setProperty("data-ajax",$id); |
|
| 187 | + $result->setProperty("data-ajax", $id); |
|
| 188 | 188 | $result->setValues($values); |
| 189 | - $result->addToProperty("class",$this->_rowClass); |
|
| 189 | + $result->addToProperty("class", $this->_rowClass); |
|
| 190 | 190 | return $result; |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - protected function _generatePagination($table,$js=NULL){ |
|
| 194 | - if(isset($this->_toolbar)){ |
|
| 195 | - if($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 193 | + protected function _generatePagination($table, $js=NULL) { |
|
| 194 | + if (isset($this->_toolbar)) { |
|
| 195 | + if ($this->_toolbarPosition==PositionInTable::FOOTER) |
|
| 196 | 196 | $this->_toolbar->setFloated("left"); |
| 197 | 197 | } |
| 198 | 198 | $footer=$table->getFooter(); |
| 199 | 199 | $footer->mergeCol(); |
| 200 | - $menu=new HtmlPaginationMenu("pagination-".$this->identifier,$this->_pagination->getPagesNumbers()); |
|
| 200 | + $menu=new HtmlPaginationMenu("pagination-".$this->identifier, $this->_pagination->getPagesNumbers()); |
|
| 201 | 201 | $menu->floatRight(); |
| 202 | 202 | $menu->setActiveItem($this->_pagination->getPage()-1); |
| 203 | 203 | $footer->addValues($menu); |
| 204 | - $this->_associatePaginationBehavior($menu,$js); |
|
| 204 | + $this->_associatePaginationBehavior($menu, $js); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - protected function _associatePaginationBehavior(HtmlMenu $menu,JsUtils $js=NULL){ |
|
| 208 | - if(isset($this->_urls["refresh"])){ |
|
| 209 | - $menu->postOnClick($this->_urls["refresh"],"{'p':$(this).attr('data-page')}",$this->getRefreshSelector(),["preventDefault"=>false,"jqueryDone"=>"replaceWith","hasLoader"=>false]); |
|
| 207 | + protected function _associatePaginationBehavior(HtmlMenu $menu, JsUtils $js=NULL) { |
|
| 208 | + if (isset($this->_urls["refresh"])) { |
|
| 209 | + $menu->postOnClick($this->_urls["refresh"], "{'p':$(this).attr('data-page')}", $this->getRefreshSelector(), ["preventDefault"=>false, "jqueryDone"=>"replaceWith", "hasLoader"=>false]); |
|
| 210 | 210 | } |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - protected function _getFieldName($index){ |
|
| 213 | + protected function _getFieldName($index) { |
|
| 214 | 214 | $fieldName=parent::_getFieldName($index); |
| 215 | - if(\is_object($fieldName)) |
|
| 215 | + if (\is_object($fieldName)) |
|
| 216 | 216 | $fieldName="field-".$index; |
| 217 | 217 | return $fieldName."[]"; |
| 218 | 218 | } |
| 219 | 219 | |
| 220 | - protected function _getFieldCaption($index){ |
|
| 220 | + protected function _getFieldCaption($index) { |
|
| 221 | 221 | return null; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | - protected function _setToolbarPosition($table,$captions=NULL){ |
|
| 225 | - switch ($this->_toolbarPosition){ |
|
| 224 | + protected function _setToolbarPosition($table, $captions=NULL) { |
|
| 225 | + switch ($this->_toolbarPosition) { |
|
| 226 | 226 | case PositionInTable::BEFORETABLE: |
| 227 | 227 | case PositionInTable::AFTERTABLE: |
| 228 | - if(isset($this->_compileParts)===false){ |
|
| 228 | + if (isset($this->_compileParts)===false) { |
|
| 229 | 229 | $this->content[$this->_toolbarPosition]=$this->_toolbar; |
| 230 | 230 | } |
| 231 | 231 | break; |
| 232 | 232 | case PositionInTable::HEADER: |
| 233 | 233 | case PositionInTable::FOOTER: |
| 234 | 234 | case PositionInTable::BODY: |
| 235 | - $this->addToolbarRow($this->_toolbarPosition,$table, $captions); |
|
| 235 | + $this->addToolbarRow($this->_toolbarPosition, $table, $captions); |
|
| 236 | 236 | break; |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -244,16 +244,16 @@ discard block |
||
| 244 | 244 | * @param callable $callback function called after the field compilation |
| 245 | 245 | * @return DataTable |
| 246 | 246 | */ |
| 247 | - public function afterCompile($index,$callback){ |
|
| 248 | - $this->_instanceViewer->afterCompile($index,$callback); |
|
| 247 | + public function afterCompile($index, $callback) { |
|
| 248 | + $this->_instanceViewer->afterCompile($index, $callback); |
|
| 249 | 249 | return $this; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - private function addToolbarRow($part,$table,$captions){ |
|
| 252 | + private function addToolbarRow($part, $table, $captions) { |
|
| 253 | 253 | $hasPart=$table->hasPart($part); |
| 254 | - if($hasPart){ |
|
| 254 | + if ($hasPart) { |
|
| 255 | 255 | $row=$table->getPart($part)->addRow(\sizeof($captions)); |
| 256 | - }else{ |
|
| 256 | + } else { |
|
| 257 | 257 | $row=$table->getPart($part)->getRow(0); |
| 258 | 258 | } |
| 259 | 259 | $row->mergeCol(); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | * @see Widget::getHtmlComponent() |
| 266 | 266 | * @return HtmlTable |
| 267 | 267 | */ |
| 268 | - public function getHtmlComponent(){ |
|
| 268 | + public function getHtmlComponent() { |
|
| 269 | 269 | return $this->content["table"]; |
| 270 | 270 | } |
| 271 | 271 | |
@@ -280,12 +280,12 @@ discard block |
||
| 280 | 280 | * @return DataTable |
| 281 | 281 | */ |
| 282 | 282 | public function setUrls($urls) { |
| 283 | - if(\is_array($urls)){ |
|
| 284 | - $this->_urls["refresh"]=JArray::getValue($urls, "refresh",0); |
|
| 285 | - $this->_urls["edit"]=JArray::getValue($urls, "edit",1); |
|
| 286 | - $this->_urls["delete"]=JArray::getValue($urls, "delete",2); |
|
| 287 | - }else{ |
|
| 288 | - $this->_urls=["refresh"=>$urls,"edit"=>$urls,"delete"=>$urls]; |
|
| 283 | + if (\is_array($urls)) { |
|
| 284 | + $this->_urls["refresh"]=JArray::getValue($urls, "refresh", 0); |
|
| 285 | + $this->_urls["edit"]=JArray::getValue($urls, "edit", 1); |
|
| 286 | + $this->_urls["delete"]=JArray::getValue($urls, "delete", 2); |
|
| 287 | + } else { |
|
| 288 | + $this->_urls=["refresh"=>$urls, "edit"=>$urls, "delete"=>$urls]; |
|
| 289 | 289 | } |
| 290 | 290 | return $this; |
| 291 | 291 | } |
@@ -298,8 +298,8 @@ discard block |
||
| 298 | 298 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 299 | 299 | * @return DataTable |
| 300 | 300 | */ |
| 301 | - public function paginate($page,$total_rowcount,$items_per_page=10,$pages_visibles=null){ |
|
| 302 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page,$total_rowcount); |
|
| 301 | + public function paginate($page, $total_rowcount, $items_per_page=10, $pages_visibles=null) { |
|
| 302 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page, $total_rowcount); |
|
| 303 | 303 | return $this; |
| 304 | 304 | } |
| 305 | 305 | |
@@ -310,8 +310,8 @@ discard block |
||
| 310 | 310 | * @param number $pages_visibles The number of visible pages in the Pagination component |
| 311 | 311 | * @return DataTable |
| 312 | 312 | */ |
| 313 | - public function autoPaginate($page=1,$items_per_page=10,$pages_visibles=4){ |
|
| 314 | - $this->_pagination=new Pagination($items_per_page,$pages_visibles,$page); |
|
| 313 | + public function autoPaginate($page=1, $items_per_page=10, $pages_visibles=4) { |
|
| 314 | + $this->_pagination=new Pagination($items_per_page, $pages_visibles, $page); |
|
| 315 | 315 | return $this; |
| 316 | 316 | } |
| 317 | 317 | |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | * @param array $compileParts |
| 322 | 322 | * @return DataTable |
| 323 | 323 | */ |
| 324 | - public function refresh($compileParts=["tbody"]){ |
|
| 324 | + public function refresh($compileParts=["tbody"]) { |
|
| 325 | 325 | $this->_compileParts=$compileParts; |
| 326 | 326 | return $this; |
| 327 | 327 | } |
@@ -332,14 +332,14 @@ discard block |
||
| 332 | 332 | * @param string $position |
| 333 | 333 | * @return \Ajax\common\html\HtmlDoubleElement |
| 334 | 334 | */ |
| 335 | - public function addSearchInToolbar($position=Direction::RIGHT){ |
|
| 335 | + public function addSearchInToolbar($position=Direction::RIGHT) { |
|
| 336 | 336 | return $this->addInToolbar($this->getSearchField())->setPosition($position); |
| 337 | 337 | } |
| 338 | 338 | |
| 339 | - public function getSearchField(){ |
|
| 340 | - if(isset($this->_searchField)===false){ |
|
| 341 | - $this->_searchField=new HtmlInput("search-".$this->identifier,"search","","Search..."); |
|
| 342 | - $this->_searchField->addIcon("search",Direction::RIGHT); |
|
| 339 | + public function getSearchField() { |
|
| 340 | + if (isset($this->_searchField)===false) { |
|
| 341 | + $this->_searchField=new HtmlInput("search-".$this->identifier, "search", "", "Search..."); |
|
| 342 | + $this->_searchField->addIcon("search", Direction::RIGHT); |
|
| 343 | 343 | } |
| 344 | 344 | return $this->_searchField; |
| 345 | 345 | } |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | * Returns a form corresponding to the Datatable |
| 360 | 360 | * @return \Ajax\semantic\html\collections\form\HtmlForm |
| 361 | 361 | */ |
| 362 | - public function asForm(){ |
|
| 362 | + public function asForm() { |
|
| 363 | 363 | return $this->getForm(); |
| 364 | 364 | } |
| 365 | 365 | |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | |
| 368 | 368 | protected function getTargetSelector($op) { |
| 369 | 369 | $result=$this->_targetSelector; |
| 370 | - if(!isset($result[$op])) |
|
| 370 | + if (!isset($result[$op])) |
|
| 371 | 371 | $result="#".$this->identifier; |
| 372 | 372 | return $result[$op]; |
| 373 | 373 | } |
@@ -378,15 +378,15 @@ discard block |
||
| 378 | 378 | * @return DataTable |
| 379 | 379 | */ |
| 380 | 380 | public function setTargetSelector($_targetSelector) { |
| 381 | - if(!\is_array($_targetSelector)){ |
|
| 382 | - $_targetSelector=["edit"=>$_targetSelector,"delete"=>$_targetSelector]; |
|
| 381 | + if (!\is_array($_targetSelector)) { |
|
| 382 | + $_targetSelector=["edit"=>$_targetSelector, "delete"=>$_targetSelector]; |
|
| 383 | 383 | } |
| 384 | 384 | $this->_targetSelector=$_targetSelector; |
| 385 | 385 | return $this; |
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | public function getRefreshSelector() { |
| 389 | - if(isset($this->_refreshSelector)) |
|
| 389 | + if (isset($this->_refreshSelector)) |
|
| 390 | 390 | return $this->_refreshSelector; |
| 391 | 391 | return "#".$this->identifier." tbody"; |
| 392 | 392 | } |
@@ -404,9 +404,9 @@ discard block |
||
| 404 | 404 | * {@inheritDoc} |
| 405 | 405 | * @see \Ajax\common\Widget::show() |
| 406 | 406 | */ |
| 407 | - public function show($modelInstance){ |
|
| 408 | - if(\is_array($modelInstance)){ |
|
| 409 | - if(isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
|
| 407 | + public function show($modelInstance) { |
|
| 408 | + if (\is_array($modelInstance)) { |
|
| 409 | + if (isset($modelInstance[0]) && \is_array(array_values($modelInstance)[0])) |
|
| 410 | 410 | $modelInstance=\json_decode(\json_encode($modelInstance), FALSE); |
| 411 | 411 | } |
| 412 | 412 | $this->_modelInstance=$modelInstance; |
@@ -441,24 +441,24 @@ discard block |
||
| 441 | 441 | return $this; |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
| 445 | - $this->_self->setActiveRowSelector($class,$event,$multiple); |
|
| 444 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
| 445 | + $this->_self->setActiveRowSelector($class, $event, $multiple); |
|
| 446 | 446 | return $this; |
| 447 | 447 | } |
| 448 | 448 | |
| 449 | - public function hideColumn($colIndex){ |
|
| 450 | - if(!\is_array($this->_hiddenColumns)) |
|
| 449 | + public function hideColumn($colIndex) { |
|
| 450 | + if (!\is_array($this->_hiddenColumns)) |
|
| 451 | 451 | $this->_hiddenColumns=[]; |
| 452 | 452 | $this->_hiddenColumns[]=$colIndex; |
| 453 | 453 | return $this; |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - public function setColWidth($colIndex,$width){ |
|
| 456 | + public function setColWidth($colIndex, $width) { |
|
| 457 | 457 | $this->_colWidths[$colIndex]=$width; |
| 458 | 458 | return $this; |
| 459 | 459 | } |
| 460 | 460 | public function setColWidths($_colWidths) { |
| 461 | - $this->_colWidths = $_colWidths; |
|
| 461 | + $this->_colWidths=$_colWidths; |
|
| 462 | 462 | return $this; |
| 463 | 463 | } |
| 464 | 464 | } |
@@ -28,10 +28,10 @@ discard block |
||
| 28 | 28 | |
| 29 | 29 | public function __construct($identifier, $rowCount, $colCount) { |
| 30 | 30 | parent::__construct($identifier, "table", "ui table"); |
| 31 | - $this->content=array (); |
|
| 31 | + $this->content=array(); |
|
| 32 | 32 | $this->setRowCount($rowCount, $colCount); |
| 33 | - $this->_variations=[ Variation::CELLED,Variation::PADDED,Variation::COMPACT ]; |
|
| 34 | - $this->_compileParts=["thead","tbody","tfoot"]; |
|
| 33 | + $this->_variations=[Variation::CELLED, Variation::PADDED, Variation::COMPACT]; |
|
| 34 | + $this->_compileParts=["thead", "tbody", "tfoot"]; |
|
| 35 | 35 | $this->_afterCompileEvents=[]; |
| 36 | 36 | } |
| 37 | 37 | |
@@ -41,17 +41,17 @@ discard block |
||
| 41 | 41 | * @return HtmlTableContent |
| 42 | 42 | */ |
| 43 | 43 | public function getPart($key) { |
| 44 | - if (\array_key_exists($key, $this->content) === false) { |
|
| 44 | + if (\array_key_exists($key, $this->content)===false) { |
|
| 45 | 45 | $this->content[$key]=new HtmlTableContent("", $key); |
| 46 | - if ($key !== "tbody") { |
|
| 46 | + if ($key!=="tbody") { |
|
| 47 | 47 | $this->content[$key]->setRowCount(1, $this->_colCount); |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | return $this->content[$key]; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - protected function _getFirstPart(){ |
|
| 54 | - if(isset($this->content["thead"])){ |
|
| 53 | + protected function _getFirstPart() { |
|
| 54 | + if (isset($this->content["thead"])) { |
|
| 55 | 55 | return $this->content["thead"]; |
| 56 | 56 | } |
| 57 | 57 | return $this->content["tbody"]; |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * @return boolean |
| 97 | 97 | */ |
| 98 | 98 | public function hasPart($key) { |
| 99 | - return \array_key_exists($key, $this->content) === true; |
|
| 99 | + return \array_key_exists($key, $this->content)===true; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -229,8 +229,8 @@ discard block |
||
| 229 | 229 | return $this->colAlign($colIndex, "colLeft"); |
| 230 | 230 | } |
| 231 | 231 | |
| 232 | - public function setColAlignment($colIndex,$alignment){ |
|
| 233 | - switch ($alignment){ |
|
| 232 | + public function setColAlignment($colIndex, $alignment) { |
|
| 233 | + switch ($alignment) { |
|
| 234 | 234 | case TextAlignment::LEFT: |
| 235 | 235 | $function="colLeft"; |
| 236 | 236 | break; |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | |
| 249 | 249 | private function colAlign($colIndex, $function) { |
| 250 | 250 | if (\is_array($colIndex)) { |
| 251 | - foreach ( $colIndex as $cIndex ) { |
|
| 251 | + foreach ($colIndex as $cIndex) { |
|
| 252 | 252 | $this->colAlign($cIndex, $function); |
| 253 | 253 | } |
| 254 | 254 | } else { |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @see HtmlSemDoubleElement::compile() |
| 310 | 310 | */ |
| 311 | 311 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 312 | - if(\sizeof($this->_compileParts)<3){ |
|
| 312 | + if (\sizeof($this->_compileParts)<3) { |
|
| 313 | 313 | $this->_template="%content%"; |
| 314 | 314 | $this->refresh(); |
| 315 | 315 | } |
@@ -318,11 +318,11 @@ discard block |
||
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | protected function compile_once(JsUtils $js=NULL, &$view=NULL) { |
| 321 | - parent::compile_once($js,$view); |
|
| 321 | + parent::compile_once($js, $view); |
|
| 322 | 322 | if ($this->propertyContains("class", "sortable")) { |
| 323 | - $this->addEvent("execute", "$('#" . $this->identifier . "').tablesort().data('tablesort').sort($('th.default-sort'));"); |
|
| 323 | + $this->addEvent("execute", "$('#".$this->identifier."').tablesort().data('tablesort').sort($('th.default-sort'));"); |
|
| 324 | 324 | } |
| 325 | - if(isset($this->_activeRowSelector)){ |
|
| 325 | + if (isset($this->_activeRowSelector)) { |
|
| 326 | 326 | $this->_activeRowSelector->compile(); |
| 327 | 327 | } |
| 328 | 328 | } |
@@ -336,13 +336,13 @@ discard block |
||
| 336 | 336 | public function fromDatabaseObject($object, $function) { |
| 337 | 337 | $result=$function($object); |
| 338 | 338 | if (\is_array($result)) { |
| 339 | - $result= $this->addRow($function($object)); |
|
| 339 | + $result=$this->addRow($function($object)); |
|
| 340 | 340 | } else { |
| 341 | - $result= $this->getBody()->_addRow($result); |
|
| 341 | + $result=$this->getBody()->_addRow($result); |
|
| 342 | 342 | } |
| 343 | - if(isset($this->_afterCompileEvents["onNewRow"])){ |
|
| 344 | - if(\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
| 345 | - $this->_afterCompileEvents["onNewRow"]($result,$object); |
|
| 343 | + if (isset($this->_afterCompileEvents["onNewRow"])) { |
|
| 344 | + if (\is_callable($this->_afterCompileEvents["onNewRow"])) |
|
| 345 | + $this->_afterCompileEvents["onNewRow"]($result, $object); |
|
| 346 | 346 | } |
| 347 | 347 | return $result; |
| 348 | 348 | } |
@@ -357,14 +357,14 @@ discard block |
||
| 357 | 357 | return $this; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | - public function refresh(){ |
|
| 360 | + public function refresh() { |
|
| 361 | 361 | $this->_footer=$this->getFooter(); |
| 362 | 362 | $this->addEvent("execute", '$("#'.$this->identifier.' tfoot").replaceWith("'.\addslashes($this->_footer).'");'); |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - public function run(JsUtils $js){ |
|
| 366 | - $result= parent::run($js); |
|
| 367 | - if(isset($this->_footer)) |
|
| 365 | + public function run(JsUtils $js) { |
|
| 366 | + $result=parent::run($js); |
|
| 367 | + if (isset($this->_footer)) |
|
| 368 | 368 | $this->_footer->run($js); |
| 369 | 369 | return $result; |
| 370 | 370 | } |
@@ -387,38 +387,38 @@ discard block |
||
| 387 | 387 | * @param boolean $multiple |
| 388 | 388 | * @return HtmlTable |
| 389 | 389 | */ |
| 390 | - public function setActiveRowSelector($class="active",$event="click",$multiple=false){ |
|
| 391 | - $this->_activeRowSelector=new ActiveRow($this,$class,$event,$multiple); |
|
| 390 | + public function setActiveRowSelector($class="active", $event="click", $multiple=false) { |
|
| 391 | + $this->_activeRowSelector=new ActiveRow($this, $class, $event, $multiple); |
|
| 392 | 392 | return $this; |
| 393 | 393 | } |
| 394 | 394 | |
| 395 | - public function hideColumn($colIndex){ |
|
| 396 | - if(isset($this->content["thead"])){ |
|
| 395 | + public function hideColumn($colIndex) { |
|
| 396 | + if (isset($this->content["thead"])) { |
|
| 397 | 397 | $this->content["thead"]->hideColumn($colIndex); |
| 398 | 398 | } |
| 399 | 399 | $this->content["tbody"]->hideColumn($colIndex); |
| 400 | - if(isset($this->content["tfoot"])){ |
|
| 400 | + if (isset($this->content["tfoot"])) { |
|
| 401 | 401 | $this->content["tfoot"]->hideColumn($colIndex); |
| 402 | 402 | } |
| 403 | 403 | return $this; |
| 404 | 404 | } |
| 405 | 405 | |
| 406 | - public function setColWidth($colIndex,$width){ |
|
| 406 | + public function setColWidth($colIndex, $width) { |
|
| 407 | 407 | $part=$this->_getFirstPart(); |
| 408 | - if($part!==null && $part->count()>0) |
|
| 408 | + if ($part!==null && $part->count()>0) |
|
| 409 | 409 | $part->getCell(0, $colIndex)->setWidth($width); |
| 410 | 410 | return $this; |
| 411 | 411 | } |
| 412 | 412 | |
| 413 | - public function setColWidths($widths){ |
|
| 413 | + public function setColWidths($widths) { |
|
| 414 | 414 | $part=$this->_getFirstPart(); |
| 415 | - if($part!==null && $part->count()>0){ |
|
| 415 | + if ($part!==null && $part->count()>0) { |
|
| 416 | 416 | $count=$part->getColCount(); |
| 417 | - if(!\is_array($widths)){ |
|
| 417 | + if (!\is_array($widths)) { |
|
| 418 | 418 | $widths=\array_fill(0, $count, $widths); |
| 419 | 419 | } |
| 420 | - $max=\min(\sizeof($widths),$count); |
|
| 421 | - for($i=0;$i<$max;$i++){ |
|
| 420 | + $max=\min(\sizeof($widths), $count); |
|
| 421 | + for ($i=0; $i<$max; $i++) { |
|
| 422 | 422 | $part->getCell(0, $i)->setWidth($widths[$i]); |
| 423 | 423 | } |
| 424 | 424 | } |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | * @version 1.3 |
| 16 | 16 | */ |
| 17 | 17 | abstract class BaseHtml extends BaseWidget { |
| 18 | - use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait; |
|
| 18 | + use BaseHtmlEventsTrait, BaseHtmlPropertiesTrait; |
|
| 19 | 19 | protected $_template; |
| 20 | 20 | protected $tagName; |
| 21 | - protected $_wrapBefore=array (); |
|
| 22 | - protected $_wrapAfter=array (); |
|
| 21 | + protected $_wrapBefore=array(); |
|
| 22 | + protected $_wrapAfter=array(); |
|
| 23 | 23 | protected $_bsComponent; |
| 24 | 24 | protected $_compiled=false; |
| 25 | 25 | protected $_postCompile; |
@@ -32,14 +32,14 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | abstract public function run(JsUtils $js); |
| 34 | 34 | |
| 35 | - private function _callSetter($setter,$key,$value,&$array){ |
|
| 35 | + private function _callSetter($setter, $key, $value, &$array) { |
|
| 36 | 36 | $result=false; |
| 37 | 37 | if (method_exists($this, $setter) && !JString::startswith($key, "_")) { |
| 38 | 38 | try { |
| 39 | 39 | $this->$setter($value); |
| 40 | 40 | unset($array[$key]); |
| 41 | 41 | $result=true; |
| 42 | - } catch ( \Exception $e ) { |
|
| 42 | + }catch (\Exception $e) { |
|
| 43 | 43 | $result=false; |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -47,17 +47,17 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | protected function getTemplate(JsUtils $js=NULL) { |
| 50 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 50 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | protected function ctrl($name, $value, $typeCtrl) { |
| 54 | 54 | if (\is_array($typeCtrl)) { |
| 55 | - if (array_search($value, $typeCtrl) === false) { |
|
| 56 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
| 55 | + if (array_search($value, $typeCtrl)===false) { |
|
| 56 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
| 57 | 57 | } |
| 58 | 58 | } else { |
| 59 | 59 | if (!$typeCtrl($value)) { |
| 60 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
| 60 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
| 61 | 61 | } |
| 62 | 62 | } |
| 63 | 63 | return true; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | |
| 67 | 67 | |
| 68 | 68 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 69 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 69 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 70 | 70 | return $name=$value; |
| 71 | 71 | } |
| 72 | 72 | return $this; |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
| 76 | 76 | if (\is_array($typeCtrl)) { |
| 77 | 77 | $this->removeOldValues($name, $typeCtrl); |
| 78 | - $name.=$separator . $value; |
|
| 78 | + $name.=$separator.$value; |
|
| 79 | 79 | } |
| 80 | 80 | return $this; |
| 81 | 81 | } |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | |
| 85 | 85 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 86 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 86 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 87 | 87 | if (\is_array($typeCtrl)) { |
| 88 | 88 | $this->removeOldValues($name, $typeCtrl); |
| 89 | 89 | } |
| 90 | - $name.=$separator . $value; |
|
| 90 | + $name.=$separator.$value; |
|
| 91 | 91 | } |
| 92 | 92 | return $this; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | protected function addToMember(&$name, $value, $separator=" ") { |
| 96 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
| 96 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
| 97 | 97 | return $this; |
| 98 | 98 | } |
| 99 | 99 | |
@@ -104,18 +104,18 @@ discard block |
||
| 104 | 104 | $oldValue=trim($oldValue); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - protected function _getElementBy($callback,$elements){ |
|
| 107 | + protected function _getElementBy($callback, $elements) { |
|
| 108 | 108 | if (\is_array($elements)) { |
| 109 | 109 | $elements=\array_values($elements); |
| 110 | 110 | $flag=false; |
| 111 | 111 | $index=0; |
| 112 | - while ( !$flag && $index < sizeof($elements) ) { |
|
| 112 | + while (!$flag && $index<sizeof($elements)) { |
|
| 113 | 113 | if ($elements[$index] instanceof BaseHtml) |
| 114 | 114 | $flag=($callback($elements[$index])); |
| 115 | 115 | $index++; |
| 116 | 116 | } |
| 117 | - if ($flag === true) |
|
| 118 | - return $elements[$index - 1]; |
|
| 117 | + if ($flag===true) |
|
| 118 | + return $elements[$index-1]; |
|
| 119 | 119 | } elseif ($elements instanceof BaseHtml) { |
| 120 | 120 | if ($callback($elements)) |
| 121 | 121 | return $elements; |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | public function fromArray($array) { |
| 146 | - foreach ( $this as $key => $value ) { |
|
| 147 | - if(array_key_exists($key, $array)===true) |
|
| 148 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 146 | + foreach ($this as $key => $value) { |
|
| 147 | + if (array_key_exists($key, $array)===true) |
|
| 148 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
| 149 | 149 | } |
| 150 | - foreach ( $array as $key => $value ) { |
|
| 151 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
| 152 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
| 150 | + foreach ($array as $key => $value) { |
|
| 151 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
| 152 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | return $array; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | |
| 158 | 158 | public function fromDatabaseObjects($objects, $function) { |
| 159 | 159 | if (isset($objects)) { |
| 160 | - foreach ( $objects as $object ) { |
|
| 160 | + foreach ($objects as $object) { |
|
| 161 | 161 | $this->fromDatabaseObject($object, $function); |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | |
| 180 | 180 | public function getElementById($identifier, $elements) { |
| 181 | - return $this->_getElementBy(function(BaseWidget $element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
| 181 | + return $this->_getElementBy(function(BaseWidget $element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | public function getBsComponent() { |
@@ -191,14 +191,14 @@ discard block |
||
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | protected function compile_once(JsUtils $js=NULL, &$view=NULL) { |
| 194 | - if(!$this->_compiled){ |
|
| 195 | - if(isset($js)){ |
|
| 194 | + if (!$this->_compiled) { |
|
| 195 | + if (isset($js)) { |
|
| 196 | 196 | $beforeCompile=$js->getParam("beforeCompileHtml"); |
| 197 | - if(\is_callable($beforeCompile)){ |
|
| 198 | - $beforeCompile($this,$js,$view); |
|
| 197 | + if (\is_callable($beforeCompile)) { |
|
| 198 | + $beforeCompile($this, $js, $view); |
|
| 199 | 199 | } |
| 200 | 200 | } |
| 201 | - if(\is_callable($this->_preCompile)){ |
|
| 201 | + if (\is_callable($this->_preCompile)) { |
|
| 202 | 202 | $pc=$this->_preCompile; |
| 203 | 203 | $pc(); |
| 204 | 204 | } |
@@ -207,25 +207,25 @@ discard block |
||
| 207 | 207 | } |
| 208 | 208 | |
| 209 | 209 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 210 | - $this->compile_once($js,$view); |
|
| 210 | + $this->compile_once($js, $view); |
|
| 211 | 211 | $result=$this->getTemplate($js); |
| 212 | - foreach ( $this as $key => $value ) { |
|
| 213 | - if (JString::startswith($key, "_") === false && $key !== "events") { |
|
| 212 | + foreach ($this as $key => $value) { |
|
| 213 | + if (JString::startswith($key, "_")===false && $key!=="events") { |
|
| 214 | 214 | if (\is_array($value)) { |
| 215 | 215 | $v=PropertyWrapper::wrap($value, $js); |
| 216 | 216 | } else { |
| 217 | 217 | $v=$value; |
| 218 | 218 | } |
| 219 | - $result=str_ireplace("%" . $key . "%", $v, $result); |
|
| 219 | + $result=str_ireplace("%".$key."%", $v, $result); |
|
| 220 | 220 | } |
| 221 | 221 | } |
| 222 | 222 | if (isset($js)===true) { |
| 223 | 223 | $this->run($js); |
| 224 | - if (isset($view) === true) { |
|
| 224 | + if (isset($view)===true) { |
|
| 225 | 225 | $js->addViewElement($this->_identifier, $result, $view); |
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | - if(\is_callable($this->_postCompile)){ |
|
| 228 | + if (\is_callable($this->_postCompile)) { |
|
| 229 | 229 | $pc=$this->_postCompile; |
| 230 | 230 | $pc(); |
| 231 | 231 | } |
@@ -236,11 +236,11 @@ discard block |
||
| 236 | 236 | return $this->compile(); |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - public function onPostCompile($callback){ |
|
| 239 | + public function onPostCompile($callback) { |
|
| 240 | 240 | $this->_postCompile=$callback; |
| 241 | 241 | } |
| 242 | 242 | |
| 243 | - public function onPreCompile($callback){ |
|
| 243 | + public function onPreCompile($callback) { |
|
| 244 | 244 | $this->_preCompile=$callback; |
| 245 | 245 | } |
| 246 | 246 | } |
@@ -15,52 +15,52 @@ discard block |
||
| 15 | 15 | protected $_paramParts=array(); |
| 16 | 16 | |
| 17 | 17 | public function __construct($identifier, $header="", $content="", $actions=null) { |
| 18 | - parent::__construct($identifier, "div","ui modal"); |
|
| 19 | - if(isset($header)){ |
|
| 18 | + parent::__construct($identifier, "div", "ui modal"); |
|
| 19 | + if (isset($header)) { |
|
| 20 | 20 | $this->setHeader($header); |
| 21 | 21 | } |
| 22 | - if(isset($content)){ |
|
| 22 | + if (isset($content)) { |
|
| 23 | 23 | $this->setContent($content); |
| 24 | 24 | } |
| 25 | - if(isset($actions)){ |
|
| 25 | + if (isset($actions)) { |
|
| 26 | 26 | $this->setActions($actions); |
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | public function setHeader($value) { |
| 31 | - $this->content["header"]=new HtmlSemDoubleElement("header-" . $this->identifier, "a", "header", $value); |
|
| 31 | + $this->content["header"]=new HtmlSemDoubleElement("header-".$this->identifier, "a", "header", $value); |
|
| 32 | 32 | return $this; |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function setContent($value) { |
| 36 | - $this->content["content"]=new HtmlSemDoubleElement("content-" . $this->identifier, "div", "content", $value); |
|
| 36 | + $this->content["content"]=new HtmlSemDoubleElement("content-".$this->identifier, "div", "content", $value); |
|
| 37 | 37 | return $this; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | public function setActions($actions) { |
| 41 | - $this->content["actions"]=new HtmlSemDoubleElement("content-" . $this->identifier, "div", "actions"); |
|
| 42 | - if(\is_array($actions)){ |
|
| 43 | - foreach ($actions as $action){ |
|
| 41 | + $this->content["actions"]=new HtmlSemDoubleElement("content-".$this->identifier, "div", "actions"); |
|
| 42 | + if (\is_array($actions)) { |
|
| 43 | + foreach ($actions as $action) { |
|
| 44 | 44 | $this->addAction($action); |
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | - else{ |
|
| 47 | + else { |
|
| 48 | 48 | $this->addAction($actions); |
| 49 | 49 | } |
| 50 | 50 | return $this; |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - public function addAction($action){ |
|
| 54 | - if(!$action instanceof BaseHtml){ |
|
| 53 | + public function addAction($action) { |
|
| 54 | + if (!$action instanceof BaseHtml) { |
|
| 55 | 55 | $class=""; |
| 56 | - if(\array_search($action, ["Okay","Yes"])!==false){ |
|
| 56 | + if (\array_search($action, ["Okay", "Yes"])!==false) { |
|
| 57 | 57 | $class="approve"; |
| 58 | 58 | } |
| 59 | - if(\array_search($action, ["Close","Cancel","No"])!==false){ |
|
| 59 | + if (\array_search($action, ["Close", "Cancel", "No"])!==false) { |
|
| 60 | 60 | $class="cancel"; |
| 61 | 61 | } |
| 62 | - $action=new HtmlButton("action-".$this->identifier,$action); |
|
| 63 | - if($class!=="") |
|
| 62 | + $action=new HtmlButton("action-".$this->identifier, $action); |
|
| 63 | + if ($class!=="") |
|
| 64 | 64 | $action->addToProperty("class", $class); |
| 65 | 65 | } |
| 66 | 66 | return $this->addElementInPart($action, "actions"); |
@@ -70,66 +70,66 @@ discard block |
||
| 70 | 70 | * @param int $index |
| 71 | 71 | * @return HtmlButton |
| 72 | 72 | */ |
| 73 | - public function getAction($index){ |
|
| 73 | + public function getAction($index) { |
|
| 74 | 74 | return $this->content["actions"]->getContent()[$index]; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function addContent($content,$before=false){ |
|
| 78 | - $this->content["content"]->addContent($content,$before); |
|
| 77 | + public function addContent($content, $before=false) { |
|
| 78 | + $this->content["content"]->addContent($content, $before); |
|
| 79 | 79 | return $this; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - public function addImageContent($image,$description=NULL){ |
|
| 82 | + public function addImageContent($image, $description=NULL) { |
|
| 83 | 83 | $content=$this->content["content"]; |
| 84 | - if(isset($description)){ |
|
| 85 | - $description=new HtmlSemDoubleElement("description-".$this->identifier,"div","description",$description); |
|
| 86 | - $content->addContent($description,true); |
|
| 84 | + if (isset($description)) { |
|
| 85 | + $description=new HtmlSemDoubleElement("description-".$this->identifier, "div", "description", $description); |
|
| 86 | + $content->addContent($description, true); |
|
| 87 | 87 | } |
| 88 | - if($image!==""){ |
|
| 89 | - $img=new HtmlImage("image-".$this->identifier,$image,"","medium"); |
|
| 90 | - $content->addContent($img,true); |
|
| 91 | - $content->addToProperty("class","image"); |
|
| 88 | + if ($image!=="") { |
|
| 89 | + $img=new HtmlImage("image-".$this->identifier, $image, "", "medium"); |
|
| 90 | + $content->addContent($img, true); |
|
| 91 | + $content->addToProperty("class", "image"); |
|
| 92 | 92 | } |
| 93 | 93 | return $this; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function addIconContent($icon,$description=NULL){ |
|
| 96 | + public function addIconContent($icon, $description=NULL) { |
|
| 97 | 97 | $content=$this->content["content"]; |
| 98 | - if(isset($description)){ |
|
| 99 | - $description=new HtmlSemDoubleElement("description-".$this->identifier,"div","description",$description); |
|
| 100 | - $content->addContent($description,true); |
|
| 98 | + if (isset($description)) { |
|
| 99 | + $description=new HtmlSemDoubleElement("description-".$this->identifier, "div", "description", $description); |
|
| 100 | + $content->addContent($description, true); |
|
| 101 | 101 | } |
| 102 | - if($icon!==""){ |
|
| 103 | - $img=new HtmlIcon("image-".$this->identifier,$icon); |
|
| 104 | - $content->addContent($img,true); |
|
| 105 | - $content->addToProperty("class","image"); |
|
| 102 | + if ($icon!=="") { |
|
| 103 | + $img=new HtmlIcon("image-".$this->identifier, $icon); |
|
| 104 | + $content->addContent($img, true); |
|
| 105 | + $content->addToProperty("class", "image"); |
|
| 106 | 106 | } |
| 107 | 107 | return $this; |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - private function addElementInPart($element,$part) { |
|
| 110 | + private function addElementInPart($element, $part) { |
|
| 111 | 111 | $this->content[$part]->addContent($element); |
| 112 | 112 | return $element; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - public function showDimmer($value){ |
|
| 116 | - $value=$value?"show":"hide"; |
|
| 115 | + public function showDimmer($value) { |
|
| 116 | + $value=$value ? "show" : "hide"; |
|
| 117 | 117 | $this->_paramParts[]=["'".$value." dimmer'"]; |
| 118 | 118 | return $this; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - public function setInverted($recursive=true){ |
|
| 121 | + public function setInverted($recursive=true) { |
|
| 122 | 122 | $this->_params["inverted"]=true; |
| 123 | 123 | return $this; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | - public function setBasic(){ |
|
| 126 | + public function setBasic() { |
|
| 127 | 127 | return $this->addToProperty("class", "basic"); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | |
| 131 | - public function setTransition($value){ |
|
| 132 | - $this->_paramParts[]=["'setting'","'transition'","'".$value."'"]; |
|
| 131 | + public function setTransition($value) { |
|
| 132 | + $this->_paramParts[]=["'setting'", "'transition'", "'".$value."'"]; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -139,8 +139,8 @@ discard block |
||
| 139 | 139 | * @param string $viewName |
| 140 | 140 | * @param $params The parameters to pass to the view |
| 141 | 141 | */ |
| 142 | - public function renderView(JsUtils $js,$initialController,$viewName, $params=array()) { |
|
| 143 | - return $this->setContent($js->renderContent($initialController, $viewName,$params)); |
|
| 142 | + public function renderView(JsUtils $js, $initialController, $viewName, $params=array()) { |
|
| 143 | + return $this->setContent($js->renderContent($initialController, $viewName, $params)); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -151,8 +151,8 @@ discard block |
||
| 151 | 151 | * @param string $actionName the action name |
| 152 | 152 | * @param array $params |
| 153 | 153 | */ |
| 154 | - public function forward(JsUtils $js,$initialControllerInstance,$controllerName,$actionName,$params=NULL){ |
|
| 155 | - return $this->setContent($js->forward($initialControllerInstance, $controllerName, $actionName,$params)); |
|
| 154 | + public function forward(JsUtils $js, $initialControllerInstance, $controllerName, $actionName, $params=NULL) { |
|
| 155 | + return $this->setContent($js->forward($initialControllerInstance, $controllerName, $actionName, $params)); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @see \Ajax\semantic\html\base\HtmlSemDoubleElement::compile() |
| 163 | 163 | */ |
| 164 | 164 | public function compile(JsUtils $js=NULL, &$view=NULL) { |
| 165 | - $this->content=JArray::sortAssociative($this->content, ["header","content","actions" ]); |
|
| 165 | + $this->content=JArray::sortAssociative($this->content, ["header", "content", "actions"]); |
|
| 166 | 166 | return parent::compile($js, $view); |
| 167 | 167 | } |
| 168 | 168 | /* |
@@ -170,8 +170,8 @@ discard block |
||
| 170 | 170 | * @see BaseHtml::run() |
| 171 | 171 | */ |
| 172 | 172 | public function run(JsUtils $js) { |
| 173 | - if(isset($this->_bsComponent)===false) |
|
| 174 | - $this->_bsComponent=$js->semantic()->modal("#".$this->identifier,$this->_params,$this->_paramParts); |
|
| 173 | + if (isset($this->_bsComponent)===false) |
|
| 174 | + $this->_bsComponent=$js->semantic()->modal("#".$this->identifier, $this->_params, $this->_paramParts); |
|
| 175 | 175 | $this->addEventsOnRun($js); |
| 176 | 176 | return $this->_bsComponent; |
| 177 | 177 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | return $this->jsDo("hide"); |
| 185 | 185 | } |
| 186 | 186 | |
| 187 | - public function onHidden($js){ |
|
| 187 | + public function onHidden($js) { |
|
| 188 | 188 | $this->_params["onHidden"]=$js; |
| 189 | 189 | } |
| 190 | 190 | } |
@@ -19,220 +19,220 @@ discard block |
||
| 19 | 19 | |
| 20 | 20 | public static $index=0; |
| 21 | 21 | |
| 22 | - public function __construct($identifier,$instance=NULL,$captions=NULL){ |
|
| 22 | + public function __construct($identifier, $instance=NULL, $captions=NULL) { |
|
| 23 | 23 | $this->widgetIdentifier=$identifier; |
| 24 | 24 | $this->values=[]; |
| 25 | 25 | $this->afterCompile=[]; |
| 26 | - if(isset($instance)) |
|
| 26 | + if (isset($instance)) |
|
| 27 | 27 | $this->setInstance($instance); |
| 28 | 28 | $this->setCaptions($captions); |
| 29 | 29 | $this->captionCallback=NULL; |
| 30 | - $this->defaultValueFunction=function($name,$value){return $value;}; |
|
| 30 | + $this->defaultValueFunction=function($name, $value) {return $value; }; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - public function moveFieldTo($from,$to){ |
|
| 34 | - if(JArray::moveElementTo($this->visibleProperties, $from, $to)){ |
|
| 33 | + public function moveFieldTo($from, $to) { |
|
| 34 | + if (JArray::moveElementTo($this->visibleProperties, $from, $to)) { |
|
| 35 | 35 | return JArray::moveElementTo($this->values, $from, $to); |
| 36 | 36 | } |
| 37 | 37 | return false; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - public function swapFields($index1,$index2){ |
|
| 41 | - if(JArray::swapElements($this->visibleProperties, $index1, $index2)){ |
|
| 40 | + public function swapFields($index1, $index2) { |
|
| 41 | + if (JArray::swapElements($this->visibleProperties, $index1, $index2)) { |
|
| 42 | 42 | return JArray::swapElements($this->values, $index1, $index2); |
| 43 | 43 | } |
| 44 | 44 | return false; |
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - public function removeField($index){ |
|
| 48 | - \array_splice($this->visibleProperties,$index,1); |
|
| 49 | - \array_splice($this->values,$index,1); |
|
| 50 | - \array_splice($this->captions,$index,1); |
|
| 47 | + public function removeField($index) { |
|
| 48 | + \array_splice($this->visibleProperties, $index, 1); |
|
| 49 | + \array_splice($this->values, $index, 1); |
|
| 50 | + \array_splice($this->captions, $index, 1); |
|
| 51 | 51 | return $this; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - public function getValues(){ |
|
| 54 | + public function getValues() { |
|
| 55 | 55 | $values=[]; |
| 56 | 56 | $index=0; |
| 57 | 57 | $count=$this->count(); |
| 58 | - while($index<$count){ |
|
| 58 | + while ($index<$count) { |
|
| 59 | 59 | $values[]=$this->getValue($index++); |
| 60 | 60 | } |
| 61 | 61 | return $values; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - public function getIdentifier($index=NULL){ |
|
| 65 | - if(!isset($index)) |
|
| 64 | + public function getIdentifier($index=NULL) { |
|
| 65 | + if (!isset($index)) |
|
| 66 | 66 | $index=self::$index; |
| 67 | 67 | $value=$index; |
| 68 | - if(isset($this->values["identifier"])){ |
|
| 69 | - if(\is_string($this->values["identifier"])) |
|
| 68 | + if (isset($this->values["identifier"])) { |
|
| 69 | + if (\is_string($this->values["identifier"])) |
|
| 70 | 70 | $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
| 71 | 71 | else |
| 72 | - $value=$this->values["identifier"]($index,$this->instance); |
|
| 72 | + $value=$this->values["identifier"]($index, $this->instance); |
|
| 73 | 73 | } |
| 74 | 74 | return $value; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - public function getValue($index){ |
|
| 77 | + public function getValue($index) { |
|
| 78 | 78 | $property=$this->properties[$index]; |
| 79 | 79 | return $this->_getValue($property, $index); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - protected function _beforeAddProperty($index,&$field){ |
|
| 82 | + protected function _beforeAddProperty($index, &$field) { |
|
| 83 | 83 | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - protected function _getDefaultValue($name,$value,$index){ |
|
| 86 | + protected function _getDefaultValue($name, $value, $index) { |
|
| 87 | 87 | $func=$this->defaultValueFunction; |
| 88 | - return $func($name,$value,$index,$this->instance); |
|
| 88 | + return $func($name, $value, $index, $this->instance); |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - protected function _getPropertyValue(\ReflectionProperty $property,$index){ |
|
| 91 | + protected function _getPropertyValue(\ReflectionProperty $property, $index) { |
|
| 92 | 92 | $property->setAccessible(true); |
| 93 | 93 | return $property->getValue($this->instance); |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - protected function _getValue($property,$index){ |
|
| 96 | + protected function _getValue($property, $index) { |
|
| 97 | 97 | $value=null; |
| 98 | 98 | $propertyName=$property; |
| 99 | - if($property instanceof \ReflectionProperty){ |
|
| 99 | + if ($property instanceof \ReflectionProperty) { |
|
| 100 | 100 | $value=$this->_getPropertyValue($property, $index); |
| 101 | 101 | $propertyName=$property->getName(); |
| 102 | - }elseif(\is_callable($property)) |
|
| 102 | + }elseif (\is_callable($property)) |
|
| 103 | 103 | $value=$property($this->instance); |
| 104 | - elseif(\is_array($property)){ |
|
| 105 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
| 104 | + elseif (\is_array($property)) { |
|
| 105 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
| 106 | 106 | $value=\implode("", $values); |
| 107 | - }elseif(\is_string($property)){ |
|
| 107 | + }elseif (\is_string($property)) { |
|
| 108 | 108 | $value=$property; |
| 109 | - if(isset($this->instance->{$property})){ |
|
| 109 | + if (isset($this->instance->{$property})) { |
|
| 110 | 110 | $value=$this->instance->{$property}; |
| 111 | - }elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
| 111 | + }elseif (\method_exists($this->instance, $getter=JReflection::getterName($property))) { |
|
| 112 | 112 | $value=JReflection::callMethod($this->instance, $getter, []); |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | return $this->_postGetValue($index, $propertyName, $value); |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - protected function _postGetValue($index,$propertyName,$value){ |
|
| 119 | - if(isset($this->values[$index])){ |
|
| 120 | - $value= $this->values[$index]($value,$this->instance,$index); |
|
| 121 | - }else{ |
|
| 122 | - $value=$this->_getDefaultValue($propertyName,$value, $index); |
|
| 118 | + protected function _postGetValue($index, $propertyName, $value) { |
|
| 119 | + if (isset($this->values[$index])) { |
|
| 120 | + $value=$this->values[$index]($value, $this->instance, $index); |
|
| 121 | + } else { |
|
| 122 | + $value=$this->_getDefaultValue($propertyName, $value, $index); |
|
| 123 | 123 | } |
| 124 | - if(isset($this->afterCompile[$index])){ |
|
| 125 | - if(\is_callable($this->afterCompile[$index])){ |
|
| 126 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
| 124 | + if (isset($this->afterCompile[$index])) { |
|
| 125 | + if (\is_callable($this->afterCompile[$index])) { |
|
| 126 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
| 127 | 127 | } |
| 128 | 128 | } |
| 129 | 129 | return $value; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - public function insertField($index,$field){ |
|
| 133 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
| 132 | + public function insertField($index, $field) { |
|
| 133 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
| 134 | 134 | return $this; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - public function insertInField($index,$field){ |
|
| 137 | + public function insertInField($index, $field) { |
|
| 138 | 138 | $vb=$this->visibleProperties; |
| 139 | - if(isset($vb[$index])){ |
|
| 140 | - if(\is_array($vb[$index])){ |
|
| 139 | + if (isset($vb[$index])) { |
|
| 140 | + if (\is_array($vb[$index])) { |
|
| 141 | 141 | $this->visibleProperties[$index][]=$field; |
| 142 | - }else{ |
|
| 143 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
| 142 | + } else { |
|
| 143 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
| 144 | 144 | } |
| 145 | - }else{ |
|
| 145 | + } else { |
|
| 146 | 146 | return $this->insertField($index, $field); |
| 147 | 147 | } |
| 148 | 148 | return $this; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - public function addField($field){ |
|
| 151 | + public function addField($field) { |
|
| 152 | 152 | $this->visibleProperties[]=$field; |
| 153 | 153 | return $this; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - public function addFields($fields){ |
|
| 157 | - $this->visibleProperties=\array_merge($this->visibleProperties,$fields); |
|
| 156 | + public function addFields($fields) { |
|
| 157 | + $this->visibleProperties=\array_merge($this->visibleProperties, $fields); |
|
| 158 | 158 | return $this; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | - public function count(){ |
|
| 161 | + public function count() { |
|
| 162 | 162 | return \sizeof($this->properties); |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - public function visiblePropertiesCount(){ |
|
| 165 | + public function visiblePropertiesCount() { |
|
| 166 | 166 | return \sizeof($this->visibleProperties); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - public function getProperty($index){ |
|
| 169 | + public function getProperty($index) { |
|
| 170 | 170 | return $this->properties[$index]; |
| 171 | 171 | } |
| 172 | 172 | |
| 173 | - public function getFieldName($index){ |
|
| 173 | + public function getFieldName($index) { |
|
| 174 | 174 | $property=$this->getProperty($index); |
| 175 | - if($property instanceof \ReflectionProperty){ |
|
| 175 | + if ($property instanceof \ReflectionProperty) { |
|
| 176 | 176 | $result=$property->getName(); |
| 177 | - }elseif(\is_callable($property)){ |
|
| 177 | + }elseif (\is_callable($property)) { |
|
| 178 | 178 | $result=$this->visibleProperties[$index]; |
| 179 | - }else{ |
|
| 179 | + } else { |
|
| 180 | 180 | $result=$property; |
| 181 | 181 | } |
| 182 | 182 | return $result; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
| 186 | - protected function showableProperty(\ReflectionProperty $rProperty){ |
|
| 187 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
| 186 | + protected function showableProperty(\ReflectionProperty $rProperty) { |
|
| 187 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | public function setInstance($instance) { |
| 191 | - if(\is_string($instance)){ |
|
| 191 | + if (\is_string($instance)) { |
|
| 192 | 192 | $instance=new $instance(); |
| 193 | 193 | } |
| 194 | 194 | $this->instance=$instance; |
| 195 | 195 | $this->properties=[]; |
| 196 | 196 | $this->reflect=new \ReflectionClass($instance); |
| 197 | - if(\sizeof($this->visibleProperties)===0){ |
|
| 197 | + if (\sizeof($this->visibleProperties)===0) { |
|
| 198 | 198 | $this->properties=$this->getDefaultProperties(); |
| 199 | - }else{ |
|
| 200 | - foreach ($this->visibleProperties as $property){ |
|
| 199 | + } else { |
|
| 200 | + foreach ($this->visibleProperties as $property) { |
|
| 201 | 201 | $this->setInstanceProperty($property); |
| 202 | 202 | } |
| 203 | 203 | } |
| 204 | 204 | return $this; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - private function setInstanceProperty($property){ |
|
| 208 | - if(\is_callable($property)){ |
|
| 207 | + private function setInstanceProperty($property) { |
|
| 208 | + if (\is_callable($property)) { |
|
| 209 | 209 | $this->properties[]=$property; |
| 210 | - }elseif(\is_string($property)){ |
|
| 211 | - try{ |
|
| 210 | + }elseif (\is_string($property)) { |
|
| 211 | + try { |
|
| 212 | 212 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 213 | 213 | $rProperty=$this->reflect->getProperty($property); |
| 214 | 214 | $this->properties[]=$rProperty; |
| 215 | - }catch(\Exception $e){ |
|
| 215 | + }catch (\Exception $e) { |
|
| 216 | 216 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 217 | 217 | $this->properties[]=$property; |
| 218 | 218 | } |
| 219 | - }elseif(\is_int($property)){ |
|
| 219 | + }elseif (\is_int($property)) { |
|
| 220 | 220 | $props=$this->getDefaultProperties(); |
| 221 | - if(isset($props[$property])) |
|
| 221 | + if (isset($props[$property])) |
|
| 222 | 222 | $this->properties[]=$props[$property]; |
| 223 | 223 | else |
| 224 | 224 | $this->properties[]=$property; |
| 225 | - }else{ |
|
| 225 | + } else { |
|
| 226 | 226 | $this->properties[]=$property; |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - protected function getDefaultProperties(){ |
|
| 230 | + protected function getDefaultProperties() { |
|
| 231 | 231 | $result=[]; |
| 232 | 232 | $properties=$this->reflect->getProperties(); |
| 233 | - foreach ($properties as $property){ |
|
| 233 | + foreach ($properties as $property) { |
|
| 234 | 234 | $showable=$this->showableProperty($property); |
| 235 | - if($showable!==false){ |
|
| 235 | + if ($showable!==false) { |
|
| 236 | 236 | $result[]=$property; |
| 237 | 237 | } |
| 238 | 238 | } |
@@ -244,12 +244,12 @@ discard block |
||
| 244 | 244 | return $this; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - public function setValueFunction($index,$callback){ |
|
| 247 | + public function setValueFunction($index, $callback) { |
|
| 248 | 248 | $this->values[$index]=$callback; |
| 249 | 249 | return $this; |
| 250 | 250 | } |
| 251 | 251 | |
| 252 | - public function setIdentifierFunction($callback){ |
|
| 252 | + public function setIdentifierFunction($callback) { |
|
| 253 | 253 | $this->values["identifier"]=$callback; |
| 254 | 254 | return $this; |
| 255 | 255 | } |
@@ -262,42 +262,42 @@ discard block |
||
| 262 | 262 | return $this->properties; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - public function getCaption($index){ |
|
| 266 | - if(isset($this->captions[$index])){ |
|
| 265 | + public function getCaption($index) { |
|
| 266 | + if (isset($this->captions[$index])) { |
|
| 267 | 267 | return $this->captions[$index]; |
| 268 | 268 | } |
| 269 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
| 269 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
| 270 | 270 | return $this->properties[$index]->getName(); |
| 271 | - elseif(\is_callable($this->properties[$index])) |
|
| 271 | + elseif (\is_callable($this->properties[$index])) |
|
| 272 | 272 | return ""; |
| 273 | 273 | else |
| 274 | 274 | return $this->properties[$index]; |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - public function getCaptions(){ |
|
| 277 | + public function getCaptions() { |
|
| 278 | 278 | $count=$this->count(); |
| 279 | - if(isset($this->captions)){ |
|
| 280 | - $captions= \array_values($this->captions); |
|
| 279 | + if (isset($this->captions)) { |
|
| 280 | + $captions=\array_values($this->captions); |
|
| 281 | 281 | $captionsSize=\sizeof($captions); |
| 282 | - for($i=$captionsSize;$i<$count;$i++){ |
|
| 282 | + for ($i=$captionsSize; $i<$count; $i++) { |
|
| 283 | 283 | $captions[]=""; |
| 284 | 284 | } |
| 285 | - }else{ |
|
| 285 | + } else { |
|
| 286 | 286 | $captions=[]; |
| 287 | 287 | $index=0; |
| 288 | - while($index<$count){ |
|
| 288 | + while ($index<$count) { |
|
| 289 | 289 | $captions[]=$this->getCaption($index++); |
| 290 | 290 | } |
| 291 | 291 | } |
| 292 | - if(isset($this->captionCallback) && \is_callable($this->captionCallback)){ |
|
| 292 | + if (isset($this->captionCallback) && \is_callable($this->captionCallback)) { |
|
| 293 | 293 | $callback=$this->captionCallback; |
| 294 | - $callback($captions,$this->instance); |
|
| 294 | + $callback($captions, $this->instance); |
|
| 295 | 295 | } |
| 296 | 296 | return $captions; |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - public function setCaption($index,$caption){ |
|
| 300 | - if(isset($this->captions)===false) |
|
| 299 | + public function setCaption($index, $caption) { |
|
| 300 | + if (isset($this->captions)===false) |
|
| 301 | 301 | $this->captions=[]; |
| 302 | 302 | $this->captions[$index]=$caption; |
| 303 | 303 | return $this; |
@@ -315,7 +315,7 @@ discard block |
||
| 315 | 315 | * @param callable $callback function called after the field compilation |
| 316 | 316 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
| 317 | 317 | */ |
| 318 | - public function afterCompile($index,$callback){ |
|
| 318 | + public function afterCompile($index, $callback) { |
|
| 319 | 319 | $this->afterCompile[$index]=$callback; |
| 320 | 320 | return $this; |
| 321 | 321 | } |