Files
firefly-iii/app/Transformers/RecurrenceTransformer.php

80 lines
2.8 KiB
PHP
Raw Normal View History

<?php
/**
* RecurrenceTransformer.php
2020-02-16 13:57:18 +01:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* 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.
*
* 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/>.
*/
declare(strict_types=1);
namespace FireflyIII\Transformers;
2021-07-18 14:51:30 +02:00
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Recurrence;
2025-08-05 13:40:46 +02:00
use Illuminate\Support\Facades\Log;
2025-05-27 17:06:15 +02:00
/**
* Class RecurringTransactionTransformer
*/
class RecurrenceTransformer extends AbstractTransformer
{
2018-07-18 07:28:35 +02:00
/**
* RecurrenceTransformer constructor.
*/
public function __construct() {}
/**
2018-07-18 07:28:35 +02:00
* Transform the recurring transaction.
*
* @throws FireflyException
*/
public function transform(Recurrence $recurrence): array
{
2025-08-05 13:40:46 +02:00
Log::debug('Now in Recurrence::transform()');
2018-12-20 20:50:05 +01:00
$shortType = (string)config(sprintf('firefly.transactionTypesToShort.%s', $recurrence->transactionType->type));
$reps = 0 === (int)$recurrence->repetitions ? null : (int)$recurrence->repetitions;
2025-08-05 13:40:46 +02:00
Log::debug('Get basic data.');
2021-03-06 16:15:39 +01:00
2018-07-18 07:28:35 +02:00
// basic data.
2020-10-23 19:11:25 +02:00
return [
'id' => (string)$recurrence->id,
'created_at' => $recurrence->created_at->toAtomString(),
'updated_at' => $recurrence->updated_at->toAtomString(),
'type' => $shortType,
'title' => $recurrence->title,
'description' => $recurrence->description,
'first_date' => $recurrence->first_date->toAtomString(),
'latest_date' => $recurrence->latest_date?->toAtomString(),
'repeat_until' => $recurrence->repeat_until?->toAtomString(),
'apply_rules' => $recurrence->apply_rules,
'active' => $recurrence->active,
2019-09-04 21:06:01 +02:00
'nr_of_repetitions' => $reps,
2025-08-06 15:35:29 +02:00
'notes' => $recurrence->meta['notes'],
'repetitions' => $recurrence->meta['repetitions'],
'transactions' => $recurrence->meta['transactions'],
'links' => [
[
'rel' => 'self',
'uri' => '/recurring/'.$recurrence->id,
],
],
];
2018-07-18 07:28:35 +02:00
}
}