src/Entity/Machine.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\MachineRepository;
  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. /**
  10.  * @ORM\Entity(repositoryClass=MachineRepository::class)
  11.  */
  12. class Machine
  13. {
  14.     use TimestampableEntity;
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\Column(type="string", length=255)
  23.      */
  24.     private $name;
  25.     /**
  26.      * @ORM\Column(type="string", length=255)
  27.      */
  28.     private $code;
  29.     /**
  30.      * @ORM\Column(type="text", nullable=true)
  31.      */
  32.     private $invoiceDescription;
  33.     /**
  34.      * @ORM\Column(type="text", nullable=true)
  35.      */
  36.     private $technicalNotes;
  37.     /**
  38.      * @ORM\ManyToOne(targetEntity=Machine::class, inversedBy="children")
  39.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id" )
  40.      */
  41.     private $parent;
  42.     /**
  43.      * @ORM\OneToMany(targetEntity=Machine::class, mappedBy="parent")
  44.      */
  45.     private $children;
  46.     /**
  47.      * @ORM\ManyToMany(targetEntity=PaperSize::class, mappedBy="machines", cascade={"persist"})
  48.      */
  49.     private $paperSizes;
  50.     /**
  51.      * @ORM\OneToMany(targetEntity=MachinePaperSizeMatrix::class, mappedBy="machine", cascade={"persist", "remove"})
  52.      */
  53.     private $machinePaperSizeMatrices;
  54.     /**
  55.      * @ORM\ManyToMany(targetEntity=Task::class, inversedBy="machines", cascade={"persist"})
  56.      */
  57.     private $tasks;
  58.     /**
  59.      * @ORM\Column(type="integer", nullable=true)
  60.      */
  61.     private $waste;
  62.     /**
  63.      * @ORM\Column(type="decimal", precision=10, scale=3, nullable=true)
  64.      */
  65.     private $spoilage;
  66.     /**
  67.      * @ORM\Column(type="integer", nullable=true)
  68.      */
  69.     private $setupTime;
  70.     /**
  71.      * @ORM\Column(type="decimal", precision=10, scale=4, nullable=true)
  72.      */
  73.     private $rate;
  74.     /**
  75.      * @ORM\OneToMany(targetEntity=MachineCostMatrix::class, mappedBy="machine", orphanRemoval=true, cascade={"persist", "remove"})
  76.      */
  77.     private $machineCostMatrices;
  78.     /**
  79.      * @ORM\OneToMany(targetEntity=MachineTimeMatrix::class, mappedBy="machine", orphanRemoval=true, cascade={"persist", "remove"})
  80.      */
  81.     private $machineTimeMatrices;
  82.     public function __construct()
  83.     {
  84.         $this->children = new ArrayCollection();
  85.         $this->paperSizes = new ArrayCollection();
  86.         $this->machinePaperSizeMatrices = new ArrayCollection();
  87.         $this->tasks = new ArrayCollection();
  88.         $this->machineCostMatrices = new ArrayCollection();
  89.         $this->machineTimeMatrices = new ArrayCollection();
  90.     }
  91.     public function getId(): ?int
  92.     {
  93.         return $this->id;
  94.     }
  95.     public function getName(): ?string
  96.     {
  97.         return $this->name;
  98.     }
  99.     public function setName(string $name): self
  100.     {
  101.         $this->name $name;
  102.         return $this;
  103.     }
  104.     public function getCode(): ?string
  105.     {
  106.         return $this->code;
  107.     }
  108.     public function setCode(string $code): self
  109.     {
  110.         $this->code $code;
  111.         return $this;
  112.     }
  113.     public function getInvoiceDescription(): ?string
  114.     {
  115.         return $this->invoiceDescription;
  116.     }
  117.     public function setInvoiceDescription(?string $invoiceDescription): self
  118.     {
  119.         $this->invoiceDescription $invoiceDescription;
  120.         return $this;
  121.     }
  122.     public function getTechnicalNotes(): ?string
  123.     {
  124.         return $this->technicalNotes;
  125.     }
  126.     public function setTechnicalNotes(?string $technicalNotes): self
  127.     {
  128.         $this->technicalNotes $technicalNotes;
  129.         return $this;
  130.     }
  131.     public function getParent(): ?self
  132.     {
  133.         return $this->parent;
  134.     }
  135.     public function setParent(?self $parent): self
  136.     {
  137.         $this->parent $parent;
  138.         return $this;
  139.     }
  140.     /**
  141.      * @return Collection<int, self>
  142.      */
  143.     public function getChildren(): Collection
  144.     {
  145.         return $this->children;
  146.     }
  147.     public function addChild(self $child): self
  148.     {
  149.         if (!$this->children->contains($child)) {
  150.             $this->children[] = $child;
  151.             $child->setParent($this);
  152.         }
  153.         return $this;
  154.     }
  155.     public function removeChild(self $child): self
  156.     {
  157.         if ($this->children->removeElement($child)) {
  158.             // set the owning side to null (unless already changed)
  159.             if ($child->getParent() === $this) {
  160.                 $child->setParent(null);
  161.             }
  162.         }
  163.         return $this;
  164.     }
  165.     /**
  166.      * @return Collection<int, PaperSize>
  167.      */
  168.     public function getPaperSizes(): Collection
  169.     {
  170.         return $this->paperSizes;
  171.     }
  172.     public function addPaperSize(PaperSize $paperSize): self
  173.     {
  174.         if (!$this->paperSizes->contains($paperSize)) {
  175.             $this->paperSizes[] = $paperSize;
  176.             $paperSize->addMachine($this);
  177.         }
  178.         return $this;
  179.     }
  180.     public function removePaperSize(PaperSize $paperSize): self
  181.     {
  182.         if ($this->paperSizes->removeElement($paperSize)) {
  183.             $paperSize->removeMachine($this);
  184.         }
  185.         return $this;
  186.     }
  187.     /**
  188.      * @return Collection<int, MachinePaperSizeMatrix>
  189.      */
  190.     public function getMachinePaperSizeMatrices(): Collection
  191.     {
  192.         return $this->machinePaperSizeMatrices;
  193.     }
  194.     public function addMachinePaperSizeMatrix(MachinePaperSizeMatrix $machinePaperSizeMatrix): self
  195.     {
  196.         if (!$this->machinePaperSizeMatrices->contains($machinePaperSizeMatrix)) {
  197.             $this->machinePaperSizeMatrices[] = $machinePaperSizeMatrix;
  198.             $machinePaperSizeMatrix->setMachine($this);
  199.         }
  200.         return $this;
  201.     }
  202.     public function removeMachinePaperSizeMatrix(MachinePaperSizeMatrix $machinePaperSizeMatrix): self
  203.     {
  204.         if ($this->machinePaperSizeMatrices->removeElement($machinePaperSizeMatrix)) {
  205.             // set the owning side to null (unless already changed)
  206.             if ($machinePaperSizeMatrix->getMachine() === $this) {
  207.                 $machinePaperSizeMatrix->setMachine(null);
  208.             }
  209.         }
  210.         return $this;
  211.     }
  212.     /**
  213.      * @return Collection<int, Task>
  214.      */
  215.     public function getTasks(): Collection
  216.     {
  217.         return $this->tasks;
  218.     }
  219.     public function addTask(Task $task): self
  220.     {
  221.         if (!$this->tasks->contains($task)) {
  222.             $this->tasks[] = $task;
  223.         }
  224.         return $this;
  225.     }
  226.     public function removeTask(Task $task): self
  227.     {
  228.         $this->tasks->removeElement($task);
  229.         return $this;
  230.     }
  231.     public function getWaste(): ?int
  232.     {
  233.         return $this->waste;
  234.     }
  235.     public function setWaste(?int $waste): self
  236.     {
  237.         $this->waste $waste;
  238.         return $this;
  239.     }
  240.     public function getSpoilage(): ?string
  241.     {
  242.         return $this->spoilage;
  243.     }
  244.     public function setSpoilage(?string $spoilage): self
  245.     {
  246.         $this->spoilage $spoilage;
  247.         return $this;
  248.     }
  249.     public function getSetupTime(): ?int
  250.     {
  251.         return $this->setupTime;
  252.     }
  253.     public function setSetupTime(?int $setupTime): self
  254.     {
  255.         $this->setupTime $setupTime;
  256.         return $this;
  257.     }
  258.     public function getRate(): ?string
  259.     {
  260.         return $this->rate;
  261.     }
  262.     public function setRate(?string $rate): self
  263.     {
  264.         $this->rate $rate;
  265.         return $this;
  266.     }
  267.     /**
  268.      * @return Collection<int, MachineCostMatrix>
  269.      */
  270.     public function getMachineCostMatrices(): Collection
  271.     {
  272.         return $this->machineCostMatrices;
  273.     }
  274.     public function addMachineCostMatrix(MachineCostMatrix $machineCostMatrix): self
  275.     {
  276.         if (!$this->machineCostMatrices->contains($machineCostMatrix)) {
  277.             $this->machineCostMatrices[] = $machineCostMatrix;
  278.             $machineCostMatrix->setMachine($this);
  279.         }
  280.         return $this;
  281.     }
  282.     public function removeMachineCostMatrix(MachineCostMatrix $machineCostMatrix): self
  283.     {
  284.         if ($this->machineCostMatrices->removeElement($machineCostMatrix)) {
  285.             // set the owning side to null (unless already changed)
  286.             if ($machineCostMatrix->getMachine() === $this) {
  287.                 $machineCostMatrix->setMachine(null);
  288.             }
  289.         }
  290.         return $this;
  291.     }
  292.     /**
  293.      * @return Collection<int, MachineTimeMatrix>
  294.      */
  295.     public function getMachineTimeMatrices(): Collection
  296.     {
  297.         return $this->machineTimeMatrices;
  298.     }
  299.     public function addMachineTimeMatrix(MachineTimeMatrix $machineTimeMatrix): self
  300.     {
  301.         if (!$this->machineTimeMatrices->contains($machineTimeMatrix)) {
  302.             $this->machineTimeMatrices[] = $machineTimeMatrix;
  303.             $machineTimeMatrix->setMachine($this);
  304.         }
  305.         return $this;
  306.     }
  307.     public function removeMachineTimeMatrix(MachineTimeMatrix $machineTimeMatrix): self
  308.     {
  309.         if ($this->machineTimeMatrices->removeElement($machineTimeMatrix)) {
  310.             // set the owning side to null (unless already changed)
  311.             if ($machineTimeMatrix->getMachine() === $this) {
  312.                 $machineTimeMatrix->setMachine(null);
  313.             }
  314.         }
  315.         return $this;
  316.     }
  317.     public function __clone() {
  318.         $paperSizes = new ArrayCollection();
  319.         foreach ($this->paperSizes as $paperSize) {
  320.             /** @var Papersize $paperSize */
  321.             $paperSize->addMachine($this);
  322.             $paperSizes->add($paperSize);
  323.         }
  324.         $now = new DateTime('now');
  325.         $machinePaperSizeMatrices = new ArrayCollection();
  326.         foreach ($this->machinePaperSizeMatrices as $machinePaperSizeMatrix) {
  327.             $newMachinePaperSizeMatrix = clone $machinePaperSizeMatrix;
  328.             $newMachinePaperSizeMatrix->setCreatedAt($now);
  329.             $newMachinePaperSizeMatrix->setUpdatedAt($now);
  330.             $newMachinePaperSizeMatrix->setMachine($this);
  331.             $machinePaperSizeMatrices->add($newMachinePaperSizeMatrix);
  332.         }
  333.         $this->machinePaperSizeMatrices $machinePaperSizeMatrices;
  334.         /* machineCostMatrices */
  335.         $machineCostMatrices = new ArrayCollection();
  336.         foreach ($this->machineCostMatrices as $machineCostMatrix) {
  337.             $newMachineCostMatrix = clone $machineCostMatrix;
  338.             $newMachineCostMatrix->setCreatedAt($now);
  339.             $newMachineCostMatrix->setUpdatedAt($now);
  340.             $newMachineCostMatrix->setMachine($this);
  341.             $machineCostMatrices->add($newMachineCostMatrix);
  342.         }
  343.         $this->machineCostMatrices $machineCostMatrices;
  344.         /* machineTimeMatrices */
  345.         $machineTimeMatrices = new ArrayCollection();
  346.         foreach ($this->machineTimeMatrices as $machineTimeMatrix) {
  347.             $newMachineTimeMatrix = clone $machineTimeMatrix;
  348.             $newMachineTimeMatrix->setMachine($this);
  349.             $machineTimeMatrices->add($newMachineTimeMatrix);
  350.         }
  351.         $this->machineTimeMatrices $machineTimeMatrices;
  352.         /* Tasks */
  353.         $tasks = new ArrayCollection();
  354.         foreach ($this->tasks as $task) {
  355.             $task->addMachine($this);
  356.             $tasks->add($task);
  357.         }
  358.         $this->tasks $tasks;
  359.     }
  360.     public function getCalculatorDisplayName():string
  361.     {
  362.         return '['.$this->code.']['.$this->name.']';
  363.     }
  364.     public function __toString() {
  365.         return $this->name;
  366.     }
  367. }