diff --git a/application/cmdbabstract.class.inc.php b/application/cmdbabstract.class.inc.php index 1a8522c7d..804aeb67f 100644 --- a/application/cmdbabstract.class.inc.php +++ b/application/cmdbabstract.class.inc.php @@ -232,26 +232,25 @@ EOF * last plugin to set the message for a given message id) In practice, standard messages are recorded at the end * but they will not overwrite existing messages * + * @see SetSessionMessageFromInstance() to call from within an instance + * * @param string $sClass The class of the object (must be the final class) * @param int $iKey The identifier of the object * @param string $sMessageId Your id or one of the well-known ids: 'create', 'update' and 'apply_stimulus' * @param string $sMessage The HTML message (must be correctly escaped) - * @param string $sSeverity Any of the following: ok, info, error. + * @param string $sSeverity Any of the \WebPage::ENUM_SESSION_MESSAGE_SEVERITY_XXX constants * @param float $fRank Ordering of the message: smallest displayed first (can be negative) * @param bool $bMustNotExist Do not alter any existing message (considering the id) * - * @see SetSessionMessageFromInstance() to call from within an instance + * @return void */ - public static function SetSessionMessage( - $sClass, $iKey, $sMessageId, $sMessage, $sSeverity, $fRank, $bMustNotExist = false - ) { + public static function SetSessionMessage($sClass, $iKey, $sMessageId, $sMessage, $sSeverity, $fRank, $bMustNotExist = false) + { $sMessageKey = $sClass.'::'.$iKey; - if (!isset($_SESSION['obj_messages'][$sMessageKey])) - { + if (!isset($_SESSION['obj_messages'][$sMessageKey])) { $_SESSION['obj_messages'][$sMessageKey] = array(); } - if (!$bMustNotExist || !array_key_exists($sMessageId, $_SESSION['obj_messages'][$sMessageKey])) - { + if (!$bMustNotExist || !array_key_exists($sMessageId, $_SESSION['obj_messages'][$sMessageKey])) { $_SESSION['obj_messages'][$sMessageKey][$sMessageId] = array( 'rank' => $fRank, 'severity' => $sSeverity, diff --git a/sources/application/WebPage/WebPage.php b/sources/application/WebPage/WebPage.php index 28681b16a..c21530983 100644 --- a/sources/application/WebPage/WebPage.php +++ b/sources/application/WebPage/WebPage.php @@ -50,6 +50,34 @@ class WebPage implements Page * @since 2.7.0 N°2529 */ const PAGES_CHARSET = 'utf-8'; + + /** + * @var string + * @since 3.0.0 + */ + public const ENUM_SESSION_MESSAGE_SEVERITY_INFO = 'INFO'; + /** + * @var string + * @since 3.0.0 + */ + public const ENUM_SESSION_MESSAGE_SEVERITY_OK = 'ok'; + /** + * @var string + * @since 3.0.0 + */ + public const ENUM_SESSION_MESSAGE_SEVERITY_WARNING = 'warning'; + /** + * @var string + * @since 3.0.0 + */ + public const ENUM_SESSION_MESSAGE_SEVERITY_ERROR = 'error'; + + + /** + * @var string + * @since 3.0.0 + */ + public const DEFAULT_SESSION_MESSAGE_SEVERITY = self::ENUM_SESSION_MESSAGE_SEVERITY_INFO; const DEFAULT_PAGE_TEMPLATE_REL_PATH = 'pages/backoffice/webpage/layout'; protected $s_title; @@ -92,7 +120,6 @@ class WebPage implements Page protected $sTemplateRelPath; - /** * @var bool|string|string[] */ @@ -150,16 +177,16 @@ class WebPage implements Page $aReadMessages[] = $aMessageData['message']; $aRanks[] = $aMessageData['rank']; switch ($aMessageData['severity']) { - case 'ok': + case static::ENUM_SESSION_MESSAGE_SEVERITY_OK: $aMessages[] = AlertUIBlockFactory::MakeForSuccess('', $aMessageData['message']); break; - case 'warning': + case static::ENUM_SESSION_MESSAGE_SEVERITY_WARNING: $aMessages[] = AlertUIBlockFactory::MakeForWarning('', $aMessageData['message']); break; - case 'error': + case static::ENUM_SESSION_MESSAGE_SEVERITY_ERROR: $aMessages[] = AlertUIBlockFactory::MakeForDanger('', $aMessageData['message']); break; - case 'info': + case static::ENUM_SESSION_MESSAGE_SEVERITY_INFO: default: $aMessages[] = AlertUIBlockFactory::MakeForInformation('', $aMessageData['message']); break;