NAS.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. <?php
  2. namespace RadiusBundle\Entity;
  3. use Base\AdminBundle\Traits\TenancyIdTrait;
  4. use Base\AdminBundle\Traits\TenancyIdTraitInterface;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use DeviceBundle\Interfaces\DeviceInterface;
  7. use DeviceBundle\Validator\Constraints as ValidatorAssert;
  8. use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
  9. use MapBundle\Entity\Interfaces\LocationInterface;
  10. use MapBundle\Entity\Traits\LocationTrait;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  13. /**
  14. * @ORM\Table
  15. * @ORM\Entity
  16. * @ORM\Table(uniqueConstraints={@ORM\UniqueConstraint(name="unique_idx", columns={"host", "tenancy_id"})})
  17. *
  18. * @UniqueEntity(fields={"host", "tenancyId"}, message="errors.duplicate_key")
  19. *
  20. * @ValidatorAssert\Device
  21. */
  22. class NAS implements TenancyIdTraitInterface, DeviceInterface, LocationInterface
  23. {
  24. use ExtraDataTrait;
  25. use TenancyIdTrait;
  26. use LocationTrait;
  27. /**
  28. * @var int
  29. *
  30. * @ORM\Column(name="id", type="integer")
  31. * @ORM\Id
  32. * @ORM\GeneratedValue(strategy="AUTO")
  33. */
  34. private $id;
  35. /**
  36. * @var string $description
  37. *
  38. * @ORM\Column(type="string", length=50, nullable=true)
  39. */
  40. private $description;
  41. /**
  42. * @var string $host
  43. *
  44. * @ORM\Column(type="string", length=50, unique=true)
  45. */
  46. private $host;
  47. /**
  48. * @var string $snmpComunity
  49. *
  50. * @ORM\Column(type="string", length=50)
  51. */
  52. private $snmpComunity;
  53. /**
  54. * @var string $snmpVersion
  55. *
  56. * @ORM\Column(type="integer")
  57. */
  58. private $snmpVersion;
  59. /**
  60. * @var string $radiusPassword
  61. *
  62. * @ORM\Column(type="string", length=50)
  63. */
  64. private $radiusPassword;
  65. /**
  66. * @var NASModel $model
  67. *
  68. * @ORM\ManyToOne(targetEntity="NASModel", inversedBy="nass", fetch="EXTRA_LAZY")
  69. * @ORM\JoinColumn(name="model_id", referencedColumnName="id", onDelete="SET NULL")
  70. */
  71. private $model;
  72. /**
  73. * @var boolean $acctEnabled
  74. *
  75. * @ORM\Column(type="boolean", nullable=true)
  76. */
  77. private $acctEnabled;
  78. /**
  79. * @return string
  80. */
  81. public function __toString()
  82. {
  83. return (string)$this->description;
  84. }
  85. /**
  86. * @return int
  87. */
  88. public function getId()
  89. {
  90. return $this->id;
  91. }
  92. /**
  93. * @param int $id
  94. *
  95. * @return mixed Retorna el objeto.
  96. */
  97. public function setId($id)
  98. {
  99. $this->id = $id;
  100. return $this;
  101. }
  102. /**
  103. * @return mixed
  104. */
  105. public function getDescription()
  106. {
  107. return $this->description;
  108. }
  109. /**
  110. * @param mixed $description
  111. *
  112. * @return mixed Retorna el objeto.
  113. */
  114. public function setDescription($description)
  115. {
  116. $this->description = $description;
  117. return $this;
  118. }
  119. /**
  120. * @return mixed
  121. */
  122. public function getHost()
  123. {
  124. return $this->host;
  125. }
  126. /**
  127. * @param mixed $host
  128. *
  129. * @return mixed Retorna el objeto.
  130. */
  131. public function setHost($host)
  132. {
  133. $this->host = $host;
  134. return $this;
  135. }
  136. /**
  137. * @return mixed
  138. */
  139. public function getSnmpComunity()
  140. {
  141. return $this->snmpComunity;
  142. }
  143. /**
  144. * @param mixed $snmpComunity
  145. *
  146. * @return mixed Retorna el objeto.
  147. */
  148. public function setSnmpComunity($snmpComunity)
  149. {
  150. $this->snmpComunity = $snmpComunity;
  151. return $this;
  152. }
  153. /**
  154. * @return mixed
  155. */
  156. public function getSnmpVersion()
  157. {
  158. return $this->snmpVersion;
  159. }
  160. /**
  161. * @param mixed $snmpVersion
  162. *
  163. * @return mixed Retorna el objeto.
  164. */
  165. public function setSnmpVersion($snmpVersion)
  166. {
  167. $this->snmpVersion = $snmpVersion;
  168. return $this;
  169. }
  170. /**
  171. * @return mixed
  172. */
  173. public function getRadiusPassword()
  174. {
  175. return $this->radiusPassword;
  176. }
  177. /**
  178. * @param mixed $radiusPassword
  179. *
  180. * @return mixed Retorna el objeto.
  181. */
  182. public function setRadiusPassword($radiusPassword)
  183. {
  184. $this->radiusPassword = $radiusPassword;
  185. return $this;
  186. }
  187. /**
  188. * @return mixed
  189. */
  190. public function getModel()
  191. {
  192. return $this->model;
  193. }
  194. /**
  195. * @param mixed $model
  196. *
  197. * @return mixed Retorna el objeto.
  198. */
  199. public function setModel($model)
  200. {
  201. $this->model = $model;
  202. return $this;
  203. }
  204. /**
  205. * @return bool
  206. */
  207. public function isAcctEnabled()
  208. {
  209. return $this->acctEnabled;
  210. }
  211. /**
  212. * @param bool $acctEnabled
  213. *
  214. * @return mixed Retorna el objeto.
  215. */
  216. public function setAcctEnabled($acctEnabled)
  217. {
  218. $this->acctEnabled = $acctEnabled;
  219. return $this;
  220. }
  221. /**
  222. * @return array
  223. */
  224. public function getDeviceData()
  225. {
  226. $deviceData = array();
  227. $deviceData['deviceType'] = get_class($this);
  228. $deviceData['deviceId'] = $this->id;
  229. $deviceData['ip'] = $this->host;
  230. $deviceData['tenancy'] = $this->tenancyId;
  231. $deviceExtraData = array('snmpCommunity' => $this->snmpComunity, 'snmpVersion' => $this->snmpVersion, 'radiusPassword' => $this->radiusPassword,
  232. 'acctEnabled' => $this->acctEnabled, 'description' => $this->description);
  233. if ($this->model) {
  234. $model = $this->getModel();
  235. $deviceExtraData['modelId'] = $model->getId();
  236. $deviceExtraData['library'] = $model->getLibrary();
  237. } else {
  238. $deviceExtraData['modelId'] = null;
  239. $deviceExtraData['library'] = null;
  240. }
  241. $deviceData['extraData'] = json_encode($deviceExtraData);
  242. return $deviceData;
  243. }
  244. }