src/Entity/SiteProductsMedia.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\SiteProductsMediaRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Component\Serializer\Annotation\Groups;
  9. #[ORM\Entity(repositoryClassSiteProductsMediaRepository::class)]
  10. #[ApiResource(
  11.     normalizationContext: ['groups' => ['site_product_media:read']],
  12.     denormalizationContext: ['groups' => ['site_product_media:write']],
  13.     order: ['id' => 'DESC'],
  14. )]
  15. class SiteProductsMedia
  16. {
  17.     #[ORM\Id]
  18.     #[ORM\GeneratedValue]
  19.     #[ORM\Column]
  20.     #[Groups(['site_product:read''site_product:write''site_product_media:read''site_product_media:write''user_like:read''cat:read'])]
  21.     private ?int $id null;
  22.     #[ORM\Column(length255nullabletrue)]
  23.     #[Groups(['site_product:read''site_product:write''site_product_media:read''site_product_media:write''user_like:read''cat:read'])]
  24.     private ?string $name null;
  25.     #[ORM\ManyToOne(inversedBy'siteProductsMedia'cascade:['persist'])]
  26.     #[Groups(['site_product_media:read''site_product_media:write'])]
  27.     private ?SiteProducts $siteProduct null;
  28.     #[ORM\ManyToOne(inversedBy'siteProductsMedia'cascade:['persist''remove'])]
  29.     #[Groups(['site_product:read''site_product:write''site_product_media:read''site_product_media:write''user_like:read''cat:read'])]
  30.     private ?MediaObject $media null;
  31.     #[Groups(['site_product:read''site_product:write''site_product_media:read''site_product_media:write''user_like:read''cat:read'])]
  32.     #[ORM\Column(nullabletrue)]
  33.     private ?bool $main null;
  34.     #[ORM\OneToMany(mappedBy'mainSiteProductMedia'targetEntitySiteProducts::class,  cascade:['persist'])]
  35.     private Collection $siteProducts;
  36.     public function __construct()
  37.     {
  38.         $this->siteProducts = new ArrayCollection();
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(?string $name): static
  49.     {
  50.         $this->name $name;
  51.         return $this;
  52.     }
  53.     public function getSiteProduct(): ?SiteProducts
  54.     {
  55.         return $this->siteProduct;
  56.     }
  57.     public function setSiteProduct(?SiteProducts $siteProduct): static
  58.     {
  59.         $this->siteProduct $siteProduct;
  60.         return $this;
  61.     }
  62.     public function getMedia(): ?MediaObject
  63.     {
  64.         return $this->media;
  65.     }
  66.     public function setMedia(?MediaObject $media): static
  67.     {
  68.         $this->media $media;
  69.         return $this;
  70.     }
  71.     public function isMain(): ?bool
  72.     {
  73.         return $this->main;
  74.     }
  75.     public function setMain(?bool $main): static
  76.     {
  77.         $this->main $main;
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return Collection<int, SiteProducts>
  82.      */
  83.     public function getSiteProducts(): Collection
  84.     {
  85.         return $this->siteProducts;
  86.     }
  87.     public function addSiteProduct(SiteProducts $siteProduct): static
  88.     {
  89.         if (!$this->siteProducts->contains($siteProduct)) {
  90.             $this->siteProducts->add($siteProduct);
  91.             $siteProduct->setMainSiteProductMedia($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function removeSiteProduct(SiteProducts $siteProduct): static
  96.     {
  97.         if ($this->siteProducts->removeElement($siteProduct)) {
  98.             // set the owning side to null (unless already changed)
  99.             if ($siteProduct->getMainSiteProductMedia() === $this) {
  100.                 $siteProduct->setMainSiteProductMedia(null);
  101.             }
  102.         }
  103.         return $this;
  104.     }
  105. }