From d9194c269675e89b487fb3c69b15804cd58495ef Mon Sep 17 00:00:00 2001 From: Eric Lippmann Date: Wed, 29 Oct 2014 13:36:24 +0100 Subject: [PATCH] monitoring: Rewrite Service::getStateText() to get the optional translated textual representation of a service state --- .../library/Monitoring/Object/Service.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/modules/monitoring/library/Monitoring/Object/Service.php b/modules/monitoring/library/Monitoring/Object/Service.php index 36a763101..7a0812d8b 100644 --- a/modules/monitoring/library/Monitoring/Object/Service.php +++ b/modules/monitoring/library/Monitoring/Object/Service.php @@ -199,34 +199,35 @@ class Service extends MonitoredObject } /** - * Get the translated textual representation of a service state + * Get the optional translated textual representation of a service state * - * @param int $state + * @param int $state + * @param bool $translate * * @return string * @throws InvalidArgumentException If the service state is not valid */ - public static function getStateText($state) + public static function getStateText($state, $translate = false) { + $translate = (bool) $translate; switch ((int) $state) { case self::STATE_OK: - $text = mt('monitoring', 'ok'); + $text = $translate ? mt('monitoring', 'ok') : 'ok'; break; case self::STATE_WARNING: - $text = mt('monitoring', 'warning'); + $text = $translate ? mt('monitoring', 'warning') : 'warning'; break; case self::STATE_CRITICAL: - $text = mt('monitoring', 'critical'); + $text = $translate ? mt('monitoring', 'critical') : 'critical'; break; case self::STATE_UNKNOWN: - $text = mt('monitoring', 'unknown'); + $text = $translate ? mt('monitoring', 'unknown') : 'unknown'; break; case self::STATE_PENDING: - $text = mt('monitoring', 'pending'); + $text = $translate ? mt('monitoring', 'pending') : 'pending'; break; default: throw new InvalidArgumentException('Invalid service state \'%s\'', $state); - break; } return $text; }