src/Entity/Blog.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\BlogRepository;
  4. use App\Traits\DateTrait;
  5. use DateTime;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JMS\Serializer\Annotation as Serializer;
  8. use JMS\Serializer\Annotation\Expose;
  9. use JMS\Serializer\Annotation\Groups;
  10. use Symfony\Component\HttpFoundation\File\File;
  11. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  12. /**
  13. * @ORM\Entity(repositoryClass=BlogRepository::class)
  14. *
  15. * @Vich\Uploadable
  16. *
  17. * @ORM\HasLifecycleCallbacks()
  18. * @Serializer\ExclusionPolicy("ALL")
  19. */
  20. class Blog
  21. {
  22. /**
  23. * @ORM\Id
  24. * @ORM\GeneratedValue
  25. * @ORM\Column(type="integer")
  26. *
  27. * @Expose
  28. * @Groups({"blog_post_list", "blog"})
  29. *
  30. */
  31. private $id;
  32. /**
  33. * @ORM\Column(type="string", length=255)
  34. *
  35. * @Expose
  36. * @Groups({"blog_post_list", "blog"})
  37. */
  38. private $title;
  39. /**
  40. * @ORM\Column(type="string", length=255)
  41. */
  42. private $slug;
  43. /**
  44. * @ORM\Column(type="text")
  45. */
  46. private $body;
  47. /**
  48. * @ORM\Column(type="boolean", options={"default":false})
  49. *
  50. * @Expose
  51. * @Groups({"blog_post_list", "blog"})
  52. */
  53. private $published = TRUE;
  54. /**
  55. * @ORM\Column(type="string", length=255)
  56. *
  57. * @Expose
  58. * @Groups({"blog_post_list", "blog"})
  59. */
  60. private $article;
  61. /**
  62. * @ORM\Column(type="string", length=255, nullable=true)
  63. */
  64. private ?string $image;
  65. // Vich Uploader
  66. /**
  67. * @Vich\UploadableField(mapping="blog_post_image", fileNameProperty="image")
  68. */
  69. private ?File $imageFile = NULL;
  70. /**
  71. * @ORM\Column(type="string", length=255)
  72. */
  73. private $imgSize;
  74. use DateTrait;
  75. /*
  76. * ============================================================================================
  77. * =============================== FONCTIONS CUSTOM ===========================================
  78. * ============================================================================================
  79. */
  80. /**
  81. * @ORM\PrePersist()
  82. * @ORM\PreUpdate()
  83. */
  84. public function prePersist()
  85. {
  86. // $slugifier = new Slugify();
  87. // $this->slug = $slugifier->slugify($this->title);
  88. $this->slug = md5(uniqid());
  89. }
  90. public function getId(): ?int
  91. {
  92. return $this->id;
  93. }
  94. /*
  95. * ============================================================================================
  96. * ============================== FIN FONCTIONS CUSTOM ========================================
  97. * ============================================================================================
  98. */
  99. public function getTitle(): ?string
  100. {
  101. return $this->title;
  102. }
  103. public function setTitle(string $title): self
  104. {
  105. $this->title = $title;
  106. return $this;
  107. }
  108. public function getSlug(): ?string
  109. {
  110. return $this->slug;
  111. }
  112. public function setSlug(string $slug): self
  113. {
  114. $this->slug = $slug;
  115. return $this;
  116. }
  117. public function setArticle(string $article): self
  118. {
  119. $this->article = $article;
  120. return $this;
  121. }
  122. public function getArticle(): ?string
  123. {
  124. return $this->article;
  125. }
  126. public function getBody(): ?string
  127. {
  128. return $this->body;
  129. }
  130. public function setBody(string $body): self
  131. {
  132. $this->body = $body;
  133. return $this;
  134. }
  135. public function getPublished(): ?bool
  136. {
  137. return $this->published;
  138. }
  139. public function setPublished(bool $published): self
  140. {
  141. $this->published = $published;
  142. return $this;
  143. }
  144. public function getImage(): ?string
  145. {
  146. return $this->image ?? NULL;
  147. }
  148. public function setImage(?string $image): self
  149. {
  150. $this->image = $image;
  151. return $this;
  152. }
  153. public function getImageFile(): ?File
  154. {
  155. return $this->imageFile;
  156. }
  157. /**
  158. * @param File $imageFile
  159. *
  160. * @return void
  161. */
  162. public function setImageFile(File $imageFile): void
  163. {
  164. $this->imageFile = $imageFile;
  165. if (NULL !== $imageFile) {
  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. $this->updatedAt = new DateTime();
  169. }
  170. }
  171. public function setImgSize(string $imgSize): self
  172. {
  173. $this->imgSize = $imgSize;
  174. return $this;
  175. }
  176. public function getImgSize(): ?string
  177. {
  178. return $this->imgSize;
  179. }
  180. }