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

39 lines
1008 B
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
use League\Fractal;
use League\Fractal\TransformerAbstract;
2015-11-05 09:44:48 +01:00
use League\Fractal\Resource\Item;
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 [
'account_key' => $user->account->account_key,
2015-11-06 11:59:53 +01:00
'name' => $user->account->present()->name,
2015-11-04 16:23:22 +01:00
'token' => $user->account->getToken($this->tokenName),
'default_url' => SITE_URL
2015-11-03 15:21:17 +01:00
];
}
}