src/Entity/News.php line 33
<?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\ApiFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Metadata\Delete;
use ApiPlatform\Metadata\Get;
use ApiPlatform\Metadata\GetCollection;
use ApiPlatform\Metadata\Post;
use ApiPlatform\Metadata\Put;
#[ORM\Entity(repositoryClass: NewsRepository::class)]
#[ApiResource(
normalizationContext: ['groups' => ['news:read']],
denormalizationContext: ['groups' => ['news:write']],
order: ['id' => 'DESC'], paginationClientItemsPerPage: true,
// security: "is_granted('ROLE_ADMIN')"
)
]
#[Get()]
#[Put(security: "is_granted('EDIT_NEWS', object)")]
#[Delete(security: "is_granted('EDIT_NEWS', object)")]
#[GetCollection]
#[Post(securityPostDenormalize: "is_granted('EDIT_NEWS', object)")]
#[ApiFilter(SearchFilter::class, properties: [
'categories.id' => 'exact',
'name' => 'ipartial',
'language.id' => 'exact'
])]
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;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
#[Groups(['news:read', 'news:write'])]
private ?\DateTimeInterface $date = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $newsShot = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(type: Types::TEXT, nullable: true)]
private ?string $newsFull = 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;
#[ORM\Column(length: 255, nullable: true)]
private ?string $slider = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $dateStart = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $address = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $shortDescription = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $contentImg = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\ManyToMany(targetEntity: Category::class, mappedBy: 'news')]
private Collection $categories;
#[Groups(['news:read', 'news:write'])]
#[ORM\ManyToOne(inversedBy: 'news')]
private ?MediaObject $media = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\ManyToOne(inversedBy: 'news')]
private ?Languages $language = null;
#[Groups(['news:read', 'news:write'])]
#[ORM\ManyToOne(targetEntity: self::class, inversedBy: 'tralations')]
private ?self $translation = null;
/**
* @var Collection<int, self>
*/
#[Groups(['news:read', 'news:write'])]
#[ORM\OneToMany(mappedBy: 'translation', targetEntity: self::class)]
private Collection $tralations;
#[Groups(['news:read', 'news:write'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $opacityCard = null;
public function __construct()
{
$this->categories = new ArrayCollection();
$this->tralations = 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->newsShot;
}
public function setNewsShot(?string $newsShot): self
{
$this->newsShot = $newsShot;
return $this;
}
public function getNewsFull(): ?string
{
return $this->newsFull;
}
public function setNewsFull(?string $newsFull): self
{
$this->newsFull = $newsFull;
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;
}
public function getSlider(): ?string
{
return $this->slider;
}
public function setSlider(?string $slider): static
{
$this->slider = $slider;
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 getDateStart(): ?string
{
return $this->dateStart;
}
public function setDateStart(?string $dateStart): static
{
$this->dateStart = $dateStart;
return $this;
}
public function getAddress(): ?string
{
return $this->address;
}
public function setAddress(?string $address): static
{
$this->address = $address;
return $this;
}
public function getShortDescription(): ?string
{
return $this->shortDescription;
}
public function setShortDescription(?string $shortDescription): static
{
$this->shortDescription = $shortDescription;
return $this;
}
public function getContentImg(): ?string
{
return $this->contentImg;
}
public function setContentImg(?string $contentImg): static
{
$this->contentImg = $contentImg;
return $this;
}
public function removeCategory(Category $category): static
{
if ($this->categories->removeElement($category)) {
$category->removeNews($this);
}
return $this;
}
public function getMedia(): ?MediaObject
{
return $this->media;
}
public function setMedia(?MediaObject $media): static
{
$this->media = $media;
return $this;
}
public function getLanguage(): ?Languages
{
return $this->language;
}
public function setLanguage(?Languages $language): static
{
$this->language = $language;
return $this;
}
public function getTranslation(): ?self
{
return $this->translation;
}
public function setTranslation(?self $translation): static
{
$this->translation = $translation;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getTralations(): Collection
{
return $this->tralations;
}
public function addTralation(self $tralation): static
{
if (!$this->tralations->contains($tralation)) {
$this->tralations->add($tralation);
$tralation->setTranslation($this);
}
return $this;
}
public function removeTralation(self $tralation): static
{
if ($this->tralations->removeElement($tralation)) {
// set the owning side to null (unless already changed)
if ($tralation->getTranslation() === $this) {
$tralation->setTranslation(null);
}
}
return $this;
}
public function getOpacityCard(): ?string
{
return $this->opacityCard;
}
public function setOpacityCard(?string $opacityCard): static
{
$this->opacityCard = $opacityCard;
return $this;
}
}