src/Entity/Blog.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogRepository;
  4. use Cocur\Slugify\Slugify;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=BlogRepository::class)
  10.  */
  11. class Blog
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=500)
  21.      */
  22.     private $titre;
  23.     /**
  24.      * @ORM\Column(type="string", length=255, nullable=true)
  25.      */
  26.     private $image;
  27.     /**
  28.      * @ORM\Column(type="text", nullable=true)
  29.      */
  30.     private $description;
  31.     /**
  32.      * @ORM\Column(type="datetime")
  33.      */
  34.     private $datePublication;
  35.     /**
  36.      * @ORM\Column(type="string", length=255)
  37.      */
  38.     private $nomAuteur;
  39.     /**
  40.      * @ORM\ManyToOne(targetEntity=User::class)
  41.      * @ORM\JoinColumn(nullable=false)
  42.      */
  43.     private $auteur;
  44.     /**
  45.      * @ORM\Column(type="text")
  46.      */
  47.     private $contenu;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity=CategorieBlog::class)
  50.      * @ORM\JoinColumn(nullable=false)
  51.      */
  52.     private $categorie;
  53.     /**
  54.      * @ORM\OneToMany(targetEntity=BlogTagBlog::class, mappedBy="blog")
  55.      */
  56.     private $tags;
  57.     /**
  58.      * @ORM\Column(type="integer")
  59.      */
  60.     private $statut;
  61.     /**
  62.      * @ORM\Column(type="string", length=500, nullable=true)
  63.      */
  64.     private $metatitle;
  65.     /**
  66.      * @ORM\Column(type="text", nullable=true)
  67.      */
  68.     private $metadescription;
  69.     private $tagsArray;
  70.     public function __construct()
  71.     {
  72.         $this->tags = new ArrayCollection();
  73.     }
  74.     public function getId(): ?int
  75.     {
  76.         return $this->id;
  77.     }
  78.     public function getTitre(): ?string
  79.     {
  80.         return $this->titre;
  81.     }
  82.     public function setTitre(string $titre): self
  83.     {
  84.         $this->titre $titre;
  85.         return $this;
  86.     }
  87.     public function getImage(): ?string
  88.     {
  89.         return $this->image;
  90.     }
  91.     public function setImage(?string $image): self
  92.     {
  93.         $this->image $image;
  94.         return $this;
  95.     }
  96.     public function getDescription(): ?string
  97.     {
  98.         return $this->description;
  99.     }
  100.     public function setDescription(?string $description): self
  101.     {
  102.         $this->description $description;
  103.         return $this;
  104.     }
  105.     public function getMetadescription(): ?string
  106.     {
  107.         return $this->metadescription;
  108.     }
  109.     public function setMetadescription(?string $metadescription): self
  110.     {
  111.         $this->metadescription $metadescription;
  112.         return $this;
  113.     }
  114.     public function getMetatitle(): ?string
  115.     {
  116.         return $this->metatitle;
  117.     }
  118.     public function setMetatitle(?string $metatitle): self
  119.     {
  120.         $this->metatitle $metatitle;
  121.         return $this;
  122.     }
  123.     public function getDatePublication(): ?\DateTimeInterface
  124.     {
  125.         return $this->datePublication;
  126.     }
  127.     public function setDatePublication(\DateTimeInterface $datePublication): self
  128.     {
  129.         $this->datePublication $datePublication;
  130.         return $this;
  131.     }
  132.     public function getNomAuteur(): ?string
  133.     {
  134.         return $this->nomAuteur;
  135.     }
  136.     public function setNomAuteur(string $nomAuteur): self
  137.     {
  138.         $this->nomAuteur $nomAuteur;
  139.         return $this;
  140.     }
  141.     public function getAuteur(): ?User
  142.     {
  143.         return $this->auteur;
  144.     }
  145.     public function setAuteur(?User $auteur): self
  146.     {
  147.         $this->auteur $auteur;
  148.         return $this;
  149.     }
  150.     public function getContenu(): ?string
  151.     {
  152.         return $this->contenu;
  153.     }
  154.     public function setContenu(string $contenu): self
  155.     {
  156.         $this->contenu $contenu;
  157.         return $this;
  158.     }
  159.     public function getCategorie(): ?CategorieBlog
  160.     {
  161.         return $this->categorie;
  162.     }
  163.     public function setCategorie(?CategorieBlog $categorie): self
  164.     {
  165.         $this->categorie $categorie;
  166.         return $this;
  167.     }
  168.     /**
  169.      * @return Collection<int, BlogTagBlog>
  170.      */
  171.     public function getTags(): Collection
  172.     {
  173.         return $this->tags;
  174.     }
  175.     public function addTag(BlogTagBlog $tag): self
  176.     {
  177.         if (!$this->tags->contains($tag)) {
  178.             $this->tags[] = $tag;
  179.             $tag->setBlog($this);
  180.         }
  181.         return $this;
  182.     }
  183.     public function removeTag(BlogTagBlog $tag): self
  184.     {
  185.         if ($this->tags->removeElement($tag)) {
  186.             // set the owning side to null (unless already changed)
  187.             if ($tag->getBlog() === $this) {
  188.                 $tag->setBlog(null);
  189.             }
  190.         }
  191.         return $this;
  192.     }
  193.     public function getStatut(): ?int
  194.     {
  195.         return $this->statut;
  196.     }
  197.     public function setStatut(int $statut): self
  198.     {
  199.         $this->statut $statut;
  200.         return $this;
  201.     }
  202.     
  203.     /**
  204.      * Get the value of tagsArray
  205.      */ 
  206.     public function getTagsArray()
  207.     {
  208.         return $this->tagsArray;
  209.     }
  210.     /**
  211.      * Set the value of tagsArray
  212.      *
  213.      * @return  self
  214.      */ 
  215.     public function setTagsArray($tagsArray)
  216.     {
  217.         $this->tagsArray $tagsArray;
  218.         return $this;
  219.     }
  220.     public function convertTagsToArray(){
  221.         $tab = new ArrayCollection();
  222.         for($i=0$i<count($this->getTags()); $i++){
  223.             $tab->add($this->getTags()[$i]->getTag());
  224.         }
  225.         $this->setTagsArray($tab);
  226.     }
  227.     public function findBlogTag(int $tagId){
  228.         foreach($this->getTags() as $blogTag){
  229.             if($blogTag->getTag()->getId() == $tagId) return $blogTag;
  230.         }
  231.         return null;
  232.     }
  233.     /**
  234.      * Set the value of tags
  235.      *
  236.      * @return  self
  237.      */ 
  238.     public function setTags($tags)
  239.     {
  240.         $this->tags $tags;
  241.         return $this;
  242.     }
  243.     public function getConcatTags(){
  244.         $concat '';
  245.         for($i=0$i<count($this->getTags()); $i++){
  246.             $concat .= $this->getTags()->get($i)->getTag()->getNom();
  247.             if($i+count($this->getTags())){
  248.                 $concat .= ', ';
  249.             }
  250.         }
  251.         return $concat;
  252.     }
  253.     public function getSlugCat()
  254.     {
  255.         return (new Slugify())->slugify($this->categorie->getNom()) ;
  256.     }
  257.     public function getSlugTitle()
  258.     {
  259.         return (new Slugify())->slugify($this->getTitre()) ;
  260.     }
  261. }