src/Entity/HymnCategory.php line 15

Open in your IDE?
  1. <?php namespace App\Entity;
  2. use App\Repository\HymnCategoryRepository;
  3. use DateTime;
  4. use Doctrine\Common\Collections\{ArrayCollection, Collection};
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Gedmo\Mapping\Annotation as Gedmo;
  7. /**
  8. * HymnCategory
  9. *
  10. * @ORM\Table(name="hymn_category")
  11. * @ORM\Entity(repositoryClass=HymnCategoryRepository::class)
  12. */
  13. class HymnCategory
  14. {
  15. /**
  16. * @var int
  17. *
  18. * @ORM\Column(type="integer", name="id", options={"unsigned":true})
  19. * @ORM\Id
  20. * @ORM\GeneratedValue(strategy="IDENTITY")
  21. */
  22. private int $id;
  23. /**
  24. * @ORM\Column(type="string", length=255)
  25. */
  26. private string $title;
  27. /**
  28. * @Gedmo\Slug(fields={"title","slug"})
  29. * @ORM\Column(type="string", length=128)
  30. */
  31. private string $slug;
  32. /**
  33. * @ORM\Column(type="text", nullable=true)
  34. */
  35. private string $description;
  36. /**
  37. * @ORM\Column(type="datetime", nullable=true)
  38. */
  39. private DateTime $created_at;
  40. /**
  41. * @ORM\ManyToMany(targetEntity="App\Entity\Hymns", mappedBy="category")
  42. * @ORM\OrderBy({"title" = "ASC"})
  43. */
  44. protected Collection $hymns;
  45. /**
  46. * HymnCategory constructor
  47. *
  48. * @return void
  49. */
  50. public function __construct()
  51. {
  52. $this->hymns = new ArrayCollection();
  53. $this->setCreatedAt(new DateTime('now'));
  54. }
  55. /**
  56. * @return int|null
  57. */
  58. public function getId(): ?int
  59. {
  60. return $this->id;
  61. }
  62. /**
  63. * @param int $id
  64. * @return HymnCategory
  65. */
  66. public function setId(int $id): HymnCategory
  67. {
  68. $this->id = $id;
  69. return $this;
  70. }
  71. /**
  72. * @return string|null
  73. */
  74. public function getTitle(): ?string
  75. {
  76. return $this->title;
  77. }
  78. /**
  79. * @param string $title
  80. * @return $this
  81. */
  82. public function setTitle(string $title): self
  83. {
  84. $this->title = $title;
  85. return $this;
  86. }
  87. /**
  88. * @return string|null
  89. */
  90. public function getSlug(): ?string
  91. {
  92. return $this->slug;
  93. }
  94. /**
  95. * @param string $slug
  96. * @return $this
  97. */
  98. public function setSlug(string $slug): self
  99. {
  100. $this->slug = $slug;
  101. return $this;
  102. }
  103. /**
  104. * @return string|null
  105. */
  106. public function getDescription(): ?string
  107. {
  108. return $this->description;
  109. }
  110. /**
  111. * @param string $description
  112. * @return $this
  113. */
  114. public function setDescription(string $description): self
  115. {
  116. $this->description = $description;
  117. return $this;
  118. }
  119. /**
  120. * @return DateTime|null
  121. */
  122. public function getCreatedAt(): ?DateTime
  123. {
  124. return $this->created_at;
  125. }
  126. /**
  127. * @param DateTime $created_at
  128. * @return $this
  129. */
  130. public function setCreatedAt(DateTime $created_at): self
  131. {
  132. $this->created_at = $created_at;
  133. return $this;
  134. }
  135. /**
  136. * @return Collection
  137. */
  138. public function getHymns(): Collection
  139. {
  140. return $this->hymns;
  141. }
  142. /**
  143. * @param Collection $hymns
  144. * @return $this
  145. */
  146. public function setHymns(Collection $hymns): self
  147. {
  148. if(!$this->hymns->contains($hymns)) {
  149. $this->hymns = $hymns;
  150. }
  151. return $this;
  152. }
  153. }