<?php
namespace App\Entity;
use App\Repository\ProjectsRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity(repositoryClass=ProjectsRepository::class)
*/
class Projects
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $deadline;
/**
* @ORM\Column(type="date", nullable=true)
*/
private $closed;
/**
* @ORM\Column(type="datetime", nullable=true)
*/
private $created;
/**
* @ORM\ManyToOne(targetEntity=Customers::class, inversedBy="projects")
*/
private $customer;
/**
* @ORM\OneToMany(targetEntity=WorkHours::class, mappedBy="project")
*/
private $workHours;
/**
* @ORM\OneToMany(targetEntity=ProjectProducts::class, mappedBy="project")
*/
private $projectProducts;
/**
* @ORM\OneToMany(targetEntity=Attachment::class, mappedBy="project", cascade={"persist"}, orphanRemoval=true)
*/
private $attachments;
/**
* @ORM\OneToMany(targetEntity=Photo::class, mappedBy="project", cascade={"persist"}, orphanRemoval=true)
*/
private $photos;
/**
* @ORM\OneToMany(targetEntity=Material::class, mappedBy="project")
*/
private $materials;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $priceNetto;
/**
* @ORM\ManyToMany(targetEntity=Workers::class, inversedBy="projects")
*/
private $workers;
/**
* @ORM\Column(type="boolean", nullable=true)
*/
private $isClosed;
public function __construct()
{
$this->workHours = new ArrayCollection();
$this->projectProducts = new ArrayCollection();
$this->created = new \DateTime();
$this->attachments = new ArrayCollection();
$this->photos = new ArrayCollection();
$this->materials = new ArrayCollection();
$this->workers = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getDeadline(): ?\DateTimeInterface
{
return $this->deadline;
}
public function setDeadline(?\DateTimeInterface $deadline): self
{
$this->deadline = $deadline;
return $this;
}
public function getClosed(): ?\DateTimeInterface
{
return $this->closed;
}
public function setClosed(?\DateTimeInterface $closed): self
{
$this->closed = $closed;
return $this;
}
public function getCreated(): ?\DateTimeInterface
{
return $this->created;
}
public function setCreated(?\DateTimeInterface $created): self
{
$this->created = $created;
return $this;
}
public function getCustomer(): ?Customers
{
return $this->customer;
}
public function setCustomer(?Customers $customer): self
{
$this->customer = $customer;
return $this;
}
/**
* @return Collection|WorkHours[]
*/
public function getWorkHoursSum()
{
$sum = 0;
foreach ($this->workHours as $key => $value) {
$sum += $value->getHours();
}
return $sum;
}
/**
* @return Collection|WorkHours[]
*/
public function getWorkHours(): Collection
{
return $this->workHours;
}
public function addWorkHour(WorkHours $workHour): self
{
if (!$this->workHours->contains($workHour)) {
$this->workHours[] = $workHour;
$workHour->setProject($this);
}
return $this;
}
public function removeWorkHour(WorkHours $workHour): self
{
if ($this->workHours->removeElement($workHour)) {
// set the owning side to null (unless already changed)
if ($workHour->getProject() === $this) {
$workHour->setProject(null);
}
}
return $this;
}
/**
* @return Collection|ProjectProducts[]
*/
public function getProjectProducts(): Collection
{
return $this->projectProducts;
}
public function addProjectProduct(ProjectProducts $projectProduct): self
{
if (!$this->projectProducts->contains($projectProduct)) {
$this->projectProducts[] = $projectProduct;
$projectProduct->setProject($this);
}
return $this;
}
public function removeProjectProduct(ProjectProducts $projectProduct): self
{
if ($this->projectProducts->removeElement($projectProduct)) {
// set the owning side to null (unless already changed)
if ($projectProduct->getProject() === $this) {
$projectProduct->setProject(null);
}
}
return $this;
}
public function __toString()
{
if($this->customer){
return $this->getCustomer() . " - " . $this->name;
}
return $this->name;
}
/**
* @return Collection|Attachment[]
*/
public function getAttachments(): Collection
{
return $this->attachments;
}
public function addAttachment(Attachment $attachment): self
{
if (!$this->attachments->contains($attachment)) {
$this->attachments[] = $attachment;
$attachment->setProject($this);
}
return $this;
}
public function removeAttachment(Attachment $attachment): self
{
if ($this->attachments->removeElement($attachment)) {
// set the owning side to null (unless already changed)
if ($attachment->getProject() === $this) {
$attachment->setProject(null);
}
}
return $this;
}
public function numOfAttachments()
{
return $this->attachments?count($this->attachments):0;
}
/**
* @return Collection|Photo[]
*/
public function getPhotos(): Collection
{
return $this->photos;
}
public function addPhoto(Photo $attachment): self
{
if (!$this->photos->contains($attachment)) {
$this->photos[] = $attachment;
$attachment->setCreated(new \DateTime());
$attachment->setProject($this);
}
return $this;
}
public function removePhoto(Photo $attachment): self
{
if ($this->photos->removeElement($attachment)) {
// set the owning side to null (unless already changed)
if ($attachment->getProject() === $this) {
$attachment->setProject(null);
}
}
return $this;
}
public function numOfPhotos()
{
return $this->photos?count($this->photos):0;
}
/**
* @return Collection|Supply[]
*/
public function getMaterials(): Collection
{
return $this->materials;
}
public function addMaterial(Material $material): self
{
if (!$this->materials->contains($material)) {
$this->materials[] = $material;
$material->setProjectId($this);
}
return $this;
}
public function removeMaterial(Material $material): self
{
if ($this->materials->removeElement($material)) {
// set the owning side to null (unless already changed)
if ($material->getProjectId() === $this) {
$material->setProjectId(null);
}
}
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getPriceNetto(): ?int
{
return $this->priceNetto;
}
public function setPriceNetto(?int $priceNetto): self
{
$this->priceNetto = $priceNetto;
return $this;
}
/**
* @return Collection|workers[]
*/
public function getWorkers(): Collection
{
return $this->workers;
}
public function addWorker(workers $worker): self
{
if (!$this->workers->contains($worker)) {
$this->workers[] = $worker;
}
return $this;
}
public function removeWorker(workers $worker): self
{
$this->workers->removeElement($worker);
return $this;
}
public function getIsClosed(): ?bool
{
return $this->isClosed;
}
public function setIsClosed(?bool $isClosed): self
{
$this->isClosed = $isClosed;
$this->closed = $isClosed ? new \DateTime() : null;
return $this;
}
}