src/Entity/Channel/PositioningTest/Attempt/AttemptBlock.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel\PositioningTest\Attempt;
  3. use App\Entity\Channel\PositioningTest\Block;
  4. use App\Enum\Channel\PositioningTest\StatusEnum;
  5. use DateTime;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
  10. use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
  11. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  12. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  13. #[
  14. ORM\Entity(),
  15. ORM\Table(name: 'channel_positioning_test_attempt_blocks'),
  16. ]
  17. class AttemptBlock implements TimestampInterface, BlameInterface
  18. {
  19. use TimestampTrait;
  20. use BlameTrait;
  21. #[ORM\Id]
  22. #[ORM\GeneratedValue]
  23. #[ORM\Column(type: 'integer')]
  24. private ?int $id = null;
  25. #[ORM\Column(type: 'integer')]
  26. private ?int $rank = null;
  27. #[ORM\Column(type: 'datetime', nullable: true)]
  28. private ?DateTime $startedAt = null;
  29. #[ORM\Column(type: 'integer')]
  30. private ?int $time = 0;
  31. #[ORM\Column(type: 'integer', options: ['default' => 0])]
  32. private ?int $number = 0;
  33. #[ORM\Column(type: 'string', nullable: true, options: ['default' => StatusEnum::WAITING])]
  34. private ?string $status = StatusEnum::WAITING;
  35. #[ORM\Column(type: 'string', nullable: true, options: ['default' => null])]
  36. private ?string $result = null;
  37. #[ORM\ManyToOne(targetEntity: Attempt::class, inversedBy: 'attemptBlocks')]
  38. #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  39. private ?Attempt $attempt = null;
  40. #[ORM\ManyToOne(targetEntity: Block::class)]
  41. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  42. private ?Block $block = null;
  43. #[ORM\OneToMany(mappedBy: 'attemptBlock', targetEntity: Answer::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
  44. private ?Collection $answers;
  45. public function __construct()
  46. {
  47. $this->answers = new ArrayCollection();
  48. }
  49. public function getId(): ?int
  50. {
  51. return $this->id;
  52. }
  53. public function getRank(): ?int
  54. {
  55. return $this->rank;
  56. }
  57. public function setRank(?int $rank): static
  58. {
  59. $this->rank = $rank;
  60. return $this;
  61. }
  62. public function getStartedAt(): ?DateTime
  63. {
  64. return $this->startedAt;
  65. }
  66. public function setStartedAt(?DateTime $startedAt): static
  67. {
  68. $this->startedAt = $startedAt;
  69. return $this;
  70. }
  71. public function getTime(): ?int
  72. {
  73. return $this->time;
  74. }
  75. public function setTime(?int $time): static
  76. {
  77. $this->time = $time;
  78. return $this;
  79. }
  80. public function getNumber(): ?int
  81. {
  82. return $this->number;
  83. }
  84. public function setNumber(?int $number): static
  85. {
  86. $this->number = $number;
  87. return $this;
  88. }
  89. public function incNumber(): static
  90. {
  91. $this->number++;
  92. return $this;
  93. }
  94. public function getStatus(): ?string
  95. {
  96. return $this->status;
  97. }
  98. public function setStatus(?string $status): static
  99. {
  100. $this->status = $status;
  101. return $this;
  102. }
  103. public function getResult(): ?string
  104. {
  105. return $this->result;
  106. }
  107. public function setResult(?string $result): static
  108. {
  109. $this->result = $result;
  110. return $this;
  111. }
  112. public function getAttempt(): ?Attempt
  113. {
  114. return $this->attempt;
  115. }
  116. public function setAttempt(?Attempt $attempt): static
  117. {
  118. $this->attempt = $attempt;
  119. return $this;
  120. }
  121. public function getBlock(): ?Block
  122. {
  123. return $this->block;
  124. }
  125. public function setBlock(?Block $block): static
  126. {
  127. $this->block = $block;
  128. return $this;
  129. }
  130. /**
  131. * @return Collection<int, Answer>|null
  132. */
  133. public function getAnswers(): ?Collection
  134. {
  135. return $this->answers;
  136. }
  137. public function addAnswer(Answer $answer): self
  138. {
  139. if (!$this->answers->contains($answer)) {
  140. $answer->setAttemptBlock($this);
  141. $this->answers[] = $answer;
  142. }
  143. return $this;
  144. }
  145. public function removeAnswer(Answer $answer): self
  146. {
  147. if ($this->answers->contains($answer)) {
  148. $this->answers->removeElement($answer);
  149. }
  150. return $this;
  151. }
  152. }