|
@@ -0,0 +1,329 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace CablemodemBundle\Entity;
|
|
|
+
|
|
|
+use Doctrine\ORM\Mapping as ORM;
|
|
|
+use Gedmo\Mapping\Annotation as Gedmo;
|
|
|
+use JMS\Serializer\Annotation as JMS;
|
|
|
+use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
|
|
|
+use Symfony\Component\Validator\Constraints as Assert;
|
|
|
+use Base\AdminBundle\Traits\TenancyIdTrait;
|
|
|
+use Base\AdminBundle\Traits\TenancyIdTraitInterface;
|
|
|
+use DeviceBundle\Interfaces\DeviceInterface;
|
|
|
+use ExtraDataBundle\Entity\Traits\ExtraDataTrait;
|
|
|
+use MapBundle\Entity\Interfaces\LocationInterface;
|
|
|
+use MapBundle\Entity\Traits\LocationTrait;
|
|
|
+use WorkflowBundle\Entity\Interfaces\WorkflowInterface;
|
|
|
+use WorkflowBundle\Entity\Traits\WorkflowTrait;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ORM\Entity
|
|
|
+ * @ORM\Table(indexes={@ORM\Index(name="mac", columns={"mac"})})
|
|
|
+ *
|
|
|
+ * @UniqueEntity(fields={"mac"})
|
|
|
+ *
|
|
|
+ * @Gedmo\Loggable
|
|
|
+ */
|
|
|
+class Cablemodem implements DeviceInterface, TenancyIdTraitInterface, LocationInterface, WorkflowInterface
|
|
|
+{
|
|
|
+
|
|
|
+ use ExtraDataTrait;
|
|
|
+ use TenancyIdTrait;
|
|
|
+ use LocationTrait;
|
|
|
+ use WorkflowTrait;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var bigint $id
|
|
|
+ *
|
|
|
+ * @ORM\Column(name="id", type="bigint", nullable=false)
|
|
|
+ * @ORM\Id
|
|
|
+ * @ORM\GeneratedValue(strategy="IDENTITY")
|
|
|
+ */
|
|
|
+ protected $id;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var int
|
|
|
+ *
|
|
|
+ * @ORM\Column(type="integer")
|
|
|
+ *
|
|
|
+ * @Assert\NotNull
|
|
|
+ */
|
|
|
+ protected $clientId;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @var string $mac
|
|
|
+ *
|
|
|
+ * @ORM\Column(type="string", length=12, nullable=true, unique=true)
|
|
|
+ *
|
|
|
+ * @Gedmo\Versioned
|
|
|
+ *
|
|
|
+ * @Assert\Regex(pattern="/^[a-z0-9]+$/")
|
|
|
+ * @Assert\Length(min=12, max=12)
|
|
|
+ */
|
|
|
+ protected $mac;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\Column(type="string", length=100, nullable=true)
|
|
|
+ *
|
|
|
+ * @Gedmo\Versioned
|
|
|
+ */
|
|
|
+ protected $activationCode;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\ManyToOne(targetEntity="Node", fetch="EXTRA_LAZY", cascade={"persist"})
|
|
|
+ *
|
|
|
+ * @JMS\MaxDepth(1)
|
|
|
+ */
|
|
|
+ protected $node;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\ManyToOne(targetEntity="Profile", fetch="EXTRA_LAZY")
|
|
|
+ *
|
|
|
+ * @JMS\MaxDepth(1)
|
|
|
+ */
|
|
|
+ protected $profile;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\ManyToOne(targetEntity="CablemodemModel", fetch="EXTRA_LAZY")
|
|
|
+ *
|
|
|
+ * @JMS\MaxDepth(1)
|
|
|
+ */
|
|
|
+ protected $model;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Gedmo\Timestampable(on="create")
|
|
|
+ *
|
|
|
+ * @ORM\Column(type="datetime")
|
|
|
+ */
|
|
|
+ protected $created;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @Gedmo\Timestampable(on="update")
|
|
|
+ *
|
|
|
+ * @ORM\Column(type="datetime")
|
|
|
+ */
|
|
|
+ protected $updated;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\ManyToOne(targetEntity="\WorkflowBundle\Entity\Workflow", fetch="EXTRA_LAZY")
|
|
|
+ * @ORM\JoinColumn(name="workflow_id", referencedColumnName="id", onDelete="SET NULL")
|
|
|
+ *
|
|
|
+ * @JMS\MaxDepth(1)
|
|
|
+ */
|
|
|
+ protected $workflow;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\Column(type="string", nullable=true)
|
|
|
+ */
|
|
|
+ protected $currentState = null;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\Column(type="string", nullable=true, options={"default": "active"})
|
|
|
+ */
|
|
|
+ protected $administrativeState = 'active';
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @ORM\Column(type="string", options={"default": "success"})
|
|
|
+ */
|
|
|
+ protected $transitionState = 'success';
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function __toString()
|
|
|
+ {
|
|
|
+ return (string) ($this->mac ?: $this->activationCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function getId()
|
|
|
+ {
|
|
|
+ return $this->id;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function getClientId()
|
|
|
+ {
|
|
|
+ return $this->clientId;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getMac()
|
|
|
+ {
|
|
|
+ return $this->mac;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getActivationCode()
|
|
|
+ {
|
|
|
+ return $this->activationCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return Node
|
|
|
+ */
|
|
|
+ public function getNode()
|
|
|
+ {
|
|
|
+ return $this->node;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return Profile
|
|
|
+ */
|
|
|
+ public function getProfile()
|
|
|
+ {
|
|
|
+ return $this->profile;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return CablemodemModel
|
|
|
+ */
|
|
|
+ public function getModel()
|
|
|
+ {
|
|
|
+ return $this->model;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return \DateTime
|
|
|
+ */
|
|
|
+ public function getCreated()
|
|
|
+ {
|
|
|
+ return $this->created;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return \DateTime
|
|
|
+ */
|
|
|
+ public function getUpdated()
|
|
|
+ {
|
|
|
+ return $this->updated;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param int $clientId
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setClientId($clientId)
|
|
|
+ {
|
|
|
+ $this->clientId = $clientId;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $mac
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setMac($mac)
|
|
|
+ {
|
|
|
+ $this->mac = $mac;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $activationCode
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setActivationCode($activationCode)
|
|
|
+ {
|
|
|
+ $this->activationCode = $activationCode;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Node $node
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setNode($node)
|
|
|
+ {
|
|
|
+ $this->node = $node;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param Profile $profile
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setProfile($profile)
|
|
|
+ {
|
|
|
+ $this->profile = $profile;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param CablemodemModel $model
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setModel($model)
|
|
|
+ {
|
|
|
+ $this->model = $model;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param \DateTime $created
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setCreated($created)
|
|
|
+ {
|
|
|
+ $this->created = $created;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param \DateTime $updated
|
|
|
+ *
|
|
|
+ * @return $this
|
|
|
+ */
|
|
|
+ public function setUpdated($updated)
|
|
|
+ {
|
|
|
+ $this->updated = $updated;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getDeviceData()
|
|
|
+ {
|
|
|
+ $extraData = [
|
|
|
+ 'mac' => $this->mac,
|
|
|
+ 'activationCode' => $this->activationCode,
|
|
|
+ 'clientId' => $this->clientId,
|
|
|
+ 'modelId' => $this->model ? $this->model->getId() : null,
|
|
|
+ 'nodeId' => $this->node ? $this->node->getId() : null,
|
|
|
+ 'profileId' => $this->profile ? $this->profile->getId() : null,
|
|
|
+ ];
|
|
|
+
|
|
|
+ return [
|
|
|
+ 'deviceType' => get_class($this),
|
|
|
+ 'deviceId' => $this->id,
|
|
|
+ 'tenancy' => $this->tenancyId,
|
|
|
+ 'extraData' => json_encode($extraData),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|