NetGroup.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace IPv4Bundle\Entity;
  3. use Base\AdminBundle\Interfaces\PreRemoveInterface;
  4. use Base\AdminBundle\Traits\TenancyIdTrait;
  5. use Base\AdminBundle\Traits\TenancyIdTraitInterface;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Symfony\Component\Validator\ExecutionContext;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. /**
  11. * @ORM\Entity
  12. *
  13. * @UniqueEntity("name")
  14. * @UniqueEntity("opcode")
  15. */
  16. class NetGroup implements TenancyIdTraitInterface, PreRemoveInterface
  17. {
  18. use TenancyIdTrait;
  19. /**
  20. * @var bigint $id
  21. *
  22. * @ORM\Column(name="id", type="bigint", nullable=false)
  23. * @ORM\Id
  24. * @ORM\GeneratedValue(strategy="IDENTITY")
  25. */
  26. protected $id;
  27. /**
  28. * @var string $name
  29. *
  30. * @ORM\Column(type="string", length=100, unique=true)
  31. *
  32. * @Assert\NotBlank
  33. */
  34. protected $name;
  35. /**
  36. * @var string $opcode
  37. *
  38. * @ORM\Column(type="integer", unique=true)
  39. *
  40. * @Assert\NotBlank
  41. */
  42. protected $opcode;
  43. /**
  44. * @ORM\OneToMany(targetEntity="SubNet", mappedBy="netGroup")
  45. */
  46. protected $subNets;
  47. /**
  48. * @return string
  49. */
  50. public function __toString()
  51. {
  52. return strval($this->name);
  53. }
  54. /**
  55. * @return bigint
  56. */
  57. public function getId()
  58. {
  59. return $this->id;
  60. }
  61. /**
  62. * @param string $name
  63. *
  64. * @return NetGroup
  65. */
  66. public function setName($name)
  67. {
  68. $this->name = $name;
  69. return $this;
  70. }
  71. /**
  72. * @return string
  73. */
  74. public function getName()
  75. {
  76. return $this->name;
  77. }
  78. /**
  79. * @param string $opcode
  80. *
  81. * @return NetGroup
  82. */
  83. public function setOpcode($opcode)
  84. {
  85. $this->opcode = $opcode;
  86. return $this;
  87. }
  88. /**
  89. * @return string
  90. */
  91. public function getOpcode()
  92. {
  93. return $this->opcode;
  94. }
  95. /**
  96. * @return array
  97. */
  98. public function getEntitiesForRemove()
  99. {
  100. $entities = [];
  101. if ($this->subNets->count() != 0) {
  102. $entities['subNets'] = $this->subNets;
  103. }
  104. return $entities;
  105. }
  106. }