mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Optimized preferences.
This commit is contained in:
@@ -84,6 +84,15 @@ class Amount
|
||||
*/
|
||||
public function formatJournal(TransactionJournal $journal, $coloured = true)
|
||||
{
|
||||
$cache = new CacheProperties;
|
||||
$cache->addProperty($journal->id);
|
||||
$cache->addProperty('formatJournal');
|
||||
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
|
||||
|
||||
if (is_null($journal->symbol)) {
|
||||
$symbol = $journal->transactionCurrency->symbol;
|
||||
} else {
|
||||
@@ -94,13 +103,22 @@ class Amount
|
||||
$amount = $amount * -1;
|
||||
}
|
||||
if ($journal->transactionType->type == 'Transfer' && $coloured) {
|
||||
return '<span class="text-info">' . $this->formatWithSymbol($symbol, $amount, false) . '</span>';
|
||||
$txt = '<span class="text-info">' . $this->formatWithSymbol($symbol, $amount, false) . '</span>';
|
||||
$cache->store($txt);
|
||||
|
||||
return $txt;
|
||||
}
|
||||
if ($journal->transactionType->type == 'Transfer' && !$coloured) {
|
||||
return $this->formatWithSymbol($symbol, $amount, false);
|
||||
$txt = $this->formatWithSymbol($symbol, $amount, false);
|
||||
$cache->store($txt);
|
||||
|
||||
return $txt;
|
||||
}
|
||||
|
||||
return $this->formatWithSymbol($symbol, $amount, $coloured);
|
||||
$txt = $this->formatWithSymbol($symbol, $amount, $coloured);
|
||||
$cache->store($txt);
|
||||
|
||||
return $txt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -30,13 +30,10 @@ class Preferences
|
||||
*/
|
||||
public function get($name, $default = null)
|
||||
{
|
||||
$preferences = Preference::where('user_id', Auth::user()->id)->get();
|
||||
$preference = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id','name','data_encrypted']);
|
||||
|
||||
/** @var Preference $preference */
|
||||
foreach ($preferences as $preference) {
|
||||
if ($preference->name == $name) {
|
||||
return $preference;
|
||||
}
|
||||
if ($preference) {
|
||||
return $preference;
|
||||
}
|
||||
// no preference found and default is null:
|
||||
if (is_null($default)) {
|
||||
@@ -56,24 +53,17 @@ class Preferences
|
||||
*/
|
||||
public function set($name, $value)
|
||||
{
|
||||
$preferences = Preference::where('user_id', Auth::user()->id)->get();
|
||||
/** @var Preference $preference */
|
||||
foreach ($preferences as $preference) {
|
||||
if ($preference->name == $name) {
|
||||
$preference->data = $value;
|
||||
$preference->save();
|
||||
|
||||
return $preference;
|
||||
}
|
||||
}
|
||||
$pref = new Preference;
|
||||
$pref->name = $name;
|
||||
$pref->data = $value;
|
||||
|
||||
if (!is_null(Auth::user()->id)) {
|
||||
$pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id','name','data_encrypted']);
|
||||
if ($pref) {
|
||||
$pref->data = $value;
|
||||
} else {
|
||||
$pref = new Preference;
|
||||
$pref->name = $name;
|
||||
$pref->data = $value;
|
||||
$pref->user()->associate(Auth::user());
|
||||
$pref->save();
|
||||
|
||||
}
|
||||
$pref->save();
|
||||
|
||||
return $pref;
|
||||
|
||||
|
Reference in New Issue
Block a user