src/Entity/FiltersFilter.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Core\Annotation\ApiFilter;
  4. use ApiPlatform\Core\Annotation\ApiResource;
  5. use ApiPlatform\Core\Annotation\ApiSubresource;
  6. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
  7. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  9. use ApiPlatform\Core\Serializer\Filter\GroupFilter;
  10. use ApiPlatform\Core\Serializer\Filter\PropertyFilter;
  11. use App\Repository\FiltersFilterRepository;
  12. use Doctrine\Common\Collections\ArrayCollection;
  13. use Doctrine\Common\Collections\Collection;
  14. use Doctrine\ORM\Mapping as ORM;
  15. use Gedmo\Mapping\Annotation as Gedmo;
  16. use Symfony\Component\Serializer\Annotation\Groups;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. /**
  19.  * @ORM\Entity(repositoryClass=FiltersFilterRepository::class)
  20.  * @ApiResource(
  21.  *      normalizationContext={
  22.  *         "groups"={"filters_filter:read"}
  23.  *      },
  24.  *      denormalizationContext={
  25.  *          "groups"={"filters_filter:write"}
  26.  *      },
  27.  *      collectionOperations={
  28.  *          "get"={"security"="is_granted('ROLE_USER')"},
  29.  *          "post"={"security"="is_granted('ROLE_ADMIN')"},
  30.  *      },
  31.  *      itemOperations={
  32.  *          "get"={"security"="is_granted('ROLE_USER')"},
  33.  *          "patch"={"security"="is_granted('ROLE_ADMIN')"},
  34.  *          "delete"={"security"="is_granted('ROLE_ADMIN')"}
  35.  *      }
  36.  * )
  37.  * @ApiFilter(OrderFilter::class, properties={"id", "name", "active", "createdAt", "isBinary", "filtersCategory.name", "filtersCategory.id"})
  38.  * @ApiFilter(SearchFilter::class, properties={"name": "partial", "active": "exact", "isBinary": "exact", "filtersCategory.name": "partial", "filtersCategory.id": "exact", "channels.name": "partial", "channels.id": "exact"})
  39.  * @ApiFilter(BooleanFilter::class, properties={"active", "isBinary"})
  40.  * @ApiFilter(GroupFilter::class, arguments={"parameterName": "groups", "overrideDefaultGroups": true, "whitelist": {
  41.  *      "filter_form"
  42.  * }})
  43.  * @ApiFilter(PropertyFilter::class, 
  44.  *      arguments={
  45.  *          "parameterName"="fields", 
  46.  *          "overrideDefaultProperties"=true
  47.  *     }
  48.  * )
  49.  */
  50. class FiltersFilter
  51. {
  52.     /**
  53.      * @ORM\Id
  54.      * @ORM\GeneratedValue
  55.      * @ORM\Column(type="integer")
  56.      * @Groups({"filters_filter:read", "filters_category:read", "video:read", "channel:read", "filter_form"})
  57.      */
  58.     private $id;
  59.     /**
  60.      * @ORM\Column(type="string", length=255)
  61.      * @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read", "video:read", "channel:read",
  62.      *     "filter_form", "video_form_complete"})
  63.      */
  64.     private $name;
  65.     /**
  66.      * @ORM\Column(type="boolean", options={"default": "1"})
  67.      * @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read", "video:read", "channel:read"})
  68.      */
  69.     private $active true;
  70.     /**
  71.      * @ORM\Column(type="datetime")
  72.      * @Groups({"filters_filter:read"})
  73.      */
  74.     private $createdAt;
  75.     /**
  76.      * @ORM\Column(type="boolean", options={"default": "0"})
  77.      * @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read", "video:read", "channel:read"})
  78.      */
  79.     private $isBinary false;
  80.     /**
  81.      * @ORM\ManyToMany(targetEntity=FiltersCategory::class, inversedBy="filtersFilters")
  82.      * @Groups({"filters_filter:read", "filters_filter:write", "video:read", "channel:read"})
  83.      */
  84.     private $filtersCategory;
  85.     /**
  86.      * @ORM\ManyToMany(targetEntity=Video::class, mappedBy="filters")
  87.      * @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read"})
  88.      */
  89.     private $videos;
  90.     /**
  91.      * @ORM\Column(name="`rank`", type="integer", nullable=true)
  92.      * @Groups({"filters_filter:read", "filters_filter:write", "filters_category:read"})
  93.      */
  94.     private $rank;
  95.     public function __construct()
  96.     {
  97.         $this->filtersCategory = new ArrayCollection();
  98.         $this->createdAt = new \DateTime();
  99.         $this->active true;
  100.         $this->isBinary false;
  101.         $this->videos = new ArrayCollection();
  102.     }
  103.     public function getId(): ?int
  104.     {
  105.         return $this->id;
  106.     }
  107.     public function getName(): ?string
  108.     {
  109.         return $this->name;
  110.     }
  111.     public function setName(string $name): self
  112.     {
  113.         $this->name $name;
  114.         return $this;
  115.     }
  116.     public function getActive(): ?bool
  117.     {
  118.         return $this->active;
  119.     }
  120.     public function setActive(bool $active): self
  121.     {
  122.         $this->active $active;
  123.         return $this;
  124.     }
  125.     public function getCreatedAt(): ?\DateTimeInterface
  126.     {
  127.         return $this->createdAt;
  128.     }
  129.     public function setCreatedAt(\DateTimeInterface $createdAt): self
  130.     {
  131.         $this->createdAt $createdAt;
  132.         return $this;
  133.     }
  134.     public function getIsBinary(): ?bool
  135.     {
  136.         return $this->isBinary;
  137.     }
  138.     public function setIsBinary(bool $isBinary): self
  139.     {
  140.         $this->isBinary $isBinary;
  141.         return $this;
  142.     }
  143.     /**
  144.      * @return Collection|FiltersCategory[]
  145.      */
  146.     public function getFiltersCategory(): Collection
  147.     {
  148.         return $this->filtersCategory;
  149.     }
  150.     public function addFiltersCategory(FiltersCategory $filtersCategory): self
  151.     {
  152.         if (!$this->filtersCategory->contains($filtersCategory)) {
  153.             $this->filtersCategory[] = $filtersCategory;
  154.         }
  155.         return $this;
  156.     }
  157.     public function removeFiltersCategory(FiltersCategory $filtersCategory): self
  158.     {
  159.         $this->filtersCategory->removeElement($filtersCategory);
  160.         return $this;
  161.     }
  162.     /**
  163.      * @return Collection|Video[]
  164.      */
  165.     public function getVideos(): Collection
  166.     {
  167.         return $this->videos;
  168.     }
  169.     public function addVideo(Video $video): self
  170.     {
  171.         if (!$this->videos->contains($video)) {
  172.             $this->videos[] = $video;
  173.             $video->addFilter($this);
  174.         }
  175.         return $this;
  176.     }
  177.     public function removeVideo(Video $video): self
  178.     {
  179.         if ($this->videos->removeElement($video)) {
  180.             $video->removeFilter($this);
  181.         }
  182.         return $this;
  183.     }
  184.     public function getRank(): ?int
  185.     {
  186.         return $this->rank;
  187.     }
  188.     public function setRank(?int $rank): self
  189.     {
  190.         $this->rank $rank;
  191.         return $this;
  192.     }
  193. }