Work.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Booking;
  4. use App\Entity\Core\File;
  5. use DH\Auditor\Provider\Doctrine\Auditing\Annotation\Auditable;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10. * Classe ... qui ...
  11. */
  12. #[Auditable]
  13. #[ORM\Entity]
  14. class Work
  15. {
  16. #[ORM\Id]
  17. #[ORM\Column]
  18. #[ORM\GeneratedValue]
  19. private ?int $id = null;
  20. #[ORM\ManyToOne(inversedBy: 'work')]
  21. private Course $course;
  22. #[ORM\OneToMany(mappedBy: 'work',targetEntity: WorkByUser::class, cascade: ['persist'], orphanRemoval: true)]
  23. private $workByUsers;
  24. #[ORM\OneToMany(mappedBy: 'work',targetEntity: File::class, orphanRemoval: true)]
  25. private $files;
  26. public function __construct()
  27. {
  28. $this->workByUsers = new ArrayCollection();
  29. $this->files = new ArrayCollection();
  30. }
  31. public function getId(): ?int
  32. {
  33. return $this->id;
  34. }
  35. public function getCourse(): ?Course
  36. {
  37. return $this->course;
  38. }
  39. public function setCourse(?Course $course): self
  40. {
  41. $this->course = $course;
  42. return $this;
  43. }
  44. /**
  45. * @return Collection<int, WorkByUser>
  46. */
  47. public function getWorkByUsers(): Collection
  48. {
  49. return $this->workByUsers;
  50. }
  51. public function addWorkByUser(WorkByUser $workByUser): self
  52. {
  53. if (!$this->workByUsers->contains($workByUser)) {
  54. $this->workByUsers[] = $workByUser;
  55. $workByUser->setWork($this);
  56. }
  57. return $this;
  58. }
  59. public function removeWorkByUser(WorkByUser $workByUser): self
  60. {
  61. if ($this->workByUsers->removeElement($workByUser)) {
  62. // set the owning side to null (unless already changed)
  63. if ($workByUser->getWork() === $this) {
  64. $workByUser->setWork(null);
  65. }
  66. }
  67. return $this;
  68. }
  69. /**
  70. * @return Collection<int, File>
  71. */
  72. public function getFiles(): Collection
  73. {
  74. return $this->files;
  75. }
  76. public function addFile(File $file): self
  77. {
  78. if (!$this->files->contains($file)) {
  79. $this->files[] = $file;
  80. $file->setWork($this);
  81. }
  82. return $this;
  83. }
  84. public function removeFile(File $file): self
  85. {
  86. if ($this->files->removeElement($file)) {
  87. // set the owning side to null (unless already changed)
  88. if ($file->getWork() === $this) {
  89. $file->setWork(null);
  90. }
  91. }
  92. return $this;
  93. }
  94. }