src/Entity/News.php line 17

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