public function __construct($modelClassName, $attributeName) { parent::__construct($modelClassName, $attributeName); assert('$attributeName == null'); $states = $this->resolveStates(); $this->states = ArrayUtil::resolveArrayToLowerCase($states); }
/** * @see DataAnalyzerInterface::runAndMakeMessages() */ public function runAndMakeMessages(AnalyzerSupportedDataProvider $dataProvider, $columnName) { assert('is_string($columnName)'); $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->modelClassName, $this->attributeName); $dropDownValues = unserialize($customFieldData->serializedData); $dropDownValues = ArrayUtil::resolveArrayToLowerCase($dropDownValues); $data = $dataProvider->getCountDataByGroupByColumnName($columnName); $count = 0; $missingDropDowns = null; foreach ($data as $valueCountData) { if ($valueCountData[$columnName] == null) { continue; } if ($missingDropDowns != null) { $lowerCaseMissingValuesToMap = ArrayUtil::resolveArrayToLowerCase($missingDropDowns); } else { $lowerCaseMissingValuesToMap = array(); } if (!in_array(strtolower($valueCountData[$columnName]), $dropDownValues) && !in_array(strtolower($valueCountData[$columnName]), $lowerCaseMissingValuesToMap)) { $missingDropDowns[] = $valueCountData[$columnName]; $count++; } } if ($count > 0) { $label = '{count} dropdown value(s) are missing from the field. '; $label .= 'These values will be added upon import.'; $this->addMessage(Zurmo::t('ImportModule', $label, array('{count}' => $count))); } if ($missingDropDowns != null) { $instructionsData = array(DropDownSanitizerUtil::ADD_MISSING_VALUE => $missingDropDowns); $this->setInstructionsData($instructionsData); } }
/** * @param RedBean_OODBBean $rowBean */ public function analyzeByRow(RedBean_OODBBean $rowBean) { $resolvedAcceptableValues = ArrayUtil::resolveArrayToLowerCase(static::getAcceptableValues()); if (!in_array(strtolower($rowBean->{$this->columnName}), $resolvedAcceptableValues)) { $label = Zurmo::t('ImportModule', '{attributeLabel} specified is invalid and this row will be skipped during import.', array('{attributeLabel}' => ProductTemplate::getAnAttributeLabel('sellPriceFormula'))); $this->shouldSkipRow = true; $this->analysisMessages[] = $label; } }
/** * @param RedBean_OODBBean $rowBean */ public function analyzeByRow(RedBean_OODBBean $rowBean) { $states = $this->resolveStates(); $states = ArrayUtil::resolveArrayToLowerCase($states); if ($rowBean->{$this->columnName} != null && !in_array(strtolower($rowBean->{$this->columnName}), $states)) { $label = Zurmo::t('ImportModule', 'Is invalid.'); $this->shouldSkipRow = true; $this->analysisMessages[] = $label; } }
/** * @see BatchAttributeValueDataAnalyzer::analyzeByValue() */ protected function analyzeByValue($value) { if ($value != null) { $lowerCaseMissingValuesToMap = ArrayUtil::resolveArrayToLowerCase($this->missingDropDownInstructions[DropDownSanitizerUtil::ADD_MISSING_VALUE]); if (!in_array(strtolower($value), $this->dropDownValues) && !in_array(strtolower($value), $lowerCaseMissingValuesToMap)) { $this->missingDropDownInstructions[DropDownSanitizerUtil::ADD_MISSING_VALUE][] = $value; $this->messageCountData[static::INVALID]++; } } }
/** * (non-PHPdoc) * @see DropDownBatchAttributeValueDataAnalyzer::analyzeByValue() */ protected function analyzeByValue($value) { if ($value != null) { $customFieldValues = MultiSelectDropDownSanitizerUtil::getCustomFieldValuesFromValueString($value); foreach ($customFieldValues as $aValue) { $lowerCaseMissingValuesToMap = ArrayUtil::resolveArrayToLowerCase($this->missingDropDownInstructions[DropDownSanitizerUtil::ADD_MISSING_VALUE]); if (!in_array(strtolower($aValue), $this->dropDownValues) && !in_array(strtolower($aValue), $lowerCaseMissingValuesToMap)) { $this->missingDropDownInstructions[DropDownSanitizerUtil::ADD_MISSING_VALUE][] = $aValue; $this->messageCountData[static::INVALID]++; } } } }
public function sanitizeValue($value) { $resolvedAcceptableValues = ArrayUtil::resolveArrayToLowerCase(static::getAcceptableValues()); if ($value != null) { if (!in_array(strtolower($value), $resolvedAcceptableValues)) { return null; } return $value; } if (isset($this->mappingRuleData['defaultValue']) && $this->mappingRuleData['defaultValue'] != null) { if (!in_array(strtolower($this->mappingRuleData['defaultValue']), $resolvedAcceptableValues)) { return null; } return $this->mappingRuleData['defaultValue']; } }
public function sanitizeValue($value) { $resolvedAcceptableValues = ArrayUtil::resolveArrayToLowerCase(static::getAcceptableValues()); if ($value != null) { if (!in_array(strtolower($value), $resolvedAcceptableValues)) { return null; } $currency = Currency::getByCode($value); if ($currency != null) { return $currency; } } if (isset($this->mappingRuleData['defaultValue']) && $this->mappingRuleData['defaultValue'] != null) { $currency = Currency::getById(intval($this->mappingRuleData['defaultValue'])); if ($currency != null) { return $currency; } } }
/** * @see LinkedToMappingRuleDataAnalyzerInterface::runAndMakeMessages() */ public function runAndMakeMessages(AnalyzerSupportedDataProvider $dataProvider, $columnName, $mappingRuleType, $mappingRuleData) { assert('is_string($columnName)'); assert('is_string($mappingRuleType)'); assert('is_array($mappingRuleData)'); assert('is_int($mappingRuleData["type"])'); assert('$mappingRuleData["type"] == UserValueTypeModelAttributeMappingRuleForm::ZURMO_USER_ID || $mappingRuleData["type"] == UserValueTypeModelAttributeMappingRuleForm::EXTERNAL_SYSTEM_USER_ID || $mappingRuleData["type"] == UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME'); $this->type = $mappingRuleData["type"]; if ($mappingRuleData['type'] == UserValueTypeModelAttributeMappingRuleForm::ZURMO_USER_ID) { $this->acceptableValues = UserValueTypeSanitizerUtil::getUserIds(); } elseif ($mappingRuleData['type'] == UserValueTypeModelAttributeMappingRuleForm::EXTERNAL_SYSTEM_USER_ID) { $this->acceptableValues = UserValueTypeSanitizerUtil::getUserExternalSystemIds(); } else { $acceptableValues = UserValueTypeSanitizerUtil::getUsernames(); $this->acceptableValues = ArrayUtil::resolveArrayToLowerCase($acceptableValues); } $this->processAndMakeMessage($dataProvider, $columnName); }
public function runAndMakeMessages(AnalyzerSupportedDataProvider $dataProvider, $columnName) { assert('is_string($columnName)'); $dropDownValues = $this->resolveStates(); $dropDownValues = ArrayUtil::resolveArrayToLowerCase($dropDownValues); $data = $dataProvider->getCountDataByGroupByColumnName($columnName); $count = 0; foreach ($data as $valueCountData) { if ($valueCountData[$columnName] == null) { continue; } if (!in_array(strtolower($valueCountData[$columnName]), $dropDownValues)) { $count++; } } if ($count > 0) { $label = '{count} value(s) are not valid. '; $label .= 'Rows that have these values will be skipped during import.'; $this->addMessage(Zurmo::t('ContactsModule', $label, array('{count}' => $count))); } }
/** * Given a value, resolve that the value is a valid custom field data value. If the value does not exist yet, * check the import instructions data to determine how to handle the missing value. * * Example of importInstructionsData * array('DropDown' => array(DropDownSanitizerUtil::ADD_MISSING_VALUE => array('neverPresent', 'notPresent'))) * * @param string $modelClassName * @param string $attributeName * @param mixed $value * @param array $mappingRuleData * @param array $importInstructionsData */ public static function sanitizeValueWithInstructions($modelClassName, $attributeName, $value, $mappingRuleData, $importInstructionsData) { assert('is_string($modelClassName)'); assert('is_string($attributeName)'); assert('$mappingRuleData == null'); if (!isset($importInstructionsData["DropDown"][DropDownSanitizerUtil::ADD_MISSING_VALUE])) { $importInstructionsData["DropDown"][DropDownSanitizerUtil::ADD_MISSING_VALUE] = array(); } if ($value == null) { return $value; } $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($modelClassName, $attributeName); $dropDownValues = unserialize($customFieldData->serializedData); $lowerCaseDropDownValues = ArrayUtil::resolveArrayToLowerCase($dropDownValues); $generateMissingPickListError = false; //does the value already exist in the custom field data if (in_array(TextUtil::strToLowerWithDefaultEncoding($value), $lowerCaseDropDownValues)) { $keyToUse = array_search(TextUtil::strToLowerWithDefaultEncoding($value), $lowerCaseDropDownValues); $resolvedValueToUse = $dropDownValues[$keyToUse]; } else { //if the value does not already exist, then check the instructions data. $lowerCaseValuesToAdd = ArrayUtil::resolveArrayToLowerCase($importInstructionsData['DropDown'][DropDownSanitizerUtil::ADD_MISSING_VALUE]); if (in_array(TextUtil::strToLowerWithDefaultEncoding($value), $lowerCaseValuesToAdd)) { $keyToAddAndUse = array_search(TextUtil::strToLowerWithDefaultEncoding($value), $lowerCaseValuesToAdd); $resolvedValueToUse = $importInstructionsData['DropDown'][DropDownSanitizerUtil::ADD_MISSING_VALUE][$keyToAddAndUse]; $unserializedData = unserialize($customFieldData->serializedData); $unserializedData[] = $resolvedValueToUse; $customFieldData->serializedData = serialize($unserializedData); $saved = $customFieldData->save(); assert('$saved'); } elseif (isset($importInstructionsData['DropDown'][DropDownSanitizerUtil::MAP_MISSING_VALUES])) { $lowerCaseMissingValuesToMap = ArrayUtil::resolveArrayToLowerCase($importInstructionsData['DropDown'][DropDownSanitizerUtil::MAP_MISSING_VALUES]); if (isset($lowerCaseMissingValuesToMap[TextUtil::strToLowerWithDefaultEncoding($value)])) { $keyToUse = array_search($lowerCaseMissingValuesToMap[TextUtil::strToLowerWithDefaultEncoding($value)], $lowerCaseDropDownValues); if ($keyToUse === false) { $message = 'Pick list value specified is missing from existing pick list, has a specified mapping value' . ', but the mapping value is not a valid value.'; throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', $message)); } else { $resolvedValueToUse = $dropDownValues[$keyToUse]; } } else { $generateMissingPickListError = true; } } else { $generateMissingPickListError = true; } if ($generateMissingPickListError) { $message = 'Pick list value specified is missing from existing pick list and no valid instructions' . ' were provided on how to resolve this.'; throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', $message)); } } $customField = new OwnedCustomField(); $customField->value = $resolvedValueToUse; $customField->data = $customFieldData; return $customField; }
protected function getAcceptableValues() { if ($this->mappingRuleData['type'] == UserValueTypeModelAttributeMappingRuleForm::ZURMO_USER_ID) { return UserValueTypeSanitizerUtil::getUserIds(); } elseif ($this->mappingRuleData['type'] == UserValueTypeModelAttributeMappingRuleForm::EXTERNAL_SYSTEM_USER_ID) { return UserValueTypeSanitizerUtil::getUserExternalSystemIds(); } else { $acceptableValues = UserValueTypeSanitizerUtil::getUsernames(); return ArrayUtil::resolveArrayToLowerCase($acceptableValues); } }
protected static function processMissingValueToMapAndGetResolvedValueToUse($aValue, &$generateMissingPickListError, array $customFieldsInstructionData, array $dropDownValues, array $lowerCaseDropDownValues) { assert('is_string($aValue)'); assert('is_bool($generateMissingPickListError)'); $lowerCaseMissingValuesToMap = ArrayUtil::resolveArrayToLowerCase($customFieldsInstructionData[CustomFieldsInstructionData::MAP_MISSING_VALUES]); if (isset($lowerCaseMissingValuesToMap[mb_strtolower($aValue)])) { $keyToUse = array_search($lowerCaseMissingValuesToMap[mb_strtolower($aValue)], $lowerCaseDropDownValues); if ($keyToUse === false) { throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Pick list value specified is ' . 'missing from existing pick list, has a specified mapping value, ' . 'but the mapping value is not a valid value.')); } else { return $dropDownValues[$keyToUse]; } } else { $generateMissingPickListError = true; } }
/** * Check whether the specified value corresponds to a valid username of a user model. * @param AnalyzerSupportedDataProvider $dataProvider * @param string $columnName */ protected function resolveForTypeUsername(AnalyzerSupportedDataProvider $dataProvider, $columnName) { assert('is_string($columnName)'); $usernameValues = UserValueTypeSanitizerUtil::getUsernames(); $usernameValues = ArrayUtil::resolveArrayToLowerCase($usernameValues); $data = $dataProvider->getCountDataByGroupByColumnName($columnName); $count = 0; foreach ($data as $valueCountData) { if ($valueCountData[$columnName] == null) { continue; } if (!in_array(TextUtil::strToLowerWithDefaultEncoding($valueCountData[$columnName]), $usernameValues)) { $count++; } } if ($count > 0) { $label = '{count} username(s) specified were not found. '; $label .= 'These values will not be used during the import.'; $this->addMessage(Zurmo::t('ImportModule', $label, array('{count}' => $count))); } }
protected static function processMissingValueToMapAndGetResolvedValueToUse($aValue, &$generateMissingPickListError, $importInstructionsData) { assert('is_string($aValue)'); assert('is_bool($generateMissingPickListError)'); assert('is_array($importInstructionsData)'); $lowerCaseMissingValuesToMap = ArrayUtil::resolveArrayToLowerCase($importInstructionsData['MultiSelectDropDown'][DropDownSanitizerUtil::MAP_MISSING_VALUES]); if (isset($lowerCaseMissingValuesToMap[mb_strtolower($aValue)])) { $keyToUse = array_search($lowerCaseMissingValuesToMap[mb_strtolower($aValue)], $lowerCaseDropDownValues); if ($keyToUse === false) { $message = 'Pick list value specified is missing from existing pick list, has a specified mapping value' . ', but the mapping value is not a valid value.'; throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', $message)); } else { return $dropDownValues[$keyToUse]; } } else { $generateMissingPickListError = true; } }