src/Entity/Subject.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\SubjectRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Gedmo\Mapping\Annotation as Gedmo;
  8. use JMS\Serializer\Annotation as Serializer;
  9. /**
  10. * @ORM\Entity(repositoryClass=SubjectRepository::class)
  11. * @Serializer\ExclusionPolicy("ALL")
  12. */
  13. class Subject extends BaseEntity
  14. {
  15. /**
  16. * @ORM\Id
  17. * @ORM\GeneratedValue
  18. * @ORM\Column(type="integer")
  19. * @Serializer\Expose
  20. * @Serializer\Groups({"ligth_list"})
  21. */
  22. private $id;
  23. /**
  24. * @ORM\Column(type="string", length=255, nullable=true)
  25. * @Serializer\Expose
  26. * @Serializer\Groups({"ligth_list"})
  27. */
  28. private $title;
  29. /**
  30. * @ORM\Column(type="text", nullable=true)
  31. * @Serializer\Expose
  32. * @Serializer\Groups({"ligth_list"})
  33. */
  34. private $content;
  35. /**
  36. * @ORM\ManyToOne(targetEntity=Module::class, inversedBy="subjects")
  37. */
  38. private $module;
  39. /**
  40. * @Gedmo\Slug(fields={"title"})
  41. * @ORM\Column(length=191)
  42. */
  43. private $slug;
  44. /**
  45. * @ORM\OneToMany(targetEntity=Comment::class, mappedBy="subject", orphanRemoval=true, fetch="EXTRA_LAZY")
  46. */
  47. private $comments;
  48. /**
  49. * @ORM\OneToMany(targetEntity=SavedSubject::class, mappedBy="subject", orphanRemoval=true, fetch="EXTRA_LAZY")
  50. */
  51. private $savedSubjects;
  52. /**
  53. * @ORM\OneToMany(targetEntity=SubjectLike::class, mappedBy="subject", orphanRemoval=true, fetch="EXTRA_LAZY")
  54. * @Serializer\Expose
  55. * @Serializer\Groups({"ligth_list"})
  56. */
  57. private $subjectLikes;
  58. /**
  59. * @ORM\Column(type="string", length=255, nullable=true)
  60. */
  61. private $tags;
  62. /**
  63. * @ORM\ManyToMany(targetEntity=SubjectTag::class, mappedBy="subjects", cascade={"persist"})
  64. * @Serializer\Expose
  65. * @Serializer\Groups({"ligth_list"})
  66. */
  67. private $subjectTags;
  68. /**
  69. * @ORM\OneToMany(targetEntity=Notification::class, mappedBy="subject", orphanRemoval=true, fetch="EXTRA_LAZY")
  70. */
  71. private $notifications;
  72. public function __construct()
  73. {
  74. $this->comments = new ArrayCollection();
  75. $this->savedSubjects = new ArrayCollection();
  76. $this->subjectLikes = new ArrayCollection();
  77. $this->subjectTags = new ArrayCollection();
  78. $this->notifications = new ArrayCollection();
  79. }
  80. public function getId(): ?int
  81. {
  82. return $this->id;
  83. }
  84. public function getTitle(): ?string
  85. {
  86. return $this->title;
  87. }
  88. public function setTitle(?string $title): self
  89. {
  90. $this->title = $title;
  91. return $this;
  92. }
  93. public function getContent(): ?string
  94. {
  95. return $this->content;
  96. }
  97. public function setContent(?string $content): self
  98. {
  99. $this->content = $content;
  100. return $this;
  101. }
  102. public function getModule(): ?Module
  103. {
  104. return $this->module;
  105. }
  106. public function setModule(?Module $module): self
  107. {
  108. $this->module = $module;
  109. return $this;
  110. }
  111. /**
  112. * Get the value of slug
  113. */
  114. public function getSlug()
  115. {
  116. return $this->slug;
  117. }
  118. /**
  119. * Set the value of slug
  120. *
  121. * @return self
  122. */
  123. public function setSlug($slug)
  124. {
  125. $this->slug = $slug;
  126. return $this;
  127. }
  128. /**
  129. * @return Collection<int, Comment>
  130. */
  131. public function getComments(): Collection
  132. {
  133. return $this->comments;
  134. }
  135. public function addComment(Comment $comment): self
  136. {
  137. if (!$this->comments->contains($comment)) {
  138. $this->comments[] = $comment;
  139. $comment->setSubject($this);
  140. }
  141. return $this;
  142. }
  143. public function removeComment(Comment $comment): self
  144. {
  145. if ($this->comments->removeElement($comment)) {
  146. // set the owning side to null (unless already changed)
  147. if ($comment->getSubject() === $this) {
  148. $comment->setSubject(null);
  149. }
  150. }
  151. return $this;
  152. }
  153. /**
  154. * @return Collection<int, SavedSubject>
  155. */
  156. public function getSavedSubjects(): Collection
  157. {
  158. return $this->savedSubjects;
  159. }
  160. public function addSavedSubject(SavedSubject $savedSubject): self
  161. {
  162. if (!$this->savedSubjects->contains($savedSubject)) {
  163. $this->savedSubjects[] = $savedSubject;
  164. $savedSubject->setSubject($this);
  165. }
  166. return $this;
  167. }
  168. public function removeSavedSubject(SavedSubject $savedSubject): self
  169. {
  170. if ($this->savedSubjects->removeElement($savedSubject)) {
  171. // set the owning side to null (unless already changed)
  172. if ($savedSubject->getSubject() === $this) {
  173. $savedSubject->setSubject(null);
  174. }
  175. }
  176. return $this;
  177. }
  178. /**
  179. * @return Collection<int, SubjectLike>
  180. */
  181. public function getSubjectLikes(): Collection
  182. {
  183. return $this->subjectLikes;
  184. }
  185. public function addSubjectLike(SubjectLike $subjectLike): self
  186. {
  187. if (!$this->subjectLikes->contains($subjectLike)) {
  188. $this->subjectLikes[] = $subjectLike;
  189. $subjectLike->setSubject($this);
  190. }
  191. return $this;
  192. }
  193. public function removeSubjectLike(SubjectLike $subjectLike): self
  194. {
  195. if ($this->subjectLikes->removeElement($subjectLike)) {
  196. // set the owning side to null (unless already changed)
  197. if ($subjectLike->getSubject() === $this) {
  198. $subjectLike->setSubject(null);
  199. }
  200. }
  201. return $this;
  202. }
  203. public function getTags(): ?string
  204. {
  205. return $this->tags;
  206. }
  207. public function setTags(?string $tags): self
  208. {
  209. $this->tags = $tags;
  210. return $this;
  211. }
  212. /**
  213. * @return Collection<int, SubjectTag>
  214. */
  215. public function getSubjectTags(): Collection
  216. {
  217. return $this->subjectTags;
  218. }
  219. public function addSubjectTag(SubjectTag $subjectTag): self
  220. {
  221. if (!$this->subjectTags->contains($subjectTag)) {
  222. $this->subjectTags[] = $subjectTag;
  223. $subjectTag->addSubject($this);
  224. }
  225. return $this;
  226. }
  227. public function removeSubjectTag(SubjectTag $subjectTag): self
  228. {
  229. if ($this->subjectTags->removeElement($subjectTag)) {
  230. $subjectTag->removeSubject($this);
  231. }
  232. return $this;
  233. }
  234. /**
  235. * @return Collection<int, Notification>
  236. */
  237. public function getNotifications(): Collection
  238. {
  239. return $this->notifications;
  240. }
  241. public function addNotification(Notification $notification): self
  242. {
  243. if (!$this->notifications->contains($notification)) {
  244. $this->notifications[] = $notification;
  245. $notification->setSubject($this);
  246. }
  247. return $this;
  248. }
  249. public function removeNotification(Notification $notification): self
  250. {
  251. if ($this->notifications->removeElement($notification)) {
  252. // set the owning side to null (unless already changed)
  253. if ($notification->getSubject() === $this) {
  254. $notification->setSubject(null);
  255. }
  256. }
  257. return $this;
  258. }
  259. }