src/Entity/Product.php line 27

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProductRepository;
  4. use App\Trait\SearchEngineOptimization;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClass: ProductRepository::class)]
  9. #[ORM\InheritanceType('JOINED')]
  10. #[ORM\DiscriminatorMap(
  11.     [
  12.         'hotelContract' => HotelContract::class,
  13.         'party' => Party::class,
  14.         'xmlAPI' => XmlApi::class,
  15.         'transfer' => Transfer::class,
  16.         'extra' => Extra::class,
  17.         'customService' => CustomService::class,
  18.         'manualFlight' => ManualFlight::class,
  19.         'manualTransfer' => ManualTransfer::class,
  20.     ]
  21. )]
  22. class Product
  23. {
  24.     use SearchEngineOptimization;
  25.     #[ORM\Id]
  26.     #[ORM\GeneratedValue]
  27.     #[ORM\Column]
  28.     private ?int $id = null;
  29.     #[ORM\ManyToOne(targetEntity: Provider::class , cascade: ['persist', 'detach'] )]
  30.     #[ORM\JoinColumn(nullable: false)]
  31.     private ?Provider $provider = null;
  32.     #[ORM\OneToMany(mappedBy: 'product', targetEntity: ProductElement::class, orphanRemoval: true)]
  33.     private Collection $productElements;
  34.     #[ORM\Column(nullable: true)]
  35.     private ?bool $onlyBack = null;
  36.     #[ORM\OneToMany(mappedBy: 'product', targetEntity: FileData::class , cascade: ['persist'])]
  37.     private Collection $images;
  38.     public function __construct()
  39.     {
  40.         $this->productElements = new ArrayCollection();
  41.         $this->images = new ArrayCollection();
  42.     }
  43.     public function getId(): ?int
  44.     {
  45.         return $this->id;
  46.     }
  47.     public function getProvider(): ?Provider
  48.     {
  49.         return $this->provider;
  50.     }
  51.     public function getPrimaryImageUrl(): ?string
  52.     {
  53.         foreach ($this->images as $image){
  54.             if($image->getDisplayOrder()==1){
  55.                 return $image->getUrl();
  56.             }
  57.         }
  58.         return null;
  59.     }
  60.     public function setProvider(?Provider $provider): self
  61.     {
  62.         $this->provider = $provider;
  63.         return $this;
  64.     }
  65.     public function getType(): string
  66.     {
  67.         return get_class($this);
  68.     }
  69.     /**
  70.      * @return Collection<int, ProductElement>
  71.      */
  72.     public function getProductElements(): Collection
  73.     {
  74.         return $this->productElements;
  75.     }
  76.     public function addProductElement(ProductElement $productElement): self
  77.     {
  78.         if (!$this->productElements->contains($productElement)) {
  79.             $this->productElements->add($productElement);
  80.             $productElement->setProduct($this);
  81.         }
  82.         return $this;
  83.     }
  84.     public function removeProductElement(ProductElement $productElement): self
  85.     {
  86.         if ($this->productElements->removeElement($productElement)) {
  87.             // set the owning side to null (unless already changed)
  88.             if ($productElement->getProduct() === $this) {
  89.                 $productElement->setProduct(null);
  90.             }
  91.         }
  92.         return $this;
  93.     }
  94.     public function isOnlyBack(): ?bool
  95.     {
  96.         return $this->onlyBack;
  97.     }
  98.     public function setOnlyBack(?bool $onlyBack): self
  99.     {
  100.         $this->onlyBack = $onlyBack;
  101.         return $this;
  102.     }
  103.     /**
  104.      * @return Collection<int, FileData>
  105.      */
  106.     public function getImages(): Collection
  107.     {
  108.         return $this->images;
  109.     }
  110.     public function addImage(FileData $image): static
  111.     {
  112.         if (!$this->images->contains($image)) {
  113.             $this->images->add($image);
  114.             $image->setProduct($this);
  115.         }
  116.         return $this;
  117.     }
  118.     public function removeImage(FileData $image): static
  119.     {
  120.         if ($this->images->removeElement($image)) {
  121.             // set the owning side to null (unless already changed)
  122.             if ($image->getProduct() === $this) {
  123.                 $image->setProduct(null);
  124.             }
  125.         }
  126.         return $this;
  127.     }
  128.     public function getClass()  : string {
  129.         return "Product";
  130.     }
  131.     public function getIcon() : string{
  132.         return "fe-square";
  133.     }
  134. }