src/Entity/Address.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Annotation\Exportable;
  4. use App\Annotation\ExportableEntity;
  5. use App\Entity\Interfaces\AddressInterface;
  6. use App\Repository\AddressRepository;
  7. use App\Traits\AddressTrait;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use ReflectionClass;
  12. /**
  13. * @ORM\Entity(repositoryClass=AddressRepository::class)
  14. *
  15. * @ExportableEntity()
  16. */
  17. class Address implements AddressInterface
  18. {
  19. const TYPE_BILLING_ADDRESS = 'billing_address';
  20. const TYPE_SHIPPING_ADDRESS = 'shipping_address';
  21. use AddressTrait;
  22. /**
  23. * @ORM\ManyToOne(targetEntity=User::class, inversedBy="addresses")
  24. * @ORM\JoinColumn(nullable=false)
  25. */
  26. private $user;
  27. /**
  28. * @ORM\Column(type="string", length=255, options={"default": self::TYPE_SHIPPING_ADDRESS})
  29. *
  30. * @Exportable()
  31. */
  32. private $addressType = self::TYPE_SHIPPING_ADDRESS;
  33. /**
  34. * @ORM\OneToMany(targetEntity=CartItemShipping::class, mappedBy="shippingAddress")
  35. */
  36. private $cartItemShippings;
  37. /**
  38. * @ORM\Column(type="boolean", nullable=true)
  39. *
  40. * @Exportable()
  41. */
  42. private $preferred;
  43. /**
  44. * @ORM\Column(type="text", nullable=true)
  45. */
  46. private $comment;
  47. /**
  48. * @ORM\Column(type="boolean", nullable=false, options={"default": true})
  49. */
  50. private bool $isBillingAddress = true;
  51. public function __construct()
  52. {
  53. $this->cartItemShippings = new ArrayCollection();
  54. }
  55. /**
  56. * @return array
  57. */
  58. public static function getAddressTypes(): array
  59. {
  60. $typesAddress = [];
  61. $reflect = new ReflectionClass( __CLASS__ );
  62. foreach ( $reflect->getConstants() as $k => $const ) {
  63. if ( preg_match( "/^(TYPE)/", $k ) ) {
  64. $typesAddress[ $const ] = str_replace( "_", ".", $const );
  65. }
  66. }
  67. return $typesAddress;
  68. }
  69. /*
  70. * ============================================================================================
  71. * =============================== FONCTIONS CUSTOM ===========================================
  72. * ============================================================================================
  73. */
  74. public function __toString()
  75. {
  76. return $this->getName();
  77. }
  78. /*
  79. * ============================================================================================
  80. * ============================== FIN FONCTIONS CUSTOM ========================================
  81. * ============================================================================================
  82. */
  83. /**
  84. * @return User|null
  85. */
  86. public function getUser(): ?User
  87. {
  88. return $this->user;
  89. }
  90. public function setUser( ?User $user ): self
  91. {
  92. $this->user = $user;
  93. return $this;
  94. }
  95. public function getAddressType(): ?string
  96. {
  97. return $this->addressType;
  98. }
  99. public function setAddressType( ?string $addressType ): self
  100. {
  101. $this->addressType = $addressType;
  102. return $this;
  103. }
  104. /**
  105. * @return Collection|CartItemShipping[]
  106. */
  107. public function getCartItemShippings(): Collection
  108. {
  109. return $this->cartItemShippings;
  110. }
  111. public function addCartItemShipping( CartItemShipping $cartItemShipping ): self
  112. {
  113. if ( !$this->cartItemShippings->contains( $cartItemShipping ) ) {
  114. $this->cartItemShippings[] = $cartItemShipping;
  115. $cartItemShipping->setShippingAddress( $this );
  116. }
  117. return $this;
  118. }
  119. public function removeCartItemShipping( CartItemShipping $cartItemShipping ): self
  120. {
  121. if ( $this->cartItemShippings->removeElement( $cartItemShipping ) ) {
  122. // set the owning side to null (unless already changed)
  123. if ( $cartItemShipping->getShippingAddress() === $this ) {
  124. $cartItemShipping->setShippingAddress( NULL );
  125. }
  126. }
  127. return $this;
  128. }
  129. public function getPreferred(): ?bool
  130. {
  131. return $this->preferred;
  132. }
  133. public function setPreferred( ?bool $preferred ): self
  134. {
  135. $this->preferred = $preferred;
  136. return $this;
  137. }
  138. public function getComment(): ?string
  139. {
  140. return $this->comment;
  141. }
  142. public function setComment( ?string $comment ): self
  143. {
  144. $this->comment = $comment;
  145. return $this;
  146. }
  147. public function isIsBillingAddress(): ?bool
  148. {
  149. return $this->isBillingAddress;
  150. }
  151. public function setIsBillingAddress(bool $isBillingAddress): self
  152. {
  153. $this->isBillingAddress = $isBillingAddress;
  154. return $this;
  155. }
  156. }