*/ /** * patTemplate modfifier Number 2 String: N2S * * Convert number to string * * @package patTemplate * @package Modifiers * @author gERD Schaufelberger */ class patTemplate_Modifier_N2s extends patTemplate_Modifier { /** * Modify the value * * Parameter: * - threshold: comma separated list of threshold values from lowest to highest * - string: comma separated list of string values - there must be one more string than thresholds * * @param string value * @return string modified value */ public function modify($value, $params = array()) { $params = array_merge(array( 'threshold' => '1', 'string' => 'lower,higher' ), $params); $threshold = array_map('intval', explode(',', $params['threshold'])); $string = explode(',', $params['string']); $value = intval($value); for ($i = count($threshold) - 1; $i >= 0; --$i ) { if ($value >= $threshold[$i]) { return $string[$i + 1]; } } return $string[0]; } }