src/Entity/Channel/Session.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Account\User;
  4. use App\Entity\Common\ImportableData\ImportableDataInterface;
  5. use App\Entity\Common\ImportableData\ImportableDataTrait;
  6. use App\Entity\Sync\SyncableInterface;
  7. use App\Repository\Channel\SessionRepository;
  8. use App\Validator\Constraints as AppAssert;
  9. use Doctrine\ORM\Mapping as ORM;
  10. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  11. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  12. use Nellapp\Bundle\SDKBundle\Channel\Entity\Session\SessionInterface;
  13. use Nellapp\Bundle\SDKBundle\Channel\Entity\Session\SessionMethodTrait;
  14. use Nellapp\Bundle\SDKBundle\Enum\Session\SessionStatusEnum;
  15. use Nellapp\Bundle\SDKBundle\Notification\Entity\NotifiableInterface;
  16. use Nellapp\Bundle\SDKBundle\Notification\Entity\NotifiableTrait;
  17. use Nellapp\Bundle\SDKBundle\Permission\Entity\ChannelResourceInterface;
  18. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  19. use Symfony\Component\Serializer\Annotation as Serial;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. #[
  22. ORM\Entity(repositoryClass: SessionRepository::class),
  23. ORM\Table(name: 'channel_sessions')
  24. ]
  25. class Session implements SyncableInterface, SessionInterface, ChannelResourceInterface, ImportableDataInterface, NotifiableInterface
  26. {
  27. use NotifiableTrait;
  28. use SessionMethodTrait;
  29. use ImportableDataTrait;
  30. #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
  31. #[Serial\Groups(['Manager', 'Sync'])]
  32. protected ?int $id = null;
  33. #[ORM\Column(type: 'datetime')]
  34. #[Assert\NotBlank(groups: ['Default', 'flow_sessionCreate_step1'])]
  35. #[Serial\Groups(['Manager', 'Sync'])]
  36. private ?\DateTimeInterface $startAt = null;
  37. #[ORM\Column(type: 'datetime', nullable: true)]
  38. #[
  39. Assert\GreaterThanOrEqual(propertyPath: 'startAt', message: 'channel.session.endAt.GreaterThan', groups: ['Default', 'flow_sessionCreate_step1']),
  40. AppAssert\DateWithinIntervalOf(reference: 'startAt', maxInterval: 'P5Y', message: 'channel.session.endAt.MaxDate', groups: ['Default', 'flow_sessionCreate_step1']),
  41. Assert\NotBlank(groups: ['Default', 'flow_sessionCreate_step1'])
  42. ]
  43. #[Serial\Groups(['Manager', 'Sync'])]
  44. private ?\DateTimeInterface $endAt = null;
  45. #[ORM\ManyToOne(targetEntity: Training::class, cascade: ['persist'])]
  46. #[IdGroups(groups: 'Sync')]
  47. #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  48. private ?Training $training = null;
  49. #[ORM\OneToOne(inversedBy: 'session', targetEntity: Group::class, cascade: ['persist', 'remove'])]
  50. #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  51. #[Assert\Valid(groups: ['Default', 'flow_sessionCreate_step1'])]
  52. #[IdGroups(groups: 'Sync')]
  53. #[Serial\Groups(['Manager'])]
  54. private ?Group $group = null;
  55. #[ORM\Column(type: 'text', length: 5000, nullable: true)]
  56. #[Assert\Length(max: 5000, maxMessage: 'channel.session.description.Length.max', groups: ['Default', 'flow_sessionCreate_step2'])]
  57. #[Serial\Groups(['Manager', 'Sync'])]
  58. private ?string $description = null;
  59. #[ORM\Column(type: 'boolean', options: ['default' => false])]
  60. #[Serial\Groups(['Sync'])]
  61. private bool $hasSignaturesDeactivated = false;
  62. #[ORM\Column(type: 'boolean', options: ['default' => true])]
  63. #[Serial\Groups(['Sync'])]
  64. private bool $hasCanalVisible = true;
  65. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])]
  66. #[
  67. Assert\GreaterThanOrEqual(value: 0, message: 'session.durationInCenter.GreaterThan', groups: ['Default', 'flow_sessionCreate_step2']),
  68. Assert\NotBlank(groups: ['Default', 'flow_sessionCreate_step2'])
  69. ]
  70. private int $durationInCenter = 0;
  71. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])]
  72. #[
  73. Assert\GreaterThanOrEqual(value: 0, message: 'session.durationInCompany.GreaterThan', groups: ['Default', 'flow_sessionCreate_step2']),
  74. Assert\NotBlank(groups: ['Default', 'flow_sessionCreate_step2'])
  75. ]
  76. private int $durationInCompany = 0;
  77. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])]
  78. #[
  79. Assert\GreaterThanOrEqual(value: 0, message: 'session.durationInVisio.GreaterThan', groups: ['Default', 'flow_sessionCreate_step2']),
  80. Assert\NotBlank(groups: ['Default', 'flow_sessionCreate_step2'])
  81. ]
  82. private int $durationInVisio = 0;
  83. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])]
  84. #[
  85. Assert\GreaterThanOrEqual(value: 0, message: 'session.durationInELearning.GreaterThan', groups: ['Default', 'flow_sessionCreate_step2']),
  86. Assert\NotBlank(groups: ['Default', 'flow_sessionCreate_step2'])
  87. ]
  88. private int $durationInELearning = 0;
  89. #[ORM\Column(type: 'integer', nullable: false, options: ['default' => 0])]
  90. #[
  91. Assert\GreaterThanOrEqual(value: 0, message: 'session.durationInExam.GreaterThan', groups: ['Default', 'flow_sessionCreate_step2']),
  92. Assert\NotBlank(groups: ['Default', 'flow_sessionCreate_step2'])
  93. ]
  94. private int $durationInExam = 0;
  95. public static function getPermissionResourceClass(): string
  96. {
  97. return ChannelUserSessionPermission::class;
  98. }
  99. public function getOwnerChannel(): ?ChannelInterface
  100. {
  101. return $this->getChannel();
  102. }
  103. public function getStatus(): string
  104. {
  105. $now = (new \DateTime())->setTime(0, 0, 0);
  106. if ($this->getStartAt() > $now) {
  107. return SessionStatusEnum::NOT_STARTED;
  108. } else if($this->getEndAt() < $now) {
  109. return SessionStatusEnum::FINISHED;
  110. }
  111. return SessionStatusEnum::RUNNING;
  112. }
  113. public function getPlace(): ?Place
  114. {
  115. return $this->getGroup()?->getPlace();
  116. }
  117. public static function getSyncKey(): string
  118. {
  119. return EntityKeys::CHANNEL_SESSION;
  120. }
  121. public function getSyncDisplayLabel(): string
  122. {
  123. return $this->getLabel() ?? '';
  124. }
  125. public function getDurationInCenter(): int
  126. {
  127. return $this->durationInCenter;
  128. }
  129. public function setDurationInCenter(int $durationInCenter): static
  130. {
  131. $this->durationInCenter = $durationInCenter;
  132. return $this;
  133. }
  134. public function getDurationInCompany(): int
  135. {
  136. return $this->durationInCompany;
  137. }
  138. public function setDurationInCompany(int $durationInCompany): static
  139. {
  140. $this->durationInCompany = $durationInCompany;
  141. return $this;
  142. }
  143. public function getDescription(): ?string
  144. {
  145. return $this->description;
  146. }
  147. public function setDescription(?string $description): self
  148. {
  149. $this->description = $description;
  150. return $this;
  151. }
  152. public function getUserIds(): array
  153. {
  154. if (null === $group = $this->getGroup()) {
  155. return [];
  156. }
  157. return $group->getUsers()->map(function (User $user) {
  158. return $user->getId();
  159. })->filter(function (?string $id) {
  160. return null !== $id;
  161. })->toArray();
  162. }
  163. public function getTraining(): ?Training
  164. {
  165. return $this->training;
  166. }
  167. public function setTraining(?Training $training): static
  168. {
  169. $this->training = $training;
  170. return $this;
  171. }
  172. public function getDurationInVisio(): int
  173. {
  174. return $this->durationInVisio;
  175. }
  176. public function setDurationInVisio(int $durationInVisio): static
  177. {
  178. $this->durationInVisio = $durationInVisio;
  179. return $this;
  180. }
  181. public function getDurationInELearning(): int
  182. {
  183. return $this->durationInELearning;
  184. }
  185. public function setDurationInELearning(int $durationInELearning): static
  186. {
  187. $this->durationInELearning = $durationInELearning;
  188. return $this;
  189. }
  190. public function getDurationInExam(): int
  191. {
  192. return $this->durationInExam;
  193. }
  194. public function setDurationInExam(int $durationInExam): static
  195. {
  196. $this->durationInExam = $durationInExam;
  197. return $this;
  198. }
  199. public function getTotalDuration(): int
  200. {
  201. return $this->durationInCenter + $this->durationInVisio + $this->durationInELearning + $this->durationInExam + $this->durationInCompany;
  202. }
  203. }