mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
function-currency-TL
This commit is contained in:
parent
902f9402ba
commit
a15302457e
@ -5,6 +5,8 @@ use Visiosoft\AdvsModule\Adv\Command\appendRequestURL;
|
||||
use Visiosoft\AdvsModule\Adv\Command\GetAd;
|
||||
use Visiosoft\AdvsModule\Adv\Command\isActive;
|
||||
use Visiosoft\AdvsModule\Adv\Command\LatestAds;
|
||||
use Visiosoft\AdvsModule\Currency\Currency;
|
||||
use Visiosoft\AdvsModule\Currency\CurrencyFormat;
|
||||
|
||||
class AdvsModulePlugin extends Plugin
|
||||
{
|
||||
@ -25,6 +27,11 @@ class AdvsModulePlugin extends Plugin
|
||||
|
||||
return $ad;
|
||||
}
|
||||
), new \Twig_SimpleFunction(
|
||||
'currencyFormat',
|
||||
function ($number, $currency = null, array $options = []) {
|
||||
return app(CurrencyFormat::class)->format($number, $currency, $options);
|
||||
}
|
||||
), new \Twig_SimpleFunction(
|
||||
'isActive',
|
||||
function ($name, $type = 'module', $project = 'visiosoft') {
|
||||
|
||||
@ -0,0 +1,42 @@
|
||||
<?php namespace Visiosoft\AdvsModule\Currency;
|
||||
use Anomaly\Streams\Platform\Support\Currency;
|
||||
|
||||
class CurrencyFormat
|
||||
{
|
||||
public function format($number, $currency = null, array $options = [])
|
||||
{
|
||||
$currency = strtoupper($currency ?: config('streams::currencies.default'));
|
||||
|
||||
$direction = array_get(
|
||||
$options,
|
||||
'direction',
|
||||
config('streams::currencies.supported.' . $currency . '.direction', 'ltr')
|
||||
);
|
||||
$separator = array_get(
|
||||
$options,
|
||||
'separator',
|
||||
config('streams::currencies.supported.' . $currency . '.separator', ',')
|
||||
);
|
||||
$decimals = array_get(
|
||||
$options,
|
||||
'decimals',
|
||||
config('streams::currencies.supported.' . $currency . '.decimals', 2)
|
||||
);
|
||||
$point = array_get(
|
||||
$options,
|
||||
'point',
|
||||
config('streams::currencies.supported.' . $currency . '.point', '.')
|
||||
);
|
||||
|
||||
$prefix = null;
|
||||
$suffix = null;
|
||||
|
||||
if (strtolower($direction) == 'ltr') {
|
||||
|
||||
$prefix = app(Currency::class)->symbol($currency);
|
||||
} else {
|
||||
$suffix = app(Currency::class)->symbol($currency);
|
||||
}
|
||||
return $prefix . number_format(($number * 100) / 100, $decimals, $point, $separator) . $suffix;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user