Party.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\PartyRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Symfony\Bridge\Doctrine\Types\UuidType;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. use Symfony\Component\Uid\Uuid;
  11. #[ORM\Entity(repositoryClass: PartyRepository::class)]
  12. class Party
  13. {
  14. #[ORM\Id]
  15. #[ORM\Column(type: UuidType::NAME, nullable: true)]
  16. #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  17. #[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
  18. private ?Uuid $id = null;
  19. #[ORM\ManyToOne(inversedBy: 'parties')]
  20. private ?Gamemaster $gamemaster = null;
  21. #[ORM\ManyToOne(inversedBy: 'parties')]
  22. private ?Game $game = null;
  23. /**
  24. * @var Collection<int, Slot>
  25. */
  26. #[ORM\OneToMany(targetEntity: Slot::class, mappedBy: 'party')]
  27. #[ORM\OrderBy(["startOn" => "ASC"])]
  28. private Collection $slots;
  29. #[ORM\ManyToOne(inversedBy: 'parties')]
  30. #[ORM\JoinColumn(nullable: false)]
  31. private ?Event $event = null;
  32. #[ORM\Column(nullable: true)]
  33. private ?\DateTime $startOn = null;
  34. #[ORM\Column(nullable: true)]
  35. private ?\DateTime $endOn = null;
  36. #[ORM\Column(nullable: true)]
  37. private ?bool $gamemasterIsAuthor = null;
  38. #[ORM\Column(nullable: true)]
  39. private ?int $minParticipants = null;
  40. #[ORM\Column(nullable: true)]
  41. private ?int $maxParticipants = null;
  42. #[ORM\Column(type: Types::TEXT, nullable: true)]
  43. private ?string $description = null;
  44. #[ORM\ManyToOne(inversedBy: 'submittedParties')]
  45. private ?User $submitter = null;
  46. #[ORM\Column(nullable: true)]
  47. private ?\DateTime $submittedDate = null;
  48. #[ORM\Column(nullable: true)]
  49. private ?bool $validated = null;
  50. /**
  51. * @var Collection<int, Participation>
  52. */
  53. #[ORM\OneToMany(targetEntity: Participation::class, mappedBy: 'party', orphanRemoval: true)]
  54. private Collection $participations;
  55. public function __construct()
  56. {
  57. $this->slots = new ArrayCollection();
  58. $this->participations = new ArrayCollection();
  59. }
  60. public function getId(): ?Uuid
  61. {
  62. return $this->id;
  63. }
  64. public function setId(Uuid $id): static
  65. {
  66. $this->id = $id;
  67. return $this;
  68. }
  69. public function getGamemaster(): ?Gamemaster
  70. {
  71. return $this->gamemaster;
  72. }
  73. public function setGamemaster(?Gamemaster $gamemaster): static
  74. {
  75. $this->gamemaster = $gamemaster;
  76. return $this;
  77. }
  78. public function getGame(): ?Game
  79. {
  80. return $this->game;
  81. }
  82. public function setGame(?Game $game): static
  83. {
  84. $this->game = $game;
  85. return $this;
  86. }
  87. /**
  88. * @return Collection<int, Slot>
  89. */
  90. public function getSlots(): Collection
  91. {
  92. return $this->slots;
  93. }
  94. public function addSlot(Slot $slot): static
  95. {
  96. if (!$this->slots->contains($slot)) {
  97. $this->slots->add($slot);
  98. $slot->setParty($this);
  99. }
  100. return $this;
  101. }
  102. public function removeSlot(Slot $slot): static
  103. {
  104. if ($this->slots->removeElement($slot)) {
  105. // set the owning side to null (unless already changed)
  106. if ($slot->getParty() === $this) {
  107. $slot->setParty(null);
  108. }
  109. }
  110. return $this;
  111. }
  112. public function purgeSlots(): static
  113. {
  114. foreach ($this->getSlots() as $slot) {
  115. $this->removeSlot($slot);
  116. }
  117. return $this;
  118. }
  119. public function getEvent(): ?Event
  120. {
  121. return $this->event;
  122. }
  123. public function setEvent(?Event $event): static
  124. {
  125. $this->event = $event;
  126. return $this;
  127. }
  128. public function getStartOn(): ?\DateTime
  129. {
  130. return $this->startOn;
  131. }
  132. public function setStartOn(?\DateTime $startOn): static
  133. {
  134. $this->startOn = $startOn;
  135. return $this;
  136. }
  137. public function getEndOn(): ?\DateTime
  138. {
  139. return $this->endOn;
  140. }
  141. public function setEndOn(?\DateTime $endOn): static
  142. {
  143. $this->endOn = $endOn;
  144. return $this;
  145. }
  146. public function isGamemasterIsAuthor(): ?bool
  147. {
  148. return $this->gamemasterIsAuthor;
  149. }
  150. public function setGamemasterIsAuthor(?bool $gamemasterIsAuthor): static
  151. {
  152. $this->gamemasterIsAuthor = $gamemasterIsAuthor;
  153. return $this;
  154. }
  155. public function getMinParticipants(): ?int
  156. {
  157. return $this->minParticipants;
  158. }
  159. public function setMinParticipants(?int $minParticipants): static
  160. {
  161. $this->minParticipants = $minParticipants;
  162. return $this;
  163. }
  164. public function getMaxParticipants(): ?int
  165. {
  166. return $this->maxParticipants;
  167. }
  168. public function setMaxParticipants(?int $maxParticipants): static
  169. {
  170. $this->maxParticipants = $maxParticipants;
  171. return $this;
  172. }
  173. public function getSeatsOccuped(): ?int
  174. {
  175. $seatsOccuped = count($this->getParticipations());
  176. return $seatsOccuped;
  177. }
  178. public function getSeatsLeft(): ?int
  179. {
  180. $seatsLeft = $this->maxParticipants - count($this->getParticipations());
  181. return $seatsLeft;
  182. }
  183. public function getDescription(): ?string
  184. {
  185. return $this->description;
  186. }
  187. public function setDescription(?string $description): static
  188. {
  189. $this->description = $description;
  190. return $this;
  191. }
  192. public function getSubmitter(): ?User
  193. {
  194. return $this->submitter;
  195. }
  196. public function setSubmitter(?User $submitter): static
  197. {
  198. $this->submitter = $submitter;
  199. return $this;
  200. }
  201. public function getSubmittedDate(): ?\DateTime
  202. {
  203. return $this->submittedDate;
  204. }
  205. public function setSubmittedDate(?\DateTime $submittedDate): static
  206. {
  207. $this->submittedDate = $submittedDate;
  208. return $this;
  209. }
  210. public function isValidated(): ?bool
  211. {
  212. return $this->validated;
  213. }
  214. public function setValidated(?bool $validated): static
  215. {
  216. $this->validated = $validated;
  217. return $this;
  218. }
  219. /**
  220. * @return Collection<int, Participation>
  221. */
  222. public function getParticipations(): Collection
  223. {
  224. return $this->participations;
  225. }
  226. public function addParticipation(Participation $participation): static
  227. {
  228. if (!$this->participations->contains($participation)) {
  229. $this->participations->add($participation);
  230. $participation->setParty($this);
  231. }
  232. return $this;
  233. }
  234. public function removeParticipation(Participation $participation): static
  235. {
  236. if ($this->participations->removeElement($participation)) {
  237. // set the owning side to null (unless already changed)
  238. if ($participation->getParty() === $this) {
  239. $participation->setParty(null);
  240. }
  241. }
  242. return $this;
  243. }
  244. }