@@ -15,55 +15,55 @@ discard block |
||
15 | 15 | * @property InstanceViewer $_instanceViewer |
16 | 16 | */ |
17 | 17 | |
18 | -trait FieldAsTrait{ |
|
18 | +trait FieldAsTrait { |
|
19 | 19 | |
20 | 20 | protected abstract function _getFieldIdentifier($prefix); |
21 | - public abstract function setValueFunction($index,$callback); |
|
21 | + public abstract function setValueFunction($index, $callback); |
|
22 | 22 | |
23 | - private function _getLabelField($caption,$icon=NULL){ |
|
24 | - $label=new HtmlLabel($this->_getFieldIdentifier("lbl"),$caption,$icon); |
|
23 | + private function _getLabelField($caption, $icon=NULL) { |
|
24 | + $label=new HtmlLabel($this->_getFieldIdentifier("lbl"), $caption, $icon); |
|
25 | 25 | return $label; |
26 | 26 | } |
27 | 27 | |
28 | - public function fieldAsLabel($index,$icon=NULL){ |
|
29 | - $this->setValueFunction($index,function($caption) use($icon){ |
|
30 | - $lbl=$this->_getLabelField($caption,$icon); |
|
28 | + public function fieldAsLabel($index, $icon=NULL) { |
|
29 | + $this->setValueFunction($index, function($caption) use($icon){ |
|
30 | + $lbl=$this->_getLabelField($caption, $icon); |
|
31 | 31 | return $lbl; |
32 | 32 | } |
33 | 33 | ); |
34 | 34 | return $this; |
35 | 35 | } |
36 | 36 | |
37 | - public function fieldAsImage($index,$size=Size::SMALL,$circular=false){ |
|
38 | - $this->setValueFunction($index,function($img) use($size,$circular){ |
|
39 | - $image=new HtmlImage($this->_getFieldIdentifier("image"),$img);$image->setSize($size);if($circular)$image->setCircular(); |
|
37 | + public function fieldAsImage($index, $size=Size::SMALL, $circular=false) { |
|
38 | + $this->setValueFunction($index, function($img) use($size, $circular){ |
|
39 | + $image=new HtmlImage($this->_getFieldIdentifier("image"), $img); $image->setSize($size); if ($circular)$image->setCircular(); |
|
40 | 40 | return $image; |
41 | 41 | } |
42 | 42 | ); |
43 | 43 | return $this; |
44 | 44 | } |
45 | 45 | |
46 | - public function fieldAsAvatar($index){ |
|
47 | - $this->setValueFunction($index,function($img){return (new HtmlImage("",$img))->asAvatar();}); |
|
46 | + public function fieldAsAvatar($index) { |
|
47 | + $this->setValueFunction($index, function($img) {return (new HtmlImage("", $img))->asAvatar(); }); |
|
48 | 48 | return $this; |
49 | 49 | } |
50 | 50 | |
51 | - public function fieldAsRadio($index,$name=NULL){ |
|
52 | - $this->setValueFunction($index,function($value)use ($index,$name){ |
|
53 | - if(isset($name)===false){ |
|
51 | + public function fieldAsRadio($index, $name=NULL) { |
|
52 | + $this->setValueFunction($index, function($value)use ($index, $name){ |
|
53 | + if (isset($name)===false) { |
|
54 | 54 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
55 | 55 | } |
56 | - $radio=new HtmlRadio($this->_getFieldIdentifier("radio"),$name,$value,$value); |
|
56 | + $radio=new HtmlRadio($this->_getFieldIdentifier("radio"), $name, $value, $value); |
|
57 | 57 | return $radio; |
58 | 58 | } |
59 | 59 | ); |
60 | 60 | return $this; |
61 | 61 | } |
62 | 62 | |
63 | - public function fieldAsInput($index,$name=NULL,$type="text",$placeholder=""){ |
|
64 | - $this->setValueFunction($index,function($value) use($index,$name,$type,$placeholder){ |
|
65 | - $input=new HtmlInput($this->_getFieldIdentifier("input"),$type,$value,$placeholder); |
|
66 | - if(isset($name)===false){ |
|
63 | + public function fieldAsInput($index, $name=NULL, $type="text", $placeholder="") { |
|
64 | + $this->setValueFunction($index, function($value) use($index, $name, $type, $placeholder){ |
|
65 | + $input=new HtmlInput($this->_getFieldIdentifier("input"), $type, $value, $placeholder); |
|
66 | + if (isset($name)===false) { |
|
67 | 67 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
68 | 68 | } |
69 | 69 | $input->getField()->setProperty("name", $name); |
@@ -73,27 +73,27 @@ discard block |
||
73 | 73 | return $this; |
74 | 74 | } |
75 | 75 | |
76 | - public function fieldAsCheckbox($index,$name=NULL){ |
|
77 | - $this->setValueFunction($index,function($value) use($index,$name){ |
|
78 | - $checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"),"",$value); |
|
76 | + public function fieldAsCheckbox($index, $name=NULL) { |
|
77 | + $this->setValueFunction($index, function($value) use($index, $name){ |
|
78 | + $checkbox=new HtmlCheckbox($this->_getFieldIdentifier("ck"), "", $value); |
|
79 | 79 | $checkbox->setChecked(JString::isBooleanTrue($value)); |
80 | - if(isset($name)===false){ |
|
80 | + if (isset($name)===false) { |
|
81 | 81 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
82 | 82 | } |
83 | 83 | $checkbox->getField()->setProperty("name", $name); |
84 | - return $checkbox;} |
|
84 | + return $checkbox; } |
|
85 | 85 | ); |
86 | 86 | return $this; |
87 | 87 | } |
88 | 88 | |
89 | - public function fieldAsDropDown($index,$elements=[],$multiple=false,$name=NULL){ |
|
90 | - $this->setValueFunction($index,function($value) use($index,$elements,$multiple,$name){ |
|
91 | - $dd=new HtmlDropdown($this->_getFieldIdentifier("dd"),$value,$elements); |
|
92 | - if(isset($name)===false){ |
|
89 | + public function fieldAsDropDown($index, $elements=[], $multiple=false, $name=NULL) { |
|
90 | + $this->setValueFunction($index, function($value) use($index, $elements, $multiple, $name){ |
|
91 | + $dd=new HtmlDropdown($this->_getFieldIdentifier("dd"), $value, $elements); |
|
92 | + if (isset($name)===false) { |
|
93 | 93 | $name=$this->_instanceViewer->getCaption($index)."[]"; |
94 | 94 | } |
95 | - $dd->asSelect($name,$multiple); |
|
96 | - return $dd;} |
|
95 | + $dd->asSelect($name, $multiple); |
|
96 | + return $dd; } |
|
97 | 97 | ); |
98 | 98 | return $this; |
99 | 99 | } |
@@ -12,27 +12,27 @@ discard block |
||
12 | 12 | private $afterCompile; |
13 | 13 | private static $index=0; |
14 | 14 | |
15 | - public function __construct($instance=NULL,$captions=NULL){ |
|
15 | + public function __construct($instance=NULL, $captions=NULL) { |
|
16 | 16 | $this->values=[]; |
17 | 17 | $this->afterCompile=[]; |
18 | - if(isset($instance)) |
|
18 | + if (isset($instance)) |
|
19 | 19 | $this->setInstance($instance); |
20 | 20 | $this->setCaptions($captions); |
21 | 21 | } |
22 | 22 | |
23 | - public function getCaption($index){ |
|
24 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
23 | + public function getCaption($index) { |
|
24 | + if ($this->properties[$index] instanceof \ReflectionProperty) |
|
25 | 25 | return $this->properties[$index]->getName(); |
26 | - elseif(\is_callable($this->properties[$index])) |
|
26 | + elseif (\is_callable($this->properties[$index])) |
|
27 | 27 | return ""; |
28 | 28 | else |
29 | 29 | return $this->properties[$index]; |
30 | 30 | } |
31 | 31 | |
32 | - public function getCaptions(){ |
|
33 | - if(isset($this->captions)){ |
|
34 | - $result= $this->captions; |
|
35 | - for($i=\sizeof($result);$i<$this->count();$i++){ |
|
32 | + public function getCaptions() { |
|
33 | + if (isset($this->captions)) { |
|
34 | + $result=$this->captions; |
|
35 | + for ($i=\sizeof($result); $i<$this->count(); $i++) { |
|
36 | 36 | $result[]=""; |
37 | 37 | } |
38 | 38 | return $result; |
@@ -40,122 +40,122 @@ discard block |
||
40 | 40 | $captions=[]; |
41 | 41 | $index=0; |
42 | 42 | $count=$this->count(); |
43 | - while($index<$count){ |
|
43 | + while ($index<$count) { |
|
44 | 44 | $captions[]=$this->getCaption($index++); |
45 | 45 | } |
46 | 46 | return $captions; |
47 | 47 | } |
48 | 48 | |
49 | - public function getValues(){ |
|
49 | + public function getValues() { |
|
50 | 50 | $values=[]; |
51 | 51 | $index=0; |
52 | 52 | $count=$this->count(); |
53 | - while($index<$count){ |
|
53 | + while ($index<$count) { |
|
54 | 54 | $values[]=$this->getValue($index++); |
55 | 55 | } |
56 | 56 | return $values; |
57 | 57 | } |
58 | 58 | |
59 | - public function getIdentifier(){ |
|
59 | + public function getIdentifier() { |
|
60 | 60 | $value=self::$index; |
61 | - if(isset($this->values["identifier"])) |
|
62 | - $value=$this->values["identifier"](self::$index,$this->instance); |
|
61 | + if (isset($this->values["identifier"])) |
|
62 | + $value=$this->values["identifier"](self::$index, $this->instance); |
|
63 | 63 | self::$index++; |
64 | 64 | return $value; |
65 | 65 | } |
66 | 66 | |
67 | - public function getValue($index){ |
|
67 | + public function getValue($index) { |
|
68 | 68 | $property=$this->properties[$index]; |
69 | 69 | return $this->_getValue($property, $index); |
70 | 70 | } |
71 | 71 | |
72 | - private function _getValue($property,$index){ |
|
73 | - if($property instanceof \ReflectionProperty){ |
|
72 | + private function _getValue($property, $index) { |
|
73 | + if ($property instanceof \ReflectionProperty) { |
|
74 | 74 | $property->setAccessible(true); |
75 | 75 | $value=$property->getValue($this->instance); |
76 | - if(isset($this->values[$index])){ |
|
77 | - $value= $this->values[$index]($value); |
|
76 | + if (isset($this->values[$index])) { |
|
77 | + $value=$this->values[$index]($value); |
|
78 | 78 | } |
79 | - }else{ |
|
80 | - if(\is_callable($property)) |
|
79 | + } else { |
|
80 | + if (\is_callable($property)) |
|
81 | 81 | $value=$property($this->instance); |
82 | - elseif(\is_array($property)){ |
|
83 | - $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
|
82 | + elseif (\is_array($property)) { |
|
83 | + $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index); }, $property); |
|
84 | 84 | $value=\implode("", $values); |
85 | - }else |
|
85 | + } else |
|
86 | 86 | $value=$property; |
87 | 87 | } |
88 | - if(isset($this->afterCompile[$index])){ |
|
89 | - if(\is_callable($this->afterCompile[$index])){ |
|
90 | - $this->afterCompile[$index]($value,$this->instance,$index); |
|
88 | + if (isset($this->afterCompile[$index])) { |
|
89 | + if (\is_callable($this->afterCompile[$index])) { |
|
90 | + $this->afterCompile[$index]($value, $this->instance, $index); |
|
91 | 91 | } |
92 | 92 | } |
93 | 93 | return $value; |
94 | 94 | } |
95 | 95 | |
96 | - public function insertField($index,$field){ |
|
97 | - array_splice( $this->visibleProperties, $index, 0, $field ); |
|
96 | + public function insertField($index, $field) { |
|
97 | + array_splice($this->visibleProperties, $index, 0, $field); |
|
98 | 98 | return $this; |
99 | 99 | } |
100 | 100 | |
101 | - public function insertInField($index,$field){ |
|
101 | + public function insertInField($index, $field) { |
|
102 | 102 | $vb=$this->visibleProperties; |
103 | - if(isset($vb[$index])){ |
|
104 | - if(\is_array($vb[$index])){ |
|
103 | + if (isset($vb[$index])) { |
|
104 | + if (\is_array($vb[$index])) { |
|
105 | 105 | $this->visibleProperties[$index][]=$field; |
106 | - }else{ |
|
107 | - $this->visibleProperties[$index]=[$vb[$index],$field]; |
|
106 | + } else { |
|
107 | + $this->visibleProperties[$index]=[$vb[$index], $field]; |
|
108 | 108 | } |
109 | - }else{ |
|
109 | + } else { |
|
110 | 110 | return $this->insertField($index, $field); |
111 | 111 | } |
112 | 112 | return $this; |
113 | 113 | } |
114 | 114 | |
115 | - public function addField($field){ |
|
115 | + public function addField($field) { |
|
116 | 116 | $this->visibleProperties[]=$field; |
117 | 117 | return $this; |
118 | 118 | } |
119 | 119 | |
120 | - public function count(){ |
|
120 | + public function count() { |
|
121 | 121 | return \sizeof($this->properties); |
122 | 122 | } |
123 | 123 | |
124 | - public function visiblePropertiesCount(){ |
|
124 | + public function visiblePropertiesCount() { |
|
125 | 125 | return \sizeof($this->visibleProperties); |
126 | 126 | } |
127 | 127 | |
128 | - private function showableProperty(\ReflectionProperty $rProperty){ |
|
129 | - return JString::startswith($rProperty->getName(),"_")===false; |
|
128 | + private function showableProperty(\ReflectionProperty $rProperty) { |
|
129 | + return JString::startswith($rProperty->getName(), "_")===false; |
|
130 | 130 | } |
131 | 131 | |
132 | 132 | public function setInstance($instance) { |
133 | - if(\is_string($instance)){ |
|
133 | + if (\is_string($instance)) { |
|
134 | 134 | $instance=new $instance(); |
135 | 135 | } |
136 | 136 | $this->instance=$instance; |
137 | 137 | $this->properties=[]; |
138 | 138 | $this->reflect=new \ReflectionClass($instance); |
139 | - if(\sizeof($this->visibleProperties)===0){ |
|
139 | + if (\sizeof($this->visibleProperties)===0) { |
|
140 | 140 | $this->properties=$this->getDefaultProperties(); |
141 | - }else{ |
|
142 | - foreach ($this->visibleProperties as $property){ |
|
143 | - if(\is_callable($property)){ |
|
141 | + } else { |
|
142 | + foreach ($this->visibleProperties as $property) { |
|
143 | + if (\is_callable($property)) { |
|
144 | 144 | $this->properties[]=$property; |
145 | - }elseif(\is_string($property)){ |
|
146 | - try{ |
|
145 | + }elseif (\is_string($property)) { |
|
146 | + try { |
|
147 | 147 | $rProperty=$this->reflect->getProperty($property); |
148 | 148 | $this->properties[]=$rProperty; |
149 | - }catch(\Exception $e){ |
|
149 | + }catch (\Exception $e) { |
|
150 | 150 | $this->properties[]=$property; |
151 | 151 | } |
152 | - }elseif(\is_int($property)){ |
|
152 | + }elseif (\is_int($property)) { |
|
153 | 153 | $props=$this->getDefaultProperties(); |
154 | - if(isset($props[$property])) |
|
154 | + if (isset($props[$property])) |
|
155 | 155 | $this->properties[]=$props[$property]; |
156 | 156 | else |
157 | 157 | $this->properties[]=$property; |
158 | - }else{ |
|
158 | + } else { |
|
159 | 159 | $this->properties[]=$property; |
160 | 160 | } |
161 | 161 | } |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | return $this; |
164 | 164 | } |
165 | 165 | |
166 | - private function getDefaultProperties(){ |
|
166 | + private function getDefaultProperties() { |
|
167 | 167 | $result=[]; |
168 | 168 | $properties=$this->reflect->getProperties(); |
169 | - foreach ($properties as $property){ |
|
169 | + foreach ($properties as $property) { |
|
170 | 170 | $showable=$this->showableProperty($property); |
171 | - if($showable!==false){ |
|
171 | + if ($showable!==false) { |
|
172 | 172 | $result[]=$property; |
173 | 173 | } |
174 | 174 | } |
@@ -185,12 +185,12 @@ discard block |
||
185 | 185 | return $this; |
186 | 186 | } |
187 | 187 | |
188 | - public function setValueFunction($index,$callback){ |
|
188 | + public function setValueFunction($index, $callback) { |
|
189 | 189 | $this->values[$index]=$callback; |
190 | 190 | return $this; |
191 | 191 | } |
192 | 192 | |
193 | - public function setIdentifierFunction($callback){ |
|
193 | + public function setIdentifierFunction($callback) { |
|
194 | 194 | $this->values["identifier"]=$callback; |
195 | 195 | return $this; |
196 | 196 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | * @param callable $callback function called after the field compilation |
211 | 211 | * @return \Ajax\semantic\widgets\datatable\InstanceViewer |
212 | 212 | */ |
213 | - public function afterCompile($index,$callback){ |
|
213 | + public function afterCompile($index, $callback) { |
|
214 | 214 | $this->afterCompile[$index]=$callback; |
215 | 215 | return $this; |
216 | 216 | } |