src/Entity/Workers.php line 13

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