src/Entity/Core/ProblemDnd.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Core;
  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('problem_dnd')]
  8. #[ORM\Entity(repositoryClass: ProblemDndRepository::class)]
  9. class ProblemDnd implements JsonSerializable
  10. {
  11. const BLOCK_TYPE = 'block';
  12. #[ORM\Column(name: 'id', type: 'integer')]
  13. #[ORM\Id]
  14. #[ORM\GeneratedValue(strategy: 'AUTO')]
  15. private int $id;
  16. #[ORM\OneToOne(targetEntity: Mathproblem::class)]
  17. private Mathproblem $problem;
  18. #[ORM\OneToMany(targetEntity: ProblemDndBin::class, mappedBy: 'problemDnd')]
  19. private Collection $bins;
  20. #[ORM\Column(name: 'bins_shuffled', type: 'boolean')]
  21. private bool $binsShuffled;
  22. #[ORM\Column(name: 'single_bin', type: 'boolean')]
  23. private bool $singleBin;
  24. #[ORM\Column(name: 'type', type: 'string', nullable: true)]
  25. private $type = null;
  26. #[ORM\Column(type: 'boolean')]
  27. private bool $horizontal;
  28. #[ORM\Column(name: 'multi', type: 'boolean')]
  29. private bool $multi;
  30. public function __construct()
  31. {
  32. $this->bins = new ArrayCollection();
  33. }
  34. public function getId(): int
  35. {
  36. return $this->id;
  37. }
  38. public function getProblem(): Mathproblem
  39. {
  40. return $this->problem;
  41. }
  42. /**
  43. * @return Collection|ArrayCollection|ProblemDndBin[]
  44. */
  45. public function getBins(): Collection
  46. {
  47. return $this->bins;
  48. }
  49. public function isMulti(): bool
  50. {
  51. return $this->multi;
  52. }
  53. public function isBinsShuffled(): bool
  54. {
  55. return $this->binsShuffled;
  56. }
  57. public function setBinsShuffled(bool $BinsShuffled)
  58. {
  59. $this->binsShuffled = $BinsShuffled;
  60. }
  61. public function isSingleBin(): bool
  62. {
  63. return $this->singleBin;
  64. }
  65. public function setSingleBin(bool $singleBin)
  66. {
  67. $this->singleBin = $singleBin;
  68. }
  69. public function isHorizontal(): bool
  70. {
  71. return $this->horizontal;
  72. }
  73. public function setHorizontal(bool $horizontal)
  74. {
  75. $this->horizontal = $horizontal;
  76. }
  77. /**
  78. * @return $this
  79. */
  80. function setType(string $type): self{
  81. $this->type = $type;
  82. return $this;
  83. }
  84. function getType(): string|null{
  85. return $this->type;
  86. }
  87. public function setProblem(Mathproblem $problem): void
  88. {
  89. $this->problem = $problem;
  90. }
  91. public function setMulti(bool $multi): void
  92. {
  93. $this->multi = $multi;
  94. }
  95. public function getBinByIndex(int $index)
  96. {
  97. foreach ($this->getBins() as $bin) {
  98. if ($bin->getIndex() === $index)
  99. return $bin;
  100. }
  101. return null;
  102. }
  103. public function jsonSerialize(): mixed
  104. {
  105. return [
  106. "id" => $this->id,
  107. "binsShuffled" => $this->binsShuffled,
  108. "singleBin" => $this->singleBin,
  109. "horizontal" => $this->horizontal,
  110. "multi" => $this->multi,
  111. "type" => $this->type
  112. ];
  113. }
  114. }