2018-02-04 15:57:35 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2018-02-06 07:49:56 +01:00
|
|
|
* AttachmentTransformer.php
|
2020-02-16 13:57:18 +01:00
|
|
|
* Copyright (c) 2019 james@firefly-iii.org
|
2018-02-04 15:57:35 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This file is part of Firefly III (https://github.com/firefly-iii).
|
2018-02-04 15:57:35 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +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-02-04 15:57:35 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +02:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
2018-02-04 15:57:35 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2019-10-02 06:37:26 +02:00
|
|
|
* GNU Affero General Public License for more details.
|
2018-02-04 15:57:35 +01:00
|
|
|
*
|
2019-10-02 06:37:26 +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-02-04 15:57:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
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-12-15 07:59:02 +01:00
|
|
|
use Log;
|
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
|
|
|
{
|
2020-07-31 15:12:26 +02:00
|
|
|
private AttachmentRepositoryInterface $repository;
|
2018-09-27 07:43:30 +02:00
|
|
|
|
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')) {
|
2019-06-07 18:20:15 +02:00
|
|
|
Log::warning(sprintf('%s should not be instantiated in the TEST environment!', get_class($this)));
|
2018-12-15 07:59:02 +01:00
|
|
|
}
|
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(),
|
2020-07-12 17:54:51 +02:00
|
|
|
'attachable_id' => (int) $attachment->attachable_id,
|
2019-02-12 21:49:28 +01:00
|
|
|
'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
|
|
|
}
|