mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-24 22:11:01 -06:00
override currency_* functions
This commit is contained in:
parent
95b501e484
commit
1d16e7585e
@ -9,8 +9,7 @@ use Visiosoft\AdvsModule\Adv\Command\getPopular;
|
|||||||
use Visiosoft\AdvsModule\Adv\Command\GetUserAds;
|
use Visiosoft\AdvsModule\Adv\Command\GetUserAds;
|
||||||
use Visiosoft\AdvsModule\Adv\Command\isActive;
|
use Visiosoft\AdvsModule\Adv\Command\isActive;
|
||||||
use Visiosoft\AdvsModule\Adv\Command\LatestAds;
|
use Visiosoft\AdvsModule\Adv\Command\LatestAds;
|
||||||
use Visiosoft\AdvsModule\Currency\Currency;
|
use Visiosoft\AdvsModule\Support\Command\Currency;
|
||||||
use Visiosoft\AdvsModule\Currency\CurrencyFormat;
|
|
||||||
|
|
||||||
class AdvsModulePlugin extends Plugin
|
class AdvsModulePlugin extends Plugin
|
||||||
{
|
{
|
||||||
@ -31,11 +30,6 @@ class AdvsModulePlugin extends Plugin
|
|||||||
|
|
||||||
return $ad;
|
return $ad;
|
||||||
}
|
}
|
||||||
), new \Twig_SimpleFunction(
|
|
||||||
'currencyFormat',
|
|
||||||
function ($number, $currency = null, array $options = []) {
|
|
||||||
return app(CurrencyFormat::class)->format($number, $currency, $options);
|
|
||||||
}
|
|
||||||
), new \Twig_SimpleFunction(
|
), new \Twig_SimpleFunction(
|
||||||
'isActive',
|
'isActive',
|
||||||
function ($name, $type = 'module', $project = 'visiosoft') {
|
function ($name, $type = 'module', $project = 'visiosoft') {
|
||||||
@ -115,6 +109,15 @@ class AdvsModulePlugin extends Plugin
|
|||||||
return $popular;
|
return $popular;
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
|
new \Twig_SimpleFunction(
|
||||||
|
'currency_*',
|
||||||
|
function ($name) {
|
||||||
|
return call_user_func_array(
|
||||||
|
[app(Currency::class), camel_case($name)],
|
||||||
|
array_slice(func_get_args(), 1)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,42 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,91 @@
|
|||||||
|
<?php namespace Visiosoft\AdvsModule\Support\Command;
|
||||||
|
|
||||||
|
class Currency
|
||||||
|
{
|
||||||
|
|
||||||
|
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 = $this->symbol($currency);
|
||||||
|
} else {
|
||||||
|
$suffix = $this->symbol($currency);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$decimal_value = $this->getDecimalValue($number);
|
||||||
|
|
||||||
|
if (setting_value('visiosoft.field_type.decimal::showDecimalMaxPrice') < intval($number) and $decimal_value == 0) {
|
||||||
|
if (!setting_value('visiosoft.field_type.decimal::showDecimal')) {
|
||||||
|
$decimals = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $prefix . number_format($number, $decimals, $point, str_replace(' ', ' ', $separator)) . $suffix;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function normalize($number, $currency = null, array $options = [])
|
||||||
|
{
|
||||||
|
$currency = strtoupper($currency ?: config('streams::currencies.default'));
|
||||||
|
|
||||||
|
$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', '.')
|
||||||
|
);
|
||||||
|
|
||||||
|
return number_format(floor(($number * 100)) / 100, $decimals, $point, $separator);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function symbol($currency = null)
|
||||||
|
{
|
||||||
|
if (!$currency) {
|
||||||
|
$currency = config('streams::currencies.default');
|
||||||
|
}
|
||||||
|
|
||||||
|
return config('streams::currencies.supported.' . strtoupper($currency) . '.symbol');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDecimalValue($price)
|
||||||
|
{
|
||||||
|
$whole = (int)$price;
|
||||||
|
$decimal = ($price - $whole) * 100;
|
||||||
|
return (int)number_format($decimal);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -43,8 +43,8 @@ return [
|
|||||||
'name' => 'US Dollar',
|
'name' => 'US Dollar',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
'symbol' => '',
|
'symbol' => '',
|
||||||
'separator' => ',',
|
'separator' => '.',
|
||||||
'point' => '.',
|
'point' => ',',
|
||||||
'decimals' => 2,
|
'decimals' => 2,
|
||||||
],
|
],
|
||||||
'TRY' => [
|
'TRY' => [
|
||||||
@ -1143,14 +1143,6 @@ return [
|
|||||||
'decimals' => 2,
|
'decimals' => 2,
|
||||||
'symbol' => 'Sh',
|
'symbol' => 'Sh',
|
||||||
],
|
],
|
||||||
'USD' => [
|
|
||||||
'name' => 'US Dollar',
|
|
||||||
'direction' => 'ltr',
|
|
||||||
'separator' => ',',
|
|
||||||
'point' => '.',
|
|
||||||
'decimals' => 2,
|
|
||||||
'symbol' => '$',
|
|
||||||
],
|
|
||||||
'UYU' => [
|
'UYU' => [
|
||||||
'name' => 'Peso Uruguayo',
|
'name' => 'Peso Uruguayo',
|
||||||
'direction' => 'ltr',
|
'direction' => 'ltr',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user