first commit
This commit is contained in:
@@ -0,0 +1,255 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace KupShop\UserAddressesBundle\Entity;
|
||||
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
class DeliveryAddressEntity
|
||||
{
|
||||
private ?int $id = null;
|
||||
private ?int $id_user = null;
|
||||
#[Assert\NotBlank]
|
||||
private string $name = '';
|
||||
#[Assert\NotBlank]
|
||||
private string $surname = '';
|
||||
private string $firm = '';
|
||||
#[Assert\NotBlank]
|
||||
private string $street = '';
|
||||
#[Assert\NotBlank]
|
||||
private string $city = '';
|
||||
#[Assert\NotBlank]
|
||||
private string $zip = '';
|
||||
private string $country = '';
|
||||
private string $currency = '';
|
||||
private string $phone = '';
|
||||
private string $state = '';
|
||||
#[Assert\Email]
|
||||
private string $email = '';
|
||||
private string $customAddress = '';
|
||||
|
||||
public function getCompleteAddress(): string
|
||||
{
|
||||
return "{$this->street}, {$this->city} {$this->zip}";
|
||||
}
|
||||
|
||||
public function getAddressWithName(): string
|
||||
{
|
||||
if (empty($this->name) || empty($this->surname)) {
|
||||
if (empty($this->firm)) {
|
||||
return $this->getCompleteAddress();
|
||||
}
|
||||
|
||||
return "{$this->firm}, {$this->getCompleteAddress()}";
|
||||
}
|
||||
|
||||
if (empty($this->firm)) {
|
||||
return "{$this->name} {$this->surname}, {$this->street}, {$this->city} {$this->zip}";
|
||||
}
|
||||
|
||||
return "{$this->name} {$this->surname} ({$this->firm}), {$this->street}, {$this->city} {$this->zip}";
|
||||
}
|
||||
|
||||
public function getAddressArray(): array
|
||||
{
|
||||
$data = [
|
||||
'id' => $this->getId(),
|
||||
'delivery_name' => $this->getName(),
|
||||
'delivery_surname' => $this->getSurname(),
|
||||
'delivery_firm' => $this->getFirm(),
|
||||
'delivery_street' => $this->getStreet(),
|
||||
'delivery_city' => $this->getCity(),
|
||||
'delivery_zip' => $this->getZip(),
|
||||
'delivery_country' => $this->getCountry(),
|
||||
'delivery_currency' => $this->getCurrency(),
|
||||
'delivery_phone' => $this->getPhone(),
|
||||
'delivery_state' => $this->getState(),
|
||||
'delivery_email' => $this->getEmail(),
|
||||
'delivery_customAddress' => $this->getCustomAddress(),
|
||||
];
|
||||
|
||||
return array_filter($data, function ($value) {
|
||||
return $value !== '';
|
||||
});
|
||||
}
|
||||
|
||||
public function getCartAddressArray(): array
|
||||
{
|
||||
$data = [];
|
||||
|
||||
foreach ($this->getAddressArray() as $key => $value) {
|
||||
$data[str_replace('delivery_', '', $key)] = $value;
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getIdUser(): ?int
|
||||
{
|
||||
return $this->id_user;
|
||||
}
|
||||
|
||||
public function setIdUser(?int $id_user): DeliveryAddressEntity
|
||||
{
|
||||
$this->id_user = $id_user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function setId(?int $id): DeliveryAddressEntity
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function setName(string $name): DeliveryAddressEntity
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getSurname(): string
|
||||
{
|
||||
return $this->surname;
|
||||
}
|
||||
|
||||
public function setSurname(string $surname): DeliveryAddressEntity
|
||||
{
|
||||
$this->surname = $surname;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getFirm(): string
|
||||
{
|
||||
return $this->firm;
|
||||
}
|
||||
|
||||
public function setFirm(string $firm): DeliveryAddressEntity
|
||||
{
|
||||
$this->firm = $firm;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStreet(): string
|
||||
{
|
||||
return $this->street;
|
||||
}
|
||||
|
||||
public function setStreet(string $street): DeliveryAddressEntity
|
||||
{
|
||||
$this->street = $street;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCity(): string
|
||||
{
|
||||
return $this->city;
|
||||
}
|
||||
|
||||
public function setCity(string $city): DeliveryAddressEntity
|
||||
{
|
||||
$this->city = $city;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getZip(): string
|
||||
{
|
||||
return $this->zip;
|
||||
}
|
||||
|
||||
public function setZip(string $zip): DeliveryAddressEntity
|
||||
{
|
||||
$this->zip = $zip;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCountry(): string
|
||||
{
|
||||
return $this->country;
|
||||
}
|
||||
|
||||
public function setCountry(string $country): DeliveryAddressEntity
|
||||
{
|
||||
$this->country = $country;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getPhone(): string
|
||||
{
|
||||
return $this->phone;
|
||||
}
|
||||
|
||||
public function setPhone(string $phone): DeliveryAddressEntity
|
||||
{
|
||||
$this->phone = $phone;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getState(): string
|
||||
{
|
||||
return $this->state;
|
||||
}
|
||||
|
||||
public function setState(string $state): DeliveryAddressEntity
|
||||
{
|
||||
$this->state = $state;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
public function setEmail(string $email): DeliveryAddressEntity
|
||||
{
|
||||
$this->email = $email;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCustomAddress(): string
|
||||
{
|
||||
return $this->customAddress;
|
||||
}
|
||||
|
||||
public function setCustomAddress(string $customAddress): DeliveryAddressEntity
|
||||
{
|
||||
$this->customAddress = $customAddress;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCurrency(): string
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
public function setCurrency(string $currency): DeliveryAddressEntity
|
||||
{
|
||||
$this->currency = $currency;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user