src/Entity/Customer.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\SuperClass\BaseEntity;
  4. use App\Repository\CustomerRepository;
  5. use App\Validator\IsValidOwner;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Gedmo\Mapping\Annotation as Gedmo;
  10. /**
  11. * @ORM\Entity(repositoryClass=CustomerRepository::class)
  12. */
  13. class Customer extends BaseEntity
  14. {
  15. /**
  16. * @ORM\Column(type="string", length=255)
  17. */
  18. private $customer_id;
  19. /**
  20. * @ORM\Column(type="json")
  21. */
  22. private $response = [];
  23. /**
  24. * @ORM\Column(type="customer_type")
  25. */
  26. private $customer_type;
  27. /**
  28. * @ORM\OneToOne(targetEntity=User::class, inversedBy="customer", cascade={"persist", "remove"})
  29. * @ORM\JoinColumn(nullable=true)
  30. * @IsValidOwner()
  31. */
  32. private $owner;
  33. /**
  34. * @ORM\ManyToOne(targetEntity=User::class, cascade={"persist", "remove"})
  35. */
  36. private $created_by;
  37. /**
  38. * @ORM\OneToMany(targetEntity=Order::class, mappedBy="customer")
  39. */
  40. private $orders;
  41. public function __construct()
  42. {
  43. $this->orders = new ArrayCollection();
  44. }
  45. public function getId(): ?int
  46. {
  47. return $this->id;
  48. }
  49. public function getCustomerId(): ?string
  50. {
  51. return $this->customer_id;
  52. }
  53. public function setCustomerId(string $customer_id): self
  54. {
  55. $this->customer_id = $customer_id;
  56. return $this;
  57. }
  58. public function getResponse(): ?array
  59. {
  60. return $this->response;
  61. }
  62. public function setResponse(array $response): self
  63. {
  64. $this->response = $response;
  65. return $this;
  66. }
  67. public function getOwner(): ?User
  68. {
  69. return $this->owner;
  70. }
  71. public function setOwner(User $user): self
  72. {
  73. $this->owner = $user;
  74. return $this;
  75. }
  76. public function getCreatedBy(): ?User
  77. {
  78. return $this->created_by;
  79. }
  80. public function setCreatedBy(?User $created_by): self
  81. {
  82. $this->created_by = $created_by;
  83. return $this;
  84. }
  85. /**
  86. * @return Collection<int, Order>
  87. */
  88. public function getOrders(): Collection
  89. {
  90. return $this->orders;
  91. }
  92. public function addOrder(Order $order): self
  93. {
  94. if (!$this->orders->contains($order)) {
  95. $this->orders[] = $order;
  96. $order->setCustomer($this);
  97. }
  98. return $this;
  99. }
  100. public function removeOrder(Order $order): self
  101. {
  102. if ($this->orders->removeElement($order)) {
  103. // set the owning side to null (unless already changed)
  104. if ($order->getCustomer() === $this) {
  105. $order->setCustomer(null);
  106. }
  107. }
  108. return $this;
  109. }
  110. public function getCustomerType()
  111. {
  112. return $this->customer_type;
  113. }
  114. public function setCustomerType($customer_type): self
  115. {
  116. $this->customer_type = $customer_type;
  117. return $this;
  118. }
  119. }