#901 Added the attribute "filter" to the triggers

SVN:trunk[3104]
This commit is contained in:
Romain Quetiez
2014-03-21 10:52:20 +00:00
parent 1ecec1dd6d
commit 82e9e42939
3 changed files with 71 additions and 9 deletions

View File

@@ -64,7 +64,7 @@ abstract class Trigger extends cmdbAbstractObject
public function DoActivate($aContextArgs)
{
// Find the related
// Find the related actions
$oLinkedActions = $this->Get('action_list');
while ($oLink = $oLinkedActions->Fetch())
{
@@ -110,15 +110,39 @@ abstract class TriggerOnObject extends Trigger
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeClass("target_class", array("class_category"=>"bizmodel", "more_values"=>null, "sql"=>"target_class", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
MetaModel::Init_AddAttribute(new AttributeOQL("filter", array("allowed_values"=>null, "sql"=>"filter", "default_value"=>null, "is_null_allowed"=>true, "depends_on"=>array())));
// Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
// Search criteria
// MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
}
public function DoCheckToWrite()
{
parent::DoCheckToWrite();
$sFilter = trim($this->Get('filter'));
if (strlen($sFilter) > 0)
{
try
{
$oSearch = DBObjectSearch::FromOQL($sFilter);
if (!MetaModel::IsParentClass($this->Get('target_class'), $oSearch->GetClass()))
{
$this->m_aCheckIssues[] = Dict::Format('TriggerOnObject:WrongFilterClass', $this->Get('target_class'));
}
}
catch(OqlException $e)
{
$this->m_aCheckIssues[] = Dict::Format('TriggerOnObject:WrongFilterQuery', $e->getMessage());
}
}
}
/**
* Check whether the given object is in the scope of this trigger
* and can potentially be the subject of notifications
@@ -128,7 +152,37 @@ abstract class TriggerOnObject extends Trigger
public function IsInScope(DBObject $oObject)
{
$sRootClass = $this->Get('target_class');
return ($oObject instanceof $sRootClass);
return ($oObject instanceof $sRootClass);
}
public function DoActivate($aContextArgs)
{
$bGo = true;
if (isset($aContextArgs['this->id']))
{
$bGo = $this->IsTargetObject($aContextArgs['this->id']);
}
if ($bGo)
{
parent::DoActivate($aContextArgs);
}
}
public function IsTargetObject($iObjectId)
{
$sFilter = trim($this->Get('filter'));
if (strlen($sFilter) > 0)
{
$oSearch = DBObjectSearch::FromOQL($sFilter);
$oSearch->AddCondition('id', $iObjectId, '=');
$oSet = new DBObjectSet($oSearch);
$bRet = ($oSet->Count() > 0);
}
else
{
$bRet = true;
}
return $bRet;
}
}
/**
@@ -154,7 +208,7 @@ class TriggerOnPortalUpdate extends TriggerOnObject
MetaModel::Init_InheritAttributes();
// Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list
// Search criteria
}
@@ -181,7 +235,7 @@ abstract class TriggerOnStateChange extends TriggerOnObject
MetaModel::Init_AddAttribute(new AttributeString("state", array("allowed_values"=>null, "sql"=>"state", "default_value"=>null, "is_null_allowed"=>false, "depends_on"=>array())));
// Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'state', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class', 'state')); // Attributes to be displayed for a list
// Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
@@ -209,7 +263,7 @@ class TriggerOnStateEnter extends TriggerOnStateChange
MetaModel::Init_InheritAttributes();
// Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'state', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list
// Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
@@ -237,7 +291,7 @@ class TriggerOnStateLeave extends TriggerOnStateChange
MetaModel::Init_InheritAttributes();
// Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'state', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'state', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('target_class', 'state')); // Attributes to be displayed for a list
// Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class', 'state')); // Criteria of the std search form
@@ -265,7 +319,7 @@ class TriggerOnObjectCreate extends TriggerOnObject
MetaModel::Init_InheritAttributes();
// Display lists
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('details', array('description', 'target_class', 'filter', 'action_list')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('finalclass', 'target_class')); // Attributes to be displayed for a list
// Search criteria
MetaModel::Init_SetZListItems('standard_search', array('description', 'target_class')); // Criteria of the std search form

View File

@@ -482,6 +482,10 @@ Dict::Add('EN US', 'English', 'English', array(
'Class:TriggerOnObject+' => 'Trigger on a given class of objects',
'Class:TriggerOnObject/Attribute:target_class' => 'Target class',
'Class:TriggerOnObject/Attribute:target_class+' => '',
'Class:TriggerOnObject/Attribute:filter' => 'Filter',
'Class:TriggerOnObject/Attribute:filter+' => '',
'TriggerOnObject:WrongFilterQuery' => 'Wrong filter query: %1$s',
'TriggerOnObject:WrongFilterClass' => 'The filter query must return objects of class "%1$s"',
));
//

View File

@@ -548,6 +548,10 @@ Opérateurs :<br/>
'Class:TriggerOnObject+' => '',
'Class:TriggerOnObject/Attribute:target_class' => 'Classe cible',
'Class:TriggerOnObject/Attribute:target_class+' => 'label',
'Class:TriggerOnObject/Attribute:filter' => 'Filtre',
'Class:TriggerOnObject/Attribute:filter+' => '',
'TriggerOnObject:WrongFilterQuery' => 'Requête de filtrage incorrecte: %1$s',
'TriggerOnObject:WrongFilterClass' => 'La requête de filtrage doit retourner des objets de la classe "%1$s"',
'Class:TriggerOnStateChange' => 'Trigger on object state change',
'Class:TriggerOnStateChange+' => '',
'Class:TriggerOnStateChange/Attribute:state' => 'Etat',