src/Entity/Projects.php line 13

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