GameParticipation.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\User;
  4. use ApiPlatform\Metadata\ApiResource;
  5. use Doctrine\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity]
  8. #[ORM\Table(name: 'game_participations')]
  9. #[ORM\UniqueConstraint(name: 'unique_user_game', columns: ['user_id', 'game_id'])]
  10. #[ApiResource]
  11. class GameParticipation
  12. {
  13. #[ORM\Id]
  14. #[ORM\GeneratedValue]
  15. #[ORM\Column]
  16. private ?int $id = null;
  17. #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'gameParticipations')]
  18. #[ORM\JoinColumn(nullable: false)]
  19. private User $user;
  20. #[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'gameParticipations')]
  21. #[ORM\JoinColumn(nullable: false)]
  22. private Game $game;
  23. #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
  24. private \DateTimeImmutable $joinedAt;
  25. #[ORM\Column(length: 20, nullable: false, options: ['default' => 'active'])]
  26. private string $status = 'active';
  27. #[ORM\Column(nullable: true)]
  28. private ?int $score = null;
  29. #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
  30. private ?\DateTimeImmutable $lastPlayedAt = null;
  31. public function __construct()
  32. {
  33. $this->joinedAt = new \DateTimeImmutable();
  34. }
  35. public function getId(): ?int
  36. {
  37. return $this->id;
  38. }
  39. public function getUser(): User
  40. {
  41. return $this->user;
  42. }
  43. public function setUser(User $user): self
  44. {
  45. $this->user = $user;
  46. return $this;
  47. }
  48. public function getGame(): Game
  49. {
  50. return $this->game;
  51. }
  52. public function setGame(Game $game): self
  53. {
  54. $this->game = $game;
  55. return $this;
  56. }
  57. public function getJoinedAt(): \DateTimeImmutable
  58. {
  59. return $this->joinedAt;
  60. }
  61. public function setJoinedAt(\DateTimeImmutable $joinedAt): self
  62. {
  63. $this->joinedAt = $joinedAt;
  64. return $this;
  65. }
  66. public function getStatus(): string
  67. {
  68. return $this->status;
  69. }
  70. public function setStatus(string $status): self
  71. {
  72. $this->status = $status;
  73. return $this;
  74. }
  75. public function getScore(): ?int
  76. {
  77. return $this->score;
  78. }
  79. public function setScore(?int $score): self
  80. {
  81. $this->score = $score;
  82. return $this;
  83. }
  84. public function getLastPlayedAt(): ?\DateTimeImmutable
  85. {
  86. return $this->lastPlayedAt;
  87. }
  88. public function setLastPlayedAt(?\DateTimeImmutable $lastPlayedAt): self
  89. {
  90. $this->lastPlayedAt = $lastPlayedAt;
  91. return $this;
  92. }
  93. }