2021-03-14 10:45:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
2021-07-28 14:18:47 +02:00
|
|
|
namespace App\Http\Resources\Api\V2;
|
2021-03-14 10:45:42 +01:00
|
|
|
|
|
|
|
|
use App\Models\Brand;
|
|
|
|
|
use App\Models\Customer;
|
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
|
|
class CustomerResource extends JsonResource
|
|
|
|
|
{
|
2021-10-26 12:02:10 +02:00
|
|
|
/** @var \App\Models\Customer */
|
2021-03-14 10:45:42 +01:00
|
|
|
private $customer;
|
|
|
|
|
|
2021-10-26 12:02:10 +02:00
|
|
|
/** @var \App\Models\CustomerInfo */
|
2021-03-14 10:45:42 +01:00
|
|
|
private $info;
|
|
|
|
|
|
2021-10-26 12:02:10 +02:00
|
|
|
/** @var \App\Models\CustomerLogin */
|
2021-03-14 10:45:42 +01:00
|
|
|
private $login;
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/** @var array */
|
2021-03-14 10:45:42 +01:00
|
|
|
private static $skeleton = [
|
2023-09-06 17:24:53 +02:00
|
|
|
'hashcode' => '',
|
|
|
|
|
'firstname' => '',
|
|
|
|
|
'lastname' => '',
|
|
|
|
|
'email' => '',
|
2021-03-14 10:45:42 +01:00
|
|
|
'birth_date' => '',
|
2023-09-06 17:24:53 +02:00
|
|
|
'address' => '',
|
|
|
|
|
'address2' => '',
|
|
|
|
|
'phone' => '',
|
|
|
|
|
'country' => '',
|
|
|
|
|
'city' => '',
|
|
|
|
|
'postcode' => '',
|
|
|
|
|
'opt_in' => '',
|
|
|
|
|
'status' => '',
|
2021-03-14 10:45:42 +01:00
|
|
|
'last_connection' => ''
|
|
|
|
|
];
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
2023-09-06 17:24:53 +02:00
|
|
|
* CustomerResource.
|
2021-12-19 15:57:24 +01:00
|
|
|
*
|
2023-06-23 17:18:59 +02:00
|
|
|
* @param \App\Models\Brand $brand
|
|
|
|
|
* @param \App\Models\Customer $customer
|
2021-12-19 15:57:24 +01:00
|
|
|
*/
|
2021-03-14 10:45:42 +01:00
|
|
|
public function __construct(Brand $brand, Customer $customer)
|
|
|
|
|
{
|
|
|
|
|
$this->customer = $customer;
|
2021-08-23 20:20:51 +02:00
|
|
|
$this->info = $customer->info($brand, Customer::FIRST_OR_FAIL);
|
|
|
|
|
$this->login = $customer->login($brand, Customer::FIRST_OR_FAIL);
|
2021-03-14 10:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Transform the resource into an array.
|
|
|
|
|
*
|
2021-12-19 15:57:24 +01:00
|
|
|
* @param \Illuminate\Http\Request|null $request
|
2021-03-14 10:45:42 +01:00
|
|
|
* @return array
|
2021-12-19 15:57:24 +01:00
|
|
|
* + email string
|
2021-03-14 10:45:42 +01:00
|
|
|
* + firstname string
|
|
|
|
|
* + lastname string
|
|
|
|
|
* + birth_date datetime
|
|
|
|
|
* + address string
|
|
|
|
|
* + address2 string
|
|
|
|
|
* + phone string
|
|
|
|
|
* + country string
|
|
|
|
|
* + city string
|
|
|
|
|
* + postcode string
|
|
|
|
|
* + opt_in boolean
|
|
|
|
|
* + hashcode string
|
|
|
|
|
* + status boolean
|
2021-12-19 15:57:24 +01:00
|
|
|
* + last_connection date
|
2023-09-06 17:24:53 +02:00
|
|
|
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass, Squiz.Commenting.FunctionComment.Missing
|
2021-03-14 10:45:42 +01:00
|
|
|
*/
|
2023-09-06 17:24:53 +02:00
|
|
|
public function toArray($request = null): array
|
2021-03-14 10:45:42 +01:00
|
|
|
{
|
2023-09-06 17:24:53 +02:00
|
|
|
//phpcs:enable
|
2021-08-04 09:42:48 +02:00
|
|
|
$data = array_intersect_key(
|
2021-03-14 10:45:42 +01:00
|
|
|
array_merge(
|
|
|
|
|
[
|
|
|
|
|
'email' => $this->customer->email
|
|
|
|
|
],
|
|
|
|
|
$this->login->toArray(),
|
|
|
|
|
$this->info->toArray(),
|
|
|
|
|
['status' => $this->login->status]
|
|
|
|
|
),
|
|
|
|
|
$this->getSkeleton()
|
|
|
|
|
);
|
2021-08-04 09:42:48 +02:00
|
|
|
|
2023-09-06 17:24:53 +02:00
|
|
|
$data['country'] = $this->info->country->value();
|
2021-10-26 12:36:52 +02:00
|
|
|
$data['address2'] = $this->info->address2 ?? '';
|
2021-08-04 09:42:48 +02:00
|
|
|
return $data;
|
2021-03-14 10:45:42 +01:00
|
|
|
}
|
|
|
|
|
|
2021-12-19 15:57:24 +01:00
|
|
|
/**
|
|
|
|
|
* Returns the resource skeletton
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
2021-03-14 10:45:42 +01:00
|
|
|
public static function getSkeleton(): array
|
|
|
|
|
{
|
|
|
|
|
return self::$skeleton;
|
|
|
|
|
}
|
|
|
|
|
}
|