Cablemodem.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. <?php
  2. namespace CablemodemBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Gedmo\Mapping\Annotation as Gedmo;
  5. use JMS\Serializer\Annotation as JMS;
  6. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use Base\AdminBundle\Traits\TenancyIdTrait;
  9. use Base\AdminBundle\Traits\TenancyIdTraitInterface;
  10. use DeviceBundle\Interfaces\DeviceInterface;
  11. use DeviceBundle\Validator\Constraints as ValidatorAssert;
  12. use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
  13. use MapBundle\Entity\Interfaces\LocationInterface;
  14. use MapBundle\Entity\Traits\LocationTrait;
  15. use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
  16. use WorkflowBundle\Entity\Traits\WorkflowTrait;
  17. use Gedmo\SoftDeleteable\Traits\SoftDeleteableEntity as SoftDeleteable;
  18. use Base\AdminBundle\Interfaces\SoftDeleteInterface;
  19. /**
  20. * @ORM\Entity
  21. * @ORM\Table(indexes={@ORM\Index(name="mac", columns={"mac"})})
  22. *
  23. * @UniqueEntity(fields={"mac"})
  24. *
  25. * @Gedmo\Loggable
  26. * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=true)
  27. *
  28. * @ValidatorAssert\Device
  29. */
  30. class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface, SoftDeleteInterface
  31. {
  32. use ExtraDataTrait;
  33. use TenancyIdTrait;
  34. use LocationTrait;
  35. use WorkflowTrait;
  36. use SoftDeleteable;
  37. /**
  38. * @var bigint $id
  39. *
  40. * @ORM\Column(name="id", type="bigint", nullable=false)
  41. * @ORM\Id
  42. * @ORM\GeneratedValue(strategy="IDENTITY")
  43. */
  44. protected $id;
  45. /**
  46. * @var int
  47. *
  48. * @ORM\Column(type="integer")
  49. *
  50. * @Assert\NotNull
  51. */
  52. protected $clientId;
  53. /**
  54. * @var string $mac
  55. *
  56. * @ORM\Column(type="string", length=12, nullable=false, unique=true)
  57. *
  58. * @Gedmo\Versioned
  59. *
  60. * @Assert\Regex(pattern="/^[a-z0-9]+$/")
  61. * @Assert\Length(min=12, max=12)
  62. * @Assert\NotBlank()
  63. * @Assert\NotNull
  64. */
  65. protected $mac;
  66. /**
  67. * @ORM\Column(type="string", length=100, nullable=true)
  68. *
  69. * @Gedmo\Versioned
  70. */
  71. protected $activationCode;
  72. /**
  73. * @ORM\ManyToOne(targetEntity="Node", fetch="EXTRA_LAZY", cascade={"persist"})
  74. *
  75. * @JMS\MaxDepth(1)
  76. */
  77. protected $node;
  78. /**
  79. * @ORM\ManyToOne(targetEntity="Profile", fetch="EXTRA_LAZY")
  80. *
  81. * @JMS\MaxDepth(1)
  82. */
  83. protected $profile;
  84. /**
  85. * @ORM\ManyToOne(targetEntity="CablemodemModel", fetch="EXTRA_LAZY")
  86. *
  87. * @JMS\MaxDepth(1)
  88. */
  89. protected $model;
  90. /**
  91. * @Gedmo\Timestampable(on="create")
  92. *
  93. * @ORM\Column(type="datetime")
  94. */
  95. protected $created;
  96. /**
  97. * @Gedmo\Timestampable(on="update")
  98. *
  99. * @ORM\Column(type="datetime")
  100. */
  101. protected $updated;
  102. /**
  103. * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
  104. * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
  105. *
  106. * @JMS\MaxDepth(1)
  107. */
  108. protected $workflow;
  109. /**
  110. * @ORM\Column(type="string", nullable=true)
  111. */
  112. protected $currentState = null;
  113. /**
  114. * @ORM\Column(type="string", nullable=true, options={"default": "active"})
  115. */
  116. protected $administrativeState = 'active';
  117. /**
  118. * @ORM\Column(type="string", options={"default": "success"})
  119. */
  120. protected $transitionState = 'success';
  121. /**
  122. * @ORM\Column(type="boolean", nullable=true)
  123. */
  124. protected $mtaEnabled = false;
  125. /**
  126. * @return string
  127. */
  128. public function __toString()
  129. {
  130. return (string) ($this->mac ?: $this->activationCode);
  131. }
  132. /**
  133. * @return int
  134. */
  135. public function getId()
  136. {
  137. return $this->id;
  138. }
  139. /**
  140. * @return int
  141. */
  142. public function getClientId()
  143. {
  144. return $this->clientId;
  145. }
  146. /**
  147. * @return string
  148. */
  149. public function getMac()
  150. {
  151. return $this->mac;
  152. }
  153. /**
  154. * @return string
  155. */
  156. public function getActivationCode()
  157. {
  158. return $this->activationCode;
  159. }
  160. /**
  161. * @return Node
  162. */
  163. public function getNode()
  164. {
  165. return $this->node;
  166. }
  167. /**
  168. * @return Profile
  169. */
  170. public function getProfile()
  171. {
  172. return $this->profile;
  173. }
  174. /**
  175. * @return CablemodemModel
  176. */
  177. public function getModel()
  178. {
  179. return $this->model;
  180. }
  181. /**
  182. * @return \DateTime
  183. */
  184. public function getCreated()
  185. {
  186. return $this->created;
  187. }
  188. /**
  189. * @return \DateTime
  190. */
  191. public function getUpdated()
  192. {
  193. return $this->updated;
  194. }
  195. /**
  196. * @param int $clientId
  197. *
  198. * @return $this
  199. */
  200. public function setClientId($clientId)
  201. {
  202. $this->clientId = $clientId;
  203. return $this;
  204. }
  205. /**
  206. * @param string $mac
  207. *
  208. * @return $this
  209. */
  210. public function setMac($mac)
  211. {
  212. $this->mac = $mac;
  213. return $this;
  214. }
  215. /**
  216. * @param string $activationCode
  217. *
  218. * @return $this
  219. */
  220. public function setActivationCode($activationCode)
  221. {
  222. $this->activationCode = $activationCode;
  223. return $this;
  224. }
  225. /**
  226. * @param Node $node
  227. *
  228. * @return $this
  229. */
  230. public function setNode($node)
  231. {
  232. $this->node = $node;
  233. return $this;
  234. }
  235. /**
  236. * @param Profile $profile
  237. *
  238. * @return $this
  239. */
  240. public function setProfile($profile)
  241. {
  242. $this->profile = $profile;
  243. return $this;
  244. }
  245. /**
  246. * @param CablemodemModel $model
  247. *
  248. * @return $this
  249. */
  250. public function setModel($model)
  251. {
  252. $this->model = $model;
  253. return $this;
  254. }
  255. /**
  256. * @param \DateTime $created
  257. *
  258. * @return $this
  259. */
  260. public function setCreated($created)
  261. {
  262. $this->created = $created;
  263. return $this;
  264. }
  265. /**
  266. * @param \DateTime $updated
  267. *
  268. * @return $this
  269. */
  270. public function setUpdated($updated)
  271. {
  272. $this->updated = $updated;
  273. return $this;
  274. }
  275. /**
  276. * @return array
  277. */
  278. public function getDeviceData()
  279. {
  280. $extraData = [
  281. 'mac' => $this->mac,
  282. 'activationCode' => $this->activationCode,
  283. 'clientId' => $this->clientId,
  284. 'modelId' => $this->model ? $this->model->getId() : null,
  285. 'nodeId' => $this->node ? $this->node->getId() : null,
  286. 'profileId' => $this->profile ? $this->profile->getId() : null,
  287. ];
  288. return [
  289. 'deviceType' => get_class($this),
  290. 'deviceId' => $this->id,
  291. 'tenancy' => $this->tenancyId,
  292. 'extraData' => json_encode($extraData),
  293. ];
  294. }
  295. /**
  296. * @return array
  297. */
  298. public function getSoftDeleteCriteria()
  299. {
  300. return array('mac' => $this->mac);
  301. }
  302. /**
  303. * @return boolean
  304. */
  305. public function getMtaEnabled()
  306. {
  307. return $this->mtaEnabled;
  308. }
  309. /**
  310. * @param boolean $mtaEnabled
  311. *
  312. * @return Cablemodem
  313. */
  314. public function setMtaEnabled($mtaEnabled)
  315. {
  316. $this->mtaEnabled = $mtaEnabled;
  317. return $this;
  318. }
  319. /**
  320. * @return string
  321. */
  322. public function getDHCPOptions()
  323. {
  324. $options = [
  325. 'filename' => $this->mac . '.bin',
  326. ];
  327. if ($this->mtaEnabled) {
  328. $options['option122_dhcp_server'] = "255.255.255.255";
  329. $options['option122_provisioning_type'] = "BASIC.1";
  330. }
  331. return $options;
  332. }
  333. }