public function testGetValidCastTypesForAllAttributeTypes() { $model = new TestOperatorTypeModel(); $this->assertEquals('Integer', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'integerStandard')); $this->assertEquals('Date', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'dateStandard')); $this->assertEquals('DateTime', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'dateTimeStandard')); $this->assertEquals('Decimal', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'floatStandard')); $this->assertEquals('Time', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'timeStandard')); $this->assertEquals('Email', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'emailStandard')); $this->assertEquals('CheckBox', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'booleanStandard')); $this->assertEquals('Url', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'urlStandard')); //Test all custom fields $this->assertEquals('CheckBox', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'checkBox')); $this->assertEquals(null, ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'currency')); $this->assertEquals('Date', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'date')); $this->assertEquals('DateTime', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'dateTime')); $this->assertEquals('Decimal', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'decimal')); $this->assertEquals(null, ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'dropDown')); $this->assertEquals('Integer', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'integer')); $this->assertEquals(null, ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'phone')); $this->assertEquals(null, ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'radio')); $this->assertEquals(null, ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'text')); $this->assertEquals(null, ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'textArea')); $this->assertEquals('Url', ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, 'url')); }
/** * Sanitize post data, specifically handling any date and date time conversions from local format to the * database format. * @param string $importRulesType * @param array $postMappingData */ public static function sanitizePostByTypeForSavingMappingData($importRulesType, $postMappingData) { assert('is_string($importRulesType)'); assert('is_array($postMappingData)'); foreach ($postMappingData as $columnName => $mappingData) { if (!isset($mappingData['mappingRulesData'])) { $postMappingData[$columnName]['mappingRulesData'] = array(); } } foreach ($postMappingData as $columnName => $mappingData) { foreach ($mappingData['mappingRulesData'] as $mappingRuleFormClassName => $mappingRuleFormData) { $model = MappingRuleFormAndElementTypeUtil::makeForm($importRulesType, $mappingData['attributeIndexOrDerivedType'], $mappingRuleFormClassName); foreach ($mappingRuleFormData as $attributeName => $value) { if ($value !== null) { if (!is_array($value)) { if ($model->isAttribute($attributeName) && $model->isAttributeSafe($attributeName)) { $type = ModelAttributeToMixedTypeUtil::getTypeByModelUsingValidator($model, $model::getAttributeName()); if ($type == 'Date') { $postMappingData[$columnName]['mappingRulesData'][$mappingRuleFormClassName][$attributeName] = DateTimeUtil::resolveValueForDateDBFormatted($value); } if ($type == 'DateTime' && !empty($value)) { $postMappingData[$columnName]['mappingRulesData'][$mappingRuleFormClassName][$attributeName] = DateTimeUtil::convertDateTimeLocaleFormattedDisplayToDbFormattedDateTimeWithSecondsAsZero($value); } } } } } } } return $postMappingData; }