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. * Get the value of tagsArray
  204. */
  205. public function getTagsArray()
  206. {
  207. return $this->tagsArray;
  208. }
  209. /**
  210. * Set the value of tagsArray
  211. *
  212. * @return self
  213. */
  214. public function setTagsArray($tagsArray)
  215. {
  216. $this->tagsArray = $tagsArray;
  217. return $this;
  218. }
  219. public function convertTagsToArray(){
  220. $tab = new ArrayCollection();
  221. for($i=0; $i<count($this->getTags()); $i++){
  222. $tab->add($this->getTags()[$i]->getTag());
  223. }
  224. $this->setTagsArray($tab);
  225. }
  226. public function findBlogTag(int $tagId){
  227. foreach($this->getTags() as $blogTag){
  228. if($blogTag->getTag()->getId() == $tagId) return $blogTag;
  229. }
  230. return null;
  231. }
  232. /**
  233. * Set the value of tags
  234. *
  235. * @return self
  236. */
  237. public function setTags($tags)
  238. {
  239. $this->tags = $tags;
  240. return $this;
  241. }
  242. public function getConcatTags(){
  243. $concat = '';
  244. for($i=0; $i<count($this->getTags()); $i++){
  245. $concat .= $this->getTags()->get($i)->getTag()->getNom();
  246. if($i+1 < count($this->getTags())){
  247. $concat .= ', ';
  248. }
  249. }
  250. return $concat;
  251. }
  252. public function getSlugCat()
  253. {
  254. return (new Slugify())->slugify($this->categorie->getNom()) ;
  255. }
  256. public function getSlugTitle()
  257. {
  258. return (new Slugify())->slugify($this->getTitre()) ;
  259. }
  260. }