|
|
@@ -1,13 +1,14 @@
|
|
|
<?php
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
-namespace App\Entity\User;
|
|
|
+namespace App\Entity;
|
|
|
|
|
|
use ApiPlatform\Metadata\ApiResource;
|
|
|
+use App\Enum\GameStatusEnum;
|
|
|
use Doctrine\Common\Collections\ArrayCollection;
|
|
|
use Doctrine\Common\Collections\Collection;
|
|
|
+use Doctrine\DBAL\Types\Types;
|
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
|
-use Symfony\Component\Validator\Constraints as Assert;
|
|
|
|
|
|
#[ORM\Entity]
|
|
|
#[ApiResource]
|
|
|
@@ -21,12 +22,21 @@ class Game
|
|
|
#[ORM\Column(length: 100, unique: true, nullable: false)]
|
|
|
private string $name;
|
|
|
|
|
|
- #[ORM\OneToMany(targetEntity: GameParticipation::class, mappedBy: 'game', cascade: ['persist', 'remove'])]
|
|
|
- private Collection $gameParticipations;
|
|
|
+ #[ORM\OneToMany(targetEntity: Player::class, mappedBy: 'game', cascade: ['persist', 'remove'])]
|
|
|
+ private Collection $players;
|
|
|
+
|
|
|
+ #[ORM\OneToOne(targetEntity: Galaxy::class, mappedBy: 'game', cascade: ['persist', 'remove'])]
|
|
|
+ private ?Galaxy $galaxy = null;
|
|
|
+
|
|
|
+ #[ORM\Column(length: 24, enumType: GameStatusEnum::class, options: ['default' => GameStatusEnum::DRAFT])]
|
|
|
+ private GameStatusEnum $status = GameStatusEnum::DRAFT;
|
|
|
+
|
|
|
+ #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
|
|
|
+ private ?\DateTimeImmutable $openedAt = null;
|
|
|
|
|
|
public function __construct()
|
|
|
{
|
|
|
- $this->gameParticipations = new ArrayCollection();
|
|
|
+ $this->players = new ArrayCollection();
|
|
|
}
|
|
|
|
|
|
public function getId(): ?int
|
|
|
@@ -51,24 +61,57 @@ class Game
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- public function getGameParticipations(): Collection
|
|
|
+ public function getPlayers(): Collection
|
|
|
{
|
|
|
- return $this->gameParticipations;
|
|
|
+ return $this->players;
|
|
|
}
|
|
|
|
|
|
- public function addGameParticipation(GameParticipation $gameParticipation): self
|
|
|
+ public function addPlayer(Player $player): self
|
|
|
{
|
|
|
- if (!$this->gameParticipations->contains($gameParticipation)) {
|
|
|
- $this->gameParticipations->add($gameParticipation);
|
|
|
- $gameParticipation->setGame($this);
|
|
|
+ if (!$this->players->contains($player)) {
|
|
|
+ $this->players->add($player);
|
|
|
+ $player->setGame($this);
|
|
|
}
|
|
|
|
|
|
return $this;
|
|
|
}
|
|
|
|
|
|
- public function removeGameParticipation(GameParticipation $gameParticipation): self
|
|
|
+ public function removePlayer(Player $player): self
|
|
|
+ {
|
|
|
+ $this->players->removeElement($player);
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getGalaxy(): ?Galaxy
|
|
|
+ {
|
|
|
+ return $this->galaxy;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setGalaxy(?Galaxy $galaxy): self
|
|
|
+ {
|
|
|
+ $this->galaxy = $galaxy;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getOpenedAt(): ?\DateTimeImmutable
|
|
|
+ {
|
|
|
+ return $this->openedAt;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setOpenedAt(?\DateTimeImmutable $openedAt): self
|
|
|
+ {
|
|
|
+ $this->openedAt = $openedAt;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getStatus(): GameStatusEnum
|
|
|
+ {
|
|
|
+ return $this->status;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setStatus(GameStatusEnum $status): self
|
|
|
{
|
|
|
- $this->gameParticipations->removeElement($gameParticipation);
|
|
|
+ $this->status = $status;
|
|
|
return $this;
|
|
|
}
|
|
|
}
|