123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
- namespace CablemodemBundle\Entity;
- use Base\AdminBundle\Interfaces\PreRemoveInterface;
- use Doctrine\Common\Collections\ArrayCollection;
- use Doctrine\ORM\Mapping as ORM;
- use JMS\Serializer\Annotation as JMS;
- use Symfony\Component\Validator\Constraints as Assert;
- use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
- use Base\AdminBundle\Traits\TenancyIdTrait;
- use Base\AdminBundle\Traits\TenancyIdTraitInterface;
- /**
- * @ORM\Entity
- * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"name","tenancy_id"})})
- *
- * @UniqueEntity(fields={"tenancyId","name"})
- */
- class Node implements TenancyIdTraitInterface, PreRemoveInterface
- {
- use TenancyIdTrait;
- /**
- * @ORM\Column(name="id", type="bigint", nullable=false)
- * @ORM\Id
- * @ORM\GeneratedValue(strategy="IDENTITY")
- */
- protected $id;
- /**
- * @ORM\Column(type="string", length=100)
- *
- * @Assert\NotNull
- */
- protected $name;
- /**
- * @ORM\ManyToOne(targetEntity="Node", inversedBy="childs")
- * @ORM\JoinColumn(onDelete="CASCADE")
- *
- * @JMS\MaxDepth(1)
- */
- protected $parent;
- /**
- * @ORM\OneToMany(targetEntity="Node", mappedBy="parent")
- *
- * @JMS\MaxDepth(1)
- */
- protected $childs;
- /**
- * Constructor
- */
- public function __construct()
- {
- $this->childs = new ArrayCollection;
- }
- /**
- *
- * @return string
- */
- public function __toString()
- {
- return (string)$this->name;
- }
- /**
- * @return bigint
- */
- public function getId()
- {
- return $this->id;
- }
- /**
- * @param string $name
- *
- * @return Node
- */
- public function setName($name)
- {
- $this->name = $name;
- return $this;
- }
- /**
- * @return string
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * @param Node $parent
- *
- * @return Node
- */
- public function setParent($parent = null)
- {
- $this->parent = $parent;
- return $this;
- }
- /**
- * @return Node
- */
- public function getParent()
- {
- return $this->parent;
- }
- /**
- * @param Node $childs
- *
- * @return Node
- */
- public function addChild($childs)
- {
- $this->childs[] = $childs;
- return $this;
- }
- /**
- * @param Node $childs
- */
- public function removeChild(Node $childs)
- {
- $this->childs->removeElement($childs);
- }
- /**
- * @return Doctrine\Common\Collections\Collection
- */
- public function getChilds()
- {
- return $this->childs;
- }
- /**
- * @return array
- */
- public function getEntitiesForRemove()
- {
- $entities = [];
- if ($this->childs->count() != 0) {
- $entities['childs'] = $this->childs;
- }
- return $entities;
- }
- }
|