<?php
namespace App\Entity\Channel\PositioningTest;
use App\Entity\Channel\Channel;
use App\Repository\Channel\PositioningTest\BlockRepository;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use DrosalysWeb\ObjectExtensions\Blame\Model\BlameInterface;
use DrosalysWeb\ObjectExtensions\Blame\Model\BlameTrait;
use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
#[
ORM\Entity(repositoryClass: BlockRepository::class),
ORM\Table(name: 'channel_positioning_test_blocks'),
]
class Block implements TimestampInterface, BlameInterface
{
use TimestampTrait;
use BlameTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
#[Serial\Groups(['Manager'])]
private ?int $id = null;
#[ORM\Column(type: 'boolean')]
private bool $archived = false;
#[ORM\Column(type: 'boolean')]
private bool $locked = false;
#[ORM\Column(type: 'string', length: 255)]
#[
Assert\NotBlank(message: 'positioningTest.block.title.NotBlank'),
Assert\Length(
max: 255,
maxMessage: 'positioningTest.block.title.Length.max'
)
]
#[Serial\Groups(['Manager'])]
private ?string $title = null;
#[ORM\Column(type: 'text', length: 5000, nullable: true)]
#[
Assert\Length(
max: 5000,
maxMessage: 'positioningTest.block.mandatory_info.Length.max'
)
]
private ?string $mandatoryInfo = null;
#[ORM\Column(type: 'text', length: 5000, nullable: true)]
#[
Assert\Length(
max: 5000,
maxMessage: 'positioningTest.block.description.Length.max'
)
]
private ?string $description = null;
#[ORM\Column(type: 'boolean')]
private bool $limitedTime = false;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $estimatedTime = null; // in seconds
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private bool $exampleEnabled = true;
#[ORM\Column(type: 'string', length: 255, nullable: true)]
#[
Assert\Length(
max: 255,
maxMessage: 'positioningTest.question.label.Length.max'
)
]
private ?string $exampleLabel = null;
#[ORM\Column(type: 'text', length: 5000, nullable: true)]
#[
Assert\Length(
max: 5000,
maxMessage: 'positioningTest.question.description.Length.max'
)
]
private ?string $exampleDescription = null;
#[ORM\Column(type: 'json', length: 5000, nullable: true)]
private ?array $exampleAnswers = [];
#[ORM\ManyToOne(targetEntity: Channel::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?Channel $channel = null;
#[ORM\OneToMany(mappedBy: 'block', targetEntity: PositioningTestBlock::class)]
private ?Collection $positioningTestBlocks;
#[ORM\OneToMany(mappedBy: 'block', targetEntity: Question::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
#[ORM\OrderBy(['rank' => 'ASC'])]
#[Assert\Valid]
private ?Collection $questions;
public function __construct()
{
$this->positioningTestBlocks = new ArrayCollection();
$this->questions = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function isArchived(): bool
{
return $this->archived;
}
public function setArchived(bool $archived): static
{
$this->archived = $archived;
return $this;
}
public function isLocked(): bool
{
return $this->locked;
}
public function setLocked(bool $locked): static
{
$this->locked = $locked;
return $this;
}
public function getTitle(): ?string
{
return $this->title;
}
public function setTitle(?string $title): static
{
$this->title = $title;
return $this;
}
public function getMandatoryInfo(): ?string
{
return $this->mandatoryInfo;
}
public function setMandatoryInfo(?string $mandatoryInfo): static
{
$this->mandatoryInfo = $mandatoryInfo;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
#[Serial\Groups(['Manager'])]
public function isLimitedTime(): bool
{
return $this->limitedTime;
}
public function setLimitedTime(bool $limitedTime): static
{
$this->limitedTime = $limitedTime;
return $this;
}
#[Serial\Groups(['Manager'])]
public function getEstimatedTime(): ?int
{
return $this->estimatedTime;
}
public function setEstimatedTime(?int $estimatedTime): static
{
$this->estimatedTime = $estimatedTime;
return $this;
}
#[Assert\Callback]
public function validateEstimatedTime(ExecutionContextInterface $context, mixed $payload): void
{
if ($this->islimitedTime() && !$this->getEstimatedTime()) {
$context
->buildViolation('positioningTest.block.time.NotBlank')
->atPath('estimatedTime')
->addViolation()
;
}
}
public function isExampleEnabled(): bool
{
return $this->exampleEnabled;
}
public function setExampleEnabled(bool $exampleEnabled): static
{
$this->exampleEnabled = $exampleEnabled;
return $this;
}
public function getExampleLabel(): ?string
{
return $this->exampleLabel;
}
public function setExampleLabel(?string $exampleLabel): static
{
$this->exampleLabel = $exampleLabel;
return $this;
}
public function getExampleDescription(): ?string
{
return $this->exampleDescription;
}
public function setExampleDescription(?string $exampleDescription): static
{
$this->exampleDescription = $exampleDescription;
return $this;
}
public function getExampleAnswers(): ?array
{
return $this->exampleAnswers;
}
public function setExampleAnswers(?array $exampleAnswers): static
{
$this->exampleAnswers = $exampleAnswers;
return $this;
}
public function getChannel(): ?Channel
{
return $this->channel;
}
public function setChannel(?Channel $channel): static
{
$this->channel = $channel;
return $this;
}
public function getPositioningTests(): ?Collection
{
return $this->positioningTestBlocks;
}
public function addPositioningTest(PositioningTestBlock $test): self
{
if (!$this->positioningTestBlocks->contains($test)) {
$this->positioningTestBlocks[] = $test;
}
return $this;
}
public function removePositioningTest(PositioningTestBlock $test): self
{
if ($this->positioningTestBlocks->contains($test)) {
$this->positioningTestBlocks->removeElement($test);
}
return $this;
}
/**
* @return Collection<int, Question>|null
*/
public function getQuestions(): ?Collection
{
return $this->questions;
}
public function addQuestion(Question $question): self
{
if (!$this->questions->contains($question)) {
$question->setBlock($this);
$this->questions->add($question);
}
return $this;
}
public function removeQuestion(Question $question): self
{
if ($this->questions->contains($question)) {
$this->questions->removeElement($question);
}
return $this;
}
}