1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
invoiceninja/app/Transformers/UserTransformer.php

99 lines
2.4 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\Account;
2019-04-18 08:11:37 +02:00
use App\Models\Company;
use App\Models\CompanyToken;
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;
use App\Transformers\CompanyUserTransformer;
2019-04-03 02:09:22 +02:00
use App\Utils\Traits\MakesHash;
2019-10-04 13:54:03 +02:00
use Illuminate\Support\Carbon;
2019-03-28 03:36:36 +01:00
class UserTransformer extends EntityTransformer
{
2019-04-03 02:09:22 +02:00
use MakesHash;
2019-03-28 03:36:36 +01:00
/**
* @var array
*/
protected $defaultIncludes = [
//'company_users',
// 'token',
2019-03-28 03:36:36 +01:00
];
/**
* @var array
*/
protected $availableIncludes = [
2019-04-18 13:57:22 +02:00
'companies',
'company_users',
2019-03-28 03:36:36 +01:00
];
public function transform(User $user)
{
2019-10-04 13:54:03 +02:00
2019-03-28 03:36:36 +01:00
return [
2019-04-03 02:09:22 +02:00
'id' => $this->encodePrimaryKey($user->id),
2019-09-27 00:14:02 +02:00
'first_name' => $user->first_name ?: '',
'last_name' => $user->last_name ?: '',
'email' => $user->email ?: '',
2019-10-04 13:54:03 +02:00
'last_login' => Carbon::parse($user->last_login)->timestamp,
2019-03-28 03:36:36 +01:00
'updated_at' => $user->updated_at,
'deleted_at' => $user->deleted_at,
2019-09-27 00:14:02 +02:00
'phone' => $user->phone ?: '',
2019-10-04 13:54:03 +02:00
'email_verified_at' => $user->getEmailVerifiedAt(),
2019-09-27 00:14:02 +02:00
'signature' => $user->signature ?: '',
2019-03-28 03:36:36 +01:00
];
}
2019-04-18 08:11:37 +02:00
public function includeCompanies(User $user)
{
2019-04-18 08:11:37 +02:00
$transformer = new CompanyTransformer($this->serializer);
return $this->includeCollection($user->companies, $transformer, Company::class);
2019-04-18 08:11:37 +02:00
}
public function includeToken(User $user)
2019-04-18 08:11:37 +02:00
{
2019-04-18 08:11:37 +02:00
$transformer = new CompanyTokenTransformer($this->serializer);
return $this->includeItem($user->token, $transformer, CompanyToken::class);
2019-04-18 08:11:37 +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
}
public function includeCompanyUsers(User $user)
{
$transformer = new CompanyUserTransformer($this->serializer);
return $this->includeCollection($user->user_companies, $transformer, CompanyUser::class);
}
2019-03-28 03:36:36 +01:00
}