1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00
invoiceninja/app/Transformers/UserTransformer.php
David Bomba 957ac9f5d8
Fix for password protected authorization (#3198)
* Remove unnecessary save() on invoice

* Update copyright

* Working on Credit Repository

* Implement credits as a paymentable entity

* Add credit_id to transformer

* fix rules for update payment

* Fix random deleted_at keys in transformers

* Fix for password_protect check
2020-01-07 11:13:47 +11:00

102 lines
2.9 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Transformers;
use App\Models\Account;
use App\Models\Company;
use App\Models\CompanyToken;
use App\Models\CompanyUser;
use App\Models\User;
use App\Transformers\CompanyTokenTransformer;
use App\Transformers\CompanyTransformer;
use App\Transformers\CompanyUserTransformer;
use App\Utils\Traits\MakesHash;
use Illuminate\Support\Carbon;
class UserTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [
//'company_users',
// 'token',
];
/**
* @var array
*/
protected $availableIncludes = [
'companies',
'company_users',
'company_user'
];
public function transform(User $user)
{
return [
'id' => $this->encodePrimaryKey($user->id),
'first_name' => $user->first_name ?: '',
'last_name' => $user->last_name ?: '',
'email' => $user->email ?: '',
'last_login' => Carbon::parse($user->last_login)->timestamp,
'updated_at' => $user->updated_at,
'archived_at' => $user->deleted_at,
'phone' => $user->phone ?: '',
'email_verified_at' => $user->getEmailVerifiedAt(),
'signature' => $user->signature ?: '',
'custom_value1' => $user->custom_value1 ?: '',
'custom_value2' => $user->custom_value2 ?: '',
'custom_value3' => $user->custom_value3 ?: '',
'custom_value4' => $user->custom_value4 ?: '',
];
}
public function includeCompanies(User $user)
{
$transformer = new CompanyTransformer($this->serializer);
return $this->includeCollection($user->companies, $transformer, Company::class);
}
public function includeToken(User $user)
{
$transformer = new CompanyTokenTransformer($this->serializer);
return $this->includeItem($user->token, $transformer, CompanyToken::class);
}
public function includeCompanyTokens(User $user)
{
$transformer = new CompanyTokenTransformer($this->serializer);
return $this->includeCollection($user->tokens, $transformer, CompanyToken::class);
}
public function includeCompanyUsers(User $user)
{
$transformer = new CompanyUserTransformer($this->serializer);
return $this->includeCollection($user->company_users, $transformer, CompanyUser::class);
}
public function includeCompanyUser(User $user)
{
$transformer = new CompanyUserTransformer($this->serializer);
return $this->includeItem($user->company_user, $transformer, CompanyUser::class);
}
}