mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-24 11:08:45 +02:00
Fix for the "Notifications" tab: use the polymorphism to let each trigger determine which object is "In Scope" and thus can potentially have notifications related to it
SVN:2.0[2689]
This commit is contained in:
@@ -406,18 +406,24 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay
|
|||||||
// Display Notifications after the other tabs since this tab disappears in edition
|
// Display Notifications after the other tabs since this tab disappears in edition
|
||||||
if (!$bEditMode)
|
if (!$bEditMode)
|
||||||
{
|
{
|
||||||
// Get the actual class of the current object
|
// Look for any trigger that considers this object as "In Scope"
|
||||||
// And look for triggers referring to it
|
|
||||||
// If any trigger has been found then display a tab with notifications
|
// If any trigger has been found then display a tab with notifications
|
||||||
//
|
//
|
||||||
$sClass = get_class($this);
|
$oTriggerSet = new CMDBObjectSet(new DBObjectSearch('Trigger'));
|
||||||
$sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
|
$aTriggers = array();
|
||||||
$oTriggerSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObject AS T WHERE T.target_class IN ('$sClassList')"));
|
while($oTrigger = $oTriggerSet->Fetch())
|
||||||
if ($oTriggerSet->Count() > 0)
|
{
|
||||||
|
if($oTrigger->IsInScope($this))
|
||||||
|
{
|
||||||
|
$aTriggers[] = $oTrigger->GetKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count($aTriggers) > 0)
|
||||||
{
|
{
|
||||||
// Display notifications regarding the object
|
// Display notifications regarding the object
|
||||||
$iId = $this->GetKey();
|
$iId = $this->GetKey();
|
||||||
$oNotifSearch = DBObjectSearch::FromOQL("SELECT EventNotificationEmail AS Ev JOIN TriggerOnObject AS T ON Ev.trigger_id = T.id WHERE T.target_class IN ('$sClassList') AND Ev.object_id = $iId");
|
$sTriggersList = implode(',', $aTriggers);
|
||||||
|
$oNotifSearch = DBObjectSearch::FromOQL("SELECT EventNotificationEmail AS Ev JOIN Trigger AS T ON Ev.trigger_id = T.id WHERE T.id IN ($sTriggersList) AND Ev.object_id = $iId");
|
||||||
$oNotifSet = new DBObjectSet($oNotifSearch);
|
$oNotifSet = new DBObjectSet($oNotifSearch);
|
||||||
$sCount = ($oNotifSet->Count() > 0) ? ' ('.$oNotifSet->Count().')' : '';
|
$sCount = ($oNotifSet->Count() > 0) ? ' ('.$oNotifSet->Count().')' : '';
|
||||||
$oPage->SetCurrentTab(Dict::S('UI:NotificationsTab').$sCount);
|
$oPage->SetCurrentTab(Dict::S('UI:NotificationsTab').$sCount);
|
||||||
|
|||||||
@@ -76,6 +76,19 @@ abstract class Trigger extends cmdbAbstractObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the given object is in the scope of this trigger
|
||||||
|
* and can potentially be the subject of notifications
|
||||||
|
* @param DBObject $oObject The object to check
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsInScope(DBObject $oObject)
|
||||||
|
{
|
||||||
|
// By default the answer is no
|
||||||
|
// Overload this function in your own derived class for a different behavior
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class TriggerOnObject extends Trigger
|
abstract class TriggerOnObject extends Trigger
|
||||||
@@ -105,6 +118,18 @@ abstract class TriggerOnObject extends Trigger
|
|||||||
// MetaModel::Init_SetZListItems('standard_search', array('name')); // Criteria of the std search form
|
// 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
|
// MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the given object is in the scope of this trigger
|
||||||
|
* and can potentially be the subject of notifications
|
||||||
|
* @param DBObject $oObject The object to check
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function IsInScope(DBObject $oObject)
|
||||||
|
{
|
||||||
|
$sRootClass = $this->Get('target_class');
|
||||||
|
return ($oObject instanceof $sRootClass);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* To trigger notifications when a ticket is updated from the portal
|
* To trigger notifications when a ticket is updated from the portal
|
||||||
|
|||||||
Reference in New Issue
Block a user