コード例 #1
0
 /**
  * @see BatchAttributeValueDataAnalyzer::analyzeByValue()
  */
 protected function analyzeByValue($value)
 {
     if ($this->type == UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME) {
         $compareValue = TextUtil::strToLowerWithDefaultEncoding($value);
     } else {
         $compareValue = $value;
     }
     if ($value != null && !in_array($compareValue, $this->acceptableValues)) {
         $this->messageCountData[static::INVALID]++;
     }
 }
コード例 #2
0
 /**
  * @param RedBean_OODBBean $rowBean
  */
 public function analyzeByRow(RedBean_OODBBean $rowBean)
 {
     if ($this->mappingRuleData['type'] == UserValueTypeModelAttributeMappingRuleForm::ZURMO_USERNAME) {
         $compareValue = TextUtil::strToLowerWithDefaultEncoding($rowBean->{$this->columnName});
     } else {
         $compareValue = $rowBean->{$this->columnName};
     }
     if ($rowBean->{$this->columnName} != null && !in_array($compareValue, $this->getAcceptableValues())) {
         $label = Zurmo::t('ImportModule', 'Is an invalid user value. This value will be skipped during import.');
         $this->analysisMessages[] = $label;
     }
 }
コード例 #3
0
 public static function resolveAccountRelationLabel($type, $relationIdentifier)
 {
     assert('in_array($type, array("Singular", "SingularLowerCase"))');
     assert('in_array($relationIdentifier, array("primary", "secondary"))');
     switch ($type) {
         case 'Singular':
             return static::getSingularAccountRelationLabel($relationIdentifier);
         case 'SingularLowerCase':
             $string = static::getSingularAccountRelationLabel($relationIdentifier);
             return TextUtil::strToLowerWithDefaultEncoding($string);
     }
 }
コード例 #4
0
 public function validateModuleLabels($attribute, $params)
 {
     $data = $this->{$attribute};
     foreach (Yii::app()->languageHelper->getActiveLanguagesData() as $language => $notUsed) {
         if (empty($data[$language])) {
             $this->addError($attribute . '[' . $language . ']', Zurmo::t('Core', 'Label must not be empty.'));
         }
         if ($data[$language] != TextUtil::strToLowerWithDefaultEncoding($data[$language])) {
             $this->addError($attribute . '[' . $language . ']', Zurmo::t('ZurmoModule', 'Label must be all lowercase.'));
         }
         if (!preg_match('/^[\\p{L}A-Za-z0-9_ ]+$/u', $data[$language])) {
             $this->addError($attribute . '[' . $language . ']', Zurmo::t('ZurmoModule', 'Label must not contain any special characters.'));
         }
     }
 }
コード例 #5
0
ファイル: TextUtilTest.php プロジェクト: sandeep1027/zurmo_
 public function testStrToLowerWithDefaultEncoding()
 {
     $string = "Mary Had A Little Lamb and She LOVED It So.";
     $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($string);
     $this->assertEquals('mary had a little lamb and she loved it so.', $lowercaseString);
     // Confirm that string will stay same, if we call this function on lowercase string.
     $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($lowercaseString);
     $this->assertEquals('mary had a little lamb and she loved it so.', $lowercaseString);
     $string = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός";
     $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($string);
     $this->assertEquals('τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός', $lowercaseString);
     $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($lowercaseString);
     $this->assertEquals('τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός', $lowercaseString);
     $string = "ĄĆĘŁŃÓŚŹŻABCDEFGHIJKLMNOPRSTUWYZQXVЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮÂÀÁÄÃÊÈÉËÎÍÌÏÔÕÒÓÖÛÙÚÜÇ";
     $correctLowercase = "ąćęłńóśźżabcdefghijklmnoprstuwyzqxvёйцукенгшщзхъфывапролджэячсмитьбюâàáäãêèéëîíìïôõòóöûùúüç";
     $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($string);
     $this->assertEquals($correctLowercase, $lowercaseString);
     $lowercaseString = TextUtil::strToLowerWithDefaultEncoding($lowercaseString);
     $this->assertEquals($correctLowercase, $lowercaseString);
 }
コード例 #6
0
 /**
  * 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;
 }
コード例 #7
0
ファイル: RedBeanModel.php プロジェクト: youprofit/Zurmo
 public static function getModelLabelByTypeAndLanguage($type, $language = null)
 {
     assert('in_array($type, array("Singular", "SingularLowerCase", "Plural", "PluralLowerCase"))');
     if ($type == 'Singular') {
         return static::getLabel($language);
     }
     if ($type == 'SingularLowerCase') {
         return TextUtil::strToLowerWithDefaultEncoding(static::getLabel($language));
     }
     if ($type == 'Plural') {
         return static::getPluralLabel($language);
     }
     if ($type == 'PluralLowerCase') {
         return TextUtil::strToLowerWithDefaultEncoding(static::getPluralLabel($language));
     }
 }
コード例 #8
0
ファイル: ArrayUtil.php プロジェクト: youprofit/Zurmo
 public static function resolveArrayToLowerCase($array)
 {
     return unserialize(TextUtil::strToLowerWithDefaultEncoding(serialize($array)));
 }
コード例 #9
0
ファイル: Module.php プロジェクト: maruthisivaprasad/zurmo
 public static function getModuleLabelByTypeAndLanguage($type, $language = null)
 {
     assert('in_array($type, array("Singular", "SingularLowerCase", "Plural", "PluralLowerCase"))');
     assert('$language == null || is_string($language)');
     if ($language == null) {
         $language = Yii::app()->language;
     }
     $label = self::getCustomModuleLabelByTypeAndLanguage($type, $language);
     if ($label != null) {
         return $label;
     }
     switch ($type) {
         case 'Singular':
             return static::getSingularModuleLabel($language);
         case 'SingularLowerCase':
             $string = static::getSingularModuleLabel($language);
             return TextUtil::strToLowerWithDefaultEncoding($string);
         case 'Plural':
             return static::getPluralModuleLabel($language);
         case 'PluralLowerCase':
             $string = static::getPluralModuleLabel($language);
             return TextUtil::strToLowerWithDefaultEncoding($string);
     }
 }
コード例 #10
0
 /**
  * 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)));
     }
 }