src/Entity/Address.php line 16

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