@@ -18,27 +18,27 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | public function __construct(JsUtils $js=NULL) { |
| 20 | 20 | parent::__construct($js); |
| 21 | - $this->events=array (); |
|
| 21 | + $this->events=array(); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | protected function compileEvents() { |
| 25 | - foreach ( $this->events as $event => $jsCode ) { |
|
| 25 | + foreach ($this->events as $event => $jsCode) { |
|
| 26 | 26 | $itemSelector=JString::getValueBetween($event); |
| 27 | - if($event=="execute"){ |
|
| 27 | + if ($event=="execute") { |
|
| 28 | 28 | $this->jquery_code_for_compile []=$jsCode; |
| 29 | - }else if($event=="beforeExecute"){ |
|
| 29 | + } else if ($event=="beforeExecute") { |
|
| 30 | 30 | \array_unshift($this->jquery_code_for_compile, $jsCode); |
| 31 | - }else{ |
|
| 31 | + } else { |
|
| 32 | 32 | $selector=$this->_createSelector($itemSelector, $this->attachTo); |
| 33 | 33 | $this->jquery_code_for_compile []="$( \"".$selector."\" ).on(\"".$event."\" , function( event, data ) {".$jsCode."});"; |
| 34 | 34 | } |
| 35 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - protected function _createSelector($itemSelector,$selector){ |
|
| 39 | - if(!isset($itemSelector)) |
|
| 38 | + protected function _createSelector($itemSelector, $selector) { |
|
| 39 | + if (!isset($itemSelector)) |
|
| 40 | 40 | $itemSelector=$this->itemSelector; |
| 41 | - if(isset($itemSelector) && $itemSelector!=="") |
|
| 41 | + if (isset($itemSelector) && $itemSelector!=="") |
|
| 42 | 42 | $selector.=" ".$itemSelector; |
| 43 | 43 | return $selector; |
| 44 | 44 | } |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | $result=implode("\n", $this->jquery_code_for_compile); |
| 48 | 48 | $result=str_ireplace("\"%", "", $result); |
| 49 | 49 | $result=str_ireplace("%\"", "", $result); |
| 50 | - $result=str_replace(array ( |
|
| 50 | + $result=str_replace(array( |
|
| 51 | 51 | "\\n", |
| 52 | 52 | "\\r", |
| 53 | 53 | "\\t" |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | public function getScript() { |
| 59 | 59 | $allParams=$this->params; |
| 60 | - $this->jquery_code_for_compile=array (); |
|
| 60 | + $this->jquery_code_for_compile=array(); |
|
| 61 | 61 | $this->jquery_code_for_compile []="$( \"".$this->attachTo."\" ).{$this->uiName}(".$this->getParamsAsJSON($allParams).");"; |
| 62 | 62 | $this->compileEvents(); |
| 63 | 63 | return $this->compileJQueryCode(); |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | $itemSelector=JString::getValueBetween($event); |
| 27 | 27 | if($event=="execute"){ |
| 28 | 28 | $this->jquery_code_for_compile []=$jsCode; |
| 29 | - }else if($event=="beforeExecute"){ |
|
| 29 | + } else if($event=="beforeExecute"){ |
|
| 30 | 30 | \array_unshift($this->jquery_code_for_compile, $jsCode); |
| 31 | - }else{ |
|
| 31 | + } else{ |
|
| 32 | 32 | $selector=$this->_createSelector($itemSelector, $this->attachTo); |
| 33 | 33 | $this->jquery_code_for_compile []="$( \"".$selector."\" ).on(\"".$event."\" , function( event, data ) {".$jsCode."});"; |
| 34 | 34 | } |
@@ -36,10 +36,12 @@ discard block |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | protected function _createSelector($itemSelector,$selector){ |
| 39 | - if(!isset($itemSelector)) |
|
| 40 | - $itemSelector=$this->itemSelector; |
|
| 41 | - if(isset($itemSelector) && $itemSelector!=="") |
|
| 42 | - $selector.=" ".$itemSelector; |
|
| 39 | + if(!isset($itemSelector)) { |
|
| 40 | + $itemSelector=$this->itemSelector; |
|
| 41 | + } |
|
| 42 | + if(isset($itemSelector) && $itemSelector!=="") { |
|
| 43 | + $selector.=" ".$itemSelector; |
|
| 44 | + } |
|
| 43 | 45 | return $selector; |
| 44 | 46 | } |
| 45 | 47 | |
@@ -82,8 +84,9 @@ discard block |
||
| 82 | 84 | |
| 83 | 85 | protected function setParamCtrl($key, $value, $typeCtrl) { |
| 84 | 86 | if (\is_array($typeCtrl)) { |
| 85 | - if (array_search($value, $typeCtrl)===false) |
|
| 86 | - throw new \Exception("La valeur passée a propriété `".$key."` pour le composant `".$this->uiName."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
| 87 | + if (array_search($value, $typeCtrl)===false) { |
|
| 88 | + throw new \Exception("La valeur passée a propriété `".$key."` pour le composant `".$this->uiName."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
| 89 | + } |
|
| 87 | 90 | } else { |
| 88 | 91 | if (!$typeCtrl($value)) { |
| 89 | 92 | throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$key." au composant ".$this->uiName); |
@@ -23,8 +23,9 @@ discard block |
||
| 23 | 23 | $this->widgetIdentifier=$identifier; |
| 24 | 24 | $this->values=[]; |
| 25 | 25 | $this->afterCompile=[]; |
| 26 | - if(isset($instance)) |
|
| 27 | - $this->setInstance($instance); |
|
| 26 | + if(isset($instance)) { |
|
| 27 | + $this->setInstance($instance); |
|
| 28 | + } |
|
| 28 | 29 | $this->setCaptions($captions); |
| 29 | 30 | $this->captionCallback=NULL; |
| 30 | 31 | $this->defaultValueFunction=function($name,$value){return $value;}; |
@@ -62,14 +63,16 @@ discard block |
||
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | public function getIdentifier($index=NULL){ |
| 65 | - if(!isset($index)) |
|
| 66 | - $index=self::$index; |
|
| 66 | + if(!isset($index)) { |
|
| 67 | + $index=self::$index; |
|
| 68 | + } |
|
| 67 | 69 | $value=$index; |
| 68 | 70 | if(isset($this->values["identifier"])){ |
| 69 | - if(\is_string($this->values["identifier"])) |
|
| 70 | - $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
|
| 71 | - else |
|
| 72 | - $value=$this->values["identifier"]($index,$this->instance); |
|
| 71 | + if(\is_string($this->values["identifier"])) { |
|
| 72 | + $value=JReflection::callMethod($this->instance, $this->values["identifier"], []); |
|
| 73 | + } else { |
|
| 74 | + $value=$this->values["identifier"]($index,$this->instance); |
|
| 75 | + } |
|
| 73 | 76 | } |
| 74 | 77 | return $value; |
| 75 | 78 | } |
@@ -99,16 +102,16 @@ discard block |
||
| 99 | 102 | if($property instanceof \ReflectionProperty){ |
| 100 | 103 | $value=$this->_getPropertyValue($property, $index); |
| 101 | 104 | $propertyName=$property->getName(); |
| 102 | - }elseif(\is_callable($property)) |
|
| 103 | - $value=$property($this->instance); |
|
| 104 | - elseif(\is_array($property)){ |
|
| 105 | + } elseif(\is_callable($property)) { |
|
| 106 | + $value=$property($this->instance); |
|
| 107 | + } elseif(\is_array($property)){ |
|
| 105 | 108 | $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
| 106 | 109 | $value=\implode("", $values); |
| 107 | - }elseif(\is_string($property)){ |
|
| 110 | + } elseif(\is_string($property)){ |
|
| 108 | 111 | $value=$property; |
| 109 | 112 | if(isset($this->instance->{$property})){ |
| 110 | 113 | $value=$this->instance->{$property}; |
| 111 | - }elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
| 114 | + } elseif(\method_exists($this->instance, $getter=JReflection::getterName($property))){ |
|
| 112 | 115 | $value=JReflection::callMethod($this->instance, $getter, []); |
| 113 | 116 | } |
| 114 | 117 | } |
@@ -118,7 +121,7 @@ discard block |
||
| 118 | 121 | protected function _postGetValue($index,$propertyName,$value){ |
| 119 | 122 | if(isset($this->values[$index])){ |
| 120 | 123 | $value= $this->values[$index]($value,$this->instance,$index); |
| 121 | - }else{ |
|
| 124 | + } else{ |
|
| 122 | 125 | $value=$this->_getDefaultValue($propertyName,$value, $index); |
| 123 | 126 | } |
| 124 | 127 | if(isset($this->afterCompile[$index])){ |
@@ -139,10 +142,10 @@ discard block |
||
| 139 | 142 | if(isset($vb[$index])){ |
| 140 | 143 | if(\is_array($vb[$index])){ |
| 141 | 144 | $this->visibleProperties[$index][]=$field; |
| 142 | - }else{ |
|
| 145 | + } else{ |
|
| 143 | 146 | $this->visibleProperties[$index]=[$vb[$index],$field]; |
| 144 | 147 | } |
| 145 | - }else{ |
|
| 148 | + } else{ |
|
| 146 | 149 | return $this->insertField($index, $field); |
| 147 | 150 | } |
| 148 | 151 | return $this; |
@@ -169,9 +172,9 @@ discard block |
||
| 169 | 172 | $property=$this->getProperty($index); |
| 170 | 173 | if($property instanceof \ReflectionProperty){ |
| 171 | 174 | $result=$property->getName(); |
| 172 | - }elseif(\is_callable($property)){ |
|
| 175 | + } elseif(\is_callable($property)){ |
|
| 173 | 176 | $result=$this->visibleProperties[$index]; |
| 174 | - }else{ |
|
| 177 | + } else{ |
|
| 175 | 178 | $result=$property; |
| 176 | 179 | } |
| 177 | 180 | return $result; |
@@ -191,7 +194,7 @@ discard block |
||
| 191 | 194 | $this->reflect=new \ReflectionClass($instance); |
| 192 | 195 | if(\sizeof($this->visibleProperties)===0){ |
| 193 | 196 | $this->properties=$this->getDefaultProperties(); |
| 194 | - }else{ |
|
| 197 | + } else{ |
|
| 195 | 198 | foreach ($this->visibleProperties as $property){ |
| 196 | 199 | $this->setInstanceProperty($property); |
| 197 | 200 | } |
@@ -202,22 +205,23 @@ discard block |
||
| 202 | 205 | private function setInstanceProperty($property){ |
| 203 | 206 | if(\is_callable($property)){ |
| 204 | 207 | $this->properties[]=$property; |
| 205 | - }elseif(\is_string($property)){ |
|
| 208 | + } elseif(\is_string($property)){ |
|
| 206 | 209 | try{ |
| 207 | 210 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 208 | 211 | $rProperty=$this->reflect->getProperty($property); |
| 209 | 212 | $this->properties[]=$rProperty; |
| 210 | - }catch(\Exception $e){ |
|
| 213 | + } catch(\Exception $e){ |
|
| 211 | 214 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
| 212 | 215 | $this->properties[]=$property; |
| 213 | 216 | } |
| 214 | - }elseif(\is_int($property)){ |
|
| 217 | + } elseif(\is_int($property)){ |
|
| 215 | 218 | $props=$this->getDefaultProperties(); |
| 216 | - if(isset($props[$property])) |
|
| 217 | - $this->properties[]=$props[$property]; |
|
| 218 | - else |
|
| 219 | - $this->properties[]=$property; |
|
| 220 | - }else{ |
|
| 219 | + if(isset($props[$property])) { |
|
| 220 | + $this->properties[]=$props[$property]; |
|
| 221 | + } else { |
|
| 222 | + $this->properties[]=$property; |
|
| 223 | + } |
|
| 224 | + } else{ |
|
| 221 | 225 | $this->properties[]=$property; |
| 222 | 226 | } |
| 223 | 227 | } |
@@ -261,12 +265,13 @@ discard block |
||
| 261 | 265 | if(isset($this->captions[$index])){ |
| 262 | 266 | return $this->captions[$index]; |
| 263 | 267 | } |
| 264 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
| 265 | - return $this->properties[$index]->getName(); |
|
| 266 | - elseif(\is_callable($this->properties[$index])) |
|
| 267 | - return ""; |
|
| 268 | - else |
|
| 269 | - return $this->properties[$index]; |
|
| 268 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
| 269 | + return $this->properties[$index]->getName(); |
|
| 270 | + } elseif(\is_callable($this->properties[$index])) { |
|
| 271 | + return ""; |
|
| 272 | + } else { |
|
| 273 | + return $this->properties[$index]; |
|
| 274 | + } |
|
| 270 | 275 | } |
| 271 | 276 | |
| 272 | 277 | public function getCaptions(){ |
@@ -277,7 +282,7 @@ discard block |
||
| 277 | 282 | for($i=$captionsSize;$i<$count;$i++){ |
| 278 | 283 | $captions[]=""; |
| 279 | 284 | } |
| 280 | - }else{ |
|
| 285 | + } else{ |
|
| 281 | 286 | $captions=[]; |
| 282 | 287 | $index=0; |
| 283 | 288 | while($index<$count){ |
@@ -292,8 +297,9 @@ discard block |
||
| 292 | 297 | } |
| 293 | 298 | |
| 294 | 299 | public function setCaption($index,$caption){ |
| 295 | - if(isset($this->captions)===false) |
|
| 296 | - $this->captions=[]; |
|
| 300 | + if(isset($this->captions)===false) { |
|
| 301 | + $this->captions=[]; |
|
| 302 | + } |
|
| 297 | 303 | $this->captions[$index]=$caption; |
| 298 | 304 | return $this; |
| 299 | 305 | } |
@@ -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 | } |
@@ -244,6 +244,9 @@ discard block |
||
| 244 | 244 | return $this; |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | + /** |
|
| 248 | + * @param callable $callback |
|
| 249 | + */ |
|
| 247 | 250 | public function setValueFunction($index,$callback){ |
| 248 | 251 | $this->values[$index]=$callback; |
| 249 | 252 | return $this; |
@@ -254,6 +257,9 @@ discard block |
||
| 254 | 257 | return $this; |
| 255 | 258 | } |
| 256 | 259 | |
| 260 | + /** |
|
| 261 | + * @param integer $index |
|
| 262 | + */ |
|
| 257 | 263 | public static function setIndex($index) { |
| 258 | 264 | self::$index=$index; |
| 259 | 265 | } |
@@ -313,7 +319,7 @@ discard block |
||
| 313 | 319 | * The $callback function can take the following arguments : $field=>the compiled field, $instance : the active instance of the object, $index: the field position |
| 314 | 320 | * @param int $index postion of the compiled field |
| 315 | 321 | * @param callable $callback function called after the field compilation |
| 316 | - * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
|
| 322 | + * @return InstanceViewer |
|
| 317 | 323 | */ |
| 318 | 324 | public function afterCompile($index,$callback){ |
| 319 | 325 | $this->afterCompile[$index]=$callback; |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | return $this->setParam("context", $value); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | - public function setOffset($offset=0){ |
|
| 24 | + public function setOffset($offset=0) { |
|
| 25 | 25 | return $this->setParam("offset", $offset); |
| 26 | 26 | } |
| 27 | 27 | } |
@@ -20,7 +20,7 @@ |
||
| 20 | 20 | $this->params["onUnchecked"]="%function(){".$value."}%"; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | - public function setOnChange($value){ |
|
| 23 | + public function setOnChange($value) { |
|
| 24 | 24 | $this->params["onChange"]="%function(){".$value."}%"; |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -8,16 +8,16 @@ |
||
| 8 | 8 | class HtmlFormInput extends HtmlFormField { |
| 9 | 9 | use TextFieldsTrait; |
| 10 | 10 | |
| 11 | - public function __construct($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL) { |
|
| 12 | - if(!isset($placeholder) && $type==="text") |
|
| 11 | + public function __construct($identifier, $label=NULL, $type="text", $value=NULL, $placeholder=NULL) { |
|
| 12 | + if (!isset($placeholder) && $type==="text") |
|
| 13 | 13 | $placeholder=$label; |
| 14 | - parent::__construct("field-".$identifier, new HtmlInput($identifier,$type,$value,$placeholder), $label); |
|
| 14 | + parent::__construct("field-".$identifier, new HtmlInput($identifier, $type, $value, $placeholder), $label); |
|
| 15 | 15 | $this->_identifier=$identifier; |
| 16 | 16 | } |
| 17 | 17 | |
| 18 | - public function getDataField(){ |
|
| 19 | - $field= $this->getField(); |
|
| 20 | - if($field instanceof HtmlInput) |
|
| 18 | + public function getDataField() { |
|
| 19 | + $field=$this->getField(); |
|
| 20 | + if ($field instanceof HtmlInput) |
|
| 21 | 21 | $field=$field->getDataField(); |
| 22 | 22 | return $field; |
| 23 | 23 | } |
@@ -9,16 +9,18 @@ |
||
| 9 | 9 | use TextFieldsTrait; |
| 10 | 10 | |
| 11 | 11 | public function __construct($identifier, $label=NULL,$type="text",$value=NULL,$placeholder=NULL) { |
| 12 | - if(!isset($placeholder) && $type==="text") |
|
| 13 | - $placeholder=$label; |
|
| 12 | + if(!isset($placeholder) && $type==="text") { |
|
| 13 | + $placeholder=$label; |
|
| 14 | + } |
|
| 14 | 15 | parent::__construct("field-".$identifier, new HtmlInput($identifier,$type,$value,$placeholder), $label); |
| 15 | 16 | $this->_identifier=$identifier; |
| 16 | 17 | } |
| 17 | 18 | |
| 18 | 19 | public function getDataField(){ |
| 19 | 20 | $field= $this->getField(); |
| 20 | - if($field instanceof HtmlInput) |
|
| 21 | - $field=$field->getDataField(); |
|
| 21 | + if($field instanceof HtmlInput) { |
|
| 22 | + $field=$field->getDataField(); |
|
| 23 | + } |
|
| 22 | 24 | return $field; |
| 23 | 25 | } |
| 24 | 26 | } |
@@ -63,6 +63,10 @@ discard block |
||
| 63 | 63 | |
| 64 | 64 | |
| 65 | 65 | |
| 66 | + /** |
|
| 67 | + * @param string $name |
|
| 68 | + * @param string[] $typeCtrl |
|
| 69 | + */ |
|
| 66 | 70 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 67 | 71 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
| 68 | 72 | return $name=$value; |
@@ -80,6 +84,10 @@ discard block |
||
| 80 | 84 | |
| 81 | 85 | |
| 82 | 86 | |
| 87 | + /** |
|
| 88 | + * @param string $name |
|
| 89 | + * @param string[] $typeCtrl |
|
| 90 | + */ |
|
| 83 | 91 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 84 | 92 | if ($this->ctrl($name, $value, $typeCtrl) === true) { |
| 85 | 93 | if (\is_array($typeCtrl)) { |
@@ -90,6 +98,9 @@ discard block |
||
| 90 | 98 | return $this; |
| 91 | 99 | } |
| 92 | 100 | |
| 101 | + /** |
|
| 102 | + * @param string $name |
|
| 103 | + */ |
|
| 93 | 104 | protected function addToMember(&$name, $value, $separator=" ") { |
| 94 | 105 | $name=str_ireplace($value, "", $name) . $separator . $value; |
| 95 | 106 | return $this; |
@@ -102,6 +113,9 @@ discard block |
||
| 102 | 113 | $oldValue=trim($oldValue); |
| 103 | 114 | } |
| 104 | 115 | |
| 116 | + /** |
|
| 117 | + * @param \Closure $callback |
|
| 118 | + */ |
|
| 105 | 119 | protected function _getElementBy($callback,$elements){ |
| 106 | 120 | if (\is_array($elements)) { |
| 107 | 121 | $elements=\array_values($elements); |
@@ -183,6 +197,9 @@ discard block |
||
| 183 | 197 | return $this->_bsComponent; |
| 184 | 198 | } |
| 185 | 199 | |
| 200 | + /** |
|
| 201 | + * @param \Ajax\semantic\components\Form $bsComponent |
|
| 202 | + */ |
|
| 186 | 203 | public function setBsComponent($bsComponent) { |
| 187 | 204 | $this->_bsComponent=$bsComponent; |
| 188 | 205 | return $this; |
@@ -14,11 +14,11 @@ discard block |
||
| 14 | 14 | * @version 1.3 |
| 15 | 15 | */ |
| 16 | 16 | abstract class BaseHtml extends BaseWidget { |
| 17 | - use BaseHtmlEventsTrait,BaseHtmlPropertiesTrait; |
|
| 17 | + use BaseHtmlEventsTrait, BaseHtmlPropertiesTrait; |
|
| 18 | 18 | protected $_template; |
| 19 | 19 | protected $tagName; |
| 20 | - protected $_wrapBefore=array (); |
|
| 21 | - protected $_wrapAfter=array (); |
|
| 20 | + protected $_wrapBefore=array(); |
|
| 21 | + protected $_wrapAfter=array(); |
|
| 22 | 22 | protected $_bsComponent; |
| 23 | 23 | protected $_compiled=false; |
| 24 | 24 | protected $_postCompile; |
@@ -31,14 +31,14 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | abstract public function run(JsUtils $js); |
| 33 | 33 | |
| 34 | - private function _callSetter($setter,$key,$value,&$array){ |
|
| 34 | + private function _callSetter($setter, $key, $value, &$array) { |
|
| 35 | 35 | $result=false; |
| 36 | - if (method_exists($this, $setter) && substr($setter, 0, 1) !== "_") { |
|
| 36 | + if (method_exists($this, $setter) && substr($setter, 0, 1)!=="_") { |
|
| 37 | 37 | try { |
| 38 | 38 | $this->$setter($value); |
| 39 | 39 | unset($array[$key]); |
| 40 | 40 | $result=true; |
| 41 | - } catch ( \Exception $e ) { |
|
| 41 | + }catch (\Exception $e) { |
|
| 42 | 42 | $result=false; |
| 43 | 43 | } |
| 44 | 44 | } |
@@ -46,17 +46,17 @@ discard block |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | protected function getTemplate(JsUtils $js=NULL) { |
| 49 | - return PropertyWrapper::wrap($this->_wrapBefore, $js) . $this->_template . PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 49 | + return PropertyWrapper::wrap($this->_wrapBefore, $js).$this->_template.PropertyWrapper::wrap($this->_wrapAfter, $js); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | protected function ctrl($name, $value, $typeCtrl) { |
| 53 | 53 | if (\is_array($typeCtrl)) { |
| 54 | - if (array_search($value, $typeCtrl) === false) { |
|
| 55 | - throw new \Exception("La valeur passée `" . $value . "` à la propriété `" . $name . "` ne fait pas partie des valeurs possibles : {" . implode(",", $typeCtrl) . "}"); |
|
| 54 | + if (array_search($value, $typeCtrl)===false) { |
|
| 55 | + throw new \Exception("La valeur passée `".$value."` à la propriété `".$name."` ne fait pas partie des valeurs possibles : {".implode(",", $typeCtrl)."}"); |
|
| 56 | 56 | } |
| 57 | 57 | } else { |
| 58 | 58 | if (!$typeCtrl($value)) { |
| 59 | - throw new \Exception("La fonction " . $typeCtrl . " a retourné faux pour l'affectation de la propriété " . $name); |
|
| 59 | + throw new \Exception("La fonction ".$typeCtrl." a retourné faux pour l'affectation de la propriété ".$name); |
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | return true; |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | |
| 66 | 66 | |
| 67 | 67 | protected function setMemberCtrl(&$name, $value, $typeCtrl) { |
| 68 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 68 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 69 | 69 | return $name=$value; |
| 70 | 70 | } |
| 71 | 71 | return $this; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | protected function addToMemberUnique(&$name, $value, $typeCtrl, $separator=" ") { |
| 75 | 75 | if (\is_array($typeCtrl)) { |
| 76 | 76 | $this->removeOldValues($name, $typeCtrl); |
| 77 | - $name.=$separator . $value; |
|
| 77 | + $name.=$separator.$value; |
|
| 78 | 78 | } |
| 79 | 79 | return $this; |
| 80 | 80 | } |
@@ -82,17 +82,17 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | |
| 84 | 84 | protected function addToMemberCtrl(&$name, $value, $typeCtrl, $separator=" ") { |
| 85 | - if ($this->ctrl($name, $value, $typeCtrl) === true) { |
|
| 85 | + if ($this->ctrl($name, $value, $typeCtrl)===true) { |
|
| 86 | 86 | if (\is_array($typeCtrl)) { |
| 87 | 87 | $this->removeOldValues($name, $typeCtrl); |
| 88 | 88 | } |
| 89 | - $name.=$separator . $value; |
|
| 89 | + $name.=$separator.$value; |
|
| 90 | 90 | } |
| 91 | 91 | return $this; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | protected function addToMember(&$name, $value, $separator=" ") { |
| 95 | - $name=str_ireplace($value, "", $name) . $separator . $value; |
|
| 95 | + $name=str_ireplace($value, "", $name).$separator.$value; |
|
| 96 | 96 | return $this; |
| 97 | 97 | } |
| 98 | 98 | |
@@ -103,18 +103,18 @@ discard block |
||
| 103 | 103 | $oldValue=trim($oldValue); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - protected function _getElementBy($callback,$elements){ |
|
| 106 | + protected function _getElementBy($callback, $elements) { |
|
| 107 | 107 | if (\is_array($elements)) { |
| 108 | 108 | $elements=\array_values($elements); |
| 109 | 109 | $flag=false; |
| 110 | 110 | $index=0; |
| 111 | - while ( !$flag && $index < sizeof($elements) ) { |
|
| 111 | + while (!$flag && $index<sizeof($elements)) { |
|
| 112 | 112 | if ($elements[$index] instanceof BaseHtml) |
| 113 | 113 | $flag=($callback($elements[$index])); |
| 114 | 114 | $index++; |
| 115 | 115 | } |
| 116 | - if ($flag === true) |
|
| 117 | - return $elements[$index - 1]; |
|
| 116 | + if ($flag===true) |
|
| 117 | + return $elements[$index-1]; |
|
| 118 | 118 | } elseif ($elements instanceof BaseHtml) { |
| 119 | 119 | if ($callback($elements)) |
| 120 | 120 | return $elements; |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | public function fromArray($array) { |
| 145 | - foreach ( $this as $key => $value ) { |
|
| 146 | - if(array_key_exists($key, $array)===true) |
|
| 147 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 145 | + foreach ($this as $key => $value) { |
|
| 146 | + if (array_key_exists($key, $array)===true) |
|
| 147 | + $this->_callSetter("set".ucfirst($key), $key, $array[$key], $array); |
|
| 148 | 148 | } |
| 149 | - foreach ( $array as $key => $value ) { |
|
| 150 | - if($this->_callSetter($key, $key, $value, $array)===false){ |
|
| 151 | - $this->_callSetter("set" . ucfirst($key), $key, $value, $array); |
|
| 149 | + foreach ($array as $key => $value) { |
|
| 150 | + if ($this->_callSetter($key, $key, $value, $array)===false) { |
|
| 151 | + $this->_callSetter("set".ucfirst($key), $key, $value, $array); |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | return $array; |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | |
| 157 | 157 | public function fromDatabaseObjects($objects, $function) { |
| 158 | 158 | if (isset($objects)) { |
| 159 | - foreach ( $objects as $object ) { |
|
| 159 | + foreach ($objects as $object) { |
|
| 160 | 160 | $this->fromDatabaseObject($object, $function); |
| 161 | 161 | } |
| 162 | 162 | } |
@@ -177,7 +177,7 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | |
| 179 | 179 | public function getElementById($identifier, $elements) { |
| 180 | - return $this->_getElementBy(function(BaseWidget $element) use ($identifier){return $element->getIdentifier()===$identifier;}, $elements); |
|
| 180 | + return $this->_getElementBy(function(BaseWidget $element) use ($identifier){return $element->getIdentifier()===$identifier; }, $elements); |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | public function getBsComponent() { |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | protected function compile_once(JsUtils $js=NULL, &$view=NULL) { |
| 193 | - if(!$this->_compiled){ |
|
| 194 | - if(isset($js)){ |
|
| 193 | + if (!$this->_compiled) { |
|
| 194 | + if (isset($js)) { |
|
| 195 | 195 | $beforeCompile=$js->getParam("beforeCompileHtml"); |
| 196 | - if(\is_callable($beforeCompile)){ |
|
| 197 | - $beforeCompile($this,$js,$view); |
|
| 196 | + if (\is_callable($beforeCompile)) { |
|
| 197 | + $beforeCompile($this, $js, $view); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | - if(\is_callable($this->_preCompile)){ |
|
| 200 | + if (\is_callable($this->_preCompile)) { |
|
| 201 | 201 | $pc=$this->_preCompile; |
| 202 | 202 | $pc($this); |
| 203 | 203 | } |
@@ -207,15 +207,15 @@ 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(\strstr($result, "%{$key}%")!==false){ |
|
| 212 | + foreach ($this as $key => $value) { |
|
| 213 | + if (\strstr($result, "%{$key}%")!==false) { |
|
| 214 | 214 | if (\is_array($value)) { |
| 215 | 215 | $v=PropertyWrapper::wrap($value, $js); |
| 216 | - }elseif($value instanceof \stdClass){ |
|
| 217 | - $v=\print_r($value,true); |
|
| 218 | - }else{ |
|
| 216 | + }elseif ($value instanceof \stdClass) { |
|
| 217 | + $v=\print_r($value, true); |
|
| 218 | + } else { |
|
| 219 | 219 | $v=$value; |
| 220 | 220 | } |
| 221 | 221 | $result=str_replace("%{$key}%", $v, $result); |
@@ -223,12 +223,12 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | if (isset($js)===true) { |
| 225 | 225 | $this->run($js); |
| 226 | - if (isset($view) === true) { |
|
| 226 | + if (isset($view)===true) { |
|
| 227 | 227 | $js->addViewElement($this->_identifier, $result, $view); |
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - if(\is_callable($this->_postCompile)){ |
|
| 231 | + if (\is_callable($this->_postCompile)) { |
|
| 232 | 232 | $pc=$this->_postCompile; |
| 233 | 233 | $pc($this); |
| 234 | 234 | } |
@@ -239,11 +239,11 @@ discard block |
||
| 239 | 239 | return $this->compile(); |
| 240 | 240 | } |
| 241 | 241 | |
| 242 | - public function onPostCompile($callback){ |
|
| 242 | + public function onPostCompile($callback) { |
|
| 243 | 243 | $this->_postCompile=$callback; |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - public function onPreCompile($callback){ |
|
| 246 | + public function onPreCompile($callback) { |
|
| 247 | 247 | $this->_preCompile=$callback; |
| 248 | 248 | } |
| 249 | 249 | } |
@@ -109,15 +109,18 @@ discard block |
||
| 109 | 109 | $flag=false; |
| 110 | 110 | $index=0; |
| 111 | 111 | while ( !$flag && $index < sizeof($elements) ) { |
| 112 | - if ($elements[$index] instanceof BaseHtml) |
|
| 113 | - $flag=($callback($elements[$index])); |
|
| 112 | + if ($elements[$index] instanceof BaseHtml) { |
|
| 113 | + $flag=($callback($elements[$index])); |
|
| 114 | + } |
|
| 114 | 115 | $index++; |
| 115 | 116 | } |
| 116 | - if ($flag === true) |
|
| 117 | - return $elements[$index - 1]; |
|
| 117 | + if ($flag === true) { |
|
| 118 | + return $elements[$index - 1]; |
|
| 119 | + } |
|
| 118 | 120 | } elseif ($elements instanceof BaseHtml) { |
| 119 | - if ($callback($elements)) |
|
| 120 | - return $elements; |
|
| 121 | + if ($callback($elements)) { |
|
| 122 | + return $elements; |
|
| 123 | + } |
|
| 121 | 124 | } |
| 122 | 125 | return null; |
| 123 | 126 | } |
@@ -143,8 +146,9 @@ discard block |
||
| 143 | 146 | |
| 144 | 147 | public function fromArray($array) { |
| 145 | 148 | foreach ( $this as $key => $value ) { |
| 146 | - if(array_key_exists($key, $array)===true) |
|
| 147 | - $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 149 | + if(array_key_exists($key, $array)===true) { |
|
| 150 | + $this->_callSetter("set" . ucfirst($key), $key, $array[$key], $array); |
|
| 151 | + } |
|
| 148 | 152 | } |
| 149 | 153 | foreach ( $array as $key => $value ) { |
| 150 | 154 | if($this->_callSetter($key, $key, $value, $array)===false){ |
@@ -213,9 +217,9 @@ discard block |
||
| 213 | 217 | if(\strstr($result, "%{$key}%")!==false){ |
| 214 | 218 | if (\is_array($value)) { |
| 215 | 219 | $v=PropertyWrapper::wrap($value, $js); |
| 216 | - }elseif($value instanceof \stdClass){ |
|
| 220 | + } elseif($value instanceof \stdClass){ |
|
| 217 | 221 | $v=\print_r($value,true); |
| 218 | - }else{ |
|
| 222 | + } else{ |
|
| 219 | 223 | $v=$value; |
| 220 | 224 | } |
| 221 | 225 | $result=str_replace("%{$key}%", $v, $result); |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | * @return $this |
| 51 | 51 | */ |
| 52 | 52 | public function setSource($source) { |
| 53 | - $source=str_ireplace(array ( |
|
| 53 | + $source=str_ireplace(array( |
|
| 54 | 54 | "\"", |
| 55 | 55 | "'" |
| 56 | 56 | ), "%quote%", $source); |
@@ -15,8 +15,8 @@ discard block |
||
| 15 | 15 | * @property HtmlSemDoubleElement $_self |
| 16 | 16 | */ |
| 17 | 17 | trait BaseTrait { |
| 18 | - protected $_variations=[ ]; |
|
| 19 | - protected $_states=[ ]; |
|
| 18 | + protected $_variations=[]; |
|
| 19 | + protected $_states=[]; |
|
| 20 | 20 | protected $_baseClass; |
| 21 | 21 | |
| 22 | 22 | abstract protected function setPropertyCtrl($name, $value, $typeCtrl); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | |
| 30 | 30 | abstract public function setProperty($name, $value); |
| 31 | 31 | |
| 32 | - abstract public function addContent($content,$before=false); |
|
| 32 | + abstract public function addContent($content, $before=false); |
|
| 33 | 33 | |
| 34 | 34 | abstract public function onCreate($jsCode); |
| 35 | 35 | |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $this->_self->setProperty("class", $this->_self->getBaseClass()); |
| 51 | 51 | if (\is_string($variations)) |
| 52 | 52 | $variations=\explode(" ", $variations); |
| 53 | - foreach ( $variations as $variation ) { |
|
| 53 | + foreach ($variations as $variation) { |
|
| 54 | 54 | $this->_self->addVariation($variation); |
| 55 | 55 | } |
| 56 | 56 | return $this; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | public function addVariations($variations=array()) { |
| 65 | 65 | if (\is_string($variations)) |
| 66 | 66 | $variations=\explode(" ", $variations); |
| 67 | - foreach ( $variations as $variation ) { |
|
| 67 | + foreach ($variations as $variation) { |
|
| 68 | 68 | $this->_self->addVariation($variation); |
| 69 | 69 | } |
| 70 | 70 | return $this; |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | public function addStates($states=array()) { |
| 74 | 74 | if (\is_string($states)) |
| 75 | 75 | $states=\explode(" ", $states); |
| 76 | - foreach ( $states as $state ) { |
|
| 76 | + foreach ($states as $state) { |
|
| 77 | 77 | $this->_self->addState($state); |
| 78 | 78 | } |
| 79 | 79 | return $this; |
@@ -83,17 +83,17 @@ discard block |
||
| 83 | 83 | $this->_self->setProperty("class", $this->_self->getBaseClass()); |
| 84 | 84 | if (\is_string($states)) |
| 85 | 85 | $states=\explode(" ", $states); |
| 86 | - foreach ( $states as $state ) { |
|
| 86 | + foreach ($states as $state) { |
|
| 87 | 87 | $this->_self->addState($state); |
| 88 | 88 | } |
| 89 | 89 | return $this; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | public function addIcon($icon, $before=true) { |
| 93 | - return $this->_self->addContent(new HtmlIcon("icon-" . $this->_self->getIdentifier(), $icon), $before); |
|
| 93 | + return $this->_self->addContent(new HtmlIcon("icon-".$this->_self->getIdentifier(), $icon), $before); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - public function addSticky($context="body"){ |
|
| 96 | + public function addSticky($context="body") { |
|
| 97 | 97 | $this->_self->onCreate("$('#".$this->_self->getIdentifier()."').sticky({ context: '".$context."'});"); |
| 98 | 98 | return $this; |
| 99 | 99 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | * @return HtmlSemDoubleElement |
| 115 | 115 | */ |
| 116 | 116 | public function setDisabled($disable=true) { |
| 117 | - if($disable) |
|
| 117 | + if ($disable) |
|
| 118 | 118 | $this->_self->addToProperty("class", "disabled"); |
| 119 | 119 | return $this; |
| 120 | 120 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | * |
| 141 | 141 | * @return HtmlSemDoubleElement |
| 142 | 142 | */ |
| 143 | - public function asHeader(){ |
|
| 143 | + public function asHeader() { |
|
| 144 | 144 | return $this->_self->addToProperty("class", "header"); |
| 145 | 145 | } |
| 146 | 146 | |
@@ -148,15 +148,15 @@ discard block |
||
| 148 | 148 | * show it is currently the active user selection |
| 149 | 149 | * @return HtmlSemDoubleElement |
| 150 | 150 | */ |
| 151 | - public function setActive($value=true){ |
|
| 152 | - if($value) |
|
| 151 | + public function setActive($value=true) { |
|
| 152 | + if ($value) |
|
| 153 | 153 | $this->_self->addToProperty("class", "active"); |
| 154 | 154 | return $this; |
| 155 | 155 | } |
| 156 | 156 | |
| 157 | - public function setAttached($value=true){ |
|
| 158 | - if($value) |
|
| 159 | - $this->_self->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
| 157 | + public function setAttached($value=true) { |
|
| 158 | + if ($value) |
|
| 159 | + $this->_self->addToPropertyCtrl("class", "attached", array("attached")); |
|
| 160 | 160 | return $this; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -164,13 +164,13 @@ discard block |
||
| 164 | 164 | * can be formatted to appear on dark backgrounds |
| 165 | 165 | */ |
| 166 | 166 | public function setInverted($recursive=true) { |
| 167 | - if($recursive===true){ |
|
| 167 | + if ($recursive===true) { |
|
| 168 | 168 | $content=$this->_self->getContent(); |
| 169 | - if($content instanceof HtmlSemDoubleElement) |
|
| 169 | + if ($content instanceof HtmlSemDoubleElement) |
|
| 170 | 170 | $content->setInverted($recursive); |
| 171 | - elseif(\is_array($content) || $content instanceof \Traversable){ |
|
| 172 | - foreach ($content as $elm){ |
|
| 173 | - if($elm instanceof HtmlSemDoubleElement){ |
|
| 171 | + elseif (\is_array($content) || $content instanceof \Traversable) { |
|
| 172 | + foreach ($content as $elm) { |
|
| 173 | + if ($elm instanceof HtmlSemDoubleElement) { |
|
| 174 | 174 | $elm->setInverted($recursive); |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | public function setFloated($direction="right") { |
| 187 | - return $this->_self->addToPropertyCtrl("class", $direction . " floated", Direction::getConstantValues("floated")); |
|
| 187 | + return $this->_self->addToPropertyCtrl("class", $direction." floated", Direction::getConstantValues("floated")); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | public function floatRight() { |
@@ -199,14 +199,14 @@ discard block |
||
| 199 | 199 | return $this->_baseClass; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - protected function addBehavior(&$array,$key,$value,$before="",$after=""){ |
|
| 203 | - if(\is_string($value)){ |
|
| 204 | - if(isset($array[$key])){ |
|
| 202 | + protected function addBehavior(&$array, $key, $value, $before="", $after="") { |
|
| 203 | + if (\is_string($value)) { |
|
| 204 | + if (isset($array[$key])) { |
|
| 205 | 205 | $p=JString::replaceAtFirstAndLast($array[$key], $before, "", $after, ""); |
| 206 | 206 | $array[$key]=$before.$p.$value.$after; |
| 207 | - }else |
|
| 207 | + } else |
|
| 208 | 208 | $array[$key]=$before.$value.$after; |
| 209 | - }else{ |
|
| 209 | + } else { |
|
| 210 | 210 | $array[$key]=$value; |
| 211 | 211 | } |
| 212 | 212 | return $this; |
@@ -48,8 +48,9 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | public function setVariations($variations) { |
| 50 | 50 | $this->_self->setProperty("class", $this->_self->getBaseClass()); |
| 51 | - if (\is_string($variations)) |
|
| 52 | - $variations=\explode(" ", $variations); |
|
| 51 | + if (\is_string($variations)) { |
|
| 52 | + $variations=\explode(" ", $variations); |
|
| 53 | + } |
|
| 53 | 54 | foreach ( $variations as $variation ) { |
| 54 | 55 | $this->_self->addVariation($variation); |
| 55 | 56 | } |
@@ -62,8 +63,9 @@ discard block |
||
| 62 | 63 | } |
| 63 | 64 | |
| 64 | 65 | public function addVariations($variations=array()) { |
| 65 | - if (\is_string($variations)) |
|
| 66 | - $variations=\explode(" ", $variations); |
|
| 66 | + if (\is_string($variations)) { |
|
| 67 | + $variations=\explode(" ", $variations); |
|
| 68 | + } |
|
| 67 | 69 | foreach ( $variations as $variation ) { |
| 68 | 70 | $this->_self->addVariation($variation); |
| 69 | 71 | } |
@@ -71,8 +73,9 @@ discard block |
||
| 71 | 73 | } |
| 72 | 74 | |
| 73 | 75 | public function addStates($states=array()) { |
| 74 | - if (\is_string($states)) |
|
| 75 | - $states=\explode(" ", $states); |
|
| 76 | + if (\is_string($states)) { |
|
| 77 | + $states=\explode(" ", $states); |
|
| 78 | + } |
|
| 76 | 79 | foreach ( $states as $state ) { |
| 77 | 80 | $this->_self->addState($state); |
| 78 | 81 | } |
@@ -81,8 +84,9 @@ discard block |
||
| 81 | 84 | |
| 82 | 85 | public function setStates($states) { |
| 83 | 86 | $this->_self->setProperty("class", $this->_self->getBaseClass()); |
| 84 | - if (\is_string($states)) |
|
| 85 | - $states=\explode(" ", $states); |
|
| 87 | + if (\is_string($states)) { |
|
| 88 | + $states=\explode(" ", $states); |
|
| 89 | + } |
|
| 86 | 90 | foreach ( $states as $state ) { |
| 87 | 91 | $this->_self->addState($state); |
| 88 | 92 | } |
@@ -114,8 +118,9 @@ discard block |
||
| 114 | 118 | * @return HtmlSemDoubleElement |
| 115 | 119 | */ |
| 116 | 120 | public function setDisabled($disable=true) { |
| 117 | - if($disable) |
|
| 118 | - $this->_self->addToProperty("class", "disabled"); |
|
| 121 | + if($disable) { |
|
| 122 | + $this->_self->addToProperty("class", "disabled"); |
|
| 123 | + } |
|
| 119 | 124 | return $this; |
| 120 | 125 | } |
| 121 | 126 | |
@@ -149,14 +154,16 @@ discard block |
||
| 149 | 154 | * @return HtmlSemDoubleElement |
| 150 | 155 | */ |
| 151 | 156 | public function setActive($value=true){ |
| 152 | - if($value) |
|
| 153 | - $this->_self->addToProperty("class", "active"); |
|
| 157 | + if($value) { |
|
| 158 | + $this->_self->addToProperty("class", "active"); |
|
| 159 | + } |
|
| 154 | 160 | return $this; |
| 155 | 161 | } |
| 156 | 162 | |
| 157 | 163 | public function setAttached($value=true){ |
| 158 | - if($value) |
|
| 159 | - $this->_self->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
| 164 | + if($value) { |
|
| 165 | + $this->_self->addToPropertyCtrl("class", "attached", array ("attached" )); |
|
| 166 | + } |
|
| 160 | 167 | return $this; |
| 161 | 168 | } |
| 162 | 169 | |
@@ -166,9 +173,9 @@ discard block |
||
| 166 | 173 | public function setInverted($recursive=true) { |
| 167 | 174 | if($recursive===true){ |
| 168 | 175 | $content=$this->_self->getContent(); |
| 169 | - if($content instanceof HtmlSemDoubleElement) |
|
| 170 | - $content->setInverted($recursive); |
|
| 171 | - elseif(\is_array($content) || $content instanceof \Traversable){ |
|
| 176 | + if($content instanceof HtmlSemDoubleElement) { |
|
| 177 | + $content->setInverted($recursive); |
|
| 178 | + } elseif(\is_array($content) || $content instanceof \Traversable){ |
|
| 172 | 179 | foreach ($content as $elm){ |
| 173 | 180 | if($elm instanceof HtmlSemDoubleElement){ |
| 174 | 181 | $elm->setInverted($recursive); |
@@ -204,9 +211,10 @@ discard block |
||
| 204 | 211 | if(isset($array[$key])){ |
| 205 | 212 | $p=JString::replaceAtFirstAndLast($array[$key], $before, "", $after, ""); |
| 206 | 213 | $array[$key]=$before.$p.$value.$after; |
| 207 | - }else |
|
| 208 | - $array[$key]=$before.$value.$after; |
|
| 209 | - }else{ |
|
| 214 | + } else { |
|
| 215 | + $array[$key]=$before.$value.$after; |
|
| 216 | + } |
|
| 217 | + } else{ |
|
| 210 | 218 | $array[$key]=$value; |
| 211 | 219 | } |
| 212 | 220 | return $this; |
@@ -7,6 +7,11 @@ |
||
| 7 | 7 | use Ajax\common\html\HtmlDoubleElement; |
| 8 | 8 | |
| 9 | 9 | trait AttachedTrait { |
| 10 | + |
|
| 11 | + /** |
|
| 12 | + * @param string $name |
|
| 13 | + * @param string $value |
|
| 14 | + */ |
|
| 10 | 15 | abstract public function addToPropertyCtrl($name, $value, $typeCtrl); |
| 11 | 16 | /** |
| 12 | 17 | * @param HtmlSemDoubleElement $toElement |
@@ -17,6 +17,6 @@ |
||
| 17 | 17 | if (isset($toElement) && \method_exists($toElement, "setAttached")) { |
| 18 | 18 | $toElement->setAttached(true); |
| 19 | 19 | } |
| 20 | - return $this->addToPropertyCtrl("class", $side . " attached", Side::getConstantValues("attached")); |
|
| 20 | + return $this->addToPropertyCtrl("class", $side." attached", Side::getConstantValues("attached")); |
|
| 21 | 21 | } |
| 22 | 22 | } |