2018-02-04 15:57:35 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2018-02-06 07:49:56 +01:00
|
|
|
* AttachmentTransformer.php
|
2018-02-04 15:57:35 +01:00
|
|
|
* 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-02-06 07:49:56 +01:00
|
|
|
|
|
|
|
use FireflyIII\Models\Attachment;
|
2018-09-27 07:43:30 +02:00
|
|
|
use FireflyIII\Repositories\Attachment\AttachmentRepositoryInterface;
|
2018-02-04 15:57:35 +01:00
|
|
|
use League\Fractal\TransformerAbstract;
|
2018-12-15 07:59:02 +01:00
|
|
|
use Log;
|
2018-02-11 20:45:33 +01:00
|
|
|
use Symfony\Component\HttpFoundation\ParameterBag;
|
2018-02-04 15:57:35 +01:00
|
|
|
|
|
|
|
/**
|
2018-02-06 07:49:56 +01:00
|
|
|
* Class AttachmentTransformer
|
2018-02-04 15:57:35 +01:00
|
|
|
*/
|
2018-12-16 13:55:19 +01:00
|
|
|
class AttachmentTransformer extends AbstractTransformer
|
2018-02-04 15:57:35 +01:00
|
|
|
{
|
2018-09-27 07:43:30 +02:00
|
|
|
/** @var AttachmentRepositoryInterface */
|
|
|
|
private $repository;
|
|
|
|
|
2018-02-11 20:45:33 +01:00
|
|
|
/**
|
|
|
|
* BillTransformer constructor.
|
|
|
|
*
|
2018-02-16 22:47:08 +01:00
|
|
|
* @codeCoverageIgnore
|
2018-02-11 20:45:33 +01:00
|
|
|
*/
|
2018-12-16 13:55:19 +01:00
|
|
|
public function __construct()
|
2018-02-11 20:45:33 +01:00
|
|
|
{
|
2018-09-27 07:43:30 +02:00
|
|
|
$this->repository = app(AttachmentRepositoryInterface::class);
|
2018-12-15 07:59:02 +01:00
|
|
|
if ('testing' === config('app.env')) {
|
|
|
|
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', \get_class($this)));
|
|
|
|
}
|
2018-02-10 10:58:06 +01:00
|
|
|
}
|
|
|
|
|
2018-02-04 15:57:35 +01:00
|
|
|
/**
|
2018-02-16 22:47:08 +01:00
|
|
|
* Transform attachment.
|
|
|
|
*
|
2018-02-06 07:49:56 +01:00
|
|
|
* @param Attachment $attachment
|
2018-02-04 15:57:35 +01:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2018-02-06 07:49:56 +01:00
|
|
|
public function transform(Attachment $attachment): array
|
2018-02-04 15:57:35 +01:00
|
|
|
{
|
2018-09-27 07:43:30 +02:00
|
|
|
$this->repository->setUser($attachment->user);
|
|
|
|
|
2018-02-04 15:57:35 +01:00
|
|
|
return [
|
2018-02-06 19:49:29 +01:00
|
|
|
'id' => (int)$attachment->id,
|
2018-02-11 07:46:34 +01:00
|
|
|
'created_at' => $attachment->created_at->toAtomString(),
|
2018-12-12 20:30:25 +01:00
|
|
|
'updated_at' => $attachment->updated_at->toAtomString(),
|
2018-12-04 19:36:54 +01:00
|
|
|
'attachable_id' => $attachment->attachable_id,
|
|
|
|
'attachable_type' => str_replace('FireflyIII\\Models\\','',$attachment->attachable_type),
|
2018-02-06 19:49:29 +01:00
|
|
|
'md5' => $attachment->md5,
|
|
|
|
'filename' => $attachment->filename,
|
2018-06-24 06:51:22 +02:00
|
|
|
'download_uri' => route('api.v1.attachments.download', [$attachment->id]),
|
|
|
|
'upload_uri' => route('api.v1.attachments.upload', [$attachment->id]),
|
2018-02-06 19:49:29 +01:00
|
|
|
'title' => $attachment->title,
|
2018-09-27 07:43:30 +02:00
|
|
|
'notes' => $this->repository->getNoteText($attachment),
|
2018-12-19 06:06:01 +01:00
|
|
|
'mime' => $attachment->mime,
|
2018-06-24 06:51:22 +02:00
|
|
|
'size' => (int)$attachment->size,
|
2018-02-07 11:20:24 +01:00
|
|
|
'links' => [
|
|
|
|
[
|
|
|
|
'rel' => 'self',
|
|
|
|
'uri' => '/attachment/' . $attachment->id,
|
|
|
|
],
|
2018-02-09 19:11:55 +01:00
|
|
|
],
|
2018-02-04 15:57:35 +01:00
|
|
|
];
|
|
|
|
}
|
2018-02-06 07:49:56 +01:00
|
|
|
|
2018-03-05 19:35:58 +01:00
|
|
|
}
|