From 5d8acbb41aff4eaa60457cb581e46d72d528b692 Mon Sep 17 00:00:00 2001 From: Denis Flaven Date: Wed, 3 Aug 2011 10:36:34 +0000 Subject: [PATCH] New type of trigger: TriggerOnPortalUpdate, called when the end-user updates a ticket from the portal. SVN:trunk[1420] --- application/cmdbabstract.class.inc.php | 19 +++++++++------- core/trigger.class.inc.php | 28 ++++++++++++++++++++++++ dictionaries/dictionary.itop.core.php | 9 ++++++++ dictionaries/fr.dictionary.itop.core.php | 2 ++ portal/index.php | 8 +++++++ 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index fc81176de..0176c0110 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -353,6 +353,12 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay } $oPage->SetCurrentTab(''); + foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) + { + $oExtensionInstance->OnDisplayRelations($this, $oPage, $bEditMode); + } + + // Display Notifications after the other tabs since this tab disappears in edition if (!$bEditMode) { // Get the actual class of the current object @@ -364,19 +370,16 @@ abstract class cmdbAbstractObject extends CMDBObject implements iDisplay $oTriggerSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT TriggerOnObject AS T WHERE T.target_class IN ('$sClassList')")); if ($oTriggerSet->Count() > 0) { - $oPage->SetCurrentTab(Dict::S('UI:NotificationsTab')); - // Display notifications regarding the object $iId = $this->GetKey(); - $oBlock = new DisplayBlock(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"), 'list', false); + $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"); + $oNotifSet = new DBObjectSet($oNotifSearch); + $sCount = ($oNotifSet->Count() > 0) ? ' ('.$oNotifSet->Count().')' : ''; + $oPage->SetCurrentTab(Dict::S('UI:NotificationsTab').$sCount); + $oBlock = new DisplayBlock($oNotifSearch, 'list', false); $oBlock->Display($oPage, 'notifications', array('menu' => false)); } } - - foreach (MetaModel::EnumPlugins('iApplicationUIExtension') as $oExtensionInstance) - { - $oExtensionInstance->OnDisplayRelations($this, $oPage, $bEditMode); - } } function GetBareProperties(WebPage $oPage, $bEditMode = false) diff --git a/core/trigger.class.inc.php b/core/trigger.class.inc.php index 604e42780..77bfae61f 100644 --- a/core/trigger.class.inc.php +++ b/core/trigger.class.inc.php @@ -105,6 +105,34 @@ abstract class TriggerOnObject extends Trigger // MetaModel::Init_SetZListItems('advanced_search', array('name')); // Criteria of the advanced search form } } +/** + * To trigger notifications when a ticket is updated from the portal + */ +class TriggerOnPortalUpdate extends TriggerOnObject +{ + public static function Init() + { + $aParams = array + ( + "category" => "core/cmdb", + "key_type" => "autoincrement", + "name_attcode" => "description", + "state_attcode" => "", + "reconc_keys" => array(), + "db_table" => "priv_trigger_onportalupdate", + "db_key_field" => "id", + "db_finalclass_field" => "", + "display_template" => "", + ); + MetaModel::Init_Params($aParams); + 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('list', array('finalclass', 'target_class', 'description')); // Attributes to be displayed for a list + // Search criteria + } +} abstract class TriggerOnStateChange extends TriggerOnObject { diff --git a/dictionaries/dictionary.itop.core.php b/dictionaries/dictionary.itop.core.php index f0f7a162d..bf506b526 100644 --- a/dictionaries/dictionary.itop.core.php +++ b/dictionaries/dictionary.itop.core.php @@ -452,6 +452,15 @@ Dict::Add('EN US', 'English', 'English', array( 'Class:TriggerOnObject/Attribute:target_class+' => '', )); +// +// Class: TriggerOnPortalUpdate +// + +Dict::Add('EN US', 'English', 'English', array( + 'Class:TriggerOnPortalUpdate' => 'Trigger (when updated from the portal)', + 'Class:TriggerOnPortalUpdate+' => 'Trigger on a end-user\'s update from the portal', +)); + // // Class: TriggerOnStateChange // diff --git a/dictionaries/fr.dictionary.itop.core.php b/dictionaries/fr.dictionary.itop.core.php index 6278438df..179fe8da0 100644 --- a/dictionaries/fr.dictionary.itop.core.php +++ b/dictionaries/fr.dictionary.itop.core.php @@ -48,6 +48,8 @@ Dict::Add('FR FR', 'French', 'Français', array( 'Class:ActionEmail/Attribute:importance/Value:low+' => '', 'Class:ActionEmail/Attribute:importance/Value:normal' => 'Normale', 'Class:ActionEmail/Attribute:importance/Value:normal+' => '', + 'Class:TriggerOnPortalUdpate' => 'Déclencheur sur mise à jour depuis le portail', + 'Class:TriggerOnPortalUdpate+' => '', 'Class:TriggerOnStateEnter' => 'Déclencheur sur un objet entrant dans un état', 'Class:TriggerOnStateEnter+' => '', 'Class:TriggerOnStateLeave' => 'Déclencheur sur un objet quitant un état', diff --git a/portal/index.php b/portal/index.php index 520986976..5ced17ec3 100644 --- a/portal/index.php +++ b/portal/index.php @@ -966,6 +966,14 @@ function AddComment($oP, $id) $iChangeId = $oMyChange->DBInsert(); $oRequest->DBUpdateTracked($oMyChange); $oP->p("

".Dict::Format('UI:Class_Object_Updated', MetaModel::GetName(get_class($oRequest)), $oRequest->GetName())."

\n"); + + // If there is any trigger for the Portal Update, then activate them + $sOQL = "SELECT TriggerOnPortalUpdate WHERE target_class ='UserRequest'"; + $oSet = new DBObjectSet(DBObjectSearch::FromOQL($sOQL)); + while($oTrigger = $oSet->Fetch()) + { + $oTrigger->DoActivate($oRequest->ToArgs('this')); + } } else {