src/Entity/News.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Metadata\ApiResource;
  4. use App\Repository\NewsRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use ApiPlatform\Metadata\Get;
  10. use ApiPlatform\Metadata\Post;
  11. use ApiPlatform\Metadata\Put;
  12. use ApiPlatform\Metadata\Delete;
  13. use ApiPlatform\Metadata\ApiFilter;
  14. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  15. use Symfony\Component\Serializer\Annotation\Groups;
  16. #[ORM\Entity(repositoryClassNewsRepository::class)]
  17. #[Get]
  18. #[Put(security"is_granted('ROLE_ADMIN')")]
  19. #[Post(security"is_granted('ROLE_ADMIN')")]
  20. #[Delete(security"is_granted('ROLE_ADMIN')")]
  21. #[ApiResource(
  22.     normalizationContext: ['groups' => ['news:read']],
  23.     denormalizationContext: ['groups' => ['news:write']],
  24.     order: ['id' => 'DESC'], paginationClientItemsPerPagetrue
  25.     )
  26. ]
  27. #[ApiFilter(SearchFilter::class, properties: ['categories.id' => 'exact''name' => 'ipartial', ])]
  28. class News
  29. {
  30.     #[Groups(['news:read''news:write'])]
  31.     #[ORM\Id]
  32.     #[ORM\GeneratedValue]
  33.     #[ORM\Column]
  34.     private ?int $id null;
  35.     #[Groups(['news:read''news:write'])]
  36.     #[ORM\Column(length255)]
  37.     private ?string $name null;
  38.     #[Groups(['news:read''news:write'])]
  39.     #[ORM\Column(typeTypes::DATETIME_MUTABLE)]
  40.     private ?\DateTimeInterface $date null;
  41.     #[Groups(['news:read''news:write'])]
  42.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  43.     private ?string $news_shot null;
  44.     #[Groups(['news:read''news:write'])]
  45.     #[ORM\Column(typeTypes::TEXTnullabletrue)]
  46.     private ?string $news_full null;
  47.     #[Groups(['news:read''news:write'])]
  48.     #[ORM\Column(length2nullabletrue)]
  49.     private ?string $active null;
  50.     #[Groups(['news:read''news:write'])]
  51.     #[ORM\Column(length2nullabletrue)]
  52.     private ?string $top null;
  53.     #[Groups(['news:read''news:write'])]
  54.     #[ORM\Column(length255nullabletrue)]
  55.     private ?string $audio_link null;
  56.     #[Groups(['news:read''news:write'])]
  57.     #[ORM\Column(length255nullabletrue)]
  58.     private ?string $video_link null;
  59.     #[Groups(['news:read''news:write'])]
  60.     #[ORM\Column(length255nullabletrue)]
  61.     private ?string $audio_title null;
  62.     #[Groups(['news:read''news:write'])]
  63.     #[ORM\Column(length2nullabletrue)]
  64.     private ?string $audio_active null;
  65.     #[Groups(['news:read''news:write'])]
  66.     #[ORM\Column(length255nullabletrue)]
  67.     private ?string $video_img null;
  68.     #[Groups(['news:read''news:write'])]
  69.     #[ORM\ManyToMany(targetEntityCategory::class, mappedBy'news')]
  70.     private Collection $categories;
  71.     public function __construct() 
  72.     {
  73.         $this->categories = new ArrayCollection();
  74.     }
  75.     public function getId(): ?int
  76.     {
  77.         return $this->id;
  78.     }
  79.     public function getName(): ?string
  80.     {
  81.         return $this->name;
  82.     }
  83.     public function setName(string $name): self
  84.     {
  85.         $this->name $name;
  86.         return $this;
  87.     }
  88.     public function getDate(): ?\DateTimeInterface
  89.     {
  90.         return $this->date;
  91.     }
  92.     public function setDate(\DateTimeInterface $date): self
  93.     {
  94.         $this->date $date;
  95.         return $this;
  96.     }
  97.     public function getNewsShot(): ?string
  98.     {
  99.         return $this->news_shot;
  100.     }
  101.     public function setNewsShot(?string $news_shot): self
  102.     {
  103.         $this->news_shot $news_shot;
  104.         return $this;
  105.     }
  106.     public function getNewsFull(): ?string
  107.     {
  108.         return $this->news_full;
  109.     }
  110.     public function setNewsFull(?string $news_full): self
  111.     {
  112.         $this->news_full $news_full;
  113.         return $this;
  114.     }
  115.     public function getActive(): ?string
  116.     {
  117.         return $this->active;
  118.     }
  119.     public function setActive(string $active): self
  120.     {
  121.         $this->active $active;
  122.         return $this;
  123.     }
  124.     public function getTop(): ?string
  125.     {
  126.         return $this->top;
  127.     }
  128.     public function setTop(?string $top): self
  129.     {
  130.         $this->top $top;
  131.         return $this;
  132.     }
  133.     public function getAudioLink(): ?string
  134.     {
  135.         return $this->audio_link;
  136.     }
  137.     public function setAudioLink(?string $audio_link): self
  138.     {
  139.         $this->audio_link $audio_link;
  140.         return $this;
  141.     }
  142.     public function getVideoLink(): ?string
  143.     {
  144.         return $this->video_link;
  145.     }
  146.     public function setVideoLink(?string $video_link): self
  147.     {
  148.         $this->video_link $video_link;
  149.         return $this;
  150.     }
  151.     public function getAudioTitle(): ?string
  152.     {
  153.         return $this->audio_title;
  154.     }
  155.     public function setAudioTitle(?string $audio_title): self
  156.     {
  157.         $this->audio_title $audio_title;
  158.         return $this;
  159.     }
  160.     public function getAudioActive(): ?string
  161.     {
  162.         return $this->audio_active;
  163.     }
  164.     public function setAudioActive(?string $audio_active): self
  165.     {
  166.         $this->audio_active $audio_active;
  167.         return $this;
  168.     }
  169.     public function getVideoImg(): ?string
  170.     {
  171.         return $this->video_img;
  172.     }
  173.     public function setVideoImg(?string $video_img): self
  174.     {
  175.         $this->video_img $video_img;
  176.         return $this;
  177.     }
  178.     /**
  179.      * @return Collection<int, Category>
  180.      */
  181.     public function getCategories(): Collection
  182.     {
  183.         return $this->categories;
  184.     }
  185.     public function addCategory(Category $category): static
  186.     {
  187.         if (!$this->categories->contains($category)) {
  188.             $this->categories->add($category);
  189.             $category->addNews($this);
  190.         }
  191.         return $this;
  192.     }
  193.     public function removeCategory(Category $category): static
  194.     {
  195.         if ($this->categories->removeElement($category)) {
  196.             $category->removeNews($this);
  197.         }
  198.         return $this;
  199.     }
  200. }