2019-03-28 03:36:36 +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-28 03:36:36 +01:00
|
|
|
|
|
|
|
namespace App\Transformers;
|
|
|
|
|
2019-09-12 14:02:25 +02:00
|
|
|
use App\Models\Account;
|
2019-03-28 03:36:36 +01:00
|
|
|
use App\Models\Company;
|
2019-06-25 05:55:02 +02:00
|
|
|
use App\Models\CompanyToken;
|
2019-03-28 03:36:36 +01:00
|
|
|
use App\Models\CompanyUser;
|
|
|
|
use App\Models\User;
|
2019-09-12 14:02:25 +02:00
|
|
|
use App\Transformers\AccountTransformer;
|
2019-06-25 05:55:02 +02:00
|
|
|
use App\Transformers\CompanyTokenTransformer;
|
2019-12-25 13:22:10 +01:00
|
|
|
use App\Transformers\UserTransformer;
|
|
|
|
use App\Transformers\CompanyTransformer;
|
2019-03-28 03:36:36 +01:00
|
|
|
|
|
|
|
class CompanyUserTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $defaultIncludes = [
|
2019-10-30 08:55:22 +01:00
|
|
|
// 'account',
|
|
|
|
// 'company',
|
|
|
|
// 'user',
|
|
|
|
// 'token'
|
|
|
|
];
|
2019-03-28 03:36:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
|
|
|
'user',
|
2019-06-25 05:55:02 +02:00
|
|
|
'company',
|
2019-09-12 14:02:25 +02:00
|
|
|
'token',
|
|
|
|
'account',
|
2019-03-28 03:36:36 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
public function transform(CompanyUser $company_user)
|
|
|
|
{
|
2019-09-18 08:02:05 +02:00
|
|
|
return [
|
2019-11-26 10:11:22 +01:00
|
|
|
// 'id' => $company_user->id,
|
|
|
|
// 'account_id' => $company_user->account_id,
|
|
|
|
// 'user_id' => $company_user->user_id,
|
|
|
|
// 'company_id' => $company_user->company_id,
|
2020-03-09 11:04:47 +01:00
|
|
|
'permissions' => $company_user->permissions ?: '',
|
2020-03-09 10:38:15 +01:00
|
|
|
'notifications' => (object)$company_user->notifications,
|
|
|
|
'settings' => (object)$company_user->settings,
|
2019-03-28 03:36:36 +01:00
|
|
|
'is_owner' => (bool) $company_user->is_owner,
|
|
|
|
'is_admin' => (bool) $company_user->is_admin,
|
|
|
|
'is_locked' => (bool) $company_user->is_locked,
|
2019-11-22 22:10:53 +01:00
|
|
|
'updated_at' => (int)$company_user->updated_at,
|
2020-01-07 01:13:47 +01:00
|
|
|
'archived_at' => (int)$company_user->deleted_at,
|
2020-02-27 00:32:44 +01:00
|
|
|
'created_at' => (int)$company_user->created_at,
|
2019-09-18 08:02:05 +02:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2019-09-12 14:02:25 +02:00
|
|
|
public function includeAccount(CompanyUser $company_user)
|
|
|
|
{
|
|
|
|
$transformer = new AccountTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($company_user->account, $transformer, Account::class);
|
|
|
|
}
|
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
public function includeCompany(CompanyUser $company_user)
|
|
|
|
{
|
|
|
|
$transformer = new CompanyTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($company_user->company, $transformer, Company::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeUser(CompanyUser $company_user)
|
|
|
|
{
|
|
|
|
$transformer = new UserTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeItem($company_user->user, $transformer, User::class);
|
|
|
|
}
|
|
|
|
|
2019-06-25 05:55:02 +02:00
|
|
|
public function includeToken(CompanyUser $company_user)
|
|
|
|
{
|
2020-02-26 04:26:07 +01:00
|
|
|
$token = $company_user->tokens->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->first();
|
|
|
|
|
2019-06-25 05:55:02 +02:00
|
|
|
$transformer = new CompanyTokenTransformer($this->serializer);
|
|
|
|
|
2020-02-26 04:26:07 +01:00
|
|
|
return $this->includeItem($token, $transformer, CompanyToken::class);
|
2019-06-25 05:55:02 +02:00
|
|
|
}
|
2019-03-28 03:36:36 +01:00
|
|
|
}
|