src/Entity/Distributor.php line 20

Open in your IDE?
  1. <?php
  2.     namespace App\Entity;
  3.     use App\Repository\DistributorRepository;
  4.     use App\Traits\DateTrait;
  5.     use Doctrine\Common\Collections\ArrayCollection;
  6.     use Doctrine\Common\Collections\Collection;
  7.     use Doctrine\ORM\Mapping as ORM;
  8.     use JMS\Serializer\Annotation as Serializer;
  9.     use JMS\Serializer\Annotation\Expose;
  10.     use JMS\Serializer\Annotation\Groups;
  11.     use JMS\Serializer\Annotation\SerializedName;
  12.     /**
  13.      * @ORM\Entity(repositoryClass=DistributorRepository::class)
  14.      *
  15.      * @Serializer\ExclusionPolicy("ALL")
  16.      */
  17.     class Distributor
  18.     {
  19.         use DateTrait;
  20.         /**
  21.          * @ORM\Id
  22.          * @ORM\GeneratedValue
  23.          * @ORM\Column(type="integer")
  24.          *
  25.          * @Expose
  26.          * @Groups({"distributor", "export_distributor_datatable"})
  27.          */
  28.         private ?int $id NULL;
  29.         /**
  30.          * @ORM\Column(type="string", length=255, nullable=true)
  31.          *
  32.          * @Expose
  33.          * @Groups({"distributor", "export_distributor_datatable", "export_purchase_declaration_datatable"})
  34.          */
  35.         private ?string $company NULL;
  36.         /**
  37.          * @ORM\Column(type="string", length=255, nullable=true)
  38.          *
  39.          * @Expose
  40.          * @Groups({"distributor", "export_commercial_installer_datatable", "export_distributor_datatable", "export_installer_datatable"})
  41.          */
  42.         private ?string $postcode NULL;
  43.         /**
  44.          * @ORM\Column(type="string", length=255, nullable=true)
  45.          *
  46.          * @Expose
  47.          * @Groups({"distributor", "export_commercial_installer_datatable", "export_distributor_datatable", "export_installer_datatable"})
  48.          */
  49.         private ?string $city NULL;
  50.         /**
  51.          * @ORM\Column(type="string", length=80, nullable=true)
  52.          *
  53.          * @Expose
  54.          * @Groups({"distributor", "export_distributor_datatable"})
  55.          */
  56.         private ?string $internalCode NULL;
  57.         /**
  58.          * @ORM\Column(type="boolean", options={"default" : true}, nullable=true)
  59.          *
  60.          * @Expose
  61.          * @Groups({"distributor", "export_distributor_datatable"})
  62.          */
  63.         private ?bool $enabled TRUE;
  64.         /**
  65.          * @ORM\ManyToMany(targetEntity=User::class, mappedBy="distributors")
  66.          */
  67.         private Collection $users;
  68.         /**
  69.          * @ORM\OneToMany(targetEntity=Purchase::class, mappedBy="distributor")
  70.          */
  71.         private Collection $purchases;
  72.         /**
  73.          * @ORM\Column(type="string", length=255, nullable=true)
  74.          */
  75.         private ?string $address1 NULL;
  76.         public function __construct()
  77.         {
  78.             $this->users     = new ArrayCollection();
  79.             $this->purchases = new ArrayCollection();
  80.         }
  81.         /**
  82.          * @Serializer\VirtualProperty()
  83.          * @SerializedName("codeDep")
  84.          * @Expose
  85.          * @Groups({"export_installer_datatable", "export_commercial_installer_datatable"})
  86.          *
  87.          * @return false|string|null
  88.          */
  89.         public function getCodeDep()
  90.         {
  91.             return $this->getPostcode() !== NULL substr($this->getPostcode(), 02) : NULL;
  92.         }
  93.         public function getPostcode(): ?string
  94.         {
  95.             return $this->postcode;
  96.         }
  97.         public function setPostcode(?string $postcode): self
  98.         {
  99.             $this->postcode $postcode;
  100.             return $this;
  101.         }
  102.         public function getId(): ?int
  103.         {
  104.             return $this->id;
  105.         }
  106.         public function getCompany(): ?string
  107.         {
  108.             return $this->company;
  109.         }
  110.         public function setCompany(?string $company): self
  111.         {
  112.             $this->company $company;
  113.             return $this;
  114.         }
  115.         public function getCity(): ?string
  116.         {
  117.             return $this->city;
  118.         }
  119.         public function setCity(?string $city): self
  120.         {
  121.             $this->city $city;
  122.             return $this;
  123.         }
  124.         public function getInternalCode(): ?string
  125.         {
  126.             return $this->internalCode;
  127.         }
  128.         public function setInternalCode(?string $internalCode): self
  129.         {
  130.             $this->internalCode $internalCode;
  131.             return $this;
  132.         }
  133.         public function getEnabled(): ?bool
  134.         {
  135.             return $this->enabled;
  136.         }
  137.         public function setEnabled(?bool $enabled): self
  138.         {
  139.             $this->enabled $enabled;
  140.             return $this;
  141.         }
  142.         /**
  143.          * @return Collection|User[]
  144.          */
  145.         public function getUsers(): Collection
  146.         {
  147.             return $this->users;
  148.         }
  149.         public function addUser(User $user): self
  150.         {
  151.             if (!$this->users->contains($user)) {
  152.                 $this->users[] = $user;
  153.                 $user->addDistributor($this);
  154.             }
  155.             return $this;
  156.         }
  157.         public function removeUser(User $user): self
  158.         {
  159.             if ($this->users->removeElement($user)) {
  160.                 $user->removeDistributor($this);
  161.             }
  162.             return $this;
  163.         }
  164.         /**
  165.          * @return Collection|Purchase[]
  166.          */
  167.         public function getPurchases(): Collection
  168.         {
  169.             return $this->purchases;
  170.         }
  171.         public function addPurchase(Purchase $purchase): self
  172.         {
  173.             if (!$this->purchases->contains($purchase)) {
  174.                 $this->purchases[] = $purchase;
  175.                 $purchase->setDistributor($this);
  176.             }
  177.             return $this;
  178.         }
  179.         public function removePurchase(Purchase $purchase): self
  180.         {
  181.             if ($this->purchases->removeElement($purchase)) {
  182.                 // set the owning side to null (unless already changed)
  183.                 if ($purchase->getDistributor() === $this) {
  184.                     $purchase->setDistributor(NULL);
  185.                 }
  186.             }
  187.             return $this;
  188.         }
  189.         public function getAddress1(): ?string
  190.         {
  191.             return $this->address1;
  192.         }
  193.         public function setAddress1(?string $address1): self
  194.         {
  195.             $this->address1 $address1;
  196.             return $this;
  197.         }
  198.     }