mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-07 06:31:22 +00:00
Changed a lot of parameters.
This commit is contained in:
@@ -18,12 +18,12 @@ class Amount
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $amount
|
||||
* @param bool $coloured
|
||||
* @param string $amount
|
||||
* @param bool $coloured
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format($amount, $coloured = true)
|
||||
public function format(string $amount, bool $coloured = true)
|
||||
{
|
||||
return $this->formatAnything($this->getDefaultCurrency(), $amount, $coloured);
|
||||
}
|
||||
@@ -33,16 +33,17 @@ class Amount
|
||||
* as a currency, given two things: the currency required and the current locale.
|
||||
*
|
||||
* @param TransactionCurrency $format
|
||||
* @param $amount
|
||||
* @param string $amount
|
||||
* @param bool $coloured
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formatAnything(TransactionCurrency $format, $amount, $coloured = true)
|
||||
public function formatAnything(TransactionCurrency $format, string $amount, bool $coloured = true)
|
||||
{
|
||||
$locale = setlocale(LC_MONETARY, 0);
|
||||
$float = floatval($amount);
|
||||
$formatter = new NumberFormatter($locale, NumberFormatter::CURRENCY);
|
||||
$result = $formatter->formatCurrency($amount, $format->code);
|
||||
$result = $formatter->formatCurrency($float, $format->code);
|
||||
|
||||
if ($coloured === true) {
|
||||
if ($amount == 0) {
|
||||
@@ -66,7 +67,7 @@ class Amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formatJournal(TransactionJournal $journal, $coloured = true)
|
||||
public function formatJournal(TransactionJournal $journal, bool $coloured = true)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($journal->id);
|
||||
@@ -101,7 +102,7 @@ class Amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formatTransaction(Transaction $transaction, $coloured = true)
|
||||
public function formatTransaction(Transaction $transaction, bool $coloured = true)
|
||||
{
|
||||
$currency = $transaction->transactionJournal->transactionCurrency;
|
||||
|
||||
@@ -115,7 +116,7 @@ class Amount
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function formatWithSymbol($symbol, $amount, $coloured = true)
|
||||
public function formatWithSymbol(string $symbol, string $amount, $coloured = true)
|
||||
{
|
||||
return $this->formatAnything($this->getDefaultCurrency(), $amount, $coloured);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace FireflyIII\Support\Binder;
|
||||
|
||||
use Auth;
|
||||
use FireflyIII\Models\Account;
|
||||
use Illuminate\Support\Collection;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
@@ -27,7 +28,7 @@ class AccountList implements BinderInterface
|
||||
* @param $value
|
||||
* @param $route
|
||||
*
|
||||
* @return mixed
|
||||
* @return Collection
|
||||
*/
|
||||
public static function routeBinder($value, $route)
|
||||
{
|
||||
|
||||
@@ -26,7 +26,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function amount($name, $value = null, array $options = [])
|
||||
public function amount(string $name, $value = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
@@ -51,7 +51,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function balance($name, $value = null, array $options = [])
|
||||
public function balance(string $name, $value = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
@@ -75,7 +75,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function checkbox($name, $value = 1, $checked = null, $options = [])
|
||||
public function checkbox(string $name, $value = 1, $checked = null, $options = [])
|
||||
{
|
||||
$options['checked'] = $checked === true ? true : null;
|
||||
$label = $this->label($name, $options);
|
||||
@@ -97,7 +97,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function date($name, $value = null, array $options = [])
|
||||
public function date(string $name, $value = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
@@ -115,7 +115,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function file($name, array $options = [])
|
||||
public function file(string $name, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
@@ -133,7 +133,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function integer($name, $value = null, array $options = [])
|
||||
public function integer(string $name, $value = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
@@ -153,7 +153,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function location($name, $value = null, array $options = [])
|
||||
public function location(string $name, $value = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
@@ -174,7 +174,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function makeSelectList(Collection $set, $addEmpty = false)
|
||||
public function makeSelectList(Collection $set, bool $addEmpty = false)
|
||||
{
|
||||
$selectList = [];
|
||||
if ($addEmpty) {
|
||||
@@ -205,7 +205,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function multiCheckbox($name, array $list = [], $selected = null, array $options = [])
|
||||
public function multiCheckbox(string $name, array $list = [], $selected = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
@@ -226,7 +226,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function multiRadio($name, array $list = [], $selected = null, array $options = [])
|
||||
public function multiRadio(string $name, array $list = [], $selected = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
@@ -271,7 +271,7 @@ class ExpandedForm
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function select($name, array $list = [], $selected = null, array $options = [])
|
||||
public function select(string $name, array $list = [], $selected = null, array $options = [])
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
|
||||
@@ -66,197 +66,6 @@ class General extends Twig_Extension
|
||||
return 'FireflyIII\Support\Twig\General';
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatFilesize()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'filesize', function ($size) {
|
||||
$size = intval($size);
|
||||
|
||||
// less than one GB, more than one MB
|
||||
if ($size < (1024 * 1024 * 2014) && $size >= (1024 * 1024)) {
|
||||
return round($size / (1024 * 1024), 2) . ' MB';
|
||||
}
|
||||
|
||||
// less than one MB
|
||||
if ($size < (1024 * 1024)) {
|
||||
return round($size / 1024, 2) . ' KB';
|
||||
}
|
||||
|
||||
return $size . ' bytes';
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function mimeIcon()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'mimeIcon', function ($string) {
|
||||
switch ($string) {
|
||||
default:
|
||||
return 'fa-file-o';
|
||||
case 'application/pdf':
|
||||
return 'fa-file-pdf-o';
|
||||
case 'image/png':
|
||||
case 'image/jpeg':
|
||||
return 'fa-file-image-o';
|
||||
}
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatAmount()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatAmount', function ($string) {
|
||||
return app('amount')->format($string);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatTransaction()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatTransaction', function (Transaction $transaction) {
|
||||
return app('amount')->formatTransaction($transaction);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatAmountPlain()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatAmountPlain', function ($string) {
|
||||
return app('amount')->format($string, false);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatJournal()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatJournal', function ($journal) {
|
||||
return app('amount')->formatJournal($journal);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function balance()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'balance', function (Account $account = null) {
|
||||
if (is_null($account)) {
|
||||
return 'NULL';
|
||||
}
|
||||
$date = session('end', Carbon::now()->endOfMonth());
|
||||
|
||||
return app('steam')->balance($account, $date);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function getAccountRole()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'getAccountRole', function ($name) {
|
||||
return Config::get('firefly.accountRoles.' . $name);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function getCurrencyCode()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'getCurrencyCode', function () {
|
||||
return app('amount')->getCurrencyCode();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function getCurrencySymbol()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'getCurrencySymbol', function () {
|
||||
return app('amount')->getCurrencySymbol();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function phpdate()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'phpdate', function ($str) {
|
||||
return date($str);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function env()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'env', function ($name, $default) {
|
||||
return env($name, $default);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return "active" when the current route matches the given argument
|
||||
* exactly.
|
||||
*
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function activeRouteStrict()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'activeRouteStrict', function () {
|
||||
$args = func_get_args();
|
||||
$route = $args[0]; // name of the route.
|
||||
|
||||
if (Route::getCurrentRoute()->getName() == $route) {
|
||||
return 'active';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return "active" when a part of the route matches the argument.
|
||||
* ie. "accounts" will match "accounts.index".
|
||||
@@ -302,4 +111,197 @@ class General extends Twig_Extension
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return "active" when the current route matches the given argument
|
||||
* exactly.
|
||||
*
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function activeRouteStrict()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'activeRouteStrict', function () {
|
||||
$args = func_get_args();
|
||||
$route = $args[0]; // name of the route.
|
||||
|
||||
if (Route::getCurrentRoute()->getName() == $route) {
|
||||
return 'active';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function balance()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'balance', function (Account $account = null) {
|
||||
if (is_null($account)) {
|
||||
return 'NULL';
|
||||
}
|
||||
$date = session('end', Carbon::now()->endOfMonth());
|
||||
|
||||
return app('steam')->balance($account, $date);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function env()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'env', function ($name, $default) {
|
||||
return env($name, $default);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatAmount()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatAmount', function ($string) {
|
||||
$value = is_null($string) ? '0' : $string;
|
||||
|
||||
return app('amount')->format($value);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatAmountPlain()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatAmountPlain', function ($string) {
|
||||
return app('amount')->format($string, false);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatFilesize()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'filesize', function ($size) {
|
||||
$size = intval($size);
|
||||
|
||||
// less than one GB, more than one MB
|
||||
if ($size < (1024 * 1024 * 2014) && $size >= (1024 * 1024)) {
|
||||
return round($size / (1024 * 1024), 2) . ' MB';
|
||||
}
|
||||
|
||||
// less than one MB
|
||||
if ($size < (1024 * 1024)) {
|
||||
return round($size / 1024, 2) . ' KB';
|
||||
}
|
||||
|
||||
return $size . ' bytes';
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatJournal()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatJournal', function ($journal) {
|
||||
return app('amount')->formatJournal($journal);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function formatTransaction()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'formatTransaction', function (Transaction $transaction) {
|
||||
return app('amount')->formatTransaction($transaction);
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function getAccountRole()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'getAccountRole', function ($name) {
|
||||
return Config::get('firefly.accountRoles.' . $name);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function getCurrencyCode()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'getCurrencyCode', function () {
|
||||
return app('amount')->getCurrencyCode();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function getCurrencySymbol()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'getCurrencySymbol', function () {
|
||||
return app('amount')->getCurrencySymbol();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFilter
|
||||
*/
|
||||
protected function mimeIcon()
|
||||
{
|
||||
return new Twig_SimpleFilter(
|
||||
'mimeIcon', function ($string) {
|
||||
switch ($string) {
|
||||
default:
|
||||
return 'fa-file-o';
|
||||
case 'application/pdf':
|
||||
return 'fa-file-pdf-o';
|
||||
case 'image/png':
|
||||
case 'image/jpeg':
|
||||
return 'fa-file-image-o';
|
||||
}
|
||||
}, ['is_safe' => ['html']]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Twig_SimpleFunction
|
||||
*/
|
||||
protected function phpdate()
|
||||
{
|
||||
return new Twig_SimpleFunction(
|
||||
'phpdate', function ($str) {
|
||||
return date($str);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user