/** * @param integer $n * @param string $type * @param integer $pad * * @return string */ private function make_counter($n, $type, $pad = null) { $n = intval($n); $text = ""; $uppercase = false; switch ($type) { case "decimal-leading-zero": case "decimal": case "1": if ($pad) { $text = str_pad($n, $pad, "0", STR_PAD_LEFT); } else { $text = $n; } break; case "upper-alpha": case "upper-latin": case "A": $uppercase = true; case "lower-alpha": case "lower-latin": case "a": $text = chr($n % 26 + ord('a') - 1); break; case "upper-roman": case "I": $uppercase = true; case "lower-roman": case "i": $text = Helpers::dec2roman($n); break; case "lower-greek": $text = Helpers::unichr($n + 944); break; } if ($uppercase) { $text = strtoupper($text); } return "{$text}."; }
function counter_value($id = self::DEFAULT_COUNTER, $type = "decimal") { $type = mb_strtolower($type); if (!isset($this->_counters[$id])) { $this->_counters[$id] = 0; } $value = $this->_counters[$id]; switch ($type) { default: case "decimal": return $value; case "decimal-leading-zero": return str_pad($value, 2, "0", STR_PAD_LEFT); case "lower-roman": return Helpers::dec2roman($value); case "upper-roman": return mb_strtoupper(Helpers::dec2roman($value)); case "lower-latin": case "lower-alpha": return chr($value % 26 + ord('a') - 1); case "upper-latin": case "upper-alpha": return chr($value % 26 + ord('A') - 1); case "lower-greek": return Helpers::unichr($value + 944); case "upper-greek": return Helpers::unichr($value + 912); } }