diff --git a/core/attributedef/AttributeClass.php b/core/attributedef/AttributeClass.php new file mode 100644 index 0000000000..dd48068fde --- /dev/null +++ b/core/attributedef/AttributeClass.php @@ -0,0 +1,84 @@ +m_sCode = $sCode; + $aParams["allowed_values"] = new ValueSetEnumClasses($aParams['class_category'], $aParams['more_values']); + parent::__construct($sCode, $aParams); + } + + public function GetDefaultValue(DBObject $oHostObject = null) + { + $sDefault = parent::GetDefaultValue($oHostObject); + if (!$this->IsNullAllowed() && $this->IsNull($sDefault)) { + // For this kind of attribute specifying null as default value + // is authorized even if null is not allowed + + // Pick the first one... + $aClasses = $this->GetAllowedValues(); + $sDefault = key($aClasses); + } + + return $sDefault; + } + + /** + * @param array $aArgs + * @param string $sContains + * + * @return array|null + * @throws \CoreException + */ + public function GetAllowedValues($aArgs = array(), $sContains = '') + { + $oValSetDef = $this->GetValuesDef(); + if (!$oValSetDef) { + return null; + } + + $aListClass = $oValSetDef->GetValues($aArgs, $sContains); + /* @since 3.3.0 remove elements in class_exclusion_list */ + $sClassExclusionList = $this->GetOptional('class_exclusion_list', null); + if (!empty($sClassExclusionList)) { + foreach (explode(',', $sClassExclusionList) as $sClassName) { + unset($aListClass[trim($sClassName)]); + } + } + + return $aListClass; + } + + public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true) + { + if (empty($sValue)) { + return ''; + } + + return MetaModel::GetName($sValue); + } + + public function RequiresIndex() + { + return true; + } + + public function GetBasicFilterLooseOperator() + { + return '='; + } + +} \ No newline at end of file