mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
Merge pull request #824 from openclassify/vedatakdogan
override currency_* functions
This commit is contained in:
commit
a77320275b
@ -9,8 +9,7 @@ use Visiosoft\AdvsModule\Adv\Command\getPopular;
|
||||
use Visiosoft\AdvsModule\Adv\Command\GetUserAds;
|
||||
use Visiosoft\AdvsModule\Adv\Command\isActive;
|
||||
use Visiosoft\AdvsModule\Adv\Command\LatestAds;
|
||||
use Visiosoft\AdvsModule\Currency\Currency;
|
||||
use Visiosoft\AdvsModule\Currency\CurrencyFormat;
|
||||
use Visiosoft\AdvsModule\Support\Command\Currency;
|
||||
|
||||
class AdvsModulePlugin extends Plugin
|
||||
{
|
||||
@ -31,11 +30,6 @@ 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') {
|
||||
@ -115,6 +109,15 @@ class AdvsModulePlugin extends Plugin
|
||||
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',
|
||||
'direction' => 'ltr',
|
||||
'symbol' => '',
|
||||
'separator' => ',',
|
||||
'point' => '.',
|
||||
'separator' => '.',
|
||||
'point' => ',',
|
||||
'decimals' => 2,
|
||||
],
|
||||
'TRY' => [
|
||||
@ -1143,14 +1143,6 @@ return [
|
||||
'decimals' => 2,
|
||||
'symbol' => 'Sh',
|
||||
],
|
||||
'USD' => [
|
||||
'name' => 'US Dollar',
|
||||
'direction' => 'ltr',
|
||||
'separator' => ',',
|
||||
'point' => '.',
|
||||
'decimals' => 2,
|
||||
'symbol' => '$',
|
||||
],
|
||||
'UYU' => [
|
||||
'name' => 'Peso Uruguayo',
|
||||
'direction' => 'ltr',
|
||||
|
||||
Loading…
Reference in New Issue
Block a user