src/Entity/Channel/PositioningTest/Block.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel\PositioningTest;
  3. use App\Entity\Channel\Channel;
  4. use App\Repository\Channel\PositioningTest\BlockRepository;
  5. use DateTimeInterface;
  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 Symfony\Component\Validator\Constraints as Assert;
  14. use Symfony\Component\Serializer\Annotation as Serial;
  15. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  16. #[
  17.     ORM\Entity(repositoryClassBlockRepository::class),
  18.     ORM\Table(name'channel_positioning_test_blocks'),
  19. ]
  20. class Block implements TimestampInterfaceBlameInterface
  21. {
  22.     use TimestampTrait;
  23.     use BlameTrait;
  24.     #[ORM\Id]
  25.     #[ORM\GeneratedValue]
  26.     #[ORM\Column(type'integer')]
  27.     #[Serial\Groups(['Manager'])]
  28.     private ?int $id null;
  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'length255)]
  34.     #[
  35.         Assert\NotBlank(message'positioningTest.block.title.NotBlank'),
  36.         Assert\Length(
  37.             max255,
  38.             maxMessage'positioningTest.block.title.Length.max'
  39.         )
  40.     ]
  41.     #[Serial\Groups(['Manager'])]
  42.     private ?string $title null;
  43.     #[ORM\Column(type'text'length5000nullabletrue)]
  44.     #[
  45.         Assert\Length(
  46.             max5000,
  47.             maxMessage'positioningTest.block.mandatory_info.Length.max'
  48.         )
  49.     ]
  50.     private ?string $mandatoryInfo null;
  51.     #[ORM\Column(type'text'length5000nullabletrue)]
  52.     #[
  53.         Assert\Length(
  54.             max5000,
  55.             maxMessage'positioningTest.block.description.Length.max'
  56.         )
  57.     ]
  58.     private ?string $description null;
  59.     #[ORM\Column(type'boolean')]
  60.     private bool $limitedTime false;
  61.     #[ORM\Column(type'integer'nullabletrue)]
  62.     private ?int $estimatedTime null// in seconds
  63.     #[ORM\Column(type'boolean'options: ['default' => true])]
  64.     private bool $exampleEnabled true;
  65.     #[ORM\Column(type'string'length255nullabletrue)]
  66.     #[
  67.         Assert\Length(
  68.             max255,
  69.             maxMessage'positioningTest.question.label.Length.max'
  70.         )
  71.     ]
  72.     private ?string $exampleLabel null;
  73.     #[ORM\Column(type'text'length5000nullabletrue)]
  74.     #[
  75.         Assert\Length(
  76.             max5000,
  77.             maxMessage'positioningTest.question.description.Length.max'
  78.         )
  79.     ]
  80.     private ?string $exampleDescription null;
  81.     #[ORM\Column(type'json'length5000nullabletrue)]
  82.     private ?array $exampleAnswers = [];
  83.     #[ORM\ManyToOne(targetEntityChannel::class)]
  84.     #[ORM\JoinColumn(nullablefalseonDelete'CASCADE')]
  85.     private ?Channel $channel null;
  86.     #[ORM\OneToMany(mappedBy'block'targetEntityPositioningTestBlock::class)]
  87.     private ?Collection $positioningTestBlocks;
  88.     #[ORM\OneToMany(mappedBy'block'targetEntityQuestion::class, cascade: ['persist''remove'], orphanRemovaltrue)]
  89.     #[ORM\OrderBy(['rank' => 'ASC'])]
  90.     #[Assert\Valid]
  91.     private ?Collection $questions;
  92.     public function __construct()
  93.     {
  94.         $this->positioningTestBlocks = new ArrayCollection();
  95.         $this->questions = new ArrayCollection();
  96.     }
  97.     public function getId(): ?int
  98.     {
  99.         return $this->id;
  100.     }
  101.     public function isArchived(): bool
  102.     {
  103.         return $this->archived;
  104.     }
  105.     public function setArchived(bool $archived): static
  106.     {
  107.         $this->archived $archived;
  108.         return $this;
  109.     }
  110.     public function isLocked(): bool
  111.     {
  112.         return $this->locked;
  113.     }
  114.     public function setLocked(bool $locked): static
  115.     {
  116.         $this->locked $locked;
  117.         return $this;
  118.     }
  119.     public function getTitle(): ?string
  120.     {
  121.         return $this->title;
  122.     }
  123.     public function setTitle(?string $title): static
  124.     {
  125.         $this->title $title;
  126.         return $this;
  127.     }
  128.     public function getMandatoryInfo(): ?string
  129.     {
  130.         return $this->mandatoryInfo;
  131.     }
  132.     public function setMandatoryInfo(?string $mandatoryInfo): static
  133.     {
  134.         $this->mandatoryInfo $mandatoryInfo;
  135.         return $this;
  136.     }
  137.     public function getDescription(): ?string
  138.     {
  139.         return $this->description;
  140.     }
  141.     public function setDescription(?string $description): static
  142.     {
  143.         $this->description $description;
  144.         return $this;
  145.     }
  146.     #[Serial\Groups(['Manager'])]
  147.     public function isLimitedTime(): bool
  148.     {
  149.         return $this->limitedTime;
  150.     }
  151.     public function setLimitedTime(bool $limitedTime): static
  152.     {
  153.         $this->limitedTime $limitedTime;
  154.         return $this;
  155.     }
  156.     #[Serial\Groups(['Manager'])]
  157.     public function getEstimatedTime(): ?int
  158.     {
  159.         return $this->estimatedTime;
  160.     }
  161.     public function setEstimatedTime(?int $estimatedTime): static
  162.     {
  163.         $this->estimatedTime $estimatedTime;
  164.         return $this;
  165.     }
  166.     #[Assert\Callback]
  167.     public function validateEstimatedTime(ExecutionContextInterface $contextmixed $payload): void
  168.     {
  169.         if ($this->islimitedTime() && !$this->getEstimatedTime()) {
  170.             $context
  171.                 ->buildViolation('positioningTest.block.time.NotBlank')
  172.                 ->atPath('estimatedTime')
  173.                 ->addViolation()
  174.             ;
  175.         }
  176.     }
  177.     public function isExampleEnabled(): bool
  178.     {
  179.         return $this->exampleEnabled;
  180.     }
  181.     public function setExampleEnabled(bool $exampleEnabled): static
  182.     {
  183.         $this->exampleEnabled $exampleEnabled;
  184.         return $this;
  185.     }
  186.     public function getExampleLabel(): ?string
  187.     {
  188.         return $this->exampleLabel;
  189.     }
  190.     public function setExampleLabel(?string $exampleLabel): static
  191.     {
  192.         $this->exampleLabel $exampleLabel;
  193.         return $this;
  194.     }
  195.     public function getExampleDescription(): ?string
  196.     {
  197.         return $this->exampleDescription;
  198.     }
  199.     public function setExampleDescription(?string $exampleDescription): static
  200.     {
  201.         $this->exampleDescription $exampleDescription;
  202.         return $this;
  203.     }
  204.     public function getExampleAnswers(): ?array
  205.     {
  206.         return $this->exampleAnswers;
  207.     }
  208.     public function setExampleAnswers(?array $exampleAnswers): static
  209.     {
  210.         $this->exampleAnswers $exampleAnswers;
  211.         return $this;
  212.     }
  213.     public function getChannel(): ?Channel
  214.     {
  215.         return $this->channel;
  216.     }
  217.     public function setChannel(?Channel $channel): static
  218.     {
  219.         $this->channel $channel;
  220.         return $this;
  221.     }
  222.     public function getPositioningTests(): ?Collection
  223.     {
  224.         return $this->positioningTestBlocks;
  225.     }
  226.     public function addPositioningTest(PositioningTestBlock $test): self
  227.     {
  228.         if (!$this->positioningTestBlocks->contains($test)) {
  229.             $this->positioningTestBlocks[] = $test;
  230.         }
  231.         return $this;
  232.     }
  233.     public function removePositioningTest(PositioningTestBlock $test): self
  234.     {
  235.         if ($this->positioningTestBlocks->contains($test)) {
  236.             $this->positioningTestBlocks->removeElement($test);
  237.         }
  238.         return $this;
  239.     }
  240.     /**
  241.      * @return Collection<int, Question>|null
  242.      */
  243.     public function getQuestions(): ?Collection
  244.     {
  245.         return $this->questions;
  246.     }
  247.     public function addQuestion(Question $question): self
  248.     {
  249.         if (!$this->questions->contains($question)) {
  250.             $question->setBlock($this);
  251.             $this->questions->add($question);
  252.         }
  253.         return $this;
  254.     }
  255.     public function removeQuestion(Question $question): self
  256.     {
  257.         if ($this->questions->contains($question)) {
  258.             $this->questions->removeElement($question);
  259.         }
  260.         return $this;
  261.     }
  262. }