1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Transformers/CompanyUserTransformer.php

86 lines
2.0 KiB
PHP
Raw Normal View History

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
*
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
2019-03-28 03:36:36 +01:00
namespace App\Transformers;
use App\Models\Company;
use App\Models\CompanyToken;
2019-03-28 03:36:36 +01:00
use App\Models\CompanyUser;
use App\Models\User;
use App\Transformers\CompanyTokenTransformer;
2019-03-28 03:36:36 +01:00
/**
* @SWG\Definition(definition="CompanyUser", @SWG\Xml(name="CompanyUser"))
*/
class CompanyUserTransformer extends EntityTransformer
{
/**
* @var array
*/
protected $defaultIncludes = [
'company',
'user',
'token'
2019-03-28 03:36:36 +01:00
];
/**
* @var array
*/
protected $availableIncludes = [
'user',
'company',
'token'
2019-03-28 03:36:36 +01:00
];
public function transform(CompanyUser $company_user)
{
return [
'permissions' => $company_user->permissions,
'settings' => $company_user->settings,
'is_owner' => (bool) $company_user->is_owner,
'is_admin' => (bool) $company_user->is_admin,
'is_locked' => (bool) $company_user->is_locked,
'updated_at' => $company_user->updated_at,
'deleted_at' => $company_user->deleted_at,
];
}
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);
}
public function includeToken(CompanyUser $company_user)
{
$transformer = new CompanyTokenTransformer($this->serializer);
return $this->includeItem($company_user->token, $transformer, CompanyToken::class);
}
2019-03-28 03:36:36 +01:00
}