mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2026-01-10 12:24:50 +00:00
Refactor currency repository.
This commit is contained in:
@@ -26,6 +26,7 @@ namespace FireflyIII\Support;
|
||||
use Crypt;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\Encryption\DecryptException;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -129,7 +130,6 @@ class Amount
|
||||
* @param User $user
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getDefaultCurrencyByUser(User $user): TransactionCurrency
|
||||
{
|
||||
@@ -148,6 +148,28 @@ class Amount
|
||||
|
||||
return $default;
|
||||
}
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @return TransactionCurrency
|
||||
*/
|
||||
public function getDefaultCurrencyByUserGroup(UserGroup $userGroup): TransactionCurrency
|
||||
{
|
||||
$cache = new CacheProperties();
|
||||
$cache->addProperty('getDefaultCurrencyByGroup');
|
||||
$cache->addProperty($userGroup->id);
|
||||
if ($cache->has()) {
|
||||
return $cache->get();
|
||||
}
|
||||
$default = $userGroup->currencies()->where('group_default', true)->first();
|
||||
if(null === $default) {
|
||||
$default = $this->getSystemCurrency();
|
||||
$userGroup->currencies()->sync([$default->id => ['group_default' => true]]);
|
||||
}
|
||||
$cache->store($default);
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $value
|
||||
|
||||
Reference in New Issue
Block a user