From cc4e1ea104076a77d45e2129996290c8dcc8374f Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 24 Jan 2020 17:43:59 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B0985=20-=20Add=20applicable=20contexts=20?= =?UTF-8?q?on=20Trigger=20(Add=20portal=20contexts)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/attributedef.class.inc.php | 48 ++++++++++++++++++++++-- core/contexttag.class.inc.php | 27 ++++++++++++- core/trigger.class.inc.php | 3 +- dictionaries/en.dictionary.itop.core.php | 19 ++++------ dictionaries/fr.dictionary.itop.core.php | 25 ++++++------ 5 files changed, 92 insertions(+), 30 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 9111f0492..c18bd5d70 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -10090,15 +10090,20 @@ class AttributeEnumSet extends AttributeSet return array_merge(parent::ListExpectedParams(), array('possible_values', 'is_null_allowed', 'max_items')); } - public function GetPossibleValues($aArgs = array(), $sContains = '') + private function GetRawValues($aArgs = array(), $sContains = '') { $oValSetDef = $this->Get('possible_values'); if (!$oValSetDef) { - return null; + return array(); } - $aRawValues = $oValSetDef->GetValues($aArgs, $sContains); + return $oValSetDef->GetValues($aArgs, $sContains); + } + + public function GetPossibleValues($aArgs = array(), $sContains = '') + { + $aRawValues = $this->GetRawValues($aArgs, $sContains); $aLocalizedValues = array(); foreach($aRawValues as $sKey => $sValue) { @@ -10110,6 +10115,12 @@ class AttributeEnumSet extends AttributeSet public function GetValueLabel($sValue) { + $aValues = $this->GetRawValues(); + if (isset($aValues[$sValue])) + { + $sValue = $aValues[$sValue]; + } + if (is_null($sValue)) { // Unless a specific label is defined for the null value of this enum, use a generic "undefined" label @@ -10193,6 +10204,37 @@ class AttributeEnumSet extends AttributeSet } +class AttributeContextSet extends AttributeEnumSet +{ + + public function GetPossibleValues($aArgs = array(), $sContains = '') + { + $oValSetDef = $this->Get('possible_values'); + if (!$oValSetDef) + { + return null; + } + + return $oValSetDef->GetValues($aArgs, $sContains); + } + + public function GetValueLabel($sValue) + { + $aValues = $this->GetPossibleValues(); + if (in_array($sValue, $aValues)) + { + return $aValues[$sValue]; + } + return Dict::S('Enum:Undefined'); + } + + public function GetValueDescription($sValue) + { + return ''; + } + +} + class AttributeClassAttCodeSet extends AttributeSet { const SEARCH_WIDGET_TYPE = self::SEARCH_WIDGET_TYPE_STRING; diff --git a/core/contexttag.class.inc.php b/core/contexttag.class.inc.php index e3725de13..13f0c1d82 100644 --- a/core/contexttag.class.inc.php +++ b/core/contexttag.class.inc.php @@ -91,12 +91,37 @@ class ContextTag */ public static function GetTags() { - return array( + $aRawTags = array( ContextTag::TAG_REST, ContextTag::TAG_SYNCHRO, ContextTag::TAG_SETUP, ContextTag::TAG_CONSOLE, ContextTag::TAG_CRON, ContextTag::TAG_PORTAL); + + $aTags = array(); + + foreach ($aRawTags as $sRawTag) + { + $aTags[$sRawTag] = Dict::S("Core:Context={$sRawTag}"); + } + + $aPortalsConf = PortalDispatcherData::GetData(); + $aDispatchers = array(); + foreach ($aPortalsConf as $sPortalId => $aConf) + { + $sHandlerClass = $aConf['handler']; + $aDispatchers[$sPortalId] = new $sHandlerClass($sPortalId); + } + + foreach ($aDispatchers as $sPortalId => $oDispatcher) + { + if ($sPortalId != 'backoffice') + { + $aTags['Portal:'.$sPortalId] = $oDispatcher->GetLabel(); + } + } + + return $aTags; } } diff --git a/core/trigger.class.inc.php b/core/trigger.class.inc.php index 9ad798699..676ea1a7d 100644 --- a/core/trigger.class.inc.php +++ b/core/trigger.class.inc.php @@ -57,8 +57,7 @@ abstract class Trigger extends cmdbAbstractObject MetaModel::Init_AddAttribute(new AttributeString("description", array("allowed_values" => null, "sql" => "description", "default_value" => null, "is_null_allowed" => false, "depends_on" => array()))); MetaModel::Init_AddAttribute(new AttributeLinkedSetIndirect("action_list", array("linked_class" => "lnkTriggerAction", "ext_key_to_me" => "trigger_id", "ext_key_to_remote" => "action_id", "allowed_values" => null, "count_min" => 1, "count_max" => 0, "depends_on" => array()))); $aTags = ContextTag::GetTags(); - $sTags = implode(',', $aTags); - MetaModel::Init_AddAttribute( new AttributeEnumSet("context", array("allowed_values" => null, "possible_values" => new ValueSetEnum($sTags), "sql" => "context", "depends_on" => array(), "is_null_allowed" => true, "max_items" => 12))); + MetaModel::Init_AddAttribute( new AttributeEnumSet("context", array("allowed_values" => null, "possible_values" => new ValueSetEnum($aTags), "sql" => "context", "depends_on" => array(), "is_null_allowed" => true, "max_items" => 12))); // Display lists MetaModel::Init_SetZListItems('details', array('finalclass', 'description', 'context', 'action_list')); // Attributes to be displayed for the complete details diff --git a/dictionaries/en.dictionary.itop.core.php b/dictionaries/en.dictionary.itop.core.php index 9399c5bfd..78c576e7b 100644 --- a/dictionaries/en.dictionary.itop.core.php +++ b/dictionaries/en.dictionary.itop.core.php @@ -203,6 +203,13 @@ Operators:
'Core:AttributeTag' => 'Tags', 'Core:AttributeTag+' => 'Tags', + + 'Core:Context=REST/JSON' => 'REST', + 'Core:Context=Synchro' => 'Synchro', + 'Core:Context=Setup' => 'Setup', + 'Core:Context=GUI:Console' => 'Console', + 'Core:Context=CRON' => 'CRON', + 'Core:Context=GUI:Portal' => 'Portal', )); @@ -535,18 +542,6 @@ Dict::Add('EN US', 'English', 'English', array( 'Class:Trigger/Attribute:action_list+' => 'Actions performed when the trigger is activated', 'Class:Trigger/Attribute:finalclass' => 'Trigger sub-class', 'Class:Trigger/Attribute:finalclass+' => 'Name of the final class', - 'Class:Trigger/Attribute:context/Value:REST/JSON' => 'REST', - 'Class:Trigger/Attribute:context/Value:REST/JSON+' => 'REST/JSON', - 'Class:Trigger/Attribute:context/Value:Synchro' => 'Synchro', - 'Class:Trigger/Attribute:context/Value:Synchro+' => 'Synchro', - 'Class:Trigger/Attribute:context/Value:Setup' => 'Setup', - 'Class:Trigger/Attribute:context/Value:Setup+' => 'Setup', - 'Class:Trigger/Attribute:context/Value:GUI:Console' => 'Console', - 'Class:Trigger/Attribute:context/Value:GUI:Console+' => 'GUI:Console', - 'Class:Trigger/Attribute:context/Value:CRON' => 'CRON', - 'Class:Trigger/Attribute:context/Value:CRON+' => 'CRON', - 'Class:Trigger/Attribute:context/Value:GUI:Portal' => 'Portal', - 'Class:Trigger/Attribute:context/Value:GUI:Portal+' => 'GUI:Portal', )); // diff --git a/dictionaries/fr.dictionary.itop.core.php b/dictionaries/fr.dictionary.itop.core.php index 3213c067b..fadb9ef86 100644 --- a/dictionaries/fr.dictionary.itop.core.php +++ b/dictionaries/fr.dictionary.itop.core.php @@ -201,6 +201,19 @@ Opérateurs :
'Core:AttributeTag' => 'Taxon', 'Core:AttributeTag+' => 'Taxon', + + 'Core:Context=REST/JSON' => 'REST', + 'Core:Context=REST/JSON+' => 'REST/JSON', + 'Core:Context=Synchro' => 'Synchro', + 'Core:Context=Synchro+' => 'Synchro', + 'Core:Context=Setup' => 'Setup', + 'Core:Context=Setup+' => 'Setup', + 'Core:Context=GUI:Console' => 'Console', + 'Core:Context=GUI:Console+' => 'GUI:Console', + 'Core:Context=CRON' => 'CRON', + 'Core:Context=CRON+' => 'CRON', + 'Core:Context=GUI:Portal' => 'Portal', + 'Core:Context=GUI:Portal+' => 'GUI:Portal', )); @@ -533,18 +546,6 @@ Dict::Add('FR FR', 'French', 'Français', array( 'Class:Trigger/Attribute:action_list+' => '', 'Class:Trigger/Attribute:finalclass' => 'Sous-classe de Déclencheur', 'Class:Trigger/Attribute:finalclass+' => 'Nom de la classe instanciable', - 'Class:Trigger/Attribute:context/Value:REST/JSON' => 'REST', - 'Class:Trigger/Attribute:context/Value:REST/JSON+' => 'REST/JSON', - 'Class:Trigger/Attribute:context/Value:Synchro' => 'Synchro', - 'Class:Trigger/Attribute:context/Value:Synchro+' => 'Synchro', - 'Class:Trigger/Attribute:context/Value:Setup' => 'Setup', - 'Class:Trigger/Attribute:context/Value:Setup+' => 'Setup', - 'Class:Trigger/Attribute:context/Value:GUI:Console' => 'Console', - 'Class:Trigger/Attribute:context/Value:GUI:Console+' => 'GUI:Console', - 'Class:Trigger/Attribute:context/Value:CRON' => 'CRON', - 'Class:Trigger/Attribute:context/Value:CRON+' => 'CRON', - 'Class:Trigger/Attribute:context/Value:GUI:Portal' => 'Portal', - 'Class:Trigger/Attribute:context/Value:GUI:Portal+' => 'GUI:Portal', )); //