src/Entity/Projects.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ProjectsRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClass: ProjectsRepository::class)]
  8. class Projects
  9. {
  10. #[ORM\Id]
  11. #[ORM\GeneratedValue]
  12. #[ORM\Column(type: 'integer')]
  13. private $id;
  14. #[ORM\Column(type: 'string', length: 255)]
  15. private $name;
  16. #[ORM\Column(type: 'date', nullable: true)]
  17. private $deadline;
  18. #[ORM\Column(type: 'date', nullable: true)]
  19. private $closed;
  20. #[ORM\Column(type: 'datetime', nullable: true)]
  21. private $created;
  22. #[ORM\ManyToOne(targetEntity: Customers::class, inversedBy: 'projects')]
  23. private $customer;
  24. #[ORM\OneToMany(targetEntity: WorkHours::class, mappedBy: 'project')]
  25. private $workHours;
  26. #[ORM\OneToMany(targetEntity: ProjectProducts::class, mappedBy: 'project')]
  27. private $projectProducts;
  28. #[ORM\OneToMany(targetEntity: Attachment::class, mappedBy: 'project', cascade: ['persist'], orphanRemoval: true)]
  29. private $attachments;
  30. #[ORM\OneToMany(targetEntity: Photo::class, mappedBy: 'project', cascade: ['persist'], orphanRemoval: true)]
  31. private $photos;
  32. #[ORM\OneToMany(targetEntity: Material::class, mappedBy: 'project')]
  33. private $materials;
  34. #[ORM\Column(type: 'text', nullable: true)]
  35. private $description;
  36. #[ORM\Column(type: 'integer', nullable: true)]
  37. private $priceNetto;
  38. #[ORM\ManyToMany(targetEntity: Workers::class, inversedBy: 'projects')]
  39. private $workers;
  40. #[ORM\Column(type: 'boolean', nullable: true)]
  41. private $isClosed;
  42. public function __construct()
  43. {
  44. $this->workHours = new ArrayCollection();
  45. $this->projectProducts = new ArrayCollection();
  46. $this->created = new \DateTime();
  47. $this->attachments = new ArrayCollection();
  48. $this->photos = new ArrayCollection();
  49. $this->materials = new ArrayCollection();
  50. $this->workers = new ArrayCollection();
  51. }
  52. public function getId(): ?int
  53. {
  54. return $this->id;
  55. }
  56. public function getName(): ?string
  57. {
  58. return $this->name;
  59. }
  60. public function setName(string $name): self
  61. {
  62. $this->name = $name;
  63. return $this;
  64. }
  65. public function getDeadline(): ?\DateTimeInterface
  66. {
  67. return $this->deadline;
  68. }
  69. public function setDeadline(?\DateTimeInterface $deadline): self
  70. {
  71. $this->deadline = $deadline;
  72. return $this;
  73. }
  74. public function getClosed(): ?\DateTimeInterface
  75. {
  76. return $this->closed;
  77. }
  78. public function setClosed(?\DateTimeInterface $closed): self
  79. {
  80. $this->closed = $closed;
  81. return $this;
  82. }
  83. public function getCreated(): ?\DateTimeInterface
  84. {
  85. return $this->created;
  86. }
  87. public function setCreated(?\DateTimeInterface $created): self
  88. {
  89. $this->created = $created;
  90. return $this;
  91. }
  92. public function getCustomer(): ?Customers
  93. {
  94. return $this->customer;
  95. }
  96. public function setCustomer(?Customers $customer): self
  97. {
  98. $this->customer = $customer;
  99. return $this;
  100. }
  101. /**
  102. * @return Collection|WorkHours[]
  103. */
  104. public function getWorkHoursSum()
  105. {
  106. $sum = 0;
  107. foreach ($this->workHours as $key => $value) {
  108. $sum += $value->getHours();
  109. }
  110. return $sum;
  111. }
  112. /**
  113. * @return Collection|WorkHours[]
  114. */
  115. public function getWorkHours(): Collection
  116. {
  117. return $this->workHours;
  118. }
  119. public function addWorkHour(WorkHours $workHour): self
  120. {
  121. if (!$this->workHours->contains($workHour)) {
  122. $this->workHours[] = $workHour;
  123. $workHour->setProject($this);
  124. }
  125. return $this;
  126. }
  127. public function removeWorkHour(WorkHours $workHour): self
  128. {
  129. if ($this->workHours->removeElement($workHour)) {
  130. // set the owning side to null (unless already changed)
  131. if ($workHour->getProject() === $this) {
  132. $workHour->setProject(null);
  133. }
  134. }
  135. return $this;
  136. }
  137. /**
  138. * @return Collection|ProjectProducts[]
  139. */
  140. public function getProjectProducts(): Collection
  141. {
  142. return $this->projectProducts;
  143. }
  144. public function addProjectProduct(ProjectProducts $projectProduct): self
  145. {
  146. if (!$this->projectProducts->contains($projectProduct)) {
  147. $this->projectProducts[] = $projectProduct;
  148. $projectProduct->setProject($this);
  149. }
  150. return $this;
  151. }
  152. public function removeProjectProduct(ProjectProducts $projectProduct): self
  153. {
  154. if ($this->projectProducts->removeElement($projectProduct)) {
  155. // set the owning side to null (unless already changed)
  156. if ($projectProduct->getProject() === $this) {
  157. $projectProduct->setProject(null);
  158. }
  159. }
  160. return $this;
  161. }
  162. public function __toString()
  163. {
  164. if($this->customer){
  165. return $this->getCustomer() . " - " . $this->name;
  166. }
  167. return $this->name;
  168. }
  169. /**
  170. * @return Collection|Attachment[]
  171. */
  172. public function getAttachments(): Collection
  173. {
  174. return $this->attachments;
  175. }
  176. public function addAttachment(Attachment $attachment): self
  177. {
  178. if (!$this->attachments->contains($attachment)) {
  179. $this->attachments[] = $attachment;
  180. $attachment->setProject($this);
  181. }
  182. return $this;
  183. }
  184. public function removeAttachment(Attachment $attachment): self
  185. {
  186. if ($this->attachments->removeElement($attachment)) {
  187. // set the owning side to null (unless already changed)
  188. if ($attachment->getProject() === $this) {
  189. $attachment->setProject(null);
  190. }
  191. }
  192. return $this;
  193. }
  194. public function numOfAttachments()
  195. {
  196. return $this->attachments?count($this->attachments):0;
  197. }
  198. /**
  199. * @return Collection|Photo[]
  200. */
  201. public function getPhotos(): Collection
  202. {
  203. return $this->photos;
  204. }
  205. public function addPhoto(Photo $attachment): self
  206. {
  207. if (!$this->photos->contains($attachment)) {
  208. $this->photos[] = $attachment;
  209. $attachment->setCreated(new \DateTime());
  210. $attachment->setProject($this);
  211. }
  212. return $this;
  213. }
  214. public function removePhoto(Photo $attachment): self
  215. {
  216. if ($this->photos->removeElement($attachment)) {
  217. // set the owning side to null (unless already changed)
  218. if ($attachment->getProject() === $this) {
  219. $attachment->setProject(null);
  220. }
  221. }
  222. return $this;
  223. }
  224. public function numOfPhotos()
  225. {
  226. return $this->photos?count($this->photos):0;
  227. }
  228. /**
  229. * @return Collection|Supply[]
  230. */
  231. public function getMaterials(): Collection
  232. {
  233. return $this->materials;
  234. }
  235. public function addMaterial(Material $material): self
  236. {
  237. if (!$this->materials->contains($material)) {
  238. $this->materials[] = $material;
  239. $material->setProjectId($this);
  240. }
  241. return $this;
  242. }
  243. public function removeMaterial(Material $material): self
  244. {
  245. if ($this->materials->removeElement($material)) {
  246. // set the owning side to null (unless already changed)
  247. if ($material->getProjectId() === $this) {
  248. $material->setProjectId(null);
  249. }
  250. }
  251. return $this;
  252. }
  253. public function getDescription(): ?string
  254. {
  255. return $this->description;
  256. }
  257. public function setDescription(?string $description): self
  258. {
  259. $this->description = $description;
  260. return $this;
  261. }
  262. public function getPriceNetto(): ?int
  263. {
  264. return $this->priceNetto;
  265. }
  266. public function setPriceNetto(?int $priceNetto): self
  267. {
  268. $this->priceNetto = $priceNetto;
  269. return $this;
  270. }
  271. /**
  272. * @return Collection|workers[]
  273. */
  274. public function getWorkers(): Collection
  275. {
  276. return $this->workers;
  277. }
  278. public function addWorker(workers $worker): self
  279. {
  280. if (!$this->workers->contains($worker)) {
  281. $this->workers[] = $worker;
  282. }
  283. return $this;
  284. }
  285. public function removeWorker(workers $worker): self
  286. {
  287. $this->workers->removeElement($worker);
  288. return $this;
  289. }
  290. public function getIsClosed(): ?bool
  291. {
  292. return $this->isClosed;
  293. }
  294. public function setIsClosed(?bool $isClosed): self
  295. {
  296. $this->isClosed = $isClosed;
  297. $this->closed = $isClosed ? new \DateTime() : null;
  298. return $this;
  299. }
  300. }