mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-18 04:19:12 +00:00
Update, edit and delete currencies.
This commit is contained in:
@@ -1,26 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Database\TransactionCurrency;
|
||||
|
||||
use FireflyIII\Database\CommonDatabaseCalls;
|
||||
use Illuminate\Support\Collection;
|
||||
use FireflyIII\Database\CUD;
|
||||
use FireflyIII\Exception\NotImplementedException;
|
||||
use Illuminate\Database\Eloquent\Model as Eloquent;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\MessageBag;
|
||||
|
||||
/**
|
||||
* Class TransactionType
|
||||
*
|
||||
* @package FireflyIII\Database
|
||||
*/
|
||||
class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabaseCalls
|
||||
class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabaseCalls, CUD
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
* @param Eloquent $model
|
||||
*
|
||||
* @return \TransactionCurrency|null
|
||||
* @return bool
|
||||
*/
|
||||
public function findByCode($code)
|
||||
public function destroy(Eloquent $model)
|
||||
{
|
||||
return \TransactionCurrency::whereCode($code)->first();
|
||||
$model->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Eloquent
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
$currency = new \TransactionCurrency($data);
|
||||
$currency->save();
|
||||
return $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Eloquent $model
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function update(Eloquent $model, array $data)
|
||||
{
|
||||
$model->symbol = $data['symbol'];
|
||||
$model->code = $data['code'];
|
||||
$model->name = $data['name'];
|
||||
$model->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates an array. Returns an array containing MessageBags
|
||||
* errors/warnings/successes.
|
||||
*
|
||||
* @param array $model
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function validate(array $model)
|
||||
{
|
||||
$warnings = new MessageBag;
|
||||
$successes = new MessageBag;
|
||||
|
||||
$currency = new \TransactionCurrency($model);
|
||||
$currency->isValid();
|
||||
$errors = $currency->getErrors();
|
||||
|
||||
$fields = ['name', 'code', 'symbol'];
|
||||
foreach ($fields as $field) {
|
||||
if (!$errors->has($field)) {
|
||||
$successes->add($field, 'OK');
|
||||
}
|
||||
}
|
||||
|
||||
return ['errors' => $errors, 'warnings' => $warnings, 'successes' => $successes];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,7 +115,7 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
|
||||
*/
|
||||
public function get()
|
||||
{
|
||||
return \TransactionCurrency::orderBy('code','ASC')->get();
|
||||
return \TransactionCurrency::orderBy('code', 'ASC')->get();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,4 +128,14 @@ class TransactionCurrency implements TransactionCurrencyInterface, CommonDatabas
|
||||
// TODO: Implement getByIds() method.
|
||||
throw new NotImplementedException;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $code
|
||||
*
|
||||
* @return \TransactionCurrency|null
|
||||
*/
|
||||
public function findByCode($code)
|
||||
{
|
||||
return \TransactionCurrency::whereCode($code)->first();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user