Added a new helper function.

This commit is contained in:
James Cole
2017-02-19 07:34:39 +01:00
parent 5073fd937c
commit b5032a7597
6 changed files with 39 additions and 50 deletions

View File

@@ -19,6 +19,7 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\Transaction as TransactionModel;
use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionType;
use Steam;
use Twig_Extension;
use Twig_SimpleFilter;
use Twig_SimpleFunction;
@@ -195,7 +196,7 @@ class Transaction extends Twig_Extension
return new Twig_SimpleFunction(
'transactionDestinationAccount', function (TransactionModel $transaction): string {
$name = intval($transaction->account_encrypted) === 1 ? Crypt::decrypt($transaction->account_name) : $transaction->account_name;
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
$id = intval($transaction->account_id);
$type = $transaction->account_type;
@@ -217,7 +218,7 @@ class Transaction extends Twig_Extension
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
$name = intval($other->encrypted) === 1 ? Crypt::decrypt($other->name) : $other->name;
$name = Steam::decrypt(intval($other->encrypted), $other->name);
$id = $other->account_id;
$type = $other->type;
}
@@ -269,7 +270,7 @@ class Transaction extends Twig_Extension
'transactionSourceAccount', function (TransactionModel $transaction): string {
// if the amount is negative, assume that the current account (the one in $transaction) is indeed the source account.
$name = intval($transaction->account_encrypted) === 1 ? Crypt::decrypt($transaction->account_name) : $transaction->account_name;
$name = Steam::decrypt(intval($transaction->account_encrypted), $transaction->account_name);
$id = intval($transaction->account_id);
$type = $transaction->account_type;
@@ -289,7 +290,7 @@ class Transaction extends Twig_Extension
->leftJoin('accounts', 'accounts.id', '=', 'transactions.account_id')
->leftJoin('account_types', 'account_types.id', '=', 'accounts.account_type_id')
->first(['transactions.account_id', 'accounts.encrypted', 'accounts.name', 'account_types.type']);
$name = intval($other->encrypted) === 1 ? Crypt::decrypt($other->name) : $other->name;
$name = Steam::decrypt(intval($other->encrypted), $other->name);
$id = $other->account_id;
$type = $other->type;
}
@@ -337,21 +338,6 @@ class Transaction extends Twig_Extension
);
}
/**
* @param int $isEncrypted
* @param string $value
*
* @return string
*/
private function encrypted(int $isEncrypted, string $value): string
{
if ($isEncrypted === 1) {
return Crypt::decrypt($value);
}
return $value;
}
/**
* @param TransactionModel $transaction
*
@@ -361,14 +347,14 @@ class Transaction extends Twig_Extension
{
// journal has a budget:
if (isset($transaction->transaction_journal_budget_id)) {
$name = $this->encrypted(intval($transaction->transaction_journal_budget_encrypted), $transaction->transaction_journal_budget_name);
$name = Steam::decrypt(intval($transaction->transaction_journal_budget_encrypted), $transaction->transaction_journal_budget_name);
return sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_journal_budget_id]), $name, $name);
}
// transaction has a budget
if (isset($transaction->transaction_budget_id)) {
$name = $this->encrypted(intval($transaction->transaction_budget_encrypted), $transaction->transaction_budget_name);
$name = Steam::decrypt(intval($transaction->transaction_budget_encrypted), $transaction->transaction_budget_name);
return sprintf('<a href="%s" title="%s">%s</a>', route('budgets.show', [$transaction->transaction_budget_id]), $name, $name);
}
@@ -400,14 +386,14 @@ class Transaction extends Twig_Extension
{
// journal has a category:
if (isset($transaction->transaction_journal_category_id)) {
$name = $this->encrypted(intval($transaction->transaction_journal_category_encrypted), $transaction->transaction_journal_category_name);
$name = Steam::decrypt(intval($transaction->transaction_journal_category_encrypted), $transaction->transaction_journal_category_name);
return sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_journal_category_id]), $name, $name);
}
// transaction has a category:
if (isset($transaction->transaction_category_id)) {
$name = $this->encrypted(intval($transaction->transaction_category_encrypted), $transaction->transaction_category_name);
$name = Steam::decrypt(intval($transaction->transaction_category_encrypted), $transaction->transaction_category_name);
return sprintf('<a href="%s" title="%s">%s</a>', route('categories.show', [$transaction->transaction_category_id]), $name, $name);
}