diff --git a/core/attributedef/AttributeMetaEnum.php b/core/attributedef/AttributeMetaEnum.php new file mode 100644 index 000000000..7ddbbd88e --- /dev/null +++ b/core/attributedef/AttributeMetaEnum.php @@ -0,0 +1,137 @@ +GetHostClass(); + } + $aMappingData = $this->GetMapRule($sClass); + if ($aMappingData == null) { + $aRet = array(); + } else { + $aRet = array($aMappingData['attcode']); + } + + return $aRet; + } + + /** + * Overload the standard so as to leave the data unsorted + * + * @param array $aArgs + * @param string $sContains + * + * @return array|null + */ + public function GetAllowedValues($aArgs = array(), $sContains = '') + { + $oValSetDef = $this->GetValuesDef(); + if (!$oValSetDef) { + return null; + } + $aRawValues = $oValSetDef->GetValueList(); + + if (is_null($aRawValues)) { + return null; + } + $aLocalizedValues = array(); + foreach ($aRawValues as $sKey => $sValue) { + $aLocalizedValues[$sKey] = $this->GetValueLabel($sKey); + } + + return $aLocalizedValues; + } + + /** + * Returns the meta value for the given object. + * See also MetaModel::RebuildMetaEnums() that must be maintained when MapValue changes + * + * @param $oObject + * + * @return mixed + * @throws Exception + */ + public function MapValue($oObject) + { + $aMappingData = $this->GetMapRule(get_class($oObject)); + if ($aMappingData == null) { + $sRet = $this->GetDefaultValue(); + } else { + $sAttCode = $aMappingData['attcode']; + $value = $oObject->Get($sAttCode); + if (array_key_exists($value, $aMappingData['values'])) { + $sRet = $aMappingData['values'][$value]; + } elseif ($this->GetDefaultValue() != '') { + $sRet = $this->GetDefaultValue(); + } else { + throw new Exception('AttributeMetaEnum::MapValue(): mapping not found for value "' . $value . '" in ' . get_class($oObject) . ', on attribute ' . MetaModel::GetAttributeOrigin($this->GetHostClass(), + $this->GetCode()) . '::' . $this->GetCode()); + } + } + + return $sRet; + } + + public function GetMapRule($sClass) + { + $aMappings = $this->Get('mapping'); + if (array_key_exists($sClass, $aMappings)) { + $aMappingData = $aMappings[$sClass]; + } else { + $sParent = MetaModel::GetParentClass($sClass); + if (is_null($sParent)) { + $aMappingData = null; + } else { + $aMappingData = $this->GetMapRule($sParent); + } + } + + return $aMappingData; + } +} \ No newline at end of file