@@ -9,9 +9,16 @@ |
||
9 | 9 | |
10 | 10 | trait FieldTrait { |
11 | 11 | |
12 | + /** |
|
13 | + * @param string $name |
|
14 | + */ |
|
12 | 15 | abstract public function addToProperty($name, $value, $separator=" "); |
13 | 16 | abstract public function addLabel($caption, $style="label-default", $leftSeparator=" "); |
14 | 17 | abstract public function addContent($content,$before=false); |
18 | + |
|
19 | + /** |
|
20 | + * @return string |
|
21 | + */ |
|
15 | 22 | abstract public function getField(); |
16 | 23 | public function setFocus() { |
17 | 24 | $this->getField()->addToProperty("class", State::FOCUS); |
@@ -18,7 +18,14 @@ discard block |
||
18 | 18 | |
19 | 19 | trait FormFieldAsTrait{ |
20 | 20 | |
21 | + /** |
|
22 | + * @param string $prefix |
|
23 | + */ |
|
21 | 24 | abstract protected function _getFieldIdentifier($prefix); |
25 | + |
|
26 | + /** |
|
27 | + * @param \Closure $callback |
|
28 | + */ |
|
22 | 29 | abstract public function setValueFunction($index,$callback); |
23 | 30 | |
24 | 31 | private function _getLabelField($caption,$icon=NULL){ |
@@ -42,6 +49,9 @@ discard block |
||
42 | 49 | $element->fromArray($attributes); |
43 | 50 | } |
44 | 51 | |
52 | + /** |
|
53 | + * @param HtmlFormField $element |
|
54 | + */ |
|
45 | 55 | protected function _addRules($element,$attributes){ |
46 | 56 | if(isset($attributes["rules"])){ |
47 | 57 | $rules=$attributes["rules"]; |
@@ -53,6 +63,10 @@ discard block |
||
53 | 63 | } |
54 | 64 | } |
55 | 65 | |
66 | + /** |
|
67 | + * @param \Closure $elementCallback |
|
68 | + * @param string $identifier |
|
69 | + */ |
|
56 | 70 | protected function _fieldAs($elementCallback,$index,$attributes=NULL,$identifier=null){ |
57 | 71 | $this->setValueFunction($index,function($value) use ($index,&$attributes,$elementCallback){ |
58 | 72 | $caption=$this->_instanceViewer->getCaption($index); |
@@ -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 | } |
16 | 17 | |
17 | 18 | public function getDataField(){ |
18 | 19 | $field= $this->getField(); |
19 | 20 | //TODO check 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 | } |
25 | 27 | \ No newline at end of file |
@@ -17,8 +17,9 @@ |
||
17 | 17 | } |
18 | 18 | |
19 | 19 | public function setInputType($type){ |
20 | - if($type==="hidden") |
|
21 | - $this->addToProperty("style","display:none;"); |
|
20 | + if($type==="hidden") { |
|
21 | + $this->addToProperty("style","display:none;"); |
|
22 | + } |
|
22 | 23 | $this->getDataField()->setInputType($type); |
23 | 24 | return $this; |
24 | 25 | } |
@@ -62,10 +62,11 @@ discard block |
||
62 | 62 | } |
63 | 63 | |
64 | 64 | public function setDismissable($dismiss=true){ |
65 | - if($dismiss===true) |
|
66 | - $this->close=new HtmlIcon("close-".$this->identifier, "close"); |
|
67 | - else |
|
68 | - $this->close=NULL; |
|
65 | + if($dismiss===true) { |
|
66 | + $this->close=new HtmlIcon("close-".$this->identifier, "close"); |
|
67 | + } else { |
|
68 | + $this->close=NULL; |
|
69 | + } |
|
69 | 70 | return $this; |
70 | 71 | } |
71 | 72 | |
@@ -100,7 +101,8 @@ discard block |
||
100 | 101 | public function setMessage($message){ |
101 | 102 | if(\is_array($this->content)){ |
102 | 103 | $this->content[\sizeof($this->content)-1]=$message; |
103 | - }else |
|
104 | - $this->setContent($message); |
|
104 | + } else { |
|
105 | + $this->setContent($message); |
|
106 | + } |
|
105 | 107 | } |
106 | 108 | } |
107 | 109 | \ No newline at end of file |
@@ -17,8 +17,9 @@ discard block |
||
17 | 17 | public function __construct($instance=NULL,$captions=NULL){ |
18 | 18 | $this->values=[]; |
19 | 19 | $this->afterCompile=[]; |
20 | - if(isset($instance)) |
|
21 | - $this->setInstance($instance); |
|
20 | + if(isset($instance)) { |
|
21 | + $this->setInstance($instance); |
|
22 | + } |
|
22 | 23 | $this->setCaptions($captions); |
23 | 24 | } |
24 | 25 | |
@@ -34,8 +35,9 @@ discard block |
||
34 | 35 | |
35 | 36 | public function getIdentifier(){ |
36 | 37 | $value=self::$index; |
37 | - if(isset($this->values["identifier"])) |
|
38 | - $value=$this->values["identifier"](self::$index,$this->instance); |
|
38 | + if(isset($this->values["identifier"])) { |
|
39 | + $value=$this->values["identifier"](self::$index,$this->instance); |
|
40 | + } |
|
39 | 41 | return $value; |
40 | 42 | } |
41 | 43 | |
@@ -58,19 +60,19 @@ discard block |
||
58 | 60 | $value=$property->getValue($this->instance); |
59 | 61 | if(isset($this->values[$index])){ |
60 | 62 | $value= $this->values[$index]($value,$this->instance,$index); |
61 | - }else{ |
|
63 | + } else{ |
|
62 | 64 | $value=$this->_getDefaultValue($property->getName(),$value, $index); |
63 | 65 | } |
64 | - }else{ |
|
65 | - if(\is_callable($property)) |
|
66 | - $value=$property($this->instance); |
|
67 | - elseif(\is_array($property)){ |
|
66 | + } else{ |
|
67 | + if(\is_callable($property)) { |
|
68 | + $value=$property($this->instance); |
|
69 | + } elseif(\is_array($property)){ |
|
68 | 70 | $values=\array_map(function($v) use ($index){return $this->_getValue($v, $index);}, $property); |
69 | 71 | $value=\implode("", $values); |
70 | - }else{ |
|
72 | + } else{ |
|
71 | 73 | if(isset($this->values[$index])){ |
72 | 74 | $value= $this->values[$index]($property,$this->instance,$index); |
73 | - }else{ |
|
75 | + } else{ |
|
74 | 76 | $value=$property; |
75 | 77 | } |
76 | 78 | } |
@@ -93,10 +95,10 @@ discard block |
||
93 | 95 | if(isset($vb[$index])){ |
94 | 96 | if(\is_array($vb[$index])){ |
95 | 97 | $this->visibleProperties[$index][]=$field; |
96 | - }else{ |
|
98 | + } else{ |
|
97 | 99 | $this->visibleProperties[$index]=[$vb[$index],$field]; |
98 | 100 | } |
99 | - }else{ |
|
101 | + } else{ |
|
100 | 102 | return $this->insertField($index, $field); |
101 | 103 | } |
102 | 104 | return $this; |
@@ -132,26 +134,27 @@ discard block |
||
132 | 134 | $this->reflect=new \ReflectionClass($instance); |
133 | 135 | if(\sizeof($this->visibleProperties)===0){ |
134 | 136 | $this->properties=$this->getDefaultProperties(); |
135 | - }else{ |
|
137 | + } else{ |
|
136 | 138 | foreach ($this->visibleProperties as $property){ |
137 | 139 | if(\is_callable($property)){ |
138 | 140 | $this->properties[]=$property; |
139 | - }elseif(\is_string($property)){ |
|
141 | + } elseif(\is_string($property)){ |
|
140 | 142 | try{ |
141 | 143 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
142 | 144 | $rProperty=$this->reflect->getProperty($property); |
143 | 145 | $this->properties[]=$rProperty; |
144 | - }catch(\Exception $e){ |
|
146 | + } catch(\Exception $e){ |
|
145 | 147 | $this->_beforeAddProperty(\sizeof($this->properties), $property); |
146 | 148 | $this->properties[]=$property; |
147 | 149 | } |
148 | - }elseif(\is_int($property)){ |
|
150 | + } elseif(\is_int($property)){ |
|
149 | 151 | $props=$this->getDefaultProperties(); |
150 | - if(isset($props[$property])) |
|
151 | - $this->properties[]=$props[$property]; |
|
152 | - else |
|
153 | - $this->properties[]=$property; |
|
154 | - }else{ |
|
152 | + if(isset($props[$property])) { |
|
153 | + $this->properties[]=$props[$property]; |
|
154 | + } else { |
|
155 | + $this->properties[]=$property; |
|
156 | + } |
|
157 | + } else{ |
|
155 | 158 | $this->properties[]=$property; |
156 | 159 | } |
157 | 160 | } |
@@ -198,12 +201,13 @@ discard block |
||
198 | 201 | if(isset($this->captions[$index])){ |
199 | 202 | return $this->captions[$index]; |
200 | 203 | } |
201 | - if($this->properties[$index] instanceof \ReflectionProperty) |
|
202 | - return $this->properties[$index]->getName(); |
|
203 | - elseif(\is_callable($this->properties[$index])) |
|
204 | - return ""; |
|
205 | - else |
|
206 | - return $this->properties[$index]; |
|
204 | + if($this->properties[$index] instanceof \ReflectionProperty) { |
|
205 | + return $this->properties[$index]->getName(); |
|
206 | + } elseif(\is_callable($this->properties[$index])) { |
|
207 | + return ""; |
|
208 | + } else { |
|
209 | + return $this->properties[$index]; |
|
210 | + } |
|
207 | 211 | } |
208 | 212 | |
209 | 213 | public function getCaptions(){ |
@@ -224,8 +228,9 @@ discard block |
||
224 | 228 | } |
225 | 229 | |
226 | 230 | public function setCaption($index,$caption){ |
227 | - if(isset($this->captions)===false) |
|
228 | - $this->captions=[]; |
|
231 | + if(isset($this->captions)===false) { |
|
232 | + $this->captions=[]; |
|
233 | + } |
|
229 | 234 | $this->captions[$index]=$caption; |
230 | 235 | return $this; |
231 | 236 | } |