mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-12 01:42:32 +00:00
Expand transformers.
This commit is contained in:
@@ -21,11 +21,10 @@
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Transformers\Bill;
|
||||
namespace FireflyIII\Transformers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use FireflyIII\Models\Bill;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use League\Fractal\TransformerAbstract;
|
||||
@@ -35,6 +34,18 @@ use League\Fractal\TransformerAbstract;
|
||||
*/
|
||||
class BillTransformer extends TransformerAbstract
|
||||
{
|
||||
/**
|
||||
* List of resources possible to include
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $availableIncludes = ['attachments', 'notes'];
|
||||
/**
|
||||
* List of resources to automatically include
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $defaultIncludes = ['notes',];
|
||||
/** @var Carbon */
|
||||
private $end = null;
|
||||
/** @var Carbon */
|
||||
@@ -52,6 +63,30 @@ class BillTransformer extends TransformerAbstract
|
||||
$this->end = $end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeAttachments(Bill $bill)
|
||||
{
|
||||
$attachments = $bill->attachments()->get();
|
||||
|
||||
return $this->collection($attachments, new AttachmentTransformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
* @return \League\Fractal\Resource\Collection
|
||||
*/
|
||||
public function includeNotes(Bill $bill)
|
||||
{
|
||||
$notes = $bill->notes()->get();
|
||||
|
||||
return $this->collection($notes, new NoteTransformer);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Bill $bill
|
||||
*
|
||||
@@ -75,7 +110,6 @@ class BillTransformer extends TransformerAbstract
|
||||
'pay_dates' => $this->payDates($bill),
|
||||
'paid_dates' => $paidData['paid_dates'],
|
||||
'next_expected_match' => $paidData['next_expected_match'],
|
||||
'notes' => $this->getNote($bill),
|
||||
'links' => [
|
||||
[
|
||||
'rel' => 'self',
|
||||
@@ -204,15 +238,4 @@ class BillTransformer extends TransformerAbstract
|
||||
|
||||
return $simple->toArray();
|
||||
}
|
||||
|
||||
private function getNote($bill): string
|
||||
{
|
||||
/** @var Note $note */
|
||||
$note = $bill->notes()->first();
|
||||
if (!is_null($note)) {
|
||||
return $note->text;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user