<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\SiteProductsMediaRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: SiteProductsMediaRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['site_product_media:read']],
denormalizationContext: ['groups' => ['site_product_media:write']],
order: ['id' => 'DESC'],
)]
class SiteProductsMedia
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['site_product:read', 'site_product:write', 'site_product_media:read', 'site_product_media:write', 'user_like:read', 'cat:read'])]
private ?int $id = null;
#[ORM\Column(length: 255, nullable: true)]
#[Groups(['site_product:read', 'site_product:write', 'site_product_media:read', 'site_product_media:write', 'user_like:read', 'cat:read'])]
private ?string $name = null;
#[ORM\ManyToOne(inversedBy: 'siteProductsMedia', cascade:['persist'])]
#[Groups(['site_product_media:read', 'site_product_media:write'])]
private ?SiteProducts $siteProduct = null;
#[ORM\ManyToOne(inversedBy: 'siteProductsMedia', cascade:['persist', 'remove'])]
#[Groups(['site_product:read', 'site_product:write', 'site_product_media:read', 'site_product_media:write', 'user_like:read', 'cat:read'])]
private ?MediaObject $media = null;
#[Groups(['site_product:read', 'site_product:write', 'site_product_media:read', 'site_product_media:write', 'user_like:read', 'cat:read'])]
#[ORM\Column(nullable: true)]
private ?bool $main = null;
#[ORM\OneToMany(mappedBy: 'mainSiteProductMedia', targetEntity: SiteProducts::class, cascade:['persist'])]
private Collection $siteProducts;
public function __construct()
{
$this->siteProducts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getSiteProduct(): ?SiteProducts
{
return $this->siteProduct;
}
public function setSiteProduct(?SiteProducts $siteProduct): static
{
$this->siteProduct = $siteProduct;
return $this;
}
public function getMedia(): ?MediaObject
{
return $this->media;
}
public function setMedia(?MediaObject $media): static
{
$this->media = $media;
return $this;
}
public function isMain(): ?bool
{
return $this->main;
}
public function setMain(?bool $main): static
{
$this->main = $main;
return $this;
}
/**
* @return Collection<int, SiteProducts>
*/
public function getSiteProducts(): Collection
{
return $this->siteProducts;
}
public function addSiteProduct(SiteProducts $siteProduct): static
{
if (!$this->siteProducts->contains($siteProduct)) {
$this->siteProducts->add($siteProduct);
$siteProduct->setMainSiteProductMedia($this);
}
return $this;
}
public function removeSiteProduct(SiteProducts $siteProduct): static
{
if ($this->siteProducts->removeElement($siteProduct)) {
// set the owning side to null (unless already changed)
if ($siteProduct->getMainSiteProductMedia() === $this) {
$siteProduct->setMainSiteProductMedia(null);
}
}
return $this;
}
}