src/Entity/Channel/PositioningTest/PositioningTest.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel\PositioningTest;
  3. use App\Entity\Channel\Channel;
  4. use App\Entity\Channel\PositioningTest\Attempt\Attempt;
  5. use App\Repository\Channel\PositioningTest\PositioningTestRepository;
  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. use Nellapp\Bundle\SDKBundle\Google\Entity\GoogleDriveFile;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. #[
  16. ORM\Entity(repositoryClass: PositioningTestRepository::class),
  17. ORM\Table(name: 'channel_positioning_tests'),
  18. ]
  19. class PositioningTest implements TimestampInterface, BlameInterface
  20. {
  21. use TimestampTrait;
  22. use BlameTrait;
  23. #[ORM\Id]
  24. #[ORM\GeneratedValue]
  25. #[ORM\Column(type: 'integer')]
  26. private ?int $id = null;
  27. #[ORM\Column(type: 'string', length: 64, unique: true)]
  28. private ?string $accessToken;
  29. #[ORM\Column(type: 'boolean')]
  30. private bool $archived = false;
  31. #[ORM\Column(type: 'boolean')]
  32. private bool $locked = false;
  33. #[ORM\Column(type: 'string', length: 255)]
  34. #[
  35. Assert\NotBlank(message: 'positioningTest.test.title.NotBlank'),
  36. Assert\Length(
  37. max: 255,
  38. maxMessage: 'positioningTest.test.title.Length.max'
  39. )
  40. ]
  41. private ?string $title = null;
  42. #[ORM\Column(type: 'text', length: 5000, nullable: true)]
  43. #[
  44. Assert\Length(
  45. max: 5000,
  46. maxMessage: 'positioningTest.test.description.Length.max'
  47. )
  48. ]
  49. private ?string $description = null;
  50. #[ORM\Column(type: 'text', length: 5000, nullable: true)]
  51. #[
  52. Assert\Length(
  53. max: 5000,
  54. maxMessage: 'positioningTest.test.breakText.Length.max'
  55. )
  56. ]
  57. private ?string $breakText = null;
  58. #[ORM\Column(type: 'text', length: 5000, nullable: true)]
  59. #[
  60. Assert\Length(
  61. max: 5000,
  62. maxMessage: 'positioningTest.test.fraudText.Length.max'
  63. )
  64. ]
  65. private ?string $fraudText = null;
  66. #[ORM\ManyToOne(targetEntity: Channel::class)]
  67. #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  68. private ?Channel $channel = null;
  69. #[ORM\OneToMany(mappedBy: 'positioningTest', targetEntity: PositioningTestBlock::class, cascade: ['persist'], orphanRemoval: true)]
  70. #[ORM\OrderBy(['rank' => 'ASC'])]
  71. #[Assert\Valid]
  72. private ?Collection $positioningTestBlocks;
  73. #[ORM\OneToMany(mappedBy: 'positioningTest', targetEntity: Attempt::class)]
  74. private ?Collection $attempts;
  75. #[ORM\OneToOne(targetEntity: GoogleDriveFile::class, cascade: ['persist'])]
  76. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  77. private ?GoogleDriveFile $googleDriveFile = null;
  78. public function __construct()
  79. {
  80. $this->accessToken = bin2hex(random_bytes(32));
  81. $this->positioningTestBlocks = new ArrayCollection();
  82. $this->attempts = new ArrayCollection();
  83. }
  84. public function getId(): ?int
  85. {
  86. return $this->id;
  87. }
  88. public function getAccessToken(): ?string
  89. {
  90. return $this->accessToken;
  91. }
  92. public function setAccessToken(?string $accessToken): static
  93. {
  94. $this->accessToken = $accessToken;
  95. return $this;
  96. }
  97. public function isArchived(): bool
  98. {
  99. return $this->archived;
  100. }
  101. public function setArchived(bool $archived): static
  102. {
  103. $this->archived = $archived;
  104. return $this;
  105. }
  106. public function isLocked(): bool
  107. {
  108. return $this->locked;
  109. }
  110. public function setLocked(bool $locked): static
  111. {
  112. $this->locked = $locked;
  113. return $this;
  114. }
  115. public function getTitle(): ?string
  116. {
  117. return $this->title;
  118. }
  119. public function setTitle(?string $title): static
  120. {
  121. $this->title = $title;
  122. return $this;
  123. }
  124. public function getDescription(): ?string
  125. {
  126. return $this->description;
  127. }
  128. public function setDescription(?string $description): static
  129. {
  130. $this->description = $description;
  131. return $this;
  132. }
  133. public function getBreakText(): ?string
  134. {
  135. return $this->breakText;
  136. }
  137. public function setBreakText(?string $breakText): static
  138. {
  139. $this->breakText = $breakText;
  140. return $this;
  141. }
  142. public function getFraudText(): ?string
  143. {
  144. return $this->fraudText;
  145. }
  146. public function setFraudText(?string $fraudText): static
  147. {
  148. $this->fraudText = $fraudText;
  149. return $this;
  150. }
  151. public function getChannel(): ?Channel
  152. {
  153. return $this->channel;
  154. }
  155. public function setChannel(?Channel $channel): static
  156. {
  157. $this->channel = $channel;
  158. return $this;
  159. }
  160. /**
  161. * @return Collection<int, PositioningTestBlock>|null
  162. */
  163. public function getPositioningTestBlocks(): ?Collection
  164. {
  165. return $this->positioningTestBlocks;
  166. }
  167. public function addPositioningTestBlock(PositioningTestBlock $block): self
  168. {
  169. if (!$this->positioningTestBlocks->contains($block)) {
  170. $block->setPositioningTest($this);
  171. $this->positioningTestBlocks->add($block);
  172. }
  173. return $this;
  174. }
  175. public function removePositioningTestBlock(PositioningTestBlock $block): self
  176. {
  177. if ($this->positioningTestBlocks->contains($block)) {
  178. $this->positioningTestBlocks->removeElement($block);
  179. }
  180. return $this;
  181. }
  182. public function getAttempts(): ?Collection
  183. {
  184. return $this->attempts;
  185. }
  186. public function addAttempt(Attempt $attempt): self
  187. {
  188. if (!$this->attempts->contains($attempt)) {
  189. $this->attempts[] = $attempt;
  190. }
  191. return $this;
  192. }
  193. public function removeAttempt(Attempt $attempt): self
  194. {
  195. if ($this->attempts->contains($attempt)) {
  196. $this->attempts->removeElement($attempt);
  197. }
  198. return $this;
  199. }
  200. public function getGoogleDriveFile(): ?GoogleDriveFile
  201. {
  202. return $this->googleDriveFile;
  203. }
  204. public function setGoogleDriveFile(?GoogleDriveFile $googleDriveFile): PositioningTest
  205. {
  206. $this->googleDriveFile = $googleDriveFile;
  207. return $this;
  208. }
  209. }