160 lines
3.6 KiB
PHP
160 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Game\Entity;
|
|
|
|
use App\Game\Enum\SessionStatus;
|
|
use App\Game\Repository\SessionRepository;
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
use Doctrine\Common\Collections\Collection;
|
|
use Doctrine\DBAL\Types\Types;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
|
#[ORM\Entity(repositoryClass: SessionRepository::class)]
|
|
#[ORM\Table(name: 'session')]
|
|
class Session
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'sessions')]
|
|
#[ORM\JoinColumn(nullable: false)]
|
|
private ?Game $game = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 20, enumType: SessionStatus::class)]
|
|
private ?SessionStatus $status = null;
|
|
|
|
#[ORM\Column]
|
|
private ?int $timer = null;
|
|
|
|
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
|
|
private ?\DateTimeInterface $created = null;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'session', targetEntity: Player::class)]
|
|
private Collection $players;
|
|
|
|
#[ORM\OneToMany(mappedBy: 'session', targetEntity: SessionSetting::class)]
|
|
private Collection $settings;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->created = new \DateTime();
|
|
$this->players = new ArrayCollection();
|
|
$this->settings = new ArrayCollection();
|
|
}
|
|
|
|
public function getId(): ?int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function getGame(): ?Game
|
|
{
|
|
return $this->game;
|
|
}
|
|
|
|
public function setGame(?Game $game): static
|
|
{
|
|
$this->game = $game;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getStatus(): ?SessionStatus
|
|
{
|
|
return $this->status;
|
|
}
|
|
|
|
public function setStatus(SessionStatus $status): static
|
|
{
|
|
$this->status = $status;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getTimer(): ?int
|
|
{
|
|
return $this->timer;
|
|
}
|
|
|
|
public function setTimer(int $timer): static
|
|
{
|
|
$this->timer = $timer;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getCreated(): ?\DateTimeInterface
|
|
{
|
|
return $this->created;
|
|
}
|
|
|
|
public function setCreated(\DateTimeInterface $created): static
|
|
{
|
|
$this->created = $created;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, Player>
|
|
*/
|
|
public function getPlayers(): Collection
|
|
{
|
|
return $this->players;
|
|
}
|
|
|
|
public function addPlayer(Player $player): static
|
|
{
|
|
if (!$this->players->contains($player)) {
|
|
$this->players->add($player);
|
|
$player->setSession($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removePlayer(Player $player): static
|
|
{
|
|
if ($this->players->removeElement($player)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($player->getSession() === $this) {
|
|
$player->setSession(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, SessionSetting>
|
|
*/
|
|
public function getSettings(): Collection
|
|
{
|
|
return $this->settings;
|
|
}
|
|
|
|
public function addSetting(SessionSetting $setting): static
|
|
{
|
|
if (!$this->settings->contains($setting)) {
|
|
$this->settings->add($setting);
|
|
$setting->setSession($this);
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function removeSetting(SessionSetting $setting): static
|
|
{
|
|
if ($this->settings->removeElement($setting)) {
|
|
// set the owning side to null (unless already changed)
|
|
if ($setting->getSession() === $this) {
|
|
$setting->setSession(null);
|
|
}
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
}
|