2019-03-27 05:50:13 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-03-27 05:50:13 +01:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
namespace App\Transformers;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
use App\Models\Account;
|
2019-04-18 13:57:22 +02:00
|
|
|
use App\Models\Company;
|
2019-06-25 05:55:02 +02:00
|
|
|
use App\Models\CompanyUser;
|
2019-03-27 05:50:13 +01:00
|
|
|
use App\Models\Payment;
|
2019-04-18 13:57:22 +02:00
|
|
|
use App\Models\User;
|
|
|
|
use App\Transformers\CompanyTransformer;
|
2019-06-25 05:55:02 +02:00
|
|
|
use App\Transformers\CompanyUserTransformer;
|
2019-04-18 13:57:22 +02:00
|
|
|
use App\Transformers\UserTransformer;
|
2019-04-03 02:09:22 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class AccountTransformer.
|
|
|
|
*/
|
|
|
|
class AccountTransformer extends EntityTransformer
|
|
|
|
{
|
2019-04-03 02:09:22 +02:00
|
|
|
use MakesHash;
|
2019-03-27 05:50:13 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $defaultIncludes = [
|
2019-06-25 05:55:02 +02:00
|
|
|
//'default_company',
|
2019-09-12 14:02:25 +02:00
|
|
|
//'user',
|
|
|
|
//'company_users'
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
|
|
|
'default_company',
|
2019-06-25 05:55:02 +02:00
|
|
|
'company_users',
|
|
|
|
'companies',
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Account $account
|
|
|
|
*
|
|
|
|
* @throws \Laracasts\Presenter\Exceptions\PresenterException
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function transform(Account $account)
|
|
|
|
{
|
|
|
|
return [
|
2019-10-03 03:13:25 +02:00
|
|
|
'id' => (string)$this->encodePrimaryKey($account->id),
|
2019-09-18 14:43:37 +02:00
|
|
|
'default_url' => config('ninja.site_url'),
|
|
|
|
'plan' => $account->getPlan(),
|
2020-03-08 06:59:06 +01:00
|
|
|
'latest_version' => (string)$account->latest_version,
|
2020-02-27 00:32:44 +01:00
|
|
|
'updated_at' => (int)$account->updated_at,
|
|
|
|
'archived_at' => (int)$account->deleted_at,
|
2019-03-27 05:50:13 +01:00
|
|
|
];
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function includeCompanyUsers(Account $account)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyUserTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($account->company_users, $transformer, CompanyUser::class);
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function includeDefaultCompany(Account $account)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($account->default_company, $transformer, Company::class);
|
|
|
|
}
|
2019-04-18 13:57:22 +02:00
|
|
|
|
|
|
|
public function includeUser(Account $account)
|
|
|
|
{
|
|
|
|
$transformer = new UserTransformer($this->serializer);
|
2019-09-12 13:46:09 +02:00
|
|
|
return $this->includeItem(auth()->user(), $transformer, User::class);
|
2019-04-18 13:57:22 +02:00
|
|
|
|
2019-09-12 13:46:09 +02:00
|
|
|
// return $this->includeItem($account->default_company->owner(), $transformer, User::class);
|
2019-04-18 13:57:22 +02:00
|
|
|
}
|
2019-03-27 05:50:13 +01:00
|
|
|
}
|