<?php
namespace App\Entity;
use App\Entity\Traits\Timestampable;
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 JMS\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
#[ORM\Table(name: "news")]
#[ORM\Index(columns: ["title","content"], name: "news_index",flags: ['fulltext'])]
#[ORM\HasLifecycleCallbacks]
#[ORM\Entity(repositoryClass: NewsRepository::class)]
class News
{
use Timestampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['getNews','getNewsSearch'])]
private ?int $id = null;
#[ORM\Column(length: 255)]
#[Groups(['getNews','getNewsSearch'])]
private ?string $title = null;
#[ORM\Column(type: Types::TEXT)]
#[Groups(['getNews','getNewsSearch'])]
private ?string $content = null;
#[ORM\ManyToOne(inversedBy: 'news', cascade: ["persist"])]
#[Groups(['getNews','getNewsSearch'])]
private ?NewsCategory $newsCategory = null;
#[Groups(['getNews'])]
#[ORM\OneToMany(mappedBy: 'news', targetEntity: NewsGalerie::class,cascade: ["persist"])]
private Collection $newsGaleries;
#[Groups(['getNews','getNewsSearch'])]
#[ORM\Column(length: 255, nullable: true)]
private ?string $cover = null;
#[ORM\ManyToOne(inversedBy: 'news', cascade: ["persist"])]
private ?User $author = null;
#[ORM\Column(nullable: true)]
#[Groups(['getNews'])]
private ?bool $dropdownOpen = null;
#[ORM\ManyToOne(inversedBy: 'newsEdited', cascade: ["persist"])]
private ?User $editor = null;
#[ORM\ManyToOne(inversedBy: 'news', cascade: ["persist"])]
private ?School $school = null;
#[ORM\OneToMany(mappedBy: 'news', targetEntity: NewsBookmark::class)]
private Collection $newsBookmarks;
#[ORM\ManyToOne(inversedBy: 'news')]
private ?SchoolYear $year = null;
public function __construct()
{
$this->newsGaleries = new ArrayCollection();
$this->newsBookmarks = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(string $title): static
{
$this->title = $title;
return $this;
}
public function getContent(): ?string
{
return $this->content;
}
public function setContent(string $content): static
{
$this->content = $content;
return $this;
}
public function getNewsCategory(): ?NewsCategory
{
return $this->newsCategory;
}
public function setNewsCategory(?NewsCategory $newsCategory): static
{
$this->newsCategory = $newsCategory;
return $this;
}
/**
* @return Collection<int, NewsGalerie>
*/
public function getNewsGaleries(): Collection
{
return $this->newsGaleries;
}
public function addNewsGalery(NewsGalerie $newsGalery): static
{
if (!$this->newsGaleries->contains($newsGalery)) {
$this->newsGaleries->add($newsGalery);
$newsGalery->setNews($this);
}
return $this;
}
public function removeNewsGalery(NewsGalerie $newsGalery): static
{
if ($this->newsGaleries->removeElement($newsGalery)) {
// set the owning side to null (unless already changed)
if ($newsGalery->getNews() === $this) {
$newsGalery->setNews(null);
}
}
return $this;
}
public function getCover(): ?string
{
return $this->cover;
}
public function setCover(?string $cover): static
{
$this->cover = $cover;
return $this;
}
public function getAuthor(): ?User
{
return $this->author;
}
public function setAuthor(?User $author): static
{
$this->author = $author;
return $this;
}
public function isDropdownOpen(): ?bool
{
return $this->dropdownOpen;
}
public function setDropdownOpen(?bool $dropdownOpen): static
{
$this->dropdownOpen = $dropdownOpen;
return $this;
}
public function getEditor(): ?User
{
return $this->editor;
}
public function setEditor(?User $editor): static
{
$this->editor = $editor;
return $this;
}
public function getSchool(): ?School
{
return $this->school;
}
public function setSchool(?School $school): static
{
$this->school = $school;
return $this;
}
/**
* @return Collection<int, NewsBookmark>
*/
public function getNewsBookmarks(): Collection
{
return $this->newsBookmarks;
}
public function addNewsBookmark(NewsBookmark $newsBookmark): static
{
if (!$this->newsBookmarks->contains($newsBookmark)) {
$this->newsBookmarks->add($newsBookmark);
$newsBookmark->setNews($this);
}
return $this;
}
public function removeNewsBookmark(NewsBookmark $newsBookmark): static
{
if ($this->newsBookmarks->removeElement($newsBookmark)) {
// set the owning side to null (unless already changed)
if ($newsBookmark->getNews() === $this) {
$newsBookmark->setNews(null);
}
}
return $this;
}
public function getYear(): ?SchoolYear
{
return $this->year;
}
public function setYear(?SchoolYear $year): static
{
$this->year = $year;
return $this;
}
}