<?php
namespace App\Entity;
use App\Entity\SuperClass\BaseEntity;
use App\Repository\CustomerRepository;
use App\Validator\IsValidOwner;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
/**
* @ORM\Entity(repositoryClass=CustomerRepository::class)
*/
class Customer extends BaseEntity
{
/**
* @ORM\Column(type="string", length=255)
*/
private $customer_id;
/**
* @ORM\Column(type="json")
*/
private $response = [];
/**
* @ORM\Column(type="customer_type")
*/
private $customer_type;
/**
* @ORM\OneToOne(targetEntity=User::class, inversedBy="customer", cascade={"persist", "remove"})
* @ORM\JoinColumn(nullable=true)
* @IsValidOwner()
*/
private $owner;
/**
* @ORM\ManyToOne(targetEntity=User::class, cascade={"persist", "remove"})
*/
private $created_by;
/**
* @ORM\OneToMany(targetEntity=Order::class, mappedBy="customer")
*/
private $orders;
public function __construct()
{
$this->orders = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCustomerId(): ?string
{
return $this->customer_id;
}
public function setCustomerId(string $customer_id): self
{
$this->customer_id = $customer_id;
return $this;
}
public function getResponse(): ?array
{
return $this->response;
}
public function setResponse(array $response): self
{
$this->response = $response;
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(User $user): self
{
$this->owner = $user;
return $this;
}
public function getCreatedBy(): ?User
{
return $this->created_by;
}
public function setCreatedBy(?User $created_by): self
{
$this->created_by = $created_by;
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): self
{
if (!$this->orders->contains($order)) {
$this->orders[] = $order;
$order->setCustomer($this);
}
return $this;
}
public function removeOrder(Order $order): self
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getCustomer() === $this) {
$order->setCustomer(null);
}
}
return $this;
}
public function getCustomerType()
{
return $this->customer_type;
}
public function setCustomerType($customer_type): self
{
$this->customer_type = $customer_type;
return $this;
}
}