|
|
@@ -0,0 +1,116 @@
|
|
|
+<?php
|
|
|
+declare(strict_types=1);
|
|
|
+
|
|
|
+namespace App\Entity\User;
|
|
|
+
|
|
|
+use ApiPlatform\Metadata\ApiResource;
|
|
|
+use Doctrine\DBAL\Types\Types;
|
|
|
+use Doctrine\ORM\Mapping as ORM;
|
|
|
+
|
|
|
+#[ORM\Entity]
|
|
|
+#[ORM\Table(name: 'game_participations')]
|
|
|
+#[ORM\UniqueConstraint(name: 'unique_user_game', columns: ['user_id', 'game_id'])]
|
|
|
+#[ApiResource]
|
|
|
+class GameParticipation
|
|
|
+{
|
|
|
+ #[ORM\Id]
|
|
|
+ #[ORM\GeneratedValue]
|
|
|
+ #[ORM\Column]
|
|
|
+ private ?int $id = null;
|
|
|
+
|
|
|
+ #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'gameParticipations')]
|
|
|
+ #[ORM\JoinColumn(nullable: false)]
|
|
|
+ private User $user;
|
|
|
+
|
|
|
+ #[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'gameParticipations')]
|
|
|
+ #[ORM\JoinColumn(nullable: false)]
|
|
|
+ private Game $game;
|
|
|
+
|
|
|
+ #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
|
|
|
+ private \DateTimeImmutable $joinedAt;
|
|
|
+
|
|
|
+ #[ORM\Column(length: 20, nullable: false, options: ['default' => 'active'])]
|
|
|
+ private string $status = 'active';
|
|
|
+
|
|
|
+ #[ORM\Column(nullable: true)]
|
|
|
+ private ?int $score = null;
|
|
|
+
|
|
|
+ #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
|
|
|
+ private ?\DateTimeImmutable $lastPlayedAt = null;
|
|
|
+
|
|
|
+ public function __construct()
|
|
|
+ {
|
|
|
+ $this->joinedAt = new \DateTimeImmutable();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getId(): ?int
|
|
|
+ {
|
|
|
+ return $this->id;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getUser(): User
|
|
|
+ {
|
|
|
+ return $this->user;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setUser(User $user): self
|
|
|
+ {
|
|
|
+ $this->user = $user;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getGame(): Game
|
|
|
+ {
|
|
|
+ return $this->game;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setGame(Game $game): self
|
|
|
+ {
|
|
|
+ $this->game = $game;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getJoinedAt(): \DateTimeImmutable
|
|
|
+ {
|
|
|
+ return $this->joinedAt;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setJoinedAt(\DateTimeImmutable $joinedAt): self
|
|
|
+ {
|
|
|
+ $this->joinedAt = $joinedAt;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getStatus(): string
|
|
|
+ {
|
|
|
+ return $this->status;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setStatus(string $status): self
|
|
|
+ {
|
|
|
+ $this->status = $status;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getScore(): ?int
|
|
|
+ {
|
|
|
+ return $this->score;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setScore(?int $score): self
|
|
|
+ {
|
|
|
+ $this->score = $score;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getLastPlayedAt(): ?\DateTimeImmutable
|
|
|
+ {
|
|
|
+ return $this->lastPlayedAt;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function setLastPlayedAt(?\DateTimeImmutable $lastPlayedAt): self
|
|
|
+ {
|
|
|
+ $this->lastPlayedAt = $lastPlayedAt;
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+}
|