142 lines
3.1 KiB
PHP
142 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\Game\Entity;
|
|
|
|
use App\Game\Enum\GameStatus;
|
|
use App\Game\Repository\GameRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: GameRepository::class)]
|
|
#[ORM\Table(name: 'game')]
|
|
class Game
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(length: 255)]
|
|
private ?string $name = null;
|
|
|
|
#[ORM\Column]
|
|
private ?int $numberOfPlayers = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 20, enumType: GameStatus::class)]
|
|
private ?GameStatus $status = null;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'game', targetEntity: Session::class)]
|
|
private Collection $sessions;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'game', targetEntity: GameSetting::class)]
|
|
private Collection $settings;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->sessions = new ArrayCollection();
|
|
$this->settings = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getName(): ?string
|
|
{
|
|
return $this->name;
|
|
}
|
|
|
|
public function setName(string $name): static
|
|
{
|
|
$this->name = $name;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getNumberOfPlayers(): ?int
|
|
{
|
|
return $this->numberOfPlayers;
|
|
}
|
|
|
|
public function setNumberOfPlayers(int $numberOfPlayers): static
|
|
{
|
|
$this->numberOfPlayers = $numberOfPlayers;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getStatus(): ?GameStatus
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
public function setStatus(GameStatus $status): static
|
|
{
|
|
$this->status = $status;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Session>
|
|
*/
|
|
public function getSessions(): Collection
|
|
{
|
|
return $this->sessions;
|
|
}
|
|
|
|
public function addSession(Session $session): static
|
|
{
|
|
if (!$this->sessions->contains($session)) {
|
|
$this->sessions->add($session);
|
|
$session->setGame($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeSession(Session $session): static
|
|
{
|
|
if ($this->sessions->removeElement($session)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($session->getGame() === $this) {
|
|
$session->setGame(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, GameSetting>
|
|
*/
|
|
public function getSettings(): Collection
|
|
{
|
|
return $this->settings;
|
|
}
|
|
|
|
public function addSetting(GameSetting $setting): static
|
|
{
|
|
if (!$this->settings->contains($setting)) {
|
|
$this->settings->add($setting);
|
|
$setting->setGame($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeSetting(GameSetting $setting): static
|
|
{
|
|
if ($this->settings->removeElement($setting)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($setting->getGame() === $this) {
|
|
$setting->setGame(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|