invoiceninja/app/Ninja/Transformers/DocumentTransformer.php

41 lines
1.7 KiB
PHP
Raw Permalink Normal View History

2017-01-30 21:40:43 +02:00
<?php
namespace App\Ninja\Transformers;
2016-05-02 20:02:15 +03:00
use App\Models\Document;
/**
2016-12-29 18:17:17 +02:00
* @SWG\Definition(definition="Document", @SWG\Xml(name="Document"))
*/
2016-05-02 20:02:15 +03:00
class DocumentTransformer extends EntityTransformer
{
/**
2017-01-30 21:40:43 +02:00
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
* @SWG\Property(property="name", type="string", example="sample.png")
* @SWG\Property(property="type", type="string", example="png")
* @SWG\Property(property="path", type="string", example="abc/sample.png")
2017-01-30 21:40:43 +02:00
* @SWG\Property(property="invoice_id", type="integer", example=1)
* @SWG\Property(property="updated_at", type="integer", example=1451160233, readOnly=true)
2019-07-21 09:12:42 +03:00
* @SWG\Property(property="archived_at", type="integer", example=1451160233, readOnly=true)
2017-01-30 21:40:43 +02:00
*/
2016-05-02 20:02:15 +03:00
public function transform(Document $document)
{
2016-05-03 23:02:29 +03:00
return array_merge($this->getDefaults($document), [
2016-05-02 20:02:15 +03:00
'id' => (int) $document->public_id,
'name' => $document->name,
2017-01-30 21:40:43 +02:00
'type' => $document->type,
'path' => $document->path,
2019-07-21 09:12:42 +03:00
'invoice_id' => (int) ($document->invoice_id && $document->invoice ? $document->invoice->public_id : null),
'expense_id' => (int) ($document->expense_id && $document->expense ? $document->expense->public_id : null),
2016-06-01 21:36:27 +10:00
'updated_at' => $this->getTimestamp($document->updated_at),
2019-07-21 09:12:42 +03:00
'created_at' => $this->getTimestamp($document->created_at),
'is_deleted' => (bool) false,
2017-11-27 21:16:29 +11:00
'is_default' => (bool) $document->is_default,
2019-07-21 09:12:42 +03:00
'preview' => $document->preview,
'size' => (int) $document->size,
'width' => (int) $document->width,
'height' => (int) $document->height,
2016-05-03 23:02:29 +03:00
]);
2016-05-02 20:02:15 +03:00
}
2016-06-01 21:35:53 +10:00
}