src/Entity/AgentsNet.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Gedmo\Mapping\Annotation as Gedmo;
  5. use Gedmo\Tree\Traits\NestedSetEntity;
  6. enum AgentsNetStatusEnumint
  7. {
  8.     case SUPERUSER_ROOT 50// it is the only id known as root
  9.     case GRANT_ALL 100// is always visible and is enabled to perform all operations even on children
  10.     case DELETED 400// it is always visible 
  11.     case ONLY_VISIBLE 500// it is always visible 
  12.     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
  13.     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
  14.     case AGENT_OUT_NET 1550// agent out of network both viewing and reading
  15.     public static function fromId(int $id): ?AgentsNetStatusEnum {
  16.         foreach (self::cases() as $case) {
  17.             if ($case->value === $id) {
  18.                 return $case;
  19.             }
  20.         }
  21.         return null;
  22.     }
  23. }
  24. /**
  25.  * @Gedmo\Tree(type="nested")
  26.  * @ORM\Entity(repositoryClass="App\Repository\AgentsNetRepository")
  27.  */
  28. class AgentsNet
  29. {
  30.     public const AGENTSNET_DEFAULT_LEVEL_SHOW_STATUS 900;
  31.     use NestedSetEntity// entity tree manage
  32.     /**
  33.      * @ORM\Id
  34.      * @ORM\GeneratedValue
  35.      * @ORM\Column(type="integer")
  36.      */
  37.     private $id;
  38.     /**
  39.      * @ORM\Column(type="integer", nullable=false)
  40.      */
  41.     private $userId;
  42.     /**
  43.      * @ORM\Column(type="integer", nullable=true, options={"default":0})
  44.      */
  45.     private $status;
  46.     /**
  47.      * @Gedmo\TreeParent
  48.      * @ORM\ManyToOne(targetEntity="AgentsNet", inversedBy="children")
  49.      * @ORM\JoinColumn(name="parent_id", referencedColumnName="id", onDelete="CASCADE")
  50.      */
  51.     private $parent;
  52.     /**
  53.      * @ORM\OneToMany(targetEntity="AgentsNet", mappedBy="parent")
  54.      * @ORM\OrderBy({"left" = "ASC"})
  55.      */
  56.     private $children;
  57.     public function getId(): ?int
  58.     {
  59.         return $this->id;
  60.     }
  61.     public function getUserId(): int
  62.     {
  63.         return $this->userId;
  64.     }
  65.     public function setUserId(int $userId): self
  66.     {
  67.         $this->userId $userId;
  68.         return $this;
  69.     }
  70.     public function getStatus()
  71.     {
  72.         //cast int status in value AgentsNetStatusEnum
  73.         $statusEnum AgentsNetStatusEnum::fromId((int)$this->status);
  74.         return $statusEnum;
  75.     }
  76.     public function setStatus($status)
  77.     {
  78.         if ((int)$status>=0){
  79.             $this->status $status;
  80.         } else {
  81.             //set AgentsNetStatusEnum int value
  82.             $this->status $status->value;
  83.         }
  84.         return $this;
  85.     }
  86.     public function getParent(): ?self
  87.     {
  88.         return $this->parent;
  89.     }
  90.     public function setParent(?self $parent): self
  91.     {
  92.         $this->parent $parent;
  93.         return $this;
  94.     }
  95.     public function getChildren()
  96.     {
  97.         return $this->children;
  98.     }
  99.     public function addChild(self $child): self
  100.     {
  101.         if (!$this->children->contains($child)) {
  102.             $this->children[] = $child;
  103.             $child->setParent($this);
  104.         }
  105.         return $this;
  106.     }
  107.     public function removeChild(self $child): self
  108.     {
  109.         if ($this->children->removeElement($child)) {
  110.             // set the owning side to null (unless already changed)
  111.             if ($child->getParent() === $this) {
  112.                 $child->setParent(null);
  113.             }
  114.         }
  115.         return $this;
  116.     }
  117.     public function getLeft(): ?int
  118.     {
  119.         return $this->left;
  120.     }
  121.     public function getRight(): ?int
  122.     {
  123.         return $this->right;
  124.     }
  125.     public function getLevel(): ?int
  126.     {
  127.         return $this->level;
  128.     }
  129.     public function setLeft(?int $left): ?self
  130.     {
  131.         $this->left $left;
  132.         return $this;
  133.     }
  134.     public function setRight(?int $right): ?self
  135.     {
  136.         $this->right $right;
  137.         return $this;
  138.     }
  139.     public function setLevel(?int $level): ?self
  140.     {
  141.         $this->level $level;
  142.         return $this;
  143.     }
  144. }