<?php
namespace App\Entity\Channel\PositioningTest\Attempt;
use App\Entity\Channel\PositioningTest\Block;
use App\Enum\Channel\PositioningTest\StatusEnum;
use DateTime;
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;
#[
ORM\Entity(),
ORM\Table(name: 'channel_positioning_test_attempt_blocks'),
]
class AttemptBlock implements TimestampInterface, BlameInterface
{
use TimestampTrait;
use BlameTrait;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'integer')]
private ?int $rank = null;
#[ORM\Column(type: 'datetime', nullable: true)]
private ?DateTime $startedAt = null;
#[ORM\Column(type: 'integer')]
private ?int $time = 0;
#[ORM\Column(type: 'integer', options: ['default' => 0])]
private ?int $number = 0;
#[ORM\Column(type: 'string', nullable: true, options: ['default' => StatusEnum::WAITING])]
private ?string $status = StatusEnum::WAITING;
#[ORM\Column(type: 'string', nullable: true, options: ['default' => null])]
private ?string $result = null;
#[ORM\ManyToOne(targetEntity: Attempt::class, inversedBy: 'attemptBlocks')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?Attempt $attempt = null;
#[ORM\ManyToOne(targetEntity: Block::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Block $block = null;
#[ORM\OneToMany(mappedBy: 'attemptBlock', targetEntity: Answer::class, cascade: ['persist', 'remove'], orphanRemoval: true)]
private ?Collection $answers;
public function __construct()
{
$this->answers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getRank(): ?int
{
return $this->rank;
}
public function setRank(?int $rank): static
{
$this->rank = $rank;
return $this;
}
public function getStartedAt(): ?DateTime
{
return $this->startedAt;
}
public function setStartedAt(?DateTime $startedAt): static
{
$this->startedAt = $startedAt;
return $this;
}
public function getTime(): ?int
{
return $this->time;
}
public function setTime(?int $time): static
{
$this->time = $time;
return $this;
}
public function getNumber(): ?int
{
return $this->number;
}
public function setNumber(?int $number): static
{
$this->number = $number;
return $this;
}
public function incNumber(): static
{
$this->number++;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(?string $status): static
{
$this->status = $status;
return $this;
}
public function getResult(): ?string
{
return $this->result;
}
public function setResult(?string $result): static
{
$this->result = $result;
return $this;
}
public function getAttempt(): ?Attempt
{
return $this->attempt;
}
public function setAttempt(?Attempt $attempt): static
{
$this->attempt = $attempt;
return $this;
}
public function getBlock(): ?Block
{
return $this->block;
}
public function setBlock(?Block $block): static
{
$this->block = $block;
return $this;
}
/**
* @return Collection<int, Answer>|null
*/
public function getAnswers(): ?Collection
{
return $this->answers;
}
public function addAnswer(Answer $answer): self
{
if (!$this->answers->contains($answer)) {
$answer->setAttemptBlock($this);
$this->answers[] = $answer;
}
return $this;
}
public function removeAnswer(Answer $answer): self
{
if ($this->answers->contains($answer)) {
$this->answers->removeElement($answer);
}
return $this;
}
}