/**
  * If the attribute specified is required and the value is null, attempt to utilize a default value if it is
  * specified. If it is not specified or the default value specified is not a valid custom field data value, then
  * an InvalidValueToSanitizeException will be thrown.
  * @param string $modelClassName
  * @param string $attributeName
  * @param mixed $value
  * @param array $mappingRuleData
  */
 public static function sanitizeValue($modelClassName, $attributeName, $value, $mappingRuleData)
 {
     assert('is_string($modelClassName)');
     assert('is_string($attributeName)');
     if ($value != null) {
         return $value;
     }
     assert('$value == null || $value instanceof OwnedCustomField');
     assert('$mappingRuleData["defaultValue"] == null || is_string($mappingRuleData["defaultValue"])');
     if ($mappingRuleData['defaultValue'] != null) {
         try {
             $customField = new OwnedCustomField();
             $customField->value = $mappingRuleData['defaultValue'];
             $customField->data = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($modelClassName, $attributeName);
         } catch (NotSupportedException $e) {
             throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Pick list is missing corresponding custom field data.'));
         }
         return $customField;
     } else {
         $model = new $modelClassName(false);
         if (!$model->isAttributeRequired($attributeName)) {
             return $value;
         }
         throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Pick list value required, but missing.'));
     }
     return $value;
 }
 /**
  * If the attribute specified is required and the value is null, attempt to utilize a default value if it is
  * specified. If it is not specified or the default value specified is not a valid custom field data value, then
  * an InvalidValueToSanitizeException will be thrown.
  * @param mixed $value
  * @return sanitized value
  * @throws InvalidValueToSanitizeException
  */
 public function sanitizeValue($value)
 {
     if ($value != null) {
         return $value;
     }
     assert('$value == null || $value instanceof OwnedMultipleValuesCustomField');
     if (isset($this->mappingRuleData['defaultValue']) && $this->mappingRuleData['defaultValue'] != null) {
         try {
             $customField = new OwnedMultipleValuesCustomField();
             foreach ($this->mappingRuleData['defaultValue'] as $aDefaultValue) {
                 $customFieldValue = new CustomFieldValue();
                 $customFieldValue->value = $aDefaultValue;
                 $customField->values->add($customFieldValue);
             }
             $customField->data = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->modelClassName, $this->attributeName);
         } catch (NotSupportedException $e) {
             throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Pick list is missing corresponding custom field data.'));
         }
         return $customField;
     } else {
         $modelClassName = $this->modelClassName;
         $model = new $modelClassName(false);
         if (!$model->isAttributeRequired($this->attributeName)) {
             return $value;
         }
         throw new InvalidValueToSanitizeException(Zurmo::t('ImportModule', 'Pick list value required, but missing.'));
     }
 }
 /**
  * @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);
     }
 }
 public function __construct($modelClassName, $attributeName)
 {
     parent::__construct($modelClassName, $attributeName);
     assert('is_string($attributeName)');
     $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->modelClassName, $this->attributeName);
     $dropDownValues = unserialize($customFieldData->serializedData);
     $this->dropDownValues = ArrayUtil::resolveArrayToLowerCase($dropDownValues);
     $this->missingDropDownInstructions[DropDownSanitizerUtil::ADD_MISSING_VALUE] = array();
 }
 public function getChartData()
 {
     $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName('Opportunity', 'stage');
     $labels = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, Yii::app()->language);
     $sql = static::makeChartSqlQuery();
     $rows = R::getAll($sql);
     $chartData = array();
     foreach ($rows as $row) {
         $chartData[] = array('value' => $this->resolveCurrencyValueConversionRateForCurrentUserForDisplay($row['amount']), 'displayLabel' => static::resolveLabelByValueAndLabels($row['stage'], $labels));
     }
     return $chartData;
 }
 /**
  * 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 customFieldsInstructionData
  * array(array(CustomFieldsInstructionData::ADD_MISSING_VALUES => array('neverPresent', 'notPresent'))
  *
  * @param mixed $value
  * @return sanitized value
  * @throws InvalidValueToSanitizeException
  */
 public function sanitizeValue($value)
 {
     assert('$this->mappingRuleData == null');
     $customFieldsInstructionData = $this->getCustomFieldsInstructionDataFromColumnMappingData();
     if (!isset($customFieldsInstructionData[CustomFieldsInstructionData::ADD_MISSING_VALUES])) {
         $customFieldsInstructionData[CustomFieldsInstructionData::ADD_MISSING_VALUES] = array();
     }
     if ($value == null) {
         return $value;
     }
     $customFieldValues = static::getCustomFieldValuesFromValueString($value);
     $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->modelClassName, $this->attributeName);
     $dropDownValues = unserialize($customFieldData->serializedData);
     $lowerCaseDropDownValues = ArrayUtil::resolveArrayToLowerCase($dropDownValues);
     $resolvedValuesToUse = array();
     foreach ($customFieldValues as $aValue) {
         $generateMissingPickListError = false;
         //does the value already exist in the custom field data
         if (in_array(mb_strtolower($aValue), $lowerCaseDropDownValues)) {
             $keyToUse = array_search(mb_strtolower($aValue), $lowerCaseDropDownValues);
             $resolvedValuesToUse[] = $dropDownValues[$keyToUse];
         } else {
             //if the value does not already exist, then check the instructions data.
             $lowerCaseValuesToAdd = ArrayUtil::resolveArrayToLowerCase($customFieldsInstructionData[CustomFieldsInstructionData::ADD_MISSING_VALUES]);
             if (in_array(mb_strtolower($aValue), $lowerCaseValuesToAdd)) {
                 $keyToAddAndUse = array_search(mb_strtolower($aValue), $lowerCaseValuesToAdd);
                 $resolvedValueToUse = $customFieldsInstructionData[CustomFieldsInstructionData::ADD_MISSING_VALUES][$keyToAddAndUse];
                 $unserializedData = unserialize($customFieldData->serializedData);
                 $unserializedData[] = $resolvedValueToUse;
                 $customFieldData->serializedData = serialize($unserializedData);
                 $saved = $customFieldData->save();
                 assert('$saved');
             } elseif (isset($customFieldsInstructionData[CustomFieldsInstructionData::MAP_MISSING_VALUES])) {
                 $resolvedValueToUse = static::processMissingValueToMapAndGetResolvedValueToUse($aValue, $generateMissingPickListError, $customFieldsInstructionData, $dropDownValues, $lowerCaseDropDownValues);
             } 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));
             }
             $resolvedValuesToUse[] = $resolvedValueToUse;
         }
     }
     return static::makeOwnedMultiSelectCustomField($resolvedValuesToUse, $customFieldData);
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
 public static function findFileNameToCategoryToMessage($path, $forcedCategory = '', $forTesting = false)
 {
     assert('is_string($path)');
     assert('is_dir   ($path)');
     $fileNamesToCategoriesToMessages = array();
     $f = opendir($path);
     assert('$f !== false');
     while ($entry = readdir($f)) {
         if (!in_array($entry, array('.', '..', 'messages'))) {
             $fullEntryName = "{$path}/{$entry}";
             if (is_dir($fullEntryName)) {
                 $fileNamesToCategoriesToMessages = array_merge($fileNamesToCategoriesToMessages, static::findFileNameToCategoryToMessage($fullEntryName));
             } elseif (is_file($fullEntryName) && pathinfo($entry, PATHINFO_EXTENSION) == 'php') {
                 //Avoid any models in the framework/models folder and test models
                 if (strpos($path, '/core') === false && strpos($path, '/tests') === false && strpos($path, '/models') !== false && strpos($fullEntryName, '.php') !== false) {
                     $modelClassName = basename(substr($fullEntryName, 0, -4));
                     $modelReflectionClass = new ReflectionClass($modelClassName);
                     if ($modelReflectionClass->isSubclassOf('RedBeanModel') && $modelReflectionClass->isSubclassOf('OwnedModel') && !$modelReflectionClass->isAbstract()) {
                         $modelAttributes = $modelClassName::getAttributeNames();
                         foreach ($modelAttributes as $attributeName) {
                             //Find attributes that are a CustomField relation. This means there is drop down values
                             //that will need to be translated.
                             if ($modelClassName::isRelation($attributeName) && ($modelClassName::getRelationModelClassName($attributeName) == 'OwnedCustomField' || $modelClassName::getRelationModelClassName($attributeName) == 'CustomField' || $modelClassName::getRelationModelClassName($attributeName) == 'MultipleValuesCustomField' || $modelClassName::getRelationModelClassName($attributeName) == 'OwnedMultipleValuesCustomField')) {
                                 $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($modelClassName, $attributeName);
                                 $customFieldDataNames = unserialize($customFieldData->serializedData);
                                 foreach ($customFieldDataNames as $dataName) {
                                     $fileNamesToCategoriesToMessages[$fullEntryName]['Default'][] = $dataName;
                                 }
                             }
                         }
                     }
                 }
                 //Check for any menu labels, rights, policies, or audit event names in the modules.
                 if (strpos($fullEntryName, 'Module.php') !== false) {
                     $moduleClassName = basename(substr($fullEntryName, 0, -4));
                     $moduleReflectionClass = new ReflectionClass($moduleClassName);
                     if ($moduleReflectionClass->isSubclassOf('SecurableModule') && !$moduleReflectionClass->isAbstract()) {
                         $labelsData = static::getSecurableModuleRightsPoliciesAndAuditEventLabels($moduleClassName);
                         if (!empty($labelsData)) {
                             if (isset($fileNamesToCategoriesToMessages[$fullEntryName]['Default'])) {
                                 $fileNamesToCategoriesToMessages[$fullEntryName]['Default'] = array_merge($fileNamesToCategoriesToMessages[$fullEntryName]['Default'], $labelsData);
                             } else {
                                 $fileNamesToCategoriesToMessages[$fullEntryName]['Default'] = $labelsData;
                             }
                         }
                     }
                     //attempt to detect any 'state' adapters and look for state labels.
                     $stateAdapterClassName = $moduleClassName::getStateMetadataAdapterClassName();
                     if ($stateAdapterClassName != null && $stateAdapterClassName) {
                         $stateModelClassName = $stateAdapterClassName::getStateModelClassName();
                         $states = $stateModelClassName::getAll();
                         foreach ($states as $state) {
                             $fileNamesToCategoriesToMessages[$fullEntryName]['Default'][] = $state->name;
                         }
                     }
                     //check for menu labels
                     if (!$moduleReflectionClass->isAbstract()) {
                         if (isset($fileNamesToCategoriesToMessages[$fullEntryName]['Default'])) {
                             $fileNamesToCategoriesToMessages[$fullEntryName]['Default'] = array_merge($fileNamesToCategoriesToMessages[$fullEntryName]['Default'], static::getModuleMenuLabelNamesByModuleName($moduleClassName));
                         } else {
                             $fileNamesToCategoriesToMessages[$fullEntryName]['Default'] = static::getModuleMenuLabelNamesByModuleName($moduleClassName);
                         }
                     }
                 }
                 //Check for any panel titles that need translation
                 if (strpos($fullEntryName, 'View.php') !== false) {
                     $viewClassName = basename(substr($fullEntryName, 0, -4));
                     $moduleReflectionClass = new ReflectionClass($viewClassName);
                     if ($moduleReflectionClass->isSubclassOf('MetadataView') && !$moduleReflectionClass->isAbstract()) {
                         $metadata = $viewClassName::getDefaultMetadata();
                         if (isset($metadata['global']) && isset($metadata['global']['panels'])) {
                             foreach ($metadata['global']['panels'] as $panel) {
                                 if (isset($panel['title'])) {
                                     $fileNamesToCategoriesToMessages[$fullEntryName]['Default'][] = $panel['title'];
                                 }
                             }
                         }
                     }
                 }
                 //Avoid picking up any models or anything in the test folders
                 if ($forTesting || strpos($path, '/tests') === false) {
                     $content = file_get_contents($fullEntryName);
                     $content = str_replace('\\\'', '\'', $content);
                     if (preg_match_all(self::GOOD_YII_T, $content, $matches)) {
                         foreach ($matches[1] as $index => $category) {
                             if (preg_match_all('/^\\w*$/', $category) != 1) {
                                 echo 'This is not a valid category: ' . $category . "\n";
                             } else {
                                 if ($forcedCategory and is_string($forcedCategory) and strlen($forcedCategory)) {
                                     $category = $forcedCategory;
                                 }
                                 if (!isset($fileNamesToCategoriesToMessages[$fullEntryName][$category])) {
                                     $fileNamesToCategoriesToMessages[$fullEntryName][$category] = array();
                                 }
                                 //Remove extra lines caused by ' . ' which is used for line breaks in php. Minimum 3 spaces
                                 //will avoid catching 2 spaces between words which can be legitimate.
                                 $massagedString = preg_replace('/[\\p{Z}\\s]{3,}/u', ' ', $matches[2][$index]);
                                 // Not Coding Standard
                                 $massagedString = str_replace("' . '", '', $massagedString);
                                 $fileNamesToCategoriesToMessages[$fullEntryName][$category][] = $massagedString;
                                 if ($matches[2][$index] != $massagedString && strpos($matches[2][$index], "' .") === false && strpos($matches[2][$index], ".") > 0) {
                                     echo 'The following message should be using proper line breaks: ' . $matches[2][$index] . "\n";
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $fileNamesToCategoriesToMessages;
 }
 /**
  * Raw values such as those used by the header x-axis or y-axis rows/columns need to be translated. An example
  * is a dropdown where the value is the raw database value and needs to be properly translated for display.
  * Another example is dynamic __User, where the value is the user id, and needs to be stringified to the User
  * model.
  * @param $value
  * @return string
  */
 public function resolveValueAsLabelForHeaderCell($value, $forExport = false)
 {
     $tContent = null;
     $translatedValue = $value;
     $resolvedAttribute = $this->getResolvedAttribute();
     $displayElementType = $this->getDisplayElementType();
     $modelToReportAdapter = $this->makeResolvedAttributeModelRelationsAndAttributesToReportAdapter();
     if ($modelToReportAdapter->getModel()->isAttribute($resolvedAttribute) && $modelToReportAdapter->getModel()->isRelation($resolvedAttribute) && !$modelToReportAdapter->getModel()->isOwnedRelation($resolvedAttribute)) {
         $relationModelClassName = $modelToReportAdapter->getModel()->getRelationModelClassName($resolvedAttribute);
         $relatedModel = $relationModelClassName::getById((int) $value);
         if ($relatedModel->isAttribute('serializedLabels')) {
             $translatedValue = $relatedModel->resolveTranslatedNameByLanguage(Yii::app()->language);
         }
     } elseif ($displayElementType == 'User') {
         $user = User::getById((int) $value);
         $translatedValue = strval($user);
     } elseif ($displayElementType == 'DropDown') {
         $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->getResolvedAttributeModelClassName(), $this->getResolvedAttribute());
         $dataAndLabels = CustomFieldDataUtil::getDataIndexedByDataAndTranslatedLabelsByLanguage($customFieldData, Yii::app()->language);
         if (isset($dataAndLabels[$value])) {
             $translatedValue = $dataAndLabels[$value];
         }
     } elseif ($displayElementType == 'CheckBox') {
         if ($value) {
             $translatedValue = Zurmo::t('Core', 'Yes');
         } elseif ($value == false && $value != '') {
             $translatedValue = Zurmo::t('Core', 'No');
         }
     } elseif ($displayElementType == 'GroupByModifierMonth') {
         $translatedValue = DateTimeUtil::getMonthName($value);
     }
     if ($translatedValue === null) {
         $translatedValue = '';
     }
     if ($this->isALinkableAttribute() && !$forExport) {
         $modelClassName = get_class($modelToReportAdapter->getModel());
         $moduleClassName = $modelToReportAdapter->getModuleClassName();
         if (isset($relationModelClassName)) {
             $modelClassName = $relationModelClassName;
         }
         return ReportResultsGridUtil::makeStringForMultipleLinks($value, $modelClassName, $moduleClassName);
     }
     return $translatedValue;
 }
 /**
  * Check if picklist modification caused some issues with workflow triggers and if yes notify users
  * @return array
  * @throws NotSupportedException
  */
 public static function getWorkflowsWithInvalidTriggerCustomFieldValue()
 {
     $savedWorkflows = SavedWorkflow::getAll();
     $workflows = array();
     foreach ($savedWorkflows as $savedWorkflow) {
         $workflow = SavedWorkflowToWorkflowAdapter::makeWorkflowBySavedWorkflow($savedWorkflow);
         $hasInvalidCustomFieldValue = false;
         foreach ($workflow->getTriggers() as $trigger) {
             $modelClassName = $trigger->getModelClassName();
             $customFieldAttributeNames = CustomFieldUtil::getCustomFieldAttributeNames($modelClassName);
             $triggerAttributeName = $trigger->getAttribute();
             if (in_array($triggerAttributeName, $customFieldAttributeNames)) {
                 $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($modelClassName, $triggerAttributeName);
                 $allCustomFieldValues = unserialize($customFieldData->serializedData);
                 // Check with triggers that allow single value
                 if (in_array($trigger->getOperator(), array(OperatorRules::TYPE_EQUALS, OperatorRules::TYPE_DOES_NOT_EQUAL, OperatorRules::TYPE_BECOMES, OperatorRules::TYPE_WAS))) {
                     if (!in_array($trigger->value, $allCustomFieldValues)) {
                         $hasInvalidCustomFieldValue = true;
                         break;
                     }
                 } elseif (in_array($trigger->getOperator(), array(OperatorRules::TYPE_BECOMES_ONE_OF, OperatorRules::TYPE_WAS_ONE_OF, OperatorRules::TYPE_ONE_OF))) {
                     $triggerSelectedCustomFieldValues = MultiSelectDropDownSanitizerUtil::getCustomFieldValuesFromValueString($trigger->value);
                     foreach ($triggerSelectedCustomFieldValues as $triggerValue) {
                         if (!in_array($triggerValue, $allCustomFieldValues)) {
                             $hasInvalidCustomFieldValue = true;
                             break 2;
                         }
                     }
                 }
             }
         }
         if ($hasInvalidCustomFieldValue) {
             $workflows[] = $workflow;
         }
     }
     return $workflows;
 }
 protected function getAttributeCustomFieldData($attributeName)
 {
     assert('is_string($attributeName) || $attributeName == null');
     if ($attributeName == null) {
         return null;
     }
     return CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->modelClassName, $attributeName);
 }
 /**
  * Make sure the mappings are formed correctly.  There are several validation conditions for mapping data.
  * 1. There must be at least 2 attributes mapped to form a dependency.
  * 2. At this time no more than 4 mapped attributes is supported.
  * 3. Any mapped attribute, must have at least one of it's customFieldData values mapped to a parent value, except
  *    the top level mapping.
  * 4. Of the values mapped for a given attribute, make sure the mappings are to valid parent values.
  * @param string $attribute
  * @param $params
  */
 public function validateMappingData($attribute, $params)
 {
     assert('$this->modelClassName != null');
     assert('$attribute == "mappingData"');
     $mappingData = $this->{$attribute};
     $selectedAttributeNames = 0;
     foreach ($mappingData as $data) {
         if (isset($data['attributeName']) && $data['attributeName'] != null) {
             $selectedAttributeNames++;
         }
     }
     if (count($mappingData) < 2 || $selectedAttributeNames < 2) {
         $this->addError('mappingData', Zurmo::t('DesignerModule', 'You must select at least 2 pick-lists.'));
     }
     if (count($mappingData) > 4 || $selectedAttributeNames > 4) {
         $this->addError('mappingData', Zurmo::t('DesignerModule', 'You can only have at most 4 pick-lists selected.'));
     }
     foreach ($mappingData as $position => $attributeNameAndData) {
         assert('isset($attributeNameAndData["attributeName"])');
         if ($position > 0 && $attributeNameAndData['attributeName'] != null) {
             if (!isset($attributeNameAndData['valuesToParentValues']) || self::getValuesToParentValuesMappedCount($attributeNameAndData['valuesToParentValues']) == 0) {
                 $this->addError('mappingData', Zurmo::t('DesignerModule', 'At least one pick-list value must be mapped for each used level.'));
             } else {
                 $customFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->modelClassName, $attributeNameAndData['attributeName']);
                 $dataValues = unserialize($customFieldData->serializedData);
                 $parentPosition = $position - 1;
                 $parentAttributeName = $mappingData[$parentPosition]['attributeName'];
                 $parentCustomFieldData = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($this->modelClassName, $parentAttributeName);
                 $parentDataValues = unserialize($parentCustomFieldData->serializedData);
                 foreach ($attributeNameAndData['valuesToParentValues'] as $customFieldDataValue => $parentCustomFieldDataValue) {
                     if ($parentCustomFieldDataValue != null && !in_array($parentCustomFieldDataValue, $parentDataValues)) {
                         $this->addError('mappingData', Zurmo::t('DesignerModule', 'Each pick-list value must map correctly to a parent pick-list value. ' . 'This value does map correctly: {value} - {parentValue}', array('{value}' => $customFieldDataValue, '{parentValue}' => $parentCustomFieldDataValue)));
                     }
                 }
             }
         }
     }
 }
 /**
  * @expectedException NotSupportedException
  */
 public function testGetDataByModelClassNameAndAttributeNameNotFound()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName('TestBooleanAttributeModel', 'bool');
 }
 public function __construct($modelClassName, $modelAttributeName)
 {
     parent::__construct($modelClassName, $modelAttributeName);
     $this->data = CustomFieldDataModelUtil::getDataByModelClassNameAndAttributeName($modelClassName, $modelAttributeName);
 }
Exemplo n.º 15
0
 /**
  * How many attributes that are drop downs across the different models are using this customFieldData.
  */
 public function getModelPluralNameAndAttributeLabelsThatUseCollectionData()
 {
     return CustomFieldDataModelUtil::getModelPluralNameAndAttributeLabelsByName($this->customFieldDataName);
 }