src/Entity/Core/TemplateSet.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core;
  3. use App\Entity\Core\Topic\Topic;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use JsonSerializable;
  8. #[ORM\Table('template_set')]
  9. #[ORM\Entity(repositoryClass: TemplateSetRepository::class)]
  10. class TemplateSet implements JsonSerializable
  11. {
  12. /**
  13. * @var int
  14. */
  15. #[ORM\Column(name: 'id', type: 'integer')]
  16. #[ORM\Id]
  17. #[ORM\GeneratedValue(strategy: 'AUTO')]
  18. private $id;
  19. #[ORM\JoinColumn(name: 'topic_id', nullable: false)]
  20. #[ORM\ManyToOne(targetEntity: Topic::class, inversedBy: 'templates')]
  21. private Topic $topic;
  22. #[ORM\Column(type: 'string', length: 255)]
  23. private string $title;
  24. #[ORM\Column(type: 'string', length: 1000, nullable: true)]
  25. private ?string $description;
  26. #[ORM\Column(name: 'recommended_duration', type: 'integer', nullable: true)]
  27. private ?int $recommendedDuration;
  28. #[ORM\Column(type: 'boolean', options: ['default' => true])]
  29. private bool $enabled = true;
  30. /**
  31. * @var ArrayCollection|TemplateMathproblem[]
  32. */
  33. #[ORM\JoinTable(name: 'relation_template_template_set')]
  34. #[ORM\JoinColumn(name: 'template_set_id')]
  35. #[ORM\InverseJoinColumn(name: 'template_id')]
  36. #[ORM\ManyToMany(targetEntity: TemplateMathproblem::class, inversedBy: 'templateSets')]
  37. private Collection $templates;
  38. /**
  39. * @var int
  40. */
  41. #[ORM\Column(name: 'sort_order', type: 'integer', nullable: true, options: ['default' => 0])]
  42. private $sortOrder;
  43. public function __construct()
  44. {
  45. $this->templates = new ArrayCollection();
  46. }
  47. public function getId()
  48. {
  49. return $this->id;
  50. }
  51. public function getTopic(): Topic
  52. {
  53. return $this->topic;
  54. }
  55. public function setTopic(Topic $topic): void
  56. {
  57. $this->topic = $topic;
  58. }
  59. public function getTitle(): string
  60. {
  61. return $this->title;
  62. }
  63. public function setTitle(string $title): void
  64. {
  65. $this->title = $title;
  66. }
  67. public function getDescription(): ?string
  68. {
  69. return $this->description;
  70. }
  71. public function setDescription(string $description): void
  72. {
  73. $this->description = $description;
  74. }
  75. public function isEnabled(): bool
  76. {
  77. return $this->enabled;
  78. }
  79. public function setEnabled(bool $enabled): void
  80. {
  81. $this->enabled = $enabled;
  82. }
  83. /**
  84. * @return TemplateMathproblem[]|ArrayCollection
  85. */
  86. public function getTemplates(): Collection
  87. {
  88. return $this->templates;
  89. }
  90. public function addTemplate(TemplateMathproblem $template): void
  91. {
  92. if (!$this->templates->contains($template)) {
  93. $this->templates->add($template);
  94. $template->addTemplateSet($this);
  95. }
  96. }
  97. /**
  98. * @param TemplateMathproblem[]|ArrayCollection $templates
  99. */
  100. public function setTemplates($templates): void
  101. {
  102. $this->templates = $templates;
  103. }
  104. public function getRecommendedDuration(): ?int
  105. {
  106. return $this->recommendedDuration;
  107. }
  108. public function setRecommendedDuration(?int $recommendedDuration): void
  109. {
  110. $this->recommendedDuration = $recommendedDuration;
  111. }
  112. public function jsonSerialize(): mixed
  113. {
  114. return [
  115. "id" => $this->id,
  116. "title" => $this->title,
  117. "description" => $this->description,
  118. ];
  119. }
  120. /**
  121. * @return int
  122. */
  123. public function getSortOrder()
  124. {
  125. return $this->sortOrder;
  126. }
  127. /**
  128. * @param int $sortOrder
  129. */
  130. public function setSortOrder($sortOrder)
  131. {
  132. $this->sortOrder = $sortOrder;
  133. }
  134. }