src/Entity/Workers.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\WorkersRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: WorkersRepository::class)]
  8. class Workers
  9. {
  10. #[ORM\Id]
  11. #[ORM\GeneratedValue]
  12. #[ORM\Column(type: 'integer')]
  13. private $id;
  14. #[ORM\Column(type: 'string', length: 255, nullable: true)]
  15. private $username;
  16. #[ORM\Column(type: 'string', length: 255)]
  17. private $full_name;
  18. #[ORM\Column(type: 'integer', nullable: true)]
  19. private $price_hour;
  20. #[ORM\Column(type: 'integer', nullable: true)]
  21. private $price_month;
  22. #[ORM\Column(type: 'datetime', nullable: true)]
  23. private $created;
  24. #[ORM\OneToMany(targetEntity: WorkHours::class, mappedBy: 'worker', cascade: ['persist'])]
  25. private $workhours;
  26. #[ORM\OneToOne(targetEntity: User::class, mappedBy: 'worker', cascade: ['persist', 'remove'])]
  27. private $user;
  28. #[ORM\ManyToMany(targetEntity: Projects::class, mappedBy: 'workers')]
  29. private $projects;
  30. #[ORM\Column(type: 'boolean')]
  31. private $active;
  32. #[ORM\Column(type: 'integer', nullable: true)]
  33. private $contribution;
  34. public function __construct()
  35. {
  36. $this->workhours = new ArrayCollection();
  37. $this->created = new \DateTime();
  38. $this->projects = new ArrayCollection();
  39. }
  40. public function getId(): ?int
  41. {
  42. return $this->id;
  43. }
  44. public function getUsername(): ?string
  45. {
  46. return $this->username;
  47. }
  48. public function setUsername(string $username): self
  49. {
  50. $this->username = $username;
  51. return $this;
  52. }
  53. public function getFullName(): ?string
  54. {
  55. return $this->full_name;
  56. }
  57. public function setFullName(string $full_name): self
  58. {
  59. $this->full_name = $full_name;
  60. return $this;
  61. }
  62. public function getPriceHour(): ?int
  63. {
  64. return $this->price_hour;
  65. }
  66. public function setPriceHour(?int $price_hour): self
  67. {
  68. $this->price_hour = $price_hour;
  69. return $this;
  70. }
  71. public function getPriceMonth(): ?int
  72. {
  73. return $this->price_month;
  74. }
  75. public function setPriceMonth(?int $price_month): self
  76. {
  77. $this->price_month = $price_month;
  78. return $this;
  79. }
  80. public function getCreated(): ?\DateTimeInterface
  81. {
  82. return $this->created;
  83. }
  84. public function setCreated(?\DateTimeInterface $created): self
  85. {
  86. $this->created = $created;
  87. return $this;
  88. }
  89. /**
  90. * @return Collection|WorkHours[]
  91. */
  92. public function getWorkHours(): Collection
  93. {
  94. return new ArrayCollection();
  95. }
  96. /**
  97. * @return Collection|WorkHours[]
  98. */
  99. public function getWorkHoursAll(): Collection
  100. {
  101. return $this->workhours;
  102. }
  103. public function addWorkHour(WorkHours $workhour): self
  104. {
  105. $workhour->setWorker($this);
  106. if (!$this->workhours->contains($workhour)) {
  107. $this->workhours[] = $workhour;
  108. $workhour->setWorker($this);
  109. }
  110. return $this;
  111. }
  112. public function removeWorkHour(WorkHours $workhour): self
  113. {
  114. $workhour->setWorker($this);
  115. if ($this->workhours->removeElement($workhour)) {
  116. // set the owning side to null (unless already changed)
  117. if ($workhour->getWorker() === $this) {
  118. $workhour->setWorker(null);
  119. }
  120. }
  121. return $this;
  122. }
  123. public function __toString()
  124. {
  125. return $this->full_name;
  126. }
  127. public function getUser(): ?User
  128. {
  129. return $this->user;
  130. }
  131. public function setUser(?User $user): self
  132. {
  133. // unset the owning side of the relation if necessary
  134. if ($user === null && $this->user !== null) {
  135. $this->user->setWorker(null);
  136. }
  137. // set the owning side of the relation if necessary
  138. if ($user !== null && $user->getWorker() !== $this) {
  139. $user->setWorker($this);
  140. }
  141. $this->user = $user;
  142. return $this;
  143. }
  144. /**
  145. * @return Collection|Projects[]
  146. */
  147. public function getProjects(): Collection
  148. {
  149. return $this->projects;
  150. }
  151. public function addProject(Projects $project): self
  152. {
  153. if (!$this->projects->contains($project)) {
  154. $this->projects[] = $project;
  155. $project->addWorker($this);
  156. }
  157. return $this;
  158. }
  159. public function removeProject(Projects $project): self
  160. {
  161. if ($this->projects->removeElement($project)) {
  162. $project->removeWorker($this);
  163. }
  164. return $this;
  165. }
  166. public function getActive(): ?bool
  167. {
  168. return $this->active;
  169. }
  170. public function setActive(bool $active): self
  171. {
  172. $this->active = $active;
  173. return $this;
  174. }
  175. public function getContribution(): ?int
  176. {
  177. return $this->contribution;
  178. }
  179. public function setContribution(?int $contribution): self
  180. {
  181. $this->contribution = $contribution;
  182. return $this;
  183. }
  184. }