src/Entity/Product.php line 26

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(repositoryClassProductRepository::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.     ]
  20. )]
  21. class Product
  22. {
  23.     use SearchEngineOptimization;
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column]
  27.     private ?int $id null;
  28.     #[ORM\ManyToOne(targetEntityProvider::class , cascade: ['persist''detach'] )]
  29.     #[ORM\JoinColumn(nullablefalse)]
  30.     private ?Provider $provider null;
  31.     #[ORM\OneToMany(mappedBy'product'targetEntityProductElement::class, orphanRemovaltrue)]
  32.     private Collection $productElements;
  33.     #[ORM\Column(nullabletrue)]
  34.     private ?bool $onlyBack null;
  35.     #[ORM\OneToMany(mappedBy'product'targetEntityFileData::class , cascade: ['persist'])]
  36.     private Collection $images;
  37.     public function __construct()
  38.     {
  39.         $this->productElements = new ArrayCollection();
  40.         $this->images = new ArrayCollection();
  41.     }
  42.     public function getId(): ?int
  43.     {
  44.         return $this->id;
  45.     }
  46.     public function getProvider(): ?Provider
  47.     {
  48.         return $this->provider;
  49.     }
  50.     public function getPrimaryImageUrl(): ?string
  51.     {
  52.         foreach ($this->images as $image){
  53.             if($image->getDisplayOrder()==1){
  54.                 return $image->getUrl();
  55.             }
  56.         }
  57.         return null;
  58.     }
  59.     public function setProvider(?Provider $provider): self
  60.     {
  61.         $this->provider $provider;
  62.         return $this;
  63.     }
  64.     public function getType(): string
  65.     {
  66.         return get_class($this);
  67.     }
  68.     /**
  69.      * @return Collection<int, ProductElement>
  70.      */
  71.     public function getProductElements(): Collection
  72.     {
  73.         return $this->productElements;
  74.     }
  75.     public function addProductElement(ProductElement $productElement): self
  76.     {
  77.         if (!$this->productElements->contains($productElement)) {
  78.             $this->productElements->add($productElement);
  79.             $productElement->setProduct($this);
  80.         }
  81.         return $this;
  82.     }
  83.     public function removeProductElement(ProductElement $productElement): self
  84.     {
  85.         if ($this->productElements->removeElement($productElement)) {
  86.             // set the owning side to null (unless already changed)
  87.             if ($productElement->getProduct() === $this) {
  88.                 $productElement->setProduct(null);
  89.             }
  90.         }
  91.         return $this;
  92.     }
  93.     public function isOnlyBack(): ?bool
  94.     {
  95.         return $this->onlyBack;
  96.     }
  97.     public function setOnlyBack(?bool $onlyBack): self
  98.     {
  99.         $this->onlyBack $onlyBack;
  100.         return $this;
  101.     }
  102.     /**
  103.      * @return Collection<int, FileData>
  104.      */
  105.     public function getImages(): Collection
  106.     {
  107.         return $this->images;
  108.     }
  109.     public function addImage(FileData $image): static
  110.     {
  111.         if (!$this->images->contains($image)) {
  112.             $this->images->add($image);
  113.             $image->setProduct($this);
  114.         }
  115.         return $this;
  116.     }
  117.     public function removeImage(FileData $image): static
  118.     {
  119.         if ($this->images->removeElement($image)) {
  120.             // set the owning side to null (unless already changed)
  121.             if ($image->getProduct() === $this) {
  122.                 $image->setProduct(null);
  123.             }
  124.         }
  125.         return $this;
  126.     }
  127.     public function getClass()  : string {
  128.         return "Product";
  129.     }
  130.     public function getIcon() : string{
  131.         return "fe-square";
  132.     }
  133. }