src\Entity\News.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Symfony\Component\HttpFoundation\File\File;
  4. use Symfony\Component\Validator\Constraints as Assert;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClass\App\Repository\NewsRepository::class)]
  9. class News
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column(type'integer')]
  14.     private $id;
  15.     #[ORM\ManyToMany(targetEntity\App\Entity\Typenews::class, inversedBy'news')]
  16.     private $type;
  17.     #[ORM\JoinColumn(nullablefalse)]
  18.     #[ORM\ManyToOne(targetEntity\App\Entity\User::class, inversedBy'news')]
  19.     private $user;
  20.     #[ORM\Column(type'text')]
  21.     private $titre;
  22.     #[ORM\Column(type'text')]
  23.     private $description;
  24.     #[ORM\Column(type'string'length255nullabletrue)]
  25.     private $source;
  26.     #[ORM\Column(type'date'nullabletrue)]
  27.     private $date;
  28.     #[ORM\Column(type'time'nullabletrue)]
  29.     private $heure;
  30.     #[ORM\Column(type'string'length255nullabletrue)]
  31.     private $image;
  32.     #[ORM\Column(type'datetime')]
  33.     private $created_at;
  34.     #[ORM\Column(type'datetime'nullabletrue)]
  35.     private $updated_at;
  36.     #[ORM\Column(type'boolean')]
  37.     private $status;
  38.     #[ORM\Column(type'boolean')]
  39.     private $premium;
  40.     #[ORM\Column(type'string'length255nullabletrue)]
  41.     private $titreimage;
  42.     #[ORM\OneToMany(targetEntityCommentaire::class, mappedBy'news')]
  43.     private $commentaires;
  44.     #[ORM\Column(type'datetime'nullabletrue)]
  45.     private $notify_at;
  46.     #[ORM\OneToMany(targetEntityUserBookmark::class, mappedBy'news'orphanRemovaltrue)]
  47.     private $bookmarks;
  48.     #[ORM\Column(type'text'nullabletrue)]
  49.     private $titre_en;
  50.     #[ORM\Column(type'text'nullabletrue)]
  51.     private $description_en;
  52.     #[ORM\Column(nullabletrue)]
  53.     private ?bool $atTop null;
  54.     public function __construct()
  55.     {
  56.         $this->type = new ArrayCollection();
  57.         $this->status=false;
  58.         $this->created_at=new \DateTime();
  59.         $this->commentaires = new ArrayCollection();
  60.         $this->bookmarks = new ArrayCollection();
  61.     }
  62.     public function getId(): ?int
  63.     {
  64.         return $this->id;
  65.     }
  66.     /**
  67.      * @return Collection|Typenews[]
  68.      */
  69.     public function getType(): Collection
  70.     {
  71.         return $this->type;
  72.     }
  73.     public function addType(Typenews $type): self
  74.     {
  75.         if (!$this->type->contains($type)) {
  76.             $this->type[] = $type;
  77.         }
  78.         return $this;
  79.     }
  80.     public function removeType(Typenews $type): self
  81.     {
  82.         if ($this->type->contains($type)) {
  83.             $this->type->removeElement($type);
  84.         }
  85.         return $this;
  86.     }
  87.     public function getUser(): ?User
  88.     {
  89.         return $this->user;
  90.     }
  91.     public function setUser(?User $user): self
  92.     {
  93.         $this->user $user;
  94.         return $this;
  95.     }
  96.     public function getTitre(): ?string
  97.     {
  98.         return $this->titre;
  99.     }
  100.     public function setTitre(string $titre): self
  101.     {
  102.         $this->titre $titre;
  103.         return $this;
  104.     }
  105.     public function getDescription(): ?string
  106.     {
  107.         return $this->description;
  108.     }
  109.     public function setDescription(string $description): self
  110.     {
  111.         $this->description $description;
  112.         return $this;
  113.     }
  114.     public function getSource(): ?string
  115.     {
  116.         return $this->source;
  117.     }
  118.     public function setSource(?string $source): self
  119.     {
  120.         $this->source $source;
  121.         return $this;
  122.     }
  123.     public function getDate(): ?\DateTimeInterface
  124.     {
  125.         return $this->date;
  126.     }
  127.     public function setDate(?\DateTimeInterface $date): self
  128.     {
  129.         $this->date $date;
  130.         return $this;
  131.     }
  132.     public function getHeure(): ?\DateTimeInterface
  133.     {
  134.         return $this->heure;
  135.     }
  136.     public function setHeure(?\DateTimeInterface $heure): self
  137.     {
  138.         $this->heure $heure;
  139.         return $this;
  140.     }
  141.     public function getImage()
  142.     {
  143.         return $this->image;
  144.     }
  145.     public function setImage($image)
  146.     {
  147.         $this->image $image;
  148.         return $this;
  149.     }
  150.     public function getCreatedAt(): ?\DateTimeInterface
  151.     {
  152.         return $this->created_at;
  153.     }
  154.     public function setCreatedAt(\DateTimeInterface $created_at): self
  155.     {
  156.         $this->created_at $created_at;
  157.         return $this;
  158.     }
  159.     public function getUpdatedAt(): ?\DateTimeInterface
  160.     {
  161.         return $this->updated_at;
  162.     }
  163.     public function setUpdatedAt(?\DateTimeInterface $updated_at): self
  164.     {
  165.         $this->updated_at $updated_at;
  166.         return $this;
  167.     }
  168.     public function getStatus(): ?bool
  169.     {
  170.         return $this->status;
  171.     }
  172.     public function setStatus(bool $status): self
  173.     {
  174.         $this->status $status;
  175.         return $this;
  176.     }
  177.     public function getPremium(): ?bool
  178.     {
  179.         return $this->premium;
  180.     }
  181.     public function setPremium(bool $premium): self
  182.     {
  183.         $this->premium $premium;
  184.         return $this;
  185.     }
  186.     public function getTitreimage(): ?string
  187.     {
  188.         return $this->titreimage;
  189.     }
  190.     public function setTitreimage(?string $titreimage): self
  191.     {
  192.         $this->titreimage $titreimage;
  193.         return $this;
  194.     }
  195.     /**
  196.      * @return Collection|Commentaire[]
  197.      */
  198.     public function getCommentaires(): Collection
  199.     {
  200.         return $this->commentaires;
  201.     }
  202.     public function addCommentaire(Commentaire $commentaire): self
  203.     {
  204.         if (!$this->commentaires->contains($commentaire)) {
  205.             $this->commentaires[] = $commentaire;
  206.             $commentaire->setNews($this);
  207.         }
  208.         return $this;
  209.     }
  210.     public function removeCommentaire(Commentaire $commentaire): self
  211.     {
  212.         if ($this->commentaires->contains($commentaire)) {
  213.             $this->commentaires->removeElement($commentaire);
  214.             // set the owning side to null (unless already changed)
  215.             if ($commentaire->getNews() === $this) {
  216.                 $commentaire->setNews(null);
  217.             }
  218.         }
  219.         return $this;
  220.     }
  221.     public function getNotifyAt(): ?\DateTimeInterface
  222.     {
  223.         return $this->notify_at;
  224.     }
  225.     public function setNotifyAt(?\DateTimeInterface $notify_at): self
  226.     {
  227.         $this->notify_at $notify_at;
  228.         return $this;
  229.     }
  230.     public function getImageCode()
  231.     {
  232.         $path 'http://127.0.0.1:8000/uploads/news/'.$this->image;
  233.         $b64 file_get_contents($path);
  234.         return 'data:image/jpg;base64,'.base64_encode($b64);
  235.     }
  236.     /**
  237.      * @return Collection|UserBookmark[]
  238.      */
  239.     public function getBookmarks(): Collection
  240.     {
  241.         return $this->bookmarks;
  242.     }
  243.     public function addBookmark(UserBookmark $bookmark): self
  244.     {
  245.         if (!$this->bookmarks->contains($bookmark)) {
  246.             $this->bookmarks[] = $bookmark;
  247.             $bookmark->setNews($this);
  248.         }
  249.         return $this;
  250.     }
  251.     public function removeBookmark(UserBookmark $bookmark): self
  252.     {
  253.         if ($this->bookmarks->removeElement($bookmark)) {
  254.             // set the owning side to null (unless already changed)
  255.             if ($bookmark->getNews() === $this) {
  256.                 $bookmark->setNews(null);
  257.             }
  258.         }
  259.         return $this;
  260.     }
  261.     public function getTitreEn(): ?string
  262.     {
  263.         return $this->titre_en;
  264.     }
  265.     public function setTitreEn(?string $titre_en): self
  266.     {
  267.         $this->titre_en $titre_en;
  268.         return $this;
  269.     }
  270.     public function getDescriptionEn(): ?string
  271.     {
  272.         return $this->description_en;
  273.     }
  274.     public function setDescriptionEn(?string $description_en): self
  275.     {
  276.         $this->description_en $description_en;
  277.         return $this;
  278.     }
  279.     public function isAtTop(): ?bool
  280.     {
  281.         return $this->atTop ?? false;
  282.     }
  283.     public function setAtTop(?bool $atTop): static
  284.     {
  285.         $this->atTop $atTop ?? false;
  286.         return $this;
  287.     }
  288. }