diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 60faaa77b..ba3d31323 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -9705,21 +9705,6 @@ abstract class AttributeSet extends AttributeDBFieldVoid return array_merge(parent::ListExpectedParams(), array('is_null_allowed', 'max_items')); } - /** - * Allowed values are mandatory for this attribute to be modified - * - * @param array $aArgs - * @param string $sContains - * - * @return array|null - * @throws \CoreException - * @throws \OQLException - */ - public function GetAllowedValues($aArgs = array(), $sContains = '') - { - return parent::GetAllowedValues($aArgs, $sContains); - } - /** * Allowed different values for the set values are mandatory for this attribute to be modified * @@ -10142,8 +10127,27 @@ class AttributeEnumSet extends AttributeSet return array_merge(parent::ListExpectedParams(), array('possible_values', 'is_null_allowed', 'max_items')); } + public function GetMaxSize() + { + $aRawValues = $this->GetRawPossibleValues(); + $iMaxItems = $this->GetMaxItems(); + $aLengths = array(); + foreach (array_keys($aRawValues) as $sKey) + { + $aLengths[] = strlen($sKey); + } + rsort($aLengths, SORT_NUMERIC); + $iMaxSize = 2; + for ($i = 0; $i < min($iMaxItems, count($aLengths)); $i++) + { + $iMaxSize += $aLengths[$i] + 1; + } + return max(255, $iMaxSize); + } + private function GetRawPossibleValues($aArgs = array(), $sContains = '') { + /** @var ValueSetEnumPadded $oValSetDef */ $oValSetDef = $this->Get('possible_values'); if (!$oValSetDef) { @@ -10184,9 +10188,14 @@ class AttributeEnumSet extends AttributeSet $sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, null, true /*user lang*/); if (is_null($sLabel)) { - $sDefault = str_replace('_', ' ', $sValue); // Browse the hierarchy again, accepting default (english) translations - $sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, $sDefault, false); + $sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sValue, null, false); + if (is_null($sLabel)) + { + $sDefault = trim(str_replace('_', ' ', $sValue)); + // Browse the hierarchy again, accepting default (english) translations + $sLabel = $this->SearchLabel('/Attribute:'.$this->m_sCode.'/Value:'.$sDefault, $sDefault, false); + } } } diff --git a/core/ormset.class.inc.php b/core/ormset.class.inc.php index 3bb7cc8e3..24e638abc 100644 --- a/core/ormset.class.inc.php +++ b/core/ormset.class.inc.php @@ -111,7 +111,7 @@ class ormSet /** * - * @param array $aItems + * @param string[] $aItems * * @throws \CoreException * @throws \CoreUnexpectedValue when a code is invalid @@ -126,7 +126,7 @@ class ormSet $aValues = array(); $iCount = 0; $bError = false; - foreach($aItems as $oItem) + foreach($aItems as $sItem) { $iCount++; if (($this->iLimit != 0) && ($iCount > $this->iLimit)) @@ -134,7 +134,7 @@ class ormSet $bError = true; continue; } - $aValues[] = $oItem; + $aValues[] = $sItem; } $this->aPreserved = &$aValues; diff --git a/core/trigger.class.inc.php b/core/trigger.class.inc.php index 676ea1a7d..a7e6f5f03 100644 --- a/core/trigger.class.inc.php +++ b/core/trigger.class.inc.php @@ -57,7 +57,7 @@ abstract class Trigger extends cmdbAbstractObject MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => false, "depends_on" => array()))); MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("action_list", array("linked_class" => "lnkTriggerAction", "ext_key_to_me" => "trigger_id", "ext_key_to_remote" => "action_id", "allowed_values" => null, "count_min" => 1, "count_max" => 0, "depends_on" => array()))); $aTags = ContextTag::GetTags(); - MetaModel::Init_AddAttribute( new AttributeEnumSet("context", array("allowed_values" => null, "possible_values" => new ValueSetEnum($aTags), "sql" => "context", "depends_on" => array(), "is_null_allowed" => true, "max_items" => 12))); + MetaModel::Init_AddAttribute( new AttributeEnumSet("context", array("allowed_values" => null, "possible_values" => new ValueSetEnumPadded($aTags), "sql" => "context", "depends_on" => array(), "is_null_allowed" => true, "max_items" => 12))); // Display lists MetaModel::Init_SetZListItems('details', array('finalclass', 'description', 'context', 'action_list')); // Attributes to be displayed for the complete details diff --git a/core/valuesetdef.class.inc.php b/core/valuesetdef.class.inc.php index 85dc509a7..5eb3f79bd 100644 --- a/core/valuesetdef.class.inc.php +++ b/core/valuesetdef.class.inc.php @@ -350,10 +350,10 @@ class ValueSetEnum extends ValueSetDefinition $this->m_values = $Values; } - // Helper to export the datat model + // Helper to export the data model public function GetValueList() { - $this->LoadValues($aArgs = array()); + $this->LoadValues(null); return $this->m_aValues; } @@ -382,6 +382,29 @@ class ValueSetEnum extends ValueSetDefinition } } +class ValueSetEnumPadded extends ValueSetEnum +{ + public function __construct($Values) + { + parent::__construct($Values); + if (is_string($Values)) + { + $this->LoadValues(null); + } + else + { + $this->m_aValues = $Values; + } + $aPaddedValues = array(); + foreach ($this->m_aValues as $sKey => $sVal) + { + $sKey = str_pad($sKey, 3, '_', STR_PAD_LEFT); + $aPaddedValues[$sKey] = $sKey; + } + $this->m_values = $aPaddedValues; + } +} + /** * Fixed set values, defined as a range: 0..59 (with an optional increment) * diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index 443513aa9..d5bc92d91 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -1537,12 +1537,11 @@ EOF $aValues = array(); foreach($oValueNodes as $oValue) { - // new style... $aValues[] = self::QuoteForPHP($oValue->textContent); $aValues[] = $oValue->textContent; } - // new style... $sValues = 'array('.implode(', ', $aValues).')'; $sValues = '"'.implode(',', $aValues).'"'; - $aParameters['allowed_values'] = "new ValueSetEnum($sValues)"; + $aParameters['allowed_values'] = 'null'; + $aParameters['possible_values'] = "new ValueSetEnumPadded($sValues)"; $aParameters['sql'] = $this->GetMandatoryPropString($oField, 'sql'); $aParameters['is_null_allowed'] = $this->GetPropBoolean($oField, 'is_null_allowed', false); $aParameters['depends_on'] = $sDependencies;