<?php
namespace App\Entity;
use ApiPlatform\Metadata\ApiResource;
use App\Repository\NewsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Component\Serializer\Annotation\Groups;
#[ORM\Entity(repositoryClass: NewsRepository::class)]
#[Get]
#[Put(security: "is_granted('ROLE_ADMIN')")]
#[Post(security: "is_granted('ROLE_ADMIN')")]
#[Delete(security: "is_granted('ROLE_ADMIN')")]
#[ApiResource(
normalizationContext: ['groups' => ['news:read']],
denormalizationContext: ['groups' => ['news:write']],
order: ['id' => 'DESC'], paginationClientItemsPerPage: true
)
]
#[ApiFilter(SearchFilter::class, properties: ['categories.id' => 'exact', 'name' => 'ipartial', ])]
class News
{
#[Groups(['news:read', 'news:write'])]
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 255)]
private ?string $name = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
private ?\DateTimeInterface $date = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $news_shot = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $news_full = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 2, nullable: true)]
private ?string $active = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 2, nullable: true)]
private ?string $top = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $audio_link = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $video_link = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $audio_title = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 2, nullable: true)]
private ?string $audio_active = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $video_img = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\ManyToMany(targetEntity: Category::class, mappedBy: 'news')]
private Collection $categories;
public function __construct()
{
$this->categories = 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 getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getNewsShot(): ?string
{
return $this->news_shot;
}
public function setNewsShot(?string $news_shot): self
{
$this->news_shot = $news_shot;
return $this;
}
public function getNewsFull(): ?string
{
return $this->news_full;
}
public function setNewsFull(?string $news_full): self
{
$this->news_full = $news_full;
return $this;
}
public function getActive(): ?string
{
return $this->active;
}
public function setActive(string $active): self
{
$this->active = $active;
return $this;
}
public function getTop(): ?string
{
return $this->top;
}
public function setTop(?string $top): self
{
$this->top = $top;
return $this;
}
public function getAudioLink(): ?string
{
return $this->audio_link;
}
public function setAudioLink(?string $audio_link): self
{
$this->audio_link = $audio_link;
return $this;
}
public function getVideoLink(): ?string
{
return $this->video_link;
}
public function setVideoLink(?string $video_link): self
{
$this->video_link = $video_link;
return $this;
}
public function getAudioTitle(): ?string
{
return $this->audio_title;
}
public function setAudioTitle(?string $audio_title): self
{
$this->audio_title = $audio_title;
return $this;
}
public function getAudioActive(): ?string
{
return $this->audio_active;
}
public function setAudioActive(?string $audio_active): self
{
$this->audio_active = $audio_active;
return $this;
}
public function getVideoImg(): ?string
{
return $this->video_img;
}
public function setVideoImg(?string $video_img): self
{
$this->video_img = $video_img;
return $this;
}
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): static
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->addNews($this);
}
return $this;
}
public function removeCategory(Category $category): static
{
if ($this->categories->removeElement($category)) {
$category->removeNews($this);
}
return $this;
}
}