src/Entity/Customer.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CustomerRepository;
  4. use App\Trait\Identity;
  5. use App\Trait\Person;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\DBAL\Types\Types;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Gedmo\Timestampable\Traits\TimestampableEntity;
  11. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  12. use Symfony\Component\Serializer\Annotation\Groups;
  13. #[ORM\InheritanceType('JOINED')]
  14. #[ORM\DiscriminatorColumn(name: "dtype", type: "string")]
  15. #[ORM\DiscriminatorMap(['moral' => CustomerMoral::class, 'physical' => CustomerPhysical::class])]
  16. #[ORM\Entity(repositoryClass: CustomerRepository::class)]
  17. #[UniqueEntity(['email'])]
  18. class Customer
  19. {
  20.     use TimestampableEntity;
  21.     use Person;
  22.     use Identity;
  23.     #[ORM\Id]
  24.     #[ORM\GeneratedValue]
  25.     #[ORM\Column(type: 'integer')]
  26.     #[Groups(['customer:read'])]
  27.     private ?int $id;
  28.     #[ORM\Column(length: 255, nullable: true)]
  29.     private ?string $auxiliaryCode = null; // for accountancy (optional)
  30.     #[ORM\Column(type: Types::TEXT, nullable: true)]
  31.     private ?string $note = null;
  32.     #[ORM\Column(length: 3, nullable: true)]
  33.     #[Groups(['customer:read'])]
  34.     private ?string $currency;
  35.     #[ORM\ManyToOne]
  36.     private ?Market $market = null;
  37.     #[ORM\ManyToOne]
  38.     private ?City $city = null;
  39.     #[ORM\OneToMany(mappedBy: 'customer', targetEntity: CustomerInfoType::class, orphanRemoval: true)]
  40.     private Collection $customerInfoTypes;
  41.     #[ORM\ManyToOne(targetEntity: self::class)]
  42.     private ?self $parent = null;
  43.     #[ORM\OneToOne(cascade: ['persist', 'remove'])]
  44.     private ?FileData $logo = null;
  45.     #[ORM\Column(nullable: true)]
  46.     private ?bool $isDefault = null;
  47.     #[ORM\Column(type: Types::BOOLEAN, nullable: true)]
  48.     private ?bool $active = null;
  49.     #[ORM\Column(nullable: true)]
  50.     private ?bool $showAllHotelXml = null;
  51.     #[ORM\OneToMany(mappedBy: 'customer', targetEntity: CustomerAirlineXmlApi::class)]
  52.     private Collection $customerAirlineXmlApis;
  53.     #[ORM\ManyToOne]
  54.     private ?Agency $agency = null;
  55.     public function __construct()
  56.     {
  57.         $this->customerInfoTypes = new ArrayCollection();
  58.         $this->customerAirlineXmlApis = new ArrayCollection();
  59.     }
  60.     public function getId(): ?int
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function getCurrency(): ?string
  65.     {
  66.         return $this->currency;
  67.     }
  68.     public function setCurrency(?string $currency): self
  69.     {
  70.         $this->currency = $currency;
  71.         return $this;
  72.     }
  73.     public function getMarket(): ?Market
  74.     {
  75.         return $this->market;
  76.     }
  77.     public function setMarket(?Market $market): self
  78.     {
  79.         $this->market = $market;
  80.         return $this;
  81.     }
  82.     public function getAuxiliaryCode(): ?string
  83.     {
  84.         return $this->auxiliaryCode;
  85.     }
  86.     public function setAuxiliaryCode(?string $auxiliary_code): self
  87.     {
  88.         $this->auxiliaryCode = $auxiliary_code;
  89.         return $this;
  90.     }
  91.     public function getNote(): ?string
  92.     {
  93.         return $this->note;
  94.     }
  95.     public function setNote(?string $note): self
  96.     {
  97.         $this->note = $note;
  98.         return $this;
  99.     }
  100.     public function getCity(): ?City
  101.     {
  102.         return $this->city;
  103.     }
  104.     public function setCity(?City $city): self
  105.     {
  106.         $this->city = $city;
  107.         return $this;
  108.     }
  109.     /**
  110.      * @return Collection<int, CustomerInfoType>
  111.      */
  112.     public function getCustomerInfoTypes(): Collection
  113.     {
  114.         return $this->customerInfoTypes;
  115.     }
  116.     public function addCustomerInfoType(CustomerInfoType $customerInfoType): self
  117.     {
  118.         if (!$this->customerInfoTypes->contains($customerInfoType)) {
  119.             $this->customerInfoTypes->add($customerInfoType);
  120.             $customerInfoType->setCustomer($this);
  121.         }
  122.         return $this;
  123.     }
  124.     public function removeCustomerInfoType(CustomerInfoType $customerInfoType): self
  125.     {
  126.         if ($this->customerInfoTypes->removeElement($customerInfoType)) {
  127.             // set the owning side to null (unless already changed)
  128.             if ($customerInfoType->getCustomer() === $this) {
  129.                 $customerInfoType->setCustomer(null);
  130.             }
  131.         }
  132.         return $this;
  133.     }
  134.     public function getParent(): ?self
  135.     {
  136.         return $this->parent;
  137.     }
  138.     public function setParent(?self $parent): self
  139.     {
  140.         $this->parent = $parent;
  141.         return $this;
  142.     }
  143.     public function getLogo(): ?FileData
  144.     {
  145.         return $this->logo;
  146.     }
  147.     public function setLogo(?FileData $logo): self
  148.     {
  149.         $this->logo = $logo;
  150.         return $this;
  151.     }
  152.     public function isIsDefault(): ?bool
  153.     {
  154.         return $this->isDefault;
  155.     }
  156.     public function setIsDefault(?bool $isDefault): self
  157.     {
  158.         $this->isDefault = $isDefault;
  159.         return $this;
  160.     }
  161.     public function getActive(): ?bool
  162.     {
  163.         return $this->active;
  164.     }
  165.     public function setActive(?bool $active): self
  166.     {
  167.         $this->active = $active;
  168.         return $this;
  169.     }
  170.     public function __toString(): string
  171.     {
  172.         return $this->name;
  173.     }
  174.     public function getApiKey(): ?string
  175.     {
  176.         return hash('md5', $this->getId());
  177.     }
  178.     public function isShowAllHotelXml(): ?bool
  179.     {
  180.         return $this->showAllHotelXml;
  181.     }
  182.     public function setShowAllHotelXml(bool $showAllHotelXml): static
  183.     {
  184.         $this->showAllHotelXml = $showAllHotelXml;
  185.         return $this;
  186.     }
  187.     public function getResellerMargin(): ?float
  188.     {
  189.         return 0;
  190.     }
  191.     public function getClass()  : string {
  192.         return "Customer";
  193.     }
  194.     /**
  195.      * @return Collection<int, CustomerAirlineXmlApi>
  196.      */
  197.     public function getCustomerAirlineXmlApis(): Collection
  198.     {
  199.         return $this->customerAirlineXmlApis;
  200.     }
  201.     public function addCustomerAirlineXmlApi(CustomerAirlineXmlApi $customerAirlineXmlApi): static
  202.     {
  203.         if (!$this->customerAirlineXmlApis->contains($customerAirlineXmlApi)) {
  204.             $this->customerAirlineXmlApis->add($customerAirlineXmlApi);
  205.             $customerAirlineXmlApi->setCustomer($this);
  206.         }
  207.         return $this;
  208.     }
  209.     public function removeCustomerAirlineXmlApi(CustomerAirlineXmlApi $customerAirlineXmlApi): static
  210.     {
  211.         if ($this->customerAirlineXmlApis->removeElement($customerAirlineXmlApi)) {
  212.             // set the owning side to null (unless already changed)
  213.             if ($customerAirlineXmlApi->getCustomer() === $this) {
  214.                 $customerAirlineXmlApi->setCustomer(null);
  215.             }
  216.         }
  217.         return $this;
  218.     }
  219.     public function getAgency(): ?Agency
  220.     {
  221.         return $this->agency;
  222.     }
  223.     public function setAgency(?Agency $agency): static
  224.     {
  225.         $this->agency = $agency;
  226.         return $this;
  227.     }
  228. }