2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Transformers;
|
2015-11-03 15:21:17 +01:00
|
|
|
|
2015-11-09 03:10:01 +01:00
|
|
|
use App\Models\Account;
|
2017-01-30 20:40:43 +01:00
|
|
|
use App\Models\User;
|
2015-11-03 15:21:17 +01:00
|
|
|
|
2015-11-09 03:10:01 +01:00
|
|
|
class UserAccountTransformer extends EntityTransformer
|
2015-11-03 15:21:17 +01:00
|
|
|
{
|
2015-11-05 09:44:48 +01:00
|
|
|
protected $defaultIncludes = [
|
2017-01-30 20:40:43 +01:00
|
|
|
'user',
|
2015-11-05 09:44:48 +01:00
|
|
|
];
|
2015-11-03 15:21:17 +01:00
|
|
|
|
2015-11-05 09:44:48 +01:00
|
|
|
protected $tokenName;
|
2016-10-21 13:29:01 +02:00
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
public function __construct(Account $account, $serializer, $tokenName)
|
2015-11-03 15:21:17 +01:00
|
|
|
{
|
2015-11-27 13:55:28 +01:00
|
|
|
parent::__construct($account, $serializer);
|
2015-11-09 03:10:01 +01:00
|
|
|
|
2015-11-04 16:23:22 +01:00
|
|
|
$this->tokenName = $tokenName;
|
2015-11-03 15:21:17 +01:00
|
|
|
}
|
|
|
|
|
2015-11-05 09:44:48 +01:00
|
|
|
public function includeUser(User $user)
|
|
|
|
{
|
2015-11-27 13:55:28 +01:00
|
|
|
$transformer = new UserTransformer($this->account, $this->serializer);
|
2017-01-30 20:40:43 +01:00
|
|
|
|
2015-11-27 13:55:28 +01:00
|
|
|
return $this->includeItem($user, $transformer, 'user');
|
2015-11-05 09:44:48 +01:00
|
|
|
}
|
|
|
|
|
2015-11-03 15:21:17 +01:00
|
|
|
public function transform(User $user)
|
|
|
|
{
|
|
|
|
return [
|
2016-10-26 03:01:36 +02:00
|
|
|
'account_key' => $user->account->account_key,
|
|
|
|
'name' => $user->account->present()->name,
|
|
|
|
'token' => $user->account->getToken($user->id, $this->tokenName),
|
2016-06-21 11:21:50 +02:00
|
|
|
'default_url' => SITE_URL,
|
2016-10-26 03:01:36 +02:00
|
|
|
'plan' => $user->account->company->plan,
|
|
|
|
'logo' => $user->account->logo,
|
|
|
|
'logo_url' => $user->account->getLogoURL(),
|
2015-11-03 15:21:17 +01:00
|
|
|
];
|
|
|
|
}
|
2016-10-21 13:29:01 +02:00
|
|
|
}
|