@@ -58,7 +58,8 @@ class FieldTransformer {
5858 'placeholder ' => 'placeHolder ' ,
5959 'place-holder ' => 'placeHolder ' ,
6060 'delimiter ' => 'optionsDelimiter ' ,
61- 'is-header ' => 'isHeader '
61+ 'is-header ' => 'isHeader ' ,
62+ 'is-date ' => 'isDate '
6263 ];
6364
6465
@@ -171,40 +172,42 @@ protected function transfer()
171172 *
172173 * @return array
173174 */
174- protected function transferField (array $ field )
175+ protected function transferField (array $ properties )
175176 {
176- if (!$ this ->isKeyExists ($ field , 'name ' ) || empty (Helpers::removeNonEnglishChars ($ field ['name ' ]) ) )
177+ if (!$ this ->isKeyExists ($ properties , 'name ' ) || empty (Helpers::removeNonEnglishChars ($ properties ['name ' ]) ) )
177178 {
178179 throw new Exception ("The field 'name' was not provided! " );
179180 }
180181
181- if (!$ this ->isValidHtmlType ($ field ))
182+ if (!$ this ->isValidHtmlType ($ properties ))
182183 {
183- unset($ field ['html-type ' ]);
184+ unset($ properties ['html-type ' ]);
184185 }
185186
186- $ newField = new Field (Helpers::removeNonEnglishChars ($ field ['name ' ]));
187+ $ field = new Field (Helpers::removeNonEnglishChars ($ properties ['name ' ]));
187188
188- $ this ->setPredefindProperties ($ newField , $ field )
189- ->setDataType ($ newField , $ field )
190- ->setOptionsProperty ($ newField , $ field )
191- ->setValidationProperty ($ newField , $ field )
192- ->setLabelsProperty ($ newField , $ field )
193- ->setDataTypeParams ($ newField , $ field )
194- ->setMultipleAnswers ($ newField , $ field )
195- ->setRange ($ newField , $ field );
189+ $ field ->isDate = in_array ($ field ->name , ['created_at ' ,'updated_at ' ,'deleted_at ' ]);
196190
197- if ($ this ->isValidSelectRangeType ($ field ))
191+ $ this ->setPredefindProperties ($ field , $ properties )
192+ ->setDataType ($ field , $ properties )
193+ ->setOptionsProperty ($ field , $ properties )
194+ ->setValidationProperty ($ field , $ properties )
195+ ->setLabelsProperty ($ field , $ properties )
196+ ->setDataTypeParams ($ field , $ properties )
197+ ->setMultipleAnswers ($ field , $ properties )
198+ ->setRange ($ field , $ properties );
199+
200+ if ($ this ->isValidSelectRangeType ($ properties ))
198201 {
199- $ newField ->htmlType = 'selectRange ' ;
202+ $ field ->htmlType = 'selectRange ' ;
200203 }
201204
202- if ($ newField ->dataType == 'enum ' && empty ($ newField ->getOptions ()) )
205+ if ($ field ->dataType == 'enum ' && empty ($ field ->getOptions ()) )
203206 {
204207 throw new Exception ('To construct an enum data-type field, options must be set ' );
205208 }
206209
207- return new FieldMapper ($ newField , $ field );
210+ return new FieldMapper ($ field , $ properties );
208211 }
209212
210213 /**
@@ -238,31 +241,31 @@ protected function isValidSelectRangeType(array $field)
238241 /**
239242 * Checks if a key exists in a giving array
240243 *
241- * @param array $field
244+ * @param array $properties
242245 * @param string $name
243246 *
244247 * @return bool
245248 */
246- protected function isKeyExists (array $ field , $ name )
249+ protected function isKeyExists (array $ properties , $ name )
247250 {
248- return array_key_exists ($ name , $ field );
251+ return array_key_exists ($ name , $ properties );
249252 }
250253
251254 /**
252255 * Sets the dataType for a giving field
253256 *
254- * @param CrestApps\CodeGenerator\Models\Field $newField
255- * @param array $field
257+ * @param CrestApps\CodeGenerator\Models\Field $field
258+ * @param array $properties
256259 *
257260 * @return $this
258261 */
259- protected function setDataType (Field & $ newField , array $ field )
262+ protected function setDataType (Field & $ field , array $ properties )
260263 {
261264 $ map = $ this ->dataTypeMap ();
262265
263- if ($ this ->isKeyExists ($ field , 'data-type ' ) && $ this ->isKeyExists ($ map , 'data-type ' ) )
266+ if ($ this ->isKeyExists ($ properties , 'data-type ' ) && $ this ->isKeyExists ($ map , 'data-type ' ) )
264267 {
265- $ newField ->dataType = $ map [$ field ['data-type ' ]];
268+ $ field ->dataType = $ map [$ properties ['data-type ' ]];
266269 }
267270
268271 return $ this ;
@@ -290,15 +293,15 @@ protected function setRange(Field & $newField, array $field)
290293 * Sets the DataTypeParam for a giving field
291294 *
292295 * @param CrestApps\CodeGenerator\Models\Field $newField
293- * @param array $field
296+ * @param array $properties
294297 *
295298 * @return $this
296299 */
297- protected function setDataTypeParams (Field & $ newField , array $ field )
300+ protected function setDataTypeParams (Field & $ field , array $ properties )
298301 {
299- if ($ this ->isKeyExists ($ field , 'data-type-params ' ) && is_array ($ field ['data-type-params ' ]))
302+ if ($ this ->isKeyExists ($ properties , 'data-type-params ' ) && is_array ($ properties ['data-type-params ' ]))
300303 {
301- $ newField ->methodParams = $ field ['data-type-params ' ];
304+ $ field ->methodParams = $ properties ['data-type-params ' ];
302305 }
303306
304307 return $ this ;
@@ -311,12 +314,11 @@ protected function setDataTypeParams(Field & $newField, array $field)
311314 *
312315 * @return $this
313316 */
314- protected function setMultipleAnswers (Field & $ newField , array $ field )
317+ protected function setMultipleAnswers (Field & $ field )
315318 {
316-
317- if (in_array ($ newField ->htmlType , ['checkbox ' ,'multipleSelect ' ]))
319+ if (in_array ($ field ->htmlType , ['checkbox ' ,'multipleSelect ' ]))
318320 {
319- $ newField ->isMultipleAnswers = true ;
321+ $ field ->isMultipleAnswers = true ;
320322 }
321323
322324 return $ this ;
0 commit comments