Files
firefly-iii/app/Services/Internal/Update/CurrencyUpdateService.php

59 lines
1.9 KiB
PHP
Raw Normal View History

2018-03-25 09:01:43 +02:00
<?php
/**
* CurrencyUpdateService.php
2020-02-16 13:56:35 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-03-25 09:01:43 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-03-25 09:01:43 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-03-25 09:01:43 +02:00
*
* This program is distributed in the hope that it will be useful,
2018-03-25 09:01:43 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-03-25 09:01:43 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-03-25 09:01:43 +02:00
*/
declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update;
use FireflyIII\Models\TransactionCurrency;
2018-03-25 09:01:43 +02:00
/**
* Class CurrencyUpdateService
*/
class CurrencyUpdateService
{
public function update(TransactionCurrency $currency, array $data): TransactionCurrency
{
2022-12-29 19:42:26 +01:00
if (array_key_exists('code', $data) && '' !== (string)$data['code']) {
2023-02-17 05:49:54 +01:00
$currency->code = e($data['code']);
}
2022-12-29 19:42:26 +01:00
if (array_key_exists('symbol', $data) && '' !== (string)$data['symbol']) {
2023-02-17 05:49:54 +01:00
$currency->symbol = e($data['symbol']);
}
2022-12-29 19:42:26 +01:00
if (array_key_exists('name', $data) && '' !== (string)$data['name']) {
2023-02-17 05:49:54 +01:00
$currency->name = e($data['name']);
}
$currency->enabled = false;
if (array_key_exists('decimal_places', $data) && is_int($data['decimal_places'])) {
2023-11-05 08:15:17 +01:00
$currency->decimal_places = $data['decimal_places'];
}
2023-12-16 16:06:23 +01:00
$currency->userGroupEnabled = null;
$currency->userGroupDefault = null;
2018-03-25 09:01:43 +02:00
$currency->save();
return $currency;
}
}