mirror of
https://github.com/Combodo/iTop.git
synced 2026-03-10 11:34:13 +01:00
Compare commits
3 Commits
feature/25
...
feature/at
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1c2f923811 | ||
|
|
24b2852830 | ||
|
|
5ba44a03ea |
@@ -181,6 +181,23 @@ abstract class AttributeDefinition
|
|||||||
return $this->GetSearchType() != static::SEARCH_WIDGET_TYPE_RAW;
|
return $this->GetSearchType() != static::SEARCH_WIDGET_TYPE_RAW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsComputed()
|
||||||
|
{
|
||||||
|
return $this->IsParam('expression');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @throws \OQLException
|
||||||
|
*/
|
||||||
|
protected function GetComputedPrerequisiteAttributes(): array {
|
||||||
|
$oExpression = Expression::FromOQL($this->m_aParams['expression']);
|
||||||
|
return $oExpression->ListRequiredFields();
|
||||||
|
}
|
||||||
|
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $m_sCode;
|
protected $m_sCode;
|
||||||
/** @var array */
|
/** @var array */
|
||||||
@@ -2717,7 +2734,11 @@ class AttributeDBFieldVoid extends AttributeDefinition
|
|||||||
|
|
||||||
public function GetPrerequisiteAttributes($sClass = null)
|
public function GetPrerequisiteAttributes($sClass = null)
|
||||||
{
|
{
|
||||||
return $this->Get("depends_on");
|
$aPrerequisiteAttributes = $this->Get("depends_on");
|
||||||
|
if($this->IsComputed()) {
|
||||||
|
$aPrerequisiteAttributes = array_merge($aPrerequisiteAttributes, $this->GetComputedPrerequisiteAttributes());
|
||||||
|
}
|
||||||
|
return $aPrerequisiteAttributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function IsBasedOnDBColumns()
|
public static function IsBasedOnDBColumns()
|
||||||
@@ -2732,7 +2753,7 @@ class AttributeDBFieldVoid extends AttributeDefinition
|
|||||||
|
|
||||||
public function IsWritable()
|
public function IsWritable()
|
||||||
{
|
{
|
||||||
return !$this->IsMagic();
|
return !$this->IsMagic() && !$this->IsComputed();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetSQLExpr()
|
public function GetSQLExpr()
|
||||||
@@ -2962,14 +2983,12 @@ class AttributeInteger extends AttributeDBField
|
|||||||
|
|
||||||
public function MakeRealValue($proposedValue, $oHostObj)
|
public function MakeRealValue($proposedValue, $oHostObj)
|
||||||
{
|
{
|
||||||
if (is_null($proposedValue))
|
if (is_null($proposedValue) || $proposedValue === '')
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
} elseif(gettype($proposedValue) !== 'integer') {
|
||||||
|
IssueLog::Warning("Trying to set integer attribute ".$this->GetCode()." to type".gettype($proposedValue).".");
|
||||||
}
|
}
|
||||||
if ($proposedValue === '')
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
} // 0 is transformed into '' !
|
|
||||||
|
|
||||||
return (int)$proposedValue;
|
return (int)$proposedValue;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -706,6 +706,8 @@ abstract class DBObject implements iDisplay
|
|||||||
}
|
}
|
||||||
$this->_Set($sAttCode, $realvalue);
|
$this->_Set($sAttCode, $realvalue);
|
||||||
|
|
||||||
|
$this->UpdateDependentComputedAttributes($sAttCode);
|
||||||
|
|
||||||
$this->UpdateMetaAttributes(array($sAttCode));
|
$this->UpdateMetaAttributes(array($sAttCode));
|
||||||
|
|
||||||
// The object has changed, reset caches
|
// The object has changed, reset caches
|
||||||
@@ -6992,5 +6994,28 @@ abstract class DBObject implements iDisplay
|
|||||||
{
|
{
|
||||||
return array_key_exists($sSection, $this->aContext);
|
return array_key_exists($sSection, $this->aContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $sAttCode
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
* @throws CoreException
|
||||||
|
* @throws OQLException
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
private function UpdateDependentComputedAttributes(string $sAttCode): void
|
||||||
|
{
|
||||||
|
foreach (MetaModel::GetDependentAttributes(get_class($this), $sAttCode) as $sCode) {
|
||||||
|
$oAttDef = MetaModel::GetAttributeDef(get_class($this), $sCode);
|
||||||
|
if ($oAttDef->IsComputed()) {
|
||||||
|
$oExpression = Expression::FromOQL($oAttDef->GetParams()['expression']);
|
||||||
|
$value = $this->EvaluateExpression($oExpression);
|
||||||
|
$aAllowedValues = $oAttDef->GetAllowedValues();
|
||||||
|
if(is_null($aAllowedValues) || in_array($value, $aAllowedValues)) {
|
||||||
|
$this->_Set($sCode, $oAttDef->MakeRealValue($value, $this));
|
||||||
|
} ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2661,7 +2661,7 @@ abstract class MetaModel
|
|||||||
*/
|
*/
|
||||||
public static function GetAttributeFlags($sClass, $sState, $sAttCode)
|
public static function GetAttributeFlags($sClass, $sState, $sAttCode)
|
||||||
{
|
{
|
||||||
$iFlags = 0; // By default (if no life cycle) no flag at all
|
$iFlags = 0;
|
||||||
if (self::HasLifecycle($sClass)) {
|
if (self::HasLifecycle($sClass)) {
|
||||||
$aStates = MetaModel::EnumStates($sClass);
|
$aStates = MetaModel::EnumStates($sClass);
|
||||||
if (!array_key_exists($sState, $aStates)) {
|
if (!array_key_exists($sState, $aStates)) {
|
||||||
|
|||||||
@@ -2134,6 +2134,7 @@ EOF
|
|||||||
$this->CompileCommonProperty('default_value', $oField, $aParameters, $sModuleRelativeDir, '');
|
$this->CompileCommonProperty('default_value', $oField, $aParameters, $sModuleRelativeDir, '');
|
||||||
$this->CompileCommonProperty('is_null_allowed', $oField, $aParameters, $sModuleRelativeDir, false);
|
$this->CompileCommonProperty('is_null_allowed', $oField, $aParameters, $sModuleRelativeDir, false);
|
||||||
$this->CompileCommonProperty('allowed_values', $oField, $aParameters, $sModuleRelativeDir);
|
$this->CompileCommonProperty('allowed_values', $oField, $aParameters, $sModuleRelativeDir);
|
||||||
|
$this->CompileCommonProperty('computed', $oField, $aParameters, $sModuleRelativeDir, false);
|
||||||
$aParameters['depends_on'] = $sDependencies;
|
$aParameters['depends_on'] = $sDependencies;
|
||||||
} elseif ($sAttType == 'AttributeEnum') {
|
} elseif ($sAttType == 'AttributeEnum') {
|
||||||
$this->CompileAttributeEnumValues($sModuleRelativeDir, $sClass, $sAttCode, $oField, $aParameters, $sCss);
|
$this->CompileAttributeEnumValues($sModuleRelativeDir, $sClass, $sAttCode, $oField, $aParameters, $sCss);
|
||||||
@@ -2141,6 +2142,7 @@ EOF
|
|||||||
$this->CompileCommonProperty('sql', $oField, $aParameters, $sModuleRelativeDir);
|
$this->CompileCommonProperty('sql', $oField, $aParameters, $sModuleRelativeDir);
|
||||||
$this->CompileCommonProperty('default_value', $oField, $aParameters, $sModuleRelativeDir, '');
|
$this->CompileCommonProperty('default_value', $oField, $aParameters, $sModuleRelativeDir, '');
|
||||||
$this->CompileCommonProperty('is_null_allowed', $oField, $aParameters, $sModuleRelativeDir, false);
|
$this->CompileCommonProperty('is_null_allowed', $oField, $aParameters, $sModuleRelativeDir, false);
|
||||||
|
$this->CompileCommonProperty('computed', $oField, $aParameters, $sModuleRelativeDir, false);
|
||||||
$aParameters['depends_on'] = $sDependencies;
|
$aParameters['depends_on'] = $sDependencies;
|
||||||
} elseif ($sAttType == 'AttributeMetaEnum') {
|
} elseif ($sAttType == 'AttributeMetaEnum') {
|
||||||
$this->CompileAttributeEnumValues($sModuleRelativeDir, $sClass, $sAttCode, $oField, $aParameters, $sCss);
|
$this->CompileAttributeEnumValues($sModuleRelativeDir, $sClass, $sAttCode, $oField, $aParameters, $sCss);
|
||||||
@@ -2269,6 +2271,7 @@ EOF
|
|||||||
$this->CompileCommonProperty('is_null_allowed', $oField, $aParameters, $sModuleRelativeDir, false);
|
$this->CompileCommonProperty('is_null_allowed', $oField, $aParameters, $sModuleRelativeDir, false);
|
||||||
$this->CompileCommonProperty('default_value', $oField, $aParameters, $sModuleRelativeDir, '');
|
$this->CompileCommonProperty('default_value', $oField, $aParameters, $sModuleRelativeDir, '');
|
||||||
$this->CompileCommonProperty('allowed_values', $oField, $aParameters, $sModuleRelativeDir);
|
$this->CompileCommonProperty('allowed_values', $oField, $aParameters, $sModuleRelativeDir);
|
||||||
|
$this->CompileCommonProperty('computed', $oField, $aParameters, $sModuleRelativeDir, false);
|
||||||
$aParameters['depends_on'] = $sDependencies;
|
$aParameters['depends_on'] = $sDependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2413,7 +2416,19 @@ EOF
|
|||||||
}
|
}
|
||||||
$aParameters['thresholds'] = 'array('.implode(', ', $aThresholds).')';
|
$aParameters['thresholds'] = 'array('.implode(', ', $aThresholds).')';
|
||||||
break;
|
break;
|
||||||
|
case 'computed':
|
||||||
|
$oComputed = $oField->GetOptionalElement('computed');
|
||||||
|
if(is_null($oComputed)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sExpression = self::QuoteForPHP($oComputed->GetChildText('expression'));
|
||||||
|
if(is_null($sExpression) || $sExpression === '') {
|
||||||
|
throw new DOMFormatException("missing (or empty) mandatory tag expression under the tag '".$oField->nodeName."'");
|
||||||
|
}
|
||||||
|
|
||||||
|
$aParameters['expression'] = $sExpression;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user