[TASK] phpdoc: Use boolean/integer instead of bool/int
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Format / CurrencyViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Format;
3
4 /* *
5 * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13 /**
14 * Formats a given float to a currency representation.
15 *
16 * = Examples =
17 *
18 * <code title="Defaults">
19 * <f:format.currency>123.456</f:format.currency>
20 * </code>
21 * <output>
22 * 123,46
23 * </output>
24 *
25 * <code title="All parameters">
26 * <f:format.currency currencySign="$" decimalSeparator="." thousandsSeparator="," prependCurrency="TRUE" separateCurrency="FALSE" decimals="2">54321</f:format.currency>
27 * </code>
28 * <output>
29 * $54,321.00
30 * </output>
31 *
32 * <code title="Inline notation">
33 * {someNumber -> f:format.currency(thousandsSeparator: ',', currencySign: '€')}
34 * </code>
35 * <output>
36 * 54,321,00 €
37 * (depending on the value of {someNumber})
38 * </output>
39 *
40 * @api
41 */
42 class CurrencyViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
43
44 /**
45 * @param string $currencySign (optional) The currency sign, eg $ or €.
46 * @param string $decimalSeparator (optional) The separator for the decimal point.
47 * @param string $thousandsSeparator (optional) The thousands separator.
48 * @param boolean $prependCurrency (optional) Select if the curreny sign should be prepended
49 * @param boolean $separateCurrency (optional) Separate the currency sign from the number by a single space, defaults to true due to backwards compatibility
50 * @param integer $decimals (optional) Set decimals places.
51 * @return string the formatted amount.
52 * @api
53 */
54 public function render($currencySign = '', $decimalSeparator = ',', $thousandsSeparator = '.', $prependCurrency = FALSE, $separateCurrency = TRUE, $decimals = 2) {
55 $floatToFormat = $this->renderChildren();
56 if (empty($floatToFormat)) {
57 $floatToFormat = 0.0;
58 } else {
59 $floatToFormat = floatval($floatToFormat);
60 }
61 $output = number_format($floatToFormat, $decimals, $decimalSeparator, $thousandsSeparator);
62 if ($currencySign !== '') {
63 $currencySeparator = $separateCurrency ? ' ' : '';
64 if ($prependCurrency === TRUE) {
65 $output = $currencySign . $currencySeparator . $output;
66 } else {
67 $output = $output . $currencySeparator . $currencySign;
68 }
69 }
70 return $output;
71 }
72 }
73
74 ?>