src/Entity/Core/SelfStudy/SelfStudyCategory.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core\SelfStudy;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use JsonSerializable;
  7. #[ORM\Table('self_study_category')]
  8. #[ORM\Entity]
  9. class SelfStudyCategory implements JsonSerializable
  10. {
  11. /**
  12. * @var int
  13. */
  14. #[ORM\Column(name: 'id', type: 'integer')]
  15. #[ORM\Id]
  16. #[ORM\GeneratedValue(strategy: 'AUTO')]
  17. private $id;
  18. /**
  19. * @var string
  20. */
  21. #[ORM\Column(name: 'display_name', type: 'string', length: 255)]
  22. private $displayName;
  23. /**
  24. * @var string
  25. */
  26. #[ORM\Column(name: 'icon', type: 'string', length: 255, nullable: true)]
  27. private $icon;
  28. /**
  29. * @var string
  30. */
  31. #[ORM\Column(name: 'image', type: 'string', length: 255, nullable: true)]
  32. private $image;
  33. /**
  34. * @var string
  35. */
  36. #[ORM\Column(name: 'teaser', type: 'string', length: 1000, nullable: true)]
  37. private $teaser;
  38. /**
  39. * @var int
  40. */
  41. #[ORM\Column(name: 'sort_order', type: 'integer', nullable: true, options: ['default' => 0])]
  42. private $sortOrder;
  43. /**
  44. * @var SelfStudy
  45. */
  46. #[ORM\JoinColumn(name: 'self_study', referencedColumnName: 'id')]
  47. #[ORM\ManyToOne(targetEntity: SelfStudy::class, inversedBy: 'selfStudyCategories')]
  48. private $selfStudy;
  49. /**
  50. * @var SelfStudyTopic[]
  51. */
  52. #[ORM\OneToMany(targetEntity: SelfStudyTopic::class, mappedBy: 'selfStudyCategory', cascade: ['persist'])]
  53. private $selfStudyTopics;
  54. public function __construct()
  55. {
  56. $this->selfStudyTopics = new ArrayCollection();
  57. }
  58. public function getId(): int
  59. {
  60. return $this->id;
  61. }
  62. public function getDisplayName(): string
  63. {
  64. return $this->displayName;
  65. }
  66. public function getSelfStudy(): SelfStudy
  67. {
  68. return $this->selfStudy;
  69. }
  70. public function getIcon(): string
  71. {
  72. return $this->icon;
  73. }
  74. public function getImage(): string
  75. {
  76. return $this->image;
  77. }
  78. public function getTeaser(): ?string
  79. {
  80. return $this->teaser;
  81. }
  82. public function getSelfStudyTopics(): Collection
  83. {
  84. return $this->selfStudyTopics;
  85. }
  86. public function getSortOrder(): int
  87. {
  88. return $this->sortOrder;
  89. }
  90. public function jsonSerialize(): mixed
  91. {
  92. return [
  93. "id" => $this->getId(),
  94. "name" => $this->getDisplayName(),
  95. "icon" => $this->getIcon(),
  96. "topics" => array_map(function ($topic) {
  97. return $topic->jsonSerialize();
  98. }, $this->getSelfStudyTopics()->toArray()),
  99. ];
  100. }
  101. }