1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +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
*/
2023-08-21 03:29:31 +02:00
protected array $defaultIncludes = [
2020-08-05 04:12:38 +02:00
];
/**
* @var array
*/
2023-08-21 03:29:31 +02:00
protected array $availableIncludes = [
2020-08-05 04:12:38 +02:00
];
/**
* @param Company $company
*
* @return array
*/
public function transform(Company $company)
{
2024-01-14 05:05:00 +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)
{
2024-01-14 05:05:00 +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,
];
2024-01-14 05:05:00 +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;
}
}