mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-31 19:27:51 -06:00
85 lines
1.8 KiB
PHP
85 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace FireflyIII\Repositories\Currency;
|
|
|
|
|
|
use FireflyIII\Models\Preference;
|
|
use FireflyIII\Models\TransactionCurrency;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/**
|
|
* Class CurrencyRepository
|
|
*
|
|
* @package FireflyIII\Repositories\Currency
|
|
*/
|
|
class CurrencyRepository implements CurrencyRepositoryInterface
|
|
{
|
|
|
|
/**
|
|
* @param TransactionCurrency $currency
|
|
*
|
|
* @return int
|
|
*/
|
|
public function countJournals(TransactionCurrency $currency)
|
|
{
|
|
return $currency->transactionJournals()->count();
|
|
}
|
|
|
|
/**
|
|
* @return Collection
|
|
*/
|
|
public function get()
|
|
{
|
|
return TransactionCurrency::get();
|
|
}
|
|
|
|
/**
|
|
* @param Preference $preference
|
|
*
|
|
* @return TransactionCurrency
|
|
*/
|
|
public function getCurrencyByPreference(Preference $preference)
|
|
{
|
|
$preferred = TransactionCurrency::whereCode($preference->data)->first();
|
|
if (is_null($preferred)) {
|
|
$preferred = TransactionCurrency::first();
|
|
}
|
|
|
|
return $preferred;
|
|
}
|
|
|
|
/**
|
|
* @param array $data
|
|
*
|
|
* @return TransactionCurrency
|
|
*/
|
|
public function store(array $data)
|
|
{
|
|
$currency = TransactionCurrency::create(
|
|
[
|
|
'name' => $data['name'],
|
|
'code' => $data['code'],
|
|
'symbol' => $data['symbol'],
|
|
]
|
|
);
|
|
|
|
return $currency;
|
|
}
|
|
|
|
/**
|
|
* @param TransactionCurrency $currency
|
|
* @param array $data
|
|
*
|
|
* @return TransactionCurrency
|
|
*/
|
|
public function update(TransactionCurrency $currency, array $data)
|
|
{
|
|
$currency->code = $data['code'];
|
|
$currency->symbol = $data['symbol'];
|
|
$currency->name = $data['name'];
|
|
$currency->save();
|
|
|
|
return $currency;
|
|
}
|
|
}
|