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

86 lines
2.3 KiB
PHP
Raw Normal View History

2020-08-05 04:12:38 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2020-08-05 04:12:38 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-28 23:21:40 +01:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
2020-08-05 04:12:38 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2020-08-05 04:12:38 +02:00
*/
namespace App\Transformers\Shop;
use App\Models\Company;
2020-08-05 04:21:26 +02:00
use App\Transformers\EntityTransformer;
2020-08-05 04:12:38 +02:00
use App\Utils\Traits\MakesHash;
2020-10-28 11:10:49 +01:00
use stdClass;
2020-08-05 04:12:38 +02:00
/**
* Class CompanyShopProfileTransformer.
*/
class CompanyShopProfileTransformer extends EntityTransformer
{
use MakesHash;
/**
* @var array
*/
protected $defaultIncludes = [
];
/**
* @var array
*/
protected $availableIncludes = [
];
/**
* @param Company $company
*
* @return array
*/
public function transform(Company $company)
{
2020-10-28 11:10:49 +01:00
$std = new stdClass;
2020-08-05 04:12:38 +02:00
return [
'company_key' => (string) $company->company_key ?: '',
2020-08-05 04:12:38 +02:00
'settings' => $this->trimCompany($company),
];
}
private function trimCompany($company)
{
2020-10-28 11:10:49 +01:00
$std = new stdClass;
2020-08-05 04:27:47 +02:00
2020-08-05 04:12:38 +02:00
$trimmed_company_settings = [
2020-08-05 04:27:47 +02:00
'custom_fields' => $company->custom_fields ?: $std,
2020-08-05 04:12:38 +02:00
'custom_value1' => $company->settings->custom_value1,
'custom_value2' => $company->settings->custom_value2,
'custom_value3' => $company->settings->custom_value3,
'custom_value4' => $company->settings->custom_value4,
'name' => $company->settings->name,
'company_logo' => $company->settings->company_logo,
'website' => $company->settings->website,
'address1' => $company->settings->address1,
'address2' => $company->settings->address2,
'city' => $company->settings->city,
'state' => $company->settings->state,
'postal_code' => $company->settings->postal_code,
'phone' => $company->settings->phone,
'email' => $company->settings->email,
'country_id' => $company->settings->country_id,
'vat_number' => $company->settings->vat_number,
];
2020-10-28 11:10:49 +01:00
$new_settings = new stdClass;
2020-08-05 04:12:38 +02:00
foreach ($trimmed_company_settings as $key => $value) {
2020-08-05 04:12:38 +02:00
$new_settings->{$key} = $value;
}
2020-08-05 04:12:38 +02:00
return $new_settings;
}
}