From c2dd61e96bc746a1192c3d6f9dc1548e72d009d8 Mon Sep 17 00:00:00 2001 From: James Cole Date: Wed, 24 Dec 2014 05:58:26 +0100 Subject: [PATCH] Methods to grab the requested currency symbol. #37 --- app/lib/FireflyIII/Form/Form.php | 2 +- app/views/budgets/index.blade.php | 6 ++--- bootstrap/start.php | 44 +++++++++++++++++++++++++++---- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/app/lib/FireflyIII/Form/Form.php b/app/lib/FireflyIII/Form/Form.php index 0435415cd0..13bf163944 100644 --- a/app/lib/FireflyIII/Form/Form.php +++ b/app/lib/FireflyIII/Form/Form.php @@ -123,7 +123,7 @@ class Form $html .= \Form::input('text', $name, $value, $options); break; case 'amount': - $html .= '
'; + $html .= '
'.getCurrencySymbol().'
'; $html .= \Form::input('number', $name, $value, $options); $html .= '
'; break; diff --git a/app/views/budgets/index.blade.php b/app/views/budgets/index.blade.php index 06edd95808..60aa1d4d03 100644 --- a/app/views/budgets/index.blade.php +++ b/app/views/budgets/index.blade.php @@ -100,15 +100,15 @@ @if($budget->currentRep->amount > $budget->spent) - + {{getCurrencySymbol()}} @else - + {{getCurrencySymbol()}} @endif @else No budget - + @endif diff --git a/bootstrap/start.php b/bootstrap/start.php index 35cc8fa52e..259599da65 100644 --- a/bootstrap/start.php +++ b/bootstrap/start.php @@ -9,6 +9,7 @@ if (!function_exists('mf')) { */ function mf($amount, $coloured = true) { + $currencySymbol = getCurrencySymbol(); $amount = floatval($amount); $amount = round($amount, 2); @@ -16,18 +17,51 @@ if (!function_exists('mf')) { if ($coloured === true) { if ($amount === 0.0) { - return '€ ' . $string . ''; + return ''.$currencySymbol.' ' . $string . ''; } if ($amount > 0) { - return '€ ' . $string . ''; + return ''.$currencySymbol.' ' . $string . ''; } - return '€ ' . $string . ''; + return ''.$currencySymbol.' ' . $string . ''; } - - return '€ ' . $string; + // € + return $currencySymbol.' ' . $string; } } + +if (!function_exists('getCurrencySymbol')) { + /** + * @return string + */ + function getCurrencySymbol() + { + if (defined('FFCURRENCYSYMBOL')) { + return FFCURRENCYSYMBOL; + } + if (Cache::has('FFCURRENCYSYMBOL')) { + define('FFCURRENCYSYMBOL', Cache::get('FFCURRENCYSYMBOL')); + + return FFCURRENCYSYMBOL; + } + + /** @var \FireflyIII\Database\TransactionCurrency\TransactionCurrency $currencies */ + $currencies = App::make('FireflyIII\Database\TransactionCurrency\TransactionCurrency'); + + /** @var \FireflyIII\Shared\Preferences\Preferences $preferences */ + $preferences = App::make('FireflyIII\Shared\Preferences\Preferences'); + + $currencyPreference = $preferences->get('currencyPreference', 'EUR'); + $currency = $currencies->findByCode($currencyPreference->data); + + Cache::forever('FFCURRENCYSYMBOL', $currency->symbol); + + define('FFCURRENCYSYMBOL', $currency->symbol); + + return $currency->symbol; + } +} + if (!function_exists('boolstr')) { /** * @param $boolean