2019-03-28 03:36:36 +01:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2019-05-11 05:32:07 +02:00
|
|
|
*/
|
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;
|
|
|
|
|
|
|
|
class CompanyUserTransformer extends EntityTransformer
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $defaultIncludes = [
|
2020-12-08 21:12:10 +01:00
|
|
|
// 'user',
|
2022-06-21 11:57:17 +02:00
|
|
|
];
|
2019-03-28 03:36:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2023-08-21 03:29:31 +02:00
|
|
|
protected array $availableIncludes = [
|
2019-03-28 03:36:36 +01:00
|
|
|
'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)
|
|
|
|
{
|
2021-04-29 09:34:30 +02:00
|
|
|
$blank_obj = new \stdClass;
|
|
|
|
|
2019-09-18 08:02:05 +02:00
|
|
|
return [
|
2020-03-09 11:04:47 +01:00
|
|
|
'permissions' => $company_user->permissions ?: '',
|
2022-08-16 01:39:12 +02:00
|
|
|
'notifications' => $company_user->notifications ? (object) $company_user->notifications : $blank_obj,
|
|
|
|
'settings' => $company_user->settings ? (object) $company_user->settings : $blank_obj,
|
2023-06-06 09:42:11 +02:00
|
|
|
'react_settings' => $company_user->react_settings ? (object) $company_user->react_settings : $blank_obj,
|
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,
|
2020-09-06 11:38:10 +02:00
|
|
|
'updated_at' => (int) $company_user->updated_at,
|
|
|
|
'archived_at' => (int) $company_user->deleted_at,
|
|
|
|
'created_at' => (int) $company_user->created_at,
|
2021-01-29 13:29:42 +01:00
|
|
|
'permissions_updated_at' => (int) $company_user->permissions_updated_at,
|
2021-06-11 06:16:21 +02:00
|
|
|
'ninja_portal_url' => (string) $company_user->ninja_portal_url,
|
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);
|
2020-11-13 10:09:20 +01:00
|
|
|
$company_user->user->company_id = $company_user->company_id;
|
2019-03-28 03:36:36 +01:00
|
|
|
|
|
|
|
return $this->includeItem($company_user->user, $transformer, User::class);
|
|
|
|
}
|
|
|
|
|
2019-06-25 05:55:02 +02:00
|
|
|
public function includeToken(CompanyUser $company_user)
|
|
|
|
{
|
2023-03-13 11:31:15 +01:00
|
|
|
$token = $company_user->tokens()
|
|
|
|
->where('company_id', $company_user->company_id)
|
|
|
|
->where('user_id', $company_user->user_id)
|
|
|
|
->where('is_system', 1)
|
|
|
|
->first();
|
2020-02-26 04:26:07 +01:00
|
|
|
|
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
|
|
|
}
|