src/Entity/News.php line 59

  1. <?php
  2. namespace App\Entity;
  3. use ApiPlatform\Doctrine\Orm\Filter\DateFilter;
  4. use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
  5. use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
  6. use ApiPlatform\Metadata\ApiFilter;
  7. use ApiPlatform\Metadata\ApiResource;
  8. use ApiPlatform\Metadata\Get;
  9. use ApiPlatform\Metadata\GetCollection;
  10. use ApiPlatform\Serializer\Filter\PropertyFilter;
  11. use App\Repository\NewsRepository;
  12. use DateTimeImmutable;
  13. use Doctrine\Common\Collections\ArrayCollection;
  14. use Doctrine\Common\Collections\Collection;
  15. use Doctrine\DBAL\Types\Types;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Doctrine\ORM\Mapping\OrderBy;
  18. use Symfony\Component\Serializer\Annotation\Groups;
  19. #[ORM\Entity(repositoryClassNewsRepository::class)]
  20. #[ApiFilter(PropertyFilter::class)]
  21. #[ApiResource(
  22.     shortName'News',
  23.     description'News API',
  24.     operations: [
  25.         new Get(uriTemplate'/news/{id}'),
  26.         //new Patch(uriTemplate: '/media/{id}'),
  27.         new GetCollection(uriTemplate'/news'paginationEnabledfalse),
  28.     ],
  29.     formats: [
  30.         'jsonld',
  31.         'json',
  32.         'jsonhal',
  33.         'csv' => 'text/csv',
  34.     ],
  35.     normalizationContext: [
  36.         'groups' => ['news:read'],
  37.     ],
  38.     denormalizationContext: [
  39.         'groups' => ['news:write'],
  40.     ],
  41.      paginationItemsPerPage9,
  42. ),
  43.     ApiFilter(
  44.         OrderFilter::class,
  45.         properties: [
  46.             'newsDate',
  47.         ],
  48.     ),
  49.     ApiFilter(
  50.         DateFilter::class,
  51.         properties: [
  52.             'newsDate',
  53.         ]
  54.     )
  55. ]
  56. class News
  57. {
  58.     #[ORM\Id]
  59.     #[ORM\GeneratedValue]
  60.     #[ORM\Column]
  61.     #[Groups(['news:read','studio:read','seo:read'])]
  62.     #[ApiFilter(SearchFilter::class, strategy'exact')]
  63.     private ?int $id null;
  64.     #[ORM\Column(length255)]
  65.     #[Groups(['news:read','studio:read','news-category:read','seo:read'])]
  66.     #[ApiFilter(SearchFilter::class, strategy'partial')]
  67.     private ?string $title null;
  68.     #[ORM\Column(length255nullabletrue)]
  69.     #[Groups(['news:read''studio:read','news-category:read'])]
  70.     #[ApiFilter(SearchFilter::class, strategy'partial')]
  71.     private ?string $quelle null;
  72.     #[ORM\Column(length255nullabletrue)]
  73.     #[Groups(['news:read''studio:read','news-category:read'])]
  74.     #[ApiFilter(SearchFilter::class, strategy'exact')]
  75.     private ?string $type null;
  76.     #[ORM\Column(typeTypes::TEXT)]
  77.     #[Groups(['news:read','studio:read','news-category:read'])]
  78.     #[ApiFilter(SearchFilter::class, strategy'partial')]
  79.     private ?string $content null;
  80.     #[ORM\Column]
  81.     #[Groups(['news:read','studio:read','news-category:read','seo:read'])]
  82.     #[ApiFilter(SearchFilter::class, strategy'exact')]
  83.     private ?bool $active null;
  84.     #[ORM\Column(nullabletrue)]
  85.     #[Groups(['news:read','studio:read','news-category:read','seo:read'])]
  86.     #[ApiFilter(SearchFilter::class, strategy'partial')]
  87.     private ?DateTimeImmutable $newsDate null;
  88.     #[ORM\ManyToOne(targetEntityNewsCategory::class, inversedBy'news')]
  89.     #[Groups(['news:read','studio:read'])]
  90.     #[ApiFilter(SearchFilter::class, strategy'exact')]
  91.     private ?NewsCategory $category;
  92.     #[ORM\ManyToOne(inversedBy'news')]
  93.     #[ORM\JoinColumn(nullabletrue)]
  94.     #[ApiFilter(SearchFilter::class, strategy'exact')]
  95.     #[Groups(['news:read'])]
  96.     protected ?Studio $studio;
  97.     #[ORM\OneToMany(mappedBy'news'targetEntityStudioMedia::class, cascade: ["persist"], orphanRemovaltrue)]
  98.     #[Groups(['news:read','studio:read','seo:read'])]
  99.     protected Collection $studioMedia;
  100.     #[ORM\Column]
  101.     #[Groups(['news:read'])]
  102.     private ?DateTimeImmutable $createdAt null;
  103.     #[ORM\Column(nullabletrue)]
  104.     #[Groups(['news:read'])]
  105.     private ?int $coverId null;
  106.     public function __construct()
  107.     {
  108.         $this->createdAt = new DateTimeImmutable();
  109.         $this->newsDate = new DateTimeImmutable();
  110.         $this->active true;
  111.         $this->type 'studio';
  112.         $this->studioMedia = new ArrayCollection();
  113.     }
  114.     public function getId(): ?int
  115.     {
  116.         return $this->id;
  117.     }
  118.     public function getTitle(): ?string
  119.     {
  120.         return $this->title;
  121.     }
  122.     public function setTitle(string $title): self
  123.     {
  124.         $this->title $title;
  125.         return $this;
  126.     }
  127.     public function getQuelle(): ?string
  128.     {
  129.         return $this->quelle;
  130.     }
  131.     public function setQuelle(?string $quelle): self
  132.     {
  133.         $this->quelle $quelle;
  134.         return $this;
  135.     }
  136.     public function getContent(): ?string
  137.     {
  138.         return $this->content;
  139.     }
  140.     public function setContent(string $content): self
  141.     {
  142.         $this->content $content;
  143.         return $this;
  144.     }
  145.     public function getType(): ?string
  146.     {
  147.         return $this->type;
  148.     }
  149.     public function setType(?string $type): self
  150.     {
  151.         $this->type $type;
  152.         return $this;
  153.     }
  154.     public function isActive(): ?bool
  155.     {
  156.         return $this->active;
  157.     }
  158.     public function setActive(bool $active): self
  159.     {
  160.         $this->active $active;
  161.         return $this;
  162.     }
  163.     public function getNewsDate(): ?DateTimeImmutable
  164.     {
  165.         return $this->newsDate;
  166.     }
  167.     public function setNewsDate(?DateTimeImmutable $newsDate): self
  168.     {
  169.         $this->newsDate $newsDate;
  170.         return $this;
  171.     }
  172.     public function getCreatedAt(): ?DateTimeImmutable
  173.     {
  174.         return $this->createdAt;
  175.     }
  176.     public function setCreatedAt(DateTimeImmutable $createdAt): self
  177.     {
  178.         $this->createdAt $createdAt;
  179.         return $this;
  180.     }
  181.     public function getCategory(): ?NewsCategory
  182.     {
  183.         return $this->category;
  184.     }
  185.     public function setCategory(?NewsCategory $category): self
  186.     {
  187.         $this->category $category;
  188.         return $this;
  189.     }
  190.     public function getStudio(): ?Studio
  191.     {
  192.         return $this->studio;
  193.     }
  194.     public function setStudio(?Studio $studio): self
  195.     {
  196.         $this->studio $studio;
  197.         return $this;
  198.     }
  199.     /**
  200.      * @return Collection<int, StudioMedia>
  201.      */
  202.     public function getStudioMedia(): Collection
  203.     {
  204.         return $this->studioMedia;
  205.     }
  206.     public function addStudioMedium(StudioMedia $studioMedium): self
  207.     {
  208.         if (!$this->studioMedia->contains($studioMedium)) {
  209.             $this->studioMedia->add($studioMedium);
  210.             $studioMedium->setNews($this);
  211.         }
  212.         return $this;
  213.     }
  214.     public function removeStudioMedium(StudioMedia $studioMedium): self
  215.     {
  216.         if ($this->studioMedia->removeElement($studioMedium)) {
  217.             // set the owning side to null (unless already changed)
  218.             if ($studioMedium->getNews() === $this) {
  219.                 $studioMedium->setNews(null);
  220.             }
  221.         }
  222.         return $this;
  223.     }
  224.     public function getCoverId(): ?int
  225.     {
  226.         return $this->coverId;
  227.     }
  228.     public function setCoverId(?int $coverId): self
  229.     {
  230.         $this->coverId $coverId;
  231.         return $this;
  232.     }
  233. }