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