feat: add Game entity
This commit is contained in:
132
src/Entity/Game.php
Normal file
132
src/Entity/Game.php
Normal file
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Entity;
|
||||
|
||||
use App\Repository\GameRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
|
||||
#[ORM\Entity(repositoryClass: GameRepository::class)]
|
||||
class Game
|
||||
{
|
||||
public const string STATUS_IN_PROGRESS = 'in_progress';
|
||||
public const string STATUS_ABANDONED = 'abandoned';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
#[ORM\Column]
|
||||
private ?int $id = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: User::class)]
|
||||
#[ORM\JoinColumn(nullable: true)]
|
||||
private ?User $user = null;
|
||||
|
||||
#[ORM\ManyToOne(targetEntity: Actor::class)]
|
||||
#[ORM\JoinColumn(nullable: false)]
|
||||
private ?Actor $mainActor = null;
|
||||
|
||||
#[ORM\Column(length: 20)]
|
||||
private string $status = self::STATUS_IN_PROGRESS;
|
||||
|
||||
#[ORM\Column]
|
||||
private \DateTimeImmutable $startedAt;
|
||||
|
||||
#[ORM\Column(nullable: true)]
|
||||
private ?\DateTimeImmutable $endedAt = null;
|
||||
|
||||
/** @var Collection<int, GameRow> */
|
||||
#[ORM\OneToMany(targetEntity: GameRow::class, mappedBy: 'game', cascade: ['persist'], orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['rowOrder' => 'ASC'])]
|
||||
private Collection $rows;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->startedAt = new \DateTimeImmutable();
|
||||
$this->rows = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
}
|
||||
|
||||
public function setUser(?User $user): static
|
||||
{
|
||||
$this->user = $user;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getMainActor(): ?Actor
|
||||
{
|
||||
return $this->mainActor;
|
||||
}
|
||||
|
||||
public function setMainActor(Actor $mainActor): static
|
||||
{
|
||||
$this->mainActor = $mainActor;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(string $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getStartedAt(): \DateTimeImmutable
|
||||
{
|
||||
return $this->startedAt;
|
||||
}
|
||||
|
||||
public function getEndedAt(): ?\DateTimeImmutable
|
||||
{
|
||||
return $this->endedAt;
|
||||
}
|
||||
|
||||
public function setEndedAt(?\DateTimeImmutable $endedAt): static
|
||||
{
|
||||
$this->endedAt = $endedAt;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** @return Collection<int, GameRow> */
|
||||
public function getRows(): Collection
|
||||
{
|
||||
return $this->rows;
|
||||
}
|
||||
|
||||
public function addRow(GameRow $row): static
|
||||
{
|
||||
if (!$this->rows->contains($row)) {
|
||||
$this->rows->add($row);
|
||||
$row->setGame($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function abandon(): static
|
||||
{
|
||||
$this->status = self::STATUS_ABANDONED;
|
||||
$this->endedAt = new \DateTimeImmutable();
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user