<?php
namespace App\Entity\Channel\PositioningTest;
use App\Entity\Channel\Channel;
use App\Entity\Channel\PositioningTest\Attempt\Attempt;
use App\Repository\Channel\PositioningTest\PositioningTestRepository;
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 Nellapp\Bundle\SDKBundle\Google\Entity\GoogleDriveFile;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: PositioningTestRepository::class),
ORM\Table(name: 'channel_positioning_tests'),
]
class PositioningTest implements TimestampInterface, BlameInterface
{
use TimestampTrait;
use BlameTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 64, unique: true)]
private ?string $accessToken;
#[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.test.title.NotBlank'),
Assert\Length(
max: 255,
maxMessage: 'positioningTest.test.title.Length.max'
)
]
private ?string $title = null;
#[ORM\Column(type: 'text', length: 5000, nullable: true)]
#[
Assert\Length(
max: 5000,
maxMessage: 'positioningTest.test.description.Length.max'
)
]
private ?string $description = null;
#[ORM\Column(type: 'text', length: 5000, nullable: true)]
#[
Assert\Length(
max: 5000,
maxMessage: 'positioningTest.test.breakText.Length.max'
)
]
private ?string $breakText = null;
#[ORM\Column(type: 'text', length: 5000, nullable: true)]
#[
Assert\Length(
max: 5000,
maxMessage: 'positioningTest.test.fraudText.Length.max'
)
]
private ?string $fraudText = null;
#[ORM\ManyToOne(targetEntity: Channel::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?Channel $channel = null;
#[ORM\OneToMany(mappedBy: 'positioningTest', targetEntity: PositioningTestBlock::class, cascade: ['persist'], orphanRemoval: true)]
#[ORM\OrderBy(['rank' => 'ASC'])]
#[Assert\Valid]
private ?Collection $positioningTestBlocks;
#[ORM\OneToMany(mappedBy: 'positioningTest', targetEntity: Attempt::class)]
private ?Collection $attempts;
#[ORM\OneToOne(targetEntity: GoogleDriveFile::class, cascade: ['persist'])]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?GoogleDriveFile $googleDriveFile = null;
public function __construct()
{
$this->accessToken = bin2hex(random_bytes(32));
$this->positioningTestBlocks = new ArrayCollection();
$this->attempts = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getAccessToken(): ?string
{
return $this->accessToken;
}
public function setAccessToken(?string $accessToken): static
{
$this->accessToken = $accessToken;
return $this;
}
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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): static
{
$this->description = $description;
return $this;
}
public function getBreakText(): ?string
{
return $this->breakText;
}
public function setBreakText(?string $breakText): static
{
$this->breakText = $breakText;
return $this;
}
public function getFraudText(): ?string
{
return $this->fraudText;
}
public function setFraudText(?string $fraudText): static
{
$this->fraudText = $fraudText;
return $this;
}
public function getChannel(): ?Channel
{
return $this->channel;
}
public function setChannel(?Channel $channel): static
{
$this->channel = $channel;
return $this;
}
/**
* @return Collection<int, PositioningTestBlock>|null
*/
public function getPositioningTestBlocks(): ?Collection
{
return $this->positioningTestBlocks;
}
public function addPositioningTestBlock(PositioningTestBlock $block): self
{
if (!$this->positioningTestBlocks->contains($block)) {
$block->setPositioningTest($this);
$this->positioningTestBlocks->add($block);
}
return $this;
}
public function removePositioningTestBlock(PositioningTestBlock $block): self
{
if ($this->positioningTestBlocks->contains($block)) {
$this->positioningTestBlocks->removeElement($block);
}
return $this;
}
public function getAttempts(): ?Collection
{
return $this->attempts;
}
public function addAttempt(Attempt $attempt): self
{
if (!$this->attempts->contains($attempt)) {
$this->attempts[] = $attempt;
}
return $this;
}
public function removeAttempt(Attempt $attempt): self
{
if ($this->attempts->contains($attempt)) {
$this->attempts->removeElement($attempt);
}
return $this;
}
public function getGoogleDriveFile(): ?GoogleDriveFile
{
return $this->googleDriveFile;
}
public function setGoogleDriveFile(?GoogleDriveFile $googleDriveFile): PositioningTest
{
$this->googleDriveFile = $googleDriveFile;
return $this;
}
}