<?php
namespace App\Entity;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Annotation\ApiSubresource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
use App\Repository\FiltersFilterRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity(repositoryClass=FiltersFilterRepository::class)
* @ApiResource(
* normalizationContext={
* "groups"={"filters_filter:read"}
* },
* denormalizationContext={
* "groups"={"filters_filter:write"}
* },
* collectionOperations={
* "get"={"security"="is_granted('ROLE_USER')"},
* "post"={"security"="is_granted('ROLE_ADMIN')"},
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_USER')"},
* "patch"={"security"="is_granted('ROLE_ADMIN')"},
* "delete"={"security"="is_granted('ROLE_ADMIN')"}
* }
* )
* @ApiFilter(OrderFilter::class, properties={"id", "name", "active", "createdAt", "isBinary", "filtersCategory.name", "filtersCategory.id"})
* @ApiFilter(SearchFilter::class, properties={"name": "partial", "active": "exact", "isBinary": "exact", "filtersCategory.name": "partial", "filtersCategory.id": "exact", "channels.name": "partial", "channels.id": "exact"})
* @ApiFilter(BooleanFilter::class, properties={"active", "isBinary"})
* @ApiFilter(GroupFilter::class, arguments={"parameterName": "groups", "overrideDefaultGroups": true, "whitelist": {
* "filter_form"
* }})
* @ApiFilter(PropertyFilter::class,
* arguments={
* "parameterName"="fields",
* "overrideDefaultProperties"=true
* }
* )
*/
class FiltersFilter
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"filters_filter:read", "filters_category:read", "video:read", "channel:read", "filter_form"})
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
* @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read", "video:read", "channel:read",
* "filter_form", "video_form_complete"})
*/
private $name;
/**
* @ORM\Column(type="boolean", options={"default": "1"})
* @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read", "video:read", "channel:read"})
*/
private $active = true;
/**
* @ORM\Column(type="datetime")
* @Groups({"filters_filter:read"})
*/
private $createdAt;
/**
* @ORM\Column(type="boolean", options={"default": "0"})
* @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read", "video:read", "channel:read"})
*/
private $isBinary = false;
/**
* @ORM\ManyToMany(targetEntity=FiltersCategory::class, inversedBy="filtersFilters")
* @Groups({"filters_filter:read", "filters_filter:write", "video:read", "channel:read"})
*/
private $filtersCategory;
/**
* @ORM\ManyToMany(targetEntity=Video::class, mappedBy="filters")
* @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read"})
*/
private $videos;
/**
* @ORM\Column(name="`rank`", type="integer", nullable=true)
* @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read"})
*/
private $rank;
public function __construct()
{
$this->filtersCategory = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->active = true;
$this->isBinary = false;
$this->videos = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getIsBinary(): ?bool
{
return $this->isBinary;
}
public function setIsBinary(bool $isBinary): self
{
$this->isBinary = $isBinary;
return $this;
}
/**
* @return Collection|FiltersCategory[]
*/
public function getFiltersCategory(): Collection
{
return $this->filtersCategory;
}
public function addFiltersCategory(FiltersCategory $filtersCategory): self
{
if (!$this->filtersCategory->contains($filtersCategory)) {
$this->filtersCategory[] = $filtersCategory;
}
return $this;
}
public function removeFiltersCategory(FiltersCategory $filtersCategory): self
{
$this->filtersCategory->removeElement($filtersCategory);
return $this;
}
/**
* @return Collection|Video[]
*/
public function getVideos(): Collection
{
return $this->videos;
}
public function addVideo(Video $video): self
{
if (!$this->videos->contains($video)) {
$this->videos[] = $video;
$video->addFilter($this);
}
return $this;
}
public function removeVideo(Video $video): self
{
if ($this->videos->removeElement($video)) {
$video->removeFilter($this);
}
return $this;
}
public function getRank(): ?int
{
return $this->rank;
}
public function setRank(?int $rank): self
{
$this->rank = $rank;
return $this;
}
}