src/Entity/NewsCategory.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\NewsCategoryRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation\Groups;
  8. use App\Entity\Traits\Timestampable;
  9. #[ORM\HasLifecycleCallbacks]
  10. #[ORM\Entity(repositoryClassNewsCategoryRepository::class)]
  11. class NewsCategory
  12. {
  13.     use Timestampable;
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column]
  17.     #[Groups(['getNews'])]
  18.     private ?int $id null;
  19.     #[ORM\Column(length255)]
  20.     #[Groups(['getNews'])]
  21.     private ?string $name null;
  22.     #[ORM\OneToMany(mappedBy'newsCategory'targetEntityNews::class)]
  23.     private Collection $news;
  24.     #[ORM\ManyToOne(inversedBy'newsCategories'cascade: ["persist"])]
  25.     #[ORM\JoinColumn(nullablefalse)]
  26.     private ?User $author null;
  27.     #[ORM\ManyToOne(inversedBy'newsCategoriesEdited'cascade: ["persist"])]
  28.     private ?User $editor null;
  29.     #[ORM\ManyToOne(inversedBy'newsCategories')]
  30.     #[ORM\JoinColumn(nullablefalse)]
  31.     private ?School $school null;
  32.     public function __construct()
  33.     {
  34.         $this->news = new ArrayCollection();
  35.     }
  36.     public  function __toString(): string
  37.     {
  38.         return  $this->name;
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(string $name): static
  49.     {
  50.         $this->name $name;
  51.         return $this;
  52.     }
  53.     /**
  54.      * @return Collection<int, News>
  55.      */
  56.     public function getNews(): Collection
  57.     {
  58.         return $this->news;
  59.     }
  60.     public function addNews(News $news): static
  61.     {
  62.         if (!$this->news->contains($news)) {
  63.             $this->news->add($news);
  64.             $news->setNewsCategory($this);
  65.         }
  66.         return $this;
  67.     }
  68.     public function removeNews(News $news): static
  69.     {
  70.         if ($this->news->removeElement($news)) {
  71.             // set the owning side to null (unless already changed)
  72.             if ($news->getNewsCategory() === $this) {
  73.                 $news->setNewsCategory(null);
  74.             }
  75.         }
  76.         return $this;
  77.     }
  78.     public function getAuthor(): ?User
  79.     {
  80.         return $this->author;
  81.     }
  82.     public function setAuthor(?User $author): static
  83.     {
  84.         $this->author $author;
  85.         return $this;
  86.     }
  87.     public function getEditor(): ?User
  88.     {
  89.         return $this->editor;
  90.     }
  91.     public function setEditor(?User $editor): static
  92.     {
  93.         $this->editor $editor;
  94.         return $this;
  95.     }
  96.     public function getSchool(): ?School
  97.     {
  98.         return $this->school;
  99.     }
  100.     public function setSchool(?School $school): static
  101.     {
  102.         $this->school $school;
  103.         return $this;
  104.     }
  105. }