monitoring: Rewrite Service::getStateText() to get the optional translated textual representation of a service state

This commit is contained in:
Eric Lippmann 2014-10-29 13:36:24 +01:00
parent 5fc1f85b76
commit d9194c2696

View File

@ -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 * @return string
* @throws InvalidArgumentException If the service state is not valid * @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) { switch ((int) $state) {
case self::STATE_OK: case self::STATE_OK:
$text = mt('monitoring', 'ok'); $text = $translate ? mt('monitoring', 'ok') : 'ok';
break; break;
case self::STATE_WARNING: case self::STATE_WARNING:
$text = mt('monitoring', 'warning'); $text = $translate ? mt('monitoring', 'warning') : 'warning';
break; break;
case self::STATE_CRITICAL: case self::STATE_CRITICAL:
$text = mt('monitoring', 'critical'); $text = $translate ? mt('monitoring', 'critical') : 'critical';
break; break;
case self::STATE_UNKNOWN: case self::STATE_UNKNOWN:
$text = mt('monitoring', 'unknown'); $text = $translate ? mt('monitoring', 'unknown') : 'unknown';
break; break;
case self::STATE_PENDING: case self::STATE_PENDING:
$text = mt('monitoring', 'pending'); $text = $translate ? mt('monitoring', 'pending') : 'pending';
break; break;
default: default:
throw new InvalidArgumentException('Invalid service state \'%s\'', $state); throw new InvalidArgumentException('Invalid service state \'%s\'', $state);
break;
} }
return $text; return $text;
} }