src/Entity/Task.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\TaskRepository;
  4. use DateTime;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Gedmo\Timestampable\Traits\TimestampableEntity;
  9. use Symfony\Component\Serializer\Annotation\Groups;
  10. /**
  11.  * @ORM\Entity(repositoryClass=TaskRepository::class)
  12.  */
  13. class Task
  14. {
  15.     use TimestampableEntity;
  16.     /**
  17.      * @ORM\Id
  18.      * @ORM\GeneratedValue
  19.      * @ORM\Column(type="integer")
  20.      */
  21.     private $id;
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      */
  25.     private $name;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, unique=true)
  28.      */
  29.     private $code;
  30.     /**
  31.      * @ORM\Column(type="text", nullable=true)
  32.      */
  33.     private $invoiceDescription;
  34.     /**
  35.      * @ORM\Column(type="text", nullable=true)
  36.      */
  37.     private $technicalNotes;
  38.     /**
  39.      * @ORM\Column(type="integer", nullable=true)
  40.      */
  41.     private $setup;
  42.     /**
  43.      * @ORM\Column(type="decimal", precision=10, scale=4, nullable=true)
  44.      */
  45.     private $cost;
  46.     /**
  47.      * @ORM\ManyToMany(targetEntity=Machine::class, mappedBy="tasks")
  48.      * @Groups({"list"})
  49.      */
  50.     private $machines;
  51.     /**
  52.      * @ORM\ManyToOne(targetEntity=Label::class, inversedBy="tasks")
  53.      * @Groups({"list"})
  54.      */
  55.     private $label;
  56.     /**
  57.      * @ORM\OneToMany(targetEntity=TaskCostMatrix::class, mappedBy="task", orphanRemoval=true, cascade={"persist", "remove"}))
  58.      */
  59.     private $taskCostMatrices;
  60.     /**
  61.      * @ORM\OneToMany(targetEntity=TaskTimeMatrix::class, mappedBy="task", orphanRemoval=true, cascade={"persist", "remove"}))
  62.      */
  63.     private $taskTimeMatrices;
  64.     /**
  65.      * @ORM\Column(type="text", nullable=true)
  66.      */
  67.     private $setupDescription;
  68.     /**
  69.      * @ORM\Column(type="text", nullable=true)
  70.      */
  71.     private $costDescription;
  72.     /**
  73.      * @ORM\Column(type="text", nullable=true)
  74.      */
  75.     private $invoiceDescriptionDescription;
  76.     /**
  77.      * @ORM\Column(type="text", nullable=true)
  78.      */
  79.     private $technicalNotesDescription;
  80.     /**
  81.      * @ORM\Column(type="text", nullable=true)
  82.      */
  83.     private $costMatrixDescription;
  84.     /**
  85.      * @ORM\Column(type="text", nullable=true)
  86.      */
  87.     private $timeMatrixDescription;
  88.     /**
  89.      * @ORM\ManyToOne(targetEntity=Imposition::class, inversedBy="tasks")
  90.      * @Groups({"list"})
  91.      */
  92.     private $imposition;
  93.     public function __construct()
  94.     {
  95.         $this->machines = new ArrayCollection();
  96.         $this->taskCostMatrices = new ArrayCollection();
  97.         $this->taskTimeMatrices = new ArrayCollection();
  98.     }
  99.     public function getId(): ?int
  100.     {
  101.         return $this->id;
  102.     }
  103.     public function getName(): ?string
  104.     {
  105.         return $this->name;
  106.     }
  107.     public function setName(string $name): self
  108.     {
  109.         $this->name $name;
  110.         return $this;
  111.     }
  112.     public function getCode(): ?string
  113.     {
  114.         return $this->code;
  115.     }
  116.     public function setCode(string $code): self
  117.     {
  118.         $this->code $code;
  119.         return $this;
  120.     }
  121.     public function getInvoiceDescription(): ?string
  122.     {
  123.         return $this->invoiceDescription;
  124.     }
  125.     public function setInvoiceDescription(?string $invoiceDescription): self
  126.     {
  127.         $this->invoiceDescription $invoiceDescription;
  128.         return $this;
  129.     }
  130.     public function getTechnicalNotes(): ?string
  131.     {
  132.         return $this->technicalNotes;
  133.     }
  134.     public function setTechnicalNotes(?string $technicalNotes): self
  135.     {
  136.         $this->technicalNotes $technicalNotes;
  137.         return $this;
  138.     }
  139.     public function getSetup(): ?int
  140.     {
  141.         return $this->setup;
  142.     }
  143.     public function setSetup(int $setup): self
  144.     {
  145.         $this->setup $setup;
  146.         return $this;
  147.     }
  148.     public function getCost(): ?string
  149.     {
  150.         return $this->cost;
  151.     }
  152.     public function setCost(string $cost): self
  153.     {
  154.         $this->cost $cost;
  155.         return $this;
  156.     }
  157.     /**
  158.      * @return Collection<int, Machine>
  159.      */
  160.     public function getMachines(): Collection
  161.     {
  162.         return $this->machines;
  163.     }
  164.     public function addMachine(Machine $machine): self
  165.     {
  166.         if (!$this->machines->contains($machine)) {
  167.             $this->machines[] = $machine;
  168.             $machine->addTask($this);
  169.         }
  170.         return $this;
  171.     }
  172.     public function removeMachine(Machine $machine): self
  173.     {
  174.         if ($this->machines->removeElement($machine)) {
  175.             $machine->removeTask($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function getLabel(): ?Label
  180.     {
  181.         return $this->label;
  182.     }
  183.     public function setLabel(?Label $label): self
  184.     {
  185.         $this->label $label;
  186.         return $this;
  187.     }
  188.     /**
  189.      * @return Collection<int, TaskCostMatrix>
  190.      */
  191.     public function getTaskCostMatrices(): Collection
  192.     {
  193.         return $this->taskCostMatrices;
  194.     }
  195.     public function addTaskCostMatrix(TaskCostMatrix $taskCostMatrix): self
  196.     {
  197.         if (!$this->taskCostMatrices->contains($taskCostMatrix)) {
  198.             $this->taskCostMatrices[] = $taskCostMatrix;
  199.             $taskCostMatrix->setTask($this);
  200.         }
  201.         return $this;
  202.     }
  203.     public function removeTaskCostMatrix(TaskCostMatrix $taskCostMatrix): self
  204.     {
  205.         if ($this->taskCostMatrices->removeElement($taskCostMatrix)) {
  206.             // set the owning side to null (unless already changed)
  207.             if ($taskCostMatrix->getTask() === $this) {
  208.                 $taskCostMatrix->setTask(null);
  209.             }
  210.         }
  211.         return $this;
  212.     }
  213.     /**
  214.      * @return Collection<int, TaskTimeMatrix>
  215.      */
  216.     public function getTaskTimeMatrices(): Collection
  217.     {
  218.         return $this->taskTimeMatrices;
  219.     }
  220.     public function addTaskTimeMatrix(TaskTimeMatrix $taskTimeMatrix): self
  221.     {
  222.         if (!$this->taskTimeMatrices->contains($taskTimeMatrix)) {
  223.             $this->taskTimeMatrices[] = $taskTimeMatrix;
  224.             $taskTimeMatrix->setTask($this);
  225.         }
  226.         return $this;
  227.     }
  228.     public function removeTaskTimeMatrix(TaskTimeMatrix $taskTimeMatrix): self
  229.     {
  230.         if ($this->taskTimeMatrices->removeElement($taskTimeMatrix)) {
  231.             // set the owning side to null (unless already changed)
  232.             if ($taskTimeMatrix->getTask() === $this) {
  233.                 $taskTimeMatrix->setTask(null);
  234.             }
  235.         }
  236.         return $this;
  237.     }
  238.     public function __clone(){
  239.         $machines = new ArrayCollection();
  240.         foreach ($this->machines as $machine) {
  241.             $machine->addTask($this);
  242.             $machines->add($machine);
  243.         }
  244.         $this->machines $machines;
  245.         $now = new DateTime('now');
  246.         $taskCostMatrices = new ArrayCollection();
  247.         foreach ($this->taskCostMatrices as $taskCostMatrix) {
  248.             $newTaskCostMatrix = clone $taskCostMatrix;
  249.             $newTaskCostMatrix->setCreatedAt($now);
  250.             $newTaskCostMatrix->setUpdatedAt($now);
  251.             $taskCostMatrix->setTask($this);
  252.             $taskCostMatrices->add($newTaskCostMatrix);
  253.         }
  254.         $this->taskCostMatrices $taskCostMatrices;
  255.         /*$this->taskCostMatrices = $taskCostMatrices;*/
  256.         $taskTimeMatrices = new ArrayCollection();
  257.         foreach ($this->taskTimeMatrices as $taskTimeMatrix) {
  258.             $newTaskTimeMatrix = clone $taskTimeMatrix;
  259.             $newTaskTimeMatrix->setCreatedAt($now);
  260.             $newTaskTimeMatrix->setUpdatedAt($now);
  261.             $taskTimeMatrix->setTask($this);
  262.             $taskTimeMatrices->add($newTaskTimeMatrix);
  263.         }
  264.         $this->taskTimeMatrices $taskTimeMatrices;
  265.     }
  266.     public function getSetupDescription(): ?string
  267.     {
  268.         return $this->setupDescription;
  269.     }
  270.     public function setSetupDescription(?string $setupDescription): self
  271.     {
  272.         $this->setupDescription $setupDescription;
  273.         return $this;
  274.     }
  275.     public function getCostDescription(): ?string
  276.     {
  277.         return $this->costDescription;
  278.     }
  279.     public function setCostDescription(?string $costDescription): self
  280.     {
  281.         $this->costDescription $costDescription;
  282.         return $this;
  283.     }
  284.     public function getInvoiceDescriptionDescription(): ?string
  285.     {
  286.         return $this->invoiceDescriptionDescription;
  287.     }
  288.     public function setInvoiceDescriptionDescription(?string $invoiceDescriptionDescription): self
  289.     {
  290.         $this->invoiceDescriptionDescription $invoiceDescriptionDescription;
  291.         return $this;
  292.     }
  293.     public function getTechnicalNotesDescription(): ?string
  294.     {
  295.         return $this->technicalNotesDescription;
  296.     }
  297.     public function setTechnicalNotesDescription(?string $technicalNotesDescription): self
  298.     {
  299.         $this->technicalNotesDescription $technicalNotesDescription;
  300.         return $this;
  301.     }
  302.     public function getCostMatrixDescription(): ?string
  303.     {
  304.         return $this->costMatrixDescription;
  305.     }
  306.     public function setCostMatrixDescription(?string $costMatrixDescription): self
  307.     {
  308.         $this->costMatrixDescription $costMatrixDescription;
  309.         return $this;
  310.     }
  311.     public function getTimeMatrixDescription(): ?string
  312.     {
  313.         return $this->timeMatrixDescription;
  314.     }
  315.     public function setTimeMatrixDescription(?string $timeMatrixDescription): self
  316.     {
  317.         $this->timeMatrixDescription $timeMatrixDescription;
  318.         return $this;
  319.     }
  320.     public function getImposition(): ?Imposition
  321.     {
  322.         return $this->imposition;
  323.     }
  324.     public function setImposition(?Imposition $imposition): self
  325.     {
  326.         $this->imposition $imposition;
  327.         return $this;
  328.     }
  329.     public function getCalculatorDisplayName():string
  330.     {
  331.         return '['.$this->code.']['.$this->name.']';
  332.     }
  333.     public function __toString() {
  334.         return $this->name;
  335.     }
  336. }