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