src/Entity/News.php line 17

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\NewsRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  10. #[Vich\Uploadable]
  11. #[ORM\Entity(repositoryClassNewsRepository::class)]
  12. class News
  13. {
  14.     #[ORM\Id]
  15.     #[ORM\GeneratedValue]
  16.     #[ORM\Column(type'integer')]
  17.     private $id;
  18.     #[ORM\Column(type'boolean')]
  19.     private bool $active false;
  20.     #[ORM\JoinColumn(nullabletrue)]
  21.     #[ORM\ManyToOne(targetEntityUser::class)]
  22.     private ?User $author null;
  23.     #[Assert\NotBlank]
  24.     #[ORM\Column(type'string'length255)]
  25.     private string $title;
  26.     #[Assert\NotBlank]
  27.     #[ORM\Column(type'text')]
  28.     private string $content;
  29.     #[ORM\Column(type'text')]
  30.     private string $chapo;
  31.     
  32.     #[ORM\JoinColumn(nullabletrue)]
  33.     #[ORM\ManyToOne(targetEntityNewsCategory::class)]
  34.     private NewsCategory $category;
  35.     #[ORM\Column(type'datetime')]
  36.     private ?\DateTime $createdAt;
  37.     #[ORM\JoinTable(name'news_keywords')]
  38.     #[ORM\ManyToMany(targetEntity\App\Entity\Keywords::class, inversedBy'mentionsNews'cascade: ['persist'])]
  39.     #[ORM\OrderBy(['keyword' => 'ASC'])]
  40.     private $listekeywords;
  41.     #[ORM\JoinTable(name'news_lexiques')]
  42.     #[ORM\ManyToMany(targetEntity\App\Entity\Lexique::class, inversedBy'mentionsNews'cascade: ['persist'])]
  43.     #[ORM\OrderBy(['word' => 'ASC'])]
  44.     private $listelexique;
  45.     #[ORM\Column(type'string'length255nullabletrue)]
  46.     private ?string $pdf null;
  47.     #[Vich\UploadableField(mapping'news_pdf'fileNameProperty:'pdf')]
  48.     private ?File $pdfFile null;
  49.     #[ORM\Column(type'boolean')]
  50.     private bool $pinned false;
  51.     public function __construct()
  52.     {
  53.         $this->createdAt = new \DateTime();
  54.         $this->updatedAt = new \DateTime();
  55.         $this->listekeywords = new ArrayCollection();
  56.         $this->listelexique = new ArrayCollection();
  57.     }
  58.     public function getId(): ?int
  59.     {
  60.         return $this->id;
  61.     }
  62.     public function getTitle(): ?string
  63.     {
  64.         return $this->title;
  65.     }
  66.     public function setTitle(string $title): self
  67.     {
  68.         $this->title $title;
  69.         return $this;
  70.     }
  71.     public function getContent(): ?string
  72.     {
  73.         return $this->content;
  74.     }
  75.     public function setContent(string $content): self
  76.     {
  77.         $this->content $content;
  78.         return $this;
  79.     }
  80.     public function getCreatedAt(): ?\DateTimeInterface
  81.     {
  82.         return $this->createdAt;
  83.     }
  84.     public function setCreatedAt(?\DateTimeInterface $createdAt): self
  85.     {
  86.         $this->createdAt $createdAt;
  87.         return $this;
  88.     }
  89.     public function getCategory(): ?NewsCategory
  90.     {
  91.         return $this->category;
  92.     }
  93.     public function setCategory(NewsCategory $category): void
  94.     {
  95.         $this->category $category;
  96.     }
  97.     public function isActive(): bool
  98.     {
  99.         return $this->active;
  100.     }
  101.     public function setActive(bool $active): void
  102.     {
  103.         $this->active $active;
  104.     }
  105.     public function getAuthor(): ?User
  106.     {
  107.         return $this->author;
  108.     }
  109.     public function setAuthor(?User $author): void
  110.     {
  111.         $this->author $author;
  112.     }
  113.     public function getListekeywords(): Collection
  114.     {
  115.         return $this->listekeywords;
  116.     }
  117.     public function getListelexique(): Collection
  118.     {
  119.         return $this->listelexique;
  120.     }
  121.     public function addListelexique(Lexique $lexique): self
  122.     {
  123.         if (!$this->listelexique->contains($lexique)) {
  124.             $this->listelexique[] = $lexique;
  125.         }
  126.         return $this;
  127.     }
  128.     public function removeListelexique(Lexique $lexique): self
  129.     {
  130.         $this->listelexique->removeElement($lexique);
  131.         return $this;
  132.     }
  133.     public function setPdfFile($pdf null)
  134.     {
  135.         $this->pdfFile $pdf;
  136.         // VERY IMPORTANT:
  137.         // It is required that at least one field changes if you are using Doctrine,
  138.         // otherwise the event listeners won't be called and the file is lost
  139.         if ($pdf) {
  140.             // if 'updatedAt' is not defined in your entity, use another property
  141.             $this->updatedAt = new \DateTime('now');
  142.         }
  143.     }
  144.     public function getPdfFile()
  145.     {
  146.         return $this->pdfFile;
  147.     }
  148.     public function setPdf($pdf)
  149.     {
  150.         // $pdf = str_replace(' ', '_', $pdf);
  151.         $this->pdf $pdf;
  152.     }
  153.     public function getPdf()
  154.     {
  155.         return $this->pdf;
  156.     }
  157.     public function addListekeyword(Keywords $listekeyword): self
  158.     {
  159.         if (!$this->listekeywords->contains($listekeyword)) {
  160.             $this->listekeywords[] = $listekeyword;
  161.         }
  162.         return $this;
  163.     }
  164.     public function removeListekeyword(Keywords $listekeyword): self
  165.     {
  166.         $this->listekeywords->removeElement($listekeyword);
  167.         return $this;
  168.     }
  169.     public function getChapo(): ?string
  170.     {
  171.         return $this->chapo;
  172.     }
  173.     public function setChapo(string $chapo): self
  174.     {
  175.         $this->chapo $chapo;
  176.         return $this;
  177.     }
  178.     public function getPinned()
  179.     {
  180.         return $this->pinned;
  181.     }
  182.     public function setPinned($pinned)
  183.     {
  184.         $this->pinned $pinned;
  185.         return $this;
  186.     }
  187. }