invoiceninja/app/Transformers/AccountTransformer.php

77 lines
1.6 KiB
PHP
Raw Normal View History

2019-03-27 15:50:13 +11:00
<?php
2019-05-11 13:32:07 +10:00
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2019-03-27 15:50:13 +11:00
2019-03-28 13:36:36 +11:00
namespace App\Transformers;
2019-03-27 15:50:13 +11:00
use App\Models\Account;
2019-04-18 21:57:22 +10:00
use App\Models\Company;
2019-03-27 15:50:13 +11:00
use App\Models\Payment;
2019-04-18 21:57:22 +10:00
use App\Models\User;
use App\Transformers\CompanyTransformer;
use App\Transformers\UserTransformer;
2019-04-03 11:09:22 +11:00
use App\Utils\Traits\MakesHash;
2019-03-27 15:50:13 +11:00
/**
* Class AccountTransformer.
*/
class AccountTransformer extends EntityTransformer
{
2019-04-03 11:09:22 +11:00
use MakesHash;
2019-03-27 15:50:13 +11:00
/**
* @SWG\Property(property="account_key", type="string", example="123456")
*/
/**
* @var array
*/
protected $defaultIncludes = [
2019-04-18 21:57:22 +10:00
'default_company',
'user',
2019-03-27 15:50:13 +11:00
];
/**
* @var array
*/
protected $availableIncludes = [
'default_company',
];
/**
* @param Account $account
*
* @throws \Laracasts\Presenter\Exceptions\PresenterException
*
* @return array
*/
public function transform(Account $account)
{
return [
2019-04-03 11:09:22 +11:00
'id' => $this->encodePrimaryKey($account->id),
2019-03-27 15:50:13 +11:00
];
}
public function includeDefaultCompany(Account $account)
{
$transformer = new CompanyTransformer($this->serializer);
return $this->includeItem($account->default_company, $transformer, Company::class);
}
2019-04-18 21:57:22 +10:00
public function includeUser(Account $account)
{
$transformer = new UserTransformer($this->serializer);
return $this->includeItem($account->default_company->owner(), $transformer, User::class);
}
2019-03-27 15:50:13 +11:00
}