mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-18 10:16:49 +00:00
Optimized preferences.
This commit is contained in:
@@ -67,6 +67,7 @@ class HomeController extends Controller
|
|||||||
$frontPage = Preferences::get('frontPageAccounts', []);
|
$frontPage = Preferences::get('frontPageAccounts', []);
|
||||||
$start = Session::get('start', Carbon::now()->startOfMonth());
|
$start = Session::get('start', Carbon::now()->startOfMonth());
|
||||||
$end = Session::get('end', Carbon::now()->endOfMonth());
|
$end = Session::get('end', Carbon::now()->endOfMonth());
|
||||||
|
|
||||||
$accounts = $repository->getFrontpageAccounts($frontPage);
|
$accounts = $repository->getFrontpageAccounts($frontPage);
|
||||||
$savings = $repository->getSavingsAccounts();
|
$savings = $repository->getSavingsAccounts();
|
||||||
|
|
||||||
@@ -79,6 +80,7 @@ class HomeController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
$sum = $repository->sumOfEverything();
|
$sum = $repository->sumOfEverything();
|
||||||
|
|
||||||
if ($sum != 0) {
|
if ($sum != 0) {
|
||||||
Session::flash(
|
Session::flash(
|
||||||
'error', 'Your transactions are unbalanced. This means a'
|
'error', 'Your transactions are unbalanced. This means a'
|
||||||
@@ -89,6 +91,7 @@ class HomeController extends Controller
|
|||||||
|
|
||||||
foreach ($accounts as $account) {
|
foreach ($accounts as $account) {
|
||||||
$set = $repository->getFrontpageTransactions($account, $start, $end);
|
$set = $repository->getFrontpageTransactions($account, $start, $end);
|
||||||
|
|
||||||
if (count($set) > 0) {
|
if (count($set) > 0) {
|
||||||
$transactions[] = [$set, $account];
|
$transactions[] = [$set, $account];
|
||||||
}
|
}
|
||||||
|
@@ -55,21 +55,6 @@ class Preference extends Model
|
|||||||
return ['created_at', 'updated_at'];
|
return ['created_at', 'updated_at'];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*
|
|
||||||
* @return float|int
|
|
||||||
*/
|
|
||||||
public function getNameAttribute($value)
|
|
||||||
{
|
|
||||||
if (is_null($this->name_encrypted)) {
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
$value = Crypt::decrypt($this->name_encrypted);
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $value
|
* @param $value
|
||||||
*/
|
*/
|
||||||
@@ -79,15 +64,6 @@ class Preference extends Model
|
|||||||
$this->attributes['data_encrypted'] = Crypt::encrypt(json_encode($value));
|
$this->attributes['data_encrypted'] = Crypt::encrypt(json_encode($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param $value
|
|
||||||
*/
|
|
||||||
public function setNameAttribute($value)
|
|
||||||
{
|
|
||||||
$this->attributes['name_encrypted'] = Crypt::encrypt($value);
|
|
||||||
$this->attributes['name'] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||||
*/
|
*/
|
||||||
|
@@ -84,6 +84,15 @@ class Amount
|
|||||||
*/
|
*/
|
||||||
public function formatJournal(TransactionJournal $journal, $coloured = true)
|
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)) {
|
if (is_null($journal->symbol)) {
|
||||||
$symbol = $journal->transactionCurrency->symbol;
|
$symbol = $journal->transactionCurrency->symbol;
|
||||||
} else {
|
} else {
|
||||||
@@ -94,13 +103,22 @@ class Amount
|
|||||||
$amount = $amount * -1;
|
$amount = $amount * -1;
|
||||||
}
|
}
|
||||||
if ($journal->transactionType->type == 'Transfer' && $coloured) {
|
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) {
|
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)
|
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 */
|
if ($preference) {
|
||||||
foreach ($preferences as $preference) {
|
return $preference;
|
||||||
if ($preference->name == $name) {
|
|
||||||
return $preference;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// no preference found and default is null:
|
// no preference found and default is null:
|
||||||
if (is_null($default)) {
|
if (is_null($default)) {
|
||||||
@@ -56,24 +53,17 @@ class Preferences
|
|||||||
*/
|
*/
|
||||||
public function set($name, $value)
|
public function set($name, $value)
|
||||||
{
|
{
|
||||||
$preferences = Preference::where('user_id', Auth::user()->id)->get();
|
$pref = Preference::where('user_id', Auth::user()->id)->where('name', $name)->first(['id','name','data_encrypted']);
|
||||||
/** @var Preference $preference */
|
if ($pref) {
|
||||||
foreach ($preferences as $preference) {
|
$pref->data = $value;
|
||||||
if ($preference->name == $name) {
|
} else {
|
||||||
$preference->data = $value;
|
$pref = new Preference;
|
||||||
$preference->save();
|
$pref->name = $name;
|
||||||
|
$pref->data = $value;
|
||||||
return $preference;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$pref = new Preference;
|
|
||||||
$pref->name = $name;
|
|
||||||
$pref->data = $value;
|
|
||||||
|
|
||||||
if (!is_null(Auth::user()->id)) {
|
|
||||||
$pref->user()->associate(Auth::user());
|
$pref->user()->associate(Auth::user());
|
||||||
$pref->save();
|
|
||||||
}
|
}
|
||||||
|
$pref->save();
|
||||||
|
|
||||||
return $pref;
|
return $pref;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user