src/Entity/GroupSession.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\Common\Collections\Collection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Symfony\Component\Serializer\Annotation\Groups;
  6. /**
  7. * GroupSession
  8. *
  9. * @ORM\Table(name="group_session")
  10. * @ORM\Entity(repositoryClass="App\Repository\GroupSessionRepository")
  11. */
  12. class GroupSession
  13. {
  14. /**
  15. * @var int
  16. *
  17. * @ORM\Column(name="id", type="integer", nullable=false)
  18. * @ORM\Id
  19. * @ORM\GeneratedValue(strategy="IDENTITY")
  20. * @Groups({"agenda-api"})
  21. */
  22. private $id;
  23. /**
  24. * @var string|null
  25. * @Groups({"agenda-api"})
  26. *
  27. * @ORM\Column(name="title", type="string", length=255, nullable=true, options={"default"="NULL"})
  28. */
  29. private $title;
  30. /**
  31. * @var string|null
  32. *
  33. * @ORM\Column(name="picture", type="string", length=255, nullable=true, options={"default"="NULL"})
  34. */
  35. private $picture;
  36. /**
  37. * @var \DateTime|null
  38. *
  39. * @ORM\Column(name="start_date", type="datetime", nullable=true, options={"default"="NULL"})
  40. */
  41. private $startDate;
  42. /**
  43. * @var \DateTime|null
  44. *
  45. * @ORM\Column(name="end_date", type="datetime", nullable=true, options={"default"="NULL"})
  46. */
  47. private $endDate;
  48. /**
  49. * @var string|null
  50. *
  51. * @ORM\Column(name="description", type="string", length=65535, nullable=true, options={"default"="NULL"})
  52. */
  53. private $description;
  54. /**
  55. * @var string|null
  56. *
  57. * @ORM\Column(name="url", type="string", length=65535, nullable=true, options={"default"="NULL"})
  58. */
  59. private $url;
  60. /**
  61. * @var float|null
  62. *
  63. * @ORM\Column(name="price", type="float", precision=10, scale=0, nullable=true, options={"default"="NULL"})
  64. */
  65. private $price;
  66. /**
  67. * @var int|null
  68. *
  69. * @ORM\Column(name="group_max", type="integer", nullable=true)
  70. */
  71. private $groupMax;
  72. /**
  73. * @var string|null
  74. *
  75. * @ORM\Column(name="location", type="string", length=255, nullable=true, options={"default"="NULL"})
  76. */
  77. private $location;
  78. /**
  79. * @var bool|null
  80. *
  81. * @ORM\Column(name="open", type="boolean", nullable=true, options={"default"="NULL"})
  82. */
  83. private $open = true;
  84. /**
  85. * @var Partner|null
  86. *
  87. * @ORM\ManyToOne(targetEntity="Partner")
  88. * @ORM\JoinColumns({
  89. * @ORM\JoinColumn(name="partner_id", referencedColumnName="id")
  90. * })
  91. */
  92. private $partner;
  93. /**
  94. * @var Collection
  95. *
  96. * @ORM\OneToMany(targetEntity="Reservation", mappedBy="groupSession")
  97. */
  98. private $reservations;
  99. /**
  100. * @return int
  101. */
  102. public function getId(): int
  103. {
  104. return $this->id;
  105. }
  106. /**
  107. * @param int $id
  108. */
  109. public function setId(int $id): void
  110. {
  111. $this->id = $id;
  112. }
  113. /**
  114. * @return string|null
  115. */
  116. public function getTitle(): ?string
  117. {
  118. return $this->title;
  119. }
  120. /**
  121. * @param string|null $title
  122. */
  123. public function setTitle(?string $title): void
  124. {
  125. $this->title = $title;
  126. }
  127. /**
  128. * @return string|null
  129. */
  130. public function getPicture(): ?string
  131. {
  132. return $this->picture;
  133. }
  134. /**
  135. * @param string|null $picture
  136. */
  137. public function setPicture(?string $picture): void
  138. {
  139. $this->picture = $picture;
  140. }
  141. /**
  142. * @return \DateTime|null
  143. */
  144. public function getStartDate(): ?\DateTime
  145. {
  146. return $this->startDate;
  147. }
  148. /**
  149. * @param \DateTime|null $startDate
  150. */
  151. public function setStartDate(?\DateTime $startDate): void
  152. {
  153. $this->startDate = $startDate;
  154. }
  155. /**
  156. * @return \DateTime|null
  157. */
  158. public function getEndDate(): ?\DateTime
  159. {
  160. return $this->endDate;
  161. }
  162. /**
  163. * @param \DateTime|null $endDate
  164. */
  165. public function setEndDate(?\DateTime $endDate): void
  166. {
  167. $this->endDate = $endDate;
  168. }
  169. /**
  170. * @return string|null
  171. */
  172. public function getDescription(): ?string
  173. {
  174. return $this->description;
  175. }
  176. /**
  177. * @param string|null $description
  178. */
  179. public function setDescription(?string $description): void
  180. {
  181. $this->description = $description;
  182. }
  183. /**
  184. * @return string|null
  185. */
  186. public function getUrl(): ?string
  187. {
  188. return $this->url;
  189. }
  190. /**
  191. * @param string|null $url
  192. */
  193. public function setUrl(?string $url): void
  194. {
  195. $this->url = $url;
  196. }
  197. /**
  198. * @return float|null
  199. */
  200. public function getPrice(): ?float
  201. {
  202. return $this->price;
  203. }
  204. /**
  205. * @param float|null $price
  206. */
  207. public function setPrice(?float $price): void
  208. {
  209. $this->price = $price;
  210. }
  211. /**
  212. * @return int|null
  213. */
  214. public function getGroupMax(): ?int
  215. {
  216. return $this->groupMax;
  217. }
  218. /**
  219. * @param int|null $groupMax
  220. */
  221. public function setGroupMax(?int $groupMax): void
  222. {
  223. $this->groupMax = $groupMax;
  224. }
  225. /**
  226. * @return string|null
  227. */
  228. public function getLocation(): ?string
  229. {
  230. return $this->location;
  231. }
  232. /**
  233. * @param string|null $location
  234. */
  235. public function setLocation(?string $location): void
  236. {
  237. $this->location = $location;
  238. }
  239. /**
  240. * @return bool|null
  241. */
  242. public function getOpen(): ?bool
  243. {
  244. return $this->open;
  245. }
  246. /**
  247. * @param bool|null $open
  248. */
  249. public function setOpen(?bool $open): void
  250. {
  251. $this->open = $open;
  252. }
  253. /**
  254. * @return Partner|null
  255. */
  256. public function getPartner(): ?Partner
  257. {
  258. return $this->partner;
  259. }
  260. /**
  261. * @param Partner|null $partner
  262. */
  263. public function setPartner(?Partner $partner): void
  264. {
  265. $this->partner = $partner;
  266. }
  267. /**
  268. * @return Collection|null
  269. */
  270. public function getReservations(): ?Collection
  271. {
  272. return $this->reservations;
  273. }
  274. /**
  275. * @param Collection|null $reservations
  276. */
  277. public function setReservations(?Collection $reservations): void
  278. {
  279. $this->reservations = $reservations;
  280. }
  281. public function getReservationsWithoutCanceled()
  282. {
  283. if ($this->getReservations()) {
  284. return $this->getReservations()->filter(function (Reservation $reservation) {
  285. return $reservation->getCancelationDate() == null && !$reservation->getAbsent();
  286. });
  287. }
  288. return [];
  289. }
  290. public function getNbReservations(): int
  291. {
  292. return count($this->getReservationsWithoutCanceled());
  293. }
  294. public function hasReservation(): bool
  295. {
  296. return $this->getNbReservations() > 0;
  297. }
  298. public function availablePlaces()
  299. {
  300. if ($this->getGroupMax()) {
  301. return $this->getGroupMax() - $this->getNbReservations();
  302. }
  303. return null;
  304. }
  305. public function isReservable(): bool
  306. {
  307. if (!$this->getOpen()) {
  308. return false;
  309. }
  310. if ($this->getGroupMax()) {
  311. return $this->availablePlaces() > 0;
  312. }
  313. return true;
  314. }
  315. }