1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 23:22:52 +01:00
invoiceninja/app/Ninja/Transformers/UserAccountTransformer.php

40 lines
1.1 KiB
PHP
Raw Normal View History

2015-11-03 15:21:17 +01:00
<?php namespace App\Ninja\Transformers;
use App\Models\User;
2015-11-09 03:10:01 +01:00
use App\Models\Account;
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 = [
'user'
];
2015-11-03 15:21:17 +01:00
2015-11-05 09:44:48 +01:00
protected $tokenName;
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);
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),
'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
];
}
}