<?phpnamespace App\Entity;use Doctrine\ORM\Mapping as ORM;use Gedmo\Mapping\Annotation as Gedmo;use Gedmo\Tree\Traits\NestedSetEntity;enum AgentsNetStatusEnum: int{ case SUPERUSER_ROOT = 50; // it is the only id known as root case GRANT_ALL = 100; // is always visible and is enabled to perform all operations even on children case DELETED = 400; // it is always visible case ONLY_VISIBLE = 500; // it is always visible case ONLY_HIDDEN = 600; // it is user with root out net - this user does not belong to the unique agent network belonging to SUPERUSER_ROOT case BLOCKED_HIDDEN = 950; // the node exists but is never displayed and cannot access, this state also blocks the display of the agents subnet this user is not active and logical deleted case AGENT_OUT_NET = 1550; // agent out of network both viewing and reading public static function fromId(int $id): ?AgentsNetStatusEnum { foreach (self::cases() as $case) { if ($case->value === $id) { return $case; } } return null; }}/** * @Gedmo\Tree(type="nested") * @ORM\Entity(repositoryClass="App\Repository\AgentsNetRepository") */class AgentsNet{ public const AGENTSNET_DEFAULT_LEVEL_SHOW_STATUS = 900; use NestedSetEntity; // entity tree manage /** * @ORM\Id * @ORM\GeneratedValue * @ORM\Column(type="integer") */ private $id; /** * @ORM\Column(type="integer", nullable=false) */ private $userId; /** * @ORM\Column(type="integer", nullable=true, options={"default":0}) */ private $status; /** * @Gedmo\TreeParent * @ORM\ManyToOne(targetEntity="AgentsNet", inversedBy="children") * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE") */ private $parent; /** * @ORM\OneToMany(targetEntity="AgentsNet", mappedBy="parent") * @ORM\OrderBy({"left" = "ASC"}) */ private $children; public function getId(): ?int { return $this->id; } public function getUserId(): int { return $this->userId; } public function setUserId(int $userId): self { $this->userId = $userId; return $this; } public function getStatus() { //cast int status in value AgentsNetStatusEnum $statusEnum = AgentsNetStatusEnum::fromId((int)$this->status); return $statusEnum; } public function setStatus($status) { if ((int)$status>=0){ $this->status = $status; } else { //set AgentsNetStatusEnum int value $this->status = $status->value; } return $this; } public function getParent(): ?self { return $this->parent; } public function setParent(?self $parent): self { $this->parent = $parent; return $this; } public function getChildren() { 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 getLeft(): ?int { return $this->left; } public function getRight(): ?int { return $this->right; } public function getLevel(): ?int { return $this->level; } public function setLeft(?int $left): ?self { $this->left = $left; return $this; } public function setRight(?int $right): ?self { $this->right = $right; return $this; } public function setLevel(?int $level): ?self { $this->level = $level; return $this; }}