mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Link currency to user and user group.
This commit is contained in:
@@ -24,8 +24,10 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Eloquent;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Database\Query\Builder;
|
||||
@@ -40,6 +42,8 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
* @property Carbon|null $updated_at
|
||||
* @property Carbon|null $deleted_at
|
||||
* @property bool $enabled
|
||||
* @property bool $userDefault
|
||||
* @property bool $userEnabled
|
||||
* @property string $code
|
||||
* @property string $name
|
||||
* @property string $symbol
|
||||
@@ -107,6 +111,39 @@ class TransactionCurrency extends Model
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param User $user
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function refreshForUser(User $user)
|
||||
{
|
||||
$current = $user->currencies()->where('transaction_currencies.id', $this->id)->first();
|
||||
$default = app('amount')->getDefaultCurrencyByUser($user);
|
||||
$this->userDefault = (int)$default->id === (int)$this->id;
|
||||
$this->userEnabled = null !== $current;
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to users
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class)->withTimestamps()->withPivot('default');
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to user groups
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function userGroups(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(UserGroup::class)->withTimestamps()->withPivot('default');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return HasMany
|
||||
*/
|
||||
|
@@ -30,6 +30,7 @@ use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Support\Carbon;
|
||||
@@ -129,6 +130,16 @@ class UserGroup extends Model
|
||||
return $this->hasMany(Account::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to currencies
|
||||
*
|
||||
* @return BelongsToMany
|
||||
*/
|
||||
public function currencies(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(TransactionCurrency::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to attachments.
|
||||
*
|
||||
|
Reference in New Issue
Block a user