<?php
namespace App\Entity;
use App\Repository\TaskRepository;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
use Symfony\Component\Serializer\Annotation\Groups;
/**
* @ORM\Entity(repositoryClass=TaskRepository::class)
*/
class Task
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="string", length=255, unique=true)
*/
private $code;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $invoiceDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $technicalNotes;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $setup;
/**
* @ORM\Column(type="decimal", precision=10, scale=4, nullable=true)
*/
private $cost;
/**
* @ORM\ManyToMany(targetEntity=Machine::class, mappedBy="tasks")
* @Groups({"list"})
*/
private $machines;
/**
* @ORM\ManyToOne(targetEntity=Label::class, inversedBy="tasks")
* @Groups({"list"})
*/
private $label;
/**
* @ORM\OneToMany(targetEntity=TaskCostMatrix::class, mappedBy="task", orphanRemoval=true, cascade={"persist", "remove"}))
*/
private $taskCostMatrices;
/**
* @ORM\OneToMany(targetEntity=TaskTimeMatrix::class, mappedBy="task", orphanRemoval=true, cascade={"persist", "remove"}))
*/
private $taskTimeMatrices;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $setupDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $costDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $invoiceDescriptionDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $technicalNotesDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $costMatrixDescription;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $timeMatrixDescription;
/**
* @ORM\ManyToOne(targetEntity=Imposition::class, inversedBy="tasks")
* @Groups({"list"})
*/
private $imposition;
public function __construct()
{
$this->machines = new ArrayCollection();
$this->taskCostMatrices = new ArrayCollection();
$this->taskTimeMatrices = 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 getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getInvoiceDescription(): ?string
{
return $this->invoiceDescription;
}
public function setInvoiceDescription(?string $invoiceDescription): self
{
$this->invoiceDescription = $invoiceDescription;
return $this;
}
public function getTechnicalNotes(): ?string
{
return $this->technicalNotes;
}
public function setTechnicalNotes(?string $technicalNotes): self
{
$this->technicalNotes = $technicalNotes;
return $this;
}
public function getSetup(): ?int
{
return $this->setup;
}
public function setSetup(int $setup): self
{
$this->setup = $setup;
return $this;
}
public function getCost(): ?string
{
return $this->cost;
}
public function setCost(string $cost): self
{
$this->cost = $cost;
return $this;
}
/**
* @return Collection<int, Machine>
*/
public function getMachines(): Collection
{
return $this->machines;
}
public function addMachine(Machine $machine): self
{
if (!$this->machines->contains($machine)) {
$this->machines[] = $machine;
$machine->addTask($this);
}
return $this;
}
public function removeMachine(Machine $machine): self
{
if ($this->machines->removeElement($machine)) {
$machine->removeTask($this);
}
return $this;
}
public function getLabel(): ?Label
{
return $this->label;
}
public function setLabel(?Label $label): self
{
$this->label = $label;
return $this;
}
/**
* @return Collection<int, TaskCostMatrix>
*/
public function getTaskCostMatrices(): Collection
{
return $this->taskCostMatrices;
}
public function addTaskCostMatrix(TaskCostMatrix $taskCostMatrix): self
{
if (!$this->taskCostMatrices->contains($taskCostMatrix)) {
$this->taskCostMatrices[] = $taskCostMatrix;
$taskCostMatrix->setTask($this);
}
return $this;
}
public function removeTaskCostMatrix(TaskCostMatrix $taskCostMatrix): self
{
if ($this->taskCostMatrices->removeElement($taskCostMatrix)) {
// set the owning side to null (unless already changed)
if ($taskCostMatrix->getTask() === $this) {
$taskCostMatrix->setTask(null);
}
}
return $this;
}
/**
* @return Collection<int, TaskTimeMatrix>
*/
public function getTaskTimeMatrices(): Collection
{
return $this->taskTimeMatrices;
}
public function addTaskTimeMatrix(TaskTimeMatrix $taskTimeMatrix): self
{
if (!$this->taskTimeMatrices->contains($taskTimeMatrix)) {
$this->taskTimeMatrices[] = $taskTimeMatrix;
$taskTimeMatrix->setTask($this);
}
return $this;
}
public function removeTaskTimeMatrix(TaskTimeMatrix $taskTimeMatrix): self
{
if ($this->taskTimeMatrices->removeElement($taskTimeMatrix)) {
// set the owning side to null (unless already changed)
if ($taskTimeMatrix->getTask() === $this) {
$taskTimeMatrix->setTask(null);
}
}
return $this;
}
public function __clone(){
$machines = new ArrayCollection();
foreach ($this->machines as $machine) {
$machine->addTask($this);
$machines->add($machine);
}
$this->machines = $machines;
$now = new DateTime('now');
$taskCostMatrices = new ArrayCollection();
foreach ($this->taskCostMatrices as $taskCostMatrix) {
$newTaskCostMatrix = clone $taskCostMatrix;
$newTaskCostMatrix->setCreatedAt($now);
$newTaskCostMatrix->setUpdatedAt($now);
$taskCostMatrix->setTask($this);
$taskCostMatrices->add($newTaskCostMatrix);
}
$this->taskCostMatrices = $taskCostMatrices;
/*$this->taskCostMatrices = $taskCostMatrices;*/
$taskTimeMatrices = new ArrayCollection();
foreach ($this->taskTimeMatrices as $taskTimeMatrix) {
$newTaskTimeMatrix = clone $taskTimeMatrix;
$newTaskTimeMatrix->setCreatedAt($now);
$newTaskTimeMatrix->setUpdatedAt($now);
$taskTimeMatrix->setTask($this);
$taskTimeMatrices->add($newTaskTimeMatrix);
}
$this->taskTimeMatrices = $taskTimeMatrices;
}
public function getSetupDescription(): ?string
{
return $this->setupDescription;
}
public function setSetupDescription(?string $setupDescription): self
{
$this->setupDescription = $setupDescription;
return $this;
}
public function getCostDescription(): ?string
{
return $this->costDescription;
}
public function setCostDescription(?string $costDescription): self
{
$this->costDescription = $costDescription;
return $this;
}
public function getInvoiceDescriptionDescription(): ?string
{
return $this->invoiceDescriptionDescription;
}
public function setInvoiceDescriptionDescription(?string $invoiceDescriptionDescription): self
{
$this->invoiceDescriptionDescription = $invoiceDescriptionDescription;
return $this;
}
public function getTechnicalNotesDescription(): ?string
{
return $this->technicalNotesDescription;
}
public function setTechnicalNotesDescription(?string $technicalNotesDescription): self
{
$this->technicalNotesDescription = $technicalNotesDescription;
return $this;
}
public function getCostMatrixDescription(): ?string
{
return $this->costMatrixDescription;
}
public function setCostMatrixDescription(?string $costMatrixDescription): self
{
$this->costMatrixDescription = $costMatrixDescription;
return $this;
}
public function getTimeMatrixDescription(): ?string
{
return $this->timeMatrixDescription;
}
public function setTimeMatrixDescription(?string $timeMatrixDescription): self
{
$this->timeMatrixDescription = $timeMatrixDescription;
return $this;
}
public function getImposition(): ?Imposition
{
return $this->imposition;
}
public function setImposition(?Imposition $imposition): self
{
$this->imposition = $imposition;
return $this;
}
public function getCalculatorDisplayName():string
{
return '['.$this->code.']['.$this->name.']';
}
public function __toString() {
return $this->name;
}
}