Work.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <?php
  2. namespace AppBundle\Entity\Booking;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Dunglas\ApiBundle\Annotation\Iri;
  6. use Symfony\Component\Serializer\Annotation\Groups;
  7. use AppBundle\Entity\Traits\TimestampableEntity;
  8. use AppBundle\Entity\Traits\CreatorUpdaterEntity;
  9. use Symfony\Component\Validator\Constraints as Assert;
  10. /**
  11. *
  12. * Travail à faire pour un cours
  13. *
  14. * @Iri("http://schema.org/Work")
  15. */
  16. #[ORM\Entity]
  17. class Work
  18. {
  19. use TimestampableEntity;
  20. use CreatorUpdaterEntity;
  21. /**
  22. * @var int
  23. */
  24. #[ORM\Column(type: 'integer')]
  25. #[ORM\Id]
  26. #[ORM\GeneratedValue(strategy: 'AUTO')]
  27. #[Groups(['work', 'worksbyusers_db'])]
  28. private $id;
  29. /**
  30. * @var Course
  31. */
  32. #[ORM\ManyToOne(targetEntity: 'Course', inversedBy: 'work')]
  33. #[Groups(['work', 'worksbyusers_db_work'])]
  34. private $course;
  35. /**
  36. * @var \DateTime
  37. */
  38. #[ORM\Column(type: 'datetime')]
  39. #[Assert\DateTime]
  40. #[Assert\NotNull]
  41. #[Groups(['work', 'worksbyusers_db_work'])]
  42. private $datetime;
  43. /**
  44. * @var string
  45. */
  46. #[ORM\Column(type: 'text', nullable: true)]
  47. #[Assert\Type(type: 'string')]
  48. #[Groups(['work', 'worksbyusers_db_work'])]
  49. private $work;
  50. /**
  51. * @var ArrayCollection<WorkByUser>
  52. */
  53. #[Assert\Valid]
  54. #[ORM\OneToMany(targetEntity: 'WorkByUser', mappedBy: 'work', cascade: ['persist'], orphanRemoval: true)]
  55. #[Groups(['work'])]
  56. private $workByUsers;
  57. /**
  58. * @var ArrayCollection<AppBundle\Entity\Core\File>.
  59. */
  60. #[ORM\OneToMany(targetEntity: 'AppBundle\Entity\Core\File', mappedBy: 'work', orphanRemoval: true)]
  61. #[Groups(['work', 'worksbyusers_db_work'])]
  62. private $files;
  63. public function __construct()
  64. {
  65. $this->workByUsers = new ArrayCollection();
  66. $this->files = new ArrayCollection();
  67. }
  68. /**
  69. * Sets id.
  70. *
  71. * @param int $id
  72. *
  73. * @return $this
  74. */
  75. public function setId($id)
  76. {
  77. $this->id = $id;
  78. return $this;
  79. }
  80. /**
  81. * Gets id.
  82. *
  83. * @return int
  84. */
  85. public function getId()
  86. {
  87. return $this->id;
  88. }
  89. /**
  90. * Sets course.
  91. *
  92. * @param Course $course
  93. *
  94. * @return $this
  95. */
  96. public function setCourse(Course $course = null)
  97. {
  98. $this->course = $course;
  99. return $this;
  100. }
  101. /**
  102. * Gets course.
  103. *
  104. * @return Course
  105. */
  106. public function getCourse()
  107. {
  108. return $this->course;
  109. }
  110. /**
  111. * Sets datetime.
  112. *
  113. * @param \DateTime $datetime
  114. *
  115. * @return $this
  116. */
  117. public function setDatetime(\DateTime $datetime)
  118. {
  119. $datetime->setTime($datetime->format("H"), $datetime->format("i"), 0);
  120. $datetime->setTimezone(new \DateTimeZone('UTC'));
  121. $this->datetime = $datetime;
  122. return $this;
  123. }
  124. /**
  125. * Gets datetime.
  126. *
  127. * @return \DateTime
  128. */
  129. public function getDatetime()
  130. {
  131. return $this->datetime;
  132. }
  133. /**
  134. * Sets works.
  135. *
  136. * @param string $work
  137. *
  138. * @return $this
  139. */
  140. public function setWork($work)
  141. {
  142. $this->work = $work;
  143. return $this;
  144. }
  145. /**
  146. * Gets work.
  147. *
  148. * @return string
  149. */
  150. public function getWork()
  151. {
  152. return $this->work;
  153. }
  154. /**
  155. * Add work By User
  156. *
  157. * @param WorkByUser $workByUSer
  158. *
  159. * @return Work
  160. */
  161. public function addWorkByUser(WorkByUser $workByUSer)
  162. {
  163. $workByUSer->setWork($this);
  164. $this->workByUsers[] = $workByUSer;
  165. return $this;
  166. }
  167. /**
  168. * Remove work By User
  169. *
  170. * @param WorkByUser $workByUSer
  171. */
  172. public function removeWorkByUser(WorkByUser $workByUSer)
  173. {
  174. $this->workByUsers->removeElement($workByUSer);
  175. }
  176. /**
  177. * Get work By User
  178. *
  179. * @return \Doctrine\Common\Collections\Collection
  180. */
  181. public function getWorkByUsers()
  182. {
  183. return $this->workByUsers;
  184. }
  185. /**
  186. * Add file
  187. *
  188. * @param \AppBundle\Entity\Core\File $file
  189. *
  190. * @return Work
  191. */
  192. public function addFile(\AppBundle\Entity\Core\File $file)
  193. {
  194. $file->setWork($this);
  195. $this->files[] = $file;
  196. return $this;
  197. }
  198. /**
  199. * Remove file
  200. *
  201. * @param \AppBundle\Entity\Core\File $file
  202. */
  203. public function removeFile(\AppBundle\Entity\Core\File $file)
  204. {
  205. $this->files->removeElement($file);
  206. }
  207. /**
  208. * Get files
  209. *
  210. * @return \Doctrine\Common\Collections\Collection
  211. */
  212. public function getFiles()
  213. {
  214. return $this->files;
  215. }
  216. }