src/Entity/NewsCategory.php line 52
<?phpnamespace App\Entity;use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;use ApiPlatform\Metadata\ApiFilter;use ApiPlatform\Metadata\ApiResource;use ApiPlatform\Metadata\Get;use ApiPlatform\Metadata\GetCollection;use ApiPlatform\Serializer\Filter\PropertyFilter;use App\Repository\NewsCategoryRepository;use DateTimeImmutable;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\DBAL\Types\Types;use Doctrine\ORM\Mapping as ORM;use Symfony\Component\Serializer\Annotation\Groups;#[ORM\Entity(repositoryClass: NewsCategoryRepository::class)]#[ApiFilter(PropertyFilter::class)]#[ApiResource(shortName: 'News',description: 'News API',operations: [new Get(uriTemplate: '/news-category/{id}'),//new Patch(uriTemplate: '/media/{id}'),new GetCollection(uriTemplate: '/news->category', paginationEnabled: false),],formats: ['jsonld','json','jsonhal','csv' => 'text/csv',],normalizationContext: ['groups' => ['news-category:read'],],denormalizationContext: ['groups' => ['news-category:write'],],// paginationItemsPerPage: 10,),ApiFilter(OrderFilter::class,properties: ['position',],),]class NewsCategory{#[ORM\Id]#[ORM\GeneratedValue]#[ORM\Column]#[Groups(['news:read', 'news-category:read', 'studio:read'])]private ?int $id = null;#[ORM\Column(length: 255)]#[Groups(['news:read', 'news-category:read', 'studio:read'])]#[ApiFilter(SearchFilter::class, strategy: 'exact')]private ?string $bezeichnung = null;#[ORM\Column(type: Types::TEXT, nullable: true)]#[Groups(['news:read', 'news-category:read', 'studio:read'])]private ?string $beschreibung = null;#[ORM\Column]#[Groups(['news:read', 'news-category:read', 'studio:read'])]private ?int $position = null;#[ORM\OneToMany(mappedBy: 'category', targetEntity: News::class, cascade: ['persist', 'remove'])]#[ApiFilter(SearchFilter::class, strategy: 'exact')]protected Collection $news;#[ORM\Column]private ?DateTimeImmutable $createdAt = null;public function __construct(){$this->createdAt = new DateTimeImmutable();$this->position = 0;$this->news = new ArrayCollection();}public function getId(): ?int{return $this->id;}public function getBezeichnung(): ?string{return $this->bezeichnung;}public function setBezeichnung(string $bezeichnung): self{$this->bezeichnung = $bezeichnung;return $this;}public function getBeschreibung(): ?string{return $this->beschreibung;}public function setBeschreibung(?string $beschreibung): self{$this->beschreibung = $beschreibung;return $this;}public function getPosition(): ?int{return $this->position;}public function setPosition(int $position): self{$this->position = $position;return $this;}public function getCreatedAt(): ?DateTimeImmutable{return $this->createdAt;}public function setCreatedAt(DateTimeImmutable $createdAt): self{$this->createdAt = $createdAt;return $this;}/*** @return Collection<int, News>*/public function getNews(): Collection{return $this->news;}public function addNews(News $news): self{if (!$this->news->contains($news)) {$this->news->add($news);$news->setCategory($this);}return $this;}public function removeNews(News $news): self{if ($this->news->removeElement($news)) {// set the owning side to null (unless already changed)if ($news->getCategory() === $this) {$news->setCategory(null);}}return $this;}}