<?php
namespace App\Entity;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass="App\Repository\NewsRepository")
*/
class News
{
/**
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToMany(targetEntity="App\Entity\Typenews", inversedBy="news")
*/
private $type;
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="news")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
/**
* @ORM\Column(type="text")
*/
private $titre;
/**
* @ORM\Column(type="text")
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $source;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $date;
/**
* @ORM\Column(type="time", nullable=true)
*/
private $heure;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $image;
/**
* @ORM\Column(type="datetime")
*/
private $created_at;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $updated_at;
/**
* @ORM\Column(type="boolean")
*/
private $status;
/**
* @ORM\Column(type="boolean")
*/
private $premium;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $titreimage;
/**
* @ORM\OneToMany(targetEntity=Commentaire::class, mappedBy="news")
*/
private $commentaires;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $notify_at;
/**
* @ORM\OneToMany(targetEntity=UserBookmark::class, mappedBy="news", orphanRemoval=true)
*/
private $bookmarks;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $titre_en;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description_en;
public function __construct()
{
$this->type = new ArrayCollection();
$this->status=false;
$this->created_at=new \DateTime();
$this->commentaires = new ArrayCollection();
$this->bookmarks = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection|Typenews[]
*/
public function getType(): Collection
{
return $this->type;
}
public function addType(Typenews $type): self
{
if (!$this->type->contains($type)) {
$this->type[] = $type;
}
return $this;
}
public function removeType(Typenews $type): self
{
if ($this->type->contains($type)) {
$this->type->removeElement($type);
}
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
public function getTitre(): ?string
{
return $this->titre;
}
public function setTitre(string $titre): self
{
$this->titre = $titre;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}
public function getSource(): ?string
{
return $this->source;
}
public function setSource(?string $source): self
{
$this->source = $source;
return $this;
}
public function getDate(): ?\DateTimeInterface
{
return $this->date;
}
public function setDate(?\DateTimeInterface $date): self
{
$this->date = $date;
return $this;
}
public function getHeure(): ?\DateTimeInterface
{
return $this->heure;
}
public function setHeure(?\DateTimeInterface $heure): self
{
$this->heure = $heure;
return $this;
}
public function getImage()
{
return $this->image;
}
public function setImage($image)
{
$this->image = $image;
return $this;
}
public function getCreatedAt(): ?\DateTimeInterface
{
return $this->created_at;
}
public function setCreatedAt(\DateTimeInterface $created_at): self
{
$this->created_at = $created_at;
return $this;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updated_at;
}
public function setUpdatedAt(?\DateTimeInterface $updated_at): self
{
$this->updated_at = $updated_at;
return $this;
}
public function getStatus(): ?bool
{
return $this->status;
}
public function setStatus(bool $status): self
{
$this->status = $status;
return $this;
}
public function getPremium(): ?bool
{
return $this->premium;
}
public function setPremium(bool $premium): self
{
$this->premium = $premium;
return $this;
}
public function getTitreimage(): ?string
{
return $this->titreimage;
}
public function setTitreimage(?string $titreimage): self
{
$this->titreimage = $titreimage;
return $this;
}
/**
* @return Collection|Commentaire[]
*/
public function getCommentaires(): Collection
{
return $this->commentaires;
}
public function addCommentaire(Commentaire $commentaire): self
{
if (!$this->commentaires->contains($commentaire)) {
$this->commentaires[] = $commentaire;
$commentaire->setNews($this);
}
return $this;
}
public function removeCommentaire(Commentaire $commentaire): self
{
if ($this->commentaires->contains($commentaire)) {
$this->commentaires->removeElement($commentaire);
// set the owning side to null (unless already changed)
if ($commentaire->getNews() === $this) {
$commentaire->setNews(null);
}
}
return $this;
}
public function getNotifyAt(): ?\DateTimeInterface
{
return $this->notify_at;
}
public function setNotifyAt(?\DateTimeInterface $notify_at): self
{
$this->notify_at = $notify_at;
return $this;
}
public function getImageCode()
{
$path = 'http://127.0.0.1:8000/uploads/news/'.$this->image;
$b64 = file_get_contents($path);
return 'data:image/jpg;base64,'.base64_encode($b64);
}
/**
* @return Collection|UserBookmark[]
*/
public function getBookmarks(): Collection
{
return $this->bookmarks;
}
public function addBookmark(UserBookmark $bookmark): self
{
if (!$this->bookmarks->contains($bookmark)) {
$this->bookmarks[] = $bookmark;
$bookmark->setNews($this);
}
return $this;
}
public function removeBookmark(UserBookmark $bookmark): self
{
if ($this->bookmarks->removeElement($bookmark)) {
// set the owning side to null (unless already changed)
if ($bookmark->getNews() === $this) {
$bookmark->setNews(null);
}
}
return $this;
}
public function getTitreEn(): ?string
{
return $this->titre_en;
}
public function setTitreEn(?string $titre_en): self
{
$this->titre_en = $titre_en;
return $this;
}
public function getDescriptionEn(): ?string
{
return $this->description_en;
}
public function setDescriptionEn(?string $description_en): self
{
$this->description_en = $description_en;
return $this;
}
}