Skip to content

Commit 55ca66f

Browse files
committed
Add column renderer for currencies
1 parent a6765ba commit 55ca66f

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace wcf\system\gridView\renderer;
4+
5+
use wcf\system\WCF;
6+
use wcf\util\StringUtil;
7+
8+
/**
9+
* Formats the content of a column as a currency.
10+
*
11+
* @author Marcel Werk
12+
* @copyright 2001-2024 WoltLab GmbH
13+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
14+
* @since 6.2
15+
*/
16+
class CurrencyColumnRenderer extends AbstractColumnRenderer
17+
{
18+
public function __construct(
19+
private readonly string $currency,
20+
) {}
21+
22+
#[\Override]
23+
public function render(mixed $value, mixed $context = null): string
24+
{
25+
return \number_format(
26+
\round($value, 2),
27+
2,
28+
WCF::getLanguage()->get('wcf.global.decimalPoint'),
29+
WCF::getLanguage()->get('wcf.global.thousandsSeparator')
30+
) . ' ' . StringUtil::encodeHTML($this->currency);
31+
}
32+
33+
#[\Override]
34+
public function getClasses(): string
35+
{
36+
return 'gridView__column--digits';
37+
}
38+
}

0 commit comments

Comments
 (0)