Merge pull request #545 from openclassify/muhammet

function-currency-TL
This commit is contained in:
Ozcan Durak 2020-05-10 15:10:17 +03:00 committed by GitHub
commit e805752488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 49 additions and 0 deletions

View File

@ -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') {

View File

@ -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;
}
}