mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°917: New AttributeClassState for triggers on state (entering or leaving a state)
This commit is contained in:
@@ -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
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user