<?php
namespace App\Entity;
use App\Repository\LabelRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\Timestampable;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ORM\Entity(repositoryClass=LabelRepository::class)
*/
class Label
{
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=255)
*/
private $name;
/**
* @ORM\Column(type="text", nullable=true)
*/
private $description;
/**
* @ORM\ManyToOne(targetEntity=Label::class, inversedBy="children")
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id" )
*/
private $parent;
/**
* @ORM\OneToMany(targetEntity=Machine::class, mappedBy="parent")
*/
private $children;
/**
* @ORM\Column(type="integer")
*/
private $labelOrder;
/**
* @ORM\OneToMany(targetEntity=Task::class, mappedBy="label")
*/
private $tasks;
public function __construct()
{
$this->children = new ArrayCollection();
$this->tasks = 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 getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getParent(): ?self
{
return $this->parent;
}
public function setParent(?self $parentId): self
{
$this->parent = $parentId;
return $this;
}
/**
* @return Collection<int, self>
*/
public function getChildren(): Collection
{
return $this->children;
}
public function addChild(self $child): self
{
if (!$this->children->contains($child)) {
$this->children[] = $child;
$child->setParent($this);
}
return $this;
}
public function removeChild(self $child): self
{
if ($this->children->removeElement($child)) {
// set the owning side to null (unless already changed)
if ($child->getParent() === $this) {
$child->setParent(null);
}
}
return $this;
}
public function getLabelOrder(): ?int
{
return $this->labelOrder;
}
public function setLabelOrder(int $labelOrder): self
{
$this->labelOrder = $labelOrder;
return $this;
}
/**
* @return Collection<int, Task>
*/
public function getTasks(): Collection
{
return $this->tasks;
}
public function addTask(Task $task): self
{
if (!$this->tasks->contains($task)) {
$this->tasks[] = $task;
$task->setLabel($this);
}
return $this;
}
public function removeTask(Task $task): self
{
if ($this->tasks->removeElement($task)) {
// set the owning side to null (unless already changed)
if ($task->getLabel() === $this) {
$task->setLabel(null);
}
}
return $this;
}
}