N°917: New AttributeClassState for triggers on state (entering or leaving a state)

This commit is contained in:
Eric
2018-09-26 17:35:34 +02:00
parent 4b08eea998
commit cb7bb3242a
3 changed files with 70 additions and 7 deletions

View File

@@ -3103,7 +3103,7 @@ class AttributeString extends AttributeDBField
}
/**
* An attibute that matches an object class
* An attribute that matches an object class
*
* @package iTopORM
*/
@@ -3161,6 +3161,66 @@ class AttributeClass extends AttributeString
}
/**
* An attribute that matches a class state
*
* @package iTopORM
*/
class AttributeClassState extends AttributeString
{
const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_ENUM;
private $sTargetClass;
/**
* @param \DBObject $oHostObj
*
* @throws \CoreException
*/
public function SetTargetClass($oHostObj)
{
if (!empty($oHostObj))
{
$sTargetClass = $this->Get('class_field');
$sClass = $oHostObj->Get($sTargetClass);
$this->sTargetClass = $sClass;
}
}
public function GetAllowedValues($aArgs = array(), $sContains = '')
{
if (!empty($this->sTargetClass))
{
$aAllowedStates = array();
$aValues = MetaModel::EnumStates($this->sTargetClass);
foreach(array_keys($aValues) as $sState)
{
$aAllowedStates[$sState] = MetaModel::GetStateLabel($this->sTargetClass, $sState);
}
return $aAllowedStates;
}
return null;
}
public function GetAsHTML($sValue, $oHostObject = null, $bLocalize = true)
{
if (empty($sValue))
{
return '';
}
$this->SetTargetClass($oHostObject);
if (!empty($this->sTargetClass))
{
return MetaModel::GetStateLabel($this->sTargetClass, $sValue);
}
return $sValue;
}
}
/**
* An attibute that matches one of the language codes availables in the dictionnary
*