src/CoreBundle/Entity/ProblemDnd.php line 15

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