1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 08:21:34 +02:00
invoiceninja/app/Ninja/Transformers/UserAccountTransformer.php

77 lines
3.1 KiB
PHP
Raw Normal View History

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;
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)
{
$account = $user->account;
2015-11-03 15:21:17 +01:00
return [
'account_key' => $account->account_key,
2018-06-28 17:16:11 +02:00
'name' => $account->present()->name ?: '',
'token' => $account->getToken($user->id, $this->tokenName),
'default_url' => SITE_URL,
2018-06-28 17:16:11 +02:00
'plan' => $account->company->plan ?: '',
'logo' => $account->logo ?: '',
2018-06-28 17:24:20 +02:00
'logo_url' => $account->getLogoURL() ?: '',
'currency_id' => (int) $account->currency_id,
'timezone_id' => (int) $account->timezone_id,
'date_format_id' => (int) $account->date_format_id,
'datetime_format_id' => (int) $account->datetime_format_id,
2018-06-28 17:16:11 +02:00
'invoice_terms' => $account->invoice_terms ?: '',
'invoice_taxes' => (bool) $account->invoice_taxes,
'invoice_item_taxes' => (bool) $account->invoice_item_taxes,
'invoice_design_id' => (int) $account->invoice_design_id,
'quote_design_id' => (int) $account->quote_design_id,
'language_id' => (int) $account->language_id,
2018-06-28 17:16:11 +02:00
'invoice_footer' => $account->invoice_footer ?: '',
'invoice_labels' => $account->invoice_labels ?: '',
'show_item_taxes' => (bool) $account->show_item_taxes,
'military_time' => (bool) $account->military_time,
'tax_name1' => $account->tax_name1 ?: '',
'tax_rate1' => (float) $account->tax_rate1,
'tax_name2' => $account->tax_name2 ?: '',
'tax_rate2' => (float) $account->tax_rate2,
2018-06-28 17:16:11 +02:00
'quote_terms' => $account->quote_terms ?: '',
'show_currency_code' => (bool) $account->show_currency_code,
'enable_second_tax_rate' => (bool) $account->enable_second_tax_rate,
2018-06-28 17:16:11 +02:00
'start_of_week' => (int) $account->start_of_week,
'financial_year_start' => (int) $account->financial_year_start,
'enabled_modules' => (int) $account->enabled_modules,
'payment_terms' => (int) $account->payment_terms,
'payment_type_id' => (int) $account->payment_type_id,
'task_rate' => (float) $account->task_rate,
2018-06-28 17:16:11 +02:00
'inclusive_taxes' => (bool) $account->inclusiveu_taxes,
'convert_products' => (bool) $account->convert_products,
2018-06-28 17:16:11 +02:00
'custom_invoice_taxes1' => (bool) $account->custom_invoice_taxes1,
'custom_invoice_taxes2' => (bool) $account->custom_invoice_taxes1,
'custom_fields' => $account->custom_fields ?: '',
2015-11-03 15:21:17 +01:00
];
}
}