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\Account;
|
2019-04-18 08:11:37 +02:00
|
|
|
use App\Models\Company;
|
|
|
|
use App\Models\CompanyToken;
|
2019-05-22 02:56:47 +02:00
|
|
|
use App\Models\CompanyUser;
|
2019-03-28 03:36:36 +01:00
|
|
|
use App\Models\User;
|
2019-04-18 08:11:37 +02:00
|
|
|
use App\Transformers\CompanyTokenTransformer;
|
|
|
|
use App\Transformers\CompanyTransformer;
|
2019-05-22 02:56:47 +02:00
|
|
|
use App\Transformers\CompanyUserTransformer;
|
2019-04-03 02:09:22 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-03-28 03:36:36 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @SWG\Definition(definition="User", @SWG\Xml(name="User"))
|
|
|
|
*/
|
|
|
|
class UserTransformer extends EntityTransformer
|
|
|
|
{
|
2019-04-03 02:09:22 +02:00
|
|
|
use MakesHash;
|
2019-03-28 03:36:36 +01:00
|
|
|
/**
|
|
|
|
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
|
|
|
|
* @SWG\Property(property="first_name", type="string", example="John")
|
|
|
|
* @SWG\Property(property="last_name", type="string", example="Doe")
|
|
|
|
* @SWG\Property(property="email", type="string", example="johndoe@isp.com")
|
|
|
|
* @SWG\Property(property="account_key", type="string", example="123456")
|
|
|
|
* @SWG\Property(property="updated_at", type="integer", example=1451160233, readOnly=true)
|
|
|
|
* @SWG\Property(property="deleted_at", type="integer", example=1451160233, readOnly=true)
|
|
|
|
* @SWG\Property(property="phone", type="string", example="(212) 555-1212")
|
|
|
|
* @SWG\Property(property="registered", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="confirmed", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="oauth_user_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="oauth_provider_id", type="integer", example=1)
|
|
|
|
* @SWG\Property(property="notify_sent", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="notify_viewed", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="notify_paid", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="notify_approved", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="is_admin", type="boolean", example=false)
|
|
|
|
* @SWG\Property(property="permissions", type="integer", example=1)
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $defaultIncludes = [
|
2019-04-18 08:11:37 +02:00
|
|
|
'company_token',
|
2019-04-18 13:57:22 +02:00
|
|
|
|
2019-03-28 03:36:36 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $availableIncludes = [
|
2019-04-18 13:57:22 +02:00
|
|
|
'companies',
|
2019-05-22 02:56:47 +02:00
|
|
|
'company_tokens',
|
2019-03-28 03:36:36 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
public function transform(User $user)
|
|
|
|
{
|
|
|
|
return [
|
2019-04-03 02:09:22 +02:00
|
|
|
'id' => $this->encodePrimaryKey($user->id),
|
2019-03-28 03:36:36 +01:00
|
|
|
'first_name' => $user->first_name,
|
|
|
|
'last_name' => $user->last_name,
|
|
|
|
'email' => $user->email,
|
2019-06-03 23:46:46 +02:00
|
|
|
'last_login' => $user->last_login,
|
2019-03-28 03:36:36 +01:00
|
|
|
'updated_at' => $user->updated_at,
|
|
|
|
'deleted_at' => $user->deleted_at,
|
|
|
|
'phone' => $user->phone,
|
|
|
|
'email_verified_at' => $user->email_verified_at,
|
|
|
|
'oauth_user_id' => $user->oauth_user_id,
|
|
|
|
'oauth_provider_id' => $user->oauth_provider_id,
|
|
|
|
'signature' => $user->signature,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function includeUserCompany(User $user)
|
|
|
|
{
|
2019-06-03 23:46:46 +02:00
|
|
|
//cannot use this here as it will fail retrieving the company as we depend on the token in the header which may not be present for this request
|
2019-05-22 02:56:47 +02:00
|
|
|
//$transformer = new CompanyUserTransformer($this->serializer);
|
2019-03-28 03:36:36 +01:00
|
|
|
|
2019-05-22 02:56:47 +02:00
|
|
|
//return $this->includeItem($user->user_company(), $transformer, CompanyUser::class);
|
2019-03-28 03:36:36 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-18 08:11:37 +02:00
|
|
|
public function includeCompanies(User $user)
|
|
|
|
{
|
2019-05-22 02:56:47 +02:00
|
|
|
|
2019-04-18 08:11:37 +02:00
|
|
|
$transformer = new CompanyTransformer($this->serializer);
|
|
|
|
|
2019-05-22 02:56:47 +02:00
|
|
|
return $this->includeCollection($user->companies, $transformer, Company::class);
|
|
|
|
|
2019-04-18 08:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function includeCompanyToken(User $user)
|
|
|
|
{
|
2019-05-22 02:56:47 +02:00
|
|
|
|
2019-04-18 08:11:37 +02:00
|
|
|
$transformer = new CompanyTokenTransformer($this->serializer);
|
|
|
|
|
2019-04-18 13:57:22 +02:00
|
|
|
return $this->includeItem($user->token(), $transformer, CompanyToken::class);
|
2019-04-18 08:11:37 +02:00
|
|
|
|
2019-05-22 02:56:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function includeCompanyTokens(User $user)
|
|
|
|
{
|
|
|
|
|
|
|
|
$transformer = new CompanyTokenTransformer($this->serializer);
|
|
|
|
|
|
|
|
return $this->includeCollection($user->tokens, $transformer, CompanyToken::class);
|
2019-04-18 08:11:37 +02:00
|
|
|
|
|
|
|
}
|
2019-03-28 03:36:36 +01:00
|
|
|
}
|