2018-02-11 20:45:33 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* BudgetTransformer.php
|
|
|
|
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
|
|
|
*
|
|
|
|
* This file is part of Firefly III.
|
|
|
|
*
|
|
|
|
* Firefly III is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Firefly III 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace FireflyIII\Transformers;
|
|
|
|
|
|
|
|
|
2018-08-11 14:33:47 +02:00
|
|
|
use FireflyIII\Helpers\Collector\TransactionCollectorInterface;
|
2018-02-11 20:45:33 +01:00
|
|
|
use FireflyIII\Models\Budget;
|
2018-02-17 10:47:06 +01:00
|
|
|
use Illuminate\Support\Collection;
|
|
|
|
use League\Fractal\Resource\Collection as FractalCollection;
|
|
|
|
use League\Fractal\Resource\Item;
|
2018-02-11 20:45:33 +01:00
|
|
|
use League\Fractal\TransformerAbstract;
|
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class BudgetTransformer
|
|
|
|
*/
|
|
|
|
class BudgetTransformer extends TransformerAbstract
|
|
|
|
{
|
|
|
|
/** @var ParameterBag */
|
|
|
|
protected $parameters;
|
|
|
|
|
|
|
|
/**
|
2018-02-17 10:47:06 +01:00
|
|
|
* BudgetTransformer constructor.
|
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
2018-02-11 20:45:33 +01:00
|
|
|
*
|
|
|
|
* @param ParameterBag $parameters
|
|
|
|
*/
|
|
|
|
public function __construct(ParameterBag $parameters)
|
|
|
|
{
|
|
|
|
$this->parameters = $parameters;
|
|
|
|
}
|
|
|
|
|
2018-02-17 10:47:06 +01:00
|
|
|
/**
|
|
|
|
* Transform a budget.
|
|
|
|
*
|
2018-02-11 20:45:33 +01:00
|
|
|
* @param Budget $budget
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Budget $budget): array
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'id' => (int)$budget->id,
|
|
|
|
'updated_at' => $budget->updated_at->toAtomString(),
|
|
|
|
'created_at' => $budget->created_at->toAtomString(),
|
2018-08-06 19:14:30 +02:00
|
|
|
'active' => 1 === (int)$budget->active,
|
2018-02-11 20:45:33 +01:00
|
|
|
'name' => $budget->name,
|
|
|
|
'links' => [
|
|
|
|
[
|
|
|
|
'rel' => 'self',
|
|
|
|
'uri' => '/budgets/' . $budget->id,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2018-03-05 19:35:58 +01:00
|
|
|
}
|